use of org.folio.rest.jaxrs.model.JobExecutionProgress in project mod-source-record-manager by folio-org.
the class JobExecutionProgressDaoImpl method initializeJobExecutionProgress.
@Override
public Future<JobExecutionProgress> initializeJobExecutionProgress(String jobExecutionId, Integer totalRecords, String tenantId) {
Promise<JobExecutionProgress> promise = Promise.promise();
Promise<SQLConnection> tx = Promise.promise();
PostgresClient pgClient = pgClientFactory.createInstance(tenantId);
getSelectResult(tx, pgClient, jobExecutionId, tenantId).compose(selectResult -> {
JobExecutionProgress progress = new JobExecutionProgress().withJobExecutionId(jobExecutionId).withTotal(totalRecords);
Optional<JobExecutionProgress> optionalJobExecutionProgress = mapResultSetToOptionalJobExecutionProgress(selectResult);
return optionalJobExecutionProgress.isEmpty() ? save(progress, tenantId).map(progress) : Future.succeededFuture(optionalJobExecutionProgress.get());
}).onComplete(saveAr -> {
if (saveAr.succeeded()) {
pgClient.endTx(tx.future(), endTx -> promise.complete(saveAr.result()));
} else {
if (ValidationHelper.isDuplicate(saveAr.cause().getMessage())) {
pgClient.rollbackTx(tx.future(), r -> promise.complete());
return;
}
LOGGER.error(FAILED_INITIALIZATION_MESSAGE, jobExecutionId, saveAr.cause());
pgClient.rollbackTx(tx.future(), r -> promise.fail(saveAr.cause()));
}
});
return promise.future();
}
use of org.folio.rest.jaxrs.model.JobExecutionProgress in project mod-source-record-manager by folio-org.
the class JobExecutionDaoImplTest method prepareDataForDeletion.
private Future<JobExecution> prepareDataForDeletion(Instant completedDate) {
InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
List<JobExecution> createdJobExecutions = response.getJobExecutions();
assertThat(createdJobExecutions.size(), Matchers.is(1));
JobExecution jobExec = createdJobExecutions.get(0);
jobExec.withCompletedDate(Date.from(completedDate));
JobExecutionProgress jobExecutionProgress = new JobExecutionProgress().withJobExecutionId(jobExec.getId()).withTotal(1).withCurrentlySucceeded(1).withCurrentlyFailed(0);
JobMonitoring jobMonitoring = new JobMonitoring().withId(UUID.randomUUID().toString()).withJobExecutionId(jobExec.getId()).withNotificationSent(true).withLastEventTimestamp(new Date());
JournalRecord journalRecord = new JournalRecord().withJobExecutionId(jobExec.getId()).withSourceRecordOrder(0).withSourceId(UUID.randomUUID().toString()).withEntityType(JournalRecord.EntityType.MARC_BIBLIOGRAPHIC).withEntityId(UUID.randomUUID().toString()).withActionType(CREATE).withActionDate(new Date()).withActionStatus(COMPLETED);
JobExecutionSourceChunk jobExecutionSourceChunk = new JobExecutionSourceChunk().withId("67dfac11-1caf-4470-9ad1-d533f6360bdd").withJobExecutionId(jobExec.getId()).withLast(false).withState(JobExecutionSourceChunk.State.COMPLETED).withChunkSize(10).withProcessedAmount(42);
return jobExecutionDao.updateJobExecution(jobExec, TENANT_ID).compose(jobExecution -> {
Future<RowSet<Row>> saveProgressFuture = jobExecutionProgressDao.save(jobExecutionProgress, TENANT_ID);
Future<String> saveMonitoringFuture = jobMonitoringDao.save(jobMonitoring, TENANT_ID);
Future<String> saveJournalFuture = journalRecordDao.save(journalRecord, TENANT_ID);
Future<String> saveSourceChunkFuture = jobExecutionSourceChunkDao.save(jobExecutionSourceChunk, TENANT_ID);
return CompositeFuture.all(saveProgressFuture, saveMonitoringFuture, saveJournalFuture, saveSourceChunkFuture).compose(ar -> Future.succeededFuture(jobExecution));
});
}
use of org.folio.rest.jaxrs.model.JobExecutionProgress in project mod-source-record-manager by folio-org.
the class RecordProcessedEventHandlingServiceImplTest method shouldIncrementCurrentlySucceededAndUpdateProgressOnHandleEvent.
@Test
public void shouldIncrementCurrentlySucceededAndUpdateProgressOnHandleEvent(TestContext context) {
// given
Async async = context.async();
HashMap<String, String> payloadContext = new HashMap<>();
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DataImportEventTypes.DI_COMPLETED.value()).withContext(payloadContext);
Future<Boolean> future = jobExecutionService.initializeJobExecutions(initJobExecutionsRqDto, params).compose(initJobExecutionsRsDto -> jobExecutionService.setJobProfileToJobExecution(initJobExecutionsRsDto.getParentJobExecutionId(), jobProfileInfo, params)).compose(jobExecution -> {
dataImportEventPayload.setJobExecutionId(jobExecution.getId());
return chunkProcessingService.processChunk(rawRecordsDto, jobExecution.getId(), params);
});
// when
Future<JobExecutionProgress> jobFuture = future.compose(ar -> recordProcessedEventHandlingService.handle(Json.encode(dataImportEventPayload), params)).compose(ar -> jobExecutionProgressService.getByJobExecutionId(dataImportEventPayload.getJobExecutionId(), TENANT_ID));
// then
jobFuture.onComplete(ar -> {
context.assertTrue(ar.succeeded());
JobExecutionProgress updatedProgress = ar.result();
context.assertEquals(1, updatedProgress.getCurrentlySucceeded());
context.assertEquals(0, updatedProgress.getCurrentlyFailed());
context.assertEquals(rawRecordsDto.getRecordsMetadata().getTotal(), updatedProgress.getTotal());
jobMonitoringService.getByJobExecutionId(updatedProgress.getJobExecutionId(), params.getTenantId()).onSuccess(optionalJobMonitoring -> {
context.assertTrue(optionalJobMonitoring.isEmpty());
async.complete();
});
async.complete();
});
}
use of org.folio.rest.jaxrs.model.JobExecutionProgress in project mod-source-record-manager by folio-org.
the class JobExecutionProgressServiceImplTest method shouldNotReturnFailedFutureWhenJobExecutionIdDuplicates.
@Test
public void shouldNotReturnFailedFutureWhenJobExecutionIdDuplicates(TestContext context) {
Async async = context.async();
int expectedTotalRecords = 62;
Future<CompositeFuture> future = jobExecutionService.initializeJobExecutions(initJobExecutionsRqDto, params).compose(initJobExecutionsRsDto -> {
Future<JobExecutionProgress> future1 = jobExecutionProgressService.initializeJobExecutionProgress(initJobExecutionsRsDto.getParentJobExecutionId(), expectedTotalRecords, TENANT_ID);
Future<JobExecutionProgress> future2 = jobExecutionProgressService.initializeJobExecutionProgress(initJobExecutionsRsDto.getParentJobExecutionId(), expectedTotalRecords, TENANT_ID);
return GenericCompositeFuture.join(Arrays.asList(future1, future2));
});
future.onComplete(ar -> {
context.assertTrue(ar.succeeded());
async.complete();
});
}
use of org.folio.rest.jaxrs.model.JobExecutionProgress in project mod-source-record-manager by folio-org.
the class JobExecutionProgressServiceImplTest method shouldUpdateProgress.
@Test
public void shouldUpdateProgress(TestContext context) {
Async async = context.async();
int expectedTotalRecords = 42;
int expectedSucceededRecords = 40;
int expectedFailedRecords = 2;
Future<JobExecutionProgress> future = jobExecutionService.initializeJobExecutions(initJobExecutionsRqDto, params).compose(initJobExecutionsRsDto -> jobExecutionService.initializeJobExecutions(initJobExecutionsRqDto, params)).compose(initJobExecutionsRsDto -> jobExecutionProgressService.initializeJobExecutionProgress(initJobExecutionsRsDto.getParentJobExecutionId(), expectedTotalRecords, TENANT_ID)).compose(progress -> jobExecutionProgressService.updateJobExecutionProgress(progress.getJobExecutionId(), progressToUpdate -> progressToUpdate.withCurrentlySucceeded(expectedSucceededRecords).withCurrentlyFailed(expectedFailedRecords), TENANT_ID));
future.onComplete(ar -> {
context.assertTrue(ar.succeeded());
JobExecutionProgress progress = ar.result();
context.assertEquals(expectedTotalRecords, progress.getTotal());
context.assertEquals(expectedSucceededRecords, progress.getCurrentlySucceeded());
context.assertEquals(expectedFailedRecords, progress.getCurrentlyFailed());
jobMonitoringService.getByJobExecutionId(progress.getJobExecutionId(), params.getTenantId()).onSuccess(optionalJobMonitoring -> {
context.assertTrue(optionalJobMonitoring.isPresent());
JobMonitoring jobMonitoring = optionalJobMonitoring.get();
context.assertNotNull(jobMonitoring.getId());
context.assertEquals(progress.getJobExecutionId(), jobMonitoring.getJobExecutionId());
context.assertNotNull(jobMonitoring.getLastEventTimestamp());
context.assertFalse(jobMonitoring.getNotificationSent());
async.complete();
});
});
}
Aggregations