Wednesday, 12 October 2022

Atlas Client: Delete glossary by id

AtlasClientV2#deleteGlossaryByGuid method is used to delete the glossary by id.

 

Signature

public void deleteGlossaryByGuid(String glossaryGuid) throws AtlasServiceException

 

Example

atlasClient.deleteGlossaryByGuid(glossaryId);

 


Find the below working application.

 

atlas-application.properties

atlas.client.readTimeoutMSecs=30000
atlas.client.connectTimeoutMSecs=30000

JsonUtil.java

package com.sample.app.util;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

public class JsonUtil {
	public static String marshal(Object obj) throws JsonProcessingException {
		ObjectMapper mapper = new ObjectMapper();
		return mapper.writeValueAsString(obj);
	}

	public static <T> T unmarshal(Class<T> clazz, String json)
			throws JsonParseException, JsonMappingException, IOException {
		ObjectMapper mapper = new ObjectMapper();
		return (T) mapper.readValue(json, clazz);
	}

	public static String prettyPrintJson(Object obj) throws JsonProcessingException {
		ObjectMapper mapper = new ObjectMapper();
		mapper.enable(SerializationFeature.INDENT_OUTPUT);
		return mapper.writeValueAsString(obj);
	}
}

DeleteGlossaryById.java

package com.sample.app.glossary;

import org.apache.atlas.AtlasClientV2;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.model.glossary.AtlasGlossary;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.sample.app.util.JsonUtil;

public class DeleteGlossaryById {

  public static void main(String[] args) throws AtlasServiceException, JsonProcessingException {
    AtlasClientV2 atlasClient = new AtlasClientV2(new String[] { "http://localhost:21000" },
        new String[] { "admin", "admin" });

    String glossaryId = "62bc12e8-90b6-4bcf-bd08-f25bcf37a93b";

    AtlasGlossary atlasGlossary = atlasClient.getGlossaryByGuid(glossaryId);
    System.out.println("atlasGlossary : \n" + JsonUtil.prettyPrintJson(atlasGlossary));

    atlasClient.deleteGlossaryByGuid(glossaryId);

    // This call with throw AtlasServiceException
    atlasClient.getGlossaryByGuid(glossaryId);
  }
}

Output

atlasGlossary : 
{
  "guid" : "62bc12e8-90b6-4bcf-bd08-f25bcf37a93b",
  "qualifiedName" : "finance",
  "name" : "finance",
  "shortDescription" : "finance",
  "longDescription" : "finance"
}
Exception in thread "main" org.apache.atlas.AtlasServiceException: Metadata service API org.apache.atlas.AtlasBaseClient$API@77eca502 failed with status 404 (Not Found) Response Body ({"errorCode":"ATLAS-404-00-005","errorMessage":"Given instance guid 62bc12e8-90b6-4bcf-bd08-f25bcf37a93b is invalid/not found"})
    at org.apache.atlas.AtlasBaseClient.callAPIWithResource(AtlasBaseClient.java:427)
    at org.apache.atlas.AtlasBaseClient.callAPIWithResource(AtlasBaseClient.java:352)
    at org.apache.atlas.AtlasBaseClient.callAPI(AtlasBaseClient.java:256)
    at org.apache.atlas.AtlasClientV2.getGlossaryByGuid(AtlasClientV2.java:844)
    at com.sample.app.glossary.DeleteGlossaryById.main(DeleteGlossaryById.java:23)

After updation, you can observe that the glossary ‘finance’ is deleted.

  

Previous                                                    Next                                                    Home

No comments:

Post a Comment