Search in sources :

Example 1 with SourceStorageSnapshotsClient

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();
}
Also used : HttpException(io.vertx.ext.web.handler.HttpException) SourceStorageSnapshotsClient(org.folio.rest.client.SourceStorageSnapshotsClient) JobDuplicateUpdateException(org.folio.services.exceptions.JobDuplicateUpdateException) BadRequestException(javax.ws.rs.BadRequestException) HttpException(io.vertx.ext.web.handler.HttpException) NotFoundException(javax.ws.rs.NotFoundException)

Example 2 with SourceStorageSnapshotsClient

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();
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) DataImportProfilesClient(org.folio.rest.client.DataImportProfilesClient) Arrays(java.util.Arrays) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) UserInfo(org.folio.rest.jaxrs.model.UserInfo) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) JobDuplicateUpdateException(org.folio.services.exceptions.JobDuplicateUpdateException) JobExecutionSourceChunkDao(org.folio.dao.JobExecutionSourceChunkDao) JobExecution(org.folio.rest.jaxrs.model.JobExecution) JobProfileInfo(org.folio.rest.jaxrs.model.JobProfileInfo) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) ERROR(org.folio.rest.jaxrs.model.StatusDto.Status.ERROR) JsonObject(io.vertx.core.json.JsonObject) BadRequestException(javax.ws.rs.BadRequestException) HttpException(io.vertx.ext.web.handler.HttpException) GenericCompositeFuture(org.folio.okapi.common.GenericCompositeFuture) StatusDto(org.folio.rest.jaxrs.model.StatusDto) UUID(java.util.UUID) Future(io.vertx.core.Future) Try(org.folio.dataimport.util.Try) OkapiConnectionParams(org.folio.dataimport.util.OkapiConnectionParams) NotFoundException(javax.ws.rs.NotFoundException) String.format(java.lang.String.format) Objects(java.util.Objects) List(java.util.List) HTTP_OK(org.folio.HttpStatus.HTTP_OK) Logger(org.apache.logging.log4j.Logger) JobExecutionFilter(org.folio.dao.JobExecutionFilter) JobExecutionDtoCollection(org.folio.rest.jaxrs.model.JobExecutionDtoCollection) HTTP_CREATED(org.folio.HttpStatus.HTTP_CREATED) Optional(java.util.Optional) RestUtil(org.folio.dataimport.util.RestUtil) JobProfile(org.folio.rest.jaxrs.model.JobProfile) FilenameUtils(org.apache.commons.io.FilenameUtils) Progress(org.folio.rest.jaxrs.model.Progress) JobExecutionDao(org.folio.dao.JobExecutionDao) CANCELLED(org.folio.rest.jaxrs.model.StatusDto.Status.CANCELLED) DeleteJobExecutionsResp(org.folio.rest.jaxrs.model.DeleteJobExecutionsResp) ArrayList(java.util.ArrayList) SourceStorageSnapshotsClient(org.folio.rest.client.SourceStorageSnapshotsClient) Service(org.springframework.stereotype.Service) InitJobExecutionsRqDto(org.folio.rest.jaxrs.model.InitJobExecutionsRqDto) Promise(io.vertx.core.Promise) COMMITTED(org.folio.rest.jaxrs.model.JobExecution.Status.COMMITTED) RunBy(org.folio.rest.jaxrs.model.RunBy) File(org.folio.rest.jaxrs.model.File) SortField(org.folio.dao.util.SortField) HttpMethod(io.vertx.core.http.HttpMethod) JobExecutionUserInfoCollection(org.folio.rest.jaxrs.model.JobExecutionUserInfoCollection) JobProfileInfoCollection(org.folio.rest.jaxrs.model.JobProfileInfoCollection) HttpStatus(org.folio.HttpStatus) PROFILE_SNAPSHOT_CREATING_ERROR(org.folio.rest.jaxrs.model.StatusDto.ErrorStatus.PROFILE_SNAPSHOT_CREATING_ERROR) LogManager(org.apache.logging.log4j.LogManager) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Collections(java.util.Collections) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Promise(io.vertx.core.Promise) SourceStorageSnapshotsClient(org.folio.rest.client.SourceStorageSnapshotsClient) Date(java.util.Date) JobDuplicateUpdateException(org.folio.services.exceptions.JobDuplicateUpdateException) BadRequestException(javax.ws.rs.BadRequestException) HttpException(io.vertx.ext.web.handler.HttpException) NotFoundException(javax.ws.rs.NotFoundException)

Example 3 with SourceStorageSnapshotsClient

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();
}
Also used : HttpException(io.vertx.ext.web.handler.HttpException) SourceStorageSnapshotsClient(org.folio.rest.client.SourceStorageSnapshotsClient) JobDuplicateUpdateException(org.folio.services.exceptions.JobDuplicateUpdateException) BadRequestException(javax.ws.rs.BadRequestException) HttpException(io.vertx.ext.web.handler.HttpException) NotFoundException(javax.ws.rs.NotFoundException)

Aggregations

HttpException (io.vertx.ext.web.handler.HttpException)3 BadRequestException (javax.ws.rs.BadRequestException)3 NotFoundException (javax.ws.rs.NotFoundException)3 SourceStorageSnapshotsClient (org.folio.rest.client.SourceStorageSnapshotsClient)3 JobDuplicateUpdateException (org.folio.services.exceptions.JobDuplicateUpdateException)3 Future (io.vertx.core.Future)1 Promise (io.vertx.core.Promise)1 HttpMethod (io.vertx.core.http.HttpMethod)1 JsonObject (io.vertx.core.json.JsonObject)1 String.format (java.lang.String.format)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Date (java.util.Date)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 FilenameUtils (org.apache.commons.io.FilenameUtils)1 LogManager (org.apache.logging.log4j.LogManager)1