Search in sources :

Example 1 with Progress

use of org.folio.rest.jaxrs.model.Progress in project mod-source-record-manager by folio-org.

the class JobExecutionDaoImpl method mapRowToProgress.

private Progress mapRowToProgress(Row row) {
    Integer processedCount = row.getInteger(CURRENTLY_PROCESSED_FIELD);
    Integer total = row.getInteger(TOTAL_FIELD);
    if (processedCount == null) {
        processedCount = row.getInteger(PROGRESS_CURRENT_FIELD);
    }
    if (total == null) {
        total = row.getInteger(PROGRESS_TOTAL_FIELD);
    }
    return new Progress().withJobExecutionId(row.getValue(ID_FIELD).toString()).withCurrent(processedCount).withTotal(total);
}
Also used : Progress(org.folio.rest.jaxrs.model.Progress)

Example 2 with Progress

use of org.folio.rest.jaxrs.model.Progress in project mod-source-record-manager by folio-org.

the class MetadataProviderJobExecutionAPITest method shouldReturnSortedJobExecutionsByTotalProgressOnGet.

@Test
public void shouldReturnSortedJobExecutionsByTotalProgressOnGet() {
    List<JobExecution> createdJobExecution = constructAndPostInitJobExecutionRqDto(4).getJobExecutions();
    List<JobExecution> childJobsToUpdate = createdJobExecution.stream().filter(jobExecution -> jobExecution.getSubordinationType().equals(CHILD)).collect(Collectors.toList());
    for (int i = 0; i < childJobsToUpdate.size(); i++) {
        putJobExecution(createdJobExecution.get(i).withProgress(new Progress().withTotal(i * 5)));
    }
    // We do not expect to get JobExecution with subordinationType=PARENT_MULTIPLE
    int expectedJobExecutionsNumber = childJobsToUpdate.size();
    JobExecutionDtoCollection jobExecutionCollection = RestAssured.given().spec(spec).when().queryParam("sortBy", "progress_total,desc").get(GET_JOB_EXECUTIONS_PATH).then().statusCode(HttpStatus.SC_OK).extract().response().body().as(JobExecutionDtoCollection.class);
    List<JobExecutionDto> jobExecutions = jobExecutionCollection.getJobExecutions();
    Assert.assertEquals(expectedJobExecutionsNumber, jobExecutions.size());
    assertThat(jobExecutions.get(0).getProgress().getTotal(), greaterThan(jobExecutions.get(1).getProgress().getTotal()));
    assertThat(jobExecutions.get(1).getProgress().getTotal(), greaterThan(jobExecutions.get(2).getProgress().getTotal()));
    assertThat(jobExecutions.get(2).getProgress().getTotal(), greaterThan(jobExecutions.get(3).getProgress().getTotal()));
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) TestContext(io.vertx.ext.unit.TestContext) EDIFACT(org.folio.rest.jaxrs.model.JournalRecord.EntityType.EDIFACT) MARC_BIBLIOGRAPHIC(org.folio.rest.jaxrs.model.JournalRecord.EntityType.MARC_BIBLIOGRAPHIC) MARC_AUTHORITY(org.folio.rest.jaxrs.model.JournalRecord.EntityType.MARC_AUTHORITY) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) Matchers.not(org.hamcrest.Matchers.not) HttpStatus(org.apache.http.HttpStatus) CHILD(org.folio.rest.jaxrs.model.JobExecution.SubordinationType.CHILD) MockitoAnnotations(org.mockito.MockitoAnnotations) Matchers.everyItem(org.hamcrest.Matchers.everyItem) JobExecution(org.folio.rest.jaxrs.model.JobExecution) JobProfileInfo(org.folio.rest.jaxrs.model.JobProfileInfo) After(org.junit.After) Spy(org.mockito.Spy) Matchers.nullValue(org.hamcrest.Matchers.nullValue) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) JsonObject(io.vertx.core.json.JsonObject) ERROR(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.ERROR) ZoneOffset(java.time.ZoneOffset) HOLDINGS(org.folio.rest.jaxrs.model.JournalRecord.EntityType.HOLDINGS) JobExecutionDto(org.folio.rest.jaxrs.model.JobExecutionDto) MODIFY(org.folio.rest.jaxrs.model.JournalRecord.ActionType.MODIFY) StatusDto(org.folio.rest.jaxrs.model.StatusDto) ChangeManagerAPITest(org.folio.rest.impl.changeManager.ChangeManagerAPITest) AUTHORITY(org.folio.rest.jaxrs.model.JournalRecord.EntityType.AUTHORITY) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) UUID(java.util.UUID) Instant(java.time.Instant) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) List(java.util.List) JobExecutionDtoCollection(org.folio.rest.jaxrs.model.JobExecutionDtoCollection) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) RestAssured(io.restassured.RestAssured) Progress(org.folio.rest.jaxrs.model.Progress) Async(io.vertx.ext.unit.Async) RunWith(org.junit.runner.RunWith) PARENT_MULTIPLE(org.folio.rest.jaxrs.model.JobExecution.SubordinationType.PARENT_MULTIPLE) DeleteJobExecutionsResp(org.folio.rest.jaxrs.model.DeleteJobExecutionsResp) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) JournalRecordCollection(org.folio.rest.jaxrs.model.JournalRecordCollection) EntityType(org.folio.rest.jaxrs.model.EntityType) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Status(org.folio.services.Status) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) MARC(org.folio.rest.jaxrs.model.JobProfileInfo.DataType.MARC) ITEM(org.folio.rest.jaxrs.model.JournalRecord.EntityType.ITEM) Matchers.empty(org.hamcrest.Matchers.empty) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) UPDATE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.UPDATE) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) COMPLETED(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.COMPLETED) INSTANCE(org.folio.rest.jaxrs.model.JournalRecord.EntityType.INSTANCE) NON_MATCH(org.folio.rest.jaxrs.model.JournalRecord.ActionType.NON_MATCH) RunBy(org.folio.rest.jaxrs.model.RunBy) INVOICE(org.folio.rest.jaxrs.model.JournalRecord.EntityType.INVOICE) ChronoUnit(java.time.temporal.ChronoUnit) Matchers.hasItem(org.hamcrest.Matchers.hasItem) JobExecutionsCache(org.folio.services.JobExecutionsCache) DateTimeFormatter(java.time.format.DateTimeFormatter) Assert(org.junit.Assert) JournalRecordDaoImpl(org.folio.dao.JournalRecordDaoImpl) CREATE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.CREATE) Progress(org.folio.rest.jaxrs.model.Progress) JobExecutionDtoCollection(org.folio.rest.jaxrs.model.JobExecutionDtoCollection) JobExecutionDto(org.folio.rest.jaxrs.model.JobExecutionDto) ChangeManagerAPITest(org.folio.rest.impl.changeManager.ChangeManagerAPITest) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 3 with Progress

