Search in sources :

Example 1 with EntityResult

use of org.apache.atlas.model.legacy.EntityResult in project incubator-atlas by apache.

the class GraphBackedMetadataRepositoryDeleteTestBase method testLowerBoundsIgnoredOnDeletedEntities.

@Test
public void testLowerBoundsIgnoredOnDeletedEntities() throws Exception {
    String hrDeptGuid = createHrDeptGraph();
    ITypedReferenceableInstance hrDept = repositoryService.getEntityDefinition(hrDeptGuid);
    Map<String, String> nameGuidMap = getEmployeeNameGuidMap(hrDept);
    ITypedReferenceableInstance john = repositoryService.getEntityDefinition(nameGuidMap.get("John"));
    String johnGuid = john.getId()._getId();
    ITypedReferenceableInstance max = repositoryService.getEntityDefinition(nameGuidMap.get("Max"));
    String maxGuid = max.getId()._getId();
    ITypedReferenceableInstance jane = repositoryService.getEntityDefinition(nameGuidMap.get("Jane"));
    String janeGuid = jane.getId()._getId();
    // The lower bound constraint on Manager.subordinates should not be enforced on Jane since that entity is being deleted.
    // Prior to the fix for ATLAS-991, this call would fail with a NullRequiredAttributeException.
    EntityResult deleteResult = deleteEntities(johnGuid, maxGuid, janeGuid);
    Assert.assertEquals(deleteResult.getDeletedEntities().size(), 3);
    Assert.assertTrue(deleteResult.getDeletedEntities().containsAll(Arrays.asList(johnGuid, maxGuid, janeGuid)));
    Assert.assertEquals(deleteResult.getUpdateEntities().size(), 1);
    // Verify that Department entity was updated to disconnect its references to the deleted employees.
    Assert.assertEquals(deleteResult.getUpdateEntities().get(0), hrDeptGuid);
    hrDept = repositoryService.getEntityDefinition(hrDeptGuid);
    Object object = hrDept.get("employees");
    Assert.assertTrue(object instanceof List);
    List<ITypedReferenceableInstance> employees = (List<ITypedReferenceableInstance>) object;
    assertTestLowerBoundsIgnoredOnDeletedEntities(employees);
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) EntityResult(org.apache.atlas.model.legacy.EntityResult) Test(org.testng.annotations.Test)

Example 2 with EntityResult

use of org.apache.atlas.model.legacy.EntityResult in project incubator-atlas by apache.

the class GraphBackedMetadataRepositoryDeleteTestBase method testUpdateEntity_MultiplicityOneNonCompositeReference.

@Test
public void testUpdateEntity_MultiplicityOneNonCompositeReference() throws Exception {
    String hrDeptGuid = createHrDeptGraph();
    ITypedReferenceableInstance hrDept = repositoryService.getEntityDefinition(hrDeptGuid);
    Map<String, String> nameGuidMap = getEmployeeNameGuidMap(hrDept);
    ITypedReferenceableInstance john = repositoryService.getEntityDefinition(nameGuidMap.get("John"));
    Id johnGuid = john.getId();
    ITypedReferenceableInstance max = repositoryService.getEntityDefinition(nameGuidMap.get("Max"));
    String maxGuid = max.getId()._getId();
    AtlasVertex vertex = GraphHelper.getInstance().getVertexForGUID(maxGuid);
    Long creationTimestamp = GraphHelper.getSingleValuedProperty(vertex, Constants.TIMESTAMP_PROPERTY_KEY, Long.class);
    Assert.assertNotNull(creationTimestamp);
    Long modificationTimestampPreUpdate = GraphHelper.getSingleValuedProperty(vertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class);
    Assert.assertNotNull(modificationTimestampPreUpdate);
    ITypedReferenceableInstance jane = repositoryService.getEntityDefinition(nameGuidMap.get("Jane"));
    Id janeId = jane.getId();
    // Update max's mentor reference to john.
    ClassType personType = typeSystem.getDataType(ClassType.class, "Person");
    ITypedReferenceableInstance maxEntity = personType.createInstance(max.getId());
    maxEntity.set("mentor", johnGuid);
    EntityResult entityResult = updatePartial(maxEntity);
    assertEquals(entityResult.getUpdateEntities().size(), 1);
    assertTrue(entityResult.getUpdateEntities().contains(maxGuid));
    // Verify the update was applied correctly - john should now be max's mentor.
    max = repositoryService.getEntityDefinition(maxGuid);
    ITypedReferenceableInstance refTarget = (ITypedReferenceableInstance) max.get("mentor");
    Assert.assertEquals(refTarget.getId()._getId(), johnGuid._getId());
    // Verify modification timestamp was updated.
    vertex = GraphHelper.getInstance().getVertexForGUID(maxGuid);
    Long modificationTimestampPostUpdate = GraphHelper.getSingleValuedProperty(vertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class);
    Assert.assertNotNull(modificationTimestampPostUpdate);
    Assert.assertTrue(creationTimestamp < modificationTimestampPostUpdate);
    // Update max's mentor reference to jane.
    maxEntity.set("mentor", janeId);
    entityResult = updatePartial(maxEntity);
    assertEquals(entityResult.getUpdateEntities().size(), 1);
    assertTrue(entityResult.getUpdateEntities().contains(maxGuid));
    // Verify the update was applied correctly - jane should now be max's mentor.
    max = repositoryService.getEntityDefinition(maxGuid);
    refTarget = (ITypedReferenceableInstance) max.get("mentor");
    Assert.assertEquals(refTarget.getId()._getId(), janeId._getId());
    // Verify modification timestamp was updated.
    vertex = GraphHelper.getInstance().getVertexForGUID(maxGuid);
    Long modificationTimestampPost2ndUpdate = GraphHelper.getSingleValuedProperty(vertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class);
    Assert.assertNotNull(modificationTimestampPost2ndUpdate);
    Assert.assertTrue(modificationTimestampPostUpdate < modificationTimestampPost2ndUpdate);
    ITypedReferenceableInstance julius = repositoryService.getEntityDefinition(nameGuidMap.get("Julius"));
    Id juliusId = julius.getId();
    maxEntity = personType.createInstance(max.getId());
    maxEntity.set("manager", juliusId);
    entityResult = updatePartial(maxEntity);
    // Verify julius' subordinates were updated.
    assertEquals(entityResult.getUpdateEntities().size(), 3);
    assertTrue(entityResult.getUpdateEntities().contains(maxGuid));
    assertTrue(entityResult.getUpdateEntities().containsAll(Arrays.asList(maxGuid, janeId._getId(), juliusId._getId())));
    // Verify the update was applied correctly - julius should now be max's manager.
    max = repositoryService.getEntityDefinition(maxGuid);
    refTarget = (ITypedReferenceableInstance) max.get("manager");
    Assert.assertEquals(refTarget.getId()._getId(), juliusId._getId());
    Assert.assertEquals(refTarget.getId()._getId(), juliusId._getId());
    julius = repositoryService.getEntityDefinition(nameGuidMap.get("Julius"));
    Object object = julius.get("subordinates");
    Assert.assertTrue(object instanceof List);
    List<ITypedReferenceableInstance> refValues = (List<ITypedReferenceableInstance>) object;
    Assert.assertEquals(refValues.size(), 1);
    Assert.assertTrue(refValues.contains(max.getId()));
    assertTestUpdateEntity_MultiplicityOneNonCompositeReference(janeId._getId());
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Id(org.apache.atlas.typesystem.persistence.Id) EntityResult(org.apache.atlas.model.legacy.EntityResult) Test(org.testng.annotations.Test)

Example 3 with EntityResult

use of org.apache.atlas.model.legacy.EntityResult in project incubator-atlas by apache.

the class GraphBackedMetadataRepositoryDeleteTestBase method testDisconnectBidirectionalReferences.

/**
     * Verify deleting an entity which is contained by another
     * entity through a bi-directional composite reference.
     *
     * @throws Exception
     */
@Test
public void testDisconnectBidirectionalReferences() throws Exception {
    String hrDeptGuid = createHrDeptGraph();
    ITypedReferenceableInstance hrDept = repositoryService.getEntityDefinition(hrDeptGuid);
    Map<String, String> nameGuidMap = getEmployeeNameGuidMap(hrDept);
    String maxGuid = nameGuidMap.get("Max");
    String janeGuid = nameGuidMap.get("Jane");
    String johnGuid = nameGuidMap.get("John");
    Assert.assertNotNull(maxGuid);
    Assert.assertNotNull(janeGuid);
    Assert.assertNotNull(johnGuid);
    // Verify that Max is one of Jane's subordinates.
    ITypedReferenceableInstance jane = repositoryService.getEntityDefinition(janeGuid);
    Object refValue = jane.get("subordinates");
    Assert.assertTrue(refValue instanceof List);
    List<Object> subordinates = (List<Object>) refValue;
    Assert.assertEquals(subordinates.size(), 2);
    List<String> subordinateIds = new ArrayList<>(2);
    for (Object listValue : subordinates) {
        Assert.assertTrue(listValue instanceof ITypedReferenceableInstance);
        ITypedReferenceableInstance employee = (ITypedReferenceableInstance) listValue;
        subordinateIds.add(employee.getId()._getId());
    }
    Assert.assertTrue(subordinateIds.contains(maxGuid));
    EntityResult entityResult = deleteEntities(maxGuid);
    ITypedReferenceableInstance john = repositoryService.getEntityDefinition("Person", "name", "John");
    assertEquals(entityResult.getDeletedEntities().size(), 1);
    assertTrue(entityResult.getDeletedEntities().contains(maxGuid));
    assertEquals(entityResult.getUpdateEntities().size(), 3);
    assertTrue(entityResult.getUpdateEntities().containsAll(Arrays.asList(jane.getId()._getId(), hrDeptGuid, john.getId()._getId())));
    assertEntityDeleted(maxGuid);
    assertMaxForTestDisconnectBidirectionalReferences(nameGuidMap);
    // Now delete jane - this should disconnect the manager reference from her
    // subordinate.
    entityResult = deleteEntities(janeGuid);
    assertEquals(entityResult.getDeletedEntities().size(), 1);
    assertTrue(entityResult.getDeletedEntities().contains(janeGuid));
    assertEquals(entityResult.getUpdateEntities().size(), 2);
    assertTrue(entityResult.getUpdateEntities().containsAll(Arrays.asList(hrDeptGuid, john.getId()._getId())));
    assertEntityDeleted(janeGuid);
    john = repositoryService.getEntityDefinition("Person", "name", "John");
    assertJohnForTestDisconnectBidirectionalReferences(john, janeGuid);
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) EntityResult(org.apache.atlas.model.legacy.EntityResult) Test(org.testng.annotations.Test)

Example 4 with EntityResult

use of org.apache.atlas.model.legacy.EntityResult in project incubator-atlas by apache.

the class GraphBackedMetadataRepositoryDeleteTestBase method testDisconnectUnidirectionalArrayReferenceFromClassType.

/**
     * Verify deleting entity that is the target of a unidirectional class array reference
     * from a class instance.
     */
@Test
public void testDisconnectUnidirectionalArrayReferenceFromClassType() throws Exception {
    createDbTableGraph(TestUtils.DATABASE_NAME, TestUtils.TABLE_NAME);
    // Get the guid for one of the table's columns.
    ITypedReferenceableInstance table = repositoryService.getEntityDefinition(TestUtils.TABLE_TYPE, "name", TestUtils.TABLE_NAME);
    String tableGuid = table.getId()._getId();
    List<ITypedReferenceableInstance> columns = (List<ITypedReferenceableInstance>) table.get("columns");
    Assert.assertEquals(columns.size(), 5);
    String columnGuid = columns.get(0).getId()._getId();
    // Delete the column.
    EntityResult entityResult = deleteEntities(columnGuid);
    assertEquals(entityResult.getDeletedEntities().size(), 1);
    Assert.assertTrue(entityResult.getDeletedEntities().contains(columnGuid));
    assertEquals(entityResult.getUpdateEntities().size(), 1);
    Assert.assertTrue(entityResult.getUpdateEntities().contains(tableGuid));
    assertEntityDeleted(columnGuid);
    // Verify table.columns reference to the deleted column has been disconnected.
    table = repositoryService.getEntityDefinition(tableGuid);
    assertTestDisconnectUnidirectionalArrayReferenceFromClassType((List<ITypedReferenceableInstance>) table.get("columns"), columnGuid);
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) EntityResult(org.apache.atlas.model.legacy.EntityResult) Test(org.testng.annotations.Test)

Example 5 with EntityResult

use of org.apache.atlas.model.legacy.EntityResult in project incubator-atlas by apache.

the class EntityLineageServiceTest method testNewLineageWithDelete.

@Test
public void testNewLineageWithDelete() throws Exception {
    TestUtils.skipForGremlin3EnabledGraphDb();
    String tableName = "table" + random();
    createTable(tableName, 3, true);
    String entityGuid = getEntityId(HIVE_TABLE_TYPE, "name", tableName);
    AtlasLineageInfo inputLineage = getInputLineageInfo(entityGuid, 5);
    assertNotNull(inputLineage);
    System.out.println("input lineage = " + inputLineage);
    Map<String, AtlasEntityHeader> entitiesInput = inputLineage.getGuidEntityMap();
    assertNotNull(entitiesInput);
    assertEquals(entitiesInput.size(), 3);
    Set<LineageRelation> relationsInput = inputLineage.getRelations();
    assertNotNull(relationsInput);
    assertEquals(relationsInput.size(), 2);
    AtlasEntityHeader tableEntityInput = entitiesInput.get(entityGuid);
    assertEquals(tableEntityInput.getStatus(), Status.ACTIVE);
    AtlasLineageInfo outputLineage = getOutputLineageInfo(entityGuid, 5);
    assertNotNull(outputLineage);
    System.out.println("output lineage = " + outputLineage);
    Map<String, AtlasEntityHeader> entitiesOutput = outputLineage.getGuidEntityMap();
    assertNotNull(entitiesOutput);
    assertEquals(entitiesOutput.size(), 3);
    Set<LineageRelation> relationsOutput = outputLineage.getRelations();
    assertNotNull(relationsOutput);
    assertEquals(relationsOutput.size(), 2);
    AtlasEntityHeader tableEntityOutput = entitiesOutput.get(entityGuid);
    assertEquals(tableEntityOutput.getStatus(), Status.ACTIVE);
    AtlasLineageInfo bothLineage = getBothLineageInfo(entityGuid, 5);
    assertNotNull(bothLineage);
    System.out.println("both lineage = " + bothLineage);
    Map<String, AtlasEntityHeader> entitiesBoth = bothLineage.getGuidEntityMap();
    assertNotNull(entitiesBoth);
    assertEquals(entitiesBoth.size(), 5);
    Set<LineageRelation> relationsBoth = bothLineage.getRelations();
    assertNotNull(relationsBoth);
    assertEquals(relationsBoth.size(), 4);
    AtlasEntityHeader tableEntityBoth = entitiesBoth.get(entityGuid);
    assertEquals(tableEntityBoth.getStatus(), Status.ACTIVE);
    //Delete the table entity. Lineage for entity returns the same results as before.
    //Lineage for table name throws EntityNotFoundException
    EntityResult deleteResult = repository.deleteEntities(Arrays.asList(entityGuid));
    assertTrue(deleteResult.getDeletedEntities().contains(entityGuid));
    inputLineage = getInputLineageInfo(entityGuid, 5);
    tableEntityInput = inputLineage.getGuidEntityMap().get(entityGuid);
    assertEquals(tableEntityInput.getStatus(), Status.DELETED);
    assertEquals(inputLineage.getGuidEntityMap().size(), 3);
    outputLineage = getOutputLineageInfo(entityGuid, 5);
    tableEntityOutput = outputLineage.getGuidEntityMap().get(entityGuid);
    assertEquals(tableEntityOutput.getStatus(), Status.DELETED);
    assertEquals(outputLineage.getGuidEntityMap().size(), 3);
    bothLineage = getBothLineageInfo(entityGuid, 5);
    tableEntityBoth = bothLineage.getGuidEntityMap().get(entityGuid);
    assertEquals(tableEntityBoth.getStatus(), Status.DELETED);
    assertEquals(bothLineage.getGuidEntityMap().size(), 5);
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) LineageRelation(org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) EntityResult(org.apache.atlas.model.legacy.EntityResult) Test(org.testng.annotations.Test) BaseRepositoryTest(org.apache.atlas.BaseRepositoryTest)

Aggregations

EntityResult (org.apache.atlas.model.legacy.EntityResult)33 Test (org.testng.annotations.Test)21 ArrayList (java.util.ArrayList)12 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)12 JSONObject (org.codehaus.jettison.json.JSONObject)12 List (java.util.List)11 Referenceable (org.apache.atlas.typesystem.Referenceable)11 ImmutableList (com.google.common.collect.ImmutableList)10 Id (org.apache.atlas.typesystem.persistence.Id)6 HashMap (java.util.HashMap)5 WebResource (com.sun.jersey.api.client.WebResource)4 GuidMapping (org.apache.atlas.model.instance.GuidMapping)4 Map (java.util.Map)3 AtlasException (org.apache.atlas.AtlasException)3 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)3 BaseRepositoryTest (org.apache.atlas.BaseRepositoryTest)2 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)2 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)2 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)2 RepositoryException (org.apache.atlas.repository.RepositoryException)2