/** 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(); }
public static String seedJob() throws Exception { JSONObject defaultJob = new JSONObject() .put("config", "config") .put("ID", "ID") .put("meta", "meta") .put("reason", "reason") .put("graph", "graph"); String port = LGProperties.get("api.port"); String url = "http://localhost:" + port + "/api/job"; RequestResult result = Requests.post(url, defaultJob.toString(), new JSONObject()); String body = result.response_msg; JSONObject jBody = new JSONObject(body); String jobId = jBody.getString("job_id"); boolean exists = false; int retries = 3; while(exists == false && retries > 0) { JSONObject graph = LemonGraph.getGraph(jobId); if (graph.has("created")) { exists = true; break; } retries--; Thread.sleep(Utils.SECOND / 2); } if(!exists) { log.error("Couldn't fetch seeded job."); } return jobId; }
/** * @param jobId LG job ID to send to * @param approvedAdapters List of approved adapter names * @param seedPayload LGPayload for seeding a new job * */ public void sendAddToJobToCommandController(String jobId, ArrayList<String> approvedAdapters, LGPayload seedPayload) throws Exception { openConnections(); int ttl = 0; if (seedPayload.getJobConfig().has("ttl")) { ttl = seedPayload.getJobConfig().getInt("ttl"); } try { LemonGraph.getGraph(jobId); //verify the job already exists in LemonGraph } catch(Exception e) { throw new Exception("job:"+jobId+" doesn't exist. First perform a job create. Error:"+e.getMessage()); } seedPayload.setJobId(jobId); LGCommand cmd = new LGCommand(LGCommand.COMMAND_TYPE_ADD, jobId, ttl, 255, approvedAdapters, seedPayload); channel.basicPublish("", LGConstants.LEMONGRENADE_COORDINATORCMD , new AMQP.BasicProperties.Builder().priority(LGConstants.QUEUE_PRIORITY_NEW_JOB).build() , cmd.toByteArray()); }
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.");