Search in sources :

Example 1 with JobExecutionProgress

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

the class JobExecutionProgressDaoImpl method initializeJobExecutionProgress.

@Override
public Future<JobExecutionProgress> initializeJobExecutionProgress(String jobExecutionId, Integer totalRecords, String tenantId) {
    Promise<JobExecutionProgress> promise = Promise.promise();
    Promise<SQLConnection> tx = Promise.promise();
    PostgresClient pgClient = pgClientFactory.createInstance(tenantId);
    getSelectResult(tx, pgClient, jobExecutionId, tenantId).compose(selectResult -> {
        JobExecutionProgress progress = new JobExecutionProgress().withJobExecutionId(jobExecutionId).withTotal(totalRecords);
        Optional<JobExecutionProgress> optionalJobExecutionProgress = mapResultSetToOptionalJobExecutionProgress(selectResult);
        return optionalJobExecutionProgress.isEmpty() ? save(progress, tenantId).map(progress) : Future.succeededFuture(optionalJobExecutionProgress.get());
    }).onComplete(saveAr -> {
        if (saveAr.succeeded()) {
            pgClient.endTx(tx.future(), endTx -> promise.complete(saveAr.result()));
        } else {
            if (ValidationHelper.isDuplicate(saveAr.cause().getMessage())) {
                pgClient.rollbackTx(tx.future(), r -> promise.complete());
                return;
            }
            LOGGER.error(FAILED_INITIALIZATION_MESSAGE, jobExecutionId, saveAr.cause());
            pgClient.rollbackTx(tx.future(), r -> promise.fail(saveAr.cause()));
        }
    });
    return promise.future();
}
Also used : ValidationHelper(org.folio.rest.tools.utils.ValidationHelper) Promise(io.vertx.core.Promise) PostgresClient.convertToPsqlStandard(org.folio.rest.persist.PostgresClient.convertToPsqlStandard) SQLConnection(org.folio.rest.persist.SQLConnection) Autowired(org.springframework.beans.factory.annotation.Autowired) UnaryOperator(java.util.function.UnaryOperator) Future(io.vertx.core.Future) NotFoundException(javax.ws.rs.NotFoundException) PostgresClient(org.folio.rest.persist.PostgresClient) Tuple(io.vertx.sqlclient.Tuple) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) RowIterator(io.vertx.sqlclient.RowIterator) Logger(org.apache.logging.log4j.Logger) JobExecutionProgress(org.folio.rest.jaxrs.model.JobExecutionProgress) Row(io.vertx.sqlclient.Row) Optional(java.util.Optional) RowSet(io.vertx.sqlclient.RowSet) AsyncResult(io.vertx.core.AsyncResult) Repository(org.springframework.stereotype.Repository) LogManager(org.apache.logging.log4j.LogManager) JobExecutionProgress(org.folio.rest.jaxrs.model.JobExecutionProgress) Optional(java.util.Optional) SQLConnection(org.folio.rest.persist.SQLConnection) PostgresClient(org.folio.rest.persist.PostgresClient)

Example 2 with JobExecutionProgress

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

the class JobExecutionDaoImplTest method prepareDataForDeletion.