use of org.folio.rest.jaxrs.model.Progress in project mod-source-record-manager by folio-org.

the class RecordProcessedEventHandlingServiceImpl method handle.

@Override
public Future<Boolean> handle(String eventContent, OkapiConnectionParams params) {
    Promise<Boolean> promise = Promise.promise();
    DataImportEventPayload dataImportEventPayload;
    try {
        dataImportEventPayload = new ObjectMapper().readValue(eventContent, DataImportEventPayload.class);
    } catch (IOException e) {
        LOGGER.error("Failed to read eventContent {}", eventContent, e);
        promise.fail(e);
        return promise.future();
    }
    String jobExecutionId = dataImportEventPayload.getJobExecutionId();
    try {
        DataImportEventTypes eventType = DataImportEventTypes.valueOf(dataImportEventPayload.getEventType());
        jobExecutionProgressService.updateJobExecutionProgress(jobExecutionId, progress -> changeProgressAccordingToEventType(progress, eventType), params.getTenantId()).compose(updatedProgress -> updateJobExecutionIfAllRecordsProcessed(jobExecutionId, updatedProgress, params)).onComplete(ar -> {
            if (ar.failed()) {
                LOGGER.error("Failed to handle {} event", eventType, ar.cause());
                updateJobStatusToError(jobExecutionId, params).onComplete(statusAr -> promise.fail(ar.cause()));
            } else {
                promise.complete(true);
            }
        });
    } catch (Exception e) {
        LOGGER.error("Failed to handle event {}", eventContent, e);
        updateJobStatusToError(jobExecutionId, params);
        promise.fail(e);
    }
    return promise.future();
}
Also used : StatusDto(org.folio.rest.jaxrs.model.StatusDto) Date(java.util.Date) Promise(io.vertx.core.Promise) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataImportEventPayload(org.folio.DataImportEventPayload) Autowired(org.springframework.beans.factory.annotation.Autowired) CANCELLED(org.folio.rest.jaxrs.model.JobExecution.Status.CANCELLED) IOException(java.io.IOException) COMMITTED(org.folio.rest.jaxrs.model.JobExecution.Status.COMMITTED) Future(io.vertx.core.Future) OkapiConnectionParams(org.folio.dataimport.util.OkapiConnectionParams) String.format(java.lang.String.format) Logger(org.apache.logging.log4j.Logger) JobExecutionProgress(org.folio.rest.jaxrs.model.JobExecutionProgress) JournalService(org.folio.services.journal.JournalService) JobExecutionProgressService(org.folio.services.progress.JobExecutionProgressService) DataImportEventTypes(org.folio.rest.jaxrs.model.DataImportEventTypes) Service(org.springframework.stereotype.Service) JobExecution(org.folio.rest.jaxrs.model.JobExecution) Qualifier(org.springframework.beans.factory.annotation.Qualifier) LogManager(org.apache.logging.log4j.LogManager) Progress(org.folio.rest.jaxrs.model.Progress) IOException(java.io.IOException) DataImportEventTypes(org.folio.rest.jaxrs.model.DataImportEventTypes) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) DataImportEventPayload(org.folio.DataImportEventPayload)

