Commit bff013f0 by Madhan Neethiraj Committed by Suma Shivaprasad

ATLAS-1030: performance trace instrumentation for REST APIs

parent e895819f
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Handles logging of performance measurements.
*/
public final class AtlasPerfTracer {
protected final Logger logger;
protected final String tag;
private final long startTimeMs;
private static long reportingThresholdMs = 0L;
public static Logger getPerfLogger(String name) {
return LoggerFactory.getLogger("org.apache.atlas.perf." + name);
}
public static Logger getPerfLogger(Class<?> cls) {
return AtlasPerfTracer.getPerfLogger(cls.getName());
}
public static boolean isPerfTraceEnabled(Logger logger) {
return logger.isDebugEnabled();
}
public static AtlasPerfTracer getPerfTracer(Logger logger, String tag) {
return new AtlasPerfTracer(logger, tag);
}
public static void log(AtlasPerfTracer tracer) {
if (tracer != null) {
tracer.log();
}
}
private AtlasPerfTracer(Logger logger, String tag) {
this.logger = logger;
this.tag = tag;
startTimeMs = System.currentTimeMillis();
}
public String getTag() {
return tag;
}
public long getStartTime() {
return startTimeMs;
}
public long getElapsedTime() {
return System.currentTimeMillis() - startTimeMs;
}
public void log() {
long elapsedTime = getElapsedTime();
if (elapsedTime > reportingThresholdMs) {
logger.debug("PERF|" + tag + "|" + elapsedTime);
}
}
}
...@@ -48,6 +48,22 @@ ...@@ -48,6 +48,22 @@
<appender-ref ref="FILE"/> <appender-ref ref="FILE"/>
</logger> </logger>
<!-- uncomment this block to generate performance traces
<appender name="perf_appender" class="org.apache.log4j.DailyRollingFileAppender">
<param name="file" value="${atlas.log.dir}/atlas_perf.log" />
<param name="datePattern" value="'.'yyyy-MM-dd" />
<param name="append" value="true" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d|%t|%m%n" />
</layout>
</appender>
<logger name="org.apache.atlas.perf" additivity="false">
<level value="debug" />
<appender-ref ref="perf_appender" />
</logger>
-->
<logger name="com.thinkaurelius.titan" additivity="false"> <logger name="com.thinkaurelius.titan" additivity="false">
<level value="warn"/> <level value="warn"/>
<appender-ref ref="FILE"/> <appender-ref ref="FILE"/>
......
...@@ -41,6 +41,22 @@ ...@@ -41,6 +41,22 @@
<appender-ref ref="console"/> <appender-ref ref="console"/>
</logger> </logger>
<!-- uncomment this block to generate performance traces
<appender name="perf_appender" class="org.apache.log4j.DailyRollingFileAppender">
<param name="file" value="${atlas.log.dir}/atlas_perf.log" />
<param name="datePattern" value="'.'yyyy-MM-dd" />
<param name="append" value="true" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d|%t|%m%n" />
</layout>
</appender>
<logger name="org.apache.atlas.perf" additivity="false">
<level value="debug" />
<appender-ref ref="perf_appender" />
</logger>
-->
<logger name="com.thinkaurelius.titan" additivity="false"> <logger name="com.thinkaurelius.titan" additivity="false">
<level value="info"/> <level value="info"/>
<appender-ref ref="console"/> <appender-ref ref="console"/>
......
...@@ -31,6 +31,7 @@ import javax.ws.rs.core.MediaType; ...@@ -31,6 +31,7 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.atlas.web.filters.AtlasCSRFPreventionFilter; import org.apache.atlas.web.filters.AtlasCSRFPreventionFilter;
import org.apache.atlas.web.service.ServiceState; import org.apache.atlas.web.service.ServiceState;
import org.apache.atlas.web.util.Servlets; import org.apache.atlas.web.util.Servlets;
...@@ -39,6 +40,7 @@ import org.apache.commons.configuration.PropertiesConfiguration; ...@@ -39,6 +40,7 @@ import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
...@@ -51,6 +53,7 @@ import com.google.inject.Inject; ...@@ -51,6 +53,7 @@ import com.google.inject.Inject;
@Path("admin") @Path("admin")
@Singleton @Singleton
public class AdminResource { public class AdminResource {
private static final Logger PERF_LOG = AtlasPerfTracer.getPerfLogger("rest.AdminResource");
private static final String isCSRF_ENABLED = "atlas.rest-csrf.enabled"; private static final String isCSRF_ENABLED = "atlas.rest-csrf.enabled";
private static final String BROWSER_USER_AGENT_PARAM = "atlas.rest-csrf.browser-useragents-regex"; private static final String BROWSER_USER_AGENT_PARAM = "atlas.rest-csrf.browser-useragents-regex";
...@@ -75,22 +78,32 @@ public class AdminResource { ...@@ -75,22 +78,32 @@ public class AdminResource {
@Path("stack") @Path("stack")
@Produces(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN)
public String getThreadDump() { public String getThreadDump() {
ThreadGroup topThreadGroup = Thread.currentThread().getThreadGroup(); AtlasPerfTracer perf = null;
while (topThreadGroup.getParent() != null) { try {
topThreadGroup = topThreadGroup.getParent(); if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
} perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "AdminResource.getThreadDump()");
Thread[] threads = new Thread[topThreadGroup.activeCount()]; }
int nr = topThreadGroup.enumerate(threads); ThreadGroup topThreadGroup = Thread.currentThread().getThreadGroup();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < nr; i++) { while (topThreadGroup.getParent() != null) {
builder.append(threads[i].getName()).append("\nState: "). topThreadGroup = topThreadGroup.getParent();
append(threads[i].getState()).append("\n"); }
String stackTrace = StringUtils.join(threads[i].getStackTrace(), "\n"); Thread[] threads = new Thread[topThreadGroup.activeCount()];
builder.append(stackTrace);
int nr = topThreadGroup.enumerate(threads);
StringBuilder builder = new StringBuilder();
for (int i = 0; i < nr; i++) {
builder.append(threads[i].getName()).append("\nState: ").
append(threads[i].getState()).append("\n");
String stackTrace = StringUtils.join(threads[i].getStackTrace(), "\n");
builder.append(stackTrace);
}
return builder.toString();
} finally {
AtlasPerfTracer.log(perf);
} }
return builder.toString();
} }
/** /**
...@@ -102,38 +115,58 @@ public class AdminResource { ...@@ -102,38 +115,58 @@ public class AdminResource {
@Path("version") @Path("version")
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public Response getVersion() { public Response getVersion() {
if (version == null) { AtlasPerfTracer perf = null;
try {
PropertiesConfiguration configProperties = new PropertiesConfiguration("atlas-buildinfo.properties"); try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
JSONObject response = new JSONObject(); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "AdminResource.getVersion()");
response.put("Version", configProperties.getString("build.version", "UNKNOWN")); }
response.put("Name", configProperties.getString("project.name", "apache-atlas"));
response.put("Description", configProperties.getString("project.description", if (version == null) {
"Metadata Management and Data Governance Platform over Hadoop")); try {
PropertiesConfiguration configProperties = new PropertiesConfiguration("atlas-buildinfo.properties");
// todo: add hadoop version?
// response.put("Hadoop", VersionInfo.getVersion() + "-r" + VersionInfo.getRevision()); JSONObject response = new JSONObject();
version = Response.ok(response).build(); response.put("Version", configProperties.getString("build.version", "UNKNOWN"));
} catch (JSONException | ConfigurationException e) { response.put("Name", configProperties.getString("project.name", "apache-atlas"));
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); response.put("Description", configProperties.getString("project.description",
"Metadata Management and Data Governance Platform over Hadoop"));
// todo: add hadoop version?
// response.put("Hadoop", VersionInfo.getVersion() + "-r" + VersionInfo.getRevision());
version = Response.ok(response).build();
} catch (JSONException | ConfigurationException e) {
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
}
} }
}
return version; return version;
} finally {
AtlasPerfTracer.log(perf);
}
} }
@GET @GET
@Path("status") @Path("status")
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public Response getStatus() { public Response getStatus() {
JSONObject responseData = new JSONObject(); AtlasPerfTracer perf = null;
try { try {
responseData.put(AtlasClient.STATUS, serviceState.getState().toString()); if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
Response response = Response.ok(responseData).build(); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "AdminResource.getStatus()");
return response; }
} catch (JSONException e) {
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); JSONObject responseData = new JSONObject();
try {
responseData.put(AtlasClient.STATUS, serviceState.getState().toString());
Response response = Response.ok(responseData).build();
return response;
} catch (JSONException e) {
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
}
} finally {
AtlasPerfTracer.log(perf);
} }
} }
...@@ -143,7 +176,12 @@ public class AdminResource { ...@@ -143,7 +176,12 @@ public class AdminResource {
public Response getUserProfile() { public Response getUserProfile() {
JSONObject responseData = new JSONObject(); JSONObject responseData = new JSONObject();
Boolean enableTaxonomy = null; Boolean enableTaxonomy = null;
AtlasPerfTracer perf = null;
try { try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "AdminResource.getUserProfile()");
}
PropertiesConfiguration configProperties = new PropertiesConfiguration("atlas-application.properties"); PropertiesConfiguration configProperties = new PropertiesConfiguration("atlas-application.properties");
enableTaxonomy = new Boolean(configProperties.getString(isTaxonomyEnabled, "false")); enableTaxonomy = new Boolean(configProperties.getString(isTaxonomyEnabled, "false"));
Authentication auth = SecurityContextHolder.getContext().getAuthentication(); Authentication auth = SecurityContextHolder.getContext().getAuthentication();
...@@ -170,6 +208,8 @@ public class AdminResource { ...@@ -170,6 +208,8 @@ public class AdminResource {
return response; return response;
} catch (JSONException | ConfigurationException e) { } catch (JSONException | ConfigurationException e) {
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
} }
} }
} }
...@@ -22,6 +22,7 @@ import org.apache.atlas.AtlasClient; ...@@ -22,6 +22,7 @@ import org.apache.atlas.AtlasClient;
import org.apache.atlas.discovery.DiscoveryException; import org.apache.atlas.discovery.DiscoveryException;
import org.apache.atlas.discovery.LineageService; import org.apache.atlas.discovery.LineageService;
import org.apache.atlas.typesystem.exception.EntityNotFoundException; import org.apache.atlas.typesystem.exception.EntityNotFoundException;
import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.atlas.web.util.Servlets; import org.apache.atlas.web.util.Servlets;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -47,6 +48,7 @@ import javax.ws.rs.core.Response; ...@@ -47,6 +48,7 @@ import javax.ws.rs.core.Response;
public class DataSetLineageResource { public class DataSetLineageResource {
private static final Logger LOG = LoggerFactory.getLogger(DataSetLineageResource.class); private static final Logger LOG = LoggerFactory.getLogger(DataSetLineageResource.class);
private static final Logger PERF_LOG = AtlasPerfTracer.getPerfLogger("rest.DataSetLineageResource");
private final LineageService lineageService; private final LineageService lineageService;
...@@ -73,7 +75,12 @@ public class DataSetLineageResource { ...@@ -73,7 +75,12 @@ public class DataSetLineageResource {
public Response inputsGraph(@Context HttpServletRequest request, @PathParam("tableName") String tableName) { public Response inputsGraph(@Context HttpServletRequest request, @PathParam("tableName") String tableName) {
LOG.info("Fetching lineage inputs graph for tableName={}", tableName); LOG.info("Fetching lineage inputs graph for tableName={}", tableName);
AtlasPerfTracer perf = null;
try { try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DataSetLineageResource.inputsGraph(" + tableName + ")");
}
final String jsonResult = lineageService.getInputsGraph(tableName); final String jsonResult = lineageService.getInputsGraph(tableName);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
...@@ -91,6 +98,8 @@ public class DataSetLineageResource { ...@@ -91,6 +98,8 @@ public class DataSetLineageResource {
} catch (Throwable e) { } catch (Throwable e) {
LOG.error("Unable to get lineage inputs graph for table {}", tableName, e); LOG.error("Unable to get lineage inputs graph for table {}", tableName, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
} }
} }
...@@ -106,7 +115,12 @@ public class DataSetLineageResource { ...@@ -106,7 +115,12 @@ public class DataSetLineageResource {
public Response outputsGraph(@Context HttpServletRequest request, @PathParam("tableName") String tableName) { public Response outputsGraph(@Context HttpServletRequest request, @PathParam("tableName") String tableName) {
LOG.info("Fetching lineage outputs graph for tableName={}", tableName); LOG.info("Fetching lineage outputs graph for tableName={}", tableName);
AtlasPerfTracer perf = null;
try { try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DataSetLineageResource.outputsGraph(" + tableName + ")");
}
final String jsonResult = lineageService.getOutputsGraph(tableName); final String jsonResult = lineageService.getOutputsGraph(tableName);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
...@@ -124,6 +138,8 @@ public class DataSetLineageResource { ...@@ -124,6 +138,8 @@ public class DataSetLineageResource {
} catch (Throwable e) { } catch (Throwable e) {
LOG.error("Unable to get lineage outputs graph for table {}", tableName, e); LOG.error("Unable to get lineage outputs graph for table {}", tableName, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
} }
} }
...@@ -139,7 +155,12 @@ public class DataSetLineageResource { ...@@ -139,7 +155,12 @@ public class DataSetLineageResource {
public Response schema(@Context HttpServletRequest request, @PathParam("tableName") String tableName) { public Response schema(@Context HttpServletRequest request, @PathParam("tableName") String tableName) {
LOG.info("Fetching schema for tableName={}", tableName); LOG.info("Fetching schema for tableName={}", tableName);
AtlasPerfTracer perf = null;
try { try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DataSetLineageResource.schema(" + tableName + ")");
}
final String jsonResult = lineageService.getSchema(tableName); final String jsonResult = lineageService.getSchema(tableName);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
...@@ -157,6 +178,8 @@ public class DataSetLineageResource { ...@@ -157,6 +178,8 @@ public class DataSetLineageResource {
} catch (Throwable e) { } catch (Throwable e) {
LOG.error("Unable to get schema for table {}", tableName, e); LOG.error("Unable to get schema for table {}", tableName, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
} }
} }
} }
...@@ -33,6 +33,7 @@ import org.apache.atlas.typesystem.exception.TypeNotFoundException; ...@@ -33,6 +33,7 @@ import org.apache.atlas.typesystem.exception.TypeNotFoundException;
import org.apache.atlas.typesystem.json.InstanceSerialization; import org.apache.atlas.typesystem.json.InstanceSerialization;
import org.apache.atlas.typesystem.types.ValueConversionException; import org.apache.atlas.typesystem.types.ValueConversionException;
import org.apache.atlas.utils.ParamChecker; import org.apache.atlas.utils.ParamChecker;
import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.atlas.web.util.Servlets; import org.apache.atlas.web.util.Servlets;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONArray;
...@@ -77,6 +78,8 @@ import java.util.List; ...@@ -77,6 +78,8 @@ import java.util.List;
public class EntityResource { public class EntityResource {
private static final Logger LOG = LoggerFactory.getLogger(EntityResource.class); private static final Logger LOG = LoggerFactory.getLogger(EntityResource.class);
private static final Logger PERF_LOG = AtlasPerfTracer.getPerfLogger("rest.EntityResource");
private static final String TRAIT_NAME = "traitName"; private static final String TRAIT_NAME = "traitName";
private final MetadataService metadataService; private final MetadataService metadataService;
...@@ -106,7 +109,12 @@ public class EntityResource { ...@@ -106,7 +109,12 @@ public class EntityResource {
public Response submit(@Context HttpServletRequest request) { public Response submit(@Context HttpServletRequest request) {
String entityJson = null; String entityJson = null;
AtlasPerfTracer perf = null;
try { try {
if(AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.submit()");
}
String entities = Servlets.getRequestPayload(request); String entities = Servlets.getRequestPayload(request);
//Handle backward compatibility - if entities is not JSONArray, convert to JSONArray //Handle backward compatibility - if entities is not JSONArray, convert to JSONArray
...@@ -142,6 +150,8 @@ public class EntityResource { ...@@ -142,6 +150,8 @@ public class EntityResource {
} catch (Throwable e) { } catch (Throwable e) {
LOG.error("Unable to persist entity instance entityDef={}", entityJson, e); LOG.error("Unable to persist entity instance entityDef={}", entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
} }
} }
...@@ -185,7 +195,12 @@ public class EntityResource { ...@@ -185,7 +195,12 @@ public class EntityResource {
public Response updateEntities(@Context HttpServletRequest request) { public Response updateEntities(@Context HttpServletRequest request) {
String entityJson = null; String entityJson = null;
AtlasPerfTracer perf = null;
try { try {
if(AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.updateEntities()");
}
final String entities = Servlets.getRequestPayload(request); final String entities = Servlets.getRequestPayload(request);
entityJson = AtlasClient.toString(new JSONArray(entities)); entityJson = AtlasClient.toString(new JSONArray(entities));
...@@ -208,6 +223,8 @@ public class EntityResource { ...@@ -208,6 +223,8 @@ public class EntityResource {
} catch (Throwable e) { } catch (Throwable e) {
LOG.error("Unable to persist entity instance entityDef={}", entityJson, e); LOG.error("Unable to persist entity instance entityDef={}", entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
} }
} }
...@@ -249,7 +266,12 @@ public class EntityResource { ...@@ -249,7 +266,12 @@ public class EntityResource {
@QueryParam("value") String value, @Context HttpServletRequest request) { @QueryParam("value") String value, @Context HttpServletRequest request) {
String entityJson = null; String entityJson = null;
AtlasPerfTracer perf = null;
try { try {
if(AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.updateByUniqueAttribute()");
}
entityJson = Servlets.getRequestPayload(request); entityJson = Servlets.getRequestPayload(request);
LOG.info("Partially updating entity by unique attribute {} {} {} {} ", entityType, attribute, value, entityJson); LOG.info("Partially updating entity by unique attribute {} {} {} {} ", entityType, attribute, value, entityJson);
...@@ -278,6 +300,8 @@ public class EntityResource { ...@@ -278,6 +300,8 @@ public class EntityResource {
} catch (Throwable e) { } catch (Throwable e) {
LOG.error("Unable to partially update entity {} {} " + entityType + ":" + attribute + "." + value, entityJson, e); LOG.error("Unable to partially update entity {} {} " + entityType + ":" + attribute + "." + value, entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
} }
} }
...@@ -296,10 +320,19 @@ public class EntityResource { ...@@ -296,10 +320,19 @@ public class EntityResource {
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public Response updateEntityByGuid(@PathParam("guid") String guid, @QueryParam("property") String attribute, public Response updateEntityByGuid(@PathParam("guid") String guid, @QueryParam("property") String attribute,
@Context HttpServletRequest request) { @Context HttpServletRequest request) {
if (StringUtils.isEmpty(attribute)) { AtlasPerfTracer perf = null;
return updateEntityPartialByGuid(guid, request); try {
} else { if(AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
return updateEntityAttributeByGuid(guid, attribute, request); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.updateEntityByGuid()");
}
if (StringUtils.isEmpty(attribute)) {
return updateEntityPartialByGuid(guid, request);
} else {
return updateEntityAttributeByGuid(guid, attribute, request);
}
} finally {
AtlasPerfTracer.log(perf);
} }
} }
...@@ -383,8 +416,13 @@ public class EntityResource { ...@@ -383,8 +416,13 @@ public class EntityResource {
@QueryParam("type") String entityType, @QueryParam("type") String entityType,
@QueryParam("property") String attribute, @QueryParam("property") String attribute,
@QueryParam("value") String value) { @QueryParam("value") String value) {
AtlasPerfTracer perf = null;
try { try {
if(AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.deleteEntities()");
}
AtlasClient.EntityResult entityResult; AtlasClient.EntityResult entityResult;
if (guids != null && !guids.isEmpty()) { if (guids != null && !guids.isEmpty()) {
LOG.info("Deleting entities {}", guids); LOG.info("Deleting entities {}", guids);
...@@ -409,6 +447,8 @@ public class EntityResource { ...@@ -409,6 +447,8 @@ public class EntityResource {
} catch (Throwable e) { } catch (Throwable e) {
LOG.error("Unable to delete entities {} {} {} {} ", guids, entityType, attribute, value, e); LOG.error("Unable to delete entities {} {} {} {} ", guids, entityType, attribute, value, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
} }
} }
...@@ -421,7 +461,12 @@ public class EntityResource { ...@@ -421,7 +461,12 @@ public class EntityResource {
@Path("{guid}") @Path("{guid}")
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public Response getEntityDefinition(@PathParam("guid") String guid) { public Response getEntityDefinition(@PathParam("guid") String guid) {
AtlasPerfTracer perf = null;
try { try {
if(AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.getEntityDefinition()");
}
LOG.debug("Fetching entity definition for guid={} ", guid); LOG.debug("Fetching entity definition for guid={} ", guid);
ParamChecker.notEmpty(guid, "guid cannot be null"); ParamChecker.notEmpty(guid, "guid cannot be null");
final String entityDefinition = metadataService.getEntityDefinition(guid); final String entityDefinition = metadataService.getEntityDefinition(guid);
...@@ -449,6 +494,8 @@ public class EntityResource { ...@@ -449,6 +494,8 @@ public class EntityResource {
} catch (Throwable e) { } catch (Throwable e) {
LOG.error("Unable to get instance definition for GUID {}", guid, e); LOG.error("Unable to get instance definition for GUID {}", guid, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
} }
} }
...@@ -489,12 +536,21 @@ public class EntityResource { ...@@ -489,12 +536,21 @@ public class EntityResource {
public Response getEntity(@QueryParam("type") String entityType, public Response getEntity(@QueryParam("type") String entityType,
@QueryParam("property") String attribute, @QueryParam("property") String attribute,
@QueryParam("value") String value) { @QueryParam("value") String value) {
if (StringUtils.isEmpty(attribute)) { AtlasPerfTracer perf = null;
//List API try {
return getEntityListByType(entityType); if(AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
} else { perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.getEntity(" + entityType + ", " + attribute + ", " + value + ")");
//Get entity by unique attribute }
return getEntityDefinitionByAttribute(entityType, attribute, value);
if (StringUtils.isEmpty(attribute)) {
//List API
return getEntityListByType(entityType);
} else {
//Get entity by unique attribute
return getEntityDefinitionByAttribute(entityType, attribute, value);
}
} finally {
AtlasPerfTracer.log(perf);
} }
} }
...@@ -553,7 +609,12 @@ public class EntityResource { ...@@ -553,7 +609,12 @@ public class EntityResource {
@Path("{guid}/traits") @Path("{guid}/traits")
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public Response getTraitNames(@PathParam("guid") String guid) { public Response getTraitNames(@PathParam("guid") String guid) {
AtlasPerfTracer perf = null;
try { try {
if(AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.getTraitNames(" + guid + ")");
}
LOG.debug("Fetching trait names for entity={}", guid); LOG.debug("Fetching trait names for entity={}", guid);
final List<String> traitNames = metadataService.getTraitNames(guid); final List<String> traitNames = metadataService.getTraitNames(guid);
...@@ -572,6 +633,8 @@ public class EntityResource { ...@@ -572,6 +633,8 @@ public class EntityResource {
} catch (Throwable e) { } catch (Throwable e) {
LOG.error("Unable to get trait names for entity {}", guid, e); LOG.error("Unable to get trait names for entity {}", guid, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
} }
} }
...@@ -586,7 +649,12 @@ public class EntityResource { ...@@ -586,7 +649,12 @@ public class EntityResource {
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public Response addTrait(@Context HttpServletRequest request, @PathParam("guid") final String guid) { public Response addTrait(@Context HttpServletRequest request, @PathParam("guid") final String guid) {
String traitDefinition = null; String traitDefinition = null;
AtlasPerfTracer perf = null;
try { try {
if(AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.addTrait(" + guid + ")");
}
traitDefinition = Servlets.getRequestPayload(request); traitDefinition = Servlets.getRequestPayload(request);
LOG.info("Adding trait={} for entity={} ", traitDefinition, guid); LOG.info("Adding trait={} for entity={} ", traitDefinition, guid);
metadataService.addTrait(guid, traitDefinition); metadataService.addTrait(guid, traitDefinition);
...@@ -608,6 +676,8 @@ public class EntityResource { ...@@ -608,6 +676,8 @@ public class EntityResource {
} catch (Throwable e) { } catch (Throwable e) {
LOG.error("Unable to add trait for entity={} traitDef={}", guid, traitDefinition, e); LOG.error("Unable to add trait for entity={} traitDef={}", guid, traitDefinition, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
} }
} }
...@@ -624,7 +694,12 @@ public class EntityResource { ...@@ -624,7 +694,12 @@ public class EntityResource {
public Response deleteTrait(@Context HttpServletRequest request, @PathParam("guid") String guid, public Response deleteTrait(@Context HttpServletRequest request, @PathParam("guid") String guid,
@PathParam(TRAIT_NAME) String traitName) { @PathParam(TRAIT_NAME) String traitName) {
LOG.info("Deleting trait={} from entity={} ", traitName, guid); LOG.info("Deleting trait={} from entity={} ", traitName, guid);
AtlasPerfTracer perf = null;
try { try {
if(AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.deleteTrait(" + guid + ", " + traitName + ")");
}
metadataService.deleteTrait(guid, traitName); metadataService.deleteTrait(guid, traitName);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
...@@ -644,6 +719,8 @@ public class EntityResource { ...@@ -644,6 +719,8 @@ public class EntityResource {
} catch (Throwable e) { } catch (Throwable e) {
LOG.error("Unable to delete trait name={} for entity={}", traitName, guid, e); LOG.error("Unable to delete trait name={} for entity={}", traitName, guid, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
} }
} }
...@@ -664,7 +741,12 @@ public class EntityResource { ...@@ -664,7 +741,12 @@ public class EntityResource {
@QueryParam("count") @DefaultValue("100") short count) { @QueryParam("count") @DefaultValue("100") short count) {
LOG.debug("Audit events request for entity {}, start key {}, number of results required {}", guid, startKey, LOG.debug("Audit events request for entity {}, start key {}, number of results required {}", guid, startKey,
count); count);
AtlasPerfTracer perf = null;
try { try {
if(AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.getAuditEvents(" + guid + ", " + startKey + ", " + count + ")");
}
List<EntityAuditEvent> events = metadataService.getAuditEvents(guid, startKey, count); List<EntityAuditEvent> events = metadataService.getAuditEvents(guid, startKey, count);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
...@@ -677,6 +759,8 @@ public class EntityResource { ...@@ -677,6 +759,8 @@ public class EntityResource {
} catch (Throwable e) { } catch (Throwable e) {
LOG.error("Unable to get audit events for entity guid={} startKey={}", guid, startKey, 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)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
} }
} }
......
...@@ -22,7 +22,9 @@ import org.apache.atlas.AtlasException; ...@@ -22,7 +22,9 @@ import org.apache.atlas.AtlasException;
import org.apache.atlas.catalog.*; import org.apache.atlas.catalog.*;
import org.apache.atlas.catalog.exception.CatalogException; import org.apache.atlas.catalog.exception.CatalogException;
import org.apache.atlas.services.MetadataService; import org.apache.atlas.services.MetadataService;
import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.atlas.web.util.Servlets; import org.apache.atlas.web.util.Servlets;
import org.slf4j.Logger;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
...@@ -36,6 +38,7 @@ import java.util.*; ...@@ -36,6 +38,7 @@ import java.util.*;
@Path("v1/entities") @Path("v1/entities")
@Singleton @Singleton
public class EntityService extends BaseService { public class EntityService extends BaseService {
private static final Logger PERF_LOG = AtlasPerfTracer.getPerfLogger("rest.EntityService");
private final EntityResourceProvider entityResourceProvider; private final EntityResourceProvider entityResourceProvider;
private final EntityTagResourceProvider entityTagResourceProvider; private final EntityTagResourceProvider entityTagResourceProvider;
...@@ -50,12 +53,21 @@ public class EntityService extends BaseService { ...@@ -50,12 +53,21 @@ public class EntityService extends BaseService {
@GET @GET
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public Response getEntities(@Context HttpHeaders headers, @Context UriInfo ui) throws CatalogException { public Response getEntities(@Context HttpHeaders headers, @Context UriInfo ui) throws CatalogException {
String queryString = decode(getQueryString(ui)); AtlasPerfTracer perf = null;
try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityService.getEntities()");
}
BaseRequest request = new CollectionRequest(Collections.<String, Object>emptyMap(), queryString); String queryString = decode(getQueryString(ui));
Result result = getResources(entityResourceProvider, request);
return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build(); BaseRequest request = new CollectionRequest(Collections.<String, Object>emptyMap(), queryString);
Result result = getResources(entityResourceProvider, request);
return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build();
} finally {
AtlasPerfTracer.log(perf);
}
} }
@GET @GET
...@@ -64,11 +76,19 @@ public class EntityService extends BaseService { ...@@ -64,11 +76,19 @@ public class EntityService extends BaseService {
public Response getEntity(@Context HttpHeaders headers, public Response getEntity(@Context HttpHeaders headers,
@Context UriInfo ui, @Context UriInfo ui,
@PathParam("entityId") String entityId) throws CatalogException { @PathParam("entityId") String entityId) throws CatalogException {
AtlasPerfTracer perf = null;
BaseRequest request = new InstanceRequest(Collections.<String, Object>singletonMap("id", entityId)); try {
Result result = getResource(entityResourceProvider, request); if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityService.getEntity(" + entityId + ")");
return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build(); }
BaseRequest request = new InstanceRequest(Collections.<String, Object>singletonMap("id", entityId));
Result result = getResource(entityResourceProvider, request);
return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build();
} finally {
AtlasPerfTracer.log(perf);
}
} }
@GET @GET
...@@ -78,13 +98,21 @@ public class EntityService extends BaseService { ...@@ -78,13 +98,21 @@ public class EntityService extends BaseService {
@Context UriInfo ui, @Context UriInfo ui,
@PathParam("entityId") String entityId, @PathParam("entityId") String entityId,
@PathParam("tag") String tagName) throws CatalogException { @PathParam("tag") String tagName) throws CatalogException {
AtlasPerfTracer perf = null;
Map<String, Object> properties = new HashMap<>(); try {
properties.put("id", entityId); if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
properties.put("name", tagName); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityService.getEntityTag(" + entityId + ", " + tagName + ")");
Result result = getResource(entityTagResourceProvider, new InstanceRequest(properties)); }
return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build(); Map<String, Object> properties = new HashMap<>();
properties.put("id", entityId);
properties.put("name", tagName);
Result result = getResource(entityTagResourceProvider, new InstanceRequest(properties));
return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build();
} finally {
AtlasPerfTracer.log(perf);
}
} }
@GET @GET
...@@ -93,12 +121,20 @@ public class EntityService extends BaseService { ...@@ -93,12 +121,20 @@ public class EntityService extends BaseService {
public Response getEntityTags(@Context HttpHeaders headers, public Response getEntityTags(@Context HttpHeaders headers,
@Context UriInfo ui, @Context UriInfo ui,
@PathParam("entityId") String entityGuid) throws CatalogException { @PathParam("entityId") String entityGuid) throws CatalogException {
AtlasPerfTracer perf = null;
BaseRequest request = new CollectionRequest(Collections.<String, Object>singletonMap("id", entityGuid), try {
decode(getQueryString(ui))); if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
Result result = getResources(entityTagResourceProvider, request); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityService.getEntityTags(" + entityGuid + ")");
}
return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build();
BaseRequest request = new CollectionRequest(Collections.<String, Object>singletonMap("id", entityGuid),
decode(getQueryString(ui)));
Result result = getResources(entityTagResourceProvider, request);
return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build();
} finally {
AtlasPerfTracer.log(perf);
}
} }
@POST @POST
...@@ -109,14 +145,22 @@ public class EntityService extends BaseService { ...@@ -109,14 +145,22 @@ public class EntityService extends BaseService {
@Context UriInfo ui, @Context UriInfo ui,
@PathParam("entityId") String entityId, @PathParam("entityId") String entityId,
@PathParam("tag") String tagName) throws CatalogException { @PathParam("tag") String tagName) throws CatalogException {
AtlasPerfTracer perf = null;
Map<String, Object> properties = new HashMap<>(); try {
properties.put("id", entityId); if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
properties.put("name", tagName); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityService.tagEntity(" + entityId + ", " + tagName + ")");
createResource(entityTagResourceProvider, new InstanceRequest(properties)); }
return Response.status(Response.Status.CREATED).entity( Map<String, Object> properties = new HashMap<>();
new Results(ui.getRequestUri().toString(), 201)).build(); properties.put("id", entityId);
properties.put("name", tagName);
createResource(entityTagResourceProvider, new InstanceRequest(properties));
return Response.status(Response.Status.CREATED).entity(
new Results(ui.getRequestUri().toString(), 201)).build();
} finally {
AtlasPerfTracer.log(perf);
}
} }
@POST @POST
...@@ -124,25 +168,34 @@ public class EntityService extends BaseService { ...@@ -124,25 +168,34 @@ public class EntityService extends BaseService {
public Response tagEntities(String body, public Response tagEntities(String body,
@Context HttpHeaders headers, @Context HttpHeaders headers,
@Context UriInfo ui) throws CatalogException { @Context UriInfo ui) throws CatalogException {
AtlasPerfTracer perf = null;
Map<String, Object> properties = parsePayload(body); try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
if (properties.get("tags") == null || properties.size() != 1) { perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityService.tagEntities()");
throw new CatalogException( }
"Invalid Request, no 'tags' property specified. Creation of entity resource not supported.", 400);
Map<String, Object> properties = parsePayload(body);
if (properties.get("tags") == null || properties.size() != 1) {
throw new CatalogException(
"Invalid Request, no 'tags' property specified. Creation of entity resource not supported.", 400);
}
String queryString = decode(getQueryString(ui));
Collection<String> createResults = createResources(
entityTagResourceProvider, new CollectionRequest(properties, queryString));
Collection<Results> result = new ArrayList<>();
for (String relativeUrl : createResults) {
result.add(new Results(ui.getBaseUri().toString() + relativeUrl, 201));
}
return Response.status(Response.Status.CREATED).entity(
new GenericEntity<Collection<Results>>(result) {
}).build();
} finally {
AtlasPerfTracer.log(perf);
} }
String queryString = decode(getQueryString(ui));
Collection<String> createResults = createResources(
entityTagResourceProvider, new CollectionRequest(properties, queryString));
Collection<Results> result = new ArrayList<>();
for (String relativeUrl : createResults) {
result.add(new Results(ui.getBaseUri().toString() + relativeUrl, 201));
}
return Response.status(Response.Status.CREATED).entity(
new GenericEntity<Collection<Results>>(result) {}).build();
} }
@DELETE @DELETE
...@@ -152,13 +205,21 @@ public class EntityService extends BaseService { ...@@ -152,13 +205,21 @@ public class EntityService extends BaseService {
@Context UriInfo ui, @Context UriInfo ui,
@PathParam("entityId") String entityId, @PathParam("entityId") String entityId,
@PathParam("tag") String tagName) throws CatalogException { @PathParam("tag") String tagName) throws CatalogException {
AtlasPerfTracer perf = null;
Map<String, Object> properties = new HashMap<>(); try {
properties.put("id", entityId); if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
properties.put("name", tagName); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityService.deleteEntityTag()");
deleteResource(entityTagResourceProvider, new InstanceRequest(properties)); }
return Response.status(Response.Status.OK).entity( Map<String, Object> properties = new HashMap<>();
new Results(ui.getRequestUri().toString(), 200)).build(); properties.put("id", entityId);
properties.put("name", tagName);
deleteResource(entityTagResourceProvider, new InstanceRequest(properties));
return Response.status(Response.Status.OK).entity(
new Results(ui.getRequestUri().toString(), 200)).build();
} finally {
AtlasPerfTracer.log(perf);
}
} }
} }
...@@ -22,6 +22,7 @@ import org.apache.atlas.AtlasClient; ...@@ -22,6 +22,7 @@ import org.apache.atlas.AtlasClient;
import org.apache.atlas.discovery.DiscoveryException; import org.apache.atlas.discovery.DiscoveryException;
import org.apache.atlas.discovery.LineageService; import org.apache.atlas.discovery.LineageService;
import org.apache.atlas.typesystem.exception.EntityNotFoundException; import org.apache.atlas.typesystem.exception.EntityNotFoundException;
import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.atlas.web.util.Servlets; import org.apache.atlas.web.util.Servlets;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -41,6 +42,7 @@ import javax.ws.rs.core.Response; ...@@ -41,6 +42,7 @@ import javax.ws.rs.core.Response;
@Singleton @Singleton
public class LineageResource { public class LineageResource {
private static final Logger LOG = LoggerFactory.getLogger(DataSetLineageResource.class); private static final Logger LOG = LoggerFactory.getLogger(DataSetLineageResource.class);
private static final Logger PERF_LOG = AtlasPerfTracer.getPerfLogger("rest.LineageResource");
private final LineageService lineageService; private final LineageService lineageService;
...@@ -67,7 +69,12 @@ public class LineageResource { ...@@ -67,7 +69,12 @@ public class LineageResource {
public Response inputsGraph(@PathParam("guid") String guid) { public Response inputsGraph(@PathParam("guid") String guid) {
LOG.info("Fetching lineage inputs graph for guid={}", guid); LOG.info("Fetching lineage inputs graph for guid={}", guid);
AtlasPerfTracer perf = null;
try { try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "LineageResource.inputsGraph(" + guid + ")");
}
final String jsonResult = lineageService.getInputsGraphForEntity(guid); final String jsonResult = lineageService.getInputsGraphForEntity(guid);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
...@@ -84,6 +91,8 @@ public class LineageResource { ...@@ -84,6 +91,8 @@ public class LineageResource {
} catch (Throwable e) { } catch (Throwable e) {
LOG.error("Unable to get lineage inputs graph for entity guid={}", guid, e); LOG.error("Unable to get lineage inputs graph for entity guid={}", guid, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
} }
} }
...@@ -99,7 +108,12 @@ public class LineageResource { ...@@ -99,7 +108,12 @@ public class LineageResource {
public Response outputsGraph(@PathParam("guid") String guid) { public Response outputsGraph(@PathParam("guid") String guid) {
LOG.info("Fetching lineage outputs graph for entity guid={}", guid); LOG.info("Fetching lineage outputs graph for entity guid={}", guid);
AtlasPerfTracer perf = null;
try { try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "LineageResource.outputsGraph(" + guid + ")");
}
final String jsonResult = lineageService.getOutputsGraphForEntity(guid); final String jsonResult = lineageService.getOutputsGraphForEntity(guid);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
...@@ -116,6 +130,8 @@ public class LineageResource { ...@@ -116,6 +130,8 @@ public class LineageResource {
} catch (Throwable e) { } catch (Throwable e) {
LOG.error("Unable to get lineage outputs graph for entity guid={}", guid, e); LOG.error("Unable to get lineage outputs graph for entity guid={}", guid, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
} }
} }
...@@ -131,7 +147,12 @@ public class LineageResource { ...@@ -131,7 +147,12 @@ public class LineageResource {
public Response schema(@PathParam("guid") String guid) { public Response schema(@PathParam("guid") String guid) {
LOG.info("Fetching schema for entity guid={}", guid); LOG.info("Fetching schema for entity guid={}", guid);
AtlasPerfTracer perf = null;
try { try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "LineageResource.schema(" + guid + ")");
}
final String jsonResult = lineageService.getSchemaForEntity(guid); final String jsonResult = lineageService.getSchemaForEntity(guid);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
...@@ -148,6 +169,8 @@ public class LineageResource { ...@@ -148,6 +169,8 @@ public class LineageResource {
} catch (Throwable e) { } catch (Throwable e) {
LOG.error("Unable to get schema for entity={}", guid, e); LOG.error("Unable to get schema for entity={}", guid, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
} }
} }
} }
...@@ -20,6 +20,7 @@ package org.apache.atlas.web.resources; ...@@ -20,6 +20,7 @@ package org.apache.atlas.web.resources;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.atlas.utils.ParamChecker; import org.apache.atlas.utils.ParamChecker;
import org.apache.atlas.discovery.DiscoveryException; import org.apache.atlas.discovery.DiscoveryException;
import org.apache.atlas.discovery.DiscoveryService; import org.apache.atlas.discovery.DiscoveryService;
...@@ -51,6 +52,7 @@ import org.apache.hadoop.classification.InterfaceAudience; ...@@ -51,6 +52,7 @@ import org.apache.hadoop.classification.InterfaceAudience;
public class MetadataDiscoveryResource { public class MetadataDiscoveryResource {
private static final Logger LOG = LoggerFactory.getLogger(MetadataDiscoveryResource.class); private static final Logger LOG = LoggerFactory.getLogger(MetadataDiscoveryResource.class);
private static final Logger PERF_LOG = AtlasPerfTracer.getPerfLogger("rest.MetadataDiscoveryResource");
private static final String QUERY_TYPE_DSL = "dsl"; private static final String QUERY_TYPE_DSL = "dsl";
private static final String QUERY_TYPE_GREMLIN = "gremlin"; private static final String QUERY_TYPE_GREMLIN = "gremlin";
private static final String QUERY_TYPE_FULLTEXT = "full-text"; private static final String QUERY_TYPE_FULLTEXT = "full-text";
...@@ -80,7 +82,12 @@ public class MetadataDiscoveryResource { ...@@ -80,7 +82,12 @@ public class MetadataDiscoveryResource {
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public Response search(@QueryParam("query") String query) { public Response search(@QueryParam("query") String query) {
JSONObject response; JSONObject response;
AtlasPerfTracer perf = null;
try { // fall back to dsl try { // fall back to dsl
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "MetadataDiscoveryResource.search(" + query + ")");
}
ParamChecker.notEmpty(query, "query cannot be null"); ParamChecker.notEmpty(query, "query cannot be null");
final String jsonResultStr = discoveryService.searchByDSL(query); final String jsonResultStr = discoveryService.searchByDSL(query);
...@@ -94,6 +101,8 @@ public class MetadataDiscoveryResource { ...@@ -94,6 +101,8 @@ public class MetadataDiscoveryResource {
} catch (Throwable throwable) { } catch (Throwable throwable) {
LOG.error("Unable to get entity list for query {} using dsl", query, throwable); LOG.error("Unable to get entity list for query {} using dsl", query, throwable);
return searchUsingFullText(query); return searchUsingFullText(query);
} finally {
AtlasPerfTracer.log(perf);
} }
} }
...@@ -108,7 +117,12 @@ public class MetadataDiscoveryResource { ...@@ -108,7 +117,12 @@ public class MetadataDiscoveryResource {
@Consumes(Servlets.JSON_MEDIA_TYPE) @Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public Response searchUsingQueryDSL(@QueryParam("query") String dslQuery) { public Response searchUsingQueryDSL(@QueryParam("query") String dslQuery) {
AtlasPerfTracer perf = null;
try { try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "MetadataDiscoveryResource.searchUsingQueryDSL(" + dslQuery + ")");
}
ParamChecker.notEmpty(dslQuery, "dslQuery cannot be null"); ParamChecker.notEmpty(dslQuery, "dslQuery cannot be null");
final String jsonResultStr = discoveryService.searchByDSL(dslQuery); final String jsonResultStr = discoveryService.searchByDSL(dslQuery);
...@@ -121,6 +135,8 @@ public class MetadataDiscoveryResource { ...@@ -121,6 +135,8 @@ public class MetadataDiscoveryResource {
} catch (Throwable e) { } catch (Throwable e) {
LOG.error("Unable to get entity list for dslQuery {}", dslQuery, e); LOG.error("Unable to get entity list for dslQuery {}", dslQuery, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
} }
} }
...@@ -136,7 +152,12 @@ public class MetadataDiscoveryResource { ...@@ -136,7 +152,12 @@ public class MetadataDiscoveryResource {
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
@InterfaceAudience.Private @InterfaceAudience.Private
public Response searchUsingGremlinQuery(@QueryParam("query") String gremlinQuery) { public Response searchUsingGremlinQuery(@QueryParam("query") String gremlinQuery) {
AtlasPerfTracer perf = null;
try { try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "MetadataDiscoveryResource.searchUsingGremlinQuery(" + gremlinQuery + ")");
}
ParamChecker.notEmpty(gremlinQuery, "gremlinQuery cannot be null or empty"); ParamChecker.notEmpty(gremlinQuery, "gremlinQuery cannot be null or empty");
final List<Map<String, String>> results = discoveryService.searchByGremlin(gremlinQuery); final List<Map<String, String>> results = discoveryService.searchByGremlin(gremlinQuery);
...@@ -159,6 +180,8 @@ public class MetadataDiscoveryResource { ...@@ -159,6 +180,8 @@ public class MetadataDiscoveryResource {
} catch (Throwable e) { } catch (Throwable e) {
LOG.error("Unable to get entity list for gremlinQuery {}", gremlinQuery, e); LOG.error("Unable to get entity list for gremlinQuery {}", gremlinQuery, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
} }
} }
...@@ -173,7 +196,12 @@ public class MetadataDiscoveryResource { ...@@ -173,7 +196,12 @@ public class MetadataDiscoveryResource {
@Consumes(Servlets.JSON_MEDIA_TYPE) @Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public Response searchUsingFullText(@QueryParam("query") String query) { public Response searchUsingFullText(@QueryParam("query") String query) {
AtlasPerfTracer perf = null;
try { try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "MetadataDiscoveryResource.searchUsingFullText(" + query + ")");
}
ParamChecker.notEmpty(query, "query cannot be null or empty"); ParamChecker.notEmpty(query, "query cannot be null or empty");
final String jsonResultStr = discoveryService.searchByFullText(query); final String jsonResultStr = discoveryService.searchByFullText(query);
JSONArray rowsJsonArr = new JSONArray(jsonResultStr); JSONArray rowsJsonArr = new JSONArray(jsonResultStr);
...@@ -186,6 +214,8 @@ public class MetadataDiscoveryResource { ...@@ -186,6 +214,8 @@ public class MetadataDiscoveryResource {
} catch (Throwable e) { } catch (Throwable e) {
LOG.error("Unable to get entity list for query {}", query, e); LOG.error("Unable to get entity list for query {}", query, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
} }
} }
......
...@@ -24,7 +24,9 @@ import org.apache.atlas.catalog.Request; ...@@ -24,7 +24,9 @@ import org.apache.atlas.catalog.Request;
import org.apache.atlas.catalog.exception.CatalogException; import org.apache.atlas.catalog.exception.CatalogException;
import org.apache.atlas.catalog.exception.InvalidPayloadException; import org.apache.atlas.catalog.exception.InvalidPayloadException;
import org.apache.atlas.services.MetadataService; import org.apache.atlas.services.MetadataService;
import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.atlas.web.util.Servlets; import org.apache.atlas.web.util.Servlets;
import org.slf4j.Logger;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
...@@ -41,6 +43,7 @@ import java.util.Map; ...@@ -41,6 +43,7 @@ import java.util.Map;
@Path("v1/taxonomies") @Path("v1/taxonomies")
@Singleton @Singleton
public class TaxonomyService extends BaseService { public class TaxonomyService extends BaseService {
private static final Logger PERF_LOG = AtlasPerfTracer.getPerfLogger("rest.TaxonomyService");
private ResourceProvider taxonomyResourceProvider; private ResourceProvider taxonomyResourceProvider;
private ResourceProvider termResourceProvider; private ResourceProvider termResourceProvider;
...@@ -58,20 +61,37 @@ public class TaxonomyService extends BaseService { ...@@ -58,20 +61,37 @@ public class TaxonomyService extends BaseService {
public Response getTaxonomy(@Context HttpHeaders headers, public Response getTaxonomy(@Context HttpHeaders headers,
@Context UriInfo ui, @Context UriInfo ui,
@PathParam("taxonomyName") String taxonomyName) throws CatalogException { @PathParam("taxonomyName") String taxonomyName) throws CatalogException {
AtlasPerfTracer perf = null;
Map<String, Object> properties = new HashMap<>(); try {
properties.put("name", taxonomyName); if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
Result result = getResource(taxonomyResourceProvider, new InstanceRequest(properties)); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.getTaxonomy(" + taxonomyName + ")");
return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build(); }
Map<String, Object> properties = new HashMap<>();
properties.put("name", taxonomyName);
Result result = getResource(taxonomyResourceProvider, new InstanceRequest(properties));
return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build();
} finally {
AtlasPerfTracer.log(perf);
}
} }
@GET @GET
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public Response getTaxonomies(@Context HttpHeaders headers, @Context UriInfo ui) throws CatalogException { public Response getTaxonomies(@Context HttpHeaders headers, @Context UriInfo ui) throws CatalogException {
String queryString = decode(getQueryString(ui)); AtlasPerfTracer perf = null;
Request request = new CollectionRequest(Collections.<String, Object>emptyMap(), queryString); try {
Result result = getResources(taxonomyResourceProvider, request); if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build(); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.getTaxonomies()");
}
String queryString = decode(getQueryString(ui));
Request request = new CollectionRequest(Collections.<String, Object>emptyMap(), queryString);
Result result = getResources(taxonomyResourceProvider, request);
return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build();
} finally {
AtlasPerfTracer.log(perf);
}
} }
@POST @POST
...@@ -81,14 +101,22 @@ public class TaxonomyService extends BaseService { ...@@ -81,14 +101,22 @@ public class TaxonomyService extends BaseService {
@Context HttpHeaders headers, @Context HttpHeaders headers,
@Context UriInfo ui, @Context UriInfo ui,
@PathParam("taxonomyName") String taxonomyName) throws CatalogException { @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); Map<String, Object> properties = parsePayload(body);
properties.put("name", taxonomyName); properties.put("name", taxonomyName);
createResource(taxonomyResourceProvider, new InstanceRequest(properties)); createResource(taxonomyResourceProvider, new InstanceRequest(properties));
return Response.status(Response.Status.CREATED).entity( return Response.status(Response.Status.CREATED).entity(
new Results(ui.getRequestUri().toString(), 201)).build(); new Results(ui.getRequestUri().toString(), 201)).build();
} finally {
AtlasPerfTracer.log(perf);
}
} }
@PUT @PUT
...@@ -98,14 +126,22 @@ public class TaxonomyService extends BaseService { ...@@ -98,14 +126,22 @@ public class TaxonomyService extends BaseService {
@Context HttpHeaders headers, @Context HttpHeaders headers,
@Context UriInfo ui, @Context UriInfo ui,
@PathParam("taxonomyName") String taxonomyName) throws CatalogException { @PathParam("taxonomyName") String taxonomyName) throws CatalogException {
AtlasPerfTracer perf = null;
Map<String, Object> queryProperties = new HashMap<>(); try {
queryProperties.put("name", taxonomyName); if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
Map<String, Object> updateProperties = parsePayload(body); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.updateTaxonomy(" + taxonomyName + ")");
updateResource(taxonomyResourceProvider, new InstanceRequest(queryProperties, updateProperties)); }
return Response.status(Response.Status.OK).entity( Map<String, Object> queryProperties = new HashMap<>();
new Results(ui.getRequestUri().toString(), 200)).build(); queryProperties.put("name", taxonomyName);
Map<String, Object> updateProperties = parsePayload(body);
updateResource(taxonomyResourceProvider, new InstanceRequest(queryProperties, updateProperties));
return Response.status(Response.Status.OK).entity(
new Results(ui.getRequestUri().toString(), 200)).build();
} finally {
AtlasPerfTracer.log(perf);
}
} }
@DELETE @DELETE
...@@ -114,14 +150,22 @@ public class TaxonomyService extends BaseService { ...@@ -114,14 +150,22 @@ public class TaxonomyService extends BaseService {
public Response deleteTaxonomy(@Context HttpHeaders headers, public Response deleteTaxonomy(@Context HttpHeaders headers,
@Context UriInfo ui, @Context UriInfo ui,
@PathParam("taxonomyName") String taxonomyName) throws CatalogException { @PathParam("taxonomyName") String taxonomyName) throws CatalogException {
AtlasPerfTracer perf = null;
try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.deleteTaxonomy(" + taxonomyName + ")");
}
Map<String, Object> properties = new HashMap<>(); Map<String, Object> properties = new HashMap<>();
properties.put("name", taxonomyName); properties.put("name", taxonomyName);
deleteResource(taxonomyResourceProvider, new InstanceRequest(properties)); deleteResource(taxonomyResourceProvider, new InstanceRequest(properties));
return Response.status(Response.Status.OK).entity( return Response.status(Response.Status.OK).entity(
new Results(ui.getRequestUri().toString(), 200)).build(); new Results(ui.getRequestUri().toString(), 200)).build();
} finally {
AtlasPerfTracer.log(perf);
}
} }
@GET @GET
...@@ -131,13 +175,21 @@ public class TaxonomyService extends BaseService { ...@@ -131,13 +175,21 @@ public class TaxonomyService extends BaseService {
@Context UriInfo ui, @Context UriInfo ui,
@PathParam("taxonomyName") String taxonomyName, @PathParam("taxonomyName") String taxonomyName,
@PathParam("termName") String termName) throws CatalogException { @PathParam("termName") String termName) throws CatalogException {
AtlasPerfTracer perf = null;
TermPath termPath = new TermPath(taxonomyName, termName); try {
Map<String, Object> properties = new HashMap<>(); if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
properties.put("termPath", termPath); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.getTaxonomyTerm(" + taxonomyName + ", " + termName + ")");
Result result = getResource(termResourceProvider, new InstanceRequest(properties)); }
return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build(); TermPath termPath = new TermPath(taxonomyName, termName);
Map<String, Object> properties = new HashMap<>();
properties.put("termPath", termPath);
Result result = getResource(termResourceProvider, new InstanceRequest(properties));
return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build();
} finally {
AtlasPerfTracer.log(perf);
}
} }
@GET @GET
...@@ -146,14 +198,22 @@ public class TaxonomyService extends BaseService { ...@@ -146,14 +198,22 @@ public class TaxonomyService extends BaseService {
public Response getTaxonomyTerms(@Context HttpHeaders headers, public Response getTaxonomyTerms(@Context HttpHeaders headers,
@Context UriInfo ui, @Context UriInfo ui,
@PathParam("taxonomyName") String taxonomyName) throws CatalogException { @PathParam("taxonomyName") String taxonomyName) throws CatalogException {
AtlasPerfTracer perf = null;
String queryString = decode(getQueryString(ui)); try {
TermPath termPath = new TermPath(taxonomyName, null); if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
Request request = new CollectionRequest( perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.getTaxonomyTerms(" + taxonomyName + ")");
Collections.<String, Object>singletonMap("termPath", termPath), queryString); }
Result result = getResources(termResourceProvider, request);
String queryString = decode(getQueryString(ui));
return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build(); TermPath termPath = new TermPath(taxonomyName, null);
Request request = new CollectionRequest(
Collections.<String, Object>singletonMap("termPath", termPath), queryString);
Result result = getResources(termResourceProvider, request);
return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build();
} finally {
AtlasPerfTracer.log(perf);
}
} }
@GET @GET
...@@ -164,26 +224,34 @@ public class TaxonomyService extends BaseService { ...@@ -164,26 +224,34 @@ public class TaxonomyService extends BaseService {
@PathParam("taxonomyName") String taxonomyName, @PathParam("taxonomyName") String taxonomyName,
@PathParam("rootTerm") String rootTerm, @PathParam("rootTerm") String rootTerm,
@PathParam("remainder") String remainder) throws CatalogException { @PathParam("remainder") String remainder) throws CatalogException {
AtlasPerfTracer perf = null;
Result result; try {
String termName = String.format("%s%s", rootTerm, if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
remainder.replaceAll("/?terms/?([.]*)", "$1.")); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.getSubTerms(" + taxonomyName + ", " + rootTerm + ", " + remainder + ")");
String queryString = decode(getQueryString(ui)); }
TermPath termPath = new TermPath(taxonomyName, termName);
Result result;
Map<String, Object> properties = new HashMap<>(); String termName = String.format("%s%s", rootTerm,
properties.put("termPath", termPath); remainder.replaceAll("/?terms/?([.]*)", "$1."));
String queryString = decode(getQueryString(ui));
List<PathSegment> pathSegments = ui.getPathSegments(); TermPath termPath = new TermPath(taxonomyName, termName);
int lastIndex = pathSegments.size() - 1;
String lastSegment = pathSegments.get(lastIndex).getPath(); Map<String, Object> properties = new HashMap<>();
if (lastSegment.equals("terms") || (lastSegment.isEmpty() && pathSegments.get(lastIndex - 1).getPath().equals("terms"))) { properties.put("termPath", termPath);
result = getResources(termResourceProvider, new CollectionRequest(properties, queryString));
} else { List<PathSegment> pathSegments = ui.getPathSegments();
result = getResource(termResourceProvider, new InstanceRequest(properties)); 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);
} }
return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build();
} }
@POST @POST
...@@ -194,14 +262,22 @@ public class TaxonomyService extends BaseService { ...@@ -194,14 +262,22 @@ public class TaxonomyService extends BaseService {
@Context UriInfo ui, @Context UriInfo ui,
@PathParam("taxonomyName") String taxonomyName, @PathParam("taxonomyName") String taxonomyName,
@PathParam("termName") String termName) throws CatalogException { @PathParam("termName") String termName) throws CatalogException {
AtlasPerfTracer perf = null;
Map<String, Object> properties = parsePayload(body); try {
validateName(termName); if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
properties.put("termPath", new TermPath(taxonomyName, termName)); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.createTerm(" + taxonomyName + ", " + termName + ")");
createResource(termResourceProvider, new InstanceRequest(properties)); }
return Response.status(Response.Status.CREATED).entity( Map<String, Object> properties = parsePayload(body);
new Results(ui.getRequestUri().toString(), 201)).build(); validateName(termName);
properties.put("termPath", new TermPath(taxonomyName, termName));
createResource(termResourceProvider, new InstanceRequest(properties));
return Response.status(Response.Status.CREATED).entity(
new Results(ui.getRequestUri().toString(), 201)).build();
} finally {
AtlasPerfTracer.log(perf);
}
} }
@POST @POST
...@@ -213,16 +289,24 @@ public class TaxonomyService extends BaseService { ...@@ -213,16 +289,24 @@ public class TaxonomyService extends BaseService {
@PathParam("taxonomyName") String taxonomyName, @PathParam("taxonomyName") String taxonomyName,
@PathParam("termName") String termName, @PathParam("termName") String termName,
@PathParam("remainder") String remainder) throws CatalogException { @PathParam("remainder") String remainder) throws CatalogException {
AtlasPerfTracer perf = null;
Map<String, Object> properties = parsePayload(body); try {
String[] pathTokens = remainder.split("/"); if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
validateName(pathTokens[pathTokens.length -1]); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.createSubTerm(" + taxonomyName + ", " + termName + ", " + remainder + ")");
properties.put("termPath", new TermPath(taxonomyName, String.format("%s%s", termName, }
remainder.replaceAll("/?terms/?([.]*)", "$1."))));
createResource(termResourceProvider, new InstanceRequest(properties)); Map<String, Object> properties = parsePayload(body);
String[] pathTokens = remainder.split("/");
return Response.status(Response.Status.CREATED).entity( validateName(pathTokens[pathTokens.length - 1]);
new Results(ui.getRequestUri().toString(), 201)).build(); properties.put("termPath", new TermPath(taxonomyName, String.format("%s%s", termName,
remainder.replaceAll("/?terms/?([.]*)", "$1."))));
createResource(termResourceProvider, new InstanceRequest(properties));
return Response.status(Response.Status.CREATED).entity(
new Results(ui.getRequestUri().toString(), 201)).build();
} finally {
AtlasPerfTracer.log(perf);
}
} }
@PUT @PUT
...@@ -233,15 +317,23 @@ public class TaxonomyService extends BaseService { ...@@ -233,15 +317,23 @@ public class TaxonomyService extends BaseService {
@Context UriInfo ui, @Context UriInfo ui,
@PathParam("taxonomyName") String taxonomyName, @PathParam("taxonomyName") String taxonomyName,
@PathParam("termName") String termName) throws CatalogException { @PathParam("termName") String termName) throws CatalogException {
AtlasPerfTracer perf = null;
Map<String, Object> queryProperties = new HashMap<>(); try {
queryProperties.put("termPath", new TermPath(taxonomyName, termName)); if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.updateTerm(" + taxonomyName + ", " + termName + ")");
Map<String, Object> updateProperties = parsePayload(body); }
updateResource(termResourceProvider, new InstanceRequest(queryProperties, updateProperties));
Map<String, Object> queryProperties = new HashMap<>();
return Response.status(Response.Status.OK).entity( queryProperties.put("termPath", new TermPath(taxonomyName, termName));
new Results(ui.getRequestUri().toString(), 200)).build();
Map<String, Object> updateProperties = parsePayload(body);
updateResource(termResourceProvider, new InstanceRequest(queryProperties, updateProperties));
return Response.status(Response.Status.OK).entity(
new Results(ui.getRequestUri().toString(), 200)).build();
} finally {
AtlasPerfTracer.log(perf);
}
} }
@PUT @PUT
...@@ -253,16 +345,24 @@ public class TaxonomyService extends BaseService { ...@@ -253,16 +345,24 @@ public class TaxonomyService extends BaseService {
@PathParam("taxonomyName") String taxonomyName, @PathParam("taxonomyName") String taxonomyName,
@PathParam("termName") String termName, @PathParam("termName") String termName,
@PathParam("remainder") String remainder) throws CatalogException { @PathParam("remainder") String remainder) throws CatalogException {
AtlasPerfTracer perf = null;
Map<String, Object> queryProperties = new HashMap<>(); try {
queryProperties.put("termPath", new TermPath(taxonomyName, String.format("%s%s", termName, if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
remainder.replaceAll("/?terms/?([.]*)", "$1.")))); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.updateSubTerm(" + taxonomyName + ", " + termName + ", " + remainder + ")");
}
Map<String, Object> updateProperties = parsePayload(body);
updateResource(termResourceProvider, new InstanceRequest(queryProperties, updateProperties)); Map<String, Object> queryProperties = new HashMap<>();
queryProperties.put("termPath", new TermPath(taxonomyName, String.format("%s%s", termName,
return Response.status(Response.Status.OK).entity( remainder.replaceAll("/?terms/?([.]*)", "$1."))));
new Results(ui.getRequestUri().toString(), 200)).build();
Map<String, Object> updateProperties = parsePayload(body);
updateResource(termResourceProvider, new InstanceRequest(queryProperties, updateProperties));
return Response.status(Response.Status.OK).entity(
new Results(ui.getRequestUri().toString(), 200)).build();
} finally {
AtlasPerfTracer.log(perf);
}
} }
@DELETE @DELETE
...@@ -272,13 +372,21 @@ public class TaxonomyService extends BaseService { ...@@ -272,13 +372,21 @@ public class TaxonomyService extends BaseService {
@Context UriInfo ui, @Context UriInfo ui,
@PathParam("taxonomyName") String taxonomyName, @PathParam("taxonomyName") String taxonomyName,
@PathParam("termName") String termName) throws CatalogException { @PathParam("termName") String termName) throws CatalogException {
AtlasPerfTracer perf = null;
Map<String, Object> properties = new HashMap<>(); try {
properties.put("termPath", new TermPath(taxonomyName, termName)); if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
deleteResource(termResourceProvider, new InstanceRequest(properties)); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.deleteTerm(" + taxonomyName + ", " + termName + ")");
}
return Response.status(Response.Status.OK).entity(
new Results(ui.getRequestUri().toString(), 200)).build(); Map<String, Object> properties = new HashMap<>();
properties.put("termPath", new TermPath(taxonomyName, termName));
deleteResource(termResourceProvider, new InstanceRequest(properties));
return Response.status(Response.Status.OK).entity(
new Results(ui.getRequestUri().toString(), 200)).build();
} finally {
AtlasPerfTracer.log(perf);
}
} }
@DELETE @DELETE
...@@ -289,14 +397,22 @@ public class TaxonomyService extends BaseService { ...@@ -289,14 +397,22 @@ public class TaxonomyService extends BaseService {
@PathParam("taxonomyName") String taxonomyName, @PathParam("taxonomyName") String taxonomyName,
@PathParam("termName") String termName, @PathParam("termName") String termName,
@PathParam("remainder") String remainder) throws CatalogException { @PathParam("remainder") String remainder) throws CatalogException {
AtlasPerfTracer perf = null;
Map<String, Object> properties = new HashMap<>(); try {
properties.put("termPath", new TermPath(taxonomyName, String.format("%s%s", termName, if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
remainder.replaceAll("/?terms/?([.]*)", "$1.")))); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.deleteSubTerm(" + taxonomyName + ", " + termName + ", " + remainder + ")");
deleteResource(termResourceProvider, new InstanceRequest(properties)); }
return Response.status(Response.Status.OK).entity( Map<String, Object> properties = new HashMap<>();
new Results(ui.getRequestUri().toString(), 200)).build(); properties.put("termPath", new TermPath(taxonomyName, String.format("%s%s", termName,
remainder.replaceAll("/?terms/?([.]*)", "$1."))));
deleteResource(termResourceProvider, new InstanceRequest(properties));
return Response.status(Response.Status.OK).entity(
new Results(ui.getRequestUri().toString(), 200)).build();
} finally {
AtlasPerfTracer.log(perf);
}
} }
protected ResourceProvider createTaxonomyResourceProvider(AtlasTypeSystem typeSystem) { protected ResourceProvider createTaxonomyResourceProvider(AtlasTypeSystem typeSystem) {
......
...@@ -24,6 +24,7 @@ import org.apache.atlas.AtlasException; ...@@ -24,6 +24,7 @@ import org.apache.atlas.AtlasException;
import org.apache.atlas.services.MetadataService; import org.apache.atlas.services.MetadataService;
import org.apache.atlas.typesystem.exception.TypeExistsException; import org.apache.atlas.typesystem.exception.TypeExistsException;
import org.apache.atlas.typesystem.types.DataTypes; import org.apache.atlas.typesystem.types.DataTypes;
import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.atlas.web.util.Servlets; import org.apache.atlas.web.util.Servlets;
import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONException;
...@@ -62,6 +63,7 @@ import java.util.List; ...@@ -62,6 +63,7 @@ import java.util.List;
public class TypesResource { public class TypesResource {
private static final Logger LOG = LoggerFactory.getLogger(TypesResource.class); private static final Logger LOG = LoggerFactory.getLogger(TypesResource.class);
private static final Logger PERF_LOG = AtlasPerfTracer.getPerfLogger("rest.TypesResource");
private final MetadataService metadataService; private final MetadataService metadataService;
...@@ -80,7 +82,12 @@ public class TypesResource { ...@@ -80,7 +82,12 @@ public class TypesResource {
@Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON}) @Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON})
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public Response submit(@Context HttpServletRequest request) { public Response submit(@Context HttpServletRequest request) {
AtlasPerfTracer perf = null;
try { try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.submit()");
}
final String typeDefinition = Servlets.getRequestPayload(request); final String typeDefinition = Servlets.getRequestPayload(request);
LOG.info("Creating type with definition {} ", typeDefinition); LOG.info("Creating type with definition {} ", typeDefinition);
...@@ -108,6 +115,8 @@ public class TypesResource { ...@@ -108,6 +115,8 @@ public class TypesResource {
} catch (Throwable e) { } catch (Throwable e) {
LOG.error("Unable to persist types", e); LOG.error("Unable to persist types", e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
} }
} }
...@@ -124,7 +133,12 @@ public class TypesResource { ...@@ -124,7 +133,12 @@ public class TypesResource {
@Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON}) @Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON})
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public Response update(@Context HttpServletRequest request) { public Response update(@Context HttpServletRequest request) {
AtlasPerfTracer perf = null;
try { try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.update()");
}
final String typeDefinition = Servlets.getRequestPayload(request); final String typeDefinition = Servlets.getRequestPayload(request);
LOG.info("Updating type with definition {} ", typeDefinition); LOG.info("Updating type with definition {} ", typeDefinition);
...@@ -152,6 +166,8 @@ public class TypesResource { ...@@ -152,6 +166,8 @@ public class TypesResource {
} catch (Throwable e) { } catch (Throwable e) {
LOG.error("Unable to persist types", e); LOG.error("Unable to persist types", e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
} }
} }
...@@ -164,7 +180,12 @@ public class TypesResource { ...@@ -164,7 +180,12 @@ public class TypesResource {
@Path("{typeName}") @Path("{typeName}")
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public Response getDefinition(@Context HttpServletRequest request, @PathParam("typeName") String typeName) { public Response getDefinition(@Context HttpServletRequest request, @PathParam("typeName") String typeName) {
AtlasPerfTracer perf = null;
try { try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.getDefinition(" + typeName + ")");
}
final String typeDefinition = metadataService.getTypeDefinition(typeName); final String typeDefinition = metadataService.getTypeDefinition(typeName);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
...@@ -182,6 +203,8 @@ public class TypesResource { ...@@ -182,6 +203,8 @@ public class TypesResource {
} catch (Throwable e) { } catch (Throwable e) {
LOG.error("Unable to get type definition for type {}", typeName, e); LOG.error("Unable to get type definition for type {}", typeName, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
} }
} }
...@@ -197,7 +220,12 @@ public class TypesResource { ...@@ -197,7 +220,12 @@ public class TypesResource {
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public Response getTypesByFilter(@Context HttpServletRequest request, public Response getTypesByFilter(@Context HttpServletRequest request,
@DefaultValue(TYPE_ALL) @QueryParam("type") String type) { @DefaultValue(TYPE_ALL) @QueryParam("type") String type) {
AtlasPerfTracer perf = null;
try { try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.getTypesByFilter(" + type + ")");
}
List<String> result; List<String> result;
if (TYPE_ALL.equals(type)) { if (TYPE_ALL.equals(type)) {
result = metadataService.getTypeNamesList(); result = metadataService.getTypeNamesList();
...@@ -219,6 +247,8 @@ public class TypesResource { ...@@ -219,6 +247,8 @@ public class TypesResource {
} catch (Throwable e) { } catch (Throwable e) {
LOG.error("Unable to get types list", e); LOG.error("Unable to get types list", e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment