Search in sources :

Example 46 with AtlasEntityHeader

use of org.apache.atlas.model.instance.AtlasEntityHeader in project incubator-atlas by apache.

the class EntityLineageJerseyResourceIT method testOutputLineageInfo.

@Test
public void testOutputLineageInfo() throws Exception {
    String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
    MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
    queryParams.add(DIRECTION_PARAM, OUTPUT_DIRECTION);
    queryParams.add(DEPTH_PARAM, "5");
    JSONObject response = atlasClientV1.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams, tableId);
    Assert.assertNotNull(response);
    System.out.println("output lineage info = " + response);
    AtlasLineageInfo outputLineageInfo = gson.fromJson(response.toString(), AtlasLineageInfo.class);
    Map<String, AtlasEntityHeader> entities = outputLineageInfo.getGuidEntityMap();
    Assert.assertNotNull(entities);
    Set<AtlasLineageInfo.LineageRelation> relations = outputLineageInfo.getRelations();
    Assert.assertNotNull(relations);
    Assert.assertEquals(entities.size(), 5);
    Assert.assertEquals(relations.size(), 4);
    Assert.assertEquals(outputLineageInfo.getLineageDirection(), AtlasLineageInfo.LineageDirection.OUTPUT);
    Assert.assertEquals(outputLineageInfo.getLineageDepth(), 5);
    Assert.assertEquals(outputLineageInfo.getBaseEntityGuid(), tableId);
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) JSONObject(org.codehaus.jettison.json.JSONObject) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.testng.annotations.Test)

Example 47 with AtlasEntityHeader

use of org.apache.atlas.model.instance.AtlasEntityHeader in project incubator-atlas by apache.

the class EntityV2JerseyResourceIT method testEntityInvalidValue.

@Test
public void testEntityInvalidValue() throws Exception {
    AtlasEntity databaseInstance = new AtlasEntity(DATABASE_TYPE_V2);
    String dbName = randomString();
    String nullString = null;
    String emptyString = "";
    databaseInstance.setAttribute("name", dbName);
    databaseInstance.setAttribute("description", nullString);
    AtlasEntityHeader created = createEntity(databaseInstance);
    // null valid value for required attr - description
    assertNull(created);
    databaseInstance.setAttribute("description", emptyString);
    created = createEntity(databaseInstance);
    // empty string valid value for required attr
    assertNotNull(created);
    databaseInstance.setGuid(created.getGuid());
    databaseInstance.setAttribute("owner", nullString);
    databaseInstance.setAttribute("locationUri", emptyString);
    created = updateEntity(databaseInstance);
    // null/empty string valid value for optional attr
    assertNotNull(created);
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) Test(org.testng.annotations.Test)

Example 48 with AtlasEntityHeader

use of org.apache.atlas.model.instance.AtlasEntityHeader in project incubator-atlas by apache.

the class EntityV2JerseyResourceIT method testSubmitEntityWithBadDateFormat.

@Test
public void testSubmitEntityWithBadDateFormat() throws Exception {
    AtlasEntity hiveDBEntity = createHiveDBInstanceV2("db" + randomString());
    AtlasEntityHeader hiveDBHeader = createEntity(hiveDBEntity);
    hiveDBEntity.setGuid(hiveDBHeader.getGuid());
    AtlasEntity tableInstance = createHiveTableInstanceV2(hiveDBEntity, "table" + randomString());
    //Dates with an invalid format are simply nulled out.  This does not produce
    //an error.  See AtlasBuiltInTypes.AtlasDateType.getNormalizedValue().
    tableInstance.setAttribute("lastAccessTime", 1107201407);
    AtlasEntityHeader tableEntityHeader = createEntity(tableInstance);
    assertNotNull(tableEntityHeader);
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) Test(org.testng.annotations.Test)

Example 49 with AtlasEntityHeader

use of org.apache.atlas.model.instance.AtlasEntityHeader in project incubator-atlas by apache.

