public static String createGraph(JSONObject meta) throws Exception { return createGraph(null, meta); }
/** Gets the graph from LemonGraph/DB*/ @GET @Path("/job/{id}/graph") @Produces(MediaType.APPLICATION_JSON) public Response getJobGraphData(@PathParam("id") String jobId) { if (Utils.graphStoreStr.equalsIgnoreCase("lemongraph")) { try { JSONObject graph = LemonGraph.getGraph(jobId); return Response.status(200).entity(graph.toString()).build(); } catch (Exception e) { log.error("Lookup from LemonGraph failed " + e.getMessage()); return Response.status(404).entity("Graph Not stored in lemongraph").build(); } } return Response.status(404).entity("Not found").build(); }
/** * Test connection to LemonGraph * @return 'true' if up, 'false' if down. */ public boolean testLemonGraph() { LemonGraph lg = new LemonGraph(); boolean isUp = lg.isApiUp(); return isUp; }
try { JSONObject meta = new JSONObject(); jobId =lg.createGraph(meta); LemonGraphResponse lgr2 = null; try { lgr2 = lg.postToGraph(graphId, lgo); } catch (InvalidGraphException e) { System.out.println("Error can't lookup graph id " + graphId); HashMap <String,String> adapterPatterns = new HashMap<String,String>(); adapterPatterns.put("001",adapterPattern); JSONObject newgraph = lg.queryBasedOnPatterns(graphId, adapterPatterns, lastCount); JSONArray d= newgraph.getJSONArray("data"); HashMap<String, JSONArray> resultMap = lg.parseLemonGraphResult(newgraph); int id = 0; for (Map.Entry<String, JSONArray> entry : resultMap.entrySet()) { LemonGraphResponse lgr3 = lg.postToGraph(graphId, lgo2); } catch (InvalidGraphException e) { System.out.println("Unable to post changes to graph " + graphId + " aborting..."); lg.deleteGraph(graphId); } catch (Exception e) { System.out.println("Delete failed message: "+e.getMessage());
LemonGraph lg = new LemonGraph(); boolean isUp = lg.isApiUp(); JSONObject meta = new JSONObject(); meta.put("somemeta",3); jobId = lg.createGraph(meta); } catch (Exception e) { System.out.println(e.getMessage()); lg.deleteGraph(jobId); } catch (Exception e) { System.out.println("Delete failed message: "+e.getMessage());
protected void close() { try { AdapterManager.close(); JobManager.close(); LemonGraph.close(); } catch(Exception e) { log.error("Failed to close connections."); e.printStackTrace(); } }
jobId = LemonGraph.createGraph(new JSONObject()); //fetch a valid jobId from LEMONGRAPH LemonGraph.deleteGraph(jobId);//clear the empty job we got the ID from
if(jobId.length() == LGJob.JOB_ID_LENGTH) { //a valid job ID was sent in try { JSONObject job = LemonGraph.getGraph(jobId); //check that a job for given ID doesn't already exist if (job.get("id").equals(jobId)) { throw new Exception("jobId:" + jobId + " already exists."); if ((graphStore != null) && (graphStore.equalsIgnoreCase("lemongraph"))) { try { jobId = LemonGraph.createGraph(jobId, seedPayload.getJobConfig()); //Adds new job to LEMONGRAPH and gets jobId } catch(Exception e) { throw e;
String jobId = iterator.next().toString(); try { LEMONGRAPH.deleteGraph(jobId);
/** * Looks to see if the graph exists in LemonGraph, If not, it creates it. * @param meta is the 'meta' data to store in the graph at create time * @return Job UUID as defined by LEMONGRAPH * @throws Exception when failing to connect to LEMONGRAPH or failing to hit createGraph **/ public static String createGraph(String graphId, JSONObject meta) throws Exception { if(graphId != null && graphId.length() > 0 && graphId.length() != LGJob.JOB_ID_LENGTH) { throw new Exception("Invalid length for graph ID:"+graphId); } LemonGraphResponse lgr; if (!testConnection()) { log.error("Lemongraph is not connected... Error"); throw new Exception("Unable to connect to LEMONGRAPH. Create Failed."); } lgr = createGraphHelper(graphId, meta); if (!lgr.getSuccess()) { throw new Exception("LEMONGRAPH API call to createGraph Failed!!!"); } return lgr.getJobId(); }
/** * Adds the response nodes/edges from LGPayload into LEMONGRAPH. * @param payload LGPayload * @return Returns a LemonGraphResponse * @throws InvalidGraphException */ public static LemonGraphResponse postToGraph(LGPayload payload) throws InvalidGraphException { LemonGraphObject lgo = buildLemonGraphFromPayloadNodesandEdges(payload.getResponseNodes(), payload.getResponseEdges()); if (payload.getPayloadType().equals(LGConstants.LG_PAYLOAD_TYPE_COMMAND)) {lgo.setSeed(true);} return postToGraph(payload.getJobId(), lgo); }
public static JSONObject getGraph(String jobId) throws InvalidGraphException { JSONObject ret; String uri = restUrl + "graph/" + jobId; String body = getContent(uri); ret = new JSONObject(body); return ret; }
public void run() { LemonGraph lg = new LemonGraph(); System.out.println("Thread "+getName()+" Starting "); for (int c=1; c<= runCount; c++) { doTest(lg, c); } System.out.println("Thread "+getName()+" Complete"); }
/** Gets the graph from LemonGraph/DB in d3 format */ @GET @Path("/job/{id}/graph/d3") @Produces(MediaType.APPLICATION_JSON) public Response getJobGraphDataD3(@PathParam("id") String jobId) { // if (Utils.graphStoreStr.equalsIgnoreCase("lemongraph")) { try { JSONObject graph = LemonGraph.getGraphD3(jobId); return Response.status(200).entity(graph.toString()).build(); } catch (Exception e) { log.error("Lookup from LemonGraph failed " + e.getMessage()); return Response.status(404).entity("Graph Not stored in lemongraph").build(); } } return Response.status(404).entity("Not found").build(); }
/** Gets the graph from LemonGraph/DB in cytoscape format */ @GET @Path("/job/{id}/graph/cytoscape") @Produces(MediaType.APPLICATION_JSON) public Response getJobGraphDataCytoscape(@PathParam("id") String jobId) { // if (Utils.graphStoreStr.equalsIgnoreCase("lemongraph")) { try { JSONObject graph = LemonGraph.getGraphCytoscape(jobId); return Response.status(200).entity(graph.toString()).build(); } catch (Exception e) { log.error("Lookup from LemonGraph failed " + e.getMessage()); return Response.status(404).entity("Graph Not stored in lemongraph").build(); } } return Response.status(404).entity("Not found").build(); }
public void close() { try { JOB_MANAGER.close(); ADAPTER_MANAGER.close(); SUBMIT_TO_RABBIT.close(); LEMONGRAPH.close(); } catch(Exception e) { log.error("Failed to close connections."); e.printStackTrace(); } }
JSONObject graphRet = LemonGraph.deleteGraph(currentID); int status = graphRet.getInt("status"); if(status != 204) { //no content status expected for delete
public static JSONObject getGraphCytoscape(String jobId) throws InvalidGraphException { JSONObject ret; String uri = restUrl + "cytoscape/"+jobId; String body = getContent(uri); ret = new JSONObject(body); return ret; }
@Override public void prepare(final Map config, final TopologyContext context) { checkRunning = false; JOB_MANAGER = new JobManager(); ADAPTER_MANAGER = new AdapterManager(); SUBMIT_TO_RABBIT = new SubmitToRabbitMQ(); LEMONGRAPH = new LemonGraph(); log.info("Performing startup reset/expire for jobs."); resetJobs();//reset required jobs on startup expireJobs();//delete required jobs on startup LAST_RESET = System.currentTimeMillis(); }
/** Gets the graph from LemonGraph/DB in d3 format */ @GET @Path("/job/{id}/graph/d3/{start}/{stop}") @Produces(MediaType.APPLICATION_JSON) public Response getJobGraphDataD3(@PathParam("id") String jobId , @PathParam("start") int start , @PathParam("stop") int stop) { if (Utils.graphStoreStr.equalsIgnoreCase("lemongraph")) { try { JSONObject graph = LemonGraph.getGraphD3(jobId, start, stop); return Response.status(200).entity(graph.toString()).build(); } catch (Exception e) { log.error("Lookup from LemonGraph failed " + e.getMessage()); return Response.status(404).entity("Graph Not stored in lemongraph").build(); } } return Response.status(404).entity("Not found").build(); }