Search in sources :

Example 11 with Struct

use of org.apache.atlas.v1.model.instance.Struct in project atlas by apache.

the class EntityJerseyResourceIT method testAddTraitWithAttribute.

@Test
public void testAddTraitWithAttribute() throws Exception {
    String dbName = "db" + randomString();
    String tableName = "table" + randomString();
    Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    Id dbId = createInstance(hiveDBInstance);
    Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
    Id id = createInstance(hiveTableInstance);
    final String guid = id._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }
    final String traitName = "PII_Trait" + randomString();
    TraitTypeDefinition piiTrait = TypesUtil.createTraitTypeDef(traitName, null, Collections.<String>emptySet(), TypesUtil.createRequiredAttrDef("type", AtlasBaseTypeDef.ATLAS_TYPE_STRING));
    String traitDefinitionAsJSON = AtlasType.toV1Json(piiTrait);
    LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
    TypesDef typesDef = new TypesDef(Collections.emptyList(), Collections.emptyList(), Collections.singletonList(piiTrait), Collections.emptyList());
    createType(typesDef);
    Struct traitInstance = new Struct(traitName);
    traitInstance.set("type", "SSN");
    atlasClientV1.addTrait(guid, traitInstance);
    // verify the response
    Referenceable entity = atlasClientV1.getEntity(guid);
    Assert.assertNotNull(entity);
    Assert.assertEquals(entity.getId()._getId(), guid);
    assertNotNull(entity.getTrait(traitName));
    assertEquals(entity.getTrait(traitName).get("type"), traitInstance.get("type"));
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Id(org.apache.atlas.v1.model.instance.Id) Struct(org.apache.atlas.v1.model.instance.Struct) Test(org.testng.annotations.Test)

Example 12 with Struct

use of org.apache.atlas.v1.model.instance.Struct in project atlas by apache.

the class EntityJerseyResourceIT method testAddExistingTrait.

@Test
public void testAddExistingTrait() throws Exception {
    String dbName = "db" + randomString();
    String tableName = "table" + randomString();
    Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    Id dbId = createInstance(hiveDBInstance);
    Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
    Id id = createInstance(hiveTableInstance);
    final String guid = id._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }
    String traitName = "PII_Trait" + randomString();
    TraitTypeDefinition piiTrait = TypesUtil.createTraitTypeDef(traitName, null, Collections.<String>emptySet());
    String traitDefinitionAsJSON = AtlasType.toV1Json(piiTrait);
    LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
    TypesDef typesDef = new TypesDef(Collections.emptyList(), Collections.emptyList(), Collections.singletonList(piiTrait), Collections.emptyList());
    createType(typesDef);
    Struct traitInstance = new Struct(traitName);
    atlasClientV1.addTrait(guid, traitInstance);
    try {
        atlasClientV1.addTrait(guid, traitInstance);
        fail("Duplicate trait addition should've failed");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus(), BAD_REQUEST);
    }
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) AtlasServiceException(org.apache.atlas.AtlasServiceException) Id(org.apache.atlas.v1.model.instance.Id) Struct(org.apache.atlas.v1.model.instance.Struct) Test(org.testng.annotations.Test)

Example 13 with Struct

use of org.apache.atlas.v1.model.instance.Struct in project atlas by apache.

the class MetadataDiscoveryJerseyResourceIT method createInstance.

private Id createInstance() throws Exception {
    Referenceable entityInstance = new Referenceable("dsl_test_type", "Classification");
    entityInstance.set("name", randomString());
    entityInstance.set("description", randomString());
    Struct traitInstance = (Struct) entityInstance.getTrait("Classification");
    tagName = randomString();
    traitInstance.set("tag", tagName);
    List<String> traits = entityInstance.getTraitNames();
    assertEquals(traits.size(), 1);
    return createInstance(entityInstance);
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Struct(org.apache.atlas.v1.model.instance.Struct)

Example 14 with Struct

use of org.apache.atlas.v1.model.instance.Struct in project atlas by apache.

the class DataSetLineageJerseyResourceIT method testInputsGraphForEntity.

@Test
public void testInputsGraphForEntity() throws Exception {
    String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId();
    ObjectNode results = atlasClientV1.getInputGraphForEntity(tableId);
    Assert.assertNotNull(results);
    Struct resultsInstance = AtlasType.fromV1Json(results.toString(), Struct.class);
    resultsInstance.normalize();
    Map<String, Object> vertices = (Map<String, Object>) resultsInstance.get("vertices");
    Assert.assertEquals(vertices.size(), 4);
    Object verticesObject = vertices.get(tableId);
    Struct vertex = null;
    if (verticesObject instanceof Map) {
        vertex = new Struct((Map) verticesObject);
    } else if (verticesObject instanceof Struct) {
        vertex = (Struct) verticesObject;
    }
    assertEquals(((Struct) vertex.get("vertexId")).get("state"), Id.EntityState.ACTIVE.name());
    Map<String, Struct> edges = (Map<String, Struct>) resultsInstance.get("edges");
    Assert.assertEquals(edges.size(), 4);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Map(java.util.Map) Struct(org.apache.atlas.v1.model.instance.Struct) Test(org.testng.annotations.Test)

Example 15 with Struct

use of org.apache.atlas.v1.model.instance.Struct in project atlas by apache.

the class DataSetLineageJerseyResourceIT method testOutputsGraph.

@Test
public void testOutputsGraph() throws Exception {
    String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
    ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LINEAGE_INPUTS_GRAPH, null, tableId, "/outputs/graph");
    Assert.assertNotNull(response);
    System.out.println("outputs graph= " + response);
    Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
    JsonNode results = response.get(AtlasClient.RESULTS);
    Assert.assertNotNull(results);
    Struct resultsInstance = AtlasType.fromV1Json(results.toString(), Struct.class);
    Map<String, Struct> vertices = (Map<String, Struct>) resultsInstance.get("vertices");
    Assert.assertEquals(vertices.size(), 3);
    Map<String, Struct> edges = (Map<String, Struct>) resultsInstance.get("edges");
    Assert.assertEquals(edges.size(), 4);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) Map(java.util.Map) Struct(org.apache.atlas.v1.model.instance.Struct) Test(org.testng.annotations.Test)

Aggregations

Struct (org.apache.atlas.v1.model.instance.Struct)36 Referenceable (org.apache.atlas.v1.model.instance.Referenceable)22 Test (org.testng.annotations.Test)17 HashMap (java.util.HashMap)9 Map (java.util.Map)9 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)9 EntityNotificationV1 (org.apache.atlas.v1.model.notification.EntityNotificationV1)7 AtlasClassificationType (org.apache.atlas.type.AtlasClassificationType)6 Id (org.apache.atlas.v1.model.instance.Id)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)5 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)3 AtlasStruct (org.apache.atlas.model.instance.AtlasStruct)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 AtlasException (org.apache.atlas.AtlasException)2 AtlasServiceException (org.apache.atlas.AtlasServiceException)2 EntityAuditEvent (org.apache.atlas.EntityAuditEvent)2 EntityChangeListener (org.apache.atlas.listener.EntityChangeListener)2 EntityChangeListenerV2 (org.apache.atlas.listener.EntityChangeListenerV2)2