Commit 8827bfb4 by Jyoti Singh Committed by Madhan Neethiraj

ATLAS-3875: added missing APIs in AtlasClient

parent a42f0c1c
......@@ -37,10 +37,10 @@ import com.sun.jersey.multipart.MultiPart;
import com.sun.jersey.multipart.file.FileDataBodyPart;
import com.sun.jersey.multipart.file.StreamDataBodyPart;
import com.sun.jersey.multipart.impl.MultiPartWriter;
import org.apache.atlas.model.impexp.AtlasServer;
import org.apache.atlas.model.impexp.AtlasExportRequest;
import org.apache.atlas.model.impexp.AtlasImportRequest;
import org.apache.atlas.model.impexp.AtlasImportResult;
import org.apache.atlas.model.impexp.AtlasServer;
import org.apache.atlas.model.metrics.AtlasMetrics;
import org.apache.atlas.security.SecureClientUtils;
import org.apache.atlas.type.AtlasType;
......@@ -66,7 +66,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.net.ConnectException;
import java.net.URI;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
......
......@@ -741,6 +741,7 @@
<resource>
<directory>${basedir}/../addons/models/</directory>
<includes>
<include>0000-Area0/0011-glossary_model.json</include>
<include>0000-Area0/0010-base_model.json</include>
<include>1000-Hadoop/**</include>
</includes>
......
......@@ -56,4 +56,7 @@ public class TestUtils {
return System.getProperty("projectBaseDir") + "/webapp/target" ;
}
public static String getGlossaryType(){
return System.getProperty("projectBaseDir") + "/webapp/target/models/0000-Area0/0011-glossary_model.json";
}
}
......@@ -24,6 +24,8 @@ import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasClientV2;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.kafka.AtlasKafkaMessage;
import org.apache.atlas.kafka.KafkaNotification;
import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
......@@ -31,24 +33,36 @@ 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.model.typedef.*;
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.AtlasStructDef.AtlasAttributeDef.Cardinality;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef;
import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.notification.NotificationConsumer;
import org.apache.atlas.notification.NotificationInterface;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.atlas.utils.ParamChecker;
import org.apache.atlas.v1.model.instance.Id;
import org.apache.atlas.v1.model.instance.Referenceable;
import org.apache.atlas.v1.model.instance.Struct;
import org.apache.atlas.v1.model.typedef.*;
import org.apache.atlas.v1.model.typedef.EnumTypeDefinition.EnumValue;
import org.apache.atlas.notification.NotificationConsumer;
import org.apache.atlas.kafka.*;
import org.apache.atlas.v1.model.notification.EntityNotificationV1;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.atlas.v1.model.typedef.AttributeDefinition;
import org.apache.atlas.v1.model.typedef.ClassTypeDefinition;
import org.apache.atlas.v1.model.typedef.EnumTypeDefinition;
import org.apache.atlas.v1.model.typedef.EnumTypeDefinition.EnumValue;
import org.apache.atlas.v1.model.typedef.Multiplicity;
import org.apache.atlas.v1.model.typedef.StructTypeDefinition;
import org.apache.atlas.v1.model.typedef.TraitTypeDefinition;
import org.apache.atlas.v1.model.typedef.TypesDef;
import org.apache.atlas.v1.typesystem.types.utils.TypesUtil;
import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.atlas.utils.ParamChecker;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.RandomStringUtils;
import org.slf4j.Logger;
......@@ -66,6 +80,8 @@ import java.util.Map;
import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE;
import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF;
import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF;
import static org.apache.atlas.type.AtlasTypeUtil.createBusinessMetadataDef;
import static org.apache.atlas.type.AtlasTypeUtil.createOptionalAttrDef;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
......@@ -160,6 +176,22 @@ public abstract class BaseResourceIT {
}
}
for (AtlasRelationshipDef relationshipDef : typesDef.getRelationshipDefs()) {
if (atlasClientV2.typeWithNameExists(relationshipDef.getName())) {
LOG.warn("Type with name {} already exists. Skipping", relationshipDef.getName());
} else {
toCreate.getRelationshipDefs().add(relationshipDef);
}
}
for (AtlasBusinessMetadataDef businessMetadataDef : typesDef.getBusinessMetadataDefs()) {
if (atlasClientV2.typeWithNameExists(businessMetadataDef.getName())) {
LOG.warn("Type with name {} already exists. Skipping", businessMetadataDef.getName());
} else {
toCreate.getBusinessMetadataDefs().add(businessMetadataDef);
}
}
atlasClientV2.createAtlasTypeDefs(toCreate);
}
......@@ -440,11 +472,33 @@ public abstract class BaseResourceIT {
AtlasClassificationDef secTrait = AtlasTypeUtil.createTraitTypeDef(SEC_TAG, Collections.<String>emptySet());
AtlasClassificationDef financeTrait = AtlasTypeUtil.createTraitTypeDef(FINANCE_TAG, Collections.<String>emptySet());
//bussinessmetadata
String _description = "_description";
Map<String, String> options = new HashMap<>();
options.put("maxStrLength", "20");
AtlasBusinessMetadataDef bmNoApplicableTypes = createBusinessMetadataDef("bmNoApplicableTypes", _description, "1.0",
createOptionalAttrDef("attr0", "string", options, _description));
AtlasBusinessMetadataDef bmNoAttributes = createBusinessMetadataDef("bmNoAttributes", _description, "1.0", null);
options.put("applicableEntityTypes", "[\"" + DATABASE_TYPE_V2 + "\",\"" + HIVE_TABLE_TYPE_V2 + "\"]");
AtlasBusinessMetadataDef bmWithAllTypes = createBusinessMetadataDef("bmWithAllTypes", _description, "1.0",
createOptionalAttrDef("attr1", AtlasBusinessMetadataDef.ATLAS_TYPE_BOOLEAN, options, _description),
createOptionalAttrDef("attr2", AtlasBusinessMetadataDef.ATLAS_TYPE_BYTE, options, _description),
createOptionalAttrDef("attr8", AtlasBusinessMetadataDef.ATLAS_TYPE_STRING, options, _description));
AtlasBusinessMetadataDef bmWithAllTypesMV = createBusinessMetadataDef("bmWithAllTypesMV", _description, "1.0",
createOptionalAttrDef("attr11", "array<boolean>", options, _description),
createOptionalAttrDef("attr18", "array<string>", options, _description));
AtlasTypesDef typesDef = new AtlasTypesDef(Collections.singletonList(enumDef),
Collections.singletonList(structTypeDef),
Arrays.asList(classificationTrait, piiTrait, phiTrait, pciTrait, soxTrait, secTrait, financeTrait),
Arrays.asList(dbClsTypeDef, columnClsDef, tblClsDef, loadProcessClsDef));
Arrays.asList(dbClsTypeDef, columnClsDef, tblClsDef, loadProcessClsDef),
new ArrayList<>(),
Arrays.asList(bmNoApplicableTypes, bmNoAttributes, bmWithAllTypes, bmWithAllTypesMV));
batchCreateTypes(typesDef);
}
......@@ -549,6 +603,7 @@ public abstract class BaseResourceIT {
return tableInstance;
}
protected Referenceable createHiveDBInstanceBuiltIn(String dbName) {
Referenceable databaseInstance = new Referenceable(DATABASE_TYPE_BUILTIN);
......@@ -560,7 +615,6 @@ public abstract class BaseResourceIT {
return databaseInstance;
}
protected Referenceable createHiveDBInstanceV1(String dbName) {
Referenceable databaseInstance = new Referenceable(DATABASE_TYPE);
......@@ -584,7 +638,6 @@ public abstract class BaseResourceIT {
return atlasEntity;
}
public interface Predicate {
/**
......
......@@ -23,12 +23,16 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.model.discovery.AtlasQuickSearchResult;
import org.apache.atlas.model.discovery.AtlasSearchResult;
import org.apache.atlas.model.discovery.QuickSearchParameters;
import org.apache.atlas.model.discovery.SearchParameters;
import org.apache.atlas.model.impexp.AtlasImportRequest;
import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntityHeader;
import org.apache.atlas.model.instance.EntityMutationResponse;
import org.apache.atlas.model.profile.AtlasUserSavedSearch;
import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.type.AtlasTypeUtil;
......@@ -42,15 +46,18 @@ import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.fail;
public class BasicSearchIT extends BaseResourceIT {
private AtlasUserSavedSearch userSavedSearch;
@BeforeClass
@Override
......@@ -113,6 +120,13 @@ public class BasicSearchIT extends BaseResourceIT {
};
}
@DataProvider
public Object[][] attributeSearchJSONNames() {
return new String[][]{
{"search-parameters/attribute-filters"}
};
}
@Test(dataProvider = "basicSearchJSONNames")
public void testDiscoveryWithSearchParameters(String jsonFile) {
try {
......@@ -141,6 +155,137 @@ public class BasicSearchIT extends BaseResourceIT {
}
}
@Test(dataProvider = "attributeSearchJSONNames")
public void testAttributeSearch(String jsonFile) {
try {
BasicSearchParametersWithExpectation[] testExpectations =
TestResourceFileUtils.readObjectFromJson(jsonFile, BasicSearchParametersWithExpectation[].class);
assertNotNull(testExpectations);
for (BasicSearchParametersWithExpectation testExpectation : testExpectations) {
LOG.info("TestDescription :{}", testExpectation.testDescription);
LOG.info("SearchParameters :{}", testExpectation.searchParameters);
SearchParameters parameters = testExpectation.getSearchParameters();
if (parameters.getEntityFilters() == null || parameters.getEntityFilters().getAttributeName() == null) {
continue;
}
SearchParameters.FilterCriteria filterCriteria = parameters.getEntityFilters();
AtlasSearchResult searchResult = atlasClientV2.attributeSearch(parameters.getTypeName(), filterCriteria.getAttributeName(), filterCriteria.getAttributeValue(), parameters.getLimit(), parameters.getOffset());
if (testExpectation.expectedCount > 0) {
assertNotNull(searchResult.getEntities());
assertEquals(searchResult.getEntities().size(), testExpectation.expectedCount);
}
if (testExpectation.searchParameters.getSortBy() != null && !testExpectation.searchParameters.getSortBy().isEmpty()) {
assertNotNull(searchResult.getEntities());
assertEquals(searchResult.getEntities().get(0).getAttribute("name"),
"testtable_1");
}
}
} catch (IOException | AtlasServiceException e) {
fail(e.getMessage());
}
}
@Test(dataProvider = "attributeSearchJSONNames")
public void testSavedSearch(String jsonFile) {
try {
BasicSearchParametersWithExpectation[] testExpectations =
TestResourceFileUtils.readObjectFromJson(jsonFile, BasicSearchParametersWithExpectation[].class);
assertNotNull(testExpectations);
for (BasicSearchParametersWithExpectation testExpectation : testExpectations) {
LOG.info("TestDescription :{}", testExpectation.testDescription);
LOG.info("SearchParameters :{}", testExpectation.searchParameters);
SearchParameters parameters = testExpectation.getSearchParameters();
AtlasUserSavedSearch savedSearch = new AtlasUserSavedSearch();
savedSearch.setSearchType(AtlasUserSavedSearch.SavedSearchType.BASIC);
savedSearch.setName("basic_test");
savedSearch.setGuid("");
savedSearch.setSearchParameters(parameters);
savedSearch.setOwnerName("admin");
userSavedSearch = atlasClientV2.addSavedSearch(savedSearch);
assertNotNull(userSavedSearch);
List<AtlasUserSavedSearch> list = atlasClientV2.getSavedSearches("admin");
assertNotNull(list);
}
} catch (IOException | AtlasServiceException e) {
fail(e.getMessage());
}
}
@Test(dependsOnMethods = "testSavedSearch")
public void testExecuteSavedSearchByName() {
try {
AtlasSearchResult searchResult = atlasClientV2.executeSavedSearch("admin", "basic_test");
assertNotNull(searchResult);
} catch (AtlasServiceException e) {
fail(e.getMessage());
}
}
@Test(dependsOnMethods = "testSavedSearch")
public void tesUpdateSavedSearch() {
try {
userSavedSearch.setSearchType(AtlasUserSavedSearch.SavedSearchType.ADVANCED);
userSavedSearch = atlasClientV2.updateSavedSearch(userSavedSearch);
assertNotNull(userSavedSearch);
assertEquals(userSavedSearch.getSearchType(), AtlasUserSavedSearch.SavedSearchType.ADVANCED);
} catch (AtlasServiceException e) {
fail(e.getMessage());
}
}
@Test(dependsOnMethods = "tesUpdateSavedSearch")
public void testExecuteSavedSearchByGuid() {
try {
AtlasSearchResult searchResult = atlasClientV2.executeSavedSearch(userSavedSearch.getGuid());
assertNotNull(searchResult);
} catch (AtlasServiceException e) {
fail(e.getMessage());
}
}
@Test(dependsOnMethods = "testExecuteSavedSearchByGuid")
public void testDeleteSavedSearch() {
AtlasUserSavedSearch searchAfterDelete = null;
try {
atlasClientV2.deleteSavedSearch(userSavedSearch.getGuid());
searchAfterDelete = atlasClientV2.getSavedSearch("admin", "basic_test");
} catch (AtlasServiceException e) {
assertNull(searchAfterDelete);
}
}
@Test
public void testGetQuickSearch() {
try {
AtlasQuickSearchResult result = atlasClientV2.quickSearch("test", "hdfs_path", false, 2, 0);
assertNotNull(result);
List<AtlasEntityHeader> list = result.getSearchResults().getEntities();
assertEquals(list.size(), 1);
} catch (AtlasServiceException e) {
fail(e.getMessage());
}
}
@Test
public void testPostQuickSearch() {
try {
QuickSearchParameters quickSearchParameters = new QuickSearchParameters();
quickSearchParameters.setQuery("test");
quickSearchParameters.setTypeName("hdfs_path");
AtlasQuickSearchResult result = atlasClientV2.quickSearch(quickSearchParameters);
List<AtlasEntityHeader> list = result.getSearchResults().getEntities();
assertEquals(list.size(), 1);
} catch (AtlasServiceException e) {
fail(e.getMessage());
}
}
@JsonAutoDetect(getterVisibility = PUBLIC_ONLY, setterVisibility = PUBLIC_ONLY, fieldVisibility = NONE)
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
......@@ -182,4 +327,4 @@ public class BasicSearchIT extends BaseResourceIT {
this.testDescription = testDescription;
}
}
}
}
\ 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
*
* 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.
*/
package org.apache.atlas.web.integration;
import org.apache.atlas.model.instance.AtlasEntityHeader;
import org.apache.atlas.model.lineage.AtlasLineageInfo;
import org.apache.atlas.v1.model.instance.Id;
import org.apache.atlas.v1.model.instance.Referenceable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.apache.atlas.AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME;
/**
* Entity Lineage v2 Integration Tests.
*/
public class LineageClientV2IT extends DataSetLineageJerseyResourceIT {
private static final Logger LOG = LoggerFactory.getLogger(LineageClientV2IT.class);
private String salesFactTable;
private String salesMonthlyTable;
private String salesDBName;
@BeforeClass
public void setUp() throws Exception {
super.setUp();
createTypeDefinitionsV1();
setupInstances();
}
@Test
public void testGetLineageInfo() throws Exception {
String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE,
REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId();
AtlasLineageInfo inputLineageInfo = atlasClientV2.getLineageInfo(tableId, AtlasLineageInfo.LineageDirection.INPUT, 5);
Assert.assertNotNull(inputLineageInfo);
Map<String, AtlasEntityHeader> entities = inputLineageInfo.getGuidEntityMap();
Assert.assertNotNull(entities);
Set<AtlasLineageInfo.LineageRelation> relations = inputLineageInfo.getRelations();
Assert.assertNotNull(relations);
Assert.assertEquals(entities.size(), 6);
Assert.assertEquals(relations.size(), 5);
Assert.assertEquals(inputLineageInfo.getLineageDirection(), AtlasLineageInfo.LineageDirection.INPUT);
Assert.assertEquals(inputLineageInfo.getLineageDepth(), 5);
Assert.assertEquals(inputLineageInfo.getBaseEntityGuid(), tableId);
}
@Test
public void testGetLineageInfoByAttribute() throws Exception {
Map<String, String> attributeMap = new HashMap<>();
attributeMap.put("qualifiedName", salesMonthlyTable);
AtlasLineageInfo bothLineageInfo = atlasClientV2.getLineageInfo(HIVE_TABLE_TYPE, attributeMap, AtlasLineageInfo.LineageDirection.BOTH, 5);
Assert.assertNotNull(bothLineageInfo);
Map<String, AtlasEntityHeader> entities = bothLineageInfo.getGuidEntityMap();
Assert.assertNotNull(entities);
Set<AtlasLineageInfo.LineageRelation> relations = bothLineageInfo.getRelations();
Assert.assertNotNull(relations);
Assert.assertEquals(entities.size(), 6);
Assert.assertEquals(relations.size(), 5);
Assert.assertEquals(bothLineageInfo.getLineageDirection(), AtlasLineageInfo.LineageDirection.BOTH);
Assert.assertEquals(bothLineageInfo.getLineageDepth(), 5);
}
private void setupInstances() throws Exception {
salesDBName = "Sales" + randomString();
Id salesDB = database(salesDBName, "Sales Database", "John ETL", "hdfs://host:8000/apps/warehouse/sales");
List<Referenceable> salesFactColumns = Arrays.asList(column("time_id", "int", "time id"), column("product_id", "int", "product id"),
column("customer_id", "int", "customer id"),
column("sales", "double", "product id"));
salesFactTable = "sales_fact" + randomString();
Id salesFact = table(salesFactTable, "sales fact table", salesDB, "Joe", "MANAGED", salesFactColumns);
List<Referenceable> timeDimColumns = Arrays.asList(column("time_id", "int", "time id"), column("dayOfYear", "int", "day Of Year"),
column("weekDay", "int", "week Day"));
Id timeDim =
table("time_dim" + randomString(), "time dimension table", salesDB, "John Doe", "EXTERNAL",
timeDimColumns);
Id reportingDB =
database("Reporting" + randomString(), "reporting database", "Jane BI",
"hdfs://host:8000/apps/warehouse/reporting");
Id salesFactDaily =
table("sales_fact_daily_mv" + randomString(), "sales fact daily materialized view", reportingDB,
"Joe BI", "MANAGED", salesFactColumns);
loadProcess("loadSalesDaily" + randomString(), "John ETL", Arrays.asList(salesFact, timeDim),
Collections.singletonList(salesFactDaily), "create table as select ", "plan", "id", "graph");
salesMonthlyTable = "sales_fact_monthly_mv" + randomString();
Id salesFactMonthly =
table(salesMonthlyTable, "sales fact monthly materialized view", reportingDB, "Jane BI",
"MANAGED", salesFactColumns);
loadProcess("loadSalesMonthly" + randomString(), "John ETL", Collections.singletonList(salesFactDaily),
Collections.singletonList(salesFactMonthly), "create table as select ", "plan", "id", "graph");
}
}
......@@ -20,18 +20,20 @@ package org.apache.atlas.web.integration;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.apache.atlas.AtlasClientV2;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.TypeCategory;
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.AtlasStructDef.AtlasConstraintDef;
import org.apache.atlas.model.typedef.AtlasTypeDefHeader;
import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.atlas.utils.AuthenticationUtil;
......@@ -46,6 +48,7 @@ import javax.ws.rs.core.Response;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import static org.apache.atlas.AtlasErrorCode.TYPE_NAME_NOT_FOUND;
import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality;
......@@ -102,6 +105,33 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT {
for (AtlasEntityDef entityDef : typeDefinitions.getEntityDefs()) {
checkIfTypeExists(entityDef.getName());
}
for (AtlasRelationshipDef relationshipDef : typeDefinitions.getRelationshipDefs()) {
checkIfTypeExists(relationshipDef.getName());
}
for (AtlasBusinessMetadataDef businessMetadataDef : typeDefinitions.getBusinessMetadataDefs()) {
checkIfTypeExists(businessMetadataDef.getName());
}
}
@Test
public void testGetHeaders() throws Exception {
MultivaluedMap<String, String> filterParams = new MultivaluedMapImpl();
filterParams.add(SearchFilter.PARAM_TYPE, "ENTITY");
List<AtlasTypeDefHeader> headers = clientV2.getAllTypeDefHeaders(new SearchFilter(filterParams));
assertNotNull(headers);
}
@Test(dependsOnMethods = "testGetDefinition")
public void testDeleteAtlasTypeByName() throws Exception {
String typeName = "table";
boolean typeExists = atlasClientV2.typeWithNameExists(typeName);
if (typeExists) {
clientV2.deleteTypeByName(typeName);
boolean afterDelete = atlasClientV2.typeWithNameExists(typeName);
assertEquals(afterDelete, false);
}
}
@Test
......@@ -191,9 +221,21 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT {
verifyByNameAndGUID(entityDef);
}
}
if (CollectionUtils.isNotEmpty(typeDefinitions.getRelationshipDefs())) {
for (AtlasRelationshipDef relationshipDef : typeDefinitions.getRelationshipDefs()) {
verifyByNameAndGUID(relationshipDef);
}
}
if (CollectionUtils.isNotEmpty(typeDefinitions.getBusinessMetadataDefs())) {
for (AtlasBusinessMetadataDef businessMetadataDef : typeDefinitions.getBusinessMetadataDefs()) {
verifyByNameAndGUID(businessMetadataDef);
}
}
}
@Test
@Test()
public void testInvalidGets() throws Exception {
try {
AtlasEnumDef byName = clientV2.getEnumDefByName("blah");
......@@ -259,6 +301,37 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT {
"Should've returned a 404");
}
try {
AtlasRelationshipDef byName = clientV2.getRelationshipDefByName("blah");
fail("Get for invalid name should have reported a failure");
} catch (AtlasServiceException e) {
assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(),
"Should've returned a 404");
}
try {
AtlasRelationshipDef byGuid = clientV2.getRelationshipDefByGuid("blah");
fail("Get for invalid name should have reported a failure");
} catch (AtlasServiceException e) {
assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(),
"Should've returned a 404");
}
try {
AtlasBusinessMetadataDef byName = clientV2.getBusinessMetadataDefByName("blah");
fail("Get for invalid name should have reported a failure");
} catch (AtlasServiceException e) {
assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(),
"Should've returned a 404");
}
try {
AtlasBusinessMetadataDef byGuid = clientV2.getBusinessMetadataDefGuid("blah");
fail("Get for invalid name should have reported a failure");
} catch (AtlasServiceException e) {
assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(),
"Should've returned a 404");
}
}
......@@ -339,6 +412,10 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT {
byName = clientV2.getClassificationDefByName(typeDef.getName());
} else if (typeDef.getCategory() == TypeCategory.STRUCT) {
byName = clientV2.getStructDefByName(typeDef.getName());
} else if (typeDef.getCategory() == TypeCategory.RELATIONSHIP) {
byName = clientV2.getRelationshipDefByName(typeDef.getName());
} else if (typeDef.getCategory() == TypeCategory.BUSINESS_METADATA) {
byName = clientV2.getBusinessMetadataDefByName(typeDef.getName());
}
assertNotNull(byName);
} catch (AtlasServiceException e) {
......@@ -355,6 +432,10 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT {
byGuid = clientV2.getClassificationDefByGuid(typeDef.getGuid());
} else if (typeDef.getCategory() == TypeCategory.STRUCT) {
byGuid = clientV2.getStructDefByGuid(typeDef.getGuid());
} else if (typeDef.getCategory() == TypeCategory.RELATIONSHIP) {
byGuid = clientV2.getRelationshipDefByGuid(typeDef.getGuid());
} else if (typeDef.getCategory() == TypeCategory.BUSINESS_METADATA) {
byGuid = clientV2.getBusinessMetadataDefGuid(typeDef.getGuid());
}
assertNotNull(byGuid);
} catch (AtlasServiceException e) {
......@@ -368,6 +449,8 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT {
def.getStructDefs().clear();
def.getClassificationDefs().clear();
def.getEntityDefs().clear();
def.getRelationshipDefs().clear();
def.getBusinessMetadataDefs().clear();
}
private void checkIfTypeExists(String typeName) throws Exception {
......
[ {
"testDescription": "hive_table contains testtable or retentionSize != 0",
"searchParameters": {
"typeName": "hive_table",
"excludeDeletedEntities": true,
"classification": "",
"query": "",
"limit": 25,
"offset": 0,
"entityFilters": {
"attributeName": "name",
"attributeValue": "testtable",
"condition" : "OR",
"criterion" : [
{
"attributeName": "name",
"operator": "contains",
"attributeValue": "testtable"
},
{
"attributeName": "retention",
"operator": "neq",
"attributeValue": "0"
}
]
},
"tagFilters": null,
"attributes": [
""
]
},
"expectedCount": 3
}]
\ No newline at end of file
GlossaryName, TermName, ShortDescription, LongDescription, Examples, Abbreviation, Usage, AdditionalAttributes, TranslationTerms, ValidValuesFor, Synonyms, ReplacedBy, ValidValues, ReplacementTerms, SeeAlso, TranslatedTerms, IsA, Antonyms, Classifies, PreferredToTerms, PreferredTerms
testBankingGlossary,BankBranch,SD4,LD4,"EXAMPLE","ABBREVIATION","USAGE",,,,,,,,,,,,,,
\ No newline at end of file
TypeName,UniqueAttributeValue,BusinessAttributeName,BusinessAttributeValue,UniqueAttributeName[optional]
hive_table_v2,tableqZPo3C488c,bmWithAllTypes.attr8,"Awesome Attribute 1",qualifiedName
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