Search in sources :

Example 1 with JobOutput

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

the class JobUtil method isJobDone.

/**
 * A job is done if the status is either CANCELLED or FAILED
 * If a job status is SUCCESSFUL, it is done if all files have been downloaded or they have expired
 *
 * @param job
 * @return
 */
public static boolean isJobDone(Job job) {
    try {
        // Job is still in progress
        if (job == null || job.getStatus() == null || job.getStatus() == JobStatus.IN_PROGRESS || job.getStatus() == JobStatus.SUBMITTED) {
            return false;
        }
        // Job has finished but was not successful
        if (job.getStatus() == JobStatus.CANCELLED || job.getStatus() == JobStatus.FAILED) {
            return true;
        }
        // Job has expired, it's done.
        if (job.getExpiresAt() != null && job.getExpiresAt().isBefore(OffsetDateTime.now())) {
            return true;
        }
        // If it hasn't expired, look to see if all files have been downloaded, if so, it's done
        List<JobOutput> jobOutputs = job.getJobOutputs();
        if (jobOutputs == null || jobOutputs.isEmpty()) {
            return false;
        }
        JobOutput aRemaining = jobOutputs.stream().filter(c -> c.getError() == null || !c.getError()).filter(c -> !c.getDownloaded()).findAny().orElse(null);
        return aRemaining == null;
    } catch (Exception ex) {
        // Logging should never break anything
        String jobId = job.getJobUuid();
        log.error("Unable to determine if job " + jobId + " is done", ex);
        return false;
    }
}
Also used : JobStatus(gov.cms.ab2d.common.model.JobStatus) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) Job(gov.cms.ab2d.common.model.Job) JobOutput(gov.cms.ab2d.common.model.JobOutput) JobOutput(gov.cms.ab2d.common.model.JobOutput)

Example 2 with JobOutput

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

the class JobPreProcessorUnitTest method testDownloadedAll.

@Test
void testDownloadedAll() {
    Job job = new Job();
    // Error file that was downloaded
    JobOutput jo1 = createJobOutput(job, true, true);
    // Error file that was not downloaded
    JobOutput jo2 = createJobOutput(job, true, false);
    // Data file that was downloaded
    JobOutput jo3 = createJobOutput(job, false, true);
    // Data file that was not downloaded - anything that includes this should return false
    JobOutput jo4 = createJobOutput(job, false, false);
    JobPreProcessorImpl impl = (JobPreProcessorImpl) cut;
    // Start with null or empty results
    assertTrue(impl.downloadedAll(null));
    assertTrue(impl.downloadedAll(Collections.emptyList()));
    // Try each individual
    assertTrue(impl.downloadedAll(List.of(jo1)));
    assertTrue(impl.downloadedAll(List.of(jo2)));
    assertTrue(impl.downloadedAll(List.of(jo3)));
    assertFalse(impl.downloadedAll(List.of(jo4)));
    // Try combinations
    assertTrue(impl.downloadedAll(List.of(jo1, jo2, jo3)));
    assertFalse(impl.downloadedAll(List.of(jo1, jo2, jo3, jo4)));
    assertFalse(impl.downloadedAll(List.of(jo1, jo4)));
    assertFalse(impl.downloadedAll(List.of(jo2, jo3, jo4)));
}
Also used : Job(gov.cms.ab2d.common.model.Job) JobOutput(gov.cms.ab2d.common.model.JobOutput) Test(org.junit.jupiter.api.Test)

Example 3 with JobOutput

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

the class JobProcessorIntegrationTest method when_beneHasNoEobs_notCounted.

@Test
@DisplayName("When bene has no eobs then do not count bene toward statistic")
void when_beneHasNoEobs_notCounted() {
    reset(mockBfdClient);
    OngoingStubbing<IBaseBundle> stubbing = when(mockBfdClient.requestEOBFromServer(eq(STU3), anyLong(), any()));
    stubbing = andThenAnswerEobs(stubbing, 0, 95);
    stubbing.thenReturn(BundleUtils.createBundle()).thenReturn(BundleUtils.createBundle()).thenReturn(BundleUtils.createBundle()).thenReturn(BundleUtils.createBundle()).thenReturn(BundleUtils.createBundle());
    var processedJob = cut.process(job.getJobUuid());
    assertEquals(JobStatus.SUCCESSFUL, processedJob.getStatus());
    assertEquals(COMPLETED_PERCENT, processedJob.getStatusMessage());
    assertNotNull(processedJob.getExpiresAt());
    assertNotNull(processedJob.getCompletedAt());
    List<LoggableEvent> beneSearchEvents = loggerEventRepository.load(ContractSearchEvent.class);
    assertEquals(1, beneSearchEvents.size());
    ContractSearchEvent event = (ContractSearchEvent) beneSearchEvents.get(0);
    assertEquals(JOB_UUID, event.getJobId());
    assertEquals(100, event.getBenesExpected());
    assertEquals(100, event.getBenesSearched());
    assertEquals(CONTRACT_NAME, event.getContractNumber());
    assertEquals(95, event.getBenesWithEobs());
    final List<JobOutput> jobOutputs = processedJob.getJobOutputs();
    assertFalse(jobOutputs.isEmpty());
}
Also used : LoggableEvent(gov.cms.ab2d.eventlogger.LoggableEvent) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) JobOutput(gov.cms.ab2d.common.model.JobOutput) ContractSearchEvent(gov.cms.ab2d.eventlogger.events.ContractSearchEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SpringIntegrationTest(org.springframework.integration.test.context.SpringIntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with JobOutput

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

the class ContractProcessorInvalidPatientTest method testInvalidBenes.

@Test
void testInvalidBenes() throws IOException {
    when(mapping.map(any(ContractDTO.class))).thenReturn(new ContractForCoverageDTO(contract.getContractNumber(), contract.getAttestedOn(), ContractForCoverageDTO.ContractType.NORMAL));
    org.hl7.fhir.dstu3.model.Bundle b1 = BundleUtils.createBundle(createBundleEntry("1"));
    org.hl7.fhir.dstu3.model.Bundle b2 = BundleUtils.createBundle(createBundleEntry("2"));
    org.hl7.fhir.dstu3.model.Bundle b4 = BundleUtils.createBundle(createBundleEntry("4"));
    when(bfdClient.requestEOBFromServer(eq(STU3), eq(1L), any())).thenReturn(b1);
    when(bfdClient.requestEOBFromServer(eq(STU3), eq(2L), any())).thenReturn(b2);
    when(bfdClient.requestEOBFromServer(eq(STU3), eq(3L), any())).thenReturn(b4);
    when(coverageDriver.numberOfBeneficiariesToProcess(any(Job.class), any(ContractDTO.class))).thenReturn(3);
    List<FilterOutByDate.DateRange> dates = singletonList(TestUtil.getOpenRange());
    List<CoverageSummary> summaries = List.of(new CoverageSummary(createIdentifierWithoutMbi(1L), null, dates), new CoverageSummary(createIdentifierWithoutMbi(2L), null, dates), new CoverageSummary(createIdentifierWithoutMbi(3L), null, dates));
    when(coverageDriver.pageCoverage(any(CoveragePagingRequest.class))).thenReturn(new CoveragePagingResult(summaries, null));
    List<JobOutput> outputs = cut.process(job);
    assertNotNull(outputs);
    assertEquals(1, outputs.size());
    String fileName1 = contractId + "_0001.ndjson";
    String output1 = outputs.get(0).getFilePath();
    assertTrue(output1.equalsIgnoreCase(fileName1));
    String actual1 = Files.readString(Path.of(tmpDirFolder.getAbsolutePath() + File.separator + job.getJobUuid() + "/" + output1));
    assertTrue(actual1.contains("Patient/1") && actual1.contains("Patient/2"));
    assertFalse(actual1.contains("Patient/3") || actual1.contains("Patient/4"));
}
Also used : CoverageSummary(gov.cms.ab2d.coverage.model.CoverageSummary) ContractForCoverageDTO(gov.cms.ab2d.coverage.model.ContractForCoverageDTO) CoveragePagingRequest(gov.cms.ab2d.coverage.model.CoveragePagingRequest) CoveragePagingResult(gov.cms.ab2d.coverage.model.CoveragePagingResult) ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) Job(gov.cms.ab2d.common.model.Job) JobOutput(gov.cms.ab2d.common.model.JobOutput) Test(org.junit.jupiter.api.Test)

Example 5 with JobOutput

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

the class JobUtilTest method createBasicJob.

private Job createBasicJob(JobStatus status, boolean[] outputsDownloaded, boolean isExpired) {
    Job job = new Job();
    job.setId(1L);
    job.setJobUuid("JOB");
    job.setStatus(status);
    job.setFhirVersion(STU3);
    OffsetDateTime expiresAt = OffsetDateTime.now();
    if (isExpired) {
        expiresAt = expiresAt.minus(1, ChronoUnit.HOURS);
    } else {
        expiresAt = expiresAt.plus(1, ChronoUnit.HOURS);
    }
    job.setExpiresAt(expiresAt);
    List<JobOutput> jobOutputs = new ArrayList<>();
    job.setJobOutputs(jobOutputs);
    if (outputsDownloaded != null) {
        for (int i = 0; i < outputsDownloaded.length; i++) {
            JobOutput output = new JobOutput();
            output.setDownloaded(outputsDownloaded[i]);
            jobOutputs.add(output);
        }
    }
    return job;
}
Also used : OffsetDateTime(java.time.OffsetDateTime) ArrayList(java.util.ArrayList) Job(gov.cms.ab2d.common.model.Job) JobOutput(gov.cms.ab2d.common.model.JobOutput)

Aggregations

JobOutput (gov.cms.ab2d.common.model.JobOutput)17 Job (gov.cms.ab2d.common.model.Job)9 Test (org.junit.jupiter.api.Test)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 ArrayList (java.util.ArrayList)4 OffsetDateTime (java.time.OffsetDateTime)3 ContractDTO (gov.cms.ab2d.common.dto.ContractDTO)2 PdpClient (gov.cms.ab2d.common.model.PdpClient)2 LoggableEvent (gov.cms.ab2d.eventlogger.LoggableEvent)2 ContractSearchEvent (gov.cms.ab2d.eventlogger.events.ContractSearchEvent)2 List (java.util.List)2 Slf4j (lombok.extern.slf4j.Slf4j)2 IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)2 DisplayName (org.junit.jupiter.api.DisplayName)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Trace (com.newrelic.api.agent.Trace)1 AggregatorCallable (gov.cms.ab2d.aggregator.AggregatorCallable)1 JobCompletedResponse (gov.cms.ab2d.api.controller.JobCompletedResponse)1 JobProcessingException (gov.cms.ab2d.api.controller.JobProcessingException)1 TooManyRequestsException (gov.cms.ab2d.api.controller.TooManyRequestsException)1