You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ma...@apache.org on 2020/08/13 15:18:44 UTC
[atlas] branch branch-2.0 updated (3b553e1 -> 17e0c06)
This is an automated email from the ASF dual-hosted git repository.
madhan pushed a change to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/atlas.git.
from 3b553e1 ATLAS-3912: moved classes from intg to repository or common module
new 4b350f8 ATLAS-3875: adding sample client change
new 17e0c06 ATLAS-3875: updated sample client to improve logging
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
{client/client-v2 => atlas-examples}/pom.xml | 22 +-
atlas-examples/sample-app/README.md | 13 +
.../sample-app}/pom.xml | 75 +++---
.../atlas/examples/sampleapp/DiscoveryExample.java | 89 +++++++
.../atlas/examples/sampleapp/EntityExample.java | 277 +++++++++++++++++++++
.../atlas/examples/sampleapp/GlossaryExample.java | 112 +++++++++
.../atlas/examples/sampleapp/LineageExample.java | 48 ++++
.../apache/atlas/examples/sampleapp/SampleApp.java | 144 +++++++++++
.../examples/sampleapp/SampleAppConstants.java | 75 ++++++
.../atlas/examples/sampleapp/TypeDefExample.java | 274 ++++++++++++++++++++
.../main/resources/atlas-application.properties | 8 +-
pom.xml | 1 +
12 files changed, 1083 insertions(+), 55 deletions(-)
copy {client/client-v2 => atlas-examples}/pom.xml (70%)
create mode 100644 atlas-examples/sample-app/README.md
copy {tools/classification-updater => atlas-examples/sample-app}/pom.xml (54%)
create mode 100644 atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/DiscoveryExample.java
create mode 100644 atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/EntityExample.java
create mode 100644 atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/GlossaryExample.java
create mode 100644 atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/LineageExample.java
create mode 100644 atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/SampleApp.java
create mode 100644 atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/SampleAppConstants.java
create mode 100644 atlas-examples/sample-app/src/main/java/org/apache/atlas/examples/sampleapp/TypeDefExample.java
copy intg/src/test/resources/test.properties => atlas-examples/sample-app/src/main/resources/atlas-application.properties (83%)
[atlas] 02/02: ATLAS-3875: updated sample client to improve logging
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
madhan pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/atlas.git
commit 17e0c06829796e2481c047886d1d17e3bf8091f4
Author: jyoti0208 <sj...@gmail.com>
AuthorDate: Wed Aug 12 18:08:36 2020 -0700
ATLAS-3875: updated sample client to improve logging
Signed-off-by: Madhan Neethiraj <ma...@apache.org>
(cherry picked from commit 83e9c21f7805b7badc9390a15fd747e1e6a7f8e2)
---
.../atlas/examples/sampleapp/DiscoveryExample.java | 20 ++++-----
.../atlas/examples/sampleapp/EntityExample.java | 23 +++++-----
.../atlas/examples/sampleapp/GlossaryExample.java | 12 +++---
.../atlas/examples/sampleapp/LineageExample.java | 4 +-
.../apache/atlas/examples/sampleapp/SampleApp.java | 49 ++++++++++------------
.../examples/sampleapp/SampleAppConstants.java | 20 ++++-----
.../atlas/examples/sampleapp/TypeDefExample.java | 24 +++++------
7 files changed, 73 insertions(+), 79 deletions(-)
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
index b61e6eb..d309c9e 100644
--- 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
@@ -41,14 +41,14 @@ public class DiscoveryExample {
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);
+ SampleApp.log("DSL Query: " + dslQuery);
+ SampleApp.log(" result count: " + resultCount);
for (int i = 0; i < resultCount; i++) {
- System.out.println(" result # " + (i + 1) + ": " + entities.get(i));
+ SampleApp.log(" result # " + (i + 1) + ": " + entities.get(i));
}
} catch (Exception e) {
- System.out.println("query -: " + dslQuery + " failed");
+ SampleApp.log("query -: " + dslQuery + " failed");
}
}
}
@@ -59,11 +59,11 @@ public class DiscoveryExample {
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);
+ SampleApp.log("Quick search: query-string=" + searchString);
+ SampleApp.log(" result count: " + resultCount);
for (int i = 0; i < resultCount; i++) {
- System.out.println(" result # " + (i + 1) + ": " + entities.get(i));
+ SampleApp.log(" result # " + (i + 1) + ": " + entities.get(i));
}
} catch (AtlasServiceException e) {
e.printStackTrace();
@@ -76,11 +76,11 @@ public class DiscoveryExample {
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);
+ SampleApp.log("Basic search: typeName=" + typeName + ", classification=" + classification + ", query=" + query);
+ SampleApp.log(" result count: " + resultCount);
for (int i = 0; i < resultCount; i++) {
- System.out.println(" result # " + (i + 1) + ": " + entities.get(i));
+ SampleApp.log(" 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
index 23fc3b8..3d9d484 100644
--- 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
@@ -65,25 +65,25 @@ public class EntityExample {
if (dbEntity == null) {
dbEntity = createDatabaseEntity(DATABASE_NAME);
- System.out.println("Created database entity: typeName=" + dbEntity.getTypeName() + ", guid=" + dbEntity.getGuid());
+ SampleApp.log("Created entity: typeName=" + dbEntity.getTypeName() + ", qualifiedName=" + dbEntity.getAttribute(ATTR_QUALIFIED_NAME) + ", guid=" + dbEntity.getGuid());
}
if (tableEntityCanada == null) {
tableEntityCanada = createTableEntity(TABLE_NAME + "_CANADA");
- System.out.println("Created table entity : typeName=" + tableEntityCanada.getTypeName() + ", guid=" + tableEntityCanada.getGuid());
+ SampleApp.log("Created entity: typeName=" + tableEntityCanada.getTypeName() + ", qualifiedName=" + tableEntityCanada.getAttribute(ATTR_QUALIFIED_NAME) + ", guid=" + tableEntityCanada.getGuid());
}
if (tableEntityUS == null) {
tableEntityUS = createTableEntity(TABLE_NAME + "_US");
- System.out.println("Created table entity : typeName=" + tableEntityUS.getTypeName() + ", guid=" + tableEntityUS.getGuid());
+ SampleApp.log("Created entity: typeName=" + tableEntityUS.getTypeName() + ", qualifiedName=" + tableEntityUS.getAttribute(ATTR_QUALIFIED_NAME) + ", guid=" + tableEntityUS.getGuid());
}
if (loadProcess == null) {
loadProcess = createProcessEntity(PROCESS_NAME);
- System.out.println("Created process entity : typeName=" + loadProcess.getTypeName() + ", guid=" + loadProcess.getGuid());
+ SampleApp.log("Created entity: typeName=" + loadProcess.getTypeName() + ", qualifiedName=" + loadProcess.getAttribute(ATTR_QUALIFIED_NAME) + ", guid=" + loadProcess.getGuid());
}
}
@@ -95,22 +95,23 @@ public class EntityExample {
AtlasEntityWithExtInfo entity = client.getEntityByGuid(entityGuid);
if (entity != null) {
- System.out.println("Retrieved entity with guid=" + entityGuid + ": " + entity);
+ SampleApp.log("Retrieved entity with guid=" + entityGuid);
+ SampleApp.log(" " + entity);
}
}
public void deleteEntities() throws Exception {
client.deleteEntityByGuid(loadProcess.getGuid());
- System.out.println("Deleted entity: guid=" + loadProcess.getGuid());
+ SampleApp.log("Deleted entity: guid=" + loadProcess.getGuid());
List<String> entityGuids = Arrays.asList(tableEntityUS.getGuid(), tableEntityCanada.getGuid(), dbEntity.getGuid());
client.deleteEntitiesByGuids(entityGuids);
- System.out.println("Deleted entities:");
+ SampleApp.log("Deleted entities:");
for (String entityGuid : entityGuids) {
- System.out.println(" guid=" + entityGuid);
+ SampleApp.log(" guid=" + entityGuid);
}
}
@@ -119,14 +120,14 @@ public class EntityExample {
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);
+ SampleAppConstants.METRIC_TAG);
}
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);
+ "create table as select ", "plan", "id", "graph", SampleAppConstants.CLASSIFIED_TAG);
}
private AtlasEntityHeader createProcess(String name, String description, String user, List<AtlasEntity> inputs, List<AtlasEntity> outputs,
@@ -193,7 +194,7 @@ public class EntityExample {
}
}
} catch (AtlasServiceException e) {
- System.out.println("failed in create entity");
+ SampleApp.log("failed in create entity");
e.printStackTrace();
}
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
index a49b8e8..e4fc4ed 100644
--- 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
@@ -51,12 +51,12 @@ public class GlossaryExample {
assert (extInfo != null);
- System.out.println("extra info of Glossary is :- " + extInfo.getGuid() + " name is :- " + extInfo.getName() + " language is :- " + extInfo.getLanguage());
+ SampleApp.log("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");
+ SampleApp.log("EmpSalaryTerm: term already exists");
return;
}
@@ -72,13 +72,13 @@ public class GlossaryExample {
empSalaryTerm = client.createGlossaryTerm(term);
if (empSalaryTerm != null) {
- System.out.println("Created term for Employee Salary: " + empSalaryTerm);
+ SampleApp.log("Created term for Employee Salary: " + empSalaryTerm);
}
}
public void createGlossaryCategory() throws Exception {
if (empCompanyCategory != null) {
- System.out.println("EmpSalaryCategory: category already exists");
+ SampleApp.log("EmpSalaryCategory: category already exists");
return;
}
@@ -94,7 +94,7 @@ public class GlossaryExample {
empCompanyCategory = client.createGlossaryCategory(category);
if (empCompanyCategory != null) {
- System.out.println("Created Category for Employee Category :- " + empCompanyCategory);
+ SampleApp.log("Created Category for Employee Category :- " + empCompanyCategory);
}
}
@@ -102,7 +102,7 @@ public class GlossaryExample {
if (empGlossary != null) {
client.deleteGlossaryByGuid(empGlossary.getGuid());
- System.out.println("empGlossary is not present. Skipping the delete operation.");
+ SampleApp.log("empGlossary is not present. Skipping the delete operation.");
}
empGlossary = 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
index d923965..aba3b81 100644
--- 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
@@ -41,8 +41,8 @@ public class LineageExample {
AtlasEntityHeader fromEntity = guidEntityMap.get(relation.getFromEntityId());
AtlasEntityHeader toEntity = guidEntityMap.get(relation.getToEntityId());
- System.out.println(fromEntity.getDisplayText() + "(" + fromEntity.getTypeName() + ") -> " +
- toEntity.getDisplayText() + "(" + toEntity.getTypeName() + ")");
+ SampleApp.log(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
index 5ef6a90..f663de1 100644
--- 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
@@ -22,7 +22,7 @@ import org.apache.atlas.AtlasException;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.utils.AuthenticationUtil;
-import java.util.Scanner;
+import java.util.Date;
public class SampleApp {
private AtlasClientV2 client;
@@ -36,17 +36,17 @@ public class SampleApp {
}
public static void main(String[] args) throws Exception {
- String[] basicAuthUsernamePassword = null;
- String[] atlasServerUrls = null;
- SampleApp sampleApp = null;
+ SampleApp sampleApp = null;
try {
- atlasServerUrls = getServerUrl();
-
if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
- basicAuthUsernamePassword = getUserInput();
- sampleApp = new SampleApp(atlasServerUrls, basicAuthUsernamePassword);
+ String[] atlasServerUrls = getServerUrl();
+ String[] basicAuthUsernamePassword = getUserInput();
+
+ sampleApp = new SampleApp(atlasServerUrls, basicAuthUsernamePassword);
} else {
+ String[] atlasServerUrls = getServerUrl();
+
sampleApp = new SampleApp(atlasServerUrls);
}
@@ -75,8 +75,6 @@ public class SampleApp {
sampleApp.glossaryExample();
entityExample.deleteEntities();
-
- typeDefExample.removeTypeDefinitions();
} finally {
if (sampleApp != null && sampleApp.getClient() != null) {
sampleApp.getClient().close();
@@ -84,6 +82,10 @@ public class SampleApp {
}
}
+ public static void log(String message) {
+ System.out.println("[" + new Date() + "] " + message);
+ }
+
public AtlasClientV2 getClient() {
return client;
}
@@ -99,7 +101,7 @@ public class SampleApp {
discoveryExample.testSearch();
discoveryExample.quickSearch(entity.getTypeName());
- discoveryExample.basicSearch(entity.getTypeName(), SampleAppConstants.METRIC_CLASSIFICATION, (String)entity.getAttribute(SampleAppConstants.ATTR_NAME));
+ discoveryExample.basicSearch(entity.getTypeName(), SampleAppConstants.METRIC_TAG, (String)entity.getAttribute(SampleAppConstants.ATTR_NAME));
}
private void glossaryExample() throws Exception {
@@ -113,39 +115,30 @@ public class SampleApp {
}
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();
+ String username = System.console().readLine("Enter username: ");
+ char[] pwChar = System.console().readPassword("Enter password: ");
+ String password = (pwChar != null) ? new String(pwChar) : "";
- System.out.println("Enter password for atlas :- ");
- password = scanner.nextLine();
+ return new String[] { username, password };
} catch (Exception e) {
System.out.print("Error while reading user input");
System.exit(1);
}
- return new String[] { username, password };
+ return null; // will not reach here
}
private static String[] getServerUrl() {
- String atlasServerUrl = null;
-
try {
- Scanner scanner = new Scanner(System.in);
-
- System.out.println("Enter url for Atlas server :- ");
+ String atlasServerUrl = System.console().readLine("Enter Atlas server URL: ");
- atlasServerUrl = scanner.nextLine();
+ return new String[] { atlasServerUrl };
} catch (Exception e) {
System.out.print("Error while reading user input");
System.exit(1);
}
- return new String[] { atlasServerUrl };
+ return null; // will not reach here
}
}
\ 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
index d6f113a..4b7b44d 100644
--- 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
@@ -56,20 +56,20 @@ public final class SampleAppConstants {
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 PII_TAG = "SAMPLE_PII";
+ public static final String FINANCE_TAG = "SAMPLE_FINANCE";
+ public static final String CLASSIFIED_TAG = "SAMPLE_CLASSIFIED";
+ public static final String METRIC_TAG = "SAMPLE_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";
+ public static final String TABLE_DATABASE_TYPE = "sample_db_tables";
+ public static final String TABLE_COLUMNS_TYPE = "sample_table_columns";
+ public static final String ENUM_TABLE_TYPE = "sample_tableType";
+ public static final String BUSINESS_METADATA_TYPE = "sample_bmWithAllTypes";
+ public static final String BUSINESS_METADATA_TYPE_MV = "sample_bmWithAllTypesMV";
+ public static final String STRUCT_TYPE_SERDE = "sample_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
index 01c5b31..be89bd1 100644
--- 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
@@ -58,9 +58,9 @@ public class TypeDefExample {
SampleAppConstants.COLUMN_TYPE,
SampleAppConstants.PROCESS_TYPE,
SampleAppConstants.PII_TAG,
- SampleAppConstants.CLASSIFICATION,
+ SampleAppConstants.CLASSIFIED_TAG,
SampleAppConstants.FINANCE_TAG,
- SampleAppConstants.METRIC_CLASSIFICATION
+ SampleAppConstants.METRIC_TAG
};
private final AtlasClientV2 client;
@@ -104,7 +104,7 @@ public class TypeDefExample {
assert (!typesDef.isEmpty());
- System.out.println("Created type [" + typeName + "]");
+ SampleApp.log("Created type: " + typeName);
}
}
@@ -114,7 +114,7 @@ public class TypeDefExample {
typesDef = null;
- System.out.println("Deleted TypeDef successfully!");
+ SampleApp.log("Deleted TypesDef successfully!");
}
}
@@ -172,10 +172,10 @@ public class TypeDefExample {
}
private List<AtlasClassificationDef> createClassificationDefs() {
- AtlasClassificationDef classification = createTraitTypeDef(SampleAppConstants.CLASSIFICATION, Collections.<String>emptySet(), AtlasTypeUtil.createRequiredAttrDef("tag", "string"));
+ AtlasClassificationDef classification = createTraitTypeDef(SampleAppConstants.CLASSIFIED_TAG, 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());
+ AtlasClassificationDef metric = createTraitTypeDef(SampleAppConstants.METRIC_TAG, Collections.emptySet());
return Arrays.asList(classification, pii, finance, metric);
}
@@ -223,7 +223,7 @@ public class TypeDefExample {
for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) {
if (client.typeWithNameExists(enumDef.getName())) {
- System.out.println("Type " + enumDef.getName() + " already exists. Skipping");
+ SampleApp.log(enumDef.getName() + ": type already exists. Skipping");
} else {
typesToCreate.getEnumDefs().add(enumDef);
}
@@ -231,7 +231,7 @@ public class TypeDefExample {
for (AtlasStructDef structDef : typesDef.getStructDefs()) {
if (client.typeWithNameExists(structDef.getName())) {
- System.out.println("Type " + structDef.getName() + " already exists. Skipping");
+ SampleApp.log(structDef.getName() + ": type already exists. Skipping");
} else {
typesToCreate.getStructDefs().add(structDef);
}
@@ -239,7 +239,7 @@ public class TypeDefExample {
for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
if (client.typeWithNameExists(entityDef.getName())) {
- System.out.println("Type " + entityDef.getName() + " already exists. Skipping");
+ SampleApp.log(entityDef.getName() + ": type already exists. Skipping");
} else {
typesToCreate.getEntityDefs().add(entityDef);
}
@@ -247,7 +247,7 @@ public class TypeDefExample {
for (AtlasClassificationDef classificationDef : typesDef.getClassificationDefs()) {
if (client.typeWithNameExists(classificationDef.getName())) {
- System.out.println("Type " + classificationDef.getName() + " already exists. Skipping");
+ SampleApp.log(classificationDef.getName() + ": type already exists. Skipping");
} else {
typesToCreate.getClassificationDefs().add(classificationDef);
}
@@ -255,7 +255,7 @@ public class TypeDefExample {
for (AtlasRelationshipDef relationshipDef : typesDef.getRelationshipDefs()) {
if (client.typeWithNameExists(relationshipDef.getName())) {
- System.out.println("Type " + relationshipDef.getName() + " already exists. Skipping");
+ SampleApp.log(relationshipDef.getName() + ": type already exists. Skipping");
} else {
typesToCreate.getRelationshipDefs().add(relationshipDef);
}
@@ -263,7 +263,7 @@ public class TypeDefExample {
for (AtlasBusinessMetadataDef businessMetadataDef : typesDef.getBusinessMetadataDefs()) {
if (client.typeWithNameExists(businessMetadataDef.getName())) {
- System.out.println("Type " + businessMetadataDef.getName() + " already exists. Skipping");
+ SampleApp.log(businessMetadataDef.getName() + ": type already exists. Skipping");
} else {
typesToCreate.getBusinessMetadataDefs().add(businessMetadataDef);
}
[atlas] 01/02: ATLAS-3875: adding sample client change
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
madhan pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/atlas.git
commit 4b350f85bdf930cac815e3ba1c7ebdda0450e5e8
Author: jyoti0208 <sj...@gmail.com>
AuthorDate: Tue Aug 4 11:59:42 2020 -0400
ATLAS-3875: adding sample client change
Signed-off-by: Madhan Neethiraj <ma...@apache.org>
(cherry picked from commit b7255ec7e24f87da6f2dba47965a4e22e94c2250)
---
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..931729a
--- /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>2.2.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>atlas-examples</artifactId>
+ <packaging>pom</packaging>
+ <modules>
+ <module>sample-app</module>
+ </modules>
+
+
+</project>
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..6fc628f
--- /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>2.2.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>
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 aa586ff..2759207 100644
--- a/pom.xml
+++ b/pom.xml
@@ -805,6 +805,7 @@
<module>addons/impala-bridge</module>
<module>distro</module>
+ <module>atlas-examples</module>
</modules>
<repositories>