This is an automated email from the ASF dual-hosted git repository.
madhan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git
The following commit(s) were added to refs/heads/master by this push:
new b7255ec ATLAS-3875: adding sample client change
b7255ec is described below
commit b7255ec7e24f87da6f2dba47965a4e22e94c2250
Author: jyoti0208 <[email protected]>
AuthorDate: Tue Aug 4 11:59:42 2020 -0400
ATLAS-3875: adding sample client change
Signed-off-by: Madhan Neethiraj <[email protected]>
---
atlas-examples/pom.xml | 36 +++
atlas-examples/sample-app/README.md | 13 +
atlas-examples/sample-app/pom.xml | 104 ++++++++
.../atlas/examples/sampleapp/DiscoveryExample.java | 89 +++++++
.../atlas/examples/sampleapp/EntityExample.java | 276 +++++++++++++++++++++
.../atlas/examples/sampleapp/GlossaryExample.java | 112 +++++++++
.../atlas/examples/sampleapp/LineageExample.java | 48 ++++
.../apache/atlas/examples/sampleapp/SampleApp.java | 151 +++++++++++
.../examples/sampleapp/SampleAppConstants.java | 75 ++++++
.../atlas/examples/sampleapp/TypeDefExample.java | 274 ++++++++++++++++++++
.../main/resources/atlas-application.properties | 25 ++
pom.xml | 1 +
12 files changed, 1204 insertions(+)
diff --git a/atlas-examples/pom.xml b/atlas-examples/pom.xml
new file mode 100644
index 0000000..1ff213c
--- /dev/null
+++ b/atlas-examples/pom.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>apache-atlas</artifactId>
+ <groupId>org.apache.atlas</groupId>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>atlas-examples</artifactId>
+ <packaging>pom</packaging>
+ <modules>
+ <module>sample-app</module>
+ </modules>
+
+
+</project>
\ No newline at end of file
diff --git a/atlas-examples/sample-app/README.md
b/atlas-examples/sample-app/README.md
new file mode 100644
index 0000000..65ac54c
--- /dev/null
+++ b/atlas-examples/sample-app/README.md
@@ -0,0 +1,13 @@
+## Introduction
+This is a simple application to demonstrate the use of AtlasClient. SampleApp
provides examples to use following Client APIs.
+1. TypeDef
+2. Entity
+3. Lineage
+4. Search
+5. Glossary
+
+## Setting up
+1. cd ~/Desktop/atlas/atlas-examples/sample-app (the location where you have
downloaded sample-app)
+2. mvn clean install
+3. mvn exec:java
+4. Then it will ask you to enter AtlasServer URL, username and password.
\ No newline at end of file
diff --git a/atlas-examples/sample-app/pom.xml
b/atlas-examples/sample-app/pom.xml
new file mode 100644
index 0000000..aa3c637
--- /dev/null
+++ b/atlas-examples/sample-app/pom.xml
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>atlas-examples</artifactId>
+ <groupId>org.apache.atlas</groupId>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>sample-app</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.atlas</groupId>
+ <artifactId>atlas-client-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.atlas</groupId>
+ <artifactId>atlas-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.atlas</groupId>
+ <artifactId>atlas-client-v2</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.atlas</groupId>
+ <artifactId>atlas-intg</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>${jackson.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>java</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+
<mainClass>org.apache.atlas.examples.sampleapp.SampleApp</mainClass>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
diff --git
a/atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/DiscoveryExample.java
b/atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/DiscoveryExample.java
new file mode 100644
index 0000000..b61e6eb
--- /dev/null
+++
b/atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/DiscoveryExample.java
@@ -0,0 +1,89 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.atlas.examples.sampleapp;
+
+import org.apache.atlas.AtlasClientV2;
+import org.apache.atlas.AtlasServiceException;
+import org.apache.atlas.model.discovery.AtlasQuickSearchResult;
+import org.apache.atlas.model.discovery.AtlasSearchResult;
+import org.apache.atlas.model.instance.AtlasEntityHeader;
+
+import java.util.List;
+
+public class DiscoveryExample {
+ private static final String[] DSL_QUERIES = new String[] { "from DataSet",
"from Process" };
+
+ private final AtlasClientV2 client;
+
+ DiscoveryExample(AtlasClientV2 client) {
+ this.client = client;
+ }
+
+ public void testSearch() {
+ for (String dslQuery : DSL_QUERIES) {
+ try {
+ AtlasSearchResult result =
client.dslSearchWithParams(dslQuery, 10, 0);
+ List<AtlasEntityHeader> entities = result != null ?
result.getEntities() : null;
+ int resultCount = entities == null ? 0 :
entities.size();
+
+ System.out.println("DSL Query: " + dslQuery);
+ System.out.println(" result count: " + resultCount);
+
+ for (int i = 0; i < resultCount; i++) {
+ System.out.println(" result # " + (i + 1) + ": " +
entities.get(i));
+ }
+ } catch (Exception e) {
+ System.out.println("query -: " + dslQuery + " failed");
+ }
+ }
+ }
+
+ public void quickSearch(String searchString) {
+ try {
+ AtlasQuickSearchResult result =
client.quickSearch(searchString, SampleAppConstants.TABLE_TYPE, false, 2, 0);
+ List<AtlasEntityHeader> entities = result != null &&
result.getSearchResults() != null ? result.getSearchResults().getEntities() :
null;
+ int resultCount = entities == null ? 0 :
entities.size();
+
+ System.out.println("Quick search: query-string=" + searchString);
+ System.out.println(" result count: " + resultCount);
+
+ for (int i = 0; i < resultCount; i++) {
+ System.out.println(" result # " + (i + 1) + ": " +
entities.get(i));
+ }
+ } catch (AtlasServiceException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void basicSearch(String typeName, String classification, String
query) {
+ try {
+ AtlasSearchResult result = client.basicSearch(typeName,
classification, query, false, 2, 0);
+ List<AtlasEntityHeader> entities = result != null ?
result.getEntities() : null;
+ int resultCount = entities == null ? 0 :
entities.size();
+
+ System.out.println("Basic search: typeName=" + typeName + ",
classification=" + classification + ", query=" + query);
+ System.out.println(" result count: " + resultCount);
+
+ for (int i = 0; i < resultCount; i++) {
+ System.out.println(" result # " + (i + 1) + ": " +
entities.get(i));
+ }
+ } catch (AtlasServiceException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git
a/atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/EntityExample.java
b/atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/EntityExample.java
new file mode 100644
index 0000000..23fc3b8
--- /dev/null
+++
b/atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/EntityExample.java
@@ -0,0 +1,276 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.atlas.examples.sampleapp;
+
+import org.apache.atlas.AtlasClientV2;
+import org.apache.atlas.AtlasServiceException;
+import org.apache.atlas.model.instance.AtlasClassification;
+import org.apache.atlas.model.instance.AtlasEntity;
+import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
+import org.apache.atlas.model.instance.AtlasEntityHeader;
+import org.apache.atlas.model.instance.AtlasStruct;
+import org.apache.atlas.model.instance.EntityMutationResponse;
+import org.apache.atlas.model.instance.EntityMutations;
+import org.apache.atlas.type.AtlasTypeUtil;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static java.util.Arrays.asList;
+import static org.apache.atlas.examples.sampleapp.SampleAppConstants.*;
+import static org.apache.atlas.type.AtlasTypeUtil.toAtlasRelatedObjectId;
+import static org.apache.atlas.type.AtlasTypeUtil.toAtlasRelatedObjectIds;
+
+public class EntityExample {
+ private static final String DATABASE_NAME =
"employee_db_entity";
+ private static final String TABLE_NAME =
"employee_table_entity";
+ private static final String PROCESS_NAME =
"employee_process_entity";
+ private static final String METADATA_NAMESPACE_SUFFIX = "@cl1";
+ private static final String MANAGED_TABLE = "Managed";
+ private static final String ATTR_NAME = "name";
+ private static final String ATTR_DESCRIPTION = "description";
+ private static final String ATTR_QUALIFIED_NAME = "qualifiedName";
+ private static final String REFERENCEABLE_ATTRIBUTE_NAME =
ATTR_QUALIFIED_NAME;
+ private static final String COLUMN_TIME_ID = "time_id";
+ private static final String COLUMN_CUSTOMER_ID = "customer_id";
+ private static final String COLUMN_COMPANY_ID = "company_id";
+
+ private final AtlasClientV2 client;
+ private AtlasEntity dbEntity;
+ private AtlasEntity tableEntityUS;
+ private AtlasEntity tableEntityCanada;
+ private AtlasEntityHeader loadProcess;
+
+ EntityExample(AtlasClientV2 client) {
+ this.client = client;
+ }
+
+ public void createEntities() throws Exception {
+ if (dbEntity == null) {
+ dbEntity = createDatabaseEntity(DATABASE_NAME);
+
+ System.out.println("Created database entity: typeName=" +
dbEntity.getTypeName() + ", guid=" + dbEntity.getGuid());
+ }
+
+ if (tableEntityCanada == null) {
+ tableEntityCanada = createTableEntity(TABLE_NAME + "_CANADA");
+
+ System.out.println("Created table entity : typeName=" +
tableEntityCanada.getTypeName() + ", guid=" + tableEntityCanada.getGuid());
+ }
+
+ if (tableEntityUS == null) {
+ tableEntityUS = createTableEntity(TABLE_NAME + "_US");
+
+ System.out.println("Created table entity : typeName=" +
tableEntityUS.getTypeName() + ", guid=" + tableEntityUS.getGuid());
+ }
+
+ if (loadProcess == null) {
+ loadProcess = createProcessEntity(PROCESS_NAME);
+
+ System.out.println("Created process entity : typeName=" +
loadProcess.getTypeName() + ", guid=" + loadProcess.getGuid());
+ }
+ }
+
+ public AtlasEntity getTableEntity() {
+ return tableEntityUS;
+ }
+
+ public void getEntityByGuid(String entityGuid) throws Exception {
+ AtlasEntityWithExtInfo entity = client.getEntityByGuid(entityGuid);
+
+ if (entity != null) {
+ System.out.println("Retrieved entity with guid=" + entityGuid + ":
" + entity);
+ }
+ }
+
+ public void deleteEntities() throws Exception {
+ client.deleteEntityByGuid(loadProcess.getGuid());
+
+ System.out.println("Deleted entity: guid=" + loadProcess.getGuid());
+
+ List<String> entityGuids = Arrays.asList(tableEntityUS.getGuid(),
tableEntityCanada.getGuid(), dbEntity.getGuid());
+
+ client.deleteEntitiesByGuids(entityGuids);
+
+ System.out.println("Deleted entities:");
+ for (String entityGuid : entityGuids) {
+ System.out.println(" guid=" + entityGuid);
+ }
+ }
+
+ private AtlasEntity createTableEntity(String tableName) throws Exception {
+ return createHiveTable(dbEntity, tableName, MANAGED_TABLE,
+ Arrays.asList(createColumn(COLUMN_TIME_ID, "int", "time id"),
+ createColumn(COLUMN_CUSTOMER_ID, "int",
"customer id", SampleAppConstants.PII_TAG),
+ createColumn(COLUMN_COMPANY_ID, "double",
"company id", SampleAppConstants.FINANCE_TAG)),
+ SampleAppConstants.METRIC_CLASSIFICATION);
+ }
+
+ private AtlasEntityHeader createProcessEntity(String processName) throws
Exception {
+ return createProcess(processName, "hive query for monthly avg salary",
"user ETL",
+ asList(tableEntityUS),
+ asList(tableEntityCanada),
+ "create table as select ", "plan", "id", "graph",
SampleAppConstants.CLASSIFICATION);
+ }
+
+ private AtlasEntityHeader createProcess(String name, String description,
String user, List<AtlasEntity> inputs, List<AtlasEntity> outputs,
+ String queryText, String
queryPlan, String queryId, String queryGraph, String... classificationNames)
throws Exception {
+
+ AtlasEntity entity = new AtlasEntity(SampleAppConstants.PROCESS_TYPE);
+
+ entity.setAttribute(ATTR_NAME, name);
+ entity.setAttribute(REFERENCEABLE_ATTRIBUTE_NAME, name +
METADATA_NAMESPACE_SUFFIX);
+ entity.setAttribute(ATTR_DESCRIPTION, description);
+ entity.setAttribute(ATTR_USERNAME, user);
+ entity.setAttribute(ATTR_START_TIME, System.currentTimeMillis());
+ entity.setAttribute(ATTR_END_TIME, System.currentTimeMillis() + 10000);
+ entity.setAttribute(ATTR_QUERY_TEXT, queryText);
+ entity.setAttribute(ATTR_QUERY_PLAN, queryPlan);
+ entity.setAttribute(ATTR_QUERY_ID, queryId);
+ entity.setAttribute(ATTR_QUERY_GRAPH, queryGraph);
+ entity.setAttribute(ATTR_OPERATION_TYPE, "testOperation");
+
+ entity.setRelationshipAttribute(ATTR_INPUTS,
toAtlasRelatedObjectIds(inputs));
+ entity.setRelationshipAttribute(ATTR_OUTPUTS,
toAtlasRelatedObjectIds(outputs));
+
+ entity.setClassifications(toAtlasClassifications(classificationNames));
+
+ return createEntity(new AtlasEntityWithExtInfo(entity));
+ }
+
+ private AtlasEntity createColumn(String name, String dataType, String
comment, String... classificationNames) {
+ AtlasEntity ret = new AtlasEntity(SampleAppConstants.COLUMN_TYPE);
+
+ ret.setAttribute(ATTR_NAME, name);
+ ret.setAttribute(REFERENCEABLE_ATTRIBUTE_NAME, name +
METADATA_NAMESPACE_SUFFIX);
+ ret.setAttribute(ATTR_DATA_TYPE, dataType);
+ ret.setAttribute(ATTR_COMMENT, comment);
+
+ ret.setClassifications(toAtlasClassifications(classificationNames));
+
+ return ret;
+ }
+
+ private List<AtlasClassification> toAtlasClassifications(String[]
classificationNames) {
+ List<AtlasClassification> ret = new ArrayList<>();
+
+ if (classificationNames != null) {
+ for (String classificationName : classificationNames) {
+ ret.add(new AtlasClassification(classificationName));
+ }
+ }
+
+ return ret;
+ }
+
+ private AtlasEntityHeader createEntity(AtlasEntityWithExtInfo
atlasEntityWithExtInfo) {
+ EntityMutationResponse entity;
+
+ try {
+ entity = client.createEntity(atlasEntityWithExtInfo);
+
+ if (entity != null &&
entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE) != null) {
+ List<AtlasEntityHeader> list =
entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE);
+
+ if (list.size() > 0) {
+ return
entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).get(0);
+ }
+ }
+ } catch (AtlasServiceException e) {
+ System.out.println("failed in create entity");
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+ private AtlasEntity createDatabaseEntity(String dbName) {
+ AtlasEntity hiveDBInstance = createHiveDBInstance(dbName);
+ AtlasEntityHeader entityHeader = createEntity(new
AtlasEntityWithExtInfo(hiveDBInstance));
+
+ if (entityHeader != null && entityHeader.getGuid() != null) {
+ hiveDBInstance.setGuid(entityHeader.getGuid());
+ }
+
+ return hiveDBInstance;
+ }
+
+ protected AtlasEntity createHiveDBInstance(String dbName) {
+ AtlasEntity entity = new AtlasEntity(SampleAppConstants.DATABASE_TYPE);
+
+ entity.setAttribute(ATTR_NAME, dbName);
+ entity.setAttribute(ATTR_DESCRIPTION, "employee database");
+ entity.setAttribute(METADATA_NAMESPACE_SUFFIX, "employeeCluster");
+ entity.setAttribute(REFERENCEABLE_ATTRIBUTE_NAME, dbName +
METADATA_NAMESPACE_SUFFIX);
+ entity.setAttribute(ATTR_OWNER, "user");
+ entity.setAttribute(ATTR_LOCATION_URI, "/tmp");
+ entity.setAttribute(ATTR_CREATE_TIME, 1000);
+
+ return entity;
+ }
+
+ private AtlasEntity createHiveTable(AtlasEntity database, String
tableName, String tableType, List<AtlasEntity> columns, String...
classificationNames) throws Exception {
+ AtlasEntityWithExtInfo entityWithExtInfo = new
AtlasEntityWithExtInfo();
+
+ AtlasEntity hiveTableInstance = createHiveTable(database, tableName,
tableType, classificationNames);
+ entityWithExtInfo.setEntity(hiveTableInstance);
+ hiveTableInstance.setRelationshipAttribute(ATTR_COLUMNS,
toAtlasRelatedObjectIds(columns));
+
+ for (AtlasEntity column : columns) {
+ column.setRelationshipAttribute(ATTR_TABLE,
toAtlasRelatedObjectId(hiveTableInstance));
+ entityWithExtInfo.addReferredEntity(column);
+ }
+
+ AtlasEntityHeader createdHeader = createEntity(entityWithExtInfo);
+
+ if (createdHeader != null && createdHeader.getGuid() != null) {
+ hiveTableInstance.setGuid(createdHeader.getGuid());
+ }
+
+ return hiveTableInstance;
+ }
+
+ private AtlasEntity createHiveTable(AtlasEntity database, String
tableName, String tableType, String... classificationNames) throws Exception {
+ AtlasEntity table = new AtlasEntity(SampleAppConstants.TABLE_TYPE);
+
+ table.setAttribute(ATTR_NAME, tableName);
+ table.setAttribute(REFERENCEABLE_ATTRIBUTE_NAME,
database.getAttribute(ATTR_NAME) + "." + tableName + METADATA_NAMESPACE_SUFFIX);
+ table.setAttribute(ATTR_TABLE_TYPE, tableType);
+ table.setRelationshipAttribute(ATTR_DB,
AtlasTypeUtil.getAtlasRelatedObjectId(database, TABLE_DATABASE_TYPE));
+
+ table.setAttribute(ATTR_DESCRIPTION, "emp table");
+ table.setAttribute(ATTR_LAST_ACCESS_TIME, "2014-07-11T08:00:00.000Z");
+ table.setAttribute(ATTR_LEVEL, 2);
+ table.setAttribute(ATTR_COMPRESSED, false);
+ table.setClassifications(toAtlasClassifications(classificationNames));
+
+ AtlasStruct serde1 = new AtlasStruct(STRUCT_TYPE_SERDE);
+
+ serde1.setAttribute(ATTR_NAME, "serde1");
+ serde1.setAttribute(ATTR_SERDE, "serde1");
+ table.setAttribute(ATTR_SERDE1, serde1);
+
+ AtlasStruct serde2 = new AtlasStruct(STRUCT_TYPE_SERDE);
+ serde2.setAttribute(ATTR_NAME, "serde2");
+ serde2.setAttribute(ATTR_SERDE, "serde2");
+ table.setAttribute(ATTR_SERDE2, serde2);
+
+ return table;
+ }
+}
\ No newline at end of file
diff --git
a/atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/GlossaryExample.java
b/atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/GlossaryExample.java
new file mode 100644
index 0000000..a49b8e8
--- /dev/null
+++
b/atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/GlossaryExample.java
@@ -0,0 +1,112 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.atlas.examples.sampleapp;
+
+import org.apache.atlas.AtlasClientV2;
+import org.apache.atlas.model.glossary.AtlasGlossary;
+import org.apache.atlas.model.glossary.AtlasGlossary.AtlasGlossaryExtInfo;
+import org.apache.atlas.model.glossary.AtlasGlossaryCategory;
+import org.apache.atlas.model.glossary.AtlasGlossaryTerm;
+import org.apache.atlas.model.glossary.relations.AtlasGlossaryHeader;
+
+public class GlossaryExample {
+ private static final String GLOSSARY_NAME = "EmployeeCountry";
+
+ private final AtlasClientV2 client;
+ private AtlasGlossary empGlossary;
+ private AtlasGlossaryTerm empSalaryTerm;
+ private AtlasGlossaryCategory empCompanyCategory;
+
+ GlossaryExample(AtlasClientV2 client) {
+ this.client = client;
+ }
+
+ public void createGlossary() throws Exception {
+ AtlasGlossary glossary = new AtlasGlossary();
+
+ glossary.setName(GLOSSARY_NAME);
+ glossary.setLanguage("English");
+ glossary.setShortDescription("This is a test Glossary");
+
+ empGlossary = client.createGlossary(glossary);
+ }
+
+ public void getGlossaryDetail() throws Exception {
+ AtlasGlossaryExtInfo extInfo =
client.getGlossaryExtInfo(empGlossary.getGuid());
+
+ assert (extInfo != null);
+
+ System.out.println("extra info of Glossary is :- " + extInfo.getGuid()
+ " name is :- " + extInfo.getName() + " language is :- " +
extInfo.getLanguage());
+ }
+
+ public void createGlossaryTerm() throws Exception {
+ if (empSalaryTerm != null) {
+ System.out.println("EmpSalaryTerm: term already exists");
+ return;
+ }
+
+ AtlasGlossaryHeader glossary = new AtlasGlossaryHeader();
+ AtlasGlossaryTerm term = new AtlasGlossaryTerm();
+
+ glossary.setGlossaryGuid(empGlossary.getGuid());
+ glossary.setDisplayText(empGlossary.getName());
+
+ term.setAnchor(glossary);
+ term.setName("EmpSalaryTerm");
+
+ empSalaryTerm = client.createGlossaryTerm(term);
+
+ if (empSalaryTerm != null) {
+ System.out.println("Created term for Employee Salary: " +
empSalaryTerm);
+ }
+ }
+
+ public void createGlossaryCategory() throws Exception {
+ if (empCompanyCategory != null) {
+ System.out.println("EmpSalaryCategory: category already exists");
+ return;
+ }
+
+ AtlasGlossaryHeader glossary = new AtlasGlossaryHeader();
+ AtlasGlossaryCategory category = new AtlasGlossaryCategory();
+
+ glossary.setGlossaryGuid(empGlossary.getGuid());
+ glossary.setDisplayText(empGlossary.getName());
+
+ category.setAnchor(glossary);
+ category.setName("EmpSalaryCategory");
+
+ empCompanyCategory = client.createGlossaryCategory(category);
+
+ if (empCompanyCategory != null) {
+ System.out.println("Created Category for Employee Category :- " +
empCompanyCategory);
+ }
+ }
+
+ public void deleteGlossary() throws Exception {
+ if (empGlossary != null) {
+ client.deleteGlossaryByGuid(empGlossary.getGuid());
+
+ System.out.println("empGlossary is not present. Skipping the
delete operation.");
+ }
+
+ empGlossary = null;
+ empSalaryTerm = null;
+ empCompanyCategory = null;
+ }
+}
diff --git
a/atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/LineageExample.java
b/atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/LineageExample.java
new file mode 100644
index 0000000..d923965
--- /dev/null
+++
b/atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/LineageExample.java
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.atlas.examples.sampleapp;
+
+import org.apache.atlas.AtlasClientV2;
+import org.apache.atlas.AtlasServiceException;
+import org.apache.atlas.model.instance.AtlasEntityHeader;
+import org.apache.atlas.model.lineage.AtlasLineageInfo;
+
+import java.util.Map;
+import java.util.Set;
+
+public class LineageExample {
+ private AtlasClientV2 atlasClient;
+
+ LineageExample(AtlasClientV2 atlasClient) {
+ this.atlasClient = atlasClient;
+ }
+
+ public void lineage(String guid) throws AtlasServiceException {
+ AtlasLineageInfo lineageInfo =
atlasClient.getLineageInfo(guid, AtlasLineageInfo.LineageDirection.BOTH, 0);
+ Set<AtlasLineageInfo.LineageRelation> relations =
lineageInfo.getRelations();
+ Map<String, AtlasEntityHeader> guidEntityMap =
lineageInfo.getGuidEntityMap();
+
+ for (AtlasLineageInfo.LineageRelation relation : relations) {
+ AtlasEntityHeader fromEntity =
guidEntityMap.get(relation.getFromEntityId());
+ AtlasEntityHeader toEntity =
guidEntityMap.get(relation.getToEntityId());
+
+ System.out.println(fromEntity.getDisplayText() + "(" +
fromEntity.getTypeName() + ") -> " +
+ toEntity.getDisplayText() + "(" +
toEntity.getTypeName() + ")");
+ }
+ }
+}
\ No newline at end of file
diff --git
a/atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/SampleApp.java
b/atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/SampleApp.java
new file mode 100644
index 0000000..5ef6a90
--- /dev/null
+++
b/atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/SampleApp.java
@@ -0,0 +1,151 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.atlas.examples.sampleapp;
+
+import org.apache.atlas.AtlasClientV2;
+import org.apache.atlas.AtlasException;
+import org.apache.atlas.model.instance.AtlasEntity;
+import org.apache.atlas.utils.AuthenticationUtil;
+
+import java.util.Scanner;
+
+public class SampleApp {
+ private AtlasClientV2 client;
+
+ SampleApp(String[] atlasServerUrls, String[] basicAuthUsernamePassword) {
+ client = new AtlasClientV2(atlasServerUrls, basicAuthUsernamePassword);
+ }
+
+ SampleApp(String[] atlasServerUrls) throws AtlasException {
+ client = new AtlasClientV2(atlasServerUrls);
+ }
+
+ public static void main(String[] args) throws Exception {
+ String[] basicAuthUsernamePassword = null;
+ String[] atlasServerUrls = null;
+ SampleApp sampleApp = null;
+
+ try {
+ atlasServerUrls = getServerUrl();
+
+ if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
+ basicAuthUsernamePassword = getUserInput();
+ sampleApp = new SampleApp(atlasServerUrls,
basicAuthUsernamePassword);
+ } else {
+ sampleApp = new SampleApp(atlasServerUrls);
+ }
+
+ // TypeDef Examples
+ TypeDefExample typeDefExample = new
TypeDefExample(sampleApp.getClient());
+
+ typeDefExample.createTypeDefinitions();
+ typeDefExample.printTypeDefinitions();
+
+ // Entity Examples
+ EntityExample entityExample = new
EntityExample(sampleApp.getClient());
+
+ entityExample.createEntities();
+
+ AtlasEntity createdEntity = entityExample.getTableEntity();
+
+ entityExample.getEntityByGuid(createdEntity.getGuid());
+
+ // Lineage Examples
+ sampleApp.lineageExample(createdEntity.getGuid());
+
+ // Discovery/Search Examples
+ sampleApp.discoveryExample(createdEntity);
+
+ // Glossary Examples
+ sampleApp.glossaryExample();
+
+ entityExample.deleteEntities();
+
+ typeDefExample.removeTypeDefinitions();
+ } finally {
+ if (sampleApp != null && sampleApp.getClient() != null) {
+ sampleApp.getClient().close();
+ }
+ }
+ }
+
+ public AtlasClientV2 getClient() {
+ return client;
+ }
+
+ private void lineageExample(String entityGuid) throws Exception {
+ LineageExample lineageExample = new LineageExample(client);
+
+ lineageExample.lineage(entityGuid);
+ }
+
+ private void discoveryExample(AtlasEntity entity) {
+ DiscoveryExample discoveryExample = new DiscoveryExample(client);
+
+ discoveryExample.testSearch();
+ discoveryExample.quickSearch(entity.getTypeName());
+ discoveryExample.basicSearch(entity.getTypeName(),
SampleAppConstants.METRIC_CLASSIFICATION,
(String)entity.getAttribute(SampleAppConstants.ATTR_NAME));
+ }
+
+ private void glossaryExample() throws Exception {
+ GlossaryExample glossaryExample = new GlossaryExample(client);
+
+ glossaryExample.createGlossary();
+ glossaryExample.createGlossaryTerm();
+ glossaryExample.getGlossaryDetail();
+ glossaryExample.createGlossaryCategory();
+ glossaryExample.deleteGlossary();
+ }
+
+ private static String[] getUserInput() {
+ String username = null;
+ String password = null;
+
+ try {
+ Scanner scanner = new Scanner(System.in);
+
+ System.out.println("Enter username for atlas :- ");
+ username = scanner.nextLine();
+
+ System.out.println("Enter password for atlas :- ");
+ password = scanner.nextLine();
+ } catch (Exception e) {
+ System.out.print("Error while reading user input");
+ System.exit(1);
+ }
+
+ return new String[] { username, password };
+ }
+
+ private static String[] getServerUrl() {
+ String atlasServerUrl = null;
+
+ try {
+ Scanner scanner = new Scanner(System.in);
+
+ System.out.println("Enter url for Atlas server :- ");
+
+ atlasServerUrl = scanner.nextLine();
+ } catch (Exception e) {
+ System.out.print("Error while reading user input");
+ System.exit(1);
+ }
+
+ return new String[] { atlasServerUrl };
+ }
+}
\ No newline at end of file
diff --git
a/atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/SampleAppConstants.java
b/atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/SampleAppConstants.java
new file mode 100644
index 0000000..d6f113a
--- /dev/null
+++
b/atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/SampleAppConstants.java
@@ -0,0 +1,75 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.atlas.examples.sampleapp;
+
+public final class SampleAppConstants {
+ public static final String ATTR_NAME = "name";
+ public static final String ATTR_DESCRIPTION = "description";
+ public static final String ATTR_CREATE_TIME = "createTime";
+ public static final String ATTR_OWNER = "owner";
+ public static final String ATTR_TABLE_TYPE = "tableType";
+ public static final String ATTR_LAST_ACCESS_TIME = "lastAccessTime";
+ public static final String ATTR_RANDOM_TABLE = "randomTable";
+ public static final String ATTR_TEMPORARY = "temporary";
+ public static final String ATTR_DATA_TYPE = "dataType";
+ public static final String ATTR_COMMENT = "comment";
+ public static final String ATTR_LOCATION_URI = "locationUri";
+ public static final String ATTR_USERNAME = "userName";
+ public static final String ATTR_START_TIME = "startTime";
+ public static final String ATTR_END_TIME = "endTime";
+ public static final String ATTR_QUERY_TEXT = "queryText";
+ public static final String ATTR_QUERY_PLAN = "queryPlan";
+ public static final String ATTR_QUERY_ID = "queryId";
+ public static final String ATTR_QUERY_GRAPH = "queryGraph";
+ public static final String ATTR_OPERATION_TYPE = "operationType";
+ public static final String ATTR_LEVEL = "level";
+ public static final String ATTR_COMPRESSED = "compressed";
+ public static final String ATTR_SERDE = "serde";
+ public static final String ATTR_SERDE1 = "serde1";
+ public static final String ATTR_SERDE2 = "serde2";
+ public static final String ATTR_ATTR1 = "attr1";
+ public static final String ATTR_ATTR2 = "attr2";
+ public static final String ATTR_ATTR8 = "attr8";
+ public static final String ATTR_ATTR11 = "attr11";
+ public static final String ATTR_ATTR18 = "attr88";
+ public static final String ATTR_INPUTS = "inputs";
+ public static final String ATTR_OUTPUTS = "outputs";
+ public static final String ATTR_DB = "db";
+ public static final String ATTR_TABLE = "table";
+ public static final String ATTR_COLUMNS = "columns";
+
+ public static final String ENTITY_TYPE_DATASET = "DataSet";
+ public static final String ENTITY_TYPE_PROCESS = "Process";
+
+ public static final String PII_TAG = "sample_pii_Tag";
+ public static final String FINANCE_TAG =
"sample_finance_Tag";
+ public static final String CLASSIFICATION = "classification";
+ public static final String METRIC_CLASSIFICATION = "Metric";
+
+ public static final String DATABASE_TYPE = "sample_db_type";
+ public static final String PROCESS_TYPE =
"sample_process_type";
+ public static final String TABLE_TYPE = "sample_table_type";
+ public static final String COLUMN_TYPE =
"sample_column_type";
+
+ public static final String TABLE_DATABASE_TYPE = "sample_Table_DB";
+ public static final String TABLE_COLUMNS_TYPE =
"sample_Table_Columns";
+ public static final String ENUM_TABLE_TYPE = "tableType";
+ public static final String BUSINESS_METADATA_TYPE = "bmWithAllTypes";
+ public static final String BUSINESS_METADATA_TYPE_MV = "bmWithAllTypesMV";
+ public static final String STRUCT_TYPE_SERDE = "serdeType";
+}
diff --git
a/atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/TypeDefExample.java
b/atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/TypeDefExample.java
new file mode 100644
index 0000000..01c5b31
--- /dev/null
+++
b/atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/TypeDefExample.java
@@ -0,0 +1,274 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.atlas.examples.sampleapp;
+
+import com.sun.jersey.core.util.MultivaluedMapImpl;
+import org.apache.atlas.AtlasClientV2;
+import org.apache.atlas.AtlasServiceException;
+import org.apache.atlas.model.SearchFilter;
+import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
+import org.apache.atlas.model.typedef.AtlasBusinessMetadataDef;
+import org.apache.atlas.model.typedef.AtlasClassificationDef;
+import org.apache.atlas.model.typedef.AtlasEntityDef;
+import org.apache.atlas.model.typedef.AtlasEnumDef;
+import org.apache.atlas.model.typedef.AtlasRelationshipDef;
+import org.apache.atlas.model.typedef.AtlasStructDef;
+import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
+import org.apache.atlas.model.typedef.AtlasTypesDef;
+import org.apache.atlas.type.AtlasTypeUtil;
+
+import javax.ws.rs.core.MultivaluedMap;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.atlas.examples.sampleapp.SampleAppConstants.*;
+import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.*;
+import static
org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory.AGGREGATION;
+import static
org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory.COMPOSITION;
+import static
org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality.SET;
+import static
org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE;
+import static org.apache.atlas.type.AtlasTypeUtil.createBusinessMetadataDef;
+import static org.apache.atlas.type.AtlasTypeUtil.createOptionalAttrDef;
+import static org.apache.atlas.type.AtlasTypeUtil.createRelationshipEndDef;
+import static org.apache.atlas.type.AtlasTypeUtil.createRelationshipTypeDef;
+import static org.apache.atlas.type.AtlasTypeUtil.createTraitTypeDef;
+
+public class TypeDefExample {
+ private static final String[] SAMPLE_APP_TYPES = {
+ SampleAppConstants.DATABASE_TYPE,
+ SampleAppConstants.TABLE_TYPE,
+ SampleAppConstants.COLUMN_TYPE,
+ SampleAppConstants.PROCESS_TYPE,
+ SampleAppConstants.PII_TAG,
+ SampleAppConstants.CLASSIFICATION,
+ SampleAppConstants.FINANCE_TAG,
+ SampleAppConstants.METRIC_CLASSIFICATION
+ };
+
+ private final AtlasClientV2 client;
+ private AtlasTypesDef typesDef;
+
+ TypeDefExample(AtlasClientV2 client) {
+ this.client = client;
+ }
+
+ public void createTypeDefinitions() throws Exception {
+ AtlasEntityDef databaseDef = createDatabaseDef();
+ AtlasEntityDef tableDef = createTableDef();
+ AtlasEntityDef columnDef = createColumnDef();
+ AtlasEntityDef processDef = createProcessDef();
+ AtlasStructDef serDeDef = createSerDeDef();
+ AtlasEnumDef tableTypeDef = createTableTypeEnumDef();
+
+ List<AtlasClassificationDef> classificationDefs =
createClassificationDefs();
+ List<AtlasBusinessMetadataDef> businessMetadataDef =
createBusinessMetadataDefs();
+ List<AtlasRelationshipDef> relationshipDefs =
createAtlasRelationshipDef();
+
+ AtlasTypesDef typesDef = new
AtlasTypesDef(Collections.singletonList(tableTypeDef),
+
Collections.singletonList(serDeDef),
+ classificationDefs,
+ Arrays.asList(databaseDef,
tableDef, columnDef, processDef),
+ relationshipDefs,
+ businessMetadataDef);
+
+ this.typesDef = batchCreateTypes(typesDef);
+ }
+
+ public void printTypeDefinitions() throws AtlasServiceException {
+ for (String typeName : SAMPLE_APP_TYPES) {
+ MultivaluedMap<String, String> searchParams = new
MultivaluedMapImpl();
+
+ searchParams.add(SearchFilter.PARAM_NAME, typeName);
+
+ SearchFilter searchFilter = new SearchFilter(searchParams);
+
+ AtlasTypesDef typesDef = client.getAllTypeDefs(searchFilter);
+
+ assert (!typesDef.isEmpty());
+
+ System.out.println("Created type [" + typeName + "]");
+ }
+ }
+
+ public void removeTypeDefinitions() throws AtlasServiceException {
+ if (typesDef != null) {
+ client.deleteAtlasTypeDefs(typesDef);
+
+ typesDef = null;
+
+ System.out.println("Deleted TypeDef successfully!");
+ }
+ }
+
+ private AtlasEntityDef createDatabaseDef() {
+ return
AtlasTypeUtil.createClassTypeDef(SampleAppConstants.DATABASE_TYPE,
+
Collections.singleton(ENTITY_TYPE_DATASET),
+
AtlasTypeUtil.createOptionalAttrDef("locationUri", "string"),
+
AtlasTypeUtil.createOptionalAttrDef(ATTR_CREATE_TIME, "long"),
+ new
AtlasAttributeDef(ATTR_RANDOM_TABLE,
+
AtlasBaseTypeDef.getArrayTypeName(SampleAppConstants.TABLE_TYPE),
+ true,
AtlasAttributeDef.Cardinality.SET));
+ }
+
+ private AtlasEntityDef createTableDef() {
+ return AtlasTypeUtil.createClassTypeDef(SampleAppConstants.TABLE_TYPE,
+
Collections.singleton(ENTITY_TYPE_DATASET),
+
createOptionalAttrDef(ATTR_CREATE_TIME, "long"),
+
createOptionalAttrDef(ATTR_LAST_ACCESS_TIME, "date"),
+
createOptionalAttrDef(ATTR_TEMPORARY, "boolean"),
+
createOptionalAttrDef(ATTR_TABLE_TYPE, ENUM_TABLE_TYPE),
+
createOptionalAttrDef(ATTR_SERDE1, STRUCT_TYPE_SERDE),
+
createOptionalAttrDef(ATTR_SERDE2, STRUCT_TYPE_SERDE));
+ }
+
+ private AtlasEntityDef createColumnDef() {
+ return AtlasTypeUtil.createClassTypeDef(SampleAppConstants.COLUMN_TYPE,
+
Collections.singleton(ENTITY_TYPE_DATASET),
+
AtlasTypeUtil.createOptionalAttrDef(ATTR_DATA_TYPE, "string"),
+
AtlasTypeUtil.createOptionalAttrDef(ATTR_COMMENT, "string"));
+ }
+
+ private AtlasEntityDef createProcessDef() {
+ return
AtlasTypeUtil.createClassTypeDef(SampleAppConstants.PROCESS_TYPE,
+
Collections.singleton(ENTITY_TYPE_PROCESS),
+
AtlasTypeUtil.createOptionalAttrDef(ATTR_USERNAME, "string"),
+
AtlasTypeUtil.createOptionalAttrDef(ATTR_START_TIME, "long"),
+
AtlasTypeUtil.createOptionalAttrDef(ATTR_END_TIME, "long"),
+
AtlasTypeUtil.createRequiredAttrDef(ATTR_QUERY_TEXT, "string"),
+
AtlasTypeUtil.createRequiredAttrDef(ATTR_QUERY_PLAN, "string"),
+
AtlasTypeUtil.createRequiredAttrDef(ATTR_QUERY_ID, "string"),
+
AtlasTypeUtil.createRequiredAttrDef(ATTR_QUERY_GRAPH, "string"));
+ }
+
+ private AtlasStructDef createSerDeDef() {
+ return
AtlasTypeUtil.createStructTypeDef(SampleAppConstants.STRUCT_TYPE_SERDE,
+
AtlasTypeUtil.createRequiredAttrDef(SampleAppConstants.ATTR_NAME, "string"),
+
AtlasTypeUtil.createRequiredAttrDef(ATTR_SERDE, "string"));
+ }
+
+ private AtlasEnumDef createTableTypeEnumDef() {
+ return new AtlasEnumDef(SampleAppConstants.ENUM_TABLE_TYPE,
+ SampleAppConstants.ATTR_DESCRIPTION,
+ Arrays.asList(new
AtlasEnumDef.AtlasEnumElementDef("MANAGED", null, 1),
+ new
AtlasEnumDef.AtlasEnumElementDef("EXTERNAL", null, 2)));
+ }
+
+ private List<AtlasClassificationDef> createClassificationDefs() {
+ AtlasClassificationDef classification =
createTraitTypeDef(SampleAppConstants.CLASSIFICATION,
Collections.<String>emptySet(), AtlasTypeUtil.createRequiredAttrDef("tag",
"string"));
+ AtlasClassificationDef pii =
createTraitTypeDef(SampleAppConstants.PII_TAG, Collections.<String>emptySet());
+ AtlasClassificationDef finance =
createTraitTypeDef(SampleAppConstants.FINANCE_TAG,
Collections.<String>emptySet());
+ AtlasClassificationDef metric =
createTraitTypeDef(SampleAppConstants.METRIC_CLASSIFICATION,
Collections.emptySet());
+
+ return Arrays.asList(classification, pii, finance, metric);
+ }
+
+ private List<AtlasBusinessMetadataDef> createBusinessMetadataDefs() {
+ String description = "description";
+
+ Map<String, String> options = new HashMap<>();
+
+ options.put("maxStrLength", "20");
+ options.put("applicableEntityTypes", "[\"" +
SampleAppConstants.DATABASE_TYPE + "\",\"" + SampleAppConstants.TABLE_TYPE +
"\"]");
+
+ AtlasBusinessMetadataDef bmWithAllTypes =
createBusinessMetadataDef(SampleAppConstants.BUSINESS_METADATA_TYPE,
+
description,
+
"1.0",
+
createOptionalAttrDef(ATTR_ATTR1, ATLAS_TYPE_BOOLEAN, options, description),
+
createOptionalAttrDef(ATTR_ATTR2, ATLAS_TYPE_BYTE, options, description),
+
createOptionalAttrDef(ATTR_ATTR8, ATLAS_TYPE_STRING, options, description));
+
+ AtlasBusinessMetadataDef bmWithAllTypesMV =
createBusinessMetadataDef(SampleAppConstants.BUSINESS_METADATA_TYPE_MV,
+
description,
+
"1.0",
+
createOptionalAttrDef(ATTR_ATTR11, "array<boolean>", options, description),
+
createOptionalAttrDef(ATTR_ATTR18, "array<string>", options, description));
+
+ return Arrays.asList(bmWithAllTypes, bmWithAllTypesMV);
+ }
+
+ private List<AtlasRelationshipDef> createAtlasRelationshipDef() {
+ AtlasRelationshipDef dbTablesDef =
createRelationshipTypeDef(SampleAppConstants.TABLE_DATABASE_TYPE,
SampleAppConstants.TABLE_DATABASE_TYPE,
+ "1.0",
AGGREGATION, AtlasRelationshipDef.PropagateTags.NONE,
+
createRelationshipEndDef(SampleAppConstants.TABLE_TYPE, "db", SINGLE, false),
+
createRelationshipEndDef(SampleAppConstants.DATABASE_TYPE, "tables", SET,
true));
+
+ AtlasRelationshipDef tableColumnsDef =
createRelationshipTypeDef(SampleAppConstants.TABLE_COLUMNS_TYPE,
SampleAppConstants.TABLE_COLUMNS_TYPE,
+
"1.0", COMPOSITION, AtlasRelationshipDef.PropagateTags.NONE,
+
createRelationshipEndDef(SampleAppConstants.TABLE_TYPE, "columns", SET, true),
+
createRelationshipEndDef(SampleAppConstants.COLUMN_TYPE, "table", SINGLE,
false));
+
+ return Arrays.asList(dbTablesDef, tableColumnsDef);
+ }
+
+ private AtlasTypesDef batchCreateTypes(AtlasTypesDef typesDef) throws
AtlasServiceException {
+ AtlasTypesDef typesToCreate = new AtlasTypesDef();
+
+ for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) {
+ if (client.typeWithNameExists(enumDef.getName())) {
+ System.out.println("Type " + enumDef.getName() + " already
exists. Skipping");
+ } else {
+ typesToCreate.getEnumDefs().add(enumDef);
+ }
+ }
+
+ for (AtlasStructDef structDef : typesDef.getStructDefs()) {
+ if (client.typeWithNameExists(structDef.getName())) {
+ System.out.println("Type " + structDef.getName() + " already
exists. Skipping");
+ } else {
+ typesToCreate.getStructDefs().add(structDef);
+ }
+ }
+
+ for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
+ if (client.typeWithNameExists(entityDef.getName())) {
+ System.out.println("Type " + entityDef.getName() + " already
exists. Skipping");
+ } else {
+ typesToCreate.getEntityDefs().add(entityDef);
+ }
+ }
+
+ for (AtlasClassificationDef classificationDef :
typesDef.getClassificationDefs()) {
+ if (client.typeWithNameExists(classificationDef.getName())) {
+ System.out.println("Type " + classificationDef.getName() + "
already exists. Skipping");
+ } else {
+ typesToCreate.getClassificationDefs().add(classificationDef);
+ }
+ }
+
+ for (AtlasRelationshipDef relationshipDef :
typesDef.getRelationshipDefs()) {
+ if (client.typeWithNameExists(relationshipDef.getName())) {
+ System.out.println("Type " + relationshipDef.getName() + "
already exists. Skipping");
+ } else {
+ typesToCreate.getRelationshipDefs().add(relationshipDef);
+ }
+ }
+
+ for (AtlasBusinessMetadataDef businessMetadataDef :
typesDef.getBusinessMetadataDefs()) {
+ if (client.typeWithNameExists(businessMetadataDef.getName())) {
+ System.out.println("Type " + businessMetadataDef.getName() + "
already exists. Skipping");
+ } else {
+
typesToCreate.getBusinessMetadataDefs().add(businessMetadataDef);
+ }
+ }
+
+ return client.createAtlasTypeDefs(typesToCreate);
+ }
+}
\ No newline at end of file
diff --git
a/atlas-examples/sample-app/src/main/resources/atlas-application.properties
b/atlas-examples/sample-app/src/main/resources/atlas-application.properties
new file mode 100644
index 0000000..d24c663
--- /dev/null
+++ b/atlas-examples/sample-app/src/main/resources/atlas-application.properties
@@ -0,0 +1,25 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+######### Security Properties #########
+
+# SSL config
+atlas.enableTLS=false
+
+######### Server Properties #########
+atlas.rest.address=http://localhost:31000
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 5e0442a..1223f50 100644
--- a/pom.xml
+++ b/pom.xml
@@ -806,6 +806,7 @@
<module>addons/impala-bridge</module>
<module>distro</module>
+ <module>atlas-examples</module>
</modules>
<repositories>