Java Code Examples for org.apache.atlas.model.instance.EntityMutationResponse#getFirstCreatedEntityByTypeName()
The following examples show how to use
org.apache.atlas.model.instance.EntityMutationResponse#getFirstCreatedEntityByTypeName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AtlasEntityStoreV2Test.java From atlas with Apache License 2.0 | 6 votes |
@Test(dependsOnMethods = "testCreate") public void testClassUpdate() throws Exception { init(); //Create new db instance final AtlasEntity databaseInstance = TestUtilsV2.createDBEntity(); EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(databaseInstance), false); final AtlasEntityHeader dbCreated = response.getFirstCreatedEntityByTypeName(TestUtilsV2.DATABASE_TYPE); init(); Map<String, AtlasEntity> tableCloneMap = new HashMap<>(); AtlasEntity tableClone = new AtlasEntity(tblEntity.getEntity()); tableClone.setAttribute("database", new AtlasObjectId(dbCreated.getGuid(), TestUtilsV2.DATABASE_TYPE)); tableCloneMap.put(dbCreated.getGuid(), databaseInstance); tableCloneMap.put(tableClone.getGuid(), tableClone); response = entityStore.createOrUpdate(new InMemoryMapEntityStream(tableCloneMap), false); final AtlasEntityHeader tableDefinition = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE); AtlasEntity updatedTableDefinition = getEntityFromStore(tableDefinition); assertNotNull(updatedTableDefinition.getAttribute("database")); Assert.assertEquals(((AtlasObjectId) updatedTableDefinition.getAttribute("database")).getGuid(), dbCreated.getGuid()); }
Example 2
Source File: AtlasEntityStoreV1Test.java From incubator-atlas with Apache License 2.0 | 6 votes |
@Test(dependsOnMethods = "testCreate") public void testClassUpdate() throws Exception { init(); //Create new db instance final AtlasEntity databaseInstance = TestUtilsV2.createDBEntity(); EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(databaseInstance), false); final AtlasEntityHeader dbCreated = response.getFirstCreatedEntityByTypeName(TestUtilsV2.DATABASE_TYPE); init(); Map<String, AtlasEntity> tableCloneMap = new HashMap<>(); AtlasEntity tableClone = new AtlasEntity(tblEntity.getEntity()); tableClone.setAttribute("database", new AtlasObjectId(dbCreated.getGuid(), TestUtils.DATABASE_TYPE)); tableCloneMap.put(dbCreated.getGuid(), databaseInstance); tableCloneMap.put(tableClone.getGuid(), tableClone); response = entityStore.createOrUpdate(new InMemoryMapEntityStream(tableCloneMap), false); final AtlasEntityHeader tableDefinition = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE); AtlasEntity updatedTableDefinition = getEntityFromStore(tableDefinition); Assert.assertNotNull(updatedTableDefinition.getAttribute("database")); Assert.assertEquals(((AtlasObjectId) updatedTableDefinition.getAttribute("database")).getGuid(), dbCreated.getGuid()); }
Example 3
Source File: AtlasComplexAttributesTest.java From atlas with Apache License 2.0 | 5 votes |
@Test public void testCreateComplexAttributeEntity() throws Exception { init(); EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(complexCollectionAttrEntity), false); AtlasEntityHeader entityCreated = response.getFirstCreatedEntityByTypeName(ENTITY_TYPE_WITH_COMPLEX_COLLECTION_ATTR); validateEntity(complexCollectionAttrEntity, getEntityFromStore(entityCreated)); }
Example 4
Source File: AtlasComplexAttributesTest.java From atlas with Apache License 2.0 | 4 votes |
@Test public void testPrimitiveMapAttributes() throws Exception { init(); EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(mapAttributesEntity), false); AtlasEntityHeader entityCreated = response.getFirstCreatedEntityByTypeName(ENTITY_TYPE_MAP); AtlasEntity entityFromStore = getEntityFromStore(entityCreated); validateEntity(mapAttributesEntity, entityFromStore); // Modify map of primitives AtlasEntity attrEntity = getEntityFromStore(mapAttributesEntity.getEntity().getGuid()); Map<String, String> map1 = new HashMap<String, String>() {{ put("map1Key11", "value11"); put("map1Key22", "value22"); put("map1Key33", "value33"); }}; Map<String, Integer> map2 = new HashMap<String, Integer>() {{ put("map2Key11", 1100); put("map2Key22", 2200); put("map2Key33", 3300); }}; Map<String, Boolean> map3 = new HashMap<String, Boolean>() {{ put("map3Key11", true); put("map3Key22", false); put("map3Key33", true); }}; Map<String, Float> map4 = new HashMap<String, Float>() {{ put("map4Key11", 11.0f); put("map4Key22", 22.0f); put("map4Key33", 33.0f); }}; Map<String, Date> map5 = new HashMap<String, Date>() {{ put("map5Key11", DateUtils.addHours(new Date(), 1)); put("map5Key22", DateUtils.addHours(new Date(), 2)); put("map5Key33", DateUtils.addHours(new Date(), 3)); }}; updateEntityMapAttributes(attrEntity, map1, map2, map3, map4, map5); AtlasEntitiesWithExtInfo attrEntitiesInfo = new AtlasEntitiesWithExtInfo(attrEntity); response = entityStore.createOrUpdate(new AtlasEntityStream(attrEntitiesInfo), false); AtlasEntityHeader updatedAttrEntity = response.getFirstUpdatedEntityByTypeName(ENTITY_TYPE_MAP); AtlasEntity updatedFromStore = getEntityFromStore(updatedAttrEntity); validateEntity(attrEntitiesInfo, updatedFromStore); // Add new entry to map of primitives map1.put("map1Key44", "value44"); map2.put("map2Key44", 4400); map3.put("map3Key44", false); map4.put("map4Key44", 44.0f); map5.put("map5Key44", DateUtils.addHours(new Date(), 4)); updateEntityMapAttributes(attrEntity, map1, map2, map3, map4, map5); attrEntitiesInfo = new AtlasEntitiesWithExtInfo(attrEntity); response = entityStore.createOrUpdate(new AtlasEntityStream(attrEntitiesInfo), false); updatedAttrEntity = response.getFirstUpdatedEntityByTypeName(ENTITY_TYPE_MAP); updatedFromStore = getEntityFromStore(updatedAttrEntity); validateEntity(attrEntitiesInfo, updatedFromStore); // Remove an entry from map of primitives map1.remove("map1Key11"); map2.remove("map2Key11"); map3.remove("map3Key11"); map4.remove("map4Key11"); map5.remove("map5Key11"); updateEntityMapAttributes(attrEntity, map1, map2, map3, map4, map5); attrEntitiesInfo = new AtlasEntitiesWithExtInfo(attrEntity); response = entityStore.createOrUpdate(new AtlasEntityStream(attrEntitiesInfo), false); updatedAttrEntity = response.getFirstUpdatedEntityByTypeName(ENTITY_TYPE_MAP); updatedFromStore = getEntityFromStore(updatedAttrEntity); validateEntity(attrEntitiesInfo, updatedFromStore); // Edit existing entry to map of primitives map1.put("map1Key44", "value44-edit"); map2.put("map2Key44", 5555); map3.put("map3Key44", true); map4.put("map4Key44", 55.5f); map5.put("map5Key44", DateUtils.addHours(new Date(), 5)); updateEntityMapAttributes(attrEntity, map1, map2, map3, map4, map5); attrEntitiesInfo = new AtlasEntitiesWithExtInfo(attrEntity); response = entityStore.createOrUpdate(new AtlasEntityStream(attrEntitiesInfo), false); updatedAttrEntity = response.getFirstUpdatedEntityByTypeName(ENTITY_TYPE_MAP); updatedFromStore = getEntityFromStore(updatedAttrEntity); validateEntity(attrEntitiesInfo, updatedFromStore); // clear primitive map entries map1.clear(); map2.clear(); map3.clear(); map4.clear(); map5.clear(); updateEntityMapAttributes(attrEntity, map1, map2, map3, map4, map5); attrEntitiesInfo = new AtlasEntitiesWithExtInfo(attrEntity); response = entityStore.createOrUpdate(new AtlasEntityStream(attrEntitiesInfo), false); updatedAttrEntity = response.getFirstUpdatedEntityByTypeName(ENTITY_TYPE_MAP); updatedFromStore = getEntityFromStore(updatedAttrEntity); validateEntity(attrEntitiesInfo, updatedFromStore); }
Example 5
Source File: AtlasEntityStoreV2Test.java From atlas with Apache License 2.0 | 4 votes |
@Test(priority = -1) public void testCreate() throws Exception { init(); EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(deptEntity), false); validateMutationResponse(response, EntityOperation.CREATE, 5); AtlasEntityHeader dept1 = response.getFirstCreatedEntityByTypeName(TestUtilsV2.DEPARTMENT_TYPE); validateEntity(deptEntity, getEntityFromStore(dept1), deptEntity.getEntities().get(0)); final Map<EntityOperation, List<AtlasEntityHeader>> entitiesMutated = response.getMutatedEntities(); List<AtlasEntityHeader> entitiesCreated = entitiesMutated.get(EntityOperation.CREATE); assertTrue(entitiesCreated.size() >= deptEntity.getEntities().size()); for (int i = 0; i < deptEntity.getEntities().size(); i++) { AtlasEntity expected = deptEntity.getEntities().get(i); AtlasEntity actual = getEntityFromStore(entitiesCreated.get(i)); validateEntity(deptEntity, actual, expected); } //Create DB init(); EntityMutationResponse dbCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false); validateMutationResponse(dbCreationResponse, EntityOperation.CREATE, 1); dbEntityGuid = dbCreationResponse.getCreatedEntities().get(0).getGuid(); AtlasEntityHeader db1 = dbCreationResponse.getFirstCreatedEntityByTypeName(TestUtilsV2.DATABASE_TYPE); validateEntity(dbEntity, getEntityFromStore(db1)); //Create Table //Update DB guid AtlasObjectId dbObjectId = (AtlasObjectId) tblEntity.getEntity().getAttribute("database"); dbObjectId.setGuid(db1.getGuid()); tblEntity.addReferredEntity(dbEntity.getEntity()); init(); EntityMutationResponse tableCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(tblEntity), false); validateMutationResponse(tableCreationResponse, EntityOperation.CREATE, 1); tblEntityGuid = tableCreationResponse.getCreatedEntities().get(0).getGuid(); AtlasEntityHeader tableEntity = tableCreationResponse.getFirstCreatedEntityByTypeName(TABLE_TYPE); validateEntity(tblEntity, getEntityFromStore(tableEntity)); //Create nested-collection attribute entity init(); EntityMutationResponse entityMutationResponse = entityStore.createOrUpdate(new AtlasEntityStream(nestedCollectionAttrEntity), false); validateMutationResponse(entityMutationResponse, EntityOperation.CREATE, 1); AtlasEntityHeader createdEntity = entityMutationResponse.getFirstCreatedEntityByTypeName(TestUtilsV2.ENTITY_TYPE_WITH_NESTED_COLLECTION_ATTR); validateEntity(nestedCollectionAttrEntity, getEntityFromStore(createdEntity)); }
Example 6
Source File: AtlasEntityStoreV1Test.java From incubator-atlas with Apache License 2.0 | 4 votes |
@Test public void testCreate() throws Exception { init(); EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(deptEntity), false); validateMutationResponse(response, EntityOperation.CREATE, 5); AtlasEntityHeader dept1 = response.getFirstCreatedEntityByTypeName(TestUtilsV2.DEPARTMENT_TYPE); validateEntity(deptEntity, getEntityFromStore(dept1), deptEntity.getEntities().get(0)); final Map<EntityOperation, List<AtlasEntityHeader>> entitiesMutated = response.getMutatedEntities(); List<AtlasEntityHeader> entitiesCreated = entitiesMutated.get(EntityOperation.CREATE); Assert.assertTrue(entitiesCreated.size() >= deptEntity.getEntities().size()); for (int i = 0; i < deptEntity.getEntities().size(); i++) { AtlasEntity expected = deptEntity.getEntities().get(i); AtlasEntity actual = getEntityFromStore(entitiesCreated.get(i)); validateEntity(deptEntity, actual, expected); } //Create DB init(); EntityMutationResponse dbCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false); validateMutationResponse(dbCreationResponse, EntityOperation.CREATE, 1); AtlasEntityHeader db1 = dbCreationResponse.getFirstCreatedEntityByTypeName(TestUtilsV2.DATABASE_TYPE); validateEntity(dbEntity, getEntityFromStore(db1)); //Create Table //Update DB guid AtlasObjectId dbObjectId = (AtlasObjectId) tblEntity.getEntity().getAttribute("database"); dbObjectId.setGuid(db1.getGuid()); tblEntity.addReferredEntity(dbEntity.getEntity()); init(); EntityMutationResponse tableCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(tblEntity), false); validateMutationResponse(tableCreationResponse, EntityOperation.CREATE, 1); AtlasEntityHeader tableEntity = tableCreationResponse.getFirstCreatedEntityByTypeName(TABLE_TYPE); validateEntity(tblEntity, getEntityFromStore(tableEntity)); }
Example 7
Source File: AtlasDeleteHandlerV1Test.java From incubator-atlas with Apache License 2.0 | 4 votes |
@Test public void testDeleteReference() throws Exception { //Deleting column should update table final AtlasEntity dbEntity = TestUtilsV2.createDBEntity(); init(); EntityMutationResponse dbCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false); final AtlasEntity tableEntity = TestUtilsV2.createTableEntity(dbEntity); final AtlasEntity columnEntity = TestUtilsV2.createColumnEntity(tableEntity); tableEntity.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(AtlasTypeUtil.getAtlasObjectId(columnEntity))); AtlasEntity.AtlasEntityWithExtInfo input = new AtlasEntity.AtlasEntityWithExtInfo(tableEntity); input.addReferredEntity(columnEntity); init(); EntityMutationResponse tblCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(input), false); final AtlasEntityHeader columnCreated = tblCreationResponse.getFirstCreatedEntityByTypeName(COLUMN_TYPE); final AtlasEntityHeader tableCreated = tblCreationResponse.getFirstCreatedEntityByTypeName(TABLE_TYPE); init(); EntityMutationResponse deletionResponse = entityStore.deleteById(columnCreated.getGuid()); assertEquals(deletionResponse.getDeletedEntities().size(), 1); assertEquals(deletionResponse.getDeletedEntities().get(0).getGuid(), columnCreated.getGuid()); assertEquals(deletionResponse.getUpdatedEntities().size(), 1); assertEquals(deletionResponse.getUpdatedEntities().get(0).getGuid(), tableCreated.getGuid()); assertEntityDeleted(columnCreated.getGuid()); assertColumnForTestDeleteReference(entityStore.getById(tableCreated.getGuid())); //Deleting table should update process AtlasEntity process = TestUtilsV2.createProcessEntity(null, Arrays.asList(AtlasTypeUtil.getAtlasObjectId(tableCreated))); init(); final EntityMutationResponse processCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(process), false); init(); entityStore.deleteById(tableCreated.getGuid()); assertEntityDeleted(tableCreated.getGuid()); assertTableForTestDeleteReference(tableCreated.getGuid()); assertProcessForTestDeleteReference(processCreationResponse.getFirstEntityCreated()); }
Example 8
Source File: AtlasDeleteHandlerV1Test.java From incubator-atlas with Apache License 2.0 | 4 votes |
/** * Verify deleting an entity which is contained by another * entity through a bi-directional composite reference. * * @throws Exception */ @Test public void testDisconnectBidirectionalReferences() throws Exception { AtlasEntity.AtlasEntitiesWithExtInfo hrDept = TestUtilsV2.createDeptEg2(); init(); final EntityMutationResponse hrDeptCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(hrDept), false); final AtlasEntityHeader deptCreated = hrDeptCreationResponse.getFirstCreatedEntityByTypeName(DEPARTMENT_TYPE); final AtlasEntityHeader maxEmployee = hrDeptCreationResponse.getCreatedEntityByTypeNameAndAttribute(TestUtilsV2.EMPLOYEE_TYPE, NAME, "Max"); final AtlasEntityHeader johnEmployee = hrDeptCreationResponse.getCreatedEntityByTypeNameAndAttribute(TestUtilsV2.EMPLOYEE_TYPE, NAME, "John"); final AtlasEntityHeader janeEmployee = hrDeptCreationResponse.getCreatedEntityByTypeNameAndAttribute(TestUtilsV2.MANAGER_TYPE, NAME, "Jane"); final AtlasEntityHeader juliusEmployee = hrDeptCreationResponse.getCreatedEntityByTypeNameAndAttribute(TestUtilsV2.MANAGER_TYPE, NAME, "Julius"); ITypedReferenceableInstance hrDeptInstance = metadataService.getEntityDefinition(deptCreated.getGuid()); Map<String, String> nameGuidMap = getEmployeeNameGuidMap(hrDeptInstance); // Verify that Max is one of Jane's subordinates. ITypedReferenceableInstance jane = metadataService.getEntityDefinition(janeEmployee.getGuid()); Object refValue = jane.get("subordinates"); Assert.assertTrue(refValue instanceof List); List<Object> subordinates = (List<Object>)refValue; Assert.assertEquals(subordinates.size(), 2); List<String> subordinateIds = new ArrayList<>(2); for (Object listValue : subordinates) { Assert.assertTrue(listValue instanceof ITypedReferenceableInstance); ITypedReferenceableInstance employee = (ITypedReferenceableInstance) listValue; subordinateIds.add(employee.getId()._getId()); } Assert.assertTrue(subordinateIds.contains(maxEmployee.getGuid())); init(); EntityMutationResponse entityResult = entityStore.deleteById(maxEmployee.getGuid()); ITypedReferenceableInstance john = metadataService.getEntityDefinitionReference(TestUtilsV2.EMPLOYEE_TYPE, NAME, "John"); assertEquals(entityResult.getDeletedEntities().size(), 1); assertEquals(entityResult.getDeletedEntities().get(0).getGuid(), maxEmployee.getGuid()); assertEquals(entityResult.getUpdatedEntities().size(), 3); assertEquals(extractGuids(entityResult.getUpdatedEntities()), Arrays.asList(janeEmployee.getGuid(), deptCreated.getGuid(), johnEmployee.getGuid())); assertEntityDeleted(maxEmployee.getGuid()); assertMaxForTestDisconnectBidirectionalReferences(nameGuidMap); // Now delete jane - this should disconnect the manager reference from her // subordinate. init(); entityResult = entityStore.deleteById(janeEmployee.getGuid()); assertEquals(entityResult.getDeletedEntities().size(), 1); assertEquals(entityResult.getDeletedEntities().get(0).getGuid(), janeEmployee.getGuid()); assertEquals(entityResult.getUpdatedEntities().size(), 2); assertEquals(extractGuids(entityResult.getUpdatedEntities()), Arrays.asList(deptCreated.getGuid(), johnEmployee.getGuid())); assertEntityDeleted(janeEmployee.getGuid()); final AtlasEntity.AtlasEntityWithExtInfo johnUpdated = entityStore.getById(johnEmployee.getGuid()); assertJohnForTestDisconnectBidirectionalReferences(johnUpdated, janeEmployee.getGuid()); }