Search in sources :

Example 1 with StatusDto

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

the class EventDrivenChunkProcessingServiceImpl method processRawRecordsChunk.

@Override
protected Future<Boolean> processRawRecordsChunk(RawRecordsDto incomingChunk, JobExecutionSourceChunk sourceChunk, String jobExecutionId, OkapiConnectionParams params) {
    LOGGER.debug("Starting to process raw records chunk with id: {} for jobExecutionId: {}. Chunk size: {}.", sourceChunk.getId(), jobExecutionId, sourceChunk.getChunkSize());
    Promise<Boolean> promise = Promise.promise();
    initializeJobExecutionProgressIfNecessary(jobExecutionId, incomingChunk, params.getTenantId()).compose(ar -> checkAndUpdateJobExecutionStatusIfNecessary(jobExecutionId, new StatusDto().withStatus(StatusDto.Status.PARSING_IN_PROGRESS), params)).compose(jobExec -> changeEngineService.parseRawRecordsChunkForJobExecution(incomingChunk, jobExec, sourceChunk.getId(), params)).onComplete(sendEventsAr -> updateJobExecutionIfAllSourceChunksMarkedAsError(jobExecutionId, params).onComplete(updateAr -> promise.handle(sendEventsAr.map(true))));
    return promise.future();
}
Also used : StatusDto(org.folio.rest.jaxrs.model.StatusDto) StatusDto(org.folio.rest.jaxrs.model.StatusDto) Promise(io.vertx.core.Promise) Autowired(org.springframework.beans.factory.annotation.Autowired) JobExecutionSourceChunk(org.folio.rest.jaxrs.model.JobExecutionSourceChunk) Future(io.vertx.core.Future) OkapiConnectionParams(org.folio.dataimport.util.OkapiConnectionParams) NotFoundException(javax.ws.rs.NotFoundException) RawRecordsDto(org.folio.rest.jaxrs.model.RawRecordsDto) Logger(org.apache.logging.log4j.Logger) JobExecutionProgress(org.folio.rest.jaxrs.model.JobExecutionProgress) JobExecutionProgressService(org.folio.services.progress.JobExecutionProgressService) CollectionUtils.isNotEmpty(org.apache.commons.collections4.CollectionUtils.isNotEmpty) PARSING_IN_PROGRESS(org.folio.rest.jaxrs.model.StatusDto.Status.PARSING_IN_PROGRESS) Service(org.springframework.stereotype.Service) JobExecutionSourceChunkDao(org.folio.dao.JobExecutionSourceChunkDao) JobExecution(org.folio.rest.jaxrs.model.JobExecution) LogManager(org.apache.logging.log4j.LogManager)

Example 2 with StatusDto

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

the class ChangeManagerAPITest method shouldReturn204OkEventIfRemoveJobExecutionWithCommittedStatus.

@Test
public void shouldReturn204OkEventIfRemoveJobExecutionWithCommittedStatus(TestContext testContext) {
    InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
    List<JobExecution> createdJobExecutions = response.getJobExecutions();
    assertThat(createdJobExecutions.size(), is(1));
    JobExecution jobExec = createdJobExecutions.get(0);
    WireMock.stubFor(post(RECORDS_SERVICE_URL).willReturn(created().withTransformers(RequestToResponseTransformer.NAME)));
    WireMock.stubFor(WireMock.delete(new UrlPathPattern(new RegexPattern(SNAPSHOT_SERVICE_URL + "/.*"), true)).willReturn(WireMock.noContent()));
    Async 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();
    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();
    StatusDto status = new StatusDto().withStatus(COMMITTED);
    RestAssured.given().spec(spec).body(JsonObject.mapFrom(status).toString()).when().put(JOB_EXECUTION_PATH + jobExec.getId() + STATUS_PATH).then().statusCode(HttpStatus.SC_OK);
    async = testContext.async();
    RestAssured.given().spec(spec).when().delete(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).body("status", is(COMMITTED.value()));
    async.complete();
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) StatusDto(org.folio.rest.jaxrs.model.StatusDto) JobProfileInfo(org.folio.rest.jaxrs.model.JobProfileInfo) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Async(io.vertx.ext.unit.Async) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 3 with StatusDto

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

the class ChangeManagerAPITest method shouldSetTotalZeroToJobExecutionOnUpdateStatusToError.

@Test
public void shouldSetTotalZeroToJobExecutionOnUpdateStatusToError() {
    InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
    List<JobExecution> createdJobExecutions = response.getJobExecutions();
    assertThat(createdJobExecutions.size(), is(1));
    JobExecution jobExecution = createdJobExecutions.get(0);
    assertThat(jobExecution.getSubordinationType(), is(JobExecution.SubordinationType.PARENT_SINGLE));
    Assert.assertNotNull(jobExecution.getRunBy().getFirstName());
    Assert.assertNotNull(jobExecution.getRunBy().getLastName());
    StatusDto status = new StatusDto().withStatus(ERROR).withErrorStatus(StatusDto.ErrorStatus.FILE_PROCESSING_ERROR);
    RestAssured.given().spec(spec).body(JsonObject.mapFrom(status).toString()).when().put(JOB_EXECUTION_PATH + jobExecution.getId() + STATUS_PATH).then().statusCode(HttpStatus.SC_OK).body("status", is(status.getStatus().name())).body("uiStatus", is(Status.valueOf(status.getStatus().name()).getUiStatus())).body("errorStatus", is(status.getErrorStatus().toString())).body("completedDate", notNullValue(Date.class));
    RestAssured.given().spec(spec).when().get(JOB_EXECUTION_PATH + jobExecution.getId()).then().statusCode(HttpStatus.SC_OK).body("status", is(status.getStatus().name())).body("uiStatus", is(Status.valueOf(status.getStatus().name()).getUiStatus())).body("errorStatus", is(status.getErrorStatus().toString())).body("completedDate", notNullValue(Date.class)).body("progress.total", is(0));
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) StatusDto(org.folio.rest.jaxrs.model.StatusDto) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) Date(java.util.Date) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 4 with StatusDto

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

the class ChangeManagerAPITest method shouldSetCompletedDateToJobExecutionOnUpdateStatusToError.

@Test
public void shouldSetCompletedDateToJobExecutionOnUpdateStatusToError() {
    InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
    List<JobExecution> createdJobExecutions = response.getJobExecutions();
    assertThat(createdJobExecutions.size(), is(1));
    JobExecution jobExecution = createdJobExecutions.get(0);
    assertThat(jobExecution.getSubordinationType(), is(JobExecution.SubordinationType.PARENT_SINGLE));
    Assert.assertNotNull(jobExecution.getRunBy().getFirstName());
    Assert.assertNotNull(jobExecution.getRunBy().getLastName());
    StatusDto status = new StatusDto().withStatus(ERROR).withErrorStatus(StatusDto.ErrorStatus.FILE_PROCESSING_ERROR);
    RestAssured.given().spec(spec).body(JsonObject.mapFrom(status).toString()).when().put(JOB_EXECUTION_PATH + jobExecution.getId() + STATUS_PATH).then().statusCode(HttpStatus.SC_OK).body("status", is(status.getStatus().name())).body("uiStatus", is(Status.valueOf(status.getStatus().name()).getUiStatus())).body("errorStatus", is(status.getErrorStatus().toString())).body("completedDate", notNullValue(Date.class));
    RestAssured.given().spec(spec).when().get(JOB_EXECUTION_PATH + jobExecution.getId()).then().statusCode(HttpStatus.SC_OK).body("status", is(status.getStatus().name())).body("uiStatus", is(Status.valueOf(status.getStatus().name()).getUiStatus())).body("errorStatus", is(status.getErrorStatus().toString())).body("completedDate", notNullValue(Date.class));
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) StatusDto(org.folio.rest.jaxrs.model.StatusDto) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) Date(java.util.Date) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 5 with StatusDto

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

the class ChangeManagerAPITest method shouldUpdateStatusOfChild.

@Test
public void shouldUpdateStatusOfChild() {
    InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(3);
    List<JobExecution> createdJobExecutions = response.getJobExecutions();
    assertThat(createdJobExecutions.size(), is(4));
    JobExecution child = createdJobExecutions.stream().filter(jobExec -> jobExec.getSubordinationType().equals(JobExecution.SubordinationType.CHILD)).findFirst().get();
    StatusDto status = new StatusDto().withStatus(StatusDto.Status.PARSING_IN_PROGRESS);
    RestAssured.given().spec(spec).body(JsonObject.mapFrom(status).toString()).when().put(JOB_EXECUTION_PATH + child.getId() + STATUS_PATH).then().statusCode(HttpStatus.SC_OK).body("status", is(status.getStatus().name())).body("uiStatus", is(Status.valueOf(status.getStatus().name()).getUiStatus()));
    RestAssured.given().spec(spec).when().get(JOB_EXECUTION_PATH + child.getId()).then().statusCode(HttpStatus.SC_OK).body("status", is(status.getStatus().name())).body("uiStatus", is(Status.valueOf(status.getStatus().name()).getUiStatus()));
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) StatusDto(org.folio.rest.jaxrs.model.StatusDto) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Aggregations

StatusDto (org.folio.rest.jaxrs.model.StatusDto)18 JobExecution (org.folio.rest.jaxrs.model.JobExecution)17 AbstractRestTest (org.folio.rest.impl.AbstractRestTest)14 Test (org.junit.Test)14 InitJobExecutionsRsDto (org.folio.rest.jaxrs.model.InitJobExecutionsRsDto)10 Future (io.vertx.core.Future)8 JsonObject (io.vertx.core.json.JsonObject)7 UUID (java.util.UUID)7 OkapiConnectionParams (org.folio.dataimport.util.OkapiConnectionParams)7 JobProfileInfo (org.folio.rest.jaxrs.model.JobProfileInfo)7 Async (io.vertx.ext.unit.Async)6 Collections (java.util.Collections)6 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)5 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)5 TestContext (io.vertx.ext.unit.TestContext)5 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)5 HashMap (java.util.HashMap)5 WireMock (com.github.tomakehurst.wiremock.client.WireMock)4 WireMock.created (com.github.tomakehurst.wiremock.client.WireMock.created)4 WireMock.get (com.github.tomakehurst.wiremock.client.WireMock.get)4