Search in sources :

Example 16 with AtlasEntityWithExtInfo

use of org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo 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 17 with AtlasEntityWithExtInfo

use of org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo 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)

Example 18 with AtlasEntityWithExtInfo

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

the class ImportTransformsTest method getAtlasEntityWithExtInfo.

private AtlasEntityWithExtInfo getAtlasEntityWithExtInfo() {
    AtlasEntityWithExtInfo ret = new AtlasEntityWithExtInfo(getHiveTableAtlasEntity());
    Map<String, AtlasEntity> referredEntities = new HashMap<>();
    referredEntities.put("0", getHiveColumnAtlasEntity(1));
    referredEntities.put("1", getHiveColumnAtlasEntity(2));
    referredEntities.put("2", getHiveColumnAtlasEntity(3));
    ret.setReferredEntities(referredEntities);
    return ret;
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) HashMap(java.util.HashMap) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity)

Example 19 with AtlasEntityWithExtInfo

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

the class BaseResourceIT method modifyEntity.

protected AtlasEntityHeader modifyEntity(AtlasEntity atlasEntity, boolean update) {
    EntityMutationResponse entity = null;
    try {
        if (!update) {
            entity = atlasClientV2.createEntity(new AtlasEntityWithExtInfo(atlasEntity));
            assertNotNull(entity);
            assertNotNull(entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE));
            assertTrue(entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).size() > 0);
            return entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).get(0);
        } else {
            entity = atlasClientV2.updateEntity(new AtlasEntityWithExtInfo(atlasEntity));
            assertNotNull(entity);
            assertNotNull(entity.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE));
            assertTrue(entity.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE).size() > 0);
            return entity.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE).get(0);
        }
    } catch (AtlasServiceException e) {
        LOG.error("Entity {} failed", update ? "update" : "creation", entity);
    }
    return null;
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasServiceException(org.apache.atlas.AtlasServiceException) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse)

Example 20 with AtlasEntityWithExtInfo

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

the class ExportService method processEntity.

private void processEntity(String guid, ExportContext context) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> processEntity({})", guid);
    }
    if (!context.guidsProcessed.contains(guid)) {
        TraversalDirection direction = context.guidDirection.get(guid);
        AtlasEntityWithExtInfo entityWithExtInfo = entityGraphRetriever.toAtlasEntityWithExtInfo(guid);
        context.result.getData().getEntityCreationOrder().add(entityWithExtInfo.getEntity().getGuid());
        addEntity(entityWithExtInfo, context);
        addTypes(entityWithExtInfo.getEntity(), context);
        context.guidsProcessed.add(entityWithExtInfo.getEntity().getGuid());
        getConntedEntitiesBasedOnOption(entityWithExtInfo.getEntity(), context, direction);
        if (entityWithExtInfo.getReferredEntities() != null) {
            for (AtlasEntity e : entityWithExtInfo.getReferredEntities().values()) {
                addTypes(e, context);
                getConntedEntitiesBasedOnOption(e, context, direction);
            }
            context.guidsProcessed.addAll(entityWithExtInfo.getReferredEntities().keySet());
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== processEntity({})", guid);
    }
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity)

Aggregations

AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)34 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)24 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)18 Test (org.testng.annotations.Test)17 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)8 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)8 HashMap (java.util.HashMap)6 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)6 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)6 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)5 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)4 BeforeTest (org.testng.annotations.BeforeTest)4 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 AtlasServiceException (org.apache.atlas.AtlasServiceException)2 TestUtils.randomString (org.apache.atlas.TestUtils.randomString)2 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)2 AtlasStruct (org.apache.atlas.model.instance.AtlasStruct)2 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)2 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)2