private Future<JobExecution> prepareDataForDeletion(Instant completedDate) {
    InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
    List<JobExecution> createdJobExecutions = response.getJobExecutions();
    assertThat(createdJobExecutions.size(), Matchers.is(1));
    JobExecution jobExec = createdJobExecutions.get(0);
    jobExec.withCompletedDate(Date.from(completedDate));
    JobExecutionProgress jobExecutionProgress = new JobExecutionProgress().withJobExecutionId(jobExec.getId()).withTotal(1).withCurrentlySucceeded(1).withCurrentlyFailed(0);
    JobMonitoring jobMonitoring = new JobMonitoring().withId(UUID.randomUUID().toString()).withJobExecutionId(jobExec.getId()).withNotificationSent(true).withLastEventTimestamp(new Date());
    JournalRecord journalRecord = new JournalRecord().withJobExecutionId(jobExec.getId()).withSourceRecordOrder(0).withSourceId(UUID.randomUUID().toString()).withEntityType(JournalRecord.EntityType.MARC_BIBLIOGRAPHIC).withEntityId(UUID.randomUUID().toString()).withActionType(CREATE).withActionDate(new Date()).withActionStatus(COMPLETED);
    JobExecutionSourceChunk jobExecutionSourceChunk = new JobExecutionSourceChunk().withId("67dfac11-1caf-4470-9ad1-d533f6360bdd").withJobExecutionId(jobExec.getId()).withLast(false).withState(JobExecutionSourceChunk.State.COMPLETED).withChunkSize(10).withProcessedAmount(42);
    return jobExecutionDao.updateJobExecution(jobExec, TENANT_ID).compose(jobExecution -> {
        Future<RowSet<Row>> saveProgressFuture = jobExecutionProgressDao.save(jobExecutionProgress, TENANT_ID);
        Future<String> saveMonitoringFuture = jobMonitoringDao.save(jobMonitoring, TENANT_ID);
        Future<String> saveJournalFuture = journalRecordDao.save(journalRecord, TENANT_ID);
        Future<String> saveSourceChunkFuture = jobExecutionSourceChunkDao.save(jobExecutionSourceChunk, TENANT_ID);
        return CompositeFuture.all(saveProgressFuture, saveMonitoringFuture, saveJournalFuture, saveSourceChunkFuture).compose(ar -> Future.succeededFuture(jobExecution));
    });
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) JobExecutionProgress(org.folio.rest.jaxrs.model.JobExecutionProgress) RowSet(io.vertx.sqlclient.RowSet) JobExecutionSourceChunk(org.folio.rest.jaxrs.model.JobExecutionSourceChunk) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) JobMonitoring(org.folio.rest.jaxrs.model.JobMonitoring) Date(java.util.Date) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord)

Example 3 with JobExecutionProgress

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

the class RecordProcessedEventHandlingServiceImplTest method shouldIncrementCurrentlySucceededAndUpdateProgressOnHandleEvent.

