use of org.apache.atlas.typesystem.Struct in project incubator-atlas by apache.
the class DataSetLineageJerseyResourceIT method testInputsGraph.
@Test
public void testInputsGraph() throws Exception {
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_INPUTS_GRAPH, null, salesMonthlyTable, "inputs", "graph");
Assert.assertNotNull(response);
System.out.println("inputs graph = " + response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
JSONObject results = response.getJSONObject(AtlasClient.RESULTS);
Assert.assertNotNull(results);
Struct resultsInstance = InstanceSerialization.fromJsonStruct(results.toString(), true);
Map<String, Struct> vertices = (Map<String, Struct>) resultsInstance.get("vertices");
Assert.assertEquals(vertices.size(), 4);
Map<String, Struct> edges = (Map<String, Struct>) resultsInstance.get("edges");
Assert.assertEquals(edges.size(), 4);
}
use of org.apache.atlas.typesystem.Struct in project incubator-atlas by apache.
the class KafkaConsumerTest method getEntity.
private Referenceable getEntity(String traitName) {
Referenceable entity = EntityNotificationImplTest.getEntity("id");
List<IStruct> traitInfo = new LinkedList<>();
IStruct trait = new Struct(traitName, Collections.<String, Object>emptyMap());
traitInfo.add(trait);
return entity;
}
use of org.apache.atlas.typesystem.Struct in project incubator-atlas by apache.
the class DataSetLineageServiceTest method testLineageWithDelete.
@Test(enabled = false)
public void testLineageWithDelete() throws Exception {
String tableName = "table" + random();
createTable(tableName, 3, true);
String tableId = getEntityId(HIVE_TABLE_TYPE, "name", tableName);
JSONObject results = getSchema(tableName);
assertEquals(results.getJSONArray("rows").length(), 3);
results = getInputsGraph(tableName);
Struct resultInstance = InstanceSerialization.fromJsonStruct(results.toString(), true);
Map<String, Struct> vertices = (Map) resultInstance.get("vertices");
assertEquals(vertices.size(), 2);
Struct vertex = vertices.get(tableId);
assertEquals(((Struct) vertex.get("vertexId")).get("state"), Id.EntityState.ACTIVE.name());
results = getOutputsGraph(tableName);
assertEquals(results.getJSONObject("values").getJSONObject("vertices").length(), 2);
results = new JSONObject(lineageService.getSchemaForEntity(tableId));
assertEquals(results.getJSONArray("rows").length(), 3);
results = new JSONObject(lineageService.getInputsGraphForEntity(tableId));
assertEquals(results.getJSONObject("values").getJSONObject("vertices").length(), 2);
results = new JSONObject(lineageService.getOutputsGraphForEntity(tableId));
assertEquals(results.getJSONObject("values").getJSONObject("vertices").length(), 2);
//Delete the entity. Lineage for entity returns the same results as before.
//Lineage for table name throws EntityNotFoundException
EntityResult deleteResult = repository.deleteEntities(Arrays.asList(tableId));
assertTrue(deleteResult.getDeletedEntities().contains(tableId));
results = new JSONObject(lineageService.getSchemaForEntity(tableId));
assertEquals(results.getJSONArray("rows").length(), 3);
results = new JSONObject(lineageService.getInputsGraphForEntity(tableId));
resultInstance = InstanceSerialization.fromJsonStruct(results.toString(), true);
vertices = (Map) resultInstance.get("vertices");
assertEquals(vertices.size(), 2);
vertex = vertices.get(tableId);
assertEquals(((Struct) vertex.get("vertexId")).get("state"), Id.EntityState.DELETED.name());
assertEquals(results.getJSONObject("values").getJSONObject("vertices").length(), 2);
results = new JSONObject(lineageService.getOutputsGraphForEntity(tableId));
assertEquals(results.getJSONObject("values").getJSONObject("vertices").length(), 2);
try {
getSchema(tableName);
fail("Expected EntityNotFoundException");
} catch (EntityNotFoundException e) {
//expected
}
try {
getInputsGraph(tableName);
fail("Expected EntityNotFoundException");
} catch (EntityNotFoundException e) {
//expected
}
try {
getOutputsGraph(tableName);
fail("Expected EntityNotFoundException");
} catch (EntityNotFoundException e) {
//expected
}
//Create table again should show new lineage
createTable(tableName, 2, false);
results = getSchema(tableName);
assertEquals(results.getJSONArray("rows").length(), 2);
results = getOutputsGraph(tableName);
assertEquals(results.getJSONObject("values").getJSONObject("vertices").length(), 0);
results = getInputsGraph(tableName);
assertEquals(results.getJSONObject("values").getJSONObject("vertices").length(), 0);
tableId = getEntityId(HIVE_TABLE_TYPE, "name", tableName);
results = new JSONObject(lineageService.getSchemaForEntity(tableId));
assertEquals(results.getJSONArray("rows").length(), 2);
results = new JSONObject(lineageService.getInputsGraphForEntity(tableId));
assertEquals(results.getJSONObject("values").getJSONObject("vertices").length(), 0);
results = new JSONObject(lineageService.getOutputsGraphForEntity(tableId));
assertEquals(results.getJSONObject("values").getJSONObject("vertices").length(), 0);
}
use of org.apache.atlas.typesystem.Struct in project incubator-atlas by apache.
the class DefaultMetadataServiceTest method testEntityAudit.
@Test
public void testEntityAudit() throws Exception {
//create entity
Referenceable entity = createDBEntity();
String id = TestUtils.createInstance(metadataService, entity);
assertAuditEvents(id, EntityAuditEvent.EntityAuditAction.ENTITY_CREATE);
Struct tag = new Struct(TestUtils.PII);
metadataService.addTrait(id, InstanceSerialization.toJson(tag, true));
assertAuditEvents(id, EntityAuditEvent.EntityAuditAction.TAG_ADD);
metadataService.deleteTrait(id, TestUtils.PII);
assertAuditEvents(id, EntityAuditEvent.EntityAuditAction.TAG_DELETE);
metadataService.updateEntityAttributeByGuid(id, "description", "new description");
assertAuditEvents(id, EntityAuditEvent.EntityAuditAction.ENTITY_UPDATE);
metadataService.deleteEntities(Arrays.asList(id));
assertAuditEvents(id, EntityAuditEvent.EntityAuditAction.ENTITY_DELETE);
}
use of org.apache.atlas.typesystem.Struct in project incubator-atlas by apache.
the class DefaultMetadataServiceTest method testAddDeleteTrait.
@Test
public void testAddDeleteTrait() throws Exception {
Referenceable entity = createDBEntity();
String id = TestUtils.createInstance(metadataService, entity);
//add trait
Struct tag = new Struct(TestUtils.PII);
metadataService.addTrait(id, InstanceSerialization.toJson(tag, true));
List<String> traits = metadataService.getTraitNames(id);
assertEquals(traits.size(), 1);
assertEquals(traits.get(0), PII);
//getTrait
IStruct traitDefinition = metadataService.getTraitDefinition(id, PII);
Assert.assertNotNull(traitDefinition);
assertEquals(traitDefinition.getValuesMap().size(), 0);
//delete trait
metadataService.deleteTrait(id, PII);
traits = metadataService.getTraitNames(id);
assertEquals(traits.size(), 0);
//add trait again
metadataService.addTrait(id, InstanceSerialization.toJson(tag, true));
traits = metadataService.getTraitNames(id);
assertEquals(traits.size(), 1);
assertEquals(traits.get(0), PII);
}
Aggregations