You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by su...@apache.org on 2017/02/15 00:37:16 UTC
[2/2] incubator-atlas git commit: ATLAS-1547 Add tests for
DeleteHandlerV1 (sumasai via mneethiraj)
ATLAS-1547 Add tests for DeleteHandlerV1 (sumasai via mneethiraj)
Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/aa67f8ae
Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/aa67f8ae
Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/aa67f8ae
Branch: refs/heads/master
Commit: aa67f8aee8eac8effbe2e9f4a27a28a4a32b8285
Parents: c7540b3
Author: Suma Shivaprasad <su...@gmail.com>
Authored: Tue Feb 14 13:03:43 2017 -0800
Committer: Suma Shivaprasad <su...@gmail.com>
Committed: Tue Feb 14 14:06:24 2017 -0800
----------------------------------------------------------------------
addons/models/0030-hive_model.json | 4 +-
.../atlas/model/instance/AtlasEntityHeader.java | 8 +
.../atlas/model/instance/AtlasStruct.java | 2 +-
.../model/instance/EntityMutationResponse.java | 109 ++-
.../atlas/model/typedef/AtlasStructDef.java | 2 -
.../test/java/org/apache/atlas/TestUtilsV2.java | 87 +-
.../atlas/repository/graph/GraphHelper.java | 6 +-
.../store/graph/v1/AtlasEntityStoreV1.java | 101 ++-
.../store/graph/v1/DeleteHandlerV1.java | 93 ++-
.../store/graph/v1/EntityGraphMapper.java | 6 +-
.../store/graph/v1/HardDeleteHandlerV1.java | 2 +-
.../store/graph/v1/SoftDeleteHandlerV1.java | 17 +-
.../graph/v1/AtlasDeleteHandlerV1Test.java | 791 +++++++++++++++++++
.../store/graph/v1/AtlasEntityStoreV1Test.java | 4 +-
.../store/graph/v1/SoftDeleteHandlerV1Test.java | 198 +++++
.../java/org/apache/atlas/RequestContextV1.java | 4 +-
16 files changed, 1312 insertions(+), 122 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/aa67f8ae/addons/models/0030-hive_model.json
----------------------------------------------------------------------
diff --git a/addons/models/0030-hive_model.json b/addons/models/0030-hive_model.json
index 33ba156..b359ea8 100644
--- a/addons/models/0030-hive_model.json
+++ b/addons/models/0030-hive_model.json
@@ -320,7 +320,7 @@
}
],
"isIndexable": false,
- "isOptional": false,
+ "isOptional": true,
"isUnique": false
},
{
@@ -483,7 +483,7 @@
}
],
"isIndexable": false,
- "isOptional": false,
+ "isOptional": true,
"isUnique": false
}
]
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/aa67f8ae/intg/src/main/java/org/apache/atlas/model/instance/AtlasEntityHeader.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/model/instance/AtlasEntityHeader.java b/intg/src/main/java/org/apache/atlas/model/instance/AtlasEntityHeader.java
index 93a77e0..94b3aa6 100644
--- a/intg/src/main/java/org/apache/atlas/model/instance/AtlasEntityHeader.java
+++ b/intg/src/main/java/org/apache/atlas/model/instance/AtlasEntityHeader.java
@@ -33,6 +33,8 @@ import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.PUBLIC_ONLY;
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.map.annotate.JsonSerialize;
@@ -189,4 +191,10 @@ public class AtlasEntityHeader extends AtlasStruct implements Serializable {
super(list, startIndex, pageSize, totalCount, sortType, sortBy);
}
}
+
+ @JsonIgnore
+ public AtlasObjectId getAtlasObjectId() {
+ return new AtlasObjectId(getGuid(), getTypeName());
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/aa67f8ae/intg/src/main/java/org/apache/atlas/model/instance/AtlasStruct.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/model/instance/AtlasStruct.java b/intg/src/main/java/org/apache/atlas/model/instance/AtlasStruct.java
index 4e3c795..7c8ae2d 100644
--- a/intg/src/main/java/org/apache/atlas/model/instance/AtlasStruct.java
+++ b/intg/src/main/java/org/apache/atlas/model/instance/AtlasStruct.java
@@ -104,7 +104,7 @@ public class AtlasStruct implements Serializable {
public boolean hasAttribute(String name) {
Map<String, Object> a = this.attributes;
- return a != null ? a.containsKey(name) : null;
+ return a != null ? a.containsKey(name) : false;
}
public Object getAttribute(String name) {
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/aa67f8ae/intg/src/main/java/org/apache/atlas/model/instance/EntityMutationResponse.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/model/instance/EntityMutationResponse.java b/intg/src/main/java/org/apache/atlas/model/instance/EntityMutationResponse.java
index 2f2d44f..74acfdc 100644
--- a/intg/src/main/java/org/apache/atlas/model/instance/EntityMutationResponse.java
+++ b/intg/src/main/java/org/apache/atlas/model/instance/EntityMutationResponse.java
@@ -54,7 +54,7 @@ public class EntityMutationResponse {
this.entitiesMutated = opVsEntityMap;
}
- public Map<EntityMutations.EntityOperation, List<AtlasEntityHeader>> getEntitiesMutated() {
+ public Map<EntityMutations.EntityOperation, List<AtlasEntityHeader>> getMutatedEntities() {
return entitiesMutated;
}
@@ -69,6 +69,27 @@ public class EntityMutationResponse {
return null;
}
+ public List<AtlasEntityHeader> getCreatedEntities() {
+ if ( entitiesMutated != null) {
+ return entitiesMutated.get(EntityMutations.EntityOperation.CREATE);
+ }
+ return null;
+ }
+
+ public List<AtlasEntityHeader> getUpdatedEntities() {
+ if ( entitiesMutated != null) {
+ return entitiesMutated.get(EntityMutations.EntityOperation.UPDATE);
+ }
+ return null;
+ }
+
+ public List<AtlasEntityHeader> getDeletedEntities() {
+ if ( entitiesMutated != null) {
+ return entitiesMutated.get(EntityMutations.EntityOperation.DELETE);
+ }
+ return null;
+ }
+
@JsonIgnore
public AtlasEntityHeader getFirstEntityCreated() {
final List<AtlasEntityHeader> entitiesByOperation = getEntitiesByOperation(EntityMutations.EntityOperation.CREATE);
@@ -91,30 +112,42 @@ public class EntityMutationResponse {
@JsonIgnore
public AtlasEntityHeader getFirstCreatedEntityByTypeName(String typeName) {
- final List<AtlasEntityHeader> entitiesByOperation = getEntitiesByOperation(EntityMutations.EntityOperation.CREATE);
- if ( entitiesByOperation != null && entitiesByOperation.size() > 0) {
- for (AtlasEntityHeader header : entitiesByOperation) {
- if ( header.getTypeName().equals(typeName)) {
- return header;
- }
- }
- }
+ return getFirstEntityByType(getEntitiesByOperation(EntityMutations.EntityOperation.CREATE), typeName);
+ }
- return null;
+ @JsonIgnore
+ public AtlasEntityHeader getFirstDeletedEntityByTypeName(String typeName) {
+ return getFirstEntityByType(getEntitiesByOperation(EntityMutations.EntityOperation.DELETE), typeName);
}
@JsonIgnore
- public AtlasEntityHeader getFirstUpdatedEntityByTypeName(String typeName) {
- final List<AtlasEntityHeader> entitiesByOperation = getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE);
- if ( entitiesByOperation != null && entitiesByOperation.size() > 0) {
- for (AtlasEntityHeader header : entitiesByOperation) {
- if ( header.getTypeName().equals(typeName)) {
- return header;
- }
- }
- }
+ public List<AtlasEntityHeader> getCreatedEntitiesByTypeName(String typeName) {
+ return getEntitiesByType(getEntitiesByOperation(EntityMutations.EntityOperation.CREATE), typeName);
+ }
- return null;
+ @JsonIgnore
+ public AtlasEntityHeader getCreatedEntityByTypeNameAndAttribute(String typeName, String attrName, String attrVal) {
+ return getEntityByTypeAndUniqueAttribute(getEntitiesByOperation(EntityMutations.EntityOperation.CREATE), typeName, attrName, attrVal);
+ }
+
+ @JsonIgnore
+ public AtlasEntityHeader getUpdatedEntityByTypeNameAndAttribute(String typeName, String attrName, String attrVal) {
+ return getEntityByTypeAndUniqueAttribute(getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE), typeName, attrName, attrVal);
+ }
+
+ @JsonIgnore
+ public List<AtlasEntityHeader> getUpdatedEntitiesByTypeName(String typeName) {
+ return getEntitiesByType(getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE), typeName);
+ }
+
+ @JsonIgnore
+ public List<AtlasEntityHeader> getDeletedEntitiesByTypeName(String typeName) {
+ return getEntitiesByType(getEntitiesByOperation(EntityMutations.EntityOperation.DELETE), typeName);
+ }
+
+ @JsonIgnore
+ public AtlasEntityHeader getFirstUpdatedEntityByTypeName(String typeName) {
+ return getFirstEntityByType(getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE), typeName);
}
public void addEntity(EntityMutations.EntityOperation op, AtlasEntityHeader header) {
@@ -162,6 +195,42 @@ public class EntityMutationResponse {
return toString(new StringBuilder()).toString();
}
+ private AtlasEntityHeader getFirstEntityByType(List<AtlasEntityHeader> entitiesByOperation, String typeName) {
+ if ( entitiesByOperation != null && entitiesByOperation.size() > 0) {
+ for (AtlasEntityHeader header : entitiesByOperation) {
+ if ( header.getTypeName().equals(typeName)) {
+ return header;
+ }
+ }
+ }
+ return null;
+ }
+
+ private List<AtlasEntityHeader> getEntitiesByType(List<AtlasEntityHeader> entitiesByOperation, String typeName) {
+ List<AtlasEntityHeader> ret = new ArrayList<>();
+
+ if ( entitiesByOperation != null && entitiesByOperation.size() > 0) {
+ for (AtlasEntityHeader header : entitiesByOperation) {
+ if ( header.getTypeName().equals(typeName)) {
+ ret.add(header);
+ }
+ }
+ }
+ return ret;
+ }
+
+ private AtlasEntityHeader getEntityByTypeAndUniqueAttribute(List<AtlasEntityHeader> entitiesByOperation, String typeName, String attrName, String attrVal) {
+ if (entitiesByOperation != null && entitiesByOperation.size() > 0) {
+ for (AtlasEntityHeader header : entitiesByOperation) {
+ if (header.getTypeName().equals(typeName)) {
+ if (attrVal != null && attrVal.equals(header.getAttribute(attrName))) {
+ return header;
+ }
+ }
+ }
+ }
+ return null;
+ }
public void setGuidAssignments(Map<String,String> guidAssignments) {
this.guidAssignments = guidAssignments;
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/aa67f8ae/intg/src/main/java/org/apache/atlas/model/typedef/AtlasStructDef.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/model/typedef/AtlasStructDef.java b/intg/src/main/java/org/apache/atlas/model/typedef/AtlasStructDef.java
index 2abc30b..aee4907 100644
--- a/intg/src/main/java/org/apache/atlas/model/typedef/AtlasStructDef.java
+++ b/intg/src/main/java/org/apache/atlas/model/typedef/AtlasStructDef.java
@@ -390,8 +390,6 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
cDefs = new ArrayList<>();
this.constraints = cDefs;
- } else {
- cDefs = new ArrayList<>(cDefs);
}
cDefs.add(constraintDef);
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/aa67f8ae/intg/src/test/java/org/apache/atlas/TestUtilsV2.java
----------------------------------------------------------------------
diff --git a/intg/src/test/java/org/apache/atlas/TestUtilsV2.java b/intg/src/test/java/org/apache/atlas/TestUtilsV2.java
index f268e48..00566a1 100755
--- a/intg/src/test/java/org/apache/atlas/TestUtilsV2.java
+++ b/intg/src/test/java/org/apache/atlas/TestUtilsV2.java
@@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableSet;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
+import org.apache.atlas.model.instance.AtlasEntityHeader;
import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.model.instance.AtlasStruct;
import org.apache.atlas.model.typedef.AtlasClassificationDef;
@@ -45,6 +46,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.atlas.type.AtlasTypeUtil.createStructTypeDef;
@@ -56,6 +58,8 @@ public final class TestUtilsV2 {
public static final long TEST_DATE_IN_LONG = 1418265358440L;
+ private static AtomicInteger seq = new AtomicInteger();
+
private TestUtilsV2() {
}
@@ -87,7 +91,9 @@ public final class TestUtilsV2 {
AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"),
new AtlasAttributeDef("employees", String.format("array<%s>", "Employee"), true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, false,
- new ArrayList<AtlasConstraintDef>()));
+ new ArrayList<AtlasStructDef.AtlasConstraintDef>() {{
+ add(new AtlasStructDef.AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF));
+ }}));
AtlasEntityDef personTypeDef = AtlasTypeUtil.createClassTypeDef("Person", "Person"+_description, ImmutableSet.<String>of(),
AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"),
@@ -111,7 +117,12 @@ public final class TestUtilsV2 {
new AtlasAttributeDef("manager", "Manager", true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
- Collections.<AtlasConstraintDef>emptyList()),
+ new ArrayList<AtlasConstraintDef>() {{
+ add(new AtlasConstraintDef(
+ AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, new HashMap<String, Object>() {{
+ put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, "subordinates");
+ }}));
+ }}),
new AtlasAttributeDef("mentor", EMPLOYEE_TYPE, true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
@@ -162,7 +173,9 @@ public final class TestUtilsV2 {
AtlasTypeUtil.createOptionalAttrDef("dep-code", "string"),
new AtlasAttributeDef("employees", String.format("array<%s>", "Employee"), true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, false,
- Collections.<AtlasConstraintDef>emptyList()));
+ new ArrayList<AtlasStructDef.AtlasConstraintDef>() {{
+ add(new AtlasStructDef.AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF));
+ }}));
AtlasEntityDef personTypeDef = AtlasTypeUtil.createClassTypeDef("Person", "Person"+_description,
ImmutableSet.<String>of(),
@@ -190,7 +203,12 @@ public final class TestUtilsV2 {
new AtlasAttributeDef("manager", "Manager", true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
- Collections.<AtlasConstraintDef>emptyList()),
+ new ArrayList<AtlasConstraintDef>() {{
+ add(new AtlasConstraintDef(
+ AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, new HashMap<String, Object>() {{
+ put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, "subordinates");
+ }}));
+ }}),
new AtlasAttributeDef("mentor", EMPLOYEE_TYPE, true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
@@ -239,7 +257,9 @@ public final class TestUtilsV2 {
AtlasTypeUtil.createRequiredAttrDef("dep-code", "string"),
new AtlasAttributeDef("employees", String.format("array<%s>", "Person"), true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, false,
- Collections.<AtlasConstraintDef>emptyList()));
+ new ArrayList<AtlasStructDef.AtlasConstraintDef>() {{
+ add(new AtlasStructDef.AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF));
+ }}));
AtlasEntityDef personTypeDef = AtlasTypeUtil.createClassTypeDef("Person", "Person"+_description, ImmutableSet.<String>of(),
AtlasTypeUtil.createRequiredAttrDef("name", "string"),
@@ -253,7 +273,12 @@ public final class TestUtilsV2 {
new AtlasAttributeDef("manager", "Manager", true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
- Collections.<AtlasConstraintDef>emptyList()),
+ new ArrayList<AtlasConstraintDef>() {{
+ add(new AtlasConstraintDef(
+ AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, new HashMap<String, Object>() {{
+ put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, "subordinates");
+ }}));
+ }}),
new AtlasAttributeDef("mentor", "Person", true,
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
@@ -524,6 +549,7 @@ public final class TestUtilsV2 {
ImmutableList.of(newSuperTypeDefinition));
}
+
public static AtlasTypesDef defineHiveTypes() {
String _description = "_description";
AtlasEntityDef superTypeDefinition =
@@ -556,9 +582,9 @@ public final class TestUtilsV2 {
ImmutableSet.<String>of(),
AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"),
AtlasTypeUtil.createRequiredAttrDef("type", "string"),
- new AtlasAttributeDef("table", TABLE_TYPE,
- false,
- AtlasAttributeDef.Cardinality.SINGLE, 1, 1,
+ new AtlasAttributeDef("table", TABLE_TYPE,
+ true,
+ AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
new ArrayList<AtlasStructDef.AtlasConstraintDef>() {{
add(new AtlasStructDef.AtlasConstraintDef(
@@ -604,8 +630,8 @@ public final class TestUtilsV2 {
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasConstraintDef>emptyList()),
- new AtlasAttributeDef("table", TABLE_TYPE, false,
- AtlasAttributeDef.Cardinality.SINGLE, 1, 1,
+ new AtlasAttributeDef("table", TABLE_TYPE, true,
+ AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasConstraintDef>emptyList()),
new AtlasAttributeDef("createTime", "long", true,
@@ -686,17 +712,6 @@ public final class TestUtilsV2 {
AtlasAttributeDef.Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()
- /* TODO - Fix map validation in type store and enable this
- *
- new ArrayList<AtlasStructDef.AtlasConstraintDef>() {{
- add(new AtlasStructDef.AtlasConstraintDef(
- AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_MAPPED_FROM_REF,
- new HashMap<String, Object>() {{
- put(AtlasStructDef.AtlasConstraintDef.CONSTRAINT_PARAM_REF_ATTRIBUTE, "table");
- }}));
- }}
- *
- */
),
//map of structs
new AtlasAttributeDef("partitionsMap",
@@ -748,8 +763,12 @@ public final class TestUtilsV2 {
}
public static AtlasEntity createDBEntity() {
- AtlasEntity entity = new AtlasEntity(DATABASE_TYPE);
String dbName = RandomStringUtils.randomAlphanumeric(10);
+ return createDBEntity(dbName);
+ }
+
+ public static AtlasEntity createDBEntity(String dbName) {
+ AtlasEntity entity = new AtlasEntity(DATABASE_TYPE);
entity.setAttribute(NAME, dbName);
entity.setAttribute("description", "us db");
@@ -766,9 +785,13 @@ public final class TestUtilsV2 {
}
public static AtlasEntity createTableEntity(AtlasEntity dbEntity) {
- AtlasEntity entity = new AtlasEntity(TABLE_TYPE);
String tableName = RandomStringUtils.randomAlphanumeric(10);
- entity.setAttribute(NAME, tableName);
+ return createTableEntity(dbEntity, tableName);
+ }
+
+ public static AtlasEntity createTableEntity(AtlasEntity dbEntity, String name) {
+ AtlasEntity entity = new AtlasEntity(TABLE_TYPE);
+ entity.setAttribute(NAME, name);
entity.setAttribute("description", "random table");
entity.setAttribute("type", "type");
entity.setAttribute("tableType", "MANAGED");
@@ -813,14 +836,26 @@ public final class TestUtilsV2 {
}
public static AtlasEntity createColumnEntity(AtlasEntity tableEntity) {
+ return createColumnEntity(tableEntity, "col" + seq.addAndGet(1));
+ }
+ public static AtlasEntity createColumnEntity(AtlasEntity tableEntity, String colName) {
AtlasEntity entity = new AtlasEntity(COLUMN_TYPE);
- entity.setAttribute(NAME, RandomStringUtils.randomAlphanumeric(10));
+ entity.setAttribute(NAME, colName);
entity.setAttribute("type", "VARCHAR(32)");
entity.setAttribute("table", tableEntity.getAtlasObjectId());
return entity;
}
+ public static AtlasEntity createProcessEntity(List<AtlasObjectId> inputs, List<AtlasObjectId> outputs) {
+
+ AtlasEntity entity = new AtlasEntity(PROCESS_TYPE);
+ entity.setAttribute(NAME, RandomStringUtils.randomAlphanumeric(10));
+ entity.setAttribute("inputs", inputs);
+ entity.setAttribute("outputs", outputs);
+ return entity;
+ }
+
public static List<AtlasClassificationDef> getClassificationWithValidSuperType() {
AtlasClassificationDef securityClearanceTypeDef =
AtlasTypeUtil.createTraitTypeDef("SecurityClearance1", "SecurityClearance_description", ImmutableSet.<String>of(),
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/aa67f8ae/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java b/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java
index 69b22ff..d7bffff 100755
--- a/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java
+++ b/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java
@@ -540,8 +540,7 @@ public final class GraphHelper {
*
* @return propertyValue to AtlasVertex map with the result.
*/
- public Map<String, AtlasVertex> getVerticesForPropertyValues(String property, List<String> values)
- throws RepositoryException {
+ public Map<String, AtlasVertex> getVerticesForPropertyValues(String property, List<String> values) {
if(values.isEmpty()) {
return Collections.emptyMap();
@@ -581,8 +580,7 @@ public final class GraphHelper {
*
* @return GUID to AtlasVertex map with the result.
*/
- public Map<String, AtlasVertex> getVerticesForGUIDs(List<String> guids)
- throws RepositoryException {
+ public Map<String, AtlasVertex> getVerticesForGUIDs(List<String> guids) {
return getVerticesForPropertyValues(Constants.GUID_PROPERTY_KEY, guids);
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/aa67f8ae/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java
index c6a7206..34c10f4 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java
@@ -21,24 +21,35 @@ package org.apache.atlas.repository.store.graph.v1;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.apache.atlas.AtlasErrorCode;
+import org.apache.atlas.AtlasException;
import org.apache.atlas.GraphTransaction;
+import org.apache.atlas.RequestContext;
import org.apache.atlas.RequestContextV1;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
+import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.model.instance.EntityMutationResponse;
+import org.apache.atlas.model.instance.EntityMutations;
+import org.apache.atlas.repository.graph.GraphHelper;
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.repository.store.graph.AtlasEntityStore;
import org.apache.atlas.repository.store.graph.EntityGraphDiscovery;
import org.apache.atlas.repository.store.graph.EntityGraphDiscoveryContext;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasTypeRegistry;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -47,7 +58,6 @@ import java.util.Map;
public class AtlasEntityStoreV1 implements AtlasEntityStore {
private static final Logger LOG = LoggerFactory.getLogger(AtlasEntityStoreV1.class);
-
private final DeleteHandlerV1 deleteHandler;
private final AtlasTypeRegistry typeRegistry;
@@ -101,6 +111,7 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
@GraphTransaction
public AtlasEntityWithExtInfo getByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> uniqAttributes)
throws AtlasBaseException {
+
if (LOG.isDebugEnabled()) {
LOG.debug("==> getByUniqueAttribute({}, {})", entityType.getTypeName(), uniqAttributes);
}
@@ -113,7 +124,7 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
if (ret == null) {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, entityType.getTypeName(),
- uniqAttributes.toString());
+ uniqAttributes.toString());
}
if (LOG.isDebugEnabled()) {
@@ -157,23 +168,73 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, "updateByUniqueAttributes() not implemented yet");
}
- @Override
@GraphTransaction
- public EntityMutationResponse deleteById(String guid) throws AtlasBaseException {
- throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, "deleteById() not implemented yet");
+ public EntityMutationResponse deleteById(final String guid) throws AtlasBaseException {
+
+ if (StringUtils.isEmpty(guid)) {
+ throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
+ }
+
+ // Retrieve vertices for requested guids.
+ AtlasVertex vertex = AtlasGraphUtilsV1.findByGuid(guid);
+
+ if (LOG.isDebugEnabled()) {
+ if (vertex == null) {
+ // Entity does not exist - treat as non-error, since the caller
+ // wanted to delete the entity and it's already gone.
+ LOG.debug("Deletion request ignored for non-existent entity with guid " + guid);
+ }
+ }
+
+ Collection<AtlasVertex> deletionCandidates = new ArrayList<AtlasVertex>();
+ deletionCandidates.add(vertex);
+
+ return deleteVertices(deletionCandidates);
}
@Override
@GraphTransaction
- public EntityMutationResponse deleteByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> uniqAttributes)
- throws AtlasBaseException {
- throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, "deleteByUniqueAttributes() not implemented yet");
+ public EntityMutationResponse deleteByIds(final List<String> guids) throws AtlasBaseException {
+ if (CollectionUtils.isEmpty(guids)) {
+ throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guids);
+ }
+
+ Collection<AtlasVertex> deletionCandidates = new ArrayList<>();
+
+ for (String guid : guids) {
+ // Retrieve vertices for requested guids.
+ AtlasVertex vertex = AtlasGraphUtilsV1.findByGuid(guid);
+ if (LOG.isDebugEnabled()) {
+ if (vertex == null) {
+ // Entity does not exist - treat as non-error, since the caller
+ // wanted to delete the entity and it's already gone.
+ LOG.debug("Deletion request ignored for non-existent entity with guid " + guid);
+ }
+ }
+ deletionCandidates.add(vertex);
+
+ }
+
+ if (deletionCandidates.isEmpty()) {
+ LOG.info("No deletion candidate entities were found for guids %s", guids);
+ }
+ return deleteVertices(deletionCandidates);
}
@Override
@GraphTransaction
- public EntityMutationResponse deleteByIds(List<String> guids) throws AtlasBaseException {
- throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, "deleteByIds() not implemented yet");
+ public EntityMutationResponse deleteByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> uniqAttributes)
+ throws AtlasBaseException {
+
+ if (MapUtils.isEmpty(uniqAttributes)) {
+ throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, uniqAttributes.toString());
+ }
+
+ final AtlasVertex vertex = AtlasGraphUtilsV1.findByUniqueAttributes(entityType, uniqAttributes);
+ Collection<AtlasVertex> deletionCandidates = new ArrayList<>();
+ deletionCandidates.add(vertex);
+
+ return deleteVertices(deletionCandidates);
}
@Override
@@ -216,8 +277,6 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
}
context.addUpdated(guid, entity, entityType, vertex);
-
- RequestContextV1.get().recordEntityUpdate(entity.getAtlasObjectId());
}
} else {
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entity.getTypeName());
@@ -233,10 +292,24 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
context.addCreated(guid, entity, entityType, vertex);
- RequestContextV1.get().recordEntityCreate(entity.getAtlasObjectId());
}
}
return context;
}
+
+ private EntityMutationResponse deleteVertices(Collection<AtlasVertex> deletionCandidates) throws AtlasBaseException {
+ EntityMutationResponse response = new EntityMutationResponse();
+ deleteHandler.deleteEntities(deletionCandidates);
+ RequestContextV1 req = RequestContextV1.get();
+ for (AtlasObjectId id : req.getDeletedEntityIds()) {
+ response.addEntity(EntityMutations.EntityOperation.DELETE, EntityGraphMapper.constructHeader(id));
+ }
+
+ for (AtlasObjectId id : req.getUpdatedEntityIds()) {
+ response.addEntity(EntityMutations.EntityOperation.UPDATE, EntityGraphMapper.constructHeader(id));
+ }
+
+ return response;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/aa67f8ae/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java
index 61adf2b..4d11b20 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java
@@ -25,7 +25,6 @@ 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.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graph.AtlasEdgeLabel;
@@ -34,10 +33,10 @@ import org.apache.atlas.repository.graphdb.AtlasEdge;
import org.apache.atlas.repository.graphdb.AtlasEdgeDirection;
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.type.AtlasArrayType;
-import org.apache.atlas.type.AtlasClassificationType;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasMapType;
import org.apache.atlas.type.AtlasStructType;
+import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.slf4j.Logger;
@@ -48,6 +47,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.Stack;
@@ -60,14 +60,14 @@ public abstract class DeleteHandlerV1 {
public static final Logger LOG = LoggerFactory.getLogger(DeleteHandlerV1.class);
private AtlasTypeRegistry typeRegistry;
- private boolean shouldUpdateReverseAttribute;
+ private boolean shouldUpdateInverseReferences;
private boolean softDelete;
protected static final GraphHelper graphHelper = GraphHelper.getInstance();
- public DeleteHandlerV1(AtlasTypeRegistry typeRegistry, boolean shouldUpdateReverseAttribute, boolean softDelete) {
+ public DeleteHandlerV1(AtlasTypeRegistry typeRegistry, boolean shouldUpdateInverseReference, boolean softDelete) {
this.typeRegistry = typeRegistry;
- this.shouldUpdateReverseAttribute = shouldUpdateReverseAttribute;
+ this.shouldUpdateInverseReferences = shouldUpdateInverseReference;
this.softDelete = softDelete;
}
@@ -79,21 +79,30 @@ public abstract class DeleteHandlerV1 {
* @param instanceVertices
* @throws AtlasException
*/
- public void deleteEntities(List<AtlasVertex> instanceVertices) throws AtlasBaseException {
+ public void deleteEntities(Collection<AtlasVertex> instanceVertices) throws AtlasBaseException {
RequestContextV1 requestContext = RequestContextV1.get();
Set<AtlasVertex> deletionCandidateVertices = new HashSet<>();
for (AtlasVertex instanceVertex : instanceVertices) {
- String guid = GraphHelper.getGuid(instanceVertex);
+ String guid = AtlasGraphUtilsV1.getIdFromVertex(instanceVertex);
AtlasEntity.Status state = AtlasGraphUtilsV1.getState(instanceVertex);
- if (requestContext.getDeletedEntityIds().contains(guid) || state == AtlasEntity.Status.DELETED) {
+
+ if (state == AtlasEntity.Status.DELETED) {
+ LOG.debug("Skipping deletion of {} as it is already deleted", guid);
+ continue;
+ }
+
+ String typeName = AtlasGraphUtilsV1.getTypeName(instanceVertex);
+ AtlasObjectId objId = new AtlasObjectId(guid, typeName);
+
+ if (requestContext.getDeletedEntityIds().contains(objId)) {
LOG.debug("Skipping deletion of {} as it is already deleted", guid);
continue;
}
// Get GUIDs and vertices for all deletion candidates.
- Set<GraphHelper.VertexInfo> compositeVertices = getCompositeVertices(instanceVertex);
+ Set<GraphHelper.VertexInfo> compositeVertices = getOwnedVertices(instanceVertex);
// Record all deletion candidate GUIDs in RequestContext
// and gather deletion candidate vertices.
@@ -118,19 +127,22 @@ public abstract class DeleteHandlerV1 {
* @return set of VertexInfo for all composite entities
* @throws AtlasException
*/
- public Set<GraphHelper.VertexInfo> getCompositeVertices(AtlasVertex entityVertex) throws AtlasBaseException {
- Set<GraphHelper.VertexInfo> result = new HashSet<>();
+ public Set<GraphHelper.VertexInfo> getOwnedVertices(AtlasVertex entityVertex) throws AtlasBaseException {
+ Set<GraphHelper.VertexInfo> result = new LinkedHashSet<>();
Stack<AtlasVertex> vertices = new Stack<>();
vertices.push(entityVertex);
while (vertices.size() > 0) {
AtlasVertex vertex = vertices.pop();
- String typeName = GraphHelper.getTypeName(vertex);
- String guid = GraphHelper.getGuid(vertex);
+
AtlasEntity.Status state = AtlasGraphUtilsV1.getState(vertex);
if (state == AtlasEntity.Status.DELETED) {
//If the reference vertex is marked for deletion, skip it
continue;
}
+
+ String typeName = GraphHelper.getTypeName(vertex);
+ String guid = GraphHelper.getGuid(vertex);
+
result.add(new GraphHelper.VertexInfo(guid, vertex, typeName));
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);
@@ -143,7 +155,7 @@ public abstract class DeleteHandlerV1 {
continue;
}
String edgeLabel = AtlasGraphUtilsV1.getAttributeEdgeLabel(entityType, attributeInfo.getName());
- AtlasType attrType = typeRegistry.getType(attributeInfo.getTypeName());
+ AtlasType attrType = attributeInfo.getAttributeType();
switch (attrType.getTypeCategory()) {
case OBJECT_ID_TYPE:
AtlasEdge edge = graphHelper.getEdgeForLabel(vertex, edgeLabel);
@@ -199,19 +211,19 @@ public abstract class DeleteHandlerV1 {
* Force delete is used to remove struct/trait in case of entity updates
* @param edge
* @param typeCategory
- * @param isComposite
+ * @param isOwned
* @param forceDeleteStructTrait
* @return returns true if the edge reference is hard deleted
* @throws AtlasException
*/
- public boolean deleteEdgeReference(AtlasEdge edge, TypeCategory typeCategory, boolean isComposite,
+ public boolean deleteEdgeReference(AtlasEdge edge, TypeCategory typeCategory, boolean isOwned,
boolean forceDeleteStructTrait) throws AtlasBaseException {
LOG.debug("Deleting {}", string(edge));
boolean forceDelete =
(typeCategory == TypeCategory.STRUCT || typeCategory == TypeCategory.CLASSIFICATION) && forceDeleteStructTrait;
if (typeCategory == TypeCategory.STRUCT || typeCategory == TypeCategory.CLASSIFICATION
- || (typeCategory == TypeCategory.OBJECT_ID_TYPE && isComposite)) {
+ || (typeCategory == TypeCategory.OBJECT_ID_TYPE && isOwned)) {
//If the vertex is of type struct/trait, delete the edge and then the reference vertex as the vertex is not shared by any other entities.
//If the vertex is of type class, and its composite attribute, this reference vertex' lifecycle is controlled
//through this delete, hence delete the edge and the reference vertex.
@@ -232,18 +244,19 @@ public abstract class DeleteHandlerV1 {
}
protected void deleteEdge(AtlasEdge edge, boolean updateReverseAttribute, boolean force) throws AtlasBaseException {
- //update reverse attribute
+ //update inverse attribute
if (updateReverseAttribute) {
AtlasEdgeLabel atlasEdgeLabel = new AtlasEdgeLabel(edge.getLabel());
AtlasType parentType = typeRegistry.getType(atlasEdgeLabel.getTypeName());
- if (parentType instanceof AtlasStructType) {
- AtlasStructType parentStructType = (AtlasStructType) parentType;
- //TODO - Fix this later
-// if (parentStructType.isForeignKeyAttribute(atlasEdgeLabel.getAttributeName())) {
-// deleteEdgeBetweenVertices(edge.getInVertex(), edge.getOutVertex(), atlasEdgeLabel.getAttributeName());
-// }
+ if (parentType instanceof AtlasEntityType) {
+ AtlasEntityType parentEntityType = (AtlasEntityType) parentType;
+
+ AtlasStructType.AtlasAttribute attribute = parentEntityType.getAttribute(atlasEdgeLabel.getAttributeName());
+ if (attribute.getInverseRefAttribute() != null) {
+ deleteEdgeBetweenVertices(edge.getInVertex(), edge.getOutVertex(), attribute.getInverseRefAttribute());
+ }
}
}
@@ -286,16 +299,16 @@ public abstract class DeleteHandlerV1 {
for (AtlasStructType.AtlasAttribute attributeInfo : structType.getAllAttributes().values()) {
LOG.debug("Deleting attribute {} for {}", attributeInfo.getName(), string(instanceVertex));
- boolean isComposite = isEntityType && attributeInfo.isOwnedRef();
+ boolean isOwned = isEntityType && attributeInfo.isOwnedRef();
- AtlasType attrType = typeRegistry.getType(attributeInfo.getTypeName());
+ AtlasType attrType = attributeInfo.getAttributeType();
String edgeLabel = AtlasGraphUtilsV1.getAttributeEdgeLabel(structType, attributeInfo.getName());
switch (attrType.getTypeCategory()) {
case OBJECT_ID_TYPE:
//If its class attribute, delete the reference
- deleteEdgeReference(instanceVertex, edgeLabel, attrType.getTypeCategory(), isComposite);
+ deleteEdgeReference(instanceVertex, edgeLabel, attrType.getTypeCategory(), isOwned);
break;
case STRUCT:
@@ -312,7 +325,7 @@ public abstract class DeleteHandlerV1 {
if (edges != null) {
while (edges.hasNext()) {
AtlasEdge edge = edges.next();
- deleteEdgeReference(edge, elemType.getTypeCategory(), isComposite, false);
+ deleteEdgeReference(edge, elemType.getTypeCategory(), isOwned, false);
}
}
}
@@ -330,7 +343,7 @@ public abstract class DeleteHandlerV1 {
if (keys != null) {
for (Object key : keys) {
String mapEdgeLabel = GraphHelper.getQualifiedNameForMapKey(edgeLabel, (String) key);
- deleteEdgeReference(instanceVertex, mapEdgeLabel, valueTypeCategory, isComposite);
+ deleteEdgeReference(instanceVertex, mapEdgeLabel, valueTypeCategory, isOwned);
}
}
}
@@ -342,10 +355,10 @@ public abstract class DeleteHandlerV1 {
}
public void deleteEdgeReference(AtlasVertex outVertex, String edgeLabel, TypeCategory typeCategory,
- boolean isComposite) throws AtlasBaseException {
+ boolean isOwned) throws AtlasBaseException {
AtlasEdge edge = graphHelper.getEdgeForLabel(outVertex, edgeLabel);
if (edge != null) {
- deleteEdgeReference(edge, typeCategory, isComposite, false);
+ deleteEdgeReference(edge, typeCategory, isOwned, false);
}
}
@@ -390,8 +403,11 @@ public abstract class DeleteHandlerV1 {
attributeName);
String typeName = GraphHelper.getTypeName(outVertex);
String outId = GraphHelper.getGuid(outVertex);
+
+ AtlasObjectId objId = new AtlasObjectId(outId, typeName);
AtlasEntity.Status state = AtlasGraphUtilsV1.getState(outVertex);
- if ((outId != null && RequestContextV1.get().isDeletedEntity(outId)) || state == AtlasEntity.Status.DELETED) {
+
+ if (state == AtlasEntity.Status.DELETED || (outId != null && RequestContextV1.get().isDeletedEntity(objId))) {
//If the reference vertex is marked for deletion, skip updating the reference
return;
}
@@ -401,21 +417,22 @@ public abstract class DeleteHandlerV1 {
String edgeLabel = EDGE_LABEL_PREFIX + propertyName;
AtlasEdge edge = null;
+ AtlasAttribute attribute = parentType.getAttribute(attributeName);
AtlasAttributeDef attrDef = parentType.getAttributeDef(attributeName);
- AtlasType attrType = typeRegistry.getType(attrDef.getTypeName());
+ AtlasType attrType = attribute.getAttributeType();
switch (attrType.getTypeCategory()) {
case OBJECT_ID_TYPE:
//If its class attribute, its the only edge between two vertices
if (attrDef.getIsOptional()) {
edge = graphHelper.getEdgeForLabel(outVertex, edgeLabel);
- if (shouldUpdateReverseAttribute) {
+ if (shouldUpdateInverseReferences) {
GraphHelper.setProperty(outVertex, propertyName, null);
}
} else {
// Cannot unset a required attribute.
throw new AtlasBaseException("Cannot unset required attribute " + propertyName +
- " on " + GraphHelper.getVertexDetails(outVertex) + " edge = " + edgeLabel);
+ " on " + GraphHelper.vertexString(outVertex) + " edge = " + edgeLabel);
}
break;
@@ -444,7 +461,7 @@ public abstract class DeleteHandlerV1 {
+ GraphHelper.getVertexDetails(outVertex) + " " + GraphHelper.getEdgeDetails(elementEdge));
}
- if (shouldUpdateReverseAttribute) {
+ if (shouldUpdateInverseReferences) {
//if composite attribute, remove the reference as well. else, just remove the edge
//for example, when table is deleted, process still references the table
//but when column is deleted, table will not reference the deleted column
@@ -485,7 +502,7 @@ public abstract class DeleteHandlerV1 {
propertyName + " on " + GraphHelper.getVertexDetails(outVertex) + " " + GraphHelper.getEdgeDetails(mapEdge));
}
- if (shouldUpdateReverseAttribute) {
+ if (shouldUpdateInverseReferences) {
//remove this key
LOG.debug("Removing edge {}, key {} from the map attribute {}", string(mapEdge), key,
attributeName);
@@ -506,7 +523,7 @@ public abstract class DeleteHandlerV1 {
default:
throw new IllegalStateException("There can't be an edge from " + GraphHelper.getVertexDetails(outVertex) + " to "
- + GraphHelper.getVertexDetails(inVertex) + " with attribute name " + attributeName + " which is not class/array/map attribute");
+ + GraphHelper.getVertexDetails(inVertex) + " with attribute name " + attributeName + " which is not class/array/map attribute. found " + attrType.getTypeCategory().name());
}
if (edge != null) {
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/aa67f8ae/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java
index 072d10d..6a1b301 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java
@@ -139,6 +139,10 @@ public class EntityGraphMapper {
resp.addEntity(DELETE, constructHeader(id));
}
+ for (AtlasObjectId id : req.getUpdatedEntityIds()) {
+ resp.addEntity(UPDATE, constructHeader(id));
+ }
+
return resp;
}
@@ -744,7 +748,7 @@ public class EntityGraphMapper {
return header;
}
- private AtlasEntityHeader constructHeader(AtlasObjectId id) {
+ public static AtlasEntityHeader constructHeader(AtlasObjectId id) {
AtlasEntityHeader entity = new AtlasEntityHeader(id.getTypeName());
entity.setGuid(id.getGuid());
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/aa67f8ae/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/HardDeleteHandlerV1.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/HardDeleteHandlerV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/HardDeleteHandlerV1.java
index fe0db39..f51238a 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/HardDeleteHandlerV1.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/HardDeleteHandlerV1.java
@@ -28,7 +28,7 @@ public class HardDeleteHandlerV1 extends DeleteHandlerV1 {
@Inject
public HardDeleteHandlerV1(AtlasTypeRegistry typeRegistry) {
- super(typeRegistry, false, true);
+ super(typeRegistry, true, false);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/aa67f8ae/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java
index 7e3068b..31bb24a 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java
@@ -19,6 +19,7 @@
package org.apache.atlas.repository.store.graph.v1;
import com.google.inject.Inject;
+import org.apache.atlas.RequestContextV1;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.repository.graph.GraphHelper;
@@ -46,10 +47,10 @@ public class SoftDeleteHandlerV1 extends DeleteHandlerV1 {
} else {
AtlasEntity.Status state = AtlasGraphUtilsV1.getState(instanceVertex);
if (state != AtlasEntity.Status.DELETED) {
- GraphHelper.setProperty(instanceVertex, STATE_PROPERTY_KEY, Id.EntityState.DELETED.name());
+ GraphHelper.setProperty(instanceVertex, STATE_PROPERTY_KEY, AtlasEntity.Status.DELETED.name());
GraphHelper.setProperty(instanceVertex, MODIFICATION_TIMESTAMP_PROPERTY_KEY,
- RequestContext.get().getRequestTime());
- GraphHelper.setProperty(instanceVertex, MODIFIED_BY_KEY, RequestContext.get().getUser());
+ RequestContextV1.get().getRequestTime());
+ GraphHelper.setProperty(instanceVertex, MODIFIED_BY_KEY, RequestContextV1.get().getUser());
}
}
}
@@ -59,12 +60,12 @@ public class SoftDeleteHandlerV1 extends DeleteHandlerV1 {
if (force) {
graphHelper.removeEdge(edge);
} else {
- Id.EntityState state = GraphHelper.getState(edge);
- if (state != Id.EntityState.DELETED) {
- GraphHelper.setProperty(edge, STATE_PROPERTY_KEY, Id.EntityState.DELETED.name());
+ AtlasEntity.Status state = AtlasGraphUtilsV1.getState(edge);
+ if (state != AtlasEntity.Status.DELETED) {
+ GraphHelper.setProperty(edge, STATE_PROPERTY_KEY, AtlasEntity.Status.DELETED.name());
GraphHelper
- .setProperty(edge, MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime());
- GraphHelper.setProperty(edge, MODIFIED_BY_KEY, RequestContext.get().getUser());
+ .setProperty(edge, MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContextV1.get().getRequestTime());
+ GraphHelper.setProperty(edge, MODIFIED_BY_KEY, RequestContextV1.get().getUser());
}
}
}