use of org.apache.atlas.model.instance.EntityMutationResponse 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.EntityMutationResponse 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.EntityMutationResponse in project incubator-atlas by apache.
the class InverseReferenceUpdateV1Test method setUp.
@BeforeClass
public void setUp() throws Exception {
metadataService = TestUtils.addSessionCleanupWrapper(metadataService);
AtlasTypesDef[] testTypesDefs = new AtlasTypesDef[] { TestUtilsV2.defineDeptEmployeeTypes(), TestUtilsV2.defineInverseReferenceTestTypes() };
for (AtlasTypesDef typesDef : testTypesDefs) {
AtlasTypesDef typesToCreate = AtlasTypeDefStoreInitializer.getTypesToCreate(typesDef, typeRegistry);
if (!typesToCreate.isEmpty()) {
typeDefStore.createTypesDef(typesToCreate);
}
}
deptEntity = TestUtilsV2.createDeptEg2();
init();
EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(deptEntity), false);
for (AtlasEntityHeader entityHeader : response.getCreatedEntities()) {
nameIdMap.put((String) entityHeader.getAttribute(NAME), AtlasTypeUtil.getAtlasObjectId(entityHeader));
}
}
use of org.apache.atlas.model.instance.EntityMutationResponse in project incubator-atlas by apache.
the class EntityV2JerseyResourceIT method testEntityDeduping.
@Test
public void testEntityDeduping() throws Exception {
JSONArray results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
assertEquals(results.length(), 1);
final AtlasEntity hiveDBInstanceV2 = createHiveDB();
// Do the notification thing here
waitForNotification(notificationConsumer, MAX_WAIT_TIME, new NotificationPredicate() {
@Override
public boolean evaluate(EntityNotification notification) throws Exception {
return notification != null && notification.getEntity().getId()._getId().equals(hiveDBInstanceV2.getGuid());
}
});
results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
assertEquals(results.length(), 1);
//Test the same across references
final String tableName = randomString();
AtlasEntity hiveTableInstanceV2 = createHiveTableInstanceV2(hiveDBInstanceV2, tableName);
hiveTableInstanceV2.setAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
EntityMutationResponse entity = atlasClientV2.createEntity(new AtlasEntityWithExtInfo(hiveTableInstanceV2));
assertNotNull(entity);
assertNotNull(entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE));
results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
assertEquals(results.length(), 1);
}
use of org.apache.atlas.model.instance.EntityMutationResponse in project incubator-atlas by apache.
the class EntityV2JerseyResourceIT method addProperty.
private void addProperty(String guid, String property, Object value) throws AtlasServiceException {
AtlasEntity entityByGuid = getEntityByGuid(guid);
entityByGuid.setAttribute(property, value);
EntityMutationResponse response = atlasClientV2.updateEntity(new AtlasEntityWithExtInfo(entityByGuid));
assertNotNull(response);
assertNotNull(response.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE));
}
Aggregations