Search in sources :

Example 11 with LoggableEvent

use of gov.cms.ab2d.eventlogger.LoggableEvent in project ab2d by CMSgov.

the class FileDeletionServiceTest method deleteCompletedAndExpiredJobFiles.

@DisplayName("Delete job files for successful jobs after they have expired")
@Test
void deleteCompletedAndExpiredJobFiles() throws IOException, URISyntaxException {
    Path jobPath = Paths.get(efsMount, job.getJobUuid());
    File jobDir = new File(jobPath.toString());
    if (!jobDir.exists())
        jobDir.mkdirs();
    pathsToDelete.add(jobPath);
    Path destinationJobConnection = Paths.get(jobPath.toString(), "S0000_0001.ndjson");
    Path sourceJobConnection = getSourcePath(TEST_FILE);
    Files.copy(sourceJobConnection, destinationJobConnection, StandardCopyOption.REPLACE_EXISTING);
    changeFileCreationDate(destinationJobConnection);
    fileDeletionService.deleteFiles();
    assertTrue(Files.notExists(jobPath));
    assertTrue(Files.notExists(destinationJobConnection));
    List<LoggableEvent> fileEvents = loggerEventRepository.load(FileEvent.class);
    FileEvent e1 = (FileEvent) fileEvents.get(0);
    assertTrue(e1.getFileName().equalsIgnoreCase(destinationJobConnection.toString()));
    checkNoOtherEventsLogged();
}
Also used : Path(java.nio.file.Path) LoggableEvent(gov.cms.ab2d.eventlogger.LoggableEvent) FileEvent(gov.cms.ab2d.eventlogger.events.FileEvent) File(java.io.File) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 12 with LoggableEvent

use of gov.cms.ab2d.eventlogger.LoggableEvent in project ab2d by CMSgov.

the class FileDeletionServiceTest method deleteFailedAndExpiredJobFiles.

@DisplayName("Delete job files for failed jobs immediately")
@Test
void deleteFailedAndExpiredJobFiles() throws IOException, URISyntaxException {
    Path jobPath = Paths.get(efsMount, jobFailed.getJobUuid());
    File jobDir = new File(jobPath.toString());
    if (!jobDir.exists())
        jobDir.mkdirs();
    pathsToDelete.add(jobPath);
    Path destinationJobConnection = Paths.get(jobPath.toString(), "S0000_0001.ndjson");
    Path sourceJobConnection = getSourcePath(TEST_FILE);
    Files.copy(sourceJobConnection, destinationJobConnection, StandardCopyOption.REPLACE_EXISTING);
    changeFileCreationDate(destinationJobConnection);
    fileDeletionService.deleteFiles();
    assertTrue(Files.notExists(jobPath));
    assertTrue(Files.notExists(destinationJobConnection));
    List<LoggableEvent> fileEvents = loggerEventRepository.load(FileEvent.class);
    FileEvent e1 = (FileEvent) fileEvents.get(0);
    assertTrue(e1.getFileName().equalsIgnoreCase(destinationJobConnection.toString()));
    checkNoOtherEventsLogged();
}
Also used : Path(java.nio.file.Path) LoggableEvent(gov.cms.ab2d.eventlogger.LoggableEvent) FileEvent(gov.cms.ab2d.eventlogger.events.FileEvent) File(java.io.File) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 13 with LoggableEvent

use of gov.cms.ab2d.eventlogger.LoggableEvent in project ab2d by CMSgov.

the class FileDeletionServiceTest method deleteNestedNdjson.

@DisplayName("Delete nested ndjson file not attached to a job")
@Test
void deleteNestedNdjson() throws IOException, URISyntaxException {
    final Path dirPath = Paths.get(efsMount, TEST_DIRECTORY);
    File dir = new File(dirPath.toString());
    if (!dir.exists())
        dir.mkdirs();
    pathsToDelete.add(dirPath);
    // Not connected to a job
    Path nestedFileDestination = Paths.get(efsMount, TEST_FILE_NESTED);
    Path nestedFileSource = getSourcePath(TEST_FILE_NESTED);
    Files.copy(nestedFileSource, nestedFileDestination, StandardCopyOption.REPLACE_EXISTING);
    changeFileCreationDate(nestedFileDestination);
    fileDeletionService.deleteFiles();
    assertTrue(Files.exists(nestedFileDestination));
    assertTrue(Files.exists(dirPath));
    List<LoggableEvent> fileEvents = loggerEventRepository.load(FileEvent.class);
    assertEquals(0, fileEvents.size());
    checkNoOtherEventsLogged();
}
Also used : Path(java.nio.file.Path) LoggableEvent(gov.cms.ab2d.eventlogger.LoggableEvent) File(java.io.File) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 14 with LoggableEvent

use of gov.cms.ab2d.eventlogger.LoggableEvent in project ab2d by CMSgov.

the class FileDeletionServiceTest method deleteCancelledAndExpiredJobFiles.

@DisplayName("Delete job files for cancelled jobs immediately")
@Test
void deleteCancelledAndExpiredJobFiles() throws IOException, URISyntaxException {
    Path jobPath = Paths.get(efsMount, jobCancelled.getJobUuid());
    File jobDir = new File(jobPath.toString());
    if (!jobDir.exists())
        jobDir.mkdirs();
    pathsToDelete.add(jobPath);
    Path destinationJobConnection = Paths.get(jobPath.toString(), "S0000_0001.ndjson");
    Path sourceJobConnection = getSourcePath(TEST_FILE);
    Files.copy(sourceJobConnection, destinationJobConnection, StandardCopyOption.REPLACE_EXISTING);
    changeFileCreationDate(destinationJobConnection);
    fileDeletionService.deleteFiles();
    assertTrue(Files.notExists(jobPath));
    assertTrue(Files.notExists(destinationJobConnection));
    List<LoggableEvent> fileEvents = loggerEventRepository.load(FileEvent.class);
    FileEvent e1 = (FileEvent) fileEvents.get(0);
    assertTrue(e1.getFileName().equalsIgnoreCase(destinationJobConnection.toString()));
    checkNoOtherEventsLogged();
}
Also used : Path(java.nio.file.Path) LoggableEvent(gov.cms.ab2d.eventlogger.LoggableEvent) FileEvent(gov.cms.ab2d.eventlogger.events.FileEvent) File(java.io.File) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 15 with LoggableEvent

use of gov.cms.ab2d.eventlogger.LoggableEvent in project ab2d by CMSgov.

the class LoggerEventSummary method getSummary.

public JobSummaryEvent getSummary(String jobId) {
    try {
        if (jobId == null || jobId.isEmpty()) {
            log.error("Can't do a job summary for an empty job id");
            return new JobSummaryEvent();
        }
        List<LoggableEvent> jobChangeEvents = loggerEventRepository.load(JobStatusChangeEvent.class, jobId);
        List<LoggableEvent> fileEvents = loggerEventRepository.load(FileEvent.class, jobId);
        List<LoggableEvent> downloadEvents = loggerEventRepository.load(ApiResponseEvent.class, jobId).stream().filter(e -> "File Download".equalsIgnoreCase(((ApiResponseEvent) e).getResponseString())).collect(Collectors.toList());
        List<LoggableEvent> contractSearchData = loggerEventRepository.load(ContractSearchEvent.class, jobId);
        List<LoggableEvent> allEvents = new ArrayList<>();
        allEvents.addAll(jobChangeEvents);
        allEvents.addAll(fileEvents);
        allEvents.addAll(downloadEvents);
        allEvents.addAll(contractSearchData);
        String firstUserFound = allEvents.stream().map(LoggableEvent::getOrganization).filter(Objects::nonNull).findFirst().orElse(null);
        JobSummaryEvent jobSummaryEvent = new JobSummaryEvent();
        jobSummaryEvent.setJobId(jobId);
        jobSummaryEvent.setOrganization(firstUserFound);
        jobSummaryEvent.setSubmittedTime(getTime(jobChangeEvents, "SUBMITTED"));
        jobSummaryEvent.setInProgressTime(getTime(jobChangeEvents, "IN_PROGRESS"));
        jobSummaryEvent.setSuccessfulTime(getTime(jobChangeEvents, "SUCCESSFUL"));
        jobSummaryEvent.setCancelledTime(getTime(jobChangeEvents, "CANCELLED"));
        jobSummaryEvent.setFailedTime(getTime(jobChangeEvents, "FAILED"));
        jobSummaryEvent.setNumFilesCreated(getUniqueNumFilesOfType(fileEvents, FileEvent.FileStatus.CLOSE));
        jobSummaryEvent.setNumFilesDeleted(getUniqueNumFilesOfType(fileEvents, FileEvent.FileStatus.DELETE));
        jobSummaryEvent.setNumFilesDownloaded(downloadEvents.size());
        if (!contractSearchData.isEmpty()) {
            List<ContractSearchEvent> searches = new ArrayList<>();
            for (LoggableEvent event : contractSearchData) {
                searches.add((ContractSearchEvent) event);
            }
            jobSummaryEvent.setSuccessfullySearched(searches.stream().map(ContractSearchEvent::getBenesSearched).reduce(0, Integer::sum));
            jobSummaryEvent.setErrorSearched(searches.stream().map(ContractSearchEvent::getBenesErrored).reduce(0, Integer::sum));
            jobSummaryEvent.setTotalNum(searches.stream().map(ContractSearchEvent::getBenesExpected).reduce(0, Integer::sum));
        }
        return jobSummaryEvent;
    } catch (Exception ex) {
        // Logging shouldn ever break anything
        log.error("Error creating summary object", ex);
    }
    return null;
}
Also used : JobSummaryEvent(gov.cms.ab2d.eventlogger.events.JobSummaryEvent) FileEvent(gov.cms.ab2d.eventlogger.events.FileEvent) ApiResponseEvent(gov.cms.ab2d.eventlogger.events.ApiResponseEvent) ContractSearchEvent(gov.cms.ab2d.eventlogger.events.ContractSearchEvent) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) LoggableEvent(gov.cms.ab2d.eventlogger.LoggableEvent) OffsetDateTime(java.time.OffsetDateTime) Service(org.springframework.stereotype.Service) JobStatusChangeEvent(gov.cms.ab2d.eventlogger.events.JobStatusChangeEvent) LoggableEvent(gov.cms.ab2d.eventlogger.LoggableEvent) ArrayList(java.util.ArrayList) Objects(java.util.Objects) JobSummaryEvent(gov.cms.ab2d.eventlogger.events.JobSummaryEvent) ApiResponseEvent(gov.cms.ab2d.eventlogger.events.ApiResponseEvent) ContractSearchEvent(gov.cms.ab2d.eventlogger.events.ContractSearchEvent)

Aggregations

LoggableEvent (gov.cms.ab2d.eventlogger.LoggableEvent)36 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)33 Test (org.junit.jupiter.api.Test)22 OffsetDateTime (java.time.OffsetDateTime)11 DisplayName (org.junit.jupiter.api.DisplayName)11 File (java.io.File)8 Path (java.nio.file.Path)7 ApiResponseEvent (gov.cms.ab2d.eventlogger.events.ApiResponseEvent)5 FileEvent (gov.cms.ab2d.eventlogger.events.FileEvent)5 JobStatusChangeEvent (gov.cms.ab2d.eventlogger.events.JobStatusChangeEvent)5 ApiRequestEvent (gov.cms.ab2d.eventlogger.events.ApiRequestEvent)4 ArrayList (java.util.ArrayList)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 SpringIntegrationTest (org.springframework.integration.test.context.SpringIntegrationTest)4 MvcResult (org.springframework.test.web.servlet.MvcResult)4 ContractDTO (gov.cms.ab2d.common.dto.ContractDTO)3 Job (gov.cms.ab2d.common.model.Job)3 PdpClient (gov.cms.ab2d.common.model.PdpClient)3 ContractSearchEvent (gov.cms.ab2d.eventlogger.events.ContractSearchEvent)3 IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)3