use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.
the class BaseResourceIT method createHiveDBInstanceV2.
protected AtlasEntity createHiveDBInstanceV2(String dbName) {
AtlasEntity atlasEntity = new AtlasEntity(DATABASE_TYPE_V2);
atlasEntity.setAttribute(NAME, dbName);
atlasEntity.setAttribute(DESCRIPTION, "foo database");
atlasEntity.setAttribute(CLUSTER_NAME, "fooCluster");
atlasEntity.setAttribute("owner", "user1");
atlasEntity.setAttribute("locationUri", "/tmp");
atlasEntity.setAttribute("createTime", 1000);
return atlasEntity;
}
use of org.apache.atlas.model.instance.AtlasEntity 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);
}
}
use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.
the class InverseReferenceUpdateV1Test method testInverseReferenceAutoUpdate_NonCompositeManyToOne.
@Test
public void testInverseReferenceAutoUpdate_NonCompositeManyToOne() throws Exception {
AtlasEntityType bType = typeRegistry.getEntityTypeByName("B");
AtlasEntity a1 = new AtlasEntity("A");
a1.setAttribute(NAME, TestUtils.randomString());
AtlasEntity a2 = new AtlasEntity("A");
a2.setAttribute(NAME, TestUtils.randomString());
AtlasEntity a3 = new AtlasEntity("A");
a3.setAttribute(NAME, TestUtils.randomString());
AtlasEntity b = new AtlasEntity("B");
b.setAttribute(NAME, TestUtils.randomString());
AtlasEntitiesWithExtInfo atlasEntitiesWithExtInfo = new AtlasEntitiesWithExtInfo();
atlasEntitiesWithExtInfo.addEntity(a1);
atlasEntitiesWithExtInfo.addEntity(a2);
atlasEntitiesWithExtInfo.addEntity(a3);
atlasEntitiesWithExtInfo.addEntity(b);
AtlasEntityStream entityStream = new AtlasEntityStream(atlasEntitiesWithExtInfo);
EntityMutationResponse response = entityStore.createOrUpdate(entityStream, false);
AtlasEntity bForPartialUpdate = new AtlasEntity("B");
bForPartialUpdate.setAttribute("manyA", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(a1), AtlasTypeUtil.getAtlasObjectId(a2)));
init();
response = entityStore.updateByUniqueAttributes(bType, Collections.<String, Object>singletonMap(NAME, b.getAttribute(NAME)), new AtlasEntityWithExtInfo(bForPartialUpdate));
List<AtlasEntityHeader> partialUpdatedEntities = response.getPartialUpdatedEntities();
// Verify 3 entities were updated:
// * set b.manyA reference to a1 and a2
// * set inverse a1.oneB reference to b
// * set inverse a2.oneB reference to b
assertEquals(partialUpdatedEntities.size(), 3);
AtlasEntitiesWithExtInfo storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), a2.getGuid(), b.getGuid()));
AtlasEntity storedEntity = storedEntities.getEntity(a1.getGuid());
verifyReferenceValue(storedEntity, "oneB", b.getGuid());
storedEntity = storedEntities.getEntity(a2.getGuid());
verifyReferenceValue(storedEntity, "oneB", b.getGuid());
storedEntity = storedEntities.getEntity(b.getGuid());
verifyReferenceList(storedEntity, "manyA", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(a1), AtlasTypeUtil.getAtlasObjectId(a2)));
bForPartialUpdate.setAttribute("manyA", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(a3)));
init();
response = entityStore.updateByUniqueAttributes(bType, Collections.<String, Object>singletonMap(NAME, b.getAttribute(NAME)), new AtlasEntityWithExtInfo(bForPartialUpdate));
partialUpdatedEntities = response.getPartialUpdatedEntities();
// Verify 4 entities were updated:
// * set b.manyA reference to a3
// * set inverse a3.oneB reference to b
// * disconnect inverse a1.oneB reference to b
// * disconnect inverse a2.oneB reference to b
assertEquals(partialUpdatedEntities.size(), 4);
init();
storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), a2.getGuid(), a3.getGuid(), b.getGuid()));
verifyReferenceValue(storedEntities.getEntity(a3.getGuid()), "oneB", b.getGuid());
verify_testInverseReferenceAutoUpdate_NonCompositeManyToOne(storedEntities.getEntity(a1.getGuid()), storedEntities.getEntity(a2.getGuid()), storedEntities.getEntity(a3.getGuid()), storedEntities.getEntity(b.getGuid()));
}
use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.
the class QuickStartV2IT method getTable.
private AtlasEntity getTable(String tableName) throws AtlasServiceException {
Map<String, String> attributes = new HashMap<>();
attributes.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
AtlasEntity tableEntity = atlasClientV2.getEntityByAttribute(QuickStartV2.TABLE_TYPE, attributes).getEntity();
return tableEntity;
}
use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.
the class QuickStartV2IT method getDB.
private AtlasEntity getDB(String dbName) throws AtlasServiceException, JSONException {
Map<String, String> attributes = new HashMap<>();
attributes.put("name", dbName);
AtlasEntity dbEntity = atlasClientV2.getEntityByAttribute(QuickStartV2.DATABASE_TYPE, attributes).getEntity();
return dbEntity;
}
Aggregations