AtlasClientV2 provides 'createGlossary' method to create a glossary.
Signature
public AtlasGlossary createGlossary(AtlasGlossary glossary) throws AtlasServiceException
Find the below working application.
Create atlas-application.properties file under src/main/resources folder.
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);
}
}
CreateGlossary.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 CreateGlossary {
public static void main(String[] args) throws AtlasServiceException, JsonProcessingException {
AtlasClientV2 atlasClient = new AtlasClientV2(new String[] { "http://localhost:21000" },
new String[] { "admin", "admin" });
AtlasGlossary atlasGlossary = new AtlasGlossary();
atlasGlossary.setName("myGlosary1");
atlasGlossary.setShortDescription("Demo Glossary");
atlasGlossary.setLongDescription("Demo GLossary.......");
AtlasGlossary persistedGlossary = atlasClient.createGlossary(atlasGlossary);
System.out.println(JsonUtil.prettyPrintJson(persistedGlossary));
}
}
Output
{
"guid" : "c71a18b9-9f24-4451-8acc-a9a4d55cf1a0",
"qualifiedName" : "myGlosary1",
"name" : "myGlosary1",
"shortDescription" : "Demo Glossary",
"longDescription" : "Demo GLossary......."
}
You can confirm the same by login to Atlas UI.
No comments:
Post a Comment