@POST @Path("/{id}/cancel") public void cancelJob(@PathParam("id") String id) throws JobException { final String username = securityContext.getUserPrincipal().getName(); try { jobs.cancel(username, new JobId(id), String.format("Query cancelled by user '%s'", username)); } catch (JobNotFoundException e) { throw new NotFoundException(String.format("Could not find a job with id [%s]", id)); } } }
@GET @Path("/cancel/{queryid}") @Produces(MediaType.TEXT_PLAIN) public NotificationResponse cancelQuery(@PathParam("queryid") String queryId) { try { jobsService.cancel(null, new JobId(queryId), String.format("Query cancelled by user '%s'", securityContext.getUserPrincipal().getName())); return new NotificationResponse(ResponseType.OK, "Job cancellation requested"); } catch(JobWarningException e) { return new NotificationResponse(ResponseType.WARN, e.getMessage()); } catch(JobException e) { return new NotificationResponse(ResponseType.ERROR, e.getMessage()); } }
@POST @Path("cancel") @Produces(APPLICATION_JSON) public NotificationResponse cancel(@PathParam("jobId") String jobId) throws JobResourceNotFoundException { try { final String username = securityContext.getUserPrincipal().getName(); jobsService.cancel(username, new JobId(jobId), String.format("Query cancelled by user '%s'", username)); return new NotificationResponse(ResponseType.OK, "Job cancellation requested"); } catch(JobNotFoundException e) { throw JobResourceNotFoundException.fromJobNotFoundException(e); } catch(JobWarningException e) { return new NotificationResponse(ResponseType.WARN, e.getMessage()); } catch(JobException e) { return new NotificationResponse(ResponseType.ERROR, e.getMessage()); } }
private void cancelRefreshJobIfAny(ReflectionEntry entry) { if (entry.getState() != REFRESHING && entry.getState() != METADATA_REFRESH) { return; } final Materialization m = Preconditions.checkNotNull(materializationStore.getLastMaterialization(entry.getId()), "reflection entry %s is in REFRESHING|METADATA_REFRESH state but has no materialization entry", entry.getId()); try { logger.debug("cancelling materialization job {} for reflection {}", entry.getRefreshJobId().getId(), getId(entry)); // even though the following method can block if the job's foreman is on a different node, it's not a problem here // as we always submit reflection jobs on the same node as the manager jobsService.cancel(SYSTEM_USERNAME, entry.getRefreshJobId(), "Query cancelled by Reflection Manager. Reflection configuration is stale"); } catch (JobException e) { logger.warn("Failed to cancel refresh job updated reflection {}", getId(entry), e); } // mark the materialization as cancelled m.setState(MaterializationState.CANCELED); materializationStore.save(m); // we don't need to handle the job, if it did complete and wrote some data, they will eventually get deleted // when the materialization entry is deleted }
@Test public void cancelledDownloadJob() throws Exception { final DatasetPath dsPath = new DatasetPath("DG.testDS2"); DatasetUI ds = createDatasetFromSQLAndSave(dsPath,"select * from DG.dsg1 --- comment", asList("cp")); final Job job = datasetService.prepareDownload(dsPath, ds.getDatasetVersion(), DownloadFormat.CSV, 500, SampleDataPopulator.DEFAULT_USER_NAME); l(JobsService.class).cancel(SampleDataPopulator.DEFAULT_USER_NAME, job.getJobId(), "because I can"); job.getData().loadIfNecessary(); if (l(JobsService.class).getJob(job.getJobId()).getJobAttempt().getState() == JobState.CANCELED) { try { datasetService.downloadData(job.getJobAttempt().getInfo().getDownloadInfo(), SampleDataPopulator.DEFAULT_USER_NAME); fail(); } catch (Exception e) { assertTrue(e instanceof FileNotFoundException); } } }