You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by sh...@apache.org on 2015/11/17 11:40:55 UTC
incubator-atlas git commit: ATLAS-289 updateEntity does not remove
existing edge for multiplicity-one reference (dkantor via shwethags)
Repository: incubator-atlas
Updated Branches:
refs/heads/master c0b4975bc -> 436397660
ATLAS-289 updateEntity does not remove existing edge for multiplicity-one reference (dkantor via shwethags)
Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/43639766
Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/43639766
Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/43639766
Branch: refs/heads/master
Commit: 43639766001c0fe0e067eb50f0125e3489dc41d7
Parents: c0b4975
Author: Shwetha GS <ss...@hortonworks.com>
Authored: Tue Nov 17 16:10:38 2015 +0530
Committer: Shwetha GS <ss...@hortonworks.com>
Committed: Tue Nov 17 16:10:38 2015 +0530
----------------------------------------------------------------------
release-log.txt | 1 +
.../graph/GraphBackedMetadataRepository.java | 19 ++++++++++-
.../test/java/org/apache/atlas/TestUtils.java | 28 +++++++++++++---
.../GraphBackedMetadataRepositoryTest.java | 34 ++++++++++++++++++--
4 files changed, 75 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/43639766/release-log.txt
----------------------------------------------------------------------
diff --git a/release-log.txt b/release-log.txt
index c17579c..c630ba5 100644
--- a/release-log.txt
+++ b/release-log.txt
@@ -9,6 +9,7 @@ ATLAS-54 Rename configs in hive hook (shwethags)
ATLAS-3 Mixed Index creation fails with Date types (sumasai via shwethags)
ALL CHANGES:
+ATLAS-289 updateEntity does not remove existing edge for multiplicity-one reference (dkantor via shwethags)
ATLAS-300 Need additional integration test coverage for entity notifications (tbeerbower via shwethags)
ATLAS-304 surefire fails to run tests if maven project directory path has embedded space(dkantor via sumasai)
ATLAS-301 Atlas Distribution module test is failing (yhemanth via shwethags)
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/43639766/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java
index ae92b29..6a620b5 100755
--- a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java
+++ b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java
@@ -357,6 +357,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
if (attrTypeCategory == DataTypes.TypeCategory.PRIMITIVE) {
instance.set(property, value);
} else if (attrTypeCategory == DataTypes.TypeCategory.CLASS) {
+
+ // Disconnect any existing reference to the previous reference target.
+ disconnectClassReference(instanceVertex, attributeInfo, instance);
+
Id id = new Id(value, 0, attributeInfo.dataType().getName());
instance.set(property, id);
} else {
@@ -373,6 +377,19 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
}
}
+ private void disconnectClassReference(Vertex instanceVertex, AttributeInfo attributeInfo,
+ ITypedReferenceableInstance instance) throws AtlasException {
+
+ String edgeLabel = getEdgeLabel(instance, attributeInfo);
+ Iterable<Edge> edges = instanceVertex.getEdges(Direction.OUT, edgeLabel);
+ if (edges != null) {
+ Iterator<Edge> it = edges.iterator();
+ if (it.hasNext()) {
+ titanGraph.removeEdge(it.next());
+ }
+ }
+ }
+
public Id getIdFromVertex(String dataTypeName, Vertex vertex) {
return new Id(vertex.<String>getProperty(Constants.GUID_PROPERTY_KEY),
vertex.<Integer>getProperty(Constants.VERSION_PROPERTY_KEY), dataTypeName);
@@ -849,7 +866,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
}
if (referenceVertex != null) {
- // add an edge to the class vertex from the instance
+ // Add an edge to the class vertex from the instance.
Edge edge = GraphHelper.addEdge(titanGraph, instanceVertex, referenceVertex, propertyKey);
return String.valueOf(edge.getId());
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/43639766/repository/src/test/java/org/apache/atlas/TestUtils.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/TestUtils.java b/repository/src/test/java/org/apache/atlas/TestUtils.java
index 214c387..564dbfe 100755
--- a/repository/src/test/java/org/apache/atlas/TestUtils.java
+++ b/repository/src/test/java/org/apache/atlas/TestUtils.java
@@ -114,7 +114,8 @@ public final class TestUtils {
createOptionalAttrDef("orgLevel", "OrgLevel"),
createOptionalAttrDef("address", "Address"),
new AttributeDefinition("department", "Department", Multiplicity.REQUIRED, false, "employees"),
- new AttributeDefinition("manager", "Manager", Multiplicity.OPTIONAL, false, "subordinates"));
+ new AttributeDefinition("manager", "Manager", Multiplicity.OPTIONAL, false, "subordinates"),
+ new AttributeDefinition("mentor", "Person", Multiplicity.OPTIONAL, false, null));
HierarchicalTypeDefinition<ClassType> managerTypeDef = createClassTypeDef("Manager", ImmutableList.of("Person"),
new AttributeDefinition("subordinates", String.format("array<%s>", "Person"), Multiplicity.COLLECTION,
@@ -135,7 +136,11 @@ public final class TestUtils {
Referenceable jane = new Referenceable("Manager", "SecurityClearance");
Referenceable johnAddr = new Referenceable("Address");
Referenceable janeAddr = new Referenceable("Address");
-
+ Referenceable julius = new Referenceable("Manager");
+ Referenceable juliusAddr = new Referenceable("Address");
+ Referenceable max = new Referenceable("Person");
+ Referenceable maxAddr = new Referenceable("Address");
+
hrDept.set("name", "hr");
john.set("name", "John");
john.set("department", hrDept);
@@ -149,11 +154,26 @@ public final class TestUtils {
janeAddr.set("city", "Santa Clara");
jane.set("address", janeAddr);
+ julius.set("name", "Julius");
+ julius.set("department", hrDept);
+ juliusAddr.set("street", "Madison Ave");
+ juliusAddr.set("city", "Newtonville");
+ julius.set("address", juliusAddr);
+ julius.set("subordinates", ImmutableList.<Referenceable>of());
+
+ max.set("name", "Max");
+ max.set("department", hrDept);
+ maxAddr.set("street", "Ripley St");
+ maxAddr.set("city", "Newton");
+ max.set("address", maxAddr);
+ max.set("manager", jane);
+ max.set("mentor", julius);
+
john.set("manager", jane);
- hrDept.set("employees", ImmutableList.of(john, jane));
+ hrDept.set("employees", ImmutableList.of(john, jane, julius, max));
- jane.set("subordinates", ImmutableList.of(john));
+ jane.set("subordinates", ImmutableList.of(john, max));
jane.getTrait("SecurityClearance").set("level", 1);
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/43639766/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepositoryTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepositoryTest.java b/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepositoryTest.java
index 39be47d..b6e62aa 100755
--- a/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepositoryTest.java
+++ b/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepositoryTest.java
@@ -137,12 +137,12 @@ public class GraphBackedMetadataRepositoryTest {
Assert.fail();
}
- @Test
+ @Test(dependsOnMethods = "testSubmitEntity")
public void testGetEntityList() throws Exception {
List<String> entityList = repositoryService.getEntityList(TestUtils.ENTITY_TYPE);
System.out.println("entityList = " + entityList);
Assert.assertNotNull(entityList);
- Assert.assertEquals(entityList.size(), 1); // one department
+ Assert.assertTrue(entityList.contains(guid));
}
@Test
@@ -471,6 +471,36 @@ public class GraphBackedMetadataRepositoryTest {
row = (JSONObject) results.get(0);
Assert.assertEquals(row.get("typeName"), "Person");
}
+
+ @Test(dependsOnMethods = "testSubmitEntity")
+ public void testUpdateEntity_MultiplicityOneNonCompositeReference() throws Exception {
+ ITypedReferenceableInstance john = repositoryService.getEntityDefinition("Person", "name", "John");
+ String johnGuid = john.getId()._getId();
+ ITypedReferenceableInstance max = repositoryService.getEntityDefinition("Person", "name", "Max");
+ String maxGuid = max.getId()._getId();
+ ITypedReferenceableInstance jane = repositoryService.getEntityDefinition("Person", "name", "Jane");
+ String janeGuid = jane.getId()._getId();
+
+ // Update max's mentor reference to john.
+ repositoryService.updateEntity(maxGuid, "mentor", johnGuid);
+
+ // Verify the update was applied correctly - john should now be max's mentor.
+ max = repositoryService.getEntityDefinition(maxGuid);
+ Object object = max.get("mentor");
+ Assert.assertTrue(object instanceof ITypedReferenceableInstance);
+ ITypedReferenceableInstance refTarget = (ITypedReferenceableInstance) object;
+ Assert.assertEquals(refTarget.getId()._getId(), johnGuid);
+
+ // Update max's mentor reference to jane.
+ repositoryService.updateEntity(maxGuid, "mentor", janeGuid);
+
+ // Verify the update was applied correctly - jane should now be max's mentor.
+ max = repositoryService.getEntityDefinition(maxGuid);
+ object = max.get("mentor");
+ Assert.assertTrue(object instanceof ITypedReferenceableInstance);
+ refTarget = (ITypedReferenceableInstance) object;
+ Assert.assertEquals(refTarget.getId()._getId(), janeGuid);
+ }
private ITypedReferenceableInstance createHiveTableInstance(Referenceable databaseInstance) throws Exception {
Referenceable tableInstance = new Referenceable(TestUtils.TABLE_TYPE, TestUtils.CLASSIFICATION);