Example 4 with Progress

use of org.folio.rest.jaxrs.model.Progress in project mod-source-record-manager by folio-org.

the class ChangeManagerAPITest method shouldProcessLastChunkOfRawRecords.

@Test
public void shouldProcessLastChunkOfRawRecords(TestContext testContext) {
    InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
    List<JobExecution> createdJobExecutions = response.getJobExecutions();
    assertThat(createdJobExecutions.size(), is(1));
    JobExecution jobExec = createdJobExecutions.get(0);
    jobExec.setRunBy(new RunBy().withFirstName("DIKU").withLastName("ADMINISTRATOR"));
    jobExec.setProgress(new Progress().withCurrent(1000).withTotal(1000));
    jobExec.setStartedDate(new Date());
    WireMock.stubFor(post(RECORDS_SERVICE_URL).willReturn(created().withTransformers(RequestToResponseTransformer.NAME)));
    Async async = testContext.async();
    RestAssured.given().spec(spec).body(jobExec).when().put(JOB_EXECUTION_PATH + jobExec.getId()).then().statusCode(HttpStatus.SC_OK).log().all();
    async.complete();
    async = testContext.async();
    RestAssured.given().spec(spec).body(new JobProfileInfo().withName("MARC records").withId(DEFAULT_JOB_PROFILE_ID).withDataType(JobProfileInfo.DataType.MARC)).when().put(JOB_EXECUTION_PATH + jobExec.getId() + JOB_PROFILE_PATH).then().statusCode(HttpStatus.SC_OK);
    async.complete();
    rawRecordsDto.getRecordsMetadata().setLast(true);
    async = testContext.async();
    RestAssured.given().spec(spec).body(rawRecordsDto.withId(UUID.randomUUID().toString())).when().post(JOB_EXECUTION_PATH + jobExec.getId() + RECORDS_PATH).then().statusCode(HttpStatus.SC_NO_CONTENT);
    async.complete();
    async = testContext.async();
    RestAssured.given().spec(spec).when().get(JOB_EXECUTION_PATH + jobExec.getId()).then().statusCode(HttpStatus.SC_OK);
    async.complete();
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) Progress(org.folio.rest.jaxrs.model.Progress) JobProfileInfo(org.folio.rest.jaxrs.model.JobProfileInfo) Async(io.vertx.ext.unit.Async) RunBy(org.folio.rest.jaxrs.model.RunBy) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) Date(java.util.Date) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Aggregations

Progress (org.folio.rest.jaxrs.model.Progress)4 Date (java.util.Date)3 JobExecution (org.folio.rest.jaxrs.model.JobExecution)3 Future (io.vertx.core.Future)2 Async (io.vertx.ext.unit.Async)2 AbstractRestTest (org.folio.rest.impl.AbstractRestTest)2 InitJobExecutionsRsDto (org.folio.rest.jaxrs.model.InitJobExecutionsRsDto)2 JobProfileInfo (org.folio.rest.jaxrs.model.JobProfileInfo)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 RestAssured (io.restassured.RestAssured)1 Promise (io.vertx.core.Promise)1 JsonObject (io.vertx.core.json.JsonObject)1 TestContext (io.vertx.ext.unit.TestContext)1 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)1 IOException (java.io.IOException)1 String.format (java.lang.String.format)1 Instant (java.time.Instant)1 ZoneOffset (java.time.ZoneOffset)1 ZonedDateTime (java.time.ZonedDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1