@Override public Job getJob(JobId jobId, String userName) throws JobNotFoundException { return getJob(jobId); }
@Test public void testJobCleanup() throws Exception { jobsService = (LocalJobsService) l(JobsService.class); SqlQuery ctas = getQueryFromSQL("SHOW SCHEMAS"); Job job = jobsService.submitJob(JobRequest.newBuilder() .setSqlQuery(ctas) .build(), NoOpJobStatusListener.INSTANCE); job.getData().loadIfNecessary(); SabotContext context = l(SabotContext.class); OptionValue days = OptionValue.createLong(OptionType.SYSTEM, ExecConstants.RESULTS_MAX_AGE_IN_DAYS.getOptionName(), 0); context.getOptionManager().setOption(days); OptionValue millis = OptionValue.createLong(OptionType.SYSTEM, ExecConstants.DEBUG_RESULTS_MAX_AGE_IN_MILLISECONDS.getOptionName(), 10); context.getOptionManager().setOption(millis); Thread.sleep(20); LocalJobsService.CleanupTask cleanupTask = jobsService.new CleanupTask(); cleanupTask.cleanup(); //make sure that the job output directory is gone assertFalse(jobsService.getJobResultsStore().jobOutputDirectoryExists(job.getJobId())); job = jobsService.getJob(job.getJobId()); assertFalse(JobDetailsUI.of(job).getResultsAvailable()); context.getOptionManager().setOption(OptionValue.createLong(OptionType.SYSTEM, ExecConstants.RESULTS_MAX_AGE_IN_DAYS.getOptionName(), 30)); context.getOptionManager().setOption(OptionValue.createLong(OptionType.SYSTEM, ExecConstants.DEBUG_RESULTS_MAX_AGE_IN_MILLISECONDS.getOptionName(), 0)); }
@Override public void registerListener(JobId jobId, ExternalStatusListener listener) { final QueryListener queryListener = runningJobs.get(jobId); if (queryListener != null) { queryListener.listeners.register(listener); return; } final Job job; try { job = getJob(jobId); listener.queryCompleted(job); } catch (JobNotFoundException e) { throw UserException.validationError() .message("Status requested for unknown job %s.", jobId.getId()) .build(logger); } }
@Override public void cancel(String username, JobId jobId, String reason) throws JobException { final ForemenTool tool = this.foremenTool.get(); final ExternalId id = ExternalIdHelper.toExternal(QueryIdHelper.getQueryIdFromString(jobId.getId())); if(tool.cancel(id, reason)){ logger.debug("Job cancellation requested on current node."); return; } // now remote... final Job job = getJob(jobId); NodeEndpoint endpoint = job.getJobAttempt().getEndpoint(); if(endpoint.equals(identity)){ throw new JobWarningException(jobId, "Unable to cancel job started on current node. It may have completed before cancellation was requested."); } try{ final CoordTunnel tunnel = coordTunnelCreator.get().getTunnel(JobsServiceUtil.toPB(endpoint)); Ack ack = tunnel.requestCancelQuery(id, reason).checkedGet(15, TimeUnit.SECONDS); if(ack.getOk()){ logger.debug("Job cancellation requested on {}.", endpoint.getAddress()); return; } else { throw new JobWarningException(jobId, String.format("Unable to cancel job started on %s. It may have completed before cancellation was requested.", endpoint.getAddress())); } }catch(TimeoutException | RpcException | RuntimeException e){ logger.info("Unable to cancel remote job for external id: {}", ExternalIdHelper.toString(id), e); throw new JobWarningException(jobId, String.format("Unable to cancel job on node %s.", endpoint.getAddress())); } }
@Override public QueryProfile getProfile(JobId jobId, int attempt) throws JobNotFoundException { Job job = getJob(jobId); final AttemptId attemptId = new AttemptId(JobsServiceUtil.getJobIdAsExternalId(jobId), attempt); if(jobIsDone(job.getJobAttempt())){ return profileStore.get(attemptId); } // Check if the profile for given attempt already exists. Even if the job is not done, it is possible that // profile exists for previous attempts final QueryProfile queryProfile = profileStore.get(attemptId); if (queryProfile != null) { return queryProfile; } final NodeEndpoint endpoint = job.getJobAttempt().getEndpoint(); if(endpoint.equals(identity)){ final ForemenTool tool = this.foremenTool.get(); Optional<QueryProfile> profile = tool.getProfile(attemptId.getExternalId()); return profile.orNull(); } try{ CoordTunnel tunnel = coordTunnelCreator.get().getTunnel(JobsServiceUtil.toPB(endpoint)); return tunnel.requestQueryProfile(attemptId.getExternalId()).checkedGet(15, TimeUnit.SECONDS); }catch(TimeoutException | RpcException | RuntimeException e){ logger.info("Unable to retrieve remote query profile for external id: {}", ExternalIdHelper.toString(attemptId.getExternalId()), e); return null; } }