public void addResponseNodes(JSONArray nodes) { Iterator iterator = nodes.iterator(); while(iterator.hasNext()) { JSONObject node = (JSONObject) iterator.next(); addResponseNode(node); } }
public static JSONObject buildJobSubmitObject(List approvedAdapters, String jobId, JSONObject node) { LGPayload lgp = new LGPayload(jobId); if(!node.has("type")) //add "type" if not present node.put("type","id"); if(!node.has("value")) //add value if not present node.put("value",UUID.randomUUID().toString()); lgp.addResponseNode(node); return buildJobSubmitObject(approvedAdapters, lgp); }
@Override public void process(LGPayload input, LGJavaAdapter.LGCallback callback) { List<JSONObject> requests = input.getRequestNodes(); JSONObject node; try { //We always fail for(int i = 0; i < requests.size(); i++) { node = requests.get(i); node.put("HelloWorldFail", "processed"); input.addResponseNode(node); } Exception e = new Exception("Adapter Always fails"); throw(e); } catch (Exception e) { e.printStackTrace(); callback.fail(e); } }
public static void main(String[] args) throws Exception { ArrayList<String> approvedAdapters = new ArrayList(); approvedAdapters.add("Fail"); JSONObject node = new JSONObject() .put("type", "id") .put("value", UUID.randomUUID()) .put("status", "test") ; //Read file of certs and create job_config object then LGPayload String job_id = UUID.randomUUID().toString(); JSONObject job_config = new JSONObject() .put("job_item", "job_value"); LGPayload payload = new LGPayload(job_id, "", job_config); //Add all nodes payload.addResponseNode(node); SubmitToRabbitMQ submit = new SubmitToRabbitMQ(); submit.sendNewJobToCommandController(approvedAdapters, payload); Thread.sleep(500); submit.close(); System.out.println("Job submitted."); } }
public static void main(String[] args) throws Exception { ArrayList<String> approvedAdapters = new ArrayList(); approvedAdapters.add("HelloWorld"); approvedAdapters.add("PlusBang"); JSONObject node = new JSONObject() .put("type", "id") .put("value", UUID.randomUUID()) .put("status", "test") ; //Read file of certs and create job_config object then LGPayload String job_id = UUID.randomUUID().toString(); JSONObject job_config = new JSONObject() .put("job_item", "job_value"); LGPayload payload = new LGPayload(job_id, "", job_config); //Add all nodes payload.addResponseNode(node); SubmitToRabbitMQ submit = new SubmitToRabbitMQ(); submit.sendNewJobToCommandController(approvedAdapters, payload); Thread.sleep(500); submit.close(); System.out.println("Job submitted."); } }
public static void main(String[] args) throws Exception { ArrayList<String> approvedAdapters = new ArrayList(); approvedAdapters.add("HelloWorld"); JSONObject node = new JSONObject() .put("type", "id") .put("value", UUID.randomUUID()) .put("status", "test") ; //Read file of certs and create job_config object then LGPayload String job_id = UUID.randomUUID().toString(); JSONObject job_config = new JSONObject() .put("job_item", "job_value"); LGPayload payload = new LGPayload(job_id, "", job_config); //Add all nodes payload.addResponseNode(node); SubmitToRabbitMQ submit = new SubmitToRabbitMQ(); submit.sendNewJobToCommandController(approvedAdapters, payload); Thread.sleep(500); submit.close(); System.out.println("Job submitted."); } }
@Override public void process(LGPayload input, LGCallback callback) { List<JSONObject> requests = input.getRequestNodes(); JSONObject request; JSONObject config = getJobConfig(input); log.info("POSTACTON ADAPTER CONFIG: "+config.toString()); try { for (int i = 0; i < requests.size(); i++) { request = requests.get(i); request.put("hello_postaction", request.get("hello") + "!"); input.addResponseNode(request); JSONObject edgeMeta = new JSONObject().put("type", "edge").put("value", "connects"); JSONObject dstMeta = new JSONObject().put("type", "node1").put("value", UUID.randomUUID().toString()); JSONObject dstMeta2 = new JSONObject().put("type", "node2").put("value", UUID.randomUUID().toString()); // Add an edge input.addResponseEdge(request, edgeMeta, dstMeta); input.addResponseEdge(request, edgeMeta, dstMeta2); } callback.emit(input); } catch (Exception e) { e.printStackTrace(); callback.fail(e); } }
@Override public void process(LGPayload input, LGCallback callback) { List<JSONObject> requests = input.getRequestNodes(); JSONObject request = null; try { for(int i = 0; i < requests.size(); i++) { request = requests.get(i); request.put("hello_bang", request.get("hello") + "!"); input.addResponseNode(request); JSONObject edgeMeta = new JSONObject().put("type", "edge").put("value", "connects"); JSONObject dstMeta = new JSONObject().put("type", "node1").put("value", UUID.randomUUID().toString()); JSONObject dstMeta2 = new JSONObject().put("type", "node2").put("value", UUID.randomUUID().toString()); // Add an edge input.addResponseEdge(request, edgeMeta, dstMeta); input.addResponseEdge(request, edgeMeta, dstMeta2); } callback.emit(input); } catch (Exception e) { e.printStackTrace(); callback.fail(e); } }
@Override public void process(LGPayload input, LGCallback callback) { List<JSONObject> requests = input.getRequestNodes(); JSONObject request = null; try { String result = Requests.get("http://www.google.com").response_msg; final String alphaNumeric = result.replaceAll("[^a-zA-Z0-9]+", "").substring(0, 100); for(int i = 0; i < requests.size(); i++) { request = requests.get(i); request.put("curl-google", alphaNumeric); input.addResponseNode(request); } callback.emit(input); } catch (Exception e) { e.printStackTrace(); callback.fail(e); } }
@Override public void process(LGPayload input, LGJavaAdapter.LGCallback callback) { List<JSONObject> requests = input.getRequestNodes(); JSONObject request = null; count++; try { for(int i = 0; i < requests.size(); i++) { request = requests.get(i); int id = request.getInt("ID"); if (count <= RUNTIMES) { JSONObject newNode = new JSONObject(); newNode.put("type", "hello"); newNode.put("value", "world" + id); newNode.put("hello", "world" + id); input.addResponseNode(newNode); } } Utils.sleep(SLEEPTIME); //throw new Exception(); callback.emit(input); } catch (Exception e) { e.printStackTrace(); callback.fail(e); } }
@Override public void run() { List<JSONObject> requests = input.getRequestNodes(); JSONObject request = null; try { sleep(500); for (int i = 0; i < requests.size(); i++) { request = requests.get(i); request.put("async", "ftw"); input.addResponseNode(request); input.addResponseEdge(request, new JSONObject().put("type", "connection").put("value", "foo"), new JSONObject().put("type", "lemongrenade-core-test").put("value", "ignore").put("async", true)); } callback.emit(input); } catch (Exception e) { e.printStackTrace(); callback.fail(e); } } }.start();
@Override public void process(LGPayload input, LGCallback callback) { List<JSONObject> requests = input.getRequestNodes(); JSONObject request = null; // THis is only when you want to test adapter critically failing //String causeJSONException = this.getJobConfig(input).getString("somethingyouknowdoesntexist"); try { for(int i = 0; i < requests.size(); i++) { request = requests.get(i); request.put("hello", "world"); JSONObject job_config = this.getJobConfig(input); if(job_config.has("job_item")) { request.put("job_item", "Hello "+job_config.getString("job_item")); } input.addResponseNode(request); } //throw new Exception(); log.info("HelloWorld Success!"); callback.emit(input); } catch (Exception e) { e.printStackTrace(); callback.fail(e); } }
request = requests.get(i); request.put("hello_my_bang", request.get("type")); input.addResponseNode(request);
node.put("type", "id"); node.put("value", UUID.randomUUID().toString()); lgp.addResponseNode(node);
public static void feedCoordinator(int sleep, int times, ArrayList<String> approvedAdapters, JSONObject node) throws Exception { String jobId; SubmitToRabbitMQ submit = new SubmitToRabbitMQ(); for (int i = 0; i != times; i++) { LGPayload lgp = new LGPayload(); lgp.addResponseNode(node); JSONObject jobConfig = new JSONObject(); jobConfig.put("depth","6"); lgp.setJobConfig(jobConfig); submit.sendNewJobToCommandController(approvedAdapters, lgp); if (sleep > 0) { Thread.sleep(sleep); // ~500 requests/sec } } submit.close(); }
newPayload.addResponseNode(node);
JSONObject node = nodes.getJSONObject(i); if(!node.has("LG:METADATA")) {node.put("LG:METADATA", new JSONObject());} newPayload.addResponseNode(node);
payload.addResponseNode(edge.getJSONObject(0)); //src payload.addResponseNode(edge.getJSONObject(2)); //dst