Commit b7255ec7 by jyoti0208 Committed by Madhan Neethiraj

ATLAS-3875: adding sample client change

parent fb374763
<?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
## 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
<?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
/**
* 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();
}
}
}
/**
* 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;
}
}
/**
* 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
/**
* 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
/**
* 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";
}
#
# 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
...@@ -806,6 +806,7 @@ ...@@ -806,6 +806,7 @@
<module>addons/impala-bridge</module> <module>addons/impala-bridge</module>
<module>distro</module> <module>distro</module>
<module>atlas-examples</module>
</modules> </modules>
<repositories> <repositories>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment