Search in sources :

Example 36 with Struct

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);
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) Map(java.util.Map) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Example 37 with Struct

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;
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) LinkedList(java.util.LinkedList) IStruct(org.apache.atlas.typesystem.IStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct)

Example 38 with Struct

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);
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) EntityNotFoundException(org.apache.atlas.typesystem.exception.EntityNotFoundException) EntityResult(org.apache.atlas.model.legacy.EntityResult) Map(java.util.Map) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test) BaseRepositoryTest(org.apache.atlas.BaseRepositoryTest)

Example 39 with Struct

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);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 40 with Struct

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);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct) IStruct(org.apache.atlas.typesystem.IStruct) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

Struct (org.apache.atlas.typesystem.Struct)56 Test (org.testng.annotations.Test)36 IStruct (org.apache.atlas.typesystem.IStruct)29 Referenceable (org.apache.atlas.typesystem.Referenceable)25 ITypedStruct (org.apache.atlas.typesystem.ITypedStruct)17 TraitType (org.apache.atlas.typesystem.types.TraitType)12 ArrayList (java.util.ArrayList)9 LinkedList (java.util.LinkedList)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 Id (org.apache.atlas.typesystem.persistence.Id)7 JSONObject (org.codehaus.jettison.json.JSONObject)7 BeforeTest (org.testng.annotations.BeforeTest)6 AfterTest (org.testng.annotations.AfterTest)5 ImmutableList (com.google.common.collect.ImmutableList)4 List (java.util.List)4 ITypedInstance (org.apache.atlas.typesystem.ITypedInstance)4 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)4 TypeSystem (org.apache.atlas.typesystem.types.TypeSystem)4 Date (java.util.Date)3