AtlasEntityStoreV1 implements AtlasEntityStore { private EntityMutationResponse createOrUpdate(EntityStream entityStream, boolean isPartialUpdate, boolean replaceClassifications) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> createOrUpdate()"); } if (entityStream == null || !entityStream.hasNext()) { throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "no entities to create/update."); } EntityMutationContext context = preCreateOrUpdate(entityStream, entityGraphMapper, isPartialUpdate); EntityMutationResponse ret = entityGraphMapper.mapAttributesAndClassifications(context, isPartialUpdate, replaceClassifications); ret.setGuidAssignments(context.getGuidAssignments()); if (LOG.isDebugEnabled()) { LOG.debug("<== createOrUpdate()"); } entityChangeNotifier.onEntitiesMutated(ret, entityStream instanceof EntityImportStream); return ret; } @Inject  AtlasEntityStoreV1(DeleteHandlerV1 deleteHandler, AtlasTypeRegistry typeRegistry,
                              AtlasEntityChangeNotifier entityChangeNotifier, EntityGraphMapper entityGraphMapper); @Override @GraphTransaction AtlasEntityWithExtInfo getById(String guid); @Override @GraphTransaction AtlasEntitiesWithExtInfo getByIds(List<String> guids); @Override @GraphTransaction AtlasEntityWithExtInfo getByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> uniqAttributes); @Override @GraphTransaction EntityMutationResponse bulkImport(EntityImportStream entityStream, AtlasImportResult importResult); @Override @GraphTransaction EntityMutationResponse createOrUpdate(EntityStream entityStream, boolean isPartialUpdate); @Override @GraphTransaction EntityMutationResponse updateByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> uniqAttributes,
                                                           AtlasEntityWithExtInfo updatedEntityInfo); @Override @GraphTransaction EntityMutationResponse updateEntityAttributeByGuid(String guid, String attrName, Object attrValue); @Override @GraphTransaction EntityMutationResponse deleteById(final String guid); @Override @GraphTransaction EntityMutationResponse deleteByIds(final List<String> guids); @Override @GraphTransaction EntityMutationResponse deleteByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> uniqAttributes); @Override @GraphTransaction void addClassifications(final String guid, final List<AtlasClassification> classifications); @Override @GraphTransaction void updateClassifications(String guid, List<AtlasClassification> newClassifications); @Override @GraphTransaction void addClassification(final List<String> guids, final AtlasClassification classification); @Override @GraphTransaction void deleteClassifications(final String guid, final List<String> classificationNames); @Override @GraphTransaction List<AtlasClassification> getClassifications(String guid); @Override @GraphTransaction AtlasClassification getClassification(String guid, String classificationName);  }
@Test public void testDefaultValueForPrimitiveTypes() throws Exception { init(); EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(primitiveEntity), false); List<AtlasEntityHeader> entitiesCreatedResponse = response.getEntitiesByOperation(EntityOperation.CREATE); final Map<EntityOperation, List<AtlasEntityHeader>> entitiesMutated = response.getMutatedEntities(); List<AtlasEntityHeader> entitiesCreatedwithdefault = entitiesMutated.get(EntityOperation.CREATE); AtlasEntity entityCreated = getEntityFromStore(entitiesCreatedResponse.get(0)); Map attributesMap = entityCreated.getAttributes(); String description = (String) attributesMap.get("description"); String check = (String) attributesMap.get("check"); String sourceCode = (String) attributesMap.get("sourcecode"); float diskUsage = (float) attributesMap.get("diskUsage"); boolean isstoreUse = (boolean) attributesMap.get("isstoreUse"); int cost = (int)attributesMap.get("Cost"); assertEquals(description,"test"); assertEquals(check,"check"); assertEquals(diskUsage,70.5f); assertEquals(isstoreUse,true); assertEquals(sourceCode,"Hello World"); assertEquals(cost,30); }
@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); } 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)); 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)); }
@Test(dependsOnMethods = "testCreate") public void testArrayOfEntityUpdate() throws Exception { AtlasEntity tableEntity = new AtlasEntity(tblEntity.getEntity()); List<AtlasObjectId> columns = new ArrayList<>(); AtlasEntitiesWithExtInfo entitiesInfo = new AtlasEntitiesWithExtInfo(tableEntity); AtlasEntity col1 = TestUtilsV2.createColumnEntity(tableEntity); col1.setAttribute(TestUtilsV2.NAME, "col1"); AtlasEntity col2 = TestUtilsV2.createColumnEntity(tableEntity); col2.setAttribute(TestUtilsV2.NAME, "col2"); columns.add(AtlasTypeUtil.getAtlasObjectId(col1)); columns.add(AtlasTypeUtil.getAtlasObjectId(col2)); tableEntity.setAttribute(TestUtilsV2.COLUMNS_ATTR_NAME, columns); entitiesInfo.addReferredEntity(dbEntity.getEntity()); entitiesInfo.addReferredEntity(col1); entitiesInfo.addReferredEntity(col2); init(); EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false); AtlasEntityHeader updatedTableHeader = response.getFirstUpdatedEntityByTypeName(tableEntity.getTypeName()); validateEntity(entitiesInfo, getEntityFromStore(updatedTableHeader)); AtlasEntity col3 = TestUtilsV2.createColumnEntity(tableEntity); col3.setAttribute(TestUtilsV2.NAME, "col3"); AtlasEntity col4 = TestUtilsV2.createColumnEntity(tableEntity); col4.setAttribute(TestUtilsV2.NAME, "col4"); columns.add(AtlasTypeUtil.getAtlasObjectId(col3)); columns.add(AtlasTypeUtil.getAtlasObjectId(col4)); tableEntity.setAttribute(TestUtilsV2.COLUMNS_ATTR_NAME, columns); entitiesInfo.addReferredEntity(col3); entitiesInfo.addReferredEntity(col4); init(); response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false); updatedTableHeader = response.getFirstUpdatedEntityByTypeName(tableEntity.getTypeName()); validateEntity(entitiesInfo, getEntityFromStore(updatedTableHeader)); columns.clear(); columns.add(AtlasTypeUtil.getAtlasObjectId(col4)); columns.add(AtlasTypeUtil.getAtlasObjectId(col3)); tableEntity.setAttribute(TestUtilsV2.COLUMNS_ATTR_NAME, columns); init(); response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false); updatedTableHeader = response.getFirstUpdatedEntityByTypeName(tableEntity.getTypeName()); AtlasEntity updatedEntity = getEntityFromStore(updatedTableHeader); Assert.assertTrue(((List<AtlasObjectId>) updatedEntity.getAttribute(COLUMNS_ATTR_NAME)).size() >= 2); assertEquals(response.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE).size(), 2); tableEntity.setAttribute(COLUMNS_ATTR_NAME, null); init(); response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false); updatedTableHeader = response.getFirstUpdatedEntityByTypeName(tableEntity.getTypeName()); validateEntity(entitiesInfo, getEntityFromStore(updatedTableHeader)); assertEquals(response.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE).size(), 2); }
@Test(dependsOnMethods = "testCreate") public void testMapOfPrimitivesUpdate() throws Exception { AtlasEntity tableEntity = new AtlasEntity(tblEntity.getEntity()); AtlasEntitiesWithExtInfo entitiesInfo = new AtlasEntitiesWithExtInfo(tableEntity); entitiesInfo.addReferredEntity(tableEntity); Map<String, String> paramsMap = (Map<String, String>) tableEntity.getAttribute("parametersMap"); paramsMap.put("newParam", "value"); init(); EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false); validateMutationResponse(response, EntityMutations.EntityOperation.UPDATE, 1); AtlasEntityHeader updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE); validateEntity(entitiesInfo, getEntityFromStore(updatedTable)); paramsMap.remove("key1"); init(); response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false); validateMutationResponse(response, EntityMutations.EntityOperation.UPDATE, 1); updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE); validateEntity(entitiesInfo, getEntityFromStore(updatedTable)); }
@Test(dependsOnMethods = "testCreate") public void testArrayOfStructs() throws Exception { AtlasEntity tableEntity = new AtlasEntity(tblEntity.getEntity()); AtlasEntitiesWithExtInfo entitiesInfo = new AtlasEntitiesWithExtInfo(tableEntity); List<AtlasStruct> partitions = new ArrayList<AtlasStruct>(){{ add(new AtlasStruct(TestUtilsV2.PARTITION_STRUCT_TYPE, TestUtilsV2.NAME, "part1")); add(new AtlasStruct(TestUtilsV2.PARTITION_STRUCT_TYPE, TestUtilsV2.NAME, "part2")); }}; tableEntity.setAttribute("partitions", partitions); init(); EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false); AtlasEntityHeader updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE); validateEntity(entitiesInfo, getEntityFromStore(updatedTable)); partitions.add(new AtlasStruct(TestUtils.PARTITION_STRUCT_TYPE, TestUtilsV2.NAME, "part3")); init(); response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false); updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE); validateEntity(entitiesInfo, getEntityFromStore(updatedTable)); init(); partitions.remove(1); response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false); updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE); validateEntity(entitiesInfo, getEntityFromStore(updatedTable)); init(); partitions.get(0).setAttribute(TestUtilsV2.NAME, "part4"); response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false); updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE); validateEntity(entitiesInfo, getEntityFromStore(updatedTable)); partitions.add(new AtlasStruct(TestUtils.PARTITION_STRUCT_TYPE, TestUtilsV2.NAME, "part4")); init(); response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false); updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE); validateEntity(entitiesInfo, getEntityFromStore(updatedTable)); partitions.clear(); init(); response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false); updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE); validateEntity(entitiesInfo, getEntityFromStore(updatedTable)); }
@Test(dependsOnMethods = "testCreate") public void testStructs() throws Exception { AtlasEntity databaseEntity = dbEntity.getEntity(); AtlasEntity tableEntity = new AtlasEntity(tblEntity.getEntity()); AtlasEntitiesWithExtInfo entitiesInfo = new AtlasEntitiesWithExtInfo(tableEntity); AtlasStruct serdeInstance = new AtlasStruct(TestUtils.SERDE_TYPE, TestUtilsV2.NAME, "serde1Name"); serdeInstance.setAttribute("serde", "test"); serdeInstance.setAttribute("description", "testDesc"); tableEntity.setAttribute("serde1", serdeInstance); tableEntity.setAttribute("database", new AtlasObjectId(databaseEntity.getTypeName(), TestUtilsV2.NAME, databaseEntity.getAttribute(TestUtilsV2.NAME))); init(); EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false); AtlasEntityHeader updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE); validateEntity(entitiesInfo, getEntityFromStore(updatedTable)); serdeInstance.setAttribute("serde", "testUpdated"); init(); response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false); updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE); validateEntity(entitiesInfo, getEntityFromStore(updatedTable)); tableEntity.setAttribute("description", null); init(); response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false); updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE); Assert.assertNull(updatedTable.getAttribute("description")); validateEntity(entitiesInfo, getEntityFromStore(updatedTable)); }
@Test(dependsOnMethods = "testCreate") public void testClassUpdate() throws Exception { init(); 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()); }
@Test public void testCheckOptionalAttrValueRetention() throws Exception { AtlasEntity dbEntity = TestUtilsV2.createDBEntity(); init(); EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false); AtlasEntity firstEntityCreated = getEntityFromStore(response.getFirstCreatedEntityByTypeName(TestUtilsV2.DATABASE_TYPE)); final String isReplicatedAttr = "isReplicated"; final String paramsAttr = "parameters"; Assert.assertNotNull(firstEntityCreated.getAttribute(isReplicatedAttr)); Assert.assertEquals(firstEntityCreated.getAttribute(isReplicatedAttr), Boolean.FALSE); Assert.assertNull(firstEntityCreated.getAttribute(paramsAttr)); dbEntity.setAttribute(isReplicatedAttr, Boolean.TRUE); final HashMap<String, String> params = new HashMap<String, String>() {{ put("param1", "val1"); put("param2", "val2"); }}; dbEntity.setAttribute(paramsAttr, params); init(); response = entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false); AtlasEntity firstEntityUpdated = getEntityFromStore(response.getFirstUpdatedEntityByTypeName(TestUtilsV2.DATABASE_TYPE)); Assert.assertNotNull(firstEntityUpdated); Assert.assertNotNull(firstEntityUpdated.getAttribute(isReplicatedAttr)); Assert.assertEquals(firstEntityUpdated.getAttribute(isReplicatedAttr), Boolean.TRUE); Assert.assertEquals(firstEntityUpdated.getAttribute(paramsAttr), params); }
@Test(enabled = false) public void testSpecialCharacters() throws Exception { final String typeName = "test_type_"+ RandomStringUtils.randomAlphanumeric(10); String strAttrName = randomStrWithReservedChars(); String arrayAttrName = randomStrWithReservedChars(); String mapAttrName = randomStrWithReservedChars(); AtlasEntityDef typeDefinition = AtlasTypeUtil.createClassTypeDef(typeName, "Special chars test type", ImmutableSet.<String>of(), AtlasTypeUtil.createOptionalAttrDef(strAttrName, "string"), AtlasTypeUtil.createOptionalAttrDef(arrayAttrName, "array<string>"), AtlasTypeUtil.createOptionalAttrDef(mapAttrName, "map<string,string>")); AtlasTypesDef atlasTypesDef = new AtlasTypesDef(null, null, null, Arrays.asList(typeDefinition)); typeDefStore.createTypesDef(atlasTypesDef); AtlasEntity entity = new AtlasEntity(); entity.setAttribute(strAttrName, randomStrWithReservedChars()); entity.setAttribute(arrayAttrName, new String[]{randomStrWithReservedChars()}); entity.setAttribute(mapAttrName, new HashMap<String, String>() {{ put(randomStrWithReservedChars(), randomStrWithReservedChars()); }}); AtlasEntityWithExtInfo entityWithExtInfo = new AtlasEntityWithExtInfo(entity); final EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(entityWithExtInfo), false); final AtlasEntityHeader firstEntityCreated = response.getFirstEntityCreated(); validateEntity(entityWithExtInfo, getEntityFromStore(firstEntityCreated)); }
@Test(expectedExceptions = AtlasBaseException.class) public void testCreateRequiredAttrNull() throws Exception { Map<String, AtlasEntity> tableCloneMap = new HashMap<>(); AtlasEntity tableEntity = new AtlasEntity(TABLE_TYPE); tableEntity.setAttribute(TestUtilsV2.NAME, "table_" + TestUtils.randomString()); tableCloneMap.put(tableEntity.getGuid(), tableEntity); entityStore.createOrUpdate(new InMemoryMapEntityStream(tableCloneMap), false); Assert.fail("Expected exception while creating with required attribute null"); }
@Test public void testPartialUpdateAttr() throws Exception { init(); AtlasEntity dbEntity = new AtlasEntity(TestUtilsV2.DATABASE_TYPE); dbEntity.setAttribute("name", RandomStringUtils.randomAlphanumeric(10)); dbEntity.setAttribute("description", "us db"); dbEntity.setAttribute("isReplicated", false); dbEntity.setAttribute("created", "09081988"); dbEntity.setAttribute("namespace", "db namespace"); dbEntity.setAttribute("cluster", "Fenton_Cluster"); dbEntity.setAttribute("colo", "10001"); EntityStream dbStream = new AtlasEntityStream(new AtlasEntitiesWithExtInfo(dbEntity)); EntityMutationResponse response = entityStore.createOrUpdate(dbStream, false); AtlasEntityHeader dbHeader = response.getFirstEntityCreated(); AtlasEntity createdDbEntity = getEntityFromStore(dbHeader); dbEntity = new AtlasEntity(TestUtilsV2.DATABASE_TYPE); dbEntity.setGuid(createdDbEntity.getGuid()); dbEntity.setAttribute("created", "08151947"); dbEntity.setAttribute("isReplicated", true); dbStream = new AtlasEntityStream(new AtlasEntitiesWithExtInfo(dbEntity)); try { entityStore.createOrUpdate(dbStream, false); } catch (AtlasBaseException ex) { Assert.assertEquals(ex.getAtlasErrorCode(), AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS); } dbStream.reset(); response = entityStore.createOrUpdate(dbStream, true); dbHeader = response.getFirstEntityPartialUpdated(); AtlasEntity updatedDbEntity = getEntityFromStore(dbHeader); assertEquals(updatedDbEntity.getAttribute("name"), createdDbEntity.getAttribute("name")); assertEquals(updatedDbEntity.getAttribute("description"), createdDbEntity.getAttribute("description")); assertEquals(updatedDbEntity.getAttribute("isReplicated"), true); assertEquals(updatedDbEntity.getAttribute("created"), "08151947"); assertEquals(updatedDbEntity.getAttribute("namespace"), createdDbEntity.getAttribute("namespace")); assertEquals(updatedDbEntity.getAttribute("cluster"), createdDbEntity.getAttribute("cluster")); assertEquals(updatedDbEntity.getAttribute("colo"), createdDbEntity.getAttribute("colo")); AtlasEntity tblEntity = new AtlasEntity(TABLE_TYPE); tblEntity.setAttribute("name", RandomStringUtils.randomAlphanumeric(10)); tblEntity.setAttribute("type", "type"); tblEntity.setAttribute("tableType", "MANAGED"); tblEntity.setAttribute("database", AtlasTypeUtil.getAtlasObjectId(updatedDbEntity)); AtlasEntity col1 = TestUtilsV2.createColumnEntity(tblEntity); AtlasEntity col2 = TestUtilsV2.createColumnEntity(tblEntity); col1.setAttribute(TestUtilsV2.NAME, "col1"); col2.setAttribute(TestUtilsV2.NAME, "col2"); List<AtlasObjectId> columns = new ArrayList<>(); columns.add(AtlasTypeUtil.getAtlasObjectId(col1)); columns.add(AtlasTypeUtil.getAtlasObjectId(col2)); tblEntity.setAttribute(TestUtilsV2.COLUMNS_ATTR_NAME, columns); AtlasEntitiesWithExtInfo tableEntityInfo = new AtlasEntitiesWithExtInfo(tblEntity); tableEntityInfo.addReferredEntity(col1.getGuid(), col1); tableEntityInfo.addReferredEntity(col2.getGuid(), col2); EntityStream tblStream = new AtlasEntityStream(tableEntityInfo); response = entityStore.createOrUpdate(tblStream, false); AtlasEntityHeader tblHeader = response.getFirstEntityCreated(); AtlasEntity createdTblEntity = getEntityFromStore(tblHeader); columns = (List<AtlasObjectId>) createdTblEntity.getAttribute(TestUtilsV2.COLUMNS_ATTR_NAME); assertEquals(columns.size(), 2); AtlasEntity col3 = TestUtilsV2.createColumnEntity(createdTblEntity); col3.setAttribute(TestUtilsV2.NAME, "col3"); col3.setAttribute("description", "description col3"); AtlasEntity col4 = TestUtilsV2.createColumnEntity(createdTblEntity); col4.setAttribute(TestUtilsV2.NAME, "col4"); col4.setAttribute("description", "description col4"); columns.clear(); columns.add(AtlasTypeUtil.getAtlasObjectId(col3)); columns.add(AtlasTypeUtil.getAtlasObjectId(col4)); tblEntity = new AtlasEntity(TABLE_TYPE); tblEntity.setGuid(createdTblEntity.getGuid()); tblEntity.setAttribute(TestUtilsV2.COLUMNS_ATTR_NAME, columns); tableEntityInfo = new AtlasEntitiesWithExtInfo(tblEntity); tableEntityInfo.addReferredEntity(col3.getGuid(), col3); tableEntityInfo.addReferredEntity(col4.getGuid(), col4); tblStream = new AtlasEntityStream(tableEntityInfo); response = entityStore.createOrUpdate(tblStream, true); tblHeader = response.getFirstEntityPartialUpdated(); AtlasEntity updatedTblEntity = getEntityFromStore(tblHeader); columns = (List<AtlasObjectId>) updatedTblEntity.getAttribute(TestUtilsV2.COLUMNS_ATTR_NAME); assertTrue(columns.size() >= 2); }
@Test public void testPartialUpdateArrayAttr() throws Exception { init(); final AtlasEntity dbEntity = TestUtilsV2.createDBEntity(); EntityMutationResponse dbCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false); final AtlasEntity tableEntity = TestUtilsV2.createTableEntity(dbEntity); AtlasEntitiesWithExtInfo entitiesInfo = new AtlasEntitiesWithExtInfo(tableEntity); final AtlasEntity columnEntity1 = TestUtilsV2.createColumnEntity(tableEntity); columnEntity1.setAttribute("description", "desc for col1"); entitiesInfo.addReferredEntity(columnEntity1); final AtlasEntity columnEntity2 = TestUtilsV2.createColumnEntity(tableEntity); columnEntity2.setAttribute("description", "desc for col2"); entitiesInfo.addReferredEntity(columnEntity2); final AtlasEntity columnEntity3 = TestUtilsV2.createColumnEntity(tableEntity); columnEntity3.setAttribute("description", "desc for col3"); entitiesInfo.addReferredEntity(columnEntity3); tableEntity.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(AtlasTypeUtil.getAtlasObjectId(columnEntity1), AtlasTypeUtil.getAtlasObjectId(columnEntity2), AtlasTypeUtil.getAtlasObjectId(columnEntity3))); init(); final EntityMutationResponse tblCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false); final AtlasEntityHeader createdTblHeader = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(TABLE_TYPE, NAME, (String) tableEntity.getAttribute(NAME)); final AtlasEntity createdTblEntity = getEntityFromStore(createdTblHeader); final AtlasEntityHeader column1Created = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(COLUMN_TYPE, NAME, (String) columnEntity1.getAttribute(NAME)); final AtlasEntityHeader column2Created = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(COLUMN_TYPE, NAME, (String) columnEntity2.getAttribute(NAME)); final AtlasEntityHeader column3Created = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(COLUMN_TYPE, NAME, (String) columnEntity3.getAttribute(NAME)); AtlasEntity col1 = new AtlasEntity(COLUMN_TYPE); col1.setGuid(column1Created.getGuid()); col1.setAttribute("description", "desc for col1:updated"); AtlasEntity col2 = new AtlasEntity(COLUMN_TYPE); col2.setGuid(column2Created.getGuid()); col2.setAttribute("description", "desc for col2:updated"); AtlasEntity col3 = new AtlasEntity(COLUMN_TYPE); col3.setGuid(column3Created.getGuid()); col3.setAttribute("description", "desc for col3:updated"); final AtlasEntity tableEntity1 = new AtlasEntity(TABLE_TYPE); tableEntity1.setGuid(createdTblHeader.getGuid()); tableEntity1.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(AtlasTypeUtil.getAtlasObjectId(col1), AtlasTypeUtil.getAtlasObjectId(col2), AtlasTypeUtil.getAtlasObjectId(col3))); AtlasEntitiesWithExtInfo tableInfo = new AtlasEntitiesWithExtInfo(tableEntity1); tableInfo.addReferredEntity(col1.getGuid(), col1); tableInfo.addReferredEntity(col2.getGuid(), col2); tableInfo.addReferredEntity(col3.getGuid(), col3); init(); final EntityMutationResponse tblUpdateResponse = entityStore.createOrUpdate(new AtlasEntityStream(tableInfo), true); final AtlasEntityHeader updatedTblHeader = tblUpdateResponse.getFirstEntityPartialUpdated(); final AtlasEntity updatedTblEntity2 = getEntityFromStore(updatedTblHeader); List<AtlasEntityHeader> updatedColHeaders = tblUpdateResponse.getPartialUpdatedEntitiesByTypeName(COLUMN_TYPE); final AtlasEntity updatedCol1Entity = getEntityFromStore(updatedColHeaders.get(0)); final AtlasEntity updatedCol2Entity = getEntityFromStore(updatedColHeaders.get(1)); final AtlasEntity updatedCol3Entity = getEntityFromStore(updatedColHeaders.get(2)); assertEquals(col1.getAttribute("description"), updatedCol1Entity.getAttribute("description")); assertEquals(col2.getAttribute("description"), updatedCol2Entity.getAttribute("description")); assertEquals(col3.getAttribute("description"), updatedCol3Entity.getAttribute("description")); }
@Test public void testSetObjectIdAttrToNull() throws Exception { final AtlasEntity dbEntity = TestUtilsV2.createDBEntity(); final AtlasEntity db2Entity = TestUtilsV2.createDBEntity(); entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false); entityStore.createOrUpdate(new AtlasEntityStream(db2Entity), false); final AtlasEntity tableEntity = TestUtilsV2.createTableEntity(dbEntity); tableEntity.setAttribute("databaseComposite", AtlasTypeUtil.getAtlasObjectId(db2Entity)); final EntityMutationResponse tblCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(tableEntity), false); final AtlasEntityHeader createdTblHeader = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(TABLE_TYPE, NAME, (String) tableEntity.getAttribute(NAME)); final AtlasEntity createdTblEntity = getEntityFromStore(createdTblHeader); init(); createdTblEntity.setAttribute("databaseComposite", null); final EntityMutationResponse tblUpdateResponse = entityStore.createOrUpdate(new AtlasEntityStream(createdTblEntity), true); final AtlasEntityHeader updatedTblHeader = tblUpdateResponse.getFirstEntityPartialUpdated(); final AtlasEntity updatedTblEntity = getEntityFromStore(updatedTblHeader); final AtlasEntity deletedDb2Entity = getEntityFromStore(db2Entity.getGuid()); assertEquals(deletedDb2Entity.getStatus(), AtlasEntity.Status.DELETED); }