use of gov.cms.ab2d.common.service.ResourceNotFoundException in project ab2d by CMSgov.
the class JobClientMock method poll.
public JobPollResult poll(boolean admin, String jobUuid, String organization, int delaySeconds) {
if (jobUuid.isBlank()) {
throw new ResourceNotFoundException("No job with jobUuid " + jobUuid + " was found");
}
pollAndUpdateTime(jobUuid, delaySeconds);
StartJobDTO startJobDTO = createdJobs.get(jobUuid);
if (startJobDTO == null) {
throw new ResourceNotFoundException("No job with jobUuid " + jobUuid + " was found");
}
String transactionTime = new org.hl7.fhir.dstu3.model.DateTimeType(OffsetDateTime.now().toString()).toHumanDisplay();
return new JobPollResult(startJobDTO.getUrl(), expectedStatus, progress, transactionTime, expiresAt, jobOutputList);
}
use of gov.cms.ab2d.common.service.ResourceNotFoundException in project ab2d by CMSgov.
the class JobClientMock method cancelJob.
public void cancelJob(String jobUuid, String organization) {
if (!createdJobs.containsKey(jobUuid)) {
throw new ResourceNotFoundException("No job with jobUuid " + jobUuid + " was found");
}
if (!expectedStatus.isCancellable()) {
throw new InvalidJobStateTransition("Job has a status of " + expectedStatus + ", so it cannot be cancelled");
}
JobStatusChangeEvent jobStatusChangeEvent = new JobStatusChangeEvent(createdJobs.get(jobUuid).getOrganization(), jobUuid, expectedStatus.name(), CANCELLED.name(), "Job Cancelled");
eventLogger.log(jobStatusChangeEvent);
}
use of gov.cms.ab2d.common.service.ResourceNotFoundException in project ab2d by CMSgov.
the class JwtTokenAuthenticationFilter method doFilterInternal.
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
String jobId = UtilMethods.parseJobId(request.getRequestURI());
if (shouldBePublic(request.getRequestURI())) {
if (uriFilter.test(request.getRequestURI())) {
logApiRequestEvent(request, null, null, jobId);
}
chain.doFilter(request, response);
return;
}
String token = null;
String client;
try {
token = getToken(request);
client = getClientId(token);
} catch (Exception ex) {
logApiRequestEvent(request, token, null, jobId);
throw ex;
}
if (client.isEmpty()) {
logApiRequestEvent(request, token, null, jobId);
String clientBlankMsg = "Client id was blank";
log.error(clientBlankMsg);
throw new BadJWTTokenException(clientBlankMsg);
}
// Attempt to get client object from repository (to check whether enabled and setup roles if enabled)
PdpClient pdpClient;
try {
pdpClient = pdpClientService.getClientById(client);
} catch (ResourceNotFoundException exception) {
logApiRequestEvent(request, token, null, jobId);
throw new UsernameNotFoundException("Client was not found");
}
// If client is null then continue throwing username not found
if (pdpClient == null) {
logApiRequestEvent(request, token, null, jobId);
throw new UsernameNotFoundException("Client was not found");
}
// Save organization
MDC.put(ORGANIZATION, pdpClient.getOrganization());
// If client is disabled for any reason do not proceed
if (!pdpClient.getEnabled()) {
log.error("Client {} is not enabled", pdpClient.getOrganization());
logApiRequestEvent(request, token, pdpClient.getOrganization(), jobId);
throw new ClientNotEnabledException("Client " + pdpClient.getOrganization() + " is not enabled");
}
// Otherwise setup roles and context
logApiRequestEvent(request, token, pdpClient.getOrganization(), jobId);
pdpClientService.setupClientAndRolesInSecurityContext(pdpClient, request);
// go to the next filter in the filter chain
chain.doFilter(request, response);
}
use of gov.cms.ab2d.common.service.ResourceNotFoundException in project ab2d by CMSgov.
the class JobHandler method handleMessage.
@Override
public void handleMessage(Message<?> message) {
// Worker is not able to be engaged in processing
if (workerService.getEngagement() == FeatureEngagement.NEUTRAL) {
return;
}
final List<Map<String, Object>> payload = (List<Map<String, Object>>) message.getPayload();
if (!payload.isEmpty()) {
log.info("iterating over {} submitted jobs to attempt to find one to start", payload.size());
}
for (Map<String, Object> submittedJob : payload) {
final String jobId = getJobId(submittedJob);
MDC.put(JOB_LOG, jobId);
final Lock lock = lockRegistry.obtain(jobId);
// in which case we do nothing and return.
if (lock.tryLock()) {
try {
// Attempt to start (mark an eob job as in progress) an eob job.
// A job may not be started if the workers are busy or if coverage metadata needs an update.
Job job = workerService.process(jobId);
if (job.getStatus() == JobStatus.IN_PROGRESS) {
log.info("{} job has been started so exiting loop", jobId);
break;
}
} catch (ResourceNotFoundException rnfe) {
throw new MessagingException("could not find job in database for " + jobId + " job uuid", rnfe);
} catch (Exception exception) {
throw new MessagingException("could not check coverage due to unexpected exception", exception);
} finally {
lock.unlock();
}
}
MDC.remove(JOB_LOG);
}
}
Aggregations