In this post, I am going to use ‘atlas-client-v2’ library to print all the entity type names available in Atlas.
To use atlas client, we need to define atlas-application.properties file under src/main/resources folder.
atlas-application.properties
atlas.client.readTimeoutMSecs=30000 atlas.client.connectTimeoutMSecs=30000
Get an instance of AtlasClientV2.
AtlasClientV2 atlasClient = new AtlasClientV2(new String[] { "http://localhost:21000" }, new String[] { "admin", "admin" });
Define a search filter and get all type definitions.
SearchFilter searchFilter = new SearchFilter();
AtlasTypesDef atlasTypesDef = atlasClient.getAllTypeDefs(searchFilter);
Find the below working application.
HelloWorld.java
package com.sample.app;
import java.util.List;
import org.apache.atlas.AtlasClientV2;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasTypesDef;
public class HelloWorld {
public static void main(String[] args) throws AtlasServiceException {
AtlasClientV2 atlasClient = new AtlasClientV2(new String[] { "http://localhost:21000" },
new String[] { "admin", "admin" });
SearchFilter searchFilter = new SearchFilter();
AtlasTypesDef atlasTypesDef = atlasClient.getAllTypeDefs(searchFilter);
List<AtlasEntityDef> atlasEntityDefs = atlasTypesDef.getEntityDefs();
for (AtlasEntityDef atlasEntityDef : atlasEntityDefs) {
String typeName = atlasEntityDef.getName();
System.out.println(typeName);
}
}
}
No comments:
Post a Comment