Search in sources :

Example 21 with AtlasEntity

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

the class EntityGraphRetriever method toAtlasEntityWithExtInfo.

public AtlasEntityWithExtInfo toAtlasEntityWithExtInfo(AtlasVertex entityVertex) throws AtlasBaseException {
    AtlasEntityExtInfo entityExtInfo = new AtlasEntityExtInfo();
    AtlasEntity entity = mapVertexToAtlasEntity(entityVertex, entityExtInfo);
    AtlasEntityWithExtInfo ret = new AtlasEntityWithExtInfo(entity, entityExtInfo);
    ret.compact();
    return ret;
}
Also used : AtlasEntityExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityExtInfo) AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity)

Example 22 with AtlasEntity

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

the class EntityGraphRetriever method mapVertexToAtlasEntity.

private AtlasEntity mapVertexToAtlasEntity(AtlasVertex entityVertex, AtlasEntityExtInfo entityExtInfo) throws AtlasBaseException {
    String guid = GraphHelper.getGuid(entityVertex);
    AtlasEntity entity = entityExtInfo != null ? entityExtInfo.getEntity(guid) : null;
    if (entity == null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Mapping graph vertex to atlas entity for guid {}", guid);
        }
        entity = new AtlasEntity();
        if (entityExtInfo != null) {
            entityExtInfo.addReferredEntity(guid, entity);
        }
        mapSystemAttributes(entityVertex, entity);
        mapAttributes(entityVertex, entity, entityExtInfo);
        mapClassifications(entityVertex, entity, entityExtInfo);
    }
    return entity;
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity)

Example 23 with AtlasEntity

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

the class EntityV2JerseyResourceIT method createDBAndTable.

private TypeUtils.Pair<AtlasEntity, AtlasEntity> createDBAndTable() throws Exception {
    AtlasEntity dbInstanceV2 = createHiveDB();
    AtlasEntity hiveTableInstanceV2 = createHiveTable();
    return TypeUtils.Pair.of(dbInstanceV2, hiveTableInstanceV2);
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity)

Example 24 with AtlasEntity

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

the class EntityV2JerseyResourceIT method testPartialUpdate.

@Test(dependsOnMethods = "testSubmitEntity")
public void testPartialUpdate() throws Exception {
    final List<AtlasEntity> columns = new ArrayList<>();
    Map<String, Object> values = new HashMap<>();
    values.put("name", "col1");
    values.put(NAME, "qualifiedName.col1");
    values.put("type", "string");
    values.put("comment", "col1 comment");
    AtlasEntity colEntity = new AtlasEntity(BaseResourceIT.COLUMN_TYPE_V2, values);
    columns.add(colEntity);
    AtlasEntity hiveTable = createHiveTable();
    AtlasEntity tableUpdated = hiveTable;
    hiveTable.setAttribute("columns", AtlasTypeUtil.toObjectIds(columns));
    AtlasEntityWithExtInfo entityInfo = new AtlasEntityWithExtInfo(tableUpdated);
    entityInfo.addReferredEntity(colEntity);
    LOG.debug("Full Update entity= " + tableUpdated);
    EntityMutationResponse updateResult = atlasClientV2.updateEntity(entityInfo);
    assertNotNull(updateResult);
    assertNotNull(updateResult.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE));
    assertTrue(updateResult.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE).size() > 0);
    String guid = hiveTable.getGuid();
    AtlasEntity entityByGuid1 = getEntityByGuid(guid);
    assertNotNull(entityByGuid1);
    entityByGuid1.getAttribute("columns");
    values.put("type", "int");
    colEntity = new AtlasEntity(BaseResourceIT.COLUMN_TYPE_V2, values);
    columns.clear();
    columns.add(colEntity);
    tableUpdated = new AtlasEntity(HIVE_TABLE_TYPE_V2, "name", entityByGuid1.getAttribute("name"));
    tableUpdated.setGuid(entityByGuid1.getGuid());
    tableUpdated.setAttribute("columns", AtlasTypeUtil.toObjectIds(columns));
    // tableUpdated = hiveTable;
    // tableUpdated.setAttribute("columns", AtlasTypeUtil.toObjectIds(columns));
    LOG.debug("Partial Update entity by unique attributes= " + tableUpdated);
    Map<String, String> uniqAttributes = new HashMap<>();
    uniqAttributes.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, (String) hiveTable.getAttribute("name"));
    entityInfo = new AtlasEntityWithExtInfo(tableUpdated);
    entityInfo.addReferredEntity(colEntity);
    EntityMutationResponse updateResponse = atlasClientV2.updateEntityByAttribute(BaseResourceIT.HIVE_TABLE_TYPE_V2, uniqAttributes, entityInfo);
    assertNotNull(updateResponse);
    assertNotNull(updateResponse.getEntitiesByOperation(EntityMutations.EntityOperation.PARTIAL_UPDATE));
    assertTrue(updateResponse.getEntitiesByOperation(EntityMutations.EntityOperation.PARTIAL_UPDATE).size() > 0);
    AtlasEntity entityByGuid2 = getEntityByGuid(guid);
    assertNotNull(entityByGuid2);
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) HashMap(java.util.HashMap) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 25 with AtlasEntity

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

the class EntityV2JerseyResourceIT method testCompleteUpdate.

@Test(dependsOnMethods = "testSubmitEntity")
public void testCompleteUpdate() throws Exception {
    final List<AtlasEntity> columns = new ArrayList<>();
    Map<String, Object> values1 = new HashMap<>();
    values1.put("name", "col3");
    values1.put(NAME, "qualifiedName.col3");
    values1.put("type", "string");
    values1.put("comment", "col3 comment");
    Map<String, Object> values2 = new HashMap<>();
    values2.put("name", "col4");
    values2.put(NAME, "qualifiedName.col4");
    values2.put("type", "string");
    values2.put("comment", "col4 comment");
    AtlasEntity colEntity1 = new AtlasEntity(BaseResourceIT.COLUMN_TYPE_V2, values1);
    AtlasEntity colEntity2 = new AtlasEntity(BaseResourceIT.COLUMN_TYPE_V2, values2);
    columns.add(colEntity1);
    columns.add(colEntity2);
    AtlasEntity hiveTable = createHiveTable();
    hiveTable.setAttribute("columns", AtlasTypeUtil.toObjectIds(columns));
    AtlasEntityWithExtInfo entityInfo = new AtlasEntityWithExtInfo(hiveTable);
    entityInfo.addReferredEntity(colEntity1);
    entityInfo.addReferredEntity(colEntity2);
    EntityMutationResponse updateEntityResult = atlasClientV2.updateEntity(entityInfo);
    assertNotNull(updateEntityResult);
    assertNotNull(updateEntityResult.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE));
    assertNotNull(updateEntityResult.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE));
    //2 columns are being created, and 1 hiveTable is being updated
    assertEquals(updateEntityResult.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE).size(), 1);
    assertEquals(updateEntityResult.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).size(), 2);
    AtlasEntity entityByGuid = getEntityByGuid(hiveTable.getGuid());
    List<AtlasObjectId> refs = (List<AtlasObjectId>) entityByGuid.getAttribute("columns");
    assertEquals(refs.size(), 2);
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) HashMap(java.util.HashMap) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Test(org.testng.annotations.Test)

Aggregations

AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)124 Test (org.testng.annotations.Test)58 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)43 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)36 HashMap (java.util.HashMap)25 BeforeTest (org.testng.annotations.BeforeTest)25 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)24 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)24 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)21 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)17 ArrayList (java.util.ArrayList)16 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)14 Map (java.util.Map)12 List (java.util.List)11 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)11 AtlasStruct (org.apache.atlas.model.instance.AtlasStruct)9 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)9 TestUtils.randomString (org.apache.atlas.TestUtils.randomString)7 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)7 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)7