Commit 43639766 by Shwetha GS

ATLAS-289 updateEntity does not remove existing edge for multiplicity-one…

ATLAS-289 updateEntity does not remove existing edge for multiplicity-one reference (dkantor via shwethags)
parent c0b4975b
...@@ -9,6 +9,7 @@ ATLAS-54 Rename configs in hive hook (shwethags) ...@@ -9,6 +9,7 @@ ATLAS-54 Rename configs in hive hook (shwethags)
ATLAS-3 Mixed Index creation fails with Date types (sumasai via shwethags) ATLAS-3 Mixed Index creation fails with Date types (sumasai via shwethags)
ALL CHANGES: 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-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-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) ATLAS-301 Atlas Distribution module test is failing (yhemanth via shwethags)
......
...@@ -357,6 +357,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository { ...@@ -357,6 +357,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
if (attrTypeCategory == DataTypes.TypeCategory.PRIMITIVE) { if (attrTypeCategory == DataTypes.TypeCategory.PRIMITIVE) {
instance.set(property, value); instance.set(property, value);
} else if (attrTypeCategory == DataTypes.TypeCategory.CLASS) { } 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()); Id id = new Id(value, 0, attributeInfo.dataType().getName());
instance.set(property, id); instance.set(property, id);
} else { } else {
...@@ -373,6 +377,19 @@ public class GraphBackedMetadataRepository implements MetadataRepository { ...@@ -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) { public Id getIdFromVertex(String dataTypeName, Vertex vertex) {
return new Id(vertex.<String>getProperty(Constants.GUID_PROPERTY_KEY), return new Id(vertex.<String>getProperty(Constants.GUID_PROPERTY_KEY),
vertex.<Integer>getProperty(Constants.VERSION_PROPERTY_KEY), dataTypeName); vertex.<Integer>getProperty(Constants.VERSION_PROPERTY_KEY), dataTypeName);
...@@ -849,7 +866,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository { ...@@ -849,7 +866,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
} }
if (referenceVertex != null) { 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); Edge edge = GraphHelper.addEdge(titanGraph, instanceVertex, referenceVertex, propertyKey);
return String.valueOf(edge.getId()); return String.valueOf(edge.getId());
} }
......
...@@ -114,7 +114,8 @@ public final class TestUtils { ...@@ -114,7 +114,8 @@ public final class TestUtils {
createOptionalAttrDef("orgLevel", "OrgLevel"), createOptionalAttrDef("orgLevel", "OrgLevel"),
createOptionalAttrDef("address", "Address"), createOptionalAttrDef("address", "Address"),
new AttributeDefinition("department", "Department", Multiplicity.REQUIRED, false, "employees"), 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"), HierarchicalTypeDefinition<ClassType> managerTypeDef = createClassTypeDef("Manager", ImmutableList.of("Person"),
new AttributeDefinition("subordinates", String.format("array<%s>", "Person"), Multiplicity.COLLECTION, new AttributeDefinition("subordinates", String.format("array<%s>", "Person"), Multiplicity.COLLECTION,
...@@ -135,6 +136,10 @@ public final class TestUtils { ...@@ -135,6 +136,10 @@ public final class TestUtils {
Referenceable jane = new Referenceable("Manager", "SecurityClearance"); Referenceable jane = new Referenceable("Manager", "SecurityClearance");
Referenceable johnAddr = new Referenceable("Address"); Referenceable johnAddr = new Referenceable("Address");
Referenceable janeAddr = 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"); hrDept.set("name", "hr");
john.set("name", "John"); john.set("name", "John");
...@@ -149,11 +154,26 @@ public final class TestUtils { ...@@ -149,11 +154,26 @@ public final class TestUtils {
janeAddr.set("city", "Santa Clara"); janeAddr.set("city", "Santa Clara");
jane.set("address", janeAddr); 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); 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); jane.getTrait("SecurityClearance").set("level", 1);
......
...@@ -137,12 +137,12 @@ public class GraphBackedMetadataRepositoryTest { ...@@ -137,12 +137,12 @@ public class GraphBackedMetadataRepositoryTest {
Assert.fail(); Assert.fail();
} }
@Test @Test(dependsOnMethods = "testSubmitEntity")
public void testGetEntityList() throws Exception { public void testGetEntityList() throws Exception {
List<String> entityList = repositoryService.getEntityList(TestUtils.ENTITY_TYPE); List<String> entityList = repositoryService.getEntityList(TestUtils.ENTITY_TYPE);
System.out.println("entityList = " + entityList); System.out.println("entityList = " + entityList);
Assert.assertNotNull(entityList); Assert.assertNotNull(entityList);
Assert.assertEquals(entityList.size(), 1); // one department Assert.assertTrue(entityList.contains(guid));
} }
@Test @Test
...@@ -472,6 +472,36 @@ public class GraphBackedMetadataRepositoryTest { ...@@ -472,6 +472,36 @@ public class GraphBackedMetadataRepositoryTest {
Assert.assertEquals(row.get("typeName"), "Person"); 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 { private ITypedReferenceableInstance createHiveTableInstance(Referenceable databaseInstance) throws Exception {
Referenceable tableInstance = new Referenceable(TestUtils.TABLE_TYPE, TestUtils.CLASSIFICATION); Referenceable tableInstance = new Referenceable(TestUtils.TABLE_TYPE, TestUtils.CLASSIFICATION);
tableInstance.set("name", TestUtils.TABLE_NAME); tableInstance.set("name", TestUtils.TABLE_NAME);
......
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