the class AtlasDeleteHandlerV1Test 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 {
    AtlasEntity.AtlasEntitiesWithExtInfo hrDept = TestUtilsV2.createDeptEg2();
    init();
    final EntityMutationResponse hrDeptCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(hrDept), false);
    final AtlasEntityHeader deptCreated = hrDeptCreationResponse.getFirstCreatedEntityByTypeName(DEPARTMENT_TYPE);
    final AtlasEntityHeader maxEmployee = hrDeptCreationResponse.getCreatedEntityByTypeNameAndAttribute(TestUtilsV2.EMPLOYEE_TYPE, NAME, "Max");
    final AtlasEntityHeader johnEmployee = hrDeptCreationResponse.getCreatedEntityByTypeNameAndAttribute(TestUtilsV2.EMPLOYEE_TYPE, NAME, "John");
    final AtlasEntityHeader janeEmployee = hrDeptCreationResponse.getCreatedEntityByTypeNameAndAttribute(TestUtilsV2.MANAGER_TYPE, NAME, "Jane");
    final AtlasEntityHeader juliusEmployee = hrDeptCreationResponse.getCreatedEntityByTypeNameAndAttribute(TestUtilsV2.MANAGER_TYPE, NAME, "Julius");
    ITypedReferenceableInstance hrDeptInstance = metadataService.getEntityDefinition(deptCreated.getGuid());
    Map<String, String> nameGuidMap = getEmployeeNameGuidMap(hrDeptInstance);
    // Verify that Max is one of Jane's subordinates.
    ITypedReferenceableInstance jane = metadataService.getEntityDefinition(janeEmployee.getGuid());
    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(maxEmployee.getGuid()));
    init();
    EntityMutationResponse entityResult = entityStore.deleteById(maxEmployee.getGuid());
    ITypedReferenceableInstance john = metadataService.getEntityDefinitionReference(TestUtilsV2.EMPLOYEE_TYPE, NAME, "John");
    assertEquals(entityResult.getDeletedEntities().size(), 1);
    assertEquals(entityResult.getDeletedEntities().get(0).getGuid(), maxEmployee.getGuid());
    assertEquals(entityResult.getUpdatedEntities().size(), 3);
    assertEquals(extractGuids(entityResult.getUpdatedEntities()), Arrays.asList(janeEmployee.getGuid(), deptCreated.getGuid(), johnEmployee.getGuid()));
    assertEntityDeleted(maxEmployee.getGuid());
    assertMaxForTestDisconnectBidirectionalReferences(nameGuidMap);
    // Now delete jane - this should disconnect the manager reference from her
    // subordinate.
    init();
    entityResult = entityStore.deleteById(janeEmployee.getGuid());
    assertEquals(entityResult.getDeletedEntities().size(), 1);
    assertEquals(entityResult.getDeletedEntities().get(0).getGuid(), janeEmployee.getGuid());
    assertEquals(entityResult.getUpdatedEntities().size(), 2);
    assertEquals(extractGuids(entityResult.getUpdatedEntities()), Arrays.asList(deptCreated.getGuid(), johnEmployee.getGuid()));
    assertEntityDeleted(janeEmployee.getGuid());
    final AtlasEntity.AtlasEntityWithExtInfo johnUpdated = entityStore.getById(johnEmployee.getGuid());
    assertJohnForTestDisconnectBidirectionalReferences(johnUpdated, janeEmployee.getGuid());
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) ArrayList(java.util.ArrayList) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 50 with AtlasEntityHeader

use of org.apache.atlas.model.instance.AtlasEntityHeader in project incubator-atlas by apache.

the class AtlasDeleteHandlerV1Test method testUpdateEntity_MultiplicityOneNonCompositeReference.

