Search in sources :

Example 1 with TooManyRequestsException

use of gov.cms.ab2d.api.controller.TooManyRequestsException in project ab2d by CMSgov.

the class StatusCommon method doStatus.

public ResponseEntity doStatus(String jobUuid, HttpServletRequest request, String apiPrefix) {
    MDC.put(JOB_LOG, jobUuid);
    log.info("Request submitted to get job status");
    PdpClient pdpClient = pdpClientService.getCurrentClient();
    JobPollResult jobPollResult;
    try {
        jobPollResult = jobClient.poll(pdpClient.isAdmin(), jobUuid, pdpClient.getOrganization(), retryAfterDelay);
    } catch (TooFrequentInvocations tfi) {
        log.error("Client was polling too frequently");
        throw new TooManyRequestsException("You are polling too frequently");
    }
    HttpHeaders responseHeaders = new HttpHeaders();
    switch(jobPollResult.getStatus()) {
        case SUCCESSFUL:
            return getSuccessResponse(jobPollResult, jobUuid, request, apiPrefix);
        case SUBMITTED:
        case IN_PROGRESS:
            responseHeaders.add(X_PROG, jobPollResult.getProgress() + "% complete");
            responseHeaders.add(RETRY_AFTER, Integer.toString(retryAfterDelay));
            eventLogger.log(new ApiResponseEvent(MDC.get(ORGANIZATION), jobUuid, HttpStatus.ACCEPTED, "Job in progress", jobPollResult.getProgress() + "% complete", (String) request.getAttribute(REQUEST_ID)));
            return new ResponseEntity<>(null, responseHeaders, HttpStatus.ACCEPTED);
        case FAILED:
            throwFailedResponse("Job failed while processing");
            break;
        default:
            throwFailedResponse("Unknown status of job");
    }
    throw new JobProcessingException("Unknown error");
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) TooManyRequestsException(gov.cms.ab2d.api.controller.TooManyRequestsException) ResponseEntity(org.springframework.http.ResponseEntity) JobPollResult(gov.cms.ab2d.common.dto.JobPollResult) PdpClient(gov.cms.ab2d.common.model.PdpClient) ApiResponseEvent(gov.cms.ab2d.eventlogger.events.ApiResponseEvent) JobProcessingException(gov.cms.ab2d.api.controller.JobProcessingException) TooFrequentInvocations(gov.cms.ab2d.common.model.TooFrequentInvocations)

Example 2 with TooManyRequestsException

use of gov.cms.ab2d.api.controller.TooManyRequestsException in project ab2d by CMSgov.

the class ApiCommon method checkIfCurrentClientCanAddJob.

public void checkIfCurrentClientCanAddJob() {
    PdpClient pdpClient = pdpClientService.getCurrentClient();
    String organization = pdpClient.getOrganization();
    if (jobClient.activeJobs(organization) >= pdpClient.getMaxParallelJobs()) {
        String errorMsg = "You already have active export requests in progress. Please wait until they complete before submitting a new one.";
        log.error(errorMsg);
        throw new TooManyRequestsException(errorMsg, jobClient.getActiveJobIds(organization));
    }
}
Also used : TooManyRequestsException(gov.cms.ab2d.api.controller.TooManyRequestsException) PdpClient(gov.cms.ab2d.common.model.PdpClient)

Aggregations

TooManyRequestsException (gov.cms.ab2d.api.controller.TooManyRequestsException)2 PdpClient (gov.cms.ab2d.common.model.PdpClient)2 JobProcessingException (gov.cms.ab2d.api.controller.JobProcessingException)1 JobPollResult (gov.cms.ab2d.common.dto.JobPollResult)1 TooFrequentInvocations (gov.cms.ab2d.common.model.TooFrequentInvocations)1 ApiResponseEvent (gov.cms.ab2d.eventlogger.events.ApiResponseEvent)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ResponseEntity (org.springframework.http.ResponseEntity)1