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;
}
}
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)));
}
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());
}
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"));
}
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;
}
Aggregations