Search in sources :

Example 1 with ResourceNotFoundException

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);
}
Also used : StartJobDTO(gov.cms.ab2d.common.dto.StartJobDTO) ResourceNotFoundException(gov.cms.ab2d.common.service.ResourceNotFoundException) JobPollResult(gov.cms.ab2d.common.dto.JobPollResult)

Example 2 with ResourceNotFoundException

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);
}
Also used : JobStatusChangeEvent(gov.cms.ab2d.eventlogger.events.JobStatusChangeEvent) InvalidJobStateTransition(gov.cms.ab2d.common.service.InvalidJobStateTransition) ResourceNotFoundException(gov.cms.ab2d.common.service.ResourceNotFoundException)

Example 3 with ResourceNotFoundException

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);
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) ResourceNotFoundException(gov.cms.ab2d.common.service.ResourceNotFoundException) PdpClient(gov.cms.ab2d.common.model.PdpClient) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) ServletException(javax.servlet.ServletException) ResourceNotFoundException(gov.cms.ab2d.common.service.ResourceNotFoundException) IOException(java.io.IOException) JwtVerificationException(com.okta.jwt.JwtVerificationException)

Example 4 with ResourceNotFoundException

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);
    }
}
Also used : MessagingException(org.springframework.messaging.MessagingException) List(java.util.List) Job(gov.cms.ab2d.common.model.Job) ResourceNotFoundException(gov.cms.ab2d.common.service.ResourceNotFoundException) Map(java.util.Map) MessagingException(org.springframework.messaging.MessagingException) ResourceNotFoundException(gov.cms.ab2d.common.service.ResourceNotFoundException) Lock(java.util.concurrent.locks.Lock)

Aggregations

ResourceNotFoundException (gov.cms.ab2d.common.service.ResourceNotFoundException)4 JwtVerificationException (com.okta.jwt.JwtVerificationException)1 JobPollResult (gov.cms.ab2d.common.dto.JobPollResult)1 StartJobDTO (gov.cms.ab2d.common.dto.StartJobDTO)1 Job (gov.cms.ab2d.common.model.Job)1 PdpClient (gov.cms.ab2d.common.model.PdpClient)1 InvalidJobStateTransition (gov.cms.ab2d.common.service.InvalidJobStateTransition)1 JobStatusChangeEvent (gov.cms.ab2d.eventlogger.events.JobStatusChangeEvent)1 IOException (java.io.IOException)1 List (java.util.List)1 Map (java.util.Map)1 Lock (java.util.concurrent.locks.Lock)1 ServletException (javax.servlet.ServletException)1 MessagingException (org.springframework.messaging.MessagingException)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1