@Test
public void testUpdateEntity_MultiplicityOneNonCompositeReference() throws Exception {
    AtlasEntity.AtlasEntitiesWithExtInfo hrDept = TestUtilsV2.createDeptEg2();
    init();
    RequestContextV1.clear();
    final EntityMutationResponse hrDeptCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(hrDept), false);
    final AtlasEntityHeader deptCreated = hrDeptCreationResponse.getFirstUpdatedEntityByTypeName(DEPARTMENT_TYPE);
    final AtlasEntityHeader maxEmployeeCreated = hrDeptCreationResponse.getCreatedEntityByTypeNameAndAttribute(TestUtilsV2.EMPLOYEE_TYPE, NAME, "Max");
    final AtlasEntityHeader johnEmployeeCreated = hrDeptCreationResponse.getUpdatedEntityByTypeNameAndAttribute(TestUtilsV2.EMPLOYEE_TYPE, NAME, "John");
    final AtlasEntityHeader janeEmployeeCreated = hrDeptCreationResponse.getCreatedEntityByTypeNameAndAttribute(TestUtilsV2.MANAGER_TYPE, NAME, "Jane");
    final AtlasEntityHeader juliusEmployeeCreated = hrDeptCreationResponse.getUpdatedEntityByTypeNameAndAttribute(TestUtilsV2.MANAGER_TYPE, NAME, "Julius");
    ITypedReferenceableInstance max = metadataService.getEntityDefinition(maxEmployeeCreated.getGuid());
    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);
    AtlasEntity maxEmployee = getEmployeeByName(hrDept, "Max");
    maxEmployee.setAttribute("mentor", AtlasTypeUtil.getAtlasObjectId(johnEmployeeCreated));
    maxEmployee.setAttribute("department", AtlasTypeUtil.getAtlasObjectId(deptCreated));
    maxEmployee.setAttribute("manager", AtlasTypeUtil.getAtlasObjectId(janeEmployeeCreated));
    init();
    EntityMutationResponse entityResult = entityStore.createOrUpdate(new AtlasEntityStream(maxEmployee), false);
    assertEquals(entityResult.getUpdatedEntities().size(), 1);
    assertTrue(extractGuids(entityResult.getUpdatedEntities()).contains(maxGuid));
    // Verify the update was applied correctly - john should now be max's mentor.
    max = metadataService.getEntityDefinition(maxGuid);
    ITypedReferenceableInstance refTarget = (ITypedReferenceableInstance) max.get("mentor");
    Assert.assertEquals(refTarget.getId()._getId(), johnEmployeeCreated.getGuid());
    // 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.
    maxEmployee.setAttribute("mentor", AtlasTypeUtil.getAtlasObjectId(janeEmployeeCreated));
    init();
    entityResult = entityStore.createOrUpdate(new AtlasEntityStream(maxEmployee), false);
    assertEquals(entityResult.getUpdatedEntities().size(), 1);
    assertTrue(extractGuids(entityResult.getUpdatedEntities()).contains(maxGuid));
    // Verify the update was applied correctly - jane should now be max's mentor.
    max = metadataService.getEntityDefinition(maxGuid);
    refTarget = (ITypedReferenceableInstance) max.get("mentor");
    Assert.assertEquals(refTarget.getId()._getId(), janeEmployeeCreated.getGuid());
    // 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 = metadataService.getEntityDefinition(juliusEmployeeCreated.getGuid());
    Id juliusId = julius.getId();
    init();
    maxEmployee.setAttribute("manager", AtlasTypeUtil.getAtlasObjectId(juliusEmployeeCreated));
    entityResult = entityStore.createOrUpdate(new AtlasEntityStream(maxEmployee), false);
    assertEquals(entityResult.getUpdatedEntities().size(), 3);
    List<String> updatedGuids = extractGuids(entityResult.getUpdatedEntities());
    assertTrue(updatedGuids.contains(maxGuid));
    assertTrue(updatedGuids.contains(janeEmployeeCreated.getGuid()));
    // Should have updated julius to add max in subordinates list.
    assertTrue(updatedGuids.contains(juliusEmployeeCreated.getGuid()));
    // Verify the update was applied correctly - julius should now be max's manager and max should be julius' subordinate.
    max = metadataService.getEntityDefinition(maxGuid);
    refTarget = (ITypedReferenceableInstance) max.get("manager");
    Assert.assertEquals(refTarget.getId()._getId(), juliusId._getId());
    julius = metadataService.getEntityDefinition(juliusId._getId());
    Object value = julius.get("subordinates");
    Assert.assertTrue(value instanceof List);
    List<ITypedReferenceableInstance> refList = (List<ITypedReferenceableInstance>) value;
    Assert.assertEquals(refList.size(), 1);
    Assert.assertEquals(refList.get(0).getId()._getId(), maxGuid);
    assertTestUpdateEntity_MultiplicityOneNonCompositeReference(janeEmployeeCreated.getGuid());
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Id(org.apache.atlas.typesystem.persistence.Id) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)65 Test (org.testng.annotations.Test)46 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)38 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)34 BeforeTest (org.testng.annotations.BeforeTest)22 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)15 ArrayList (java.util.ArrayList)14 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)14 HashMap (java.util.HashMap)12 AtlasLineageInfo (org.apache.atlas.model.lineage.AtlasLineageInfo)12 List (java.util.List)10 Map (java.util.Map)8 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)8 LineageRelation (org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation)8 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)8 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)8 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)7 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)6 BaseRepositoryTest (org.apache.atlas.BaseRepositoryTest)5 TestUtils.randomString (org.apache.atlas.TestUtils.randomString)5