@GET @Path("/{id}") public JobStatus getJobStatus(@PathParam("id") String id) { try { Job job = jobs.getJob(new JobId(id), securityContext.getUserPrincipal().getName()); return JobStatus.fromJob(job); } catch (JobNotFoundException e) { throw new NotFoundException(String.format("Could not find a job with id [%s]", id)); } }
try { statusListener.jobCompleted(); return new JobUI(jobsService.getJob(job.getJobId())); } catch (RuntimeException | JobNotFoundException e) { logger.debug("job {} not found for dataset {}", job.getJobId().getId(), messagePath, e);
@GET @Path("/details") @Produces(APPLICATION_JSON) public JobDetailsUI getJobDetail(@PathParam("jobId") String jobId) throws JobResourceNotFoundException { JobId id = new JobId(jobId); final Job job; try { job = jobsService.getJob(id, securityContext.getUserPrincipal().getName()); } catch (JobNotFoundException e) { throw JobResourceNotFoundException.fromJobNotFoundException(e); } return JobDetailsUI.of(job); }
@Test public void testQueryParser() throws Exception { TestSpacesStoragePlugin.setup(getCurrentDremioDaemon()); getPreview(getDataset(new DatasetPath("testA.dsA1"))); List<Job> jobs = ImmutableList.copyOf(l(JobsService.class).getJobsForDataset(new DatasetPath("testA.dsA1").toNamespaceKey(), 1000)); assertNotNull(jobs); assertTrue(jobs.size() > 0); JobUI job1 = expectSuccess(getBuilder(getAPIv2().path("job/" + jobs.get(0).getJobId().getId())).buildGet(), JobUI.class); assertEquals(jobs.get(0).getJobId(), job1.getJobId()); final Job job = l(JobsService.class).getJob(jobs.get(0).getJobId()); final JobDetails jobDetails = job.getJobAttempt().getDetails(); final JobStats jobStats = job.getJobAttempt().getStats(); assertEquals(1, jobDetails.getTableDatasetProfilesList().size()); assertEquals(1000, (long)jobDetails.getOutputRecords()); // leaf limit is 10k assertEquals(16250, (long) jobDetails.getDataVolume()); assertEquals(16250, (long) jobStats.getOutputBytes()); assertEquals(16250, (long) jobStats.getInputBytes()); assertEquals(1000, (long) jobStats.getInputRecords()); assertEquals(1000, (long) jobStats.getOutputRecords()); } }
@GET @Path("/data") @Produces(APPLICATION_JSON) public JobDataFragment getDataForVersion( @PathParam("jobId") JobId jobId, @QueryParam("limit") int limit, @QueryParam("offset") int offset) throws JobResourceNotFoundException { Preconditions.checkArgument(limit > 0, "Limit should be greater than 0"); Preconditions.checkArgument(offset >= 0, "Limit should be greater than or equal to 0"); final Job job; try { job = jobsService.getJob(jobId, securityContext.getUserPrincipal().getName()); } catch (JobNotFoundException e) { logger.warn("job not found: {}", jobId); throw JobResourceNotFoundException.fromJobNotFoundException(e); } // job results in pagination requests. return new JobUI(job).getData().range(offset, limit); }
@GET @Path("/r/{rowNum}/c/{columnName}") @Produces(APPLICATION_JSON) public Object getCellFullValue( @PathParam("jobId") JobId jobId, @PathParam("rowNum") int rowNum, @PathParam("columnName") String columnName) throws JobResourceNotFoundException { Preconditions.checkArgument(rowNum >= 0, "Row number shouldn't be negative"); Preconditions.checkNotNull(columnName, "Expected a non-null column name"); final Job job; try { job = jobsService.getJob(jobId, securityContext.getUserPrincipal().getName()); } catch (JobNotFoundException e) { logger.warn("job not found: {}", jobId); throw JobResourceNotFoundException.fromJobNotFoundException(e); } return new JobUI(job).getData().range(rowNum, 1).extractValue(columnName, 0); }
/** * Get job overview. * @param jobId job id */ @GET @Produces(APPLICATION_JSON) public JobUI getJob(@PathParam("jobId") String jobId) throws JobResourceNotFoundException { try { return new JobUI(jobsService.getJob(new JobId(jobId), securityContext.getUserPrincipal().getName())); } catch (JobNotFoundException e) { throw JobResourceNotFoundException.fromJobNotFoundException(e); } }
@GET @Path("/{id}/results") public JobData getQueryResults(@PathParam("id") String id, @QueryParam("offset") @DefaultValue("0") Integer offset, @Valid @QueryParam("limit") @DefaultValue("100") Integer limit) { Preconditions.checkArgument(limit <= 500,"limit can not exceed 500 rows"); try { Job job = jobs.getJob(new JobId(id), securityContext.getUserPrincipal().getName()); if (job.getJobAttempt().getState() != JobState.COMPLETED) { throw new BadRequestException(String.format("Can not fetch details for a job that is in [%s] state.", job.getJobAttempt().getState())); } return new QueryJobResults(job, offset, limit).getData(); } catch (JobNotFoundException e) { throw new NotFoundException(String.format("Could not find a job with id [%s]", id)); } }
recordHeader(zip, jobId, config, submissionId); final Job job = jobsService.get().getJob(jobId); for(int attemptIndex = 0; attemptIndex < job.getAttempts().size() ; attemptIndex++) { zip.putNextEntry(new ZipEntry(String.format("profile_attempt_%d.json", attemptIndex)));
private JobDetailsUI getDetails(QueryId id) throws JobNotFoundException { return JobDetailsUI.of(jobs.getJob(toId(id))); }
public Response downloadData(@PathParam("jobId") JobId jobId) throws IOException, JobResourceNotFoundException, JobNotFoundException { final Job job = jobsService.getJob(jobId, securityContext.getUserPrincipal().getName()); final JobInfo jobInfo = job.getJobAttempt().getInfo();
private boolean recordHeader(OutputStream output, JobId id, User user, String submissionId) throws UserNotFoundException, IOException, JobNotFoundException { SupportHeader header = new SupportHeader(); header.setClusterInfo(getClusterInfo()); header.setJob(jobsService.get().getJob(id).getJobAttempt()); Submission submission = new Submission() .setSubmissionId(submissionId) .setDate(System.currentTimeMillis()) .setEmail(user.getEmail()) .setFirst(user.getFirstName()) .setLast(user.getLastName()); header.setSubmission(submission); // record the dremio version that was used to run the query in the header header.setDremioVersion(jobsService.get().getProfile(id, 0).getDremioVersion()); ProtostuffUtil.toJSON(output, header, SupportHeader.getSchema(), false); return true; }
/** * Helper method to create {@link InitialPreviewResponse} from given inputs * @return */ InitialPreviewResponse createPreviewResponse(VirtualDatasetUI datasetUI, JobUI job, DatasetVersion tipVersion, Integer maxRecords, boolean catchExecutionError) throws DatasetVersionNotFoundException, NamespaceException, JobNotFoundException { JobDataFragment dataLimited = null; ApiErrorModel<?> error = null; if(maxRecords == null) { maxRecords = INITIAL_RESULTSET_SIZE; } try { if (maxRecords > 0) { dataLimited = job.getData().truncate(maxRecords); } else { dataLimited = getDataOnlyWithColumns(jobsService.getJob(job.getJobId()).getJobAttempt().getInfo()); } } catch (Exception ex) { if (!catchExecutionError) { throw ex; } if (ex instanceof UserException) { toInvalidQueryException((UserException) ex, datasetUI.getSql(), ImmutableList.<String> of()); } error = new ApiErrorModel<Void>(ApiErrorModel.ErrorType.INITIAL_PREVIEW_ERROR, ex.getMessage(), GenericErrorMessage.printStackTrace(ex), null); } final History history = getHistory(new DatasetPath(datasetUI.getFullPathList()), datasetUI.getVersion(), tipVersion); return InitialPreviewResponse.of(newDataset(datasetUI, tipVersion), job.getJobId(), dataLimited, true, history, error); }
@Test public void testDownloadJsonRest() throws Exception { final String downloadPath = new DatasetVersionResourcePath(new DatasetPath("DG.dsg1"), dsg1.getVersion()).toString(); InitialDownloadResponse initialDownloadResponse = expectSuccess( getBuilder(getAPIv2().path(downloadPath).path("download").queryParam("downloadFormat", DownloadFormat.JSON)).buildGet(), InitialDownloadResponse.class); // wait for job final Job job = l(JobsService.class).getJob(initialDownloadResponse.getJobId()); job.getData().loadIfNecessary(); // get job data Response response = getBuilder(getAPIv2().path(initialDownloadResponse.getDownloadUrl())).buildGet().invoke(); validateAllRows(readDataJson((InputStream)response.getEntity())); }
@Test public void testDownloadCsvRest() throws Exception { final String downloadPath = new DatasetVersionResourcePath(new DatasetPath("DG.dsg1"), dsg1.getVersion()).toString(); InitialDownloadResponse initialDownloadResponse = expectSuccess( getBuilder(getAPIv2().path(downloadPath).path("download").queryParam("downloadFormat", DownloadFormat.CSV)).buildGet(), InitialDownloadResponse.class); // wait for job final Job job = l(JobsService.class).getJob(initialDownloadResponse.getJobId()); job.getData().loadIfNecessary(); // get job data Response response = getBuilder(getAPIv2().path(initialDownloadResponse.getDownloadUrl())).buildGet().invoke(); validateAllRows(readDataCsv((InputStream)response.getEntity())); }
throws DatasetVersionNotFoundException, NamespaceException, JobNotFoundException { final Job jobRawData = jobsService.getJob(new JobId(jobId)); final JobUI job = new JobUI(jobRawData); final JobInfo jobInfo = jobRawData.getJobAttempt().getInfo();
job1_0.getData().loadIfNecessary(); JobDataFragment result = job1_0.getData().truncate(10); JobDataFragment storedResult = jobsService.getJob(job1_0.getJobId()).getData().truncate(10); for (Field column: result.getSchema()) { assertTrue(storedResult.getSchema().getFields().contains(column));
@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); } } }