use of org.apache.atlas.utils.AtlasPerfTracer in project incubator-atlas by apache.
the class TaxonomyService method createTaxonomy.
@POST
@Path("{taxonomyName}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response createTaxonomy(String body, @Context HttpHeaders headers, @Context UriInfo ui, @PathParam("taxonomyName") String taxonomyName) throws CatalogException {
AtlasPerfTracer perf = null;
try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.createTaxonomy(" + taxonomyName + ")");
}
Map<String, Object> properties = parsePayload(body);
properties.put("name", taxonomyName);
createResource(taxonomyResourceProvider, new InstanceRequest(properties));
return Response.status(Response.Status.CREATED).entity(new Results(ui.getRequestUri().toString(), 201)).build();
} finally {
AtlasPerfTracer.log(perf);
}
}
use of org.apache.atlas.utils.AtlasPerfTracer in project incubator-atlas by apache.
the class TaxonomyService method getSubTerms.
@GET
@Path("{taxonomyName}/terms/{rootTerm}/{remainder:.*}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response getSubTerms(@Context HttpHeaders headers, @Context UriInfo ui, @PathParam("taxonomyName") String taxonomyName, @PathParam("rootTerm") String rootTerm, @PathParam("remainder") String remainder) throws CatalogException {
AtlasPerfTracer perf = null;
try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.getSubTerms(" + taxonomyName + ", " + rootTerm + ", " + remainder + ")");
}
Result result;
String termName = String.format("%s%s", rootTerm, remainder.replaceAll("/?terms/?([.]*)", "$1."));
String queryString = decode(getQueryString(ui));
TermPath termPath = new TermPath(taxonomyName, termName);
Map<String, Object> properties = new HashMap<>();
properties.put("termPath", termPath);
List<PathSegment> pathSegments = ui.getPathSegments();
int lastIndex = pathSegments.size() - 1;
String lastSegment = pathSegments.get(lastIndex).getPath();
if (lastSegment.equals("terms") || (lastSegment.isEmpty() && pathSegments.get(lastIndex - 1).getPath().equals("terms"))) {
result = getResources(termResourceProvider, new CollectionRequest(properties, queryString));
} else {
result = getResource(termResourceProvider, new InstanceRequest(properties));
}
return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build();
} finally {
AtlasPerfTracer.log(perf);
}
}
use of org.apache.atlas.utils.AtlasPerfTracer in project incubator-atlas by apache.
the class EntityResource method deleteEntities.
/**
* Delete entities from the repository identified by their guids (including their composite references)
* or
* Deletes a single entity identified by its type and unique attribute value from the repository (including their composite references)
*
* @param guids list of deletion candidate guids
* or
* @param entityType the entity type
* @param attribute the unique attribute used to identify the entity
* @param value the unique attribute value used to identify the entity
* @return response payload as json - including guids of entities(including composite references from that entity) that were deleted
*/
@DELETE
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response deleteEntities(@QueryParam("guid") List<String> guids, @QueryParam("type") String entityType, @QueryParam("property") final String attribute, @QueryParam("value") final String value) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> EntityResource.deleteEntities({}, {}, {}, {})", guids, entityType, attribute, value);
}
AtlasPerfTracer perf = null;
try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.deleteEntities(" + guids + ", " + entityType + ", " + attribute + ", " + value + ")");
}
EntityResult entityResult;
if (guids != null && !guids.isEmpty()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Deleting entities {}", guids);
}
EntityMutationResponse mutationResponse = entityREST.deleteByGuids(guids);
entityResult = restAdapters.toCreateUpdateEntitiesResult(mutationResponse).getEntityResult();
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Deleting entity type={} with property {}={}", entityType, attribute, value);
}
Map<String, Object> attributes = new HashMap<>();
attributes.put(attribute, value);
EntityMutationResponse mutationResponse = entitiesStore.deleteByUniqueAttributes(getEntityType(entityType), attributes);
entityResult = restAdapters.toCreateUpdateEntitiesResult(mutationResponse).getEntityResult();
}
if (LOG.isDebugEnabled()) {
LOG.debug("Deleted entity result: {}", entityResult);
}
JSONObject response = getResponse(entityResult);
return Response.ok(response).build();
} catch (AtlasBaseException e) {
LOG.error("Unable to delete entities {} {} {} {} ", guids, entityType, attribute, value, e);
throw toWebApplicationException(e);
} catch (EntityNotFoundException e) {
if (guids != null && !guids.isEmpty()) {
LOG.error("An entity with GUID={} does not exist ", guids, e);
} else {
LOG.error("An entity with qualifiedName {}-{}-{} does not exist", entityType, attribute, value, e);
}
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND));
} catch (AtlasException | IllegalArgumentException e) {
LOG.error("Unable to delete entities {} {} {} {} ", guids, entityType, attribute, value, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (WebApplicationException e) {
LOG.error("Unable to delete entities {} {} {} {} ", guids, entityType, attribute, value, e);
throw e;
} catch (Throwable e) {
LOG.error("Unable to delete entities {} {} {} {} ", guids, entityType, attribute, value, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
if (LOG.isDebugEnabled()) {
LOG.debug("<== EntityResource.deleteEntities({}, {}, {}, {})", guids, entityType, attribute, value);
}
}
}
use of org.apache.atlas.utils.AtlasPerfTracer in project incubator-atlas by apache.
the class EntityResource method getAuditEvents.
/**
* Returns the entity audit events for a given entity id. The events are returned in the decreasing order of timestamp.
* @param guid entity id
* @param startKey used for pagination. Startkey is inclusive, the returned results contain the event with the given startkey.
* First time getAuditEvents() is called for an entity, startKey should be null,
* with count = (number of events required + 1). Next time getAuditEvents() is called for the same entity,
* startKey should be equal to the entityKey of the last event returned in the previous call.
* @param count number of events required
* @return
*/
@GET
@Path("{guid}/audit")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response getAuditEvents(@PathParam("guid") String guid, @QueryParam("startKey") String startKey, @QueryParam("count") @DefaultValue("100") short count) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> EntityResource.getAuditEvents({}, {}, {})", guid, startKey, count);
}
AtlasPerfTracer perf = null;
if (LOG.isDebugEnabled()) {
LOG.debug("Audit events request for entity {}, start key {}, number of results required {}", guid, startKey, count);
}
try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.getAuditEvents(" + guid + ", " + startKey + ", " + count + ")");
}
List<EntityAuditEvent> events = metadataService.getAuditEvents(guid, startKey, count);
JSONObject response = new JSONObject();
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
response.put(AtlasClient.EVENTS, getJSONArray(events));
return Response.ok(response).build();
} catch (AtlasException | IllegalArgumentException e) {
LOG.error("Unable to get audit events for entity guid={} startKey={}", guid, startKey, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (WebApplicationException e) {
LOG.error("Unable to get audit events for entity guid={} startKey={}", guid, startKey, e);
throw e;
} catch (Throwable e) {
LOG.error("Unable to get audit events for entity guid={} startKey={}", guid, startKey, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
if (LOG.isDebugEnabled()) {
LOG.debug("<== EntityResource.getAuditEvents({}, {}, {})", guid, startKey, count);
}
}
}
use of org.apache.atlas.utils.AtlasPerfTracer in project incubator-atlas by apache.
the class EntityResource method submit.
/**
* Submits the entity definitions (instances).
* The body contains the JSONArray of entity json. The service takes care of de-duping the entities based on any
* unique attribute for the give type.
*/
@POST
@Consumes({ Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON })
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response submit(@Context HttpServletRequest request) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> EntityResource.submit()");
}
String entityJson = null;
AtlasPerfTracer perf = null;
try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.submit()");
}
String entities = Servlets.getRequestPayload(request);
//Handle backward compatibility - if entities is not JSONArray, convert to JSONArray
try {
new JSONArray(entities);
} catch (JSONException e) {
final String finalEntities = entities;
entities = new JSONArray() {
{
put(finalEntities);
}
}.toString();
}
entityJson = AtlasClient.toString(new JSONArray(entities));
if (LOG.isDebugEnabled()) {
LOG.debug("submitting entities {} ", entityJson);
}
AtlasEntitiesWithExtInfo entitiesInfo = restAdapters.toAtlasEntities(entities);
EntityMutationResponse mutationResponse = entityREST.createOrUpdate(entitiesInfo);
final List<String> guids = restAdapters.getGuids(mutationResponse.getCreatedEntities());
if (LOG.isDebugEnabled()) {
LOG.debug("Created entities {}", guids);
}
final CreateUpdateEntitiesResult result = restAdapters.toCreateUpdateEntitiesResult(mutationResponse);
JSONObject response = getResponse(result);
URI locationURI = getLocationURI(guids);
return Response.created(locationURI).entity(response).build();
} catch (AtlasBaseException e) {
LOG.error("Unable to persist entity instance entityDef={}", entityJson, e);
throw toWebApplicationException(e);
} catch (EntityExistsException e) {
LOG.error("Unique constraint violation for entity entityDef={}", entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.CONFLICT));
} catch (ValueConversionException ve) {
LOG.error("Unable to persist entity instance due to a deserialization error entityDef={}", entityJson, ve);
throw new WebApplicationException(Servlets.getErrorResponse(ve.getCause() != null ? ve.getCause() : ve, Response.Status.BAD_REQUEST));
} catch (AtlasException | IllegalArgumentException e) {
LOG.error("Unable to persist entity instance entityDef={}", entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (WebApplicationException e) {
LOG.error("Unable to persist entity instance entityDef={}", entityJson, e);
throw e;
} catch (Throwable e) {
LOG.error("Unable to persist entity instance entityDef={}", entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
if (LOG.isDebugEnabled()) {
LOG.debug("<== EntityResource.submit()");
}
}
}
Aggregations