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);
}
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;
}
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);
}
}
}
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);
}
}
}
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);
}
Aggregations