public LemonGraph() { openConnection(); }
/** * This is a cheat because /ping doesn't yet exist in Lemongraph. Here we just check something * is listening on the restUrl port. * * @return boolean up or down */ public static boolean isApiUp() { openConnection(); try { String url = restUrl+"ping/"; RequestResult result = Requests.get(url); int status = result.status_code; log.info("Ping Response ["+status+"]"); } catch (Exception e) { log.error("Caught exception in ping " + e.getMessage()); return false; } // Send 'ping' return true; }
openConnection(); RequestResult result = Requests.get(url); int status = result.status_code;
openConnection(); RequestResult result = Requests.get(url); int status = result.status_code;
openConnection(); RequestResult result = Requests.get(url); int status = result.status_code;
/** * Reset tells LemonGraph to remove all 'learned' data from adapters from the graph but keeps the * initial seed data so the job can be RERAN by a user. * * @param graphId String for graph ID * @return JSONObject * @throws InvalidGraphException thrown when failing to call reset in LemonGraph */ public static JSONObject resetGraph(String graphId) throws InvalidGraphException { JSONObject ret = new JSONObject(); try { openConnection(); ContentResponse res = client.newRequest(restUrl + "reset/" + graphId) .method(HttpMethod.PUT) .send(); int status = res.getStatus(); ret.put("status", status); ret.put("message", res.getContentAsString()); } catch (Exception e) { log.error("Caught exception in reset Graph "+e.getMessage()); throw new InvalidGraphException(e.getMessage()); } return ret; }
/** * Deletes the entire graph from the LemonGraph database. * * @param graphId String of graph ID * @return JSONObject * @throws InvalidGraphException thrown when failing to hit LemonGraph graph/ */ public static JSONObject deleteGraph(String graphId) throws InvalidGraphException { JSONObject ret = new JSONObject(); try { openConnection(); ContentResponse res = client.newRequest(restUrl+"graph/"+graphId) .method(HttpMethod.DELETE) .agent("Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:17.0) Gecko/20100101 Firefox/17.0") .send(); int status = res.getStatus(); ret.put("status", status); ret.put("message", res.getContentAsString()); return ret; } catch (Exception e) { log.error("Caught exception in deleteGraph "+e.getMessage()); throw new InvalidGraphException(e.getMessage()); } }
ContentResponse res = null; try { openConnection(); Request req; if(graphId != null && graphId.length() > 0) { //ensure this is a 'real' graphId
/** * @param graphId String for graph ID * @param graph LemonGraphObject * @return LemonGraphResponse * @throws InvalidGraphException thrown when failing to connect and hit graph/ */ public static LemonGraphResponse postToGraph(String graphId, LemonGraphObject graph) throws InvalidGraphException { LemonGraphResponse lgr = new LemonGraphResponse(); ContentResponse res = null; try { openConnection(); String url = restUrl + "graph/" + graphId; Request req = client.POST(url); JSONObject graphContent = graph.get(); req.content(new StringContentProvider(graphContent.toString()), "application/json"); res = req.send(); lgr.parseContentResponse(res); // TODO: check responseCode to be 204? } catch (Exception e) { log.error("Error trying to postToGraph "+e.getMessage()); lgr.setSuccess(false); } return lgr; }