@Test
public void shouldIncrementCurrentlySucceededAndUpdateProgressOnHandleEvent(TestContext context) {
    // given
    Async async = context.async();
    HashMap<String, String> payloadContext = new HashMap<>();
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DataImportEventTypes.DI_COMPLETED.value()).withContext(payloadContext);
    Future<Boolean> future = jobExecutionService.initializeJobExecutions(initJobExecutionsRqDto, params).compose(initJobExecutionsRsDto -> jobExecutionService.setJobProfileToJobExecution(initJobExecutionsRsDto.getParentJobExecutionId(), jobProfileInfo, params)).compose(jobExecution -> {
        dataImportEventPayload.setJobExecutionId(jobExecution.getId());
        return chunkProcessingService.processChunk(rawRecordsDto, jobExecution.getId(), params);
    });
    // when
    Future<JobExecutionProgress> jobFuture = future.compose(ar -> recordProcessedEventHandlingService.handle(Json.encode(dataImportEventPayload), params)).compose(ar -> jobExecutionProgressService.getByJobExecutionId(dataImportEventPayload.getJobExecutionId(), TENANT_ID));
    // then
    jobFuture.onComplete(ar -> {
        context.assertTrue(ar.succeeded());
        JobExecutionProgress updatedProgress = ar.result();
        context.assertEquals(1, updatedProgress.getCurrentlySucceeded());
        context.assertEquals(0, updatedProgress.getCurrentlyFailed());
        context.assertEquals(rawRecordsDto.getRecordsMetadata().getTotal(), updatedProgress.getTotal());
        jobMonitoringService.getByJobExecutionId(updatedProgress.getJobExecutionId(), params.getTenantId()).onSuccess(optionalJobMonitoring -> {
            context.assertTrue(optionalJobMonitoring.isEmpty());
            async.complete();
        });
        async.complete();
    });
}
Also used : TestContext(io.vertx.ext.unit.TestContext) MappingParametersProvider(org.folio.services.mappers.processor.MappingParametersProvider) JobMonitoringDaoImpl(org.folio.dao.JobMonitoringDaoImpl) JournalServiceImpl(org.folio.services.journal.JournalServiceImpl) MockitoAnnotations(org.mockito.MockitoAnnotations) MarcRecordAnalyzer(org.folio.dataimport.util.marc.MarcRecordAnalyzer) JobProfileInfo(org.folio.rest.jaxrs.model.JobProfileInfo) JobExecution(org.folio.rest.jaxrs.model.JobExecution) Spy(org.mockito.Spy) JsonObject(io.vertx.core.json.JsonObject) MappingRuleDaoImpl(org.folio.dao.MappingRuleDaoImpl) WireMock.post(com.github.tomakehurst.wiremock.client.WireMock.post) ERROR(org.folio.rest.jaxrs.model.JobExecution.Status.ERROR) InitialRecord(org.folio.rest.jaxrs.model.InitialRecord) MappingRulesSnapshotDaoImpl(org.folio.dao.MappingRulesSnapshotDaoImpl) DataImportEventPayload(org.folio.DataImportEventPayload) UUID(java.util.UUID) Future(io.vertx.core.Future) OkapiConnectionParams(org.folio.dataimport.util.OkapiConnectionParams) MarcImportEventsHandler(org.folio.verticle.consumers.util.MarcImportEventsHandler) Optional(java.util.Optional) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) JobExecutionSourceChunkDaoImpl(org.folio.dao.JobExecutionSourceChunkDaoImpl) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) OKAPI_TENANT_HEADER(org.folio.rest.util.OkapiConnectionParams.OKAPI_TENANT_HEADER) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) RunWith(org.junit.runner.RunWith) PARSING_IN_PROGRESS(org.folio.rest.jaxrs.model.JobExecution.Status.PARSING_IN_PROGRESS) HashMap(java.util.HashMap) RecordsMetadata(org.folio.rest.jaxrs.model.RecordsMetadata) OKAPI_URL_HEADER(org.folio.dataimport.util.RestUtil.OKAPI_URL_HEADER) HrIdFieldServiceImpl(org.folio.services.afterprocessing.HrIdFieldServiceImpl) JobExecutionProgressServiceImpl(org.folio.services.progress.JobExecutionProgressServiceImpl) WireMock.ok(com.github.tomakehurst.wiremock.client.WireMock.ok) WireMock(com.github.tomakehurst.wiremock.client.WireMock) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) DataType(org.folio.rest.jaxrs.model.JobProfileInfo.DataType) TestUtil(org.folio.TestUtil) InitJobExecutionsRqDto(org.folio.rest.jaxrs.model.InitJobExecutionsRqDto) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Before(org.junit.Before) WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) InjectMocks(org.mockito.InjectMocks) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) JobExecutionProgressDaoImpl(org.folio.dao.JobExecutionProgressDaoImpl) RUNNING_COMPLETE(org.folio.rest.jaxrs.model.JobExecution.UiStatus.RUNNING_COMPLETE) Vertx(io.vertx.core.Vertx) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) IOException(java.io.IOException) Test(org.junit.Test) COMMITTED(org.folio.rest.jaxrs.model.JobExecution.Status.COMMITTED) Mockito.when(org.mockito.Mockito.when) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) MappingParamsSnapshotDaoImpl(org.folio.dao.MappingParamsSnapshotDaoImpl) WireMock.verify(com.github.tomakehurst.wiremock.client.WireMock.verify) WireMock.putRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.putRequestedFor) RawRecordsDto(org.folio.rest.jaxrs.model.RawRecordsDto) JsonArray(io.vertx.core.json.JsonArray) JobExecutionProgress(org.folio.rest.jaxrs.model.JobExecutionProgress) Rule(org.junit.Rule) WireMock.created(com.github.tomakehurst.wiremock.client.WireMock.created) File(org.folio.rest.jaxrs.model.File) JobExecutionDaoImpl(org.folio.dao.JobExecutionDaoImpl) DataImportEventTypes(org.folio.rest.jaxrs.model.DataImportEventTypes) OKAPI_TOKEN_HEADER(org.folio.rest.util.OkapiConnectionParams.OKAPI_TOKEN_HEADER) Collections(java.util.Collections) JournalRecordDaoImpl(org.folio.dao.JournalRecordDaoImpl) KafkaConfig(org.folio.kafka.KafkaConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) JobExecutionProgress(org.folio.rest.jaxrs.model.JobExecutionProgress) HashMap(java.util.HashMap) Async(io.vertx.ext.unit.Async) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DataImportEventPayload(org.folio.DataImportEventPayload) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 4 with JobExecutionProgress

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

the class JobExecutionProgressServiceImplTest method shouldNotReturnFailedFutureWhenJobExecutionIdDuplicates.

@Test
public void shouldNotReturnFailedFutureWhenJobExecutionIdDuplicates(TestContext context) {
    Async async = context.async();
    int expectedTotalRecords = 62;
    Future<CompositeFuture> future = jobExecutionService.initializeJobExecutions(initJobExecutionsRqDto, params).compose(initJobExecutionsRsDto -> {
        Future<JobExecutionProgress> future1 = jobExecutionProgressService.initializeJobExecutionProgress(initJobExecutionsRsDto.getParentJobExecutionId(), expectedTotalRecords, TENANT_ID);
        Future<JobExecutionProgress> future2 = jobExecutionProgressService.initializeJobExecutionProgress(initJobExecutionsRsDto.getParentJobExecutionId(), expectedTotalRecords, TENANT_ID);
        return GenericCompositeFuture.join(Arrays.asList(future1, future2));
    });
    future.onComplete(ar -> {
        context.assertTrue(ar.succeeded());
        async.complete();
    });
}
Also used : CompositeFuture(io.vertx.core.CompositeFuture) GenericCompositeFuture(org.folio.okapi.common.GenericCompositeFuture) JobExecutionProgress(org.folio.rest.jaxrs.model.JobExecutionProgress) Async(io.vertx.ext.unit.Async) Test(org.junit.Test) AbstractRestTest(org.folio.rest.impl.AbstractRestTest)

Example 5 with JobExecutionProgress

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

the class JobExecutionProgressServiceImplTest method shouldUpdateProgress.

@Test
public void shouldUpdateProgress(TestContext context) {
    Async async = context.async();
    int expectedTotalRecords = 42;
    int expectedSucceededRecords = 40;
    int expectedFailedRecords = 2;
    Future<JobExecutionProgress> future = jobExecutionService.initializeJobExecutions(initJobExecutionsRqDto, params).compose(initJobExecutionsRsDto -> jobExecutionService.initializeJobExecutions(initJobExecutionsRqDto, params)).compose(initJobExecutionsRsDto -> jobExecutionProgressService.initializeJobExecutionProgress(initJobExecutionsRsDto.getParentJobExecutionId(), expectedTotalRecords, TENANT_ID)).compose(progress -> jobExecutionProgressService.updateJobExecutionProgress(progress.getJobExecutionId(), progressToUpdate -> progressToUpdate.withCurrentlySucceeded(expectedSucceededRecords).withCurrentlyFailed(expectedFailedRecords), TENANT_ID));
    future.onComplete(ar -> {
        context.assertTrue(ar.succeeded());
        JobExecutionProgress progress = ar.result();
        context.assertEquals(expectedTotalRecords, progress.getTotal());
        context.assertEquals(expectedSucceededRecords, progress.getCurrentlySucceeded());
        context.assertEquals(expectedFailedRecords, progress.getCurrentlyFailed());
        jobMonitoringService.getByJobExecutionId(progress.getJobExecutionId(), params.getTenantId()).onSuccess(optionalJobMonitoring -> {
            context.assertTrue(optionalJobMonitoring.isPresent());
            JobMonitoring jobMonitoring = optionalJobMonitoring.get();
            context.assertNotNull(jobMonitoring.getId());
            context.assertEquals(progress.getJobExecutionId(), jobMonitoring.getJobExecutionId());
            context.assertNotNull(jobMonitoring.getLastEventTimestamp());
            context.assertFalse(jobMonitoring.getNotificationSent());
            async.complete();
        });
    });
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Arrays(java.util.Arrays) OKAPI_TENANT_HEADER(org.folio.rest.util.OkapiConnectionParams.OKAPI_TENANT_HEADER) JobMonitoringDaoImpl(org.folio.dao.JobMonitoringDaoImpl) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) JobExecutionProgressServiceImpl(org.folio.services.progress.JobExecutionProgressServiceImpl) OKAPI_URL_HEADER(org.folio.dataimport.util.RestUtil.OKAPI_URL_HEADER) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) CompositeFuture(io.vertx.core.CompositeFuture) MockitoAnnotations(org.mockito.MockitoAnnotations) JobExecutionProgressService(org.folio.services.progress.JobExecutionProgressService) Spy(org.mockito.Spy) InitJobExecutionsRqDto(org.folio.rest.jaxrs.model.InitJobExecutionsRqDto) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) GenericCompositeFuture(org.folio.okapi.common.GenericCompositeFuture) JobExecutionProgressDaoImpl(org.folio.dao.JobExecutionProgressDaoImpl) JobMonitoring(org.folio.rest.jaxrs.model.JobMonitoring) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) UUID(java.util.UUID) Future(io.vertx.core.Future) OkapiConnectionParams(org.folio.dataimport.util.OkapiConnectionParams) JobExecutionProgress(org.folio.rest.jaxrs.model.JobExecutionProgress) Rule(org.junit.Rule) File(org.folio.rest.jaxrs.model.File) JobExecutionDaoImpl(org.folio.dao.JobExecutionDaoImpl) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) OKAPI_TOKEN_HEADER(org.folio.rest.util.OkapiConnectionParams.OKAPI_TOKEN_HEADER) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) Collections(java.util.Collections) JobExecutionProgress(org.folio.rest.jaxrs.model.JobExecutionProgress) Async(io.vertx.ext.unit.Async) JobMonitoring(org.folio.rest.jaxrs.model.JobMonitoring) Test(org.junit.Test) AbstractRestTest(org.folio.rest.impl.AbstractRestTest)

Aggregations

JobExecutionProgress (org.folio.rest.jaxrs.model.JobExecutionProgress)12 Async (io.vertx.ext.unit.Async)9 AbstractRestTest (org.folio.rest.impl.AbstractRestTest)9 Test (org.junit.Test)9 Future (io.vertx.core.Future)8 PostgresClientFactory (org.folio.dao.util.PostgresClientFactory)8 Vertx (io.vertx.core.Vertx)6 TestContext (io.vertx.ext.unit.TestContext)6 RunTestOnContext (io.vertx.ext.unit.junit.RunTestOnContext)6 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)6 HashMap (java.util.HashMap)6 UUID (java.util.UUID)6 OkapiConnectionParams (org.folio.dataimport.util.OkapiConnectionParams)6 OKAPI_URL_HEADER (org.folio.dataimport.util.RestUtil.OKAPI_URL_HEADER)6 File (org.folio.rest.jaxrs.model.File)6 InitJobExecutionsRqDto (org.folio.rest.jaxrs.model.InitJobExecutionsRqDto)6 OKAPI_TENANT_HEADER (org.folio.rest.util.OkapiConnectionParams.OKAPI_TENANT_HEADER)6 OKAPI_TOKEN_HEADER (org.folio.rest.util.OkapiConnectionParams.OKAPI_TOKEN_HEADER)6 Before (org.junit.Before)6 Rule (org.junit.Rule)6