use of org.folio.rest.client.SourceStorageSnapshotsClient in project mod-source-record-manager by folio-org.
the class JobExecutionServiceImpl method deleteRecordsFromSRS.
private Future<Boolean> deleteRecordsFromSRS(String jobExecutionId, OkapiConnectionParams params) {
Promise<Boolean> promise = Promise.promise();
SourceStorageSnapshotsClient client = new SourceStorageSnapshotsClient(params.getOkapiUrl(), params.getTenantId(), params.getToken());
try {
client.deleteSourceStorageSnapshotsByJobExecutionId(jobExecutionId, null, response -> {
if (response.result().statusCode() == HttpStatus.HTTP_NO_CONTENT.toInt()) {
promise.complete(true);
} else {
String message = format("Records from SRS were not deleted for JobExecution %s", jobExecutionId);
LOGGER.error(message);
promise.fail(new HttpException(response.result().statusCode(), message));
}
});
} catch (Exception e) {
LOGGER.error("Error deleting records from SRS for Job Execution {}", jobExecutionId, e);
promise.fail(e);
}
return promise.future();
}
use of org.folio.rest.client.SourceStorageSnapshotsClient 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.client.SourceStorageSnapshotsClient in project mod-source-record-manager by folio-org.
the class JobExecutionServiceImpl method postSnapshot.
/**
* Performs post request with given Snapshot entity.
*
* @param snapshot Snapshot entity
* @param params object-wrapper with params necessary to connect to OKAPI
* @return future
*/
private Future<String> postSnapshot(Snapshot snapshot, OkapiConnectionParams params) {
Promise<String> promise = Promise.promise();
SourceStorageSnapshotsClient client = new SourceStorageSnapshotsClient(params.getOkapiUrl(), params.getTenantId(), params.getToken());
try {
client.postSourceStorageSnapshots(null, snapshot, response -> {
if (response.result().statusCode() != HttpStatus.HTTP_CREATED.toInt()) {
LOGGER.error("Error during post for new Snapshot. Status message: {}", response.result().statusMessage());
promise.fail(new HttpException(response.result().statusCode(), "Error during post for new Snapshot."));
} else {
promise.complete(response.result().bodyAsString());
}
});
} catch (Exception e) {
LOGGER.error("Error during post for new Snapshot", e);
promise.fail(e);
}
return promise.future();
}
Aggregations