Commit 0fe4d885 by apoorvnaik Committed by Madhan Neethiraj

ATLAS-1534: TypesREST clean up for simpler REST interface

parent 9cb56c54
......@@ -117,21 +117,45 @@ public class AtlasTypedefClientV2 extends AtlasBaseClient {
return getTypeDefByGuid(guid, AtlasEntityDef.class);
}
@Deprecated
public AtlasEnumDef createEnumDef(AtlasEnumDef enumDef) throws AtlasServiceException {
return callAPI(CREATE_ENUM_DEF, AtlasType.toJson(enumDef), AtlasEnumDef.class);
AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
atlasTypesDef.getEnumDefs().add(enumDef);
AtlasTypesDef created = createAtlasTypeDefs(atlasTypesDef);
assert created != null;
assert created.getEnumDefs() != null;
return created.getEnumDefs().get(0);
}
@Deprecated
public AtlasStructDef createStructDef(AtlasStructDef structDef) throws AtlasServiceException {
return callAPI(CREATE_STRUCT_DEF, AtlasType.toJson(structDef), AtlasStructDef.class);
AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
atlasTypesDef.getStructDefs().add(structDef);
AtlasTypesDef created = createAtlasTypeDefs(atlasTypesDef);
assert created != null;
assert created.getStructDefs() != null;
return created.getStructDefs().get(0);
}
@Deprecated
public AtlasEntityDef createEntityDef(AtlasEntityDef entityDef) throws AtlasServiceException {
return callAPI(CREATE_ENTITY_DEF, AtlasType.toJson(entityDef), AtlasEntityDef.class);
AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
atlasTypesDef.getEntityDefs().add(entityDef);
AtlasTypesDef created = createAtlasTypeDefs(atlasTypesDef);
assert created != null;
assert created.getEntityDefs() != null;
return created.getEntityDefs().get(0);
}
@Deprecated
public AtlasClassificationDef createClassificationDef(AtlasClassificationDef classificationDef)
throws AtlasServiceException {
return callAPI(CREATE_CLASSIFICATION_DEF, AtlasType.toJson(classificationDef), AtlasClassificationDef.class);
AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
atlasTypesDef.getClassificationDefs().add(classificationDef);
AtlasTypesDef created = createAtlasTypeDefs(atlasTypesDef);
assert created != null;
assert created.getClassificationDefs() != null;
return created.getClassificationDefs().get(0);
}
......
......@@ -61,6 +61,9 @@ public enum AtlasErrorCode {
CONSTRAINT_OWNED_REF_ATTRIBUTE_INVALID_TYPE(400, "ATLAS40030E", "{0}.{1}: invalid {2} constraint. Attribute {3} is not an entity type"),
CANNOT_MAP_ATTRIBUTE(400, "ATLAS40031E", "cannot map attribute: {0} of type: {1} from vertex"),
INVALID_OBJECT_ID(400, "ATLAS40032E", "ObjectId is not valid {0}"),
UNRESOLVED_REFERENCES_FOUND(400, "ATLAS40033E", "Unresolved references: byId={0}; byUniqueAttributes={1}"),
UNKNOWN_ATTRIBUTE(400, "ATLAS40034E", "Attribute {0} not found for type {1}"),
SYSTEM_TYPE(400, "ATLAS40035E", "{0} is a System-type"),
// All Not found enums go here
TYPE_NAME_NOT_FOUND(404, "ATLAS4041E", "Given typename {0} was invalid"),
......@@ -71,6 +74,7 @@ public enum AtlasErrorCode {
INSTANCE_LINEAGE_QUERY_FAILED(404, "ATLAS4047E", "Instance lineage query failed {0}"),
DISCOVERY_QUERY_FAILED(404, "ATLAS4048E", "Discovery query failed {0}"),
INSTANCE_CRUD_INVALID_PARAMS(404, "ATLAS4049E", "Invalid instance creation/updation parameters passed : {0}"),
INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND(404, "ATLAS40410E", "Instance {0} with unique attribute {1}={2} does not exist"),
// All data conflict errors go here
......@@ -82,13 +86,7 @@ public enum AtlasErrorCode {
INTERNAL_ERROR(500, "ATLAS5001E", "Internal server error {0}"),
INDEX_CREATION_FAILED(500, "ATLAS5002E", "Index creation failed for {0}"),
INDEX_ROLLBACK_FAILED(500, "ATLAS5003E", "Index rollback failed for {0}"),
FAILED_TO_OBTAIN_TYPE_UPDATE_LOCK(500, "ATLAS5004E", "Failed to get the lock; another type update might be in progress. Please try again"),
INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND(400, "ATLAS40018E", "Instance {0} with unique attribute {1}={2} does not exist"),
UNRESOLVED_REFERENCES_FOUND(400, "ATLAS40010E", "Unresolved references: byId={0}; byUniqueAttributes={1}"),
UNKNOWN_ATTRIBUTE(400, "ATLAS40019E", "Attribute {0} not found for type {1}");
FAILED_TO_OBTAIN_TYPE_UPDATE_LOCK(500, "ATLAS5004E", "Failed to get the lock; another type update might be in progress. Please try again");
private String errorCode;
private String errorMessage;
......
......@@ -19,14 +19,12 @@ package org.apache.atlas.store;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasClassificationDef.AtlasClassificationDefs;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasEntityDef.AtlasEntityDefs;
import org.apache.atlas.model.typedef.AtlasEnumDef;
import org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumDefs;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasStructDefs;
import org.apache.atlas.model.typedef.AtlasTypesDef;
import java.util.List;
......@@ -37,13 +35,7 @@ import java.util.List;
public interface AtlasTypeDefStore {
void init() throws AtlasBaseException;
/***********************/
/** EnumDef operation **/
/***********************/
AtlasEnumDef createEnumDef(AtlasEnumDef enumDef) throws AtlasBaseException;
List<AtlasEnumDef> getAllEnumDefs() throws AtlasBaseException;
/* EnumDef operations */
AtlasEnumDef getEnumDefByName(String name) throws AtlasBaseException;
......@@ -53,18 +45,7 @@ public interface AtlasTypeDefStore {
AtlasEnumDef updateEnumDefByGuid(String guid, AtlasEnumDef enumDef) throws AtlasBaseException;
void deleteEnumDefByName(String name) throws AtlasBaseException;
void deleteEnumDefByGuid(String guid) throws AtlasBaseException;
AtlasEnumDefs searchEnumDefs(SearchFilter filter) throws AtlasBaseException;
/*************************/
/** StructDef operation **/
/*************************/
AtlasStructDef createStructDef(AtlasStructDef structDef) throws AtlasBaseException;
List<AtlasStructDef> getAllStructDefs() throws AtlasBaseException;
/* StructDef operations */
AtlasStructDef getStructDefByName(String name) throws AtlasBaseException;
......@@ -74,19 +55,7 @@ public interface AtlasTypeDefStore {
AtlasStructDef updateStructDefByGuid(String guid, AtlasStructDef structDef) throws AtlasBaseException;
void deleteStructDefByName(String name) throws AtlasBaseException;
void deleteStructDefByGuid(String guid) throws AtlasBaseException;
AtlasStructDefs searchStructDefs(SearchFilter filter) throws AtlasBaseException;
/*********************************/
/** ClassificationDef operation **/
/*********************************/
AtlasClassificationDef createClassificationDef(AtlasClassificationDef classificationDef) throws AtlasBaseException;
List<AtlasClassificationDef> getAllClassificationDefs() throws AtlasBaseException;
/* ClassificationDef operations */
AtlasClassificationDef getClassificationDefByName(String name) throws AtlasBaseException;
......@@ -98,19 +67,7 @@ public interface AtlasTypeDefStore {
AtlasClassificationDef updateClassificationDefByGuid(String guid, AtlasClassificationDef classificationDef)
throws AtlasBaseException;
void deleteClassificationDefByName(String name) throws AtlasBaseException;
void deleteClassificationDefByGuid(String guid) throws AtlasBaseException;
AtlasClassificationDefs searchClassificationDefs(SearchFilter filter) throws AtlasBaseException;
/*************************/
/** EntityDef operation **/
/*************************/
AtlasEntityDef createEntityDef(AtlasEntityDef entityDef) throws AtlasBaseException;
List<AtlasEntityDef> getAllEntityDefs() throws AtlasBaseException;
/* EntityDef operations */
AtlasEntityDef getEntityDefByName(String name) throws AtlasBaseException;
......@@ -120,13 +77,7 @@ public interface AtlasTypeDefStore {
AtlasEntityDef updateEntityDefByGuid(String guid, AtlasEntityDef entityDef) throws AtlasBaseException;
void deleteEntityDefByName(String name) throws AtlasBaseException;
void deleteEntityDefByGuid(String guid) throws AtlasBaseException;
AtlasEntityDefs searchEntityDefs(SearchFilter filter) throws AtlasBaseException;
/***** Bulk Operations *****/
/* Bulk Operations */
AtlasTypesDef createTypesDef(AtlasTypesDef atlasTypesDef) throws AtlasBaseException;
......@@ -135,4 +86,9 @@ public interface AtlasTypeDefStore {
void deleteTypesDef(AtlasTypesDef atlasTypesDef) throws AtlasBaseException;
AtlasTypesDef searchTypesDef(SearchFilter searchFilter) throws AtlasBaseException;
/* Generic operation */
AtlasBaseTypeDef getByName(String name) throws AtlasBaseException;
AtlasBaseTypeDef getByGuid(String guid) throws AtlasBaseException;
}
......@@ -38,6 +38,7 @@ import org.testng.annotations.DataProvider;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
......@@ -64,36 +65,16 @@ public class AtlasTypeDefGraphStoreTest {
@Test(priority = 1)
public void testGet() {
try {
List<AtlasEnumDef> allEnumDefs = typeDefStore.getAllEnumDefs();
assertNotNull(allEnumDefs);
assertEquals(allEnumDefs.size(), 0);
} catch (AtlasBaseException e) {
fail("Get should've succeeded", e);
}
try {
List<AtlasClassificationDef> allClassificationDefs = typeDefStore.getAllClassificationDefs();
assertNotNull(allClassificationDefs);
assertEquals(allClassificationDefs.size(), 0);
} catch (AtlasBaseException e) {
fail("Get should've succeeded", e);
}
try {
List<AtlasStructDef> allStructDefs = typeDefStore.getAllStructDefs();
assertNotNull(allStructDefs);
assertEquals(allStructDefs.size(), 0);
} catch (AtlasBaseException e) {
fail("Get should've succeeded", e);
}
try {
List<AtlasEntityDef> allEntityDefs = typeDefStore.getAllEntityDefs();
assertNotNull(allEntityDefs);
// For some reason this keeps on toggling b/w 0 and 5, need to investigate
assertTrue(allEntityDefs.size()>= 0);
AtlasTypesDef typesDef = typeDefStore.searchTypesDef(new SearchFilter());
assertNotNull(typesDef.getEnumDefs());
assertEquals(typesDef.getStructDefs().size(), 0);
assertNotNull(typesDef.getStructDefs());
assertEquals(typesDef.getClassificationDefs().size(), 0);
assertNotNull(typesDef.getClassificationDefs());
assertEquals(typesDef.getEntityDefs().size(), 0);
assertNotNull(typesDef.getEntityDefs());
} catch (AtlasBaseException e) {
fail("Get should've succeeded", e);
fail("Search of types shouldn't have failed");
}
}
......@@ -385,17 +366,25 @@ public class AtlasTypeDefGraphStoreTest {
@Test(dependsOnMethods = "testGet")
public void testCreateWithInvalidSuperTypes(){
AtlasTypesDef typesDef;
// Test Classification with supertype
AtlasClassificationDef classificationDef = TestUtilsV2.getClassificationWithInvalidSuperType();
typesDef = new AtlasTypesDef();
typesDef.getClassificationDefs().add(classificationDef);
try {
AtlasClassificationDef created = typeDefStore.createClassificationDef(classificationDef);
AtlasTypesDef created = typeDefStore.createTypesDef(typesDef);
fail("Classification creation with invalid supertype should've failed");
} catch (AtlasBaseException e) {}
} catch (AtlasBaseException e) {
typesDef = null;
}
// Test Entity with supertype
AtlasEntityDef entityDef = TestUtilsV2.getEntityWithInvalidSuperType();
typesDef = new AtlasTypesDef();
typesDef.getEntityDefs().add(entityDef);
try {
AtlasEntityDef created = typeDefStore.createEntityDef(entityDef);
AtlasTypesDef created = typeDefStore.createTypesDef(typesDef);
fail("Entity creation with invalid supertype should've failed");
} catch (AtlasBaseException e) {}
......
......@@ -64,6 +64,7 @@ import org.testng.annotations.Test;
import javax.inject.Inject;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -737,7 +738,8 @@ public class AtlasEntityStoreV1Test {
AtlasTypeUtil.createOptionalAttrDef(arrayAttrName, "array<string>"),
AtlasTypeUtil.createOptionalAttrDef(mapAttrName, "map<string,string>"));
typeDefStore.createEntityDef(typeDefinition);
AtlasTypesDef atlasTypesDef = new AtlasTypesDef(null, null, null, Arrays.asList(typeDefinition));
typeDefStore.createTypesDef(atlasTypesDef);
//verify that entity can be created with reserved characters in string value, array value and map key and value
Map<String, AtlasEntity> entityCloneMap = new HashMap<>();
......
......@@ -283,7 +283,7 @@ public class TypesResource {
TypesREST typesRest = resourceContext.getResource(TypesREST.class);
JSONObject response = new JSONObject();
try {
List<String> result = RestUtils.getTypeNames(typesRest.getTypeDefHeaders());
List<String> result = RestUtils.getTypeNames(typesRest.getTypeDefHeaders(request));
response.put(AtlasClient.RESULTS, new JSONArray(result));
response.put(AtlasClient.COUNT, result.size());
......
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