use of org.apache.atlas.model.instance.AtlasEntityHeader in project incubator-atlas by apache.
the class AtlasEntityStoreV1Test method testUpdateEntityWithMap.
@Test(dependsOnMethods = "testCreate")
public void testUpdateEntityWithMap() throws Exception {
AtlasEntity tableEntity = new AtlasEntity(tblEntity.getEntity());
AtlasEntitiesWithExtInfo entitiesInfo = new AtlasEntitiesWithExtInfo(tableEntity);
Map<String, AtlasStruct> partsMap = new HashMap<>();
partsMap.put("part0", new AtlasStruct(TestUtils.PARTITION_STRUCT_TYPE, TestUtilsV2.NAME, "test"));
tableEntity.setAttribute("partitionsMap", partsMap);
init();
EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
AtlasEntityHeader tableDefinition1 = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
AtlasEntity updatedTableDef1 = getEntityFromStore(tableDefinition1);
validateEntity(entitiesInfo, updatedTableDef1);
Assert.assertTrue(partsMap.get("part0").equals(((Map<String, AtlasStruct>) updatedTableDef1.getAttribute("partitionsMap")).get("part0")));
//update map - add a map key
partsMap.put("part1", new AtlasStruct(TestUtils.PARTITION_STRUCT_TYPE, TestUtilsV2.NAME, "test1"));
tableEntity.setAttribute("partitionsMap", partsMap);
init();
response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
AtlasEntityHeader tableDefinition2 = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
AtlasEntity updatedTableDef2 = getEntityFromStore(tableDefinition2);
validateEntity(entitiesInfo, updatedTableDef2);
assertEquals(((Map<String, AtlasStruct>) updatedTableDef2.getAttribute("partitionsMap")).size(), 2);
Assert.assertTrue(partsMap.get("part1").equals(((Map<String, AtlasStruct>) updatedTableDef2.getAttribute("partitionsMap")).get("part1")));
//update map - remove a key and add another key
partsMap.remove("part0");
partsMap.put("part2", new AtlasStruct(TestUtils.PARTITION_STRUCT_TYPE, TestUtilsV2.NAME, "test2"));
tableEntity.setAttribute("partitionsMap", partsMap);
init();
response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
AtlasEntityHeader tableDefinition3 = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
AtlasEntity updatedTableDef3 = getEntityFromStore(tableDefinition3);
validateEntity(entitiesInfo, updatedTableDef3);
assertEquals(((Map<String, AtlasStruct>) updatedTableDef3.getAttribute("partitionsMap")).size(), 2);
Assert.assertNull(((Map<String, AtlasStruct>) updatedTableDef3.getAttribute("partitionsMap")).get("part0"));
Assert.assertTrue(partsMap.get("part2").equals(((Map<String, AtlasStruct>) updatedTableDef3.getAttribute("partitionsMap")).get("part2")));
//update struct value for existing map key
AtlasStruct partition2 = partsMap.get("part2");
partition2.setAttribute(TestUtilsV2.NAME, "test2Updated");
init();
response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
AtlasEntityHeader tableDefinition4 = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
AtlasEntity updatedTableDef4 = getEntityFromStore(tableDefinition4);
validateEntity(entitiesInfo, updatedTableDef4);
assertEquals(((Map<String, AtlasStruct>) updatedTableDef4.getAttribute("partitionsMap")).size(), 2);
Assert.assertNull(((Map<String, AtlasStruct>) updatedTableDef4.getAttribute("partitionsMap")).get("part0"));
Assert.assertTrue(partsMap.get("part2").equals(((Map<String, AtlasStruct>) updatedTableDef4.getAttribute("partitionsMap")).get("part2")));
//Test map pointing to a class
AtlasEntity col0 = new AtlasEntity(TestUtilsV2.COLUMN_TYPE, TestUtilsV2.NAME, "test1");
col0.setAttribute("type", "string");
col0.setAttribute("table", AtlasTypeUtil.getAtlasObjectId(tableEntity));
AtlasEntityWithExtInfo col0WithExtendedInfo = new AtlasEntityWithExtInfo(col0);
col0WithExtendedInfo.addReferredEntity(tableEntity);
col0WithExtendedInfo.addReferredEntity(dbEntity.getEntity());
init();
entityStore.createOrUpdate(new AtlasEntityStream(col0WithExtendedInfo), false);
AtlasEntity col1 = new AtlasEntity(TestUtils.COLUMN_TYPE, TestUtilsV2.NAME, "test2");
col1.setAttribute("type", "string");
col1.setAttribute("table", AtlasTypeUtil.getAtlasObjectId(tableEntity));
AtlasEntityWithExtInfo col1WithExtendedInfo = new AtlasEntityWithExtInfo(col1);
col1WithExtendedInfo.addReferredEntity(tableEntity);
col1WithExtendedInfo.addReferredEntity(dbEntity.getEntity());
init();
entityStore.createOrUpdate(new AtlasEntityStream(col1WithExtendedInfo), false);
Map<String, AtlasObjectId> columnsMap = new HashMap<String, AtlasObjectId>();
columnsMap.put("col0", AtlasTypeUtil.getAtlasObjectId(col0));
columnsMap.put("col1", AtlasTypeUtil.getAtlasObjectId(col1));
tableEntity.setAttribute(TestUtils.COLUMNS_MAP, columnsMap);
entitiesInfo.addReferredEntity(col0);
entitiesInfo.addReferredEntity(col1);
init();
response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
AtlasEntityHeader tableDefinition5 = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
validateEntity(entitiesInfo, getEntityFromStore(tableDefinition5));
//Swap elements
columnsMap.clear();
columnsMap.put("col0", AtlasTypeUtil.getAtlasObjectId(col1));
columnsMap.put("col1", AtlasTypeUtil.getAtlasObjectId(col0));
tableEntity.setAttribute(TestUtils.COLUMNS_MAP, columnsMap);
init();
response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
AtlasEntityHeader tableDefinition6 = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
validateEntity(entitiesInfo, getEntityFromStore(tableDefinition6));
Assert.assertEquals(entityStore.getById(col0.getGuid()).getEntity().getStatus(), AtlasEntity.Status.ACTIVE);
Assert.assertEquals(entityStore.getById(col1.getGuid()).getEntity().getStatus(), AtlasEntity.Status.ACTIVE);
//Drop the first key and change the class type as well to col0
columnsMap.clear();
columnsMap.put("col0", AtlasTypeUtil.getAtlasObjectId(col0));
init();
response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
AtlasEntityHeader tableDefinition7 = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
validateEntity(entitiesInfo, getEntityFromStore(tableDefinition7));
//Clear state
tableEntity.setAttribute(TestUtils.COLUMNS_MAP, null);
init();
response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
AtlasEntityHeader tableDefinition8 = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
validateEntity(entitiesInfo, getEntityFromStore(tableDefinition8));
}
use of org.apache.atlas.model.instance.AtlasEntityHeader in project incubator-atlas by apache.
the class AtlasEntityStoreV1Test method testStructs.
@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));
//update struct attribute
serdeInstance.setAttribute("serde", "testUpdated");
init();
response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
validateEntity(entitiesInfo, getEntityFromStore(updatedTable));
//set to null
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));
}
use of org.apache.atlas.model.instance.AtlasEntityHeader in project incubator-atlas by apache.
the class AtlasEntityStoreV1 method updateImportMetrics.
private void updateImportMetrics(String prefix, List<AtlasEntityHeader> list, Set<String> processedGuids, AtlasImportResult importResult) {
if (list == null) {
return;
}
for (AtlasEntityHeader h : list) {
if (processedGuids.contains(h.getGuid())) {
continue;
}
processedGuids.add(h.getGuid());
importResult.incrementMeticsCounter(String.format(prefix, h.getTypeName()));
}
}
use of org.apache.atlas.model.instance.AtlasEntityHeader in project incubator-atlas by apache.
the class TestEntitiesREST method testCreateOrUpdateEntities.
@Test
public void testCreateOrUpdateEntities() throws Exception {
AtlasEntitiesWithExtInfo entities = new AtlasEntitiesWithExtInfo();
entities.addEntity(dbEntity);
entities.addEntity(tableEntity);
for (AtlasEntity column : columns) {
entities.addReferredEntity(column);
}
EntityMutationResponse response = entityREST.createOrUpdate(entities);
List<AtlasEntityHeader> guids = response.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE);
Assert.assertNotNull(guids);
Assert.assertEquals(guids.size(), 3);
for (AtlasEntityHeader header : guids) {
createdGuids.add(header.getGuid());
}
}
use of org.apache.atlas.model.instance.AtlasEntityHeader in project incubator-atlas by apache.
the class TestEntityREST method testDeleteEntityById.
@Test(dependsOnMethods = "testDeleteClassification")
public void testDeleteEntityById() throws Exception {
EntityMutationResponse response = entityREST.deleteByGuid(dbEntity.getGuid());
List<AtlasEntityHeader> entitiesMutated = response.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE);
Assert.assertNotNull(entitiesMutated);
Assert.assertEquals(entitiesMutated.get(0).getGuid(), dbEntity.getGuid());
}
Aggregations