Commit 33d60746 by Suma Shivaprasad

ATLAS-1257 Map Entity REST APIs to ATLAS v1 backend (sumasai)

parent 758b3d4d
...@@ -64,9 +64,9 @@ def main(): ...@@ -64,9 +64,9 @@ def main():
if mc.is_hbase_local(confdir): if mc.is_hbase_local(confdir):
mc.run_hbase_action(mc.hbaseBinDir(atlas_home), "stop", None, None, True) mc.run_hbase_action(mc.hbaseBinDir(atlas_home), "stop", None, None, True)
#after 30 seconds kill it
time.sleep(30)
if mc.exist_pid(pid): if mc.exist_pid(pid):
#after 30 seconds kill it
time.sleep(30)
try: try:
sys.stderr.write("did not stop gracefully after 30 seconds seconds: killing with SIGKILL\n") sys.stderr.write("did not stop gracefully after 30 seconds seconds: killing with SIGKILL\n")
os.kill(pid, SIGKILL) os.kill(pid, SIGKILL)
......
...@@ -49,6 +49,7 @@ public enum AtlasErrorCode { ...@@ -49,6 +49,7 @@ public enum AtlasErrorCode {
INSTANCE_GUID_NOT_FOUND(404, "ATLAS4045E", "Given instance guid {0} is invalid"), INSTANCE_GUID_NOT_FOUND(404, "ATLAS4045E", "Given instance guid {0} is invalid"),
INSTANCE_LINEAGE_INVALID_PARAMS(404, "ATLAS4046E", "Invalid lineage query parameters passed {0}: {1}"), INSTANCE_LINEAGE_INVALID_PARAMS(404, "ATLAS4046E", "Invalid lineage query parameters passed {0}: {1}"),
INSTANCE_LINEAGE_QUERY_FAILED(404, "ATLAS4047E", "Instance lineage query failed {0}"), INSTANCE_LINEAGE_QUERY_FAILED(404, "ATLAS4047E", "Instance lineage query failed {0}"),
INSTANCE_ALREADY_EXISTS(405, "ATLAS4051E", "Given entity with guid/name {0} already exists"),
TYPE_ALREADY_EXISTS(409, "ATLAS4091E", "Given type {0} already exists"), TYPE_ALREADY_EXISTS(409, "ATLAS4091E", "Given type {0} already exists"),
TYPE_HAS_REFERENCES(409, "ATLAS4092E", "Given type {0} has references"), TYPE_HAS_REFERENCES(409, "ATLAS4092E", "Given type {0} has references"),
...@@ -57,9 +58,12 @@ public enum AtlasErrorCode { ...@@ -57,9 +58,12 @@ public enum AtlasErrorCode {
INTERNAL_ERROR(500, "ATLAS5001E", "Internal server error {0}"), INTERNAL_ERROR(500, "ATLAS5001E", "Internal server error {0}"),
INDEX_CREATION_FAILED(500, "ATLAS5002E", "Index creation failed for {0}"), INDEX_CREATION_FAILED(500, "ATLAS5002E", "Index creation failed for {0}"),
INDEX_ROLLBACK_FAILED(500, "ATLAS5003E", "Index rollback failed for {0}"), INDEX_ROLLBACK_FAILED(500, "ATLAS5003E", "Index rollback failed for {0}"),
PATCH_NOT_APPLICABLE_FOR_TYPE(500, "ATLAS5004E", "{0} - invalid patch for type {1}"), PATCH_NOT_APPLICABLE_FOR_TYPE(500, "ATLAS5004E", "{0} - invalid patch for type {1}"),
PATCH_FOR_UNKNOWN_TYPE(500, "ATLAS5005E", "{0} - patch references unknown type {1}") PATCH_FOR_UNKNOWN_TYPE(500, "ATLAS5005E", "{0} - patch references unknown type {1}"),
; ATTRIBUTE_UNIQUE_INVALID(400, "ATLAS40015E", "Type {0} with unique attribute {1} does not exist"),
TYPE_NAME_INVALID(400, "ATLAS40016E", "Type {0} with name {1} does not exist"),
TYPE_CATEGORY_INVALID(400, "ATLAS40017E", "Type Category {0} does not match {1} or is invalid");
private String errorCode; private String errorCode;
private String errorMessage; private String errorMessage;
......
...@@ -20,6 +20,7 @@ package org.apache.atlas.exception; ...@@ -20,6 +20,7 @@ package org.apache.atlas.exception;
import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.AtlasErrorCode;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.List;
/** /**
* Base Exception class for Atlas API. * Base Exception class for Atlas API.
...@@ -33,6 +34,11 @@ public class AtlasBaseException extends Exception { ...@@ -33,6 +34,11 @@ public class AtlasBaseException extends Exception {
this.atlasErrorCode = errorCode; this.atlasErrorCode = errorCode;
} }
public AtlasBaseException(final AtlasErrorCode errorCode, final List<String> params) {
super(errorCode.getFormattedErrorMessage(params.toArray(new String[params.size()])));
this.atlasErrorCode = errorCode;
}
public AtlasBaseException() { public AtlasBaseException() {
this(AtlasErrorCode.INTERNAL_ERROR); this(AtlasErrorCode.INTERNAL_ERROR);
} }
...@@ -69,6 +75,11 @@ public class AtlasBaseException extends Exception { ...@@ -69,6 +75,11 @@ public class AtlasBaseException extends Exception {
this.atlasErrorCode = AtlasErrorCode.INTERNAL_ERROR; this.atlasErrorCode = AtlasErrorCode.INTERNAL_ERROR;
} }
public AtlasBaseException(final AtlasErrorCode errorCode, Throwable cause, final List<String> params) {
super(errorCode.getFormattedErrorMessage(params.toArray(new String[params.size()])), cause);
this.atlasErrorCode = errorCode;
}
public AtlasErrorCode getAtlasErrorCode() { public AtlasErrorCode getAtlasErrorCode() {
return atlasErrorCode; return atlasErrorCode;
} }
......
...@@ -21,6 +21,8 @@ import java.io.Serializable; ...@@ -21,6 +21,8 @@ import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;
import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
...@@ -33,6 +35,8 @@ import org.apache.atlas.model.typedef.AtlasEntityDef; ...@@ -33,6 +35,8 @@ import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.codehaus.jackson.annotate.JsonAutoDetect; import org.codehaus.jackson.annotate.JsonAutoDetect;
import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.PUBLIC_ONLY; import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.PUBLIC_ONLY;
import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.NONE; import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.NONE;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties; import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.map.annotate.JsonSerialize; import org.codehaus.jackson.map.annotate.JsonSerialize;
...@@ -61,6 +65,9 @@ public class AtlasEntity extends AtlasStruct implements Serializable { ...@@ -61,6 +65,9 @@ public class AtlasEntity extends AtlasStruct implements Serializable {
private Date updateTime = null; private Date updateTime = null;
private Long version = null; private Long version = null;
@JsonIgnore
private static AtomicLong s_nextId = new AtomicLong(System.nanoTime());
public AtlasEntity() { public AtlasEntity() {
this(null, null); this(null, null);
} }
...@@ -76,7 +83,7 @@ public class AtlasEntity extends AtlasStruct implements Serializable { ...@@ -76,7 +83,7 @@ public class AtlasEntity extends AtlasStruct implements Serializable {
public AtlasEntity(String typeName, Map<String, Object> attributes) { public AtlasEntity(String typeName, Map<String, Object> attributes) {
super(typeName, attributes); super(typeName, attributes);
setGuid(null); setGuid(nextInternalId());
setStatus(null); setStatus(null);
setCreatedBy(null); setCreatedBy(null);
setUpdatedBy(null); setUpdatedBy(null);
...@@ -239,4 +246,39 @@ public class AtlasEntity extends AtlasStruct implements Serializable { ...@@ -239,4 +246,39 @@ public class AtlasEntity extends AtlasStruct implements Serializable {
super(list, startIndex, pageSize, totalCount, sortType, sortBy); super(list, startIndex, pageSize, totalCount, sortType, sortBy);
} }
} }
@JsonIgnore
public boolean validate(String id) {
try {
long l = Long.parseLong(id);
return l < 0;
} catch (NumberFormatException ne) {
return false;
}
}
@JsonIgnore
public boolean isUnassigned() {
return guid != null && guid.length() > 0 && guid.charAt(0) == '-';
}
@JsonIgnore
public boolean isAssigned() {
return isAssigned(guid);
}
@JsonIgnore
public static boolean isAssigned(String guid) {
try {
UUID.fromString(guid);
} catch (IllegalArgumentException e) {
return false;
}
return true;
}
private String nextInternalId() {
return "-" + Long.toString(s_nextId.getAndIncrement());
}
} }
...@@ -31,6 +31,7 @@ import org.apache.atlas.model.SearchFilter.SortType; ...@@ -31,6 +31,7 @@ import org.apache.atlas.model.SearchFilter.SortType;
import org.codehaus.jackson.annotate.JsonAutoDetect; import org.codehaus.jackson.annotate.JsonAutoDetect;
import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.PUBLIC_ONLY; import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.PUBLIC_ONLY;
import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.NONE; import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.NONE;
import org.codehaus.jackson.annotate.JsonIgnoreProperties; import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.map.annotate.JsonSerialize; import org.codehaus.jackson.map.annotate.JsonSerialize;
...@@ -140,7 +141,6 @@ public class AtlasObjectId implements Serializable { ...@@ -140,7 +141,6 @@ public class AtlasObjectId implements Serializable {
return toString(new StringBuilder()).toString(); return toString(new StringBuilder()).toString();
} }
/** /**
* REST serialization friendly list. * REST serialization friendly list.
*/ */
......
...@@ -61,7 +61,7 @@ public class EntityMutationResponse { ...@@ -61,7 +61,7 @@ public class EntityMutationResponse {
this.entitiesMutated = opVsEntityMap; this.entitiesMutated = opVsEntityMap;
} }
List<AtlasEntityHeader> getEntitiesByOperation(EntityMutations.EntityOperation op) { public List<AtlasEntityHeader> getEntitiesByOperation(EntityMutations.EntityOperation op) {
if ( entitiesMutated != null) { if ( entitiesMutated != null) {
return entitiesMutated.get(op); return entitiesMutated.get(op);
} }
......
...@@ -32,13 +32,14 @@ import org.apache.atlas.model.typedef.AtlasTypesDef; ...@@ -32,13 +32,14 @@ import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Arrays;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_ARRAY_PREFIX; import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_ARRAY_PREFIX;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_ARRAY_SUFFIX; import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_ARRAY_SUFFIX;
...@@ -112,21 +113,21 @@ public class AtlasTypeUtil { ...@@ -112,21 +113,21 @@ public class AtlasTypeUtil {
public static AtlasAttributeDef createOptionalAttrDef(String name, AtlasType dataType) { public static AtlasAttributeDef createOptionalAttrDef(String name, AtlasType dataType) {
return new AtlasAttributeDef(name, dataType.getTypeName(), true, return new AtlasAttributeDef(name, dataType.getTypeName(), true,
Cardinality.SINGLE, 0, 1, Cardinality.SINGLE, 0, 1,
true, false, false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()); Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
} }
public static AtlasAttributeDef createOptionalAttrDef(String name, String dataType) { public static AtlasAttributeDef createOptionalAttrDef(String name, String dataType) {
return new AtlasAttributeDef(name, dataType, true, return new AtlasAttributeDef(name, dataType, true,
Cardinality.SINGLE, 0, 1, Cardinality.SINGLE, 0, 1,
true, false, false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()); Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
} }
public static AtlasAttributeDef createRequiredAttrDef(String name, String dataType) { public static AtlasAttributeDef createRequiredAttrDef(String name, String dataType) {
return new AtlasAttributeDef(name, dataType, false, return new AtlasAttributeDef(name, dataType, false,
Cardinality.SINGLE, 1, 1, Cardinality.SINGLE, 1, 1,
false, false, false, true,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()); Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
} }
...@@ -147,7 +148,7 @@ public class AtlasTypeUtil { ...@@ -147,7 +148,7 @@ public class AtlasTypeUtil {
public static AtlasAttributeDef createRequiredAttrDef(String name, AtlasType dataType) { public static AtlasAttributeDef createRequiredAttrDef(String name, AtlasType dataType) {
return new AtlasAttributeDef(name, dataType.getTypeName(), false, return new AtlasAttributeDef(name, dataType.getTypeName(), false,
Cardinality.SINGLE, 1, 1, Cardinality.SINGLE, 1, 1,
false, false, false, true,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()); Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
} }
......
...@@ -22,7 +22,7 @@ import com.google.common.collect.ImmutableList; ...@@ -22,7 +22,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.apache.atlas.model.instance.AtlasEntity; import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasObjectId; import org.apache.atlas.model.instance.AtlasStruct;
import org.apache.atlas.model.typedef.AtlasClassificationDef; import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasEntityDef; import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasEnumDef; import org.apache.atlas.model.typedef.AtlasEnumDef;
...@@ -35,6 +35,8 @@ import org.apache.commons.lang.RandomStringUtils; ...@@ -35,6 +35,8 @@ import org.apache.commons.lang.RandomStringUtils;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import java.sql.Struct;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
...@@ -432,7 +434,8 @@ public final class TestUtilsV2 { ...@@ -432,7 +434,8 @@ public final class TestUtilsV2 {
AtlasTypeUtil.createClassTypeDef(COLUMN_TYPE, COLUMN_TYPE + "_description", AtlasTypeUtil.createClassTypeDef(COLUMN_TYPE, COLUMN_TYPE + "_description",
ImmutableSet.<String>of(), ImmutableSet.<String>of(),
AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"),
AtlasTypeUtil.createRequiredAttrDef("type", "string")); AtlasTypeUtil.createRequiredAttrDef("type", "string")
);
AtlasStructDef partitionDefinition = new AtlasStructDef("partition_struct_type", "partition_struct_type" + _description, "1.0", AtlasStructDef partitionDefinition = new AtlasStructDef("partition_struct_type", "partition_struct_type" + _description, "1.0",
Arrays.asList(AtlasTypeUtil.createRequiredAttrDef("name", "string"))); Arrays.asList(AtlasTypeUtil.createRequiredAttrDef("name", "string")));
...@@ -614,8 +617,18 @@ public final class TestUtilsV2 { ...@@ -614,8 +617,18 @@ public final class TestUtilsV2 {
entity.setAttribute("description", "random table"); entity.setAttribute("description", "random table");
entity.setAttribute("type", "type"); entity.setAttribute("type", "type");
entity.setAttribute("tableType", "MANAGED"); entity.setAttribute("tableType", "MANAGED");
entity.setAttribute("database", new AtlasObjectId(DATABASE_TYPE, dbId)); entity.setAttribute("database", dbId);
entity.setAttribute("created", new Date()); entity.setAttribute("created", new Date());
Map<String, Object> partAttributes = new HashMap<String, Object>() {{
put("name", "part0");
}};
final AtlasStruct partitionStruct = new AtlasStruct("partition_struct_type", partAttributes);
entity.setAttribute("partitions", new ArrayList<AtlasStruct>() {{ add(partitionStruct); }});
entity.setAttribute("parametersMap", new java.util.HashMap<String, String>() {{
put("key1", "value1");
}});
return entity; return entity;
} }
......
...@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al ...@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al
ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai) ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai)
ALL CHANGES: ALL CHANGES:
ATLAS-1257 Map Entity REST APIs to ATLAS v1 backend (sumasai)
ATLAS-1279 Remove QueryPlan attribute from Hive Process entity (svimal2106) ATLAS-1279 Remove QueryPlan attribute from Hive Process entity (svimal2106)
ATLAS-1234 Lineage REST API - v2 (sarath.kum4r@gmail.com via mneethiraj) ATLAS-1234 Lineage REST API - v2 (sarath.kum4r@gmail.com via mneethiraj)
ATLAS-1276 fix for webapp test failures (ayubkhan via mneethiraj) ATLAS-1276 fix for webapp test failures (ayubkhan via mneethiraj)
......
...@@ -292,14 +292,29 @@ public class DefaultMetadataService implements MetadataService, ActiveStateChang ...@@ -292,14 +292,29 @@ public class DefaultMetadataService implements MetadataService, ActiveStateChang
* @return entity definition as JSON * @return entity definition as JSON
*/ */
@Override @Override
public String getEntityDefinition(String guid) throws AtlasException { public String getEntityDefinitionJson(String guid) throws AtlasException {
guid = ParamChecker.notEmpty(guid, "entity id"); guid = ParamChecker.notEmpty(guid, "entity id");
final ITypedReferenceableInstance instance = repository.getEntityDefinition(guid); final ITypedReferenceableInstance instance = repository.getEntityDefinition(guid);
return InstanceSerialization.toJson(instance, true); return InstanceSerialization.toJson(instance, true);
} }
private ITypedReferenceableInstance getEntityDefinitionReference(String entityType, String attribute, String value) /**
* Return the definition for the given guid.
*
* @param guid guid
* @return entity definition as JSON
*/
@Override
public ITypedReferenceableInstance getEntityDefinition(String guid) throws AtlasException {
guid = ParamChecker.notEmpty(guid, "entity id");
final ITypedReferenceableInstance instance = repository.getEntityDefinition(guid);
return instance;
}
@Override
public ITypedReferenceableInstance getEntityDefinitionReference(String entityType, String attribute, String value)
throws AtlasException { throws AtlasException {
validateTypeExists(entityType); validateTypeExists(entityType);
validateUniqueAttribute(entityType, attribute); validateUniqueAttribute(entityType, attribute);
...@@ -356,6 +371,19 @@ public class DefaultMetadataService implements MetadataService, ActiveStateChang ...@@ -356,6 +371,19 @@ public class DefaultMetadataService implements MetadataService, ActiveStateChang
return entityResult; return entityResult;
} }
/**
* Updates an entity, instance of the type based on the guid set.
*
* @param entityInstanceDefinitions
* @return guids - json array of guids
*/
@Override
public AtlasClient.EntityResult updateEntities(ITypedReferenceableInstance[] entityInstanceDefinitions) throws AtlasException {
AtlasClient.EntityResult entityResult = repository.updateEntities(entityInstanceDefinitions);
onEntitiesAddedUpdated(entityResult);
return entityResult;
}
private void onEntitiesAddedUpdated(AtlasClient.EntityResult entityResult) throws AtlasException { private void onEntitiesAddedUpdated(AtlasClient.EntityResult entityResult) throws AtlasException {
onEntitiesAdded(entityResult.getCreatedEntities()); onEntitiesAdded(entityResult.getCreatedEntities());
onEntitiesUpdated(entityResult.getUpdateEntities()); onEntitiesUpdated(entityResult.getUpdateEntities());
......
...@@ -221,7 +221,7 @@ public class DefaultMetadataServiceTest { ...@@ -221,7 +221,7 @@ public class DefaultMetadataServiceTest {
//Verify that get entity definition returns actual values with reserved characters //Verify that get entity definition returns actual values with reserved characters
Referenceable instance = Referenceable instance =
InstanceSerialization.fromJsonReferenceable(metadataService.getEntityDefinition(id), true); InstanceSerialization.fromJsonReferenceable(metadataService.getEntityDefinitionJson(id), true);
assertReferenceableEquals(instance, entity); assertReferenceableEquals(instance, entity);
//Verify that search with reserved characters works - for string attribute //Verify that search with reserved characters works - for string attribute
...@@ -693,7 +693,7 @@ public class DefaultMetadataServiceTest { ...@@ -693,7 +693,7 @@ public class DefaultMetadataServiceTest {
serdeInstance.setNull("description"); serdeInstance.setNull("description");
updateInstance(table); updateInstance(table);
tableDefinitionJson = tableDefinitionJson =
metadataService.getEntityDefinition(tableId._getId()); metadataService.getEntityDefinitionJson(tableId._getId());
tableDefinition = InstanceSerialization.fromJsonReferenceable(tableDefinitionJson, true); tableDefinition = InstanceSerialization.fromJsonReferenceable(tableDefinitionJson, true);
Assert.assertNull(((Struct) tableDefinition.get("serde1")).get("description")); Assert.assertNull(((Struct) tableDefinition.get("serde1")).get("description"));
} }
...@@ -733,7 +733,7 @@ public class DefaultMetadataServiceTest { ...@@ -733,7 +733,7 @@ public class DefaultMetadataServiceTest {
metadataService.updateEntityAttributeByGuid(tableId._getId(), "database", dbId); metadataService.updateEntityAttributeByGuid(tableId._getId(), "database", dbId);
String tableDefinitionJson = String tableDefinitionJson =
metadataService.getEntityDefinition(tableId._getId()); metadataService.getEntityDefinitionJson(tableId._getId());
Referenceable tableDefinition = InstanceSerialization.fromJsonReferenceable(tableDefinitionJson, true); Referenceable tableDefinition = InstanceSerialization.fromJsonReferenceable(tableDefinitionJson, true);
assertEquals(dbId, (((Id) tableDefinition.get("database"))._getId())); assertEquals(dbId, (((Id) tableDefinition.get("database"))._getId()));
......
...@@ -101,13 +101,27 @@ public interface MetadataService { ...@@ -101,13 +101,27 @@ public interface MetadataService {
*/ */
List<String> createEntities(ITypedReferenceableInstance[] typedInstances) throws AtlasException; List<String> createEntities(ITypedReferenceableInstance[] typedInstances) throws AtlasException;
/** /**
* Return the definition for the given guid. * Return the definition for the given guid.
* *
* @param guid guid * @param guid guid
* @return entity definition as JSON * @return entity definition as JSON
*/ */
String getEntityDefinition(String guid) throws AtlasException; String getEntityDefinitionJson(String guid) throws AtlasException;
ITypedReferenceableInstance getEntityDefinition(String guid) throws AtlasException;
/**
* Return the definition given type and attribute. The attribute has to be unique attribute for the type
* @param entityType - type name
* @param attribute - attribute name
* @param value - attribute value
* @return
* @throws AtlasException
*/
ITypedReferenceableInstance getEntityDefinitionReference(String entityType, String attribute, String value) throws AtlasException;
/** /**
* Return the definition given type and attribute. The attribute has to be unique attribute for the type * Return the definition given type and attribute. The attribute has to be unique attribute for the type
...@@ -155,6 +169,15 @@ public interface MetadataService { ...@@ -155,6 +169,15 @@ public interface MetadataService {
*/ */
AtlasClient.EntityResult updateEntities(String entityJson) throws AtlasException; AtlasClient.EntityResult updateEntities(String entityJson) throws AtlasException;
/**
* Batch API - Adds/Updates the given entity id(guid).
*
* @param entityJson entity json
* @return json array of guids of entities created/updated
*/
AtlasClient.EntityResult updateEntities(ITypedReferenceableInstance[] iTypedReferenceableInstances) throws AtlasException;
// Trait management functions // Trait management functions
/** /**
......
/**
* 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.adapters;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.type.AtlasArrayType;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.apache.atlas.web.adapters.AtlasFormatConverters.VERSION_V1;
import static org.apache.atlas.web.adapters.AtlasFormatConverters.VERSION_V2;
public class AtlasArrayFormatConverter implements AtlasFormatAdapter {
protected AtlasFormatConverters registry;
@Inject
public void init(AtlasFormatConverters registry) throws AtlasBaseException {
this.registry = registry;
registry.registerConverter(this, AtlasFormatConverters.VERSION_V1, AtlasFormatConverters.VERSION_V2);
registry.registerConverter(this, AtlasFormatConverters.VERSION_V2, AtlasFormatConverters.VERSION_V1);
}
@Override
public TypeCategory getTypeCategory() {
return TypeCategory.ARRAY;
}
@Override
public Object convert(String sourceVersion, String targetVersion, AtlasType type, final Object source) throws AtlasBaseException {
Collection newCollection = null;
if ( source != null ) {
if (AtlasFormatConverters.isArrayListType(source.getClass())) {
newCollection = new ArrayList();
} else if (AtlasFormatConverters.isSetType(source.getClass())) {
newCollection = new LinkedHashSet();
}
AtlasArrayType arrType = (AtlasArrayType) type;
AtlasType elemType = arrType.getElementType();
Collection originalList = (Collection) source;
for (Object elem : originalList) {
AtlasFormatAdapter elemConverter = registry.getConverter(sourceVersion, targetVersion, elemType.getTypeCategory());
Object convertedVal = elemConverter.convert(sourceVersion, targetVersion, elemType, elem);
newCollection.add(convertedVal);
}
}
return newCollection;
}
}
/**
* 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.adapters;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import javax.inject.Inject;
public class AtlasEnumFormatConverter extends AtlasPrimitiveFormatConverter {
@Inject
public void init(AtlasFormatConverters registry) throws AtlasBaseException {
super.init(registry);
}
@Override
public TypeCategory getTypeCategory() {
return TypeCategory.ENUM;
}
}
/**
* 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.adapters;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.type.AtlasType;
public interface AtlasFormatAdapter {
Object convert(String sourceVersion, String targetVersion, AtlasType type, Object source) throws AtlasBaseException;
TypeCategory getTypeCategory();
}
/**
* 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.adapters;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@Singleton
public class AtlasFormatConverters {
public static String VERSION_V1 = "v1";
public static String VERSION_V2 = "v2";
private Map<String, AtlasFormatAdapter> registry = new HashMap<>();
public void registerConverter(AtlasFormatAdapter adapter, String sourceVersion, String targetVersion) {
registry.put(getKey(sourceVersion, targetVersion, adapter.getTypeCategory()), adapter);
}
public AtlasFormatAdapter getConverter(String sourceVersion, String targetVersion, TypeCategory typeCategory) throws AtlasBaseException {
if (registry.containsKey(getKey(sourceVersion, targetVersion, typeCategory))) {
return registry.get(getKey(sourceVersion, targetVersion, typeCategory));
}
throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, "Could not find the converter for this type " + typeCategory);
}
public static boolean isArrayListType(Class c) {
return List.class.isAssignableFrom(c);
}
public static boolean isSetType(Class c) {
return Set.class.isAssignableFrom(c);
}
public static boolean isPrimitiveType(final Class c) {
if (c != null) {
if (Number.class.isAssignableFrom(c)) {
return true;
}
if (String.class.isAssignableFrom(c)) {
return true;
}
if (Date.class.isAssignableFrom(c)) {
return true;
}
return c.isPrimitive();
}
return false;
}
public static boolean isMapType(Object o) {
if ( o != null ) {
return Map.class.isAssignableFrom(o.getClass());
}
return false;
}
String getKey(String sourceVersion, String targetVersion, TypeCategory typeCategory) {
return sourceVersion + "-to-" + targetVersion + "-" + typeCategory.name();
}
}
/**
* 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.adapters;
import com.google.inject.AbstractModule;
import com.google.inject.multibindings.Multibinder;
import org.apache.atlas.web.adapters.v1.ReferenceableToAtlasEntityConverter;
import org.apache.atlas.web.adapters.v1.StructToAtlasStructConverter;
import org.apache.atlas.web.adapters.v1.TraitToAtlasClassificationConverter;
import org.apache.atlas.web.adapters.v2.AtlasClassificationToTraitConverter;
import org.apache.atlas.web.adapters.v2.AtlasEntityToReferenceableConverter;
import org.apache.atlas.web.adapters.v2.AtlasStructToStructConverter;
public class AtlasFormatConvertersModule extends AbstractModule {
protected void configure() {
Multibinder<AtlasFormatAdapter> multibinder
= Multibinder.newSetBinder(binder(), AtlasFormatAdapter.class);
multibinder.addBinding().to(AtlasStructToStructConverter.class).asEagerSingleton();
multibinder.addBinding().to(AtlasEntityToReferenceableConverter.class).asEagerSingleton();
multibinder.addBinding().to(AtlasClassificationToTraitConverter.class).asEagerSingleton();
multibinder.addBinding().to(AtlasPrimitiveFormatConverter.class).asEagerSingleton();
multibinder.addBinding().to(AtlasEnumFormatConverter.class).asEagerSingleton();
multibinder.addBinding().to(AtlasMapFormatConverter.class).asEagerSingleton();
multibinder.addBinding().to(AtlasArrayFormatConverter.class).asEagerSingleton();
multibinder.addBinding().to(ReferenceableToAtlasEntityConverter.class).asEagerSingleton();
multibinder.addBinding().to(StructToAtlasStructConverter.class).asEagerSingleton();
multibinder.addBinding().to(TraitToAtlasClassificationConverter.class).asEagerSingleton();
}
}
\ 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.adapters;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
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.AtlasEntityWithAssociations;
import org.apache.atlas.model.instance.EntityMutationResponse;
import org.apache.atlas.model.instance.EntityMutations;
import org.apache.atlas.services.MetadataService;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.IReferenceableInstance;
import org.apache.atlas.typesystem.IStruct;
import org.apache.atlas.typesystem.ITypedReferenceableInstance;
import org.apache.atlas.typesystem.ITypedStruct;
import org.apache.atlas.typesystem.Referenceable;
import org.apache.atlas.typesystem.Struct;
import org.apache.atlas.typesystem.exception.EntityNotFoundException;
import org.apache.atlas.typesystem.exception.TypeNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
@Singleton
public class AtlasInstanceRestAdapters {
private static final Logger LOG = LoggerFactory.getLogger(AtlasInstanceRestAdapters.class);
@Inject
private AtlasTypeRegistry typeRegistry;
@Inject
private AtlasFormatConverters instanceFormatters;
@Inject
private MetadataService metadataService;
public ITypedReferenceableInstance[] getITypedReferenceables(List<AtlasEntity> entities) throws AtlasBaseException {
ITypedReferenceableInstance[] entitiesInOldFormat = new ITypedReferenceableInstance[entities.size()];
for (int i = 0; i < entities.size(); i++) {
ITypedReferenceableInstance typedInstance = getITypedReferenceable(entities.get(i));
entitiesInOldFormat[i] = typedInstance;
}
return entitiesInOldFormat;
}
public ITypedReferenceableInstance getITypedReferenceable(AtlasEntity entity) throws AtlasBaseException {
AtlasFormatAdapter entityFormatter = instanceFormatters.getConverter(AtlasFormatConverters.VERSION_V2, AtlasFormatConverters.VERSION_V1, TypeCategory.ENTITY);
AtlasType entityType = typeRegistry.getType(entity.getTypeName());
Referenceable ref = (Referenceable) entityFormatter.convert(AtlasFormatConverters.VERSION_V2, AtlasFormatConverters.VERSION_V1, entityType, entity);
try {
return metadataService.getTypedReferenceableInstance(ref);
} catch (AtlasException e) {
LOG.error("Exception while getting a typed reference for the entity ", e);
throw toAtlasBaseException(e);
}
}
public Referenceable getReferenceable(AtlasEntity entity) throws AtlasBaseException {
AtlasFormatAdapter entityFormatter = instanceFormatters.getConverter(AtlasFormatConverters.VERSION_V2, AtlasFormatConverters.VERSION_V1, TypeCategory.ENTITY);
AtlasType entityType = typeRegistry.getType(entity.getTypeName());
return (Referenceable) entityFormatter.convert(AtlasFormatConverters.VERSION_V2, AtlasFormatConverters.VERSION_V1, entityType, entity);
}
public ITypedStruct getTrait(AtlasClassification classification) throws AtlasBaseException {
AtlasFormatAdapter formatter = instanceFormatters.getConverter(AtlasFormatConverters.VERSION_V2, AtlasFormatConverters.VERSION_V1, TypeCategory.CLASSIFICATION);
AtlasType clsType = typeRegistry.getType(classification.getTypeName());
Struct ref = (Struct) formatter.convert(AtlasFormatConverters.VERSION_V2, AtlasFormatConverters.VERSION_V1, clsType, classification);
try {
return metadataService.createTraitInstance(ref);
} catch (AtlasException e) {
LOG.error("Exception while getting a typed reference for the entity ", e);
throw toAtlasBaseException(e);
}
}
public AtlasClassification getClassification(IStruct classification) throws AtlasBaseException {
AtlasFormatAdapter formatter = instanceFormatters.getConverter(AtlasFormatConverters.VERSION_V1, AtlasFormatConverters.VERSION_V2, TypeCategory.CLASSIFICATION);
AtlasType clsType = typeRegistry.getType(classification.getTypeName());
return (AtlasClassification) formatter.convert(AtlasFormatConverters.VERSION_V1, AtlasFormatConverters.VERSION_V2, clsType, classification);
}
public AtlasEntityWithAssociations getAtlasEntity(IReferenceableInstance referenceable) throws AtlasBaseException {
AtlasFormatAdapter entityFormatter = instanceFormatters.getConverter(AtlasFormatConverters.VERSION_V1, AtlasFormatConverters.VERSION_V2, TypeCategory.ENTITY);
AtlasType entityType = typeRegistry.getType(referenceable.getTypeName());
return (AtlasEntityWithAssociations) entityFormatter.convert(AtlasFormatConverters.VERSION_V1, AtlasFormatConverters.VERSION_V2, entityType, referenceable);
}
public static EntityMutationResponse toEntityMutationResponse(AtlasClient.EntityResult result) {
EntityMutationResponse response = new EntityMutationResponse();
for (String guid : result.getCreatedEntities()) {
AtlasEntityHeader header = new AtlasEntityHeader();
header.setGuid(guid);
response.addEntity(EntityMutations.EntityOperation.CREATE_OR_UPDATE, header);
}
for (String guid : result.getUpdateEntities()) {
AtlasEntityHeader header = new AtlasEntityHeader();
header.setGuid(guid);
response.addEntity(EntityMutations.EntityOperation.CREATE_OR_UPDATE, header);
}
for (String guid : result.getDeletedEntities()) {
AtlasEntityHeader header = new AtlasEntityHeader();
header.setGuid(guid);
response.addEntity(EntityMutations.EntityOperation.DELETE, header);
}
return response;
}
public static AtlasBaseException toAtlasBaseException(AtlasException e) {
if ( e instanceof EntityNotFoundException) {
return new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, e);
}
if ( e instanceof TypeNotFoundException) {
return new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, e);
}
return new AtlasBaseException(e);
}
}
/**
* 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.adapters;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.type.AtlasMapType;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import javax.inject.Inject;
import java.util.HashMap;
import java.util.Map;
public class AtlasMapFormatConverter implements AtlasFormatAdapter {
protected AtlasFormatConverters registry;
@Inject
public void init(AtlasFormatConverters registry) throws AtlasBaseException {
this.registry = registry;
registry.registerConverter(this, AtlasFormatConverters.VERSION_V1, AtlasFormatConverters.VERSION_V2);
registry.registerConverter(this, AtlasFormatConverters.VERSION_V2, AtlasFormatConverters.VERSION_V1);
}
@Override
public Map convert(String sourceVersion, String targetVersion, final AtlasType type, final Object source) throws AtlasBaseException {
Map newMap = new HashMap<>();
if ( source != null) {
Map origMap = (Map) source;
for (Object key : origMap.keySet()) {
AtlasMapType mapType = (AtlasMapType) type;
AtlasType keyType = mapType.getKeyType();
AtlasType valueType = mapType.getValueType();
AtlasFormatAdapter keyConverter = registry.getConverter(sourceVersion, targetVersion, keyType.getTypeCategory());
Object convertedKey = keyConverter.convert(sourceVersion, targetVersion, keyType, key);
Object val = origMap.get(key);
if (val != null) {
AtlasFormatAdapter valueConverter = registry.getConverter(sourceVersion, targetVersion, valueType.getTypeCategory());
newMap.put(convertedKey, valueConverter.convert(sourceVersion, targetVersion, valueType, val));
} else {
newMap.put(convertedKey, val);
}
}
}
return newMap;
}
@Override
public TypeCategory getTypeCategory() {
return TypeCategory.MAP;
}
}
/**
* 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.adapters;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import javax.inject.Inject;
import java.util.HashMap;
import java.util.Map;
public class AtlasPrimitiveFormatConverter implements AtlasFormatAdapter {
protected AtlasFormatConverters registry;
@Inject
public void init(AtlasFormatConverters registry) throws AtlasBaseException {
this.registry = registry;
registry.registerConverter(this, AtlasFormatConverters.VERSION_V1, AtlasFormatConverters.VERSION_V2);
registry.registerConverter(this, AtlasFormatConverters.VERSION_V2, AtlasFormatConverters.VERSION_V1);
}
@Override
public Object convert(final String sourceVersion, final String targetVersion, final AtlasType type, final Object source) throws AtlasBaseException {
return type.getNormalizedValue(source);
}
@Override
public TypeCategory getTypeCategory() {
return TypeCategory.PRIMITIVE;
}
}
/**
* 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.adapters.v1;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntityWithAssociations;
import org.apache.atlas.type.AtlasClassificationType;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.IReferenceableInstance;
import org.apache.atlas.typesystem.IStruct;
import org.apache.atlas.typesystem.persistence.Id;
import org.apache.atlas.web.adapters.AtlasFormatAdapter;
import org.apache.atlas.web.adapters.AtlasFormatConverters;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
public class ReferenceableToAtlasEntityConverter implements AtlasFormatAdapter {
protected AtlasTypeRegistry typeRegistry;
protected AtlasFormatConverters registry;
@Inject
public ReferenceableToAtlasEntityConverter(AtlasTypeRegistry typeRegistry) {
this.typeRegistry = typeRegistry;
}
@Inject
public void init(AtlasFormatConverters registry) throws AtlasBaseException {
this.registry = registry;
registry.registerConverter(this, AtlasFormatConverters.VERSION_V1, AtlasFormatConverters.VERSION_V2);
}
@Override
public Object convert(final String sourceVersion, final String targetVersion, final AtlasType type, final Object source) throws AtlasBaseException {
AtlasEntityWithAssociations result = null;
if ( source != null) {
if ( isId(source)) {
Id idObj = (Id) source;
result = new AtlasEntityWithAssociations(idObj.getTypeName());
setId(idObj, result);
} else if (isEntityType(source) ) {
IReferenceableInstance entity = (IReferenceableInstance) source;
//Resolve attributes
StructToAtlasStructConverter converter = (StructToAtlasStructConverter) registry.getConverter(sourceVersion, targetVersion, TypeCategory.STRUCT);
result = new AtlasEntityWithAssociations(entity.getTypeName(), converter.convertAttributes((AtlasEntityType) type, entity));
//Id
setId(entity, result);
//Resolve traits
List<AtlasClassification> classifications = new ArrayList<>();
for (String traitName : entity.getTraits()) {
IStruct trait = entity.getTrait(traitName);
AtlasClassificationType traitType = (AtlasClassificationType) typeRegistry.getType(traitName);
AtlasClassification clsInstance = new AtlasClassification(traitType.getTypeName(), converter.convertAttributes(traitType, trait));
classifications.add(clsInstance);
}
result.setClassifications(classifications);
}
}
return result;
}
private boolean isEntityType(Object o) {
if ( o != null && o instanceof IReferenceableInstance) {
return true;
}
return false;
}
private boolean isId(Object o) {
if ( o != null && o instanceof Id) {
return true;
}
return false;
}
@Override
public TypeCategory getTypeCategory() {
return TypeCategory.ENTITY;
}
private void setId(IReferenceableInstance entity, AtlasEntity result) {
result.setGuid(entity.getId()._getId());
}
}
/**
* 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.adapters.v1;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.apache.atlas.AtlasException;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.model.instance.AtlasStruct;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.type.AtlasClassificationType;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasStructType;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.IStruct;
import org.apache.atlas.web.adapters.AtlasFormatAdapter;
import org.apache.atlas.web.adapters.AtlasFormatConverters;
import org.apache.atlas.web.adapters.AtlasInstanceRestAdapters;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@Singleton
public class StructToAtlasStructConverter implements AtlasFormatAdapter {
protected AtlasFormatConverters registry;
@Inject
public void init(AtlasFormatConverters registry) throws AtlasBaseException {
this.registry = registry;
registry.registerConverter(this, AtlasFormatConverters.VERSION_V1, AtlasFormatConverters.VERSION_V2);
}
@Override
public Object convert(final String sourceVersion, final String targetVersion, final AtlasType type, final Object source) throws AtlasBaseException {
if (source != null) {
if (isStructType(source)) {
IStruct entity = (IStruct) source;
//Resolve attributes
StructToAtlasStructConverter converter = (StructToAtlasStructConverter) registry.getConverter(sourceVersion, targetVersion, TypeCategory.STRUCT);
return new AtlasStruct(type.getTypeName(), converter.convertAttributes((AtlasStructType) type, entity));
}
}
return null;
}
private boolean isStructType(Object o) {
if (o != null && o instanceof IStruct) {
return true;
}
return false;
}
@Override
public TypeCategory getTypeCategory() {
return TypeCategory.STRUCT;
}
public Map<String, Object> convertAttributes(AtlasStructType structType, Object entity) throws AtlasBaseException {
Collection<AtlasStructDef.AtlasAttributeDef> attributeDefs;
if (structType.getTypeCategory() == TypeCategory.STRUCT) {
attributeDefs = structType.getStructDef().getAttributeDefs();
} else if (structType.getTypeCategory() == TypeCategory.CLASSIFICATION) {
attributeDefs = ((AtlasClassificationType)structType).getAllAttributeDefs().values();
} else if (structType.getTypeCategory() == TypeCategory.ENTITY) {
attributeDefs = ((AtlasEntityType)structType).getAllAttributeDefs().values();
} else {
attributeDefs = Collections.emptyList();
}
Map<String, Object> newAttrMap = new HashMap<>();
for (AtlasStructDef.AtlasAttributeDef attrDef : attributeDefs) {
AtlasType attrType = structType.getAttributeType(attrDef.getName());
AtlasFormatAdapter attrConverter = registry.getConverter(AtlasFormatConverters.VERSION_V1, AtlasFormatConverters.VERSION_V2, attrType.getTypeCategory());
Object attrVal = null;
if ( AtlasFormatConverters.isMapType(entity)) {
attrVal = ((Map)entity).get(attrDef.getName());
} else {
try {
attrVal = ((IStruct)entity).get(attrDef.getName());
} catch (AtlasException e) {
throw AtlasInstanceRestAdapters.toAtlasBaseException(e);
}
}
final Object convertedVal = attrConverter.convert(AtlasFormatConverters.VERSION_V1, AtlasFormatConverters.VERSION_V2, attrType, attrVal);
newAttrMap.put(attrDef.getName(), convertedVal);
}
return newAttrMap;
}
}
/**
* 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.adapters.v1;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.apache.atlas.AtlasException;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.model.instance.AtlasStruct;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.type.AtlasClassificationType;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasStructType;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.IStruct;
import org.apache.atlas.web.adapters.AtlasFormatAdapter;
import org.apache.atlas.web.adapters.AtlasFormatConverters;
import org.apache.atlas.web.adapters.AtlasInstanceRestAdapters;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@Singleton
public class TraitToAtlasClassificationConverter extends StructToAtlasStructConverter {
@Inject
public void init(AtlasFormatConverters registry) throws AtlasBaseException {
super.init(registry);
}
@Override
public Object convert(final String sourceVersion, final String targetVersion, final AtlasType type, final Object source) throws AtlasBaseException {
AtlasStruct struct = (AtlasStruct) super.convert(sourceVersion, targetVersion, type, source);
if ( struct != null) {
return new AtlasClassification(struct.getTypeName(), struct.getAttributes());
}
return null;
}
@Override
public TypeCategory getTypeCategory() {
return TypeCategory.CLASSIFICATION;
}
}
/**
* 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.adapters.v2;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.model.instance.AtlasStruct;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.type.AtlasClassificationType;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasStructType;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.Struct;
import org.apache.atlas.web.adapters.AtlasFormatAdapter;
import org.apache.atlas.web.adapters.AtlasFormatConverters;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@Singleton
public class AtlasClassificationToTraitConverter extends AtlasStructToStructConverter {
@Inject
public void init(AtlasFormatConverters registry) throws AtlasBaseException {
super.init(registry);
}
@Override
public TypeCategory getTypeCategory() {
return TypeCategory.CLASSIFICATION;
}
}
/**
* 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.adapters.v2;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.typesystem.Referenceable;
import org.apache.atlas.typesystem.persistence.Id;
import org.apache.atlas.web.adapters.AtlasFormatAdapter;
import org.apache.atlas.web.adapters.AtlasFormatConverters;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import javax.inject.Inject;
import java.util.Map;
public class AtlasEntityToReferenceableConverter implements AtlasFormatAdapter {
protected AtlasFormatConverters registry;
@Inject
public void init(AtlasFormatConverters registry) throws AtlasBaseException {
this.registry = registry;
registry.registerConverter(this, AtlasFormatConverters.VERSION_V2, AtlasFormatConverters.VERSION_V1);
}
@Override
public Object convert(final String sourceVersion, final String targetVersion, final AtlasType type, final Object source) throws AtlasBaseException {
if ( source != null) {
//JSOn unmarshalling gives us a Map instead of AtlasObjectId or AtlasEntity
if ( AtlasFormatConverters.isMapType(source)) {
//Could be an entity or an Id
Map srcMap = (Map) source;
String idStr = (String)srcMap.get(AtlasObjectId.KEY_GUID);
String typeName = type.getTypeName();
if (StringUtils.isEmpty(idStr)) {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND);
}
if (MapUtils.isEmpty((Map)srcMap.get(AtlasStructToStructConverter.ATTRIBUTES_PROPERTY_KEY))) {
//Convert to Id
Id id = new Id(idStr, 0, typeName);
return id;
} else {
final Map attrMap = (Map) srcMap.get(AtlasStructToStructConverter.ATTRIBUTES_PROPERTY_KEY);
//Resolve attributes
AtlasStructToStructConverter converter = (AtlasStructToStructConverter) registry.getConverter(AtlasFormatConverters.VERSION_V2, AtlasFormatConverters.VERSION_V1, TypeCategory.STRUCT);
return new Referenceable(idStr, typeName, converter.convertAttributes((AtlasEntityType)type, attrMap));
}
} else {
if ( isEntityType(source) ) {
AtlasEntity entity = (AtlasEntity) source;
String id = entity.getGuid();
//Resolve attributes
AtlasStructToStructConverter converter = (AtlasStructToStructConverter) registry.getConverter(AtlasFormatConverters.VERSION_V2, AtlasFormatConverters.VERSION_V1, TypeCategory.STRUCT);
return new Referenceable(id, entity.getTypeName(), converter.convertAttributes((AtlasEntityType)type, entity));
} else if (isTransientId(source)) {
return new Referenceable((String) source, type.getTypeName(), null);
}
}
}
return null;
}
private boolean isEntityType(Object o) {
if ( o != null && (o instanceof AtlasEntity)) {
return true;
}
return false;
}
private boolean isTransientId(Object o) {
if ( o != null && (o instanceof String)) {
return true;
}
return false;
}
@Override
public TypeCategory getTypeCategory() {
return TypeCategory.ENTITY;
}
}
/**
* 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.adapters.v2;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.model.instance.AtlasStruct;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.type.AtlasClassificationType;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasStructType;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.typesystem.Struct;
import org.apache.atlas.web.adapters.AtlasFormatAdapter;
import org.apache.atlas.web.adapters.AtlasFormatConverters;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@Singleton
public class AtlasStructToStructConverter implements AtlasFormatAdapter {
protected AtlasFormatConverters registry;
public static final String ATTRIBUTES_PROPERTY_KEY = "attributes";
@Inject
public void init(AtlasFormatConverters registry) throws AtlasBaseException {
this.registry = registry;
registry.registerConverter(this, AtlasFormatConverters.VERSION_V2, AtlasFormatConverters.VERSION_V1);
}
@Override
public Object convert(final String sourceVersion, final String targetVersion, final AtlasType type, final Object source) throws AtlasBaseException {
if (source != null) {
//Json unmarshalling gives us a Map instead of AtlasObjectId or AtlasEntity
if (AtlasFormatConverters.isMapType(source)) {
//Could be an entity or an Id
Map srcMap = (Map) source;
final Map attrMap = (Map) srcMap.get(ATTRIBUTES_PROPERTY_KEY);
if ( attrMap != null) {
//Resolve attributes
AtlasStructToStructConverter converter = (AtlasStructToStructConverter) registry.getConverter(AtlasFormatConverters.VERSION_V2, AtlasFormatConverters.VERSION_V1, TypeCategory.STRUCT);
return new Struct(type.getTypeName(), converter.convertAttributes((AtlasStructType)type, attrMap));
}
} else if (isStructType(source)) {
AtlasStruct entity = (AtlasStruct) source;
//Resolve attributes
AtlasStructToStructConverter converter = (AtlasStructToStructConverter) registry.getConverter(AtlasFormatConverters.VERSION_V2, AtlasFormatConverters.VERSION_V1, TypeCategory.STRUCT);
return new Struct(type.getTypeName(), converter.convertAttributes((AtlasStructType) type, entity));
}
}
return null;
}
private boolean isStructType(Object o) {
if (o != null && o instanceof AtlasStruct) {
return true;
}
return false;
}
@Override
public TypeCategory getTypeCategory() {
return TypeCategory.STRUCT;
}
public Map<String, Object> convertAttributes(AtlasStructType structType, Object entity) throws AtlasBaseException {
Collection<AtlasStructDef.AtlasAttributeDef> attributeDefs;
if (structType.getTypeCategory() == TypeCategory.STRUCT) {
attributeDefs = structType.getStructDef().getAttributeDefs();
} else if (structType.getTypeCategory() == TypeCategory.CLASSIFICATION) {
attributeDefs = ((AtlasClassificationType)structType).getAllAttributeDefs().values();
} else if (structType.getTypeCategory() == TypeCategory.ENTITY) {
attributeDefs = ((AtlasEntityType)structType).getAllAttributeDefs().values();
} else {
attributeDefs = Collections.emptyList();
}
Map<String, Object> newAttrMap = new HashMap<>();
for (AtlasStructDef.AtlasAttributeDef attrDef : attributeDefs) {
AtlasType attrType = structType.getAttributeType(attrDef.getName());
AtlasFormatAdapter attrConverter = registry.getConverter(AtlasFormatConverters.VERSION_V2, AtlasFormatConverters.VERSION_V1, attrType.getTypeCategory());
Object attrVal = null;
if ( AtlasFormatConverters.isMapType(entity)) {
attrVal = ((Map)entity).get(attrDef.getName());
} else {
attrVal = ((AtlasStruct)entity).getAttribute(attrDef.getName());
}
final Object convertedVal = attrConverter.convert(AtlasFormatConverters.VERSION_V2, AtlasFormatConverters.VERSION_V1, attrType, attrVal);
newAttrMap.put(attrDef.getName(), convertedVal);
}
return newAttrMap;
}
}
...@@ -33,11 +33,11 @@ import org.apache.atlas.notification.NotificationModule; ...@@ -33,11 +33,11 @@ import org.apache.atlas.notification.NotificationModule;
import org.apache.atlas.repository.graph.AtlasGraphProvider; import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.graphdb.AtlasGraph; import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.service.Services; import org.apache.atlas.service.Services;
import org.apache.atlas.web.adapters.AtlasFormatConvertersModule;
import org.apache.atlas.web.filters.ActiveServerFilter; import org.apache.atlas.web.filters.ActiveServerFilter;
import org.apache.atlas.web.filters.AuditFilter; import org.apache.atlas.web.filters.AuditFilter;
import org.apache.atlas.web.service.ActiveInstanceElectorModule; import org.apache.atlas.web.service.ActiveInstanceElectorModule;
import org.apache.atlas.web.service.ServiceModule; import org.apache.atlas.web.service.ServiceModule;
import org.apache.commons.collections.iterators.EnumerationIterator;
import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.Configuration;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -74,7 +74,7 @@ public class GuiceServletConfig extends GuiceServletContextListener { ...@@ -74,7 +74,7 @@ public class GuiceServletConfig extends GuiceServletContextListener {
LoginProcessor loginProcessor = new LoginProcessor(); LoginProcessor loginProcessor = new LoginProcessor();
loginProcessor.login(); loginProcessor.login();
injector = Guice.createInjector(Stage.PRODUCTION, getRepositoryModule(), new ActiveInstanceElectorModule(), injector = Guice.createInjector(Stage.PRODUCTION, getRepositoryModule(), new AtlasFormatConvertersModule(), new ActiveInstanceElectorModule(),
new NotificationModule(), new ServiceModule(), new JerseyServletModule() { new NotificationModule(), new ServiceModule(), new JerseyServletModule() {
private Configuration appConfiguration = null; private Configuration appConfiguration = null;
......
...@@ -179,7 +179,7 @@ public class EntityResource { ...@@ -179,7 +179,7 @@ public class EntityResource {
response.put(AtlasClient.ENTITIES, new JSONObject(entityResult.toString()).get(AtlasClient.ENTITIES)); response.put(AtlasClient.ENTITIES, new JSONObject(entityResult.toString()).get(AtlasClient.ENTITIES));
String sampleEntityId = getSample(entityResult); String sampleEntityId = getSample(entityResult);
if (sampleEntityId != null) { if (sampleEntityId != null) {
String entityDefinition = metadataService.getEntityDefinition(sampleEntityId); String entityDefinition = metadataService.getEntityDefinitionJson(sampleEntityId);
response.put(AtlasClient.DEFINITION, new JSONObject(entityDefinition)); response.put(AtlasClient.DEFINITION, new JSONObject(entityDefinition));
} }
return response; return response;
...@@ -470,7 +470,7 @@ public class EntityResource { ...@@ -470,7 +470,7 @@ public class EntityResource {
LOG.debug("Fetching entity definition for guid={} ", guid); LOG.debug("Fetching entity definition for guid={} ", guid);
guid = ParamChecker.notEmpty(guid, "guid cannot be null"); guid = ParamChecker.notEmpty(guid, "guid cannot be null");
final String entityDefinition = metadataService.getEntityDefinition(guid); final String entityDefinition = metadataService.getEntityDefinitionJson(guid);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId()); response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
...@@ -653,7 +653,7 @@ public class EntityResource { ...@@ -653,7 +653,7 @@ public class EntityResource {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.getTraitDefinitionsForEntity(" + guid + ")"); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.getTraitDefinitionsForEntity(" + guid + ")");
} }
LOG.debug("Fetching all trait definitions for entity={}", guid); LOG.debug("Fetching all trait definitions for entity={}", guid);
final String entityDefinition = metadataService.getEntityDefinition(guid); final String entityDefinition = metadataService.getEntityDefinitionJson(guid);
Referenceable entity = InstanceSerialization.fromJsonReferenceable(entityDefinition, true); Referenceable entity = InstanceSerialization.fromJsonReferenceable(entityDefinition, true);
JSONArray traits = new JSONArray(); JSONArray traits = new JSONArray();
......
...@@ -18,19 +18,29 @@ ...@@ -18,19 +18,29 @@
package org.apache.atlas.web.rest; package org.apache.atlas.web.rest;
import com.google.inject.Inject; import com.google.inject.Inject;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.model.instance.AtlasEntity; import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntityHeader;
import org.apache.atlas.model.instance.AtlasEntityWithAssociations;
import org.apache.atlas.model.instance.EntityMutationResponse; import org.apache.atlas.model.instance.EntityMutationResponse;
import org.apache.atlas.repository.store.graph.AtlasEntityStore; import org.apache.atlas.repository.store.graph.AtlasEntityStore;
import org.apache.atlas.services.MetadataService; import org.apache.atlas.services.MetadataService;
import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.types.TypeSystem; import org.apache.atlas.typesystem.ITypedReferenceableInstance;
import org.apache.atlas.web.adapters.AtlasFormatConverters;
import org.apache.atlas.web.adapters.AtlasInstanceRestAdapters;
import org.apache.atlas.web.util.Servlets; import org.apache.atlas.web.util.Servlets;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import static org.apache.atlas.web.adapters.AtlasInstanceRestAdapters.toAtlasBaseException;
import static org.apache.atlas.web.adapters.AtlasInstanceRestAdapters.toEntityMutationResponse;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
...@@ -42,6 +52,8 @@ import javax.ws.rs.Path; ...@@ -42,6 +52,8 @@ import javax.ws.rs.Path;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
...@@ -58,14 +70,16 @@ public class EntitiesREST { ...@@ -58,14 +70,16 @@ public class EntitiesREST {
@Inject @Inject
private MetadataService metadataService; private MetadataService metadataService;
private TypeSystem typeSystem = TypeSystem.getInstance(); private AtlasTypeRegistry typeRegistry;
@Inject
AtlasInstanceRestAdapters restAdapters;
@Inject @Inject
public EntitiesREST(AtlasEntityStore entitiesStore, AtlasTypeRegistry atlasTypeRegistry) { public EntitiesREST(AtlasEntityStore entitiesStore, AtlasTypeRegistry atlasTypeRegistry) {
LOG.info("EntitiesRest Init"); LOG.info("EntitiesRest Init");
this.entitiesStore = entitiesStore; this.entitiesStore = entitiesStore;
this.typeRegistry = atlasTypeRegistry;
} }
/******* /*******
...@@ -78,7 +92,17 @@ public class EntitiesREST { ...@@ -78,7 +92,17 @@ public class EntitiesREST {
@Consumes(Servlets.JSON_MEDIA_TYPE) @Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public EntityMutationResponse createOrUpdate(List<AtlasEntity> entities) throws AtlasBaseException { public EntityMutationResponse createOrUpdate(List<AtlasEntity> entities) throws AtlasBaseException {
return null; EntityMutationResponse response = null;
ITypedReferenceableInstance[] entitiesInOldFormat = restAdapters.getITypedReferenceables(entities);
try {
final AtlasClient.EntityResult result = metadataService.updateEntities(entitiesInOldFormat);
response = toEntityMutationResponse(result);
} catch (AtlasException e) {
LOG.error("Exception while getting a typed reference for the entity ", e);
throw AtlasInstanceRestAdapters.toAtlasBaseException(e);
}
return response;
} }
/******* /*******
...@@ -90,15 +114,35 @@ public class EntitiesREST { ...@@ -90,15 +114,35 @@ public class EntitiesREST {
@Consumes(Servlets.JSON_MEDIA_TYPE) @Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public EntityMutationResponse update(List<AtlasEntity> entities) throws AtlasBaseException { public EntityMutationResponse update(List<AtlasEntity> entities) throws AtlasBaseException {
return null; return createOrUpdate(entities);
} }
@GET @GET
@Path("/guids") @Path("/guids")
@Consumes(Servlets.JSON_MEDIA_TYPE) @Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public EntityMutationResponse getById(@QueryParam("guid") List<String> guids) throws AtlasBaseException { public AtlasEntity.AtlasEntities getById(@QueryParam("guid") List<String> guids) throws AtlasBaseException {
return null;
if (CollectionUtils.isEmpty(guids)) {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guids);
}
AtlasEntity.AtlasEntities entities = new AtlasEntity.AtlasEntities();
List<AtlasEntity> entityList = new ArrayList<>();
for (String guid : guids) {
try {
ITypedReferenceableInstance ref = metadataService.getEntityDefinition(guid);
AtlasEntity entity = restAdapters.getAtlasEntity(ref);
entityList.add(entity);
} catch (AtlasException e) {
throw toAtlasBaseException(e);
}
}
entities.setList(entityList);
return entities;
} }
/******* /*******
...@@ -109,8 +153,17 @@ public class EntitiesREST { ...@@ -109,8 +153,17 @@ public class EntitiesREST {
@Path("/guids") @Path("/guids")
@Consumes(Servlets.JSON_MEDIA_TYPE) @Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public EntityMutationResponse deleteById(@QueryParam("guid") List<String> guids) throws AtlasBaseException { public EntityMutationResponse deleteById(@QueryParam("guid") final List<String> guids) throws AtlasBaseException {
return null;
if (CollectionUtils.isEmpty(guids)) {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guids);
}
try {
AtlasClient.EntityResult result = metadataService.deleteEntities(guids);
return toEntityMutationResponse(result);
} catch (AtlasException e) {
throw toAtlasBaseException(e);
}
} }
/** /**
...@@ -120,8 +173,9 @@ public class EntitiesREST { ...@@ -120,8 +173,9 @@ public class EntitiesREST {
*/ */
@GET @GET
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasEntity.AtlasEntities searchEntities() throws AtlasBaseException { public AtlasEntityHeader.AtlasEntityHeaders searchEntities() throws AtlasBaseException {
//SearchFilter searchFilter //SearchFilter searchFilter
//TODO: Need to handle getEntitiesByType for older API
return null; return 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
*
* 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.adapters;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.RepositoryMetadataModule;
import org.apache.atlas.RequestContext;
import org.apache.atlas.TestUtilsV2;
import org.apache.atlas.model.instance.AtlasEntity;
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.AtlasTypesDef;
import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.store.AtlasTypeDefStore;
import org.apache.atlas.web.rest.EntitiesREST;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import javax.inject.Inject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Guice(modules = {AtlasFormatConvertersModule.class, RepositoryMetadataModule.class})
public class TestEntitiesREST {
private static final Logger LOG = LoggerFactory.getLogger(TestEntitiesREST.class);
@Inject
private AtlasTypeDefStore typeStore;
@Inject
private EntitiesREST entitiesREST;
private List<String> createdGuids = new ArrayList<>();
private AtlasEntity dbEntity;
private AtlasEntity tableEntity;
private List<AtlasEntity> columns;
@BeforeClass
public void setUp() throws Exception {
AtlasTypesDef typesDef = TestUtilsV2.defineHiveTypes();
typeStore.createTypesDef(typesDef);
dbEntity = TestUtilsV2.createDBEntity();
tableEntity = TestUtilsV2.createTableEntity(dbEntity.getGuid());
final AtlasEntity colEntity = TestUtilsV2.createColumnEntity();
columns = new ArrayList<AtlasEntity>() {{ add(colEntity); }};
tableEntity.setAttribute("columns", columns);
}
@AfterMethod
public void cleanup() throws Exception {
RequestContext.clear();
}
@AfterClass
public void tearDown() throws Exception {
AtlasGraphProvider.cleanup();
}
@Test
public void testCreateOrUpdateEntities() throws Exception {
List<AtlasEntity> entities = new ArrayList<AtlasEntity>();
entities.add(dbEntity);
entities.add(tableEntity);
EntityMutationResponse response = entitiesREST.createOrUpdate(entities);
List<AtlasEntityHeader> guids = response.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE_OR_UPDATE);
Assert.assertNotNull(guids);
Assert.assertEquals(guids.size(), 3);
for (AtlasEntityHeader header : guids) {
createdGuids.add(header.getGuid());
}
}
@Test
public void testUpdateWithSerializedEntities() throws Exception {
//Check with serialization and deserialization of entity attributes for the case
// where attributes which are de-serialized into a map
AtlasEntity dbEntity = TestUtilsV2.createDBEntity();
AtlasEntity tableEntity = TestUtilsV2.createTableEntity(dbEntity.getGuid());
final AtlasEntity colEntity = TestUtilsV2.createColumnEntity();
List<AtlasEntity> columns = new ArrayList<AtlasEntity>() {{ add(colEntity); }};
tableEntity.setAttribute("columns", columns);
AtlasEntity newDBEntity = serDeserEntity(dbEntity);
AtlasEntity newTableEntity = serDeserEntity(tableEntity);
List<AtlasEntity> newEntities = new ArrayList<AtlasEntity>();
newEntities.add(newDBEntity);
newEntities.add(newTableEntity);
EntityMutationResponse response2 = entitiesREST.createOrUpdate(newEntities);
List<AtlasEntityHeader> newGuids = response2.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE_OR_UPDATE);
Assert.assertNotNull(newGuids);
Assert.assertEquals(newGuids.size(), 3);
}
@Test(dependsOnMethods = "testCreateOrUpdateEntities")
public void testGetEntities() throws Exception {
final AtlasEntity.AtlasEntities response = entitiesREST.getById(createdGuids);
final List<AtlasEntity> entities = response.getList();
Assert.assertNotNull(entities);
Assert.assertEquals(entities.size(), 3);
verifyAttributes(entities);
}
@Test(dependsOnMethods = "testGetEntities")
public void testDeleteEntities() throws Exception {
final EntityMutationResponse response = entitiesREST.deleteById(createdGuids);
final List<AtlasEntityHeader> entities = response.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE);
Assert.assertNotNull(entities);
Assert.assertEquals(entities.size(), 3);
}
private void verifyAttributes(List<AtlasEntity> retrievedEntities) throws Exception {
AtlasEntity retrievedDBEntity = null;
AtlasEntity retrievedTableEntity = null;
AtlasEntity retrievedColumnEntity = null;
for (AtlasEntity entity: retrievedEntities ) {
if ( entity.getTypeName().equals(TestUtilsV2.DATABASE_TYPE)) {
retrievedDBEntity = entity;
}
if ( entity.getTypeName().equals(TestUtilsV2.TABLE_TYPE)) {
retrievedTableEntity = entity;
}
if ( entity.getTypeName().equals(TestUtilsV2.COLUMN_TYPE)) {
retrievedColumnEntity = entity;
}
}
if ( retrievedDBEntity != null) {
LOG.info("verifying entity of type {} ", dbEntity.getTypeName());
verifyAttributes(dbEntity.getAttributes(), retrievedDBEntity.getAttributes());
}
if ( retrievedColumnEntity != null) {
LOG.info("verifying entity of type {} ", columns.get(0).getTypeName());
verifyAttributes(columns.get(0).getAttributes(), retrievedColumnEntity.getAttributes());
}
if ( retrievedTableEntity != null) {
LOG.info("verifying entity of type {} ", tableEntity.getTypeName());
//String
Assert.assertEquals(tableEntity.getAttribute(AtlasClient.NAME), retrievedTableEntity.getAttribute(AtlasClient.NAME));
//Map
Assert.assertEquals(tableEntity.getAttribute("parametersMap"), retrievedTableEntity.getAttribute("parametersMap"));
//enum
Assert.assertEquals(tableEntity.getAttribute("tableType"), retrievedTableEntity.getAttribute("tableType"));
//date
Assert.assertEquals(tableEntity.getAttribute("created"), retrievedTableEntity.getAttribute("created"));
//array of Ids
Assert.assertEquals(((List<AtlasEntity>) retrievedTableEntity.getAttribute("columns")).get(0).getGuid(), retrievedColumnEntity.getGuid());
//array of structs
Assert.assertEquals(((List<AtlasStruct>) retrievedTableEntity.getAttribute("partitions")), tableEntity.getAttribute("partitions"));
}
}
public static void verifyAttributes(Map<String, Object> sourceAttrs, Map<String, Object> targetAttributes) throws Exception {
for (String name : sourceAttrs.keySet() ) {
LOG.info("verifying attribute {} ", name);
Assert.assertEquals(targetAttributes.get(name), sourceAttrs.get(name));
}
}
AtlasEntity serDeserEntity(AtlasEntity entity) throws IOException {
//Convert from json to object and back to trigger the case where it gets translated to a map for attributes instead of AtlasEntity
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
String entityJson = mapper.writeValueAsString(entity);
//JSON from String to Object
AtlasEntity newEntity = mapper.readValue(entityJson, AtlasEntity.class);
return newEntity;
}
}
/**
* 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.adapters;
import org.apache.atlas.RepositoryMetadataModule;
import org.apache.atlas.RequestContext;
import org.apache.atlas.TestUtilsV2;
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.AtlasEntityWithAssociations;
import org.apache.atlas.model.instance.EntityMutationResponse;
import org.apache.atlas.model.instance.EntityMutations;
import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.store.AtlasTypeDefStore;
import org.apache.atlas.web.rest.EntityREST;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import org.testng.internal.Invoker;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@Guice(modules = {AtlasFormatConvertersModule.class, RepositoryMetadataModule.class})
public class TestEntityREST {
@Inject
private AtlasTypeDefStore typeStore;
@Inject
private EntityREST entityREST;
private AtlasEntity dbEntity;
private String dbGuid;
private AtlasClassification testClassification;
@BeforeClass
public void setUp() throws Exception {
AtlasTypesDef typesDef = TestUtilsV2.defineHiveTypes();
typeStore.createTypesDef(typesDef);
dbEntity = TestUtilsV2.createDBEntity();
}
@AfterClass
public void tearDown() throws Exception {
AtlasGraphProvider.cleanup();
}
@AfterMethod
public void cleanup() throws Exception {
RequestContext.clear();
}
@Test
public void testCreateOrUpdateEntity() throws Exception {
final EntityMutationResponse response = entityREST.createOrUpdate(dbEntity);
Assert.assertNotNull(response);
List<AtlasEntityHeader> entitiesMutated = response.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE_OR_UPDATE);
Assert.assertNotNull(entitiesMutated);
Assert.assertEquals(entitiesMutated.size(), 1);
Assert.assertNotNull(entitiesMutated.get(0));
dbGuid = entitiesMutated.get(0).getGuid();
Assert.assertEquals(entitiesMutated.size(), 1);
}
@Test(dependsOnMethods = "testCreateOrUpdateEntity")
public void testGetEntityById() throws Exception {
final AtlasEntity response = entityREST.getById(dbGuid);
Assert.assertNotNull(response);
TestEntitiesREST.verifyAttributes(response.getAttributes(), dbEntity.getAttributes());
}
@Test(dependsOnMethods = "testCreateOrUpdateEntity")
public void testAddAndGetClassification() throws Exception {
List<AtlasClassification> classifications = new ArrayList<>();
testClassification = new AtlasClassification(TestUtilsV2.CLASSIFICATION, new HashMap<String, Object>() {{ put("tag", "tagName"); }});
classifications.add(testClassification);
entityREST.addClassifications(dbGuid, classifications);
final AtlasClassification.AtlasClassifications retrievedClassifications = entityREST.getClassifications(dbGuid);
Assert.assertNotNull(retrievedClassifications);
final List<AtlasClassification> retrievedClassificationsList = retrievedClassifications.getList();
Assert.assertNotNull(retrievedClassificationsList);
Assert.assertEquals(classifications, retrievedClassificationsList);
final AtlasClassification retrievedClassification = entityREST.getClassification(dbGuid, TestUtilsV2.CLASSIFICATION);
Assert.assertNotNull(retrievedClassification);
Assert.assertEquals(retrievedClassification, testClassification);
}
@Test(dependsOnMethods = "testAddAndGetClassification")
public void testGetEntityWithAssociations() throws Exception {
AtlasEntityWithAssociations entity = entityREST.getWithAssociationsByGuid(dbGuid);
final List<AtlasClassification> retrievedClassifications = entity.getClassifications();
Assert.assertNotNull(retrievedClassifications);
Assert.assertEquals(new ArrayList<AtlasClassification>() {{ add(testClassification); }}, retrievedClassifications);
}
@Test(dependsOnMethods = "testGetEntityWithAssociations")
public void testDeleteClassification() throws Exception {
entityREST.deleteClassification(dbGuid, TestUtilsV2.CLASSIFICATION);
final AtlasClassification.AtlasClassifications retrievedClassifications = entityREST.getClassifications(dbGuid);
Assert.assertNotNull(retrievedClassifications);
Assert.assertEquals(retrievedClassifications.getList().size(), 0);
}
@Test(dependsOnMethods = "testDeleteClassification")
public void testDeleteEntityById() throws Exception {
EntityMutationResponse response = entityREST.deleteByGuid(dbGuid);
List<AtlasEntityHeader> entitiesMutated = response.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE);
Assert.assertNotNull(entitiesMutated);
Assert.assertEquals(entitiesMutated.get(0).getGuid(), dbGuid);
}
@Test
public void testUpdateGetDeleteEntityByUniqueAttribute() throws Exception {
AtlasEntity dbEntity = TestUtilsV2.createDBEntity();
entityREST.createOrUpdate(dbEntity);
final String prevDBName = (String) dbEntity.getAttribute(TestUtilsV2.NAME);
final String updatedDBName = "updatedDBName";
dbEntity.setAttribute(TestUtilsV2.NAME, updatedDBName);
final EntityMutationResponse response = entityREST.partialUpdateByUniqueAttribute(TestUtilsV2.DATABASE_TYPE, TestUtilsV2.NAME, prevDBName, dbEntity);
String dbGuid = response.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE_OR_UPDATE).get(0).getGuid();
Assert.assertTrue(AtlasEntity.isAssigned(dbGuid));
//Get By unique attribute
AtlasEntity entity = entityREST.getByUniqueAttribute(TestUtilsV2.DATABASE_TYPE, TestUtilsV2.NAME, updatedDBName);
Assert.assertNotNull(entity);
Assert.assertNotNull(entity.getGuid());
Assert.assertEquals(entity.getGuid(), dbGuid);
TestEntitiesREST.verifyAttributes(entity.getAttributes(), dbEntity.getAttributes());
final EntityMutationResponse deleteResponse = entityREST.deleteByUniqueAttribute(TestUtilsV2.DATABASE_TYPE, TestUtilsV2.NAME, (String) dbEntity.getAttribute(TestUtilsV2.NAME));
Assert.assertNotNull(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE));
Assert.assertEquals(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE).size(), 1);
Assert.assertEquals(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE).get(0).getGuid(), dbGuid);
}
}
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