Search in sources :

Example 41 with PdpClient

use of gov.cms.ab2d.common.model.PdpClient in project ab2d by CMSgov.

the class PdpClientServiceImpl method updateClientStatus.

private PdpClientDTO updateClientStatus(String contractNumber, boolean enabled) {
    PdpClient pdpClient = getClientByContract(contractNumber);
    pdpClient.setEnabled(enabled);
    PdpClient updatedPdpClient = pdpClientRepository.saveAndFlush(pdpClient);
    return mapping.getModelMapper().map(updatedPdpClient, PdpClientDTO.class);
}
Also used : PdpClient(gov.cms.ab2d.common.model.PdpClient)

Example 42 with PdpClient

use of gov.cms.ab2d.common.model.PdpClient 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 43 with PdpClient

use of gov.cms.ab2d.common.model.PdpClient 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

PdpClient (gov.cms.ab2d.common.model.PdpClient)43 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)11 BeforeEach (org.junit.jupiter.api.BeforeEach)8 Test (org.junit.jupiter.api.Test)7 Contract (gov.cms.ab2d.common.model.Contract)6 Job (gov.cms.ab2d.common.model.Job)5 ApiResponseEvent (gov.cms.ab2d.eventlogger.events.ApiResponseEvent)5 Role (gov.cms.ab2d.common.model.Role)4 PdpClientDTO (gov.cms.ab2d.common.dto.PdpClientDTO)3 LoggableEvent (gov.cms.ab2d.eventlogger.LoggableEvent)3 ApiRequestEvent (gov.cms.ab2d.eventlogger.events.ApiRequestEvent)3 ContractToContractCoverageMapping (gov.cms.ab2d.worker.config.ContractToContractCoverageMapping)3 ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)3 TooManyRequestsException (gov.cms.ab2d.api.controller.TooManyRequestsException)2 BFDClient (gov.cms.ab2d.bfd.client.BFDClient)2 ContractDTO (gov.cms.ab2d.common.dto.ContractDTO)2 StaleJob (gov.cms.ab2d.common.dto.StaleJob)2 StartJobDTO (gov.cms.ab2d.common.dto.StartJobDTO)2 JobOutput (gov.cms.ab2d.common.model.JobOutput)2 LogManager (gov.cms.ab2d.eventlogger.LogManager)2