Search in sources :

Example 16 with Struct

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

the class DataSetLineageJerseyResourceIT method testInputsGraph.

@Test
public void testInputsGraph() throws Exception {
    String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId();
    ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LINEAGE_INPUTS_GRAPH, null, tableId, "/inputs/graph");
    Assert.assertNotNull(response);
    System.out.println("inputs 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(), 4);
    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)

Example 17 with Struct

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

the class HookNotificationDeserializerTest method generateLargeEntityWithTrait.

private Referenceable generateLargeEntityWithTrait() {
    Referenceable ret = EntityNotificationTest.getEntity("id", new Struct("MyTrait", Collections.<String, Object>emptyMap()));
    // add 100 attributes, each with value of size 10k
    // Json Size=1,027,984; GZipped Size=16,387 ==> will compress, but not split
    // use the same value for all attributes - to aid better compression
    String attrValue = RandomStringUtils.randomAlphanumeric(10 * 1024);
    for (int i = 0; i < 100; i++) {
        ret.set("attr_" + i, attrValue);
    }
    return ret;
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Struct(org.apache.atlas.v1.model.instance.Struct)

Example 18 with Struct

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

the class EntityResource method getTraitDefinitionsForEntity.

/**
 * Fetches the trait definitions of all the traits associated to the given entity
 * @param guid globally unique identifier for the entity
 */
@GET
@Path("{guid}/traitDefinitions")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response getTraitDefinitionsForEntity(@PathParam("guid") String guid) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> EntityResource.getTraitDefinitionsForEntity({})", guid);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.getTraitDefinitionsForEntity(" + guid + ")");
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("Fetching all trait definitions for entity={}", guid);
        }
        final List<AtlasClassification> classifications = entitiesStore.getClassifications(guid);
        List<Struct> traits = new ArrayList<>(classifications.size());
        for (AtlasClassification classification : classifications) {
            Struct trait = restAdapters.getTrait(classification);
            traits.add(trait);
        }
        Map<String, Object> response = new HashMap<>();
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        response.put(AtlasClient.RESULTS, traits);
        response.put(AtlasClient.COUNT, traits.size());
        return Response.ok(AtlasJson.toV1Json(response)).build();
    } catch (AtlasBaseException e) {
        LOG.error("Unable to get trait definition for entity {}", guid, e);
        throw toWebApplicationException(e);
    } catch (IllegalArgumentException e) {
        LOG.error("Unable to get trait definition for entity {}", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get trait definitions for entity {}", guid, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get trait definitions for entity {}", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== EntityResource.getTraitDefinitionsForEntity({})", guid);
        }
    }
}
Also used : HashMap(java.util.HashMap) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) ArrayList(java.util.ArrayList) Struct(org.apache.atlas.v1.model.instance.Struct) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification)

Example 19 with Struct

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

the class EntityResource method getTraitDefinitionForEntity.

/**
 * Fetches the trait definition for an entity given its guid and trait name
 *
 * @param guid globally unique identifier for the entity
 * @param traitName name of the trait
 */
@GET
@Path("{guid}/traitDefinitions/{traitName}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response getTraitDefinitionForEntity(@PathParam("guid") String guid, @PathParam("traitName") String traitName) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> EntityResource.getTraitDefinitionForEntity({}, {})", guid, traitName);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.getTraitDefinitionForEntity(" + guid + ", " + traitName + ")");
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("Fetching trait definition for entity {} and trait name {}", guid, traitName);
        }
        final AtlasClassification classification = entitiesStore.getClassification(guid, traitName);
        Struct traitDefinition = restAdapters.getTrait(classification);
        Map<String, Object> response = new HashMap<>();
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        response.put(AtlasClient.RESULTS, traitDefinition);
        return Response.ok(AtlasJson.toV1Json(response)).build();
    } catch (AtlasBaseException e) {
        LOG.error("Unable to get trait definition for entity {} and trait {}", guid, traitName, e);
        throw toWebApplicationException(e);
    } catch (IllegalArgumentException e) {
        LOG.error("Unable to get trait definition for entity {} and trait {}", guid, traitName, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get trait definition for entity {} and trait {}", guid, traitName, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get trait definition for entity {} and trait {}", guid, traitName, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== EntityResource.getTraitDefinitionForEntity({}, {})", guid, traitName);
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) HashMap(java.util.HashMap) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) Struct(org.apache.atlas.v1.model.instance.Struct)

Example 20 with Struct

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

the class EntityJerseyResourceIT method testAddTraitWithNoRegistration.

@Test(expectedExceptions = AtlasServiceException.class)
public void testAddTraitWithNoRegistration() throws Exception {
    final String traitName = "PII_Trait" + randomString();
    TraitTypeDefinition piiTrait = TypesUtil.createTraitTypeDef(traitName, null, Collections.<String>emptySet());
    String traitDefinitionAsJSON = AtlasType.toV1Json(piiTrait);
    LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
    Struct traitInstance = new Struct(traitName);
    String traitInstanceAsJSON = AtlasType.toV1Json(traitInstance);
    LOG.debug("traitInstanceAsJSON = {}", traitInstanceAsJSON);
    atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.CREATE_ENTITY, traitInstanceAsJSON, "random", TRAITS);
}
Also used : 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