use of org.folio.rest.jaxrs.model.JobExecution in project mod-source-record-manager by folio-org.
the class JobExecutionServiceImpl method saveJobExecutions.
/**
* Performs save for received JobExecution entities using {@link JobExecutionDao}
*
* @param jobExecutions list on JobExecution entities
* @return future
*/
private Future<List<String>> saveJobExecutions(List<JobExecution> jobExecutions, String tenantId) {
List<Future<String>> savedJobExecutionFutures = new ArrayList<>();
for (JobExecution jobExecution : jobExecutions) {
Future<String> savedJobExecutionFuture = jobExecutionDao.save(jobExecution, tenantId);
savedJobExecutionFutures.add(savedJobExecutionFuture);
}
return GenericCompositeFuture.all(savedJobExecutionFutures).map(genericCompositeFuture -> genericCompositeFuture.result().list());
}
use of org.folio.rest.jaxrs.model.JobExecution in project mod-source-record-manager by folio-org.
the class JobExecutionServiceImpl method updateSnapshotStatus.
private Future<JobExecution> updateSnapshotStatus(JobExecution jobExecution, OkapiConnectionParams params) {
Promise<JobExecution> promise = Promise.promise();
Snapshot snapshot = new Snapshot().withJobExecutionId(jobExecution.getId()).withStatus(Snapshot.Status.fromValue(jobExecution.getStatus().name()));
SourceStorageSnapshotsClient client = new SourceStorageSnapshotsClient(params.getOkapiUrl(), params.getTenantId(), params.getToken());
try {
client.putSourceStorageSnapshotsByJobExecutionId(jobExecution.getId(), null, snapshot, response -> {
if (response.result().statusCode() == HttpStatus.HTTP_OK.toInt()) {
promise.complete(jobExecution);
} else {
jobExecutionDao.updateBlocking(jobExecution.getId(), jobExec -> {
Promise<JobExecution> jobExecutionPromise = Promise.promise();
jobExec.setErrorStatus(JobExecution.ErrorStatus.SNAPSHOT_UPDATE_ERROR);
jobExec.setStatus(JobExecution.Status.ERROR);
jobExec.setUiStatus(JobExecution.UiStatus.ERROR);
jobExec.setCompletedDate(new Date());
jobExecutionPromise.complete(jobExec);
return jobExecutionPromise.future();
}, params.getTenantId()).onComplete(jobExecutionUpdate -> {
String message = "Couldn't update snapshot status for jobExecution with id " + jobExecution.getId();
LOGGER.error(message);
promise.fail(message);
});
}
});
} catch (Exception e) {
LOGGER.error("Error during update for Snapshot with id {}", jobExecution.getId(), e);
promise.fail(e);
}
return promise.future();
}
use of org.folio.rest.jaxrs.model.JobExecution in project mod-source-record-manager by folio-org.
the class JobExecutionServiceImpl method prepareJobExecutionList.
/**
* Creates and returns list of JobExecution entities depending on received files.
* In a case if only one file passed, method returns list with one JobExecution entity
* signed by SINGLE_PARENT status.
* In a case if N files passed (N > 1), method returns list with JobExecution entities
* with one JobExecution entity signed by PARENT_MULTIPLE and N JobExecution entities signed by CHILD status.
*
* @param parentJobExecutionId id of the parent JobExecution entity
* @param files Representations of the Files user uploads
* @param userInfo The user creating JobExecution
* @param dto {@link InitJobExecutionsRqDto}
* @return list of JobExecution entities
*/
private List<JobExecution> prepareJobExecutionList(String parentJobExecutionId, List<File> files, UserInfo userInfo, InitJobExecutionsRqDto dto) {
String userId = dto.getUserId();
if (dto.getSourceType().equals(InitJobExecutionsRqDto.SourceType.ONLINE)) {
JobProfileInfo jobProfileInfo = dto.getJobProfileInfo();
if (jobProfileInfo != null && jobProfileInfo.getId().equals(DEFAULT_JOB_PROFILE_ID)) {
jobProfileInfo.withName(DEFAULT_JOB_PROFILE);
}
return Collections.singletonList(buildNewJobExecution(true, true, parentJobExecutionId, null, userId).withJobProfileInfo(jobProfileInfo).withRunBy(buildRunByFromUserInfo(userInfo)));
}
List<JobExecution> result = new ArrayList<>();
if (files.size() > 1) {
for (File file : files) {
result.add(buildNewJobExecution(false, false, parentJobExecutionId, file.getName(), userId));
}
result.add(buildNewJobExecution(true, false, parentJobExecutionId, null, userId));
} else {
File file = files.get(0);
result.add(buildNewJobExecution(true, true, parentJobExecutionId, file.getName(), userId));
}
result.forEach(job -> job.setRunBy(buildRunByFromUserInfo(userInfo)));
return result;
}
use of org.folio.rest.jaxrs.model.JobExecution in project mod-source-record-manager by folio-org.
the class JobExecutionServiceImpl method initializeJobExecutions.
@Override
public Future<InitJobExecutionsRsDto> initializeJobExecutions(InitJobExecutionsRqDto jobExecutionsRqDto, OkapiConnectionParams params) {
if (jobExecutionsRqDto.getSourceType().equals(InitJobExecutionsRqDto.SourceType.FILES) && jobExecutionsRqDto.getFiles().isEmpty()) {
String errorMessage = "Received files must not be empty";
LOGGER.error(errorMessage);
return Future.failedFuture(new BadRequestException(errorMessage));
} else {
String parentJobExecutionId = UUID.randomUUID().toString();
return lookupUser(jobExecutionsRqDto.getUserId(), params).compose(userInfo -> {
List<JobExecution> jobExecutions = prepareJobExecutionList(parentJobExecutionId, jobExecutionsRqDto.getFiles(), userInfo, jobExecutionsRqDto);
List<Snapshot> snapshots = prepareSnapshotList(jobExecutions);
Future<List<String>> savedJsonExecutionsFuture = saveJobExecutions(jobExecutions, params.getTenantId());
Future<List<String>> savedSnapshotsFuture = saveSnapshots(snapshots, params);
return GenericCompositeFuture.all(Arrays.asList(savedJsonExecutionsFuture, savedSnapshotsFuture)).map(new InitJobExecutionsRsDto().withParentJobExecutionId(parentJobExecutionId).withJobExecutions(jobExecutions));
});
}
}
use of org.folio.rest.jaxrs.model.JobExecution in project mod-source-record-manager by folio-org.
the class JobExecutionDaoImplTest method shouldNotDeleteIfJobHasNotSoftDeleted.
@Test
public void shouldNotDeleteIfJobHasNotSoftDeleted(TestContext context) {
/*
In this test we setup job execution that finishes 3 day ago, but this job has not been soft deleted.
Periodic job should not hard delete it.
*/
Async async = context.async();
Instant minusThreeDays = LocalDateTime.now().minus(3, ChronoUnit.DAYS).atOffset(ZoneOffset.UTC).toInstant();
Future<JobExecution> preparationFuture = prepareDataForDeletion(minusThreeDays);
preparationFuture.onComplete(ar -> {
JobExecution jobExecution = ar.result();
List<String> jobExecutionIds = List.of(jobExecution.getId());
jobExecutionDao.hardDeleteJobExecutions(2, TENANT_ID).onSuccess(resp -> checkDataExistenceAfterHardDeleting(1, jobExecutionIds, async));
});
}
Aggregations