/** * Action when a job is going to run * * @param job The job */ private void onJobRun(Job job) { // register as running synchronized (running) { for (int i = 0; i != running.length; i++) { if (running[i] == null) { running[i] = job; break; } } } // event before running job.onRun(); }
/** * Looks for a job in the running buffer * * @param identifier The identifier of a job * @return The job, or null if it is not found */ private Job getJobRunning(String identifier) { synchronized (running) { for (int i = 0; i != running.length; i++) { if (running[i] != null && running[i].getIdentifier().equals(identifier)) return running[i]; } return null; } }
builder.append(", "); first = false; builder.append(job.serializedJSON()); builder.append(", "); first = false; builder.append(job.serializedJSON()); builder.append(", "); first = false; builder.append(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()); }
@Override public XSPReply perform(ImpactAnalysisSetup setup) { SecurityService securityService = Register.getComponent(SecurityService.class); if (securityService == null) return XSPReplyServiceUnavailable.instance(); XSPReply reply = securityService.checkAction(ImpactAnalysisService.ACTION_PERFORM); if (!reply.isSuccess()) return reply; JobExecutionService executionService = Register.getComponent(JobExecutionService.class); if (executionService == null) return XSPReplyServiceUnavailable.instance(); XOWLImpactAnalysisJob job = new XOWLImpactAnalysisJob(setup); executionService.schedule(job); return new XSPReplyResult<>(job); } }
@Override public XSPReply cancel(Job job) { SecurityService securityService = Register.getComponent(SecurityService.class); if (securityService == null) return XSPReplyServiceUnavailable.instance(); XSPReply reply = securityService.checkAction(ACTION_CANCEL, job); if (!reply.isSuccess()) return reply; boolean success = executorPool.remove(job); if (success) { // the job was queued and prevented from running job.onTerminated(true); return XSPReplySuccess.instance(); } switch (job.getStatus()) { case Unscheduled: case Scheduled: job.onTerminated(true); return XSPReplySuccess.instance(); case Running: return job.cancel(); case Completed: return new XSPReplyApiError(ERROR_ALREADY_COMPLETED); case Cancelled: return new XSPReplyApiError(ERROR_ALREADY_CANCELLED); default: return new XSPReplyApiError(ERROR_INVALID_JOB_STATE, job.getStatus().toString()); } }
/** * 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()); }
/** * Looks for a job in the running buffer * * @param identifier The identifier of a job * @return The job, or null if it is not found */ private Job getJobRunning(String identifier) { synchronized (running) { for (int i = 0; i != running.length; i++) { if (running[i] != null && running[i].getIdentifier().equals(identifier)) return running[i]; } return null; } }
@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(); }
/** * Action when a job is going to run * * @param job The job */ private void onJobRun(Job job) { // register as running synchronized (running) { for (int i = 0; i != running.length; i++) { if (running[i] == null) { running[i] = job; break; } } } // event before running job.onRun(); Logging.get().info(new RichString("Begin running job ", job)); }
/** * 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()); }
/** * Looks for a job in the completed buffer * * @param identifier The identifier of a job * @return The job, or null if it is not found */ private Job getJobCompleted(String identifier) { synchronized (completed) { if (completedStart < 0) return null; for (int i = 0; i != completed.length; i++) { if (completed[i] == null) return null; if (completed[i].getIdentifier().equals(identifier)) return completed[i]; } } return null; }
/** * 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()); } }
/** * Looks for a job in the completed buffer * * @param identifier The identifier of a job * @return The job, or null if it is not found */ private Job getJobCompleted(String identifier) { synchronized (completed) { if (completedStart < 0) return null; for (int i = 0; i != completed.length; i++) { if (completed[i] == null) return null; if (completed[i].getIdentifier().equals(identifier)) return completed[i]; } } return null; }
/** * 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()); } }
/** * Looks for a job in the queue * * @param identifier The identifier of a job * @return The job, or null if it is not found */ private Job getJobScheduled(String identifier) { for (Runnable runnable : executorPool.getQueue()) { Job job = (Job) runnable; if (job.getIdentifier().equals(identifier)) return job; } return null; }
/** * Gets the file name for a job * * @param job The job * @return The file name */ private static String getFileName(Job job) { return "job-" + SHA1.hashSHA1(job.getIdentifier()) + ".json"; }
/** * Gets the file name for a job * * @param job The job * @return The file name */ private static String getFileName(Job job) { return "job-" + IOUtils.hashSHA1(job.getIdentifier()) + ".json"; }
/** * Looks for a job in the queue * * @param identifier The identifier of a job * @return The job, or null if it is not found */ private Job getJobScheduled(String identifier) { for (Runnable runnable : getExecutorPool().getQueue()) { Job job = (Job) runnable; if (job.getIdentifier().equals(identifier)) return job; } return null; }