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