use of org.codehaus.jettison.json.JSONException in project apex-core by apache.
the class StramWebServices method setOperatorProperties.
// not supported by WebAppProxyServlet, can only be called directly
@POST
@Path(PATH_LOGICAL_PLAN_OPERATORS + "/{operatorName}/properties")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public JSONObject setOperatorProperties(JSONObject request, @PathParam("operatorName") String operatorName) {
init();
OperatorMeta logicalOperator = dagManager.getLogicalPlan().getOperatorMeta(operatorName);
if (logicalOperator == null) {
throw new NotFoundException();
}
JSONObject response = new JSONObject();
try {
@SuppressWarnings("unchecked") Iterator<String> keys = request.keys();
while (keys.hasNext()) {
String key = keys.next();
String val = request.isNull(key) ? null : request.getString(key);
LOG.debug("Setting property for {}: {}={}", operatorName, key, val);
dagManager.setOperatorProperty(operatorName, key, val);
}
} catch (JSONException ex) {
LOG.warn("Got JSON Exception: ", ex);
} catch (Exception ex) {
LOG.error("Caught exception: ", ex);
throw new RuntimeException(ex);
}
return response;
}
use of org.codehaus.jettison.json.JSONException in project incubator-atlas by apache.
the class TypesResource method getDefinition.
/**
* Fetch the complete definition of a given type name which is unique.
*
* @param typeName name of a type which is unique.
*/
@GET
@Path("{typeName}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response getDefinition(@Context HttpServletRequest request, @PathParam("typeName") String typeName) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> TypesResource.getDefinition({})", typeName);
}
AtlasPerfTracer perf = null;
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.getDefinition(" + typeName + ")");
}
JSONObject response = new JSONObject();
try {
TypesDef typesDef = TypeConverterUtil.toTypesDef(typeRegistry.getType(typeName), typeRegistry);
;
String typeDefinition = TypesSerialization.toJson(typesDef);
response.put(AtlasClient.TYPENAME, typeName);
response.put(AtlasClient.DEFINITION, new JSONObject(typeDefinition));
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
return Response.ok(response).build();
} catch (AtlasBaseException e) {
LOG.error("Unable to get type definition for type {}", typeName, e);
throw new WebApplicationException(Servlets.getErrorResponse(e));
} catch (JSONException | IllegalArgumentException e) {
LOG.error("Unable to get type definition for type {}", typeName, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (WebApplicationException e) {
LOG.error("Unable to get type definition for type {}", typeName, e);
throw e;
} catch (Throwable e) {
LOG.error("Unable to get type definition for type {}", typeName, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
if (LOG.isDebugEnabled()) {
LOG.debug("<== TypesResource.getDefinition({})", typeName);
}
}
}
use of org.codehaus.jettison.json.JSONException in project incubator-atlas by apache.
the class LineageResource method outputsGraph.
/**
* Returns the outputs graph for a given entity id.
*
* @param guid dataset entity id
*/
@GET
@Path("{guid}/outputs/graph")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response outputsGraph(@PathParam("guid") String guid) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> LineageResource.outputsGraph({})", guid);
}
AtlasPerfTracer perf = null;
try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "LineageResource.outputsGraph(" + guid + ")");
}
AtlasLineageInfo lineageInfo = atlasLineageService.getAtlasLineageInfo(guid, LineageDirection.OUTPUT, -1);
final String result = LineageUtils.toLineageStruct(lineageInfo, typeRegistry);
JSONObject response = new JSONObject();
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
response.put(AtlasClient.RESULTS, new JSONObject(result));
return Response.ok(response).build();
} catch (AtlasBaseException e) {
LOG.error("Unable to get lineage outputs graph for entity guid={}", guid, e);
throw new WebApplicationException(Servlets.getErrorResponse(e));
} catch (WebApplicationException e) {
LOG.error("Unable to get lineage outputs graph for entity guid={}", guid, e);
throw e;
} catch (JSONException 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));
} finally {
AtlasPerfTracer.log(perf);
if (LOG.isDebugEnabled()) {
LOG.debug("<== LineageResource.outputsGraph({})", guid);
}
}
}
use of org.codehaus.jettison.json.JSONException in project incubator-atlas by apache.
the class GraphBackedDiscoveryService method searchByFullText.
//For titan 0.5.4, refer to http://s3.thinkaurelius.com/docs/titan/0.5.4/index-backends.html for indexed query
//http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query
// .html#query-string-syntax for query syntax
@Override
@GraphTransaction
public String searchByFullText(String query, QueryParams queryParams) throws DiscoveryException {
String graphQuery = String.format("v.\"%s\":(%s)", Constants.ENTITY_TEXT_PROPERTY_KEY, query);
LOG.debug("Full text query: {}", graphQuery);
Iterator<AtlasIndexQuery.Result<?, ?>> results = graph.indexQuery(Constants.FULLTEXT_INDEX, graphQuery).vertices();
JSONArray response = new JSONArray();
int index = 0;
while (results.hasNext() && index < queryParams.offset()) {
results.next();
index++;
}
while (results.hasNext() && response.length() < queryParams.limit()) {
AtlasIndexQuery.Result<?, ?> result = results.next();
AtlasVertex<?, ?> vertex = result.getVertex();
JSONObject row = new JSONObject();
String guid = GraphHelper.getGuid(vertex);
if (guid != null) {
//Filter non-class entities
try {
row.put("guid", guid);
row.put(AtlasClient.TYPENAME, GraphHelper.getTypeName(vertex));
row.put(SCORE, result.getScore());
} catch (JSONException e) {
LOG.error("Unable to create response", e);
throw new DiscoveryException("Unable to create response");
}
response.put(row);
}
}
return response.toString();
}
use of org.codehaus.jettison.json.JSONException in project incubator-atlas by apache.
the class AtlasClient method createType.
/**
* Register the given type(meta model)
* @param typeAsJson type definition a jaon
* @return result json object
* @throws AtlasServiceException
*/
public List<String> createType(String typeAsJson) throws AtlasServiceException {
LOG.debug("Creating type definition: {}", typeAsJson);
JSONObject response = callAPIWithBody(API.CREATE_TYPE, typeAsJson);
List<String> results = extractResults(response, AtlasClient.TYPES, new ExtractOperation<String, JSONObject>() {
@Override
String extractElement(JSONObject element) throws JSONException {
return element.getString(AtlasClient.NAME);
}
});
LOG.debug("Create type definition returned results: {}", results);
return results;
}
Aggregations