builder.append(", "); first = false; builder.append(job.serializedJSON()); builder.append(", "); first = false; builder.append(job.serializedJSON()); builder.append(", "); first = false; builder.append(job.serializedJSON());
if (i != 0) builder.append(", "); builder.append(scheduled.get(i).serializedJSON()); if (i != 0) builder.append(", "); builder.append(running.get(i).serializedJSON()); if (i != 0) builder.append(", "); builder.append(completed.get(i).serializedJSON());
@Override public void schedule(Job job) { ThreadPoolExecutor pool = getExecutorPool(); boolean exists = storage.exists(); if (!exists) { exists = storage.mkdirs(); } if (exists) { try (Writer write = Files.getWriter(new File(storage, getFileName(job)).getAbsolutePath())) { write.write(job.serializedJSON()); } catch (IOException exception) { Logger.DEFAULT.error(exception); } } else { Logger.DEFAULT.error("Cannot serialize the job, storage is inaccessible"); } job.onScheduled(); pool.execute(job); }
@Override public HttpResponse onMessage(String method, String uri, Map<String, String[]> parameters, String contentType, byte[] content, String accept) { String[] ids = parameters.get("id"); if (ids != null && ids.length > 0) { Job job = getJob(ids[0], JobStatus.Completed); if (job == null) return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND); return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, job.serializedJSON()); } return onRequestJobs(); }
@Override public XSPReply schedule(Job job) { boolean exists = storage.exists(); if (!exists) { exists = storage.mkdirs(); } if (exists) { try (Writer write = IOUtils.getWriter(new File(storage, getFileName(job)).getAbsolutePath())) { write.write(job.serializedJSON()); } catch (IOException exception) { Logging.get().error(exception); } } else { Logging.get().error("Cannot serialize the job, storage is inaccessible"); } job.onScheduled(); synchronized (initQueue) { if (canExecute.get()) { executorPool.execute(job); } else { initQueue.add(job); } } Logging.get().info(new RichString("Scheduled job ", job)); return new XSPReplyResult<>(job); }
if (job == null) return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND); return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, job.serializedJSON()); } else if (rest.substring(index).equals("/cancel")) { if (!HttpConstants.METHOD_POST.equals(request.getMethod()))
/** * Responds to the request to pull an artifact from the live store * When successful, this action creates the appropriate job and returns it. * * @param parameters The request parameters * @return The response */ private HttpResponse onMessagePullFromLive(Map<String, String[]> parameters) { String[] ids = parameters.get("id"); if (ids == null || ids.length == 0) return new HttpResponse(HttpURLConnection.HTTP_BAD_REQUEST, HttpConstants.MIME_TEXT_PLAIN, "Expected an id parameter"); JobExecutionService executor = ServiceUtils.getService(JobExecutionService.class); if (executor == null) return XSPReplyUtils.toHttpResponse(XSPReplyServiceUnavailable.instance(), null); Job job = new PullArtifactFromLiveJob(ids[0]); executor.schedule(job); return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, job.serializedJSON()); }
/** * Responds to the request to push an artifact to the live store * When successful, this action creates the appropriate job and returns it. * * @param parameters The request parameters * @return The response */ private HttpResponse onMessagePushToLive(Map<String, String[]> parameters) { String[] ids = parameters.get("id"); if (ids == null || ids.length == 0) return new HttpResponse(HttpURLConnection.HTTP_BAD_REQUEST, HttpConstants.MIME_TEXT_PLAIN, "Expected an id parameter"); JobExecutionService executor = ServiceUtils.getService(JobExecutionService.class); if (executor == null) return XSPReplyUtils.toHttpResponse(XSPReplyServiceUnavailable.instance(), null); Job job = new PushArtifactToLiveJob(ids[0]); executor.schedule(job); return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, job.serializedJSON()); } }
/** * Responds to a request to delete an artifact * * @param parameters The request parameters * @return The response */ private HttpResponse onMessageDeleteArtifact(Map<String, String[]> parameters) { String[] ids = parameters.get("id"); if (ids == null || ids.length == 0) return new HttpResponse(HttpURLConnection.HTTP_BAD_REQUEST, HttpConstants.MIME_TEXT_PLAIN, "Expected an id parameter"); JobExecutionService executor = ServiceUtils.getService(JobExecutionService.class); if (executor == null) return XSPReplyUtils.toHttpResponse(XSPReplyServiceUnavailable.instance(), null); Job job = new DeleteArtifactJob(ids[0]); executor.schedule(job); return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, job.serializedJSON()); }
/** * Responds to the request to pull an artifact from a connector * When successful, this action creates the appropriate job and returns it. * * @param connectorId The identifier of the connector to delete * @return The response */ private HttpResponse onMessagePullFromConnector(String connectorId) { JobExecutionService executor = Register.getComponent(JobExecutionService.class); if (executor == null) return XSPReplyUtils.toHttpResponse(XSPReplyServiceUnavailable.instance(), null); Job job = new PullArtifactJob(connectorId); executor.schedule(job); return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, job.serializedJSON()); }
/** * Responds to the request to push an artifact to a connector * When successful, this action creates the appropriate job and returns it. * * @param connectorId The identifier of the connector to delete * @param request The request to handle * @return The response */ private HttpResponse onMessagePushToConnector(String connectorId, HttpApiRequest request) { String artifact = request.getParameter("artifact"); if (artifact == null) return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_EXPECTED_QUERY_PARAMETERS, "'artifact'"), null); JobExecutionService executor = Register.getComponent(JobExecutionService.class); if (executor == null) return XSPReplyUtils.toHttpResponse(XSPReplyServiceUnavailable.instance(), null); Job job = new PushArtifactJob(connectorId, artifact); executor.schedule(job); return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, job.serializedJSON()); } }