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);
}
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);
}
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;
}
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;
}
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);
}
}
Aggregations