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