Search in sources :

Example 1 with JobMonitoring

use of org.folio.rest.jaxrs.model.JobMonitoring 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 2 with JobMonitoring

use of org.folio.rest.jaxrs.model.JobMonitoring 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)

Example 3 with JobMonitoring

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

the class JobMonitoringServiceImplTest method shouldUpdateJobMonitoring.

@Test
public void shouldUpdateJobMonitoring(TestContext context) {
    Async async = context.async();
    Future<Optional<JobMonitoring>> future = jobExecutionService.initializeJobExecutions(initJobExecutionsRqDto, params).compose(initJobExecutionsRsDto -> jobMonitoringService.saveNew(initJobExecutionsRsDto.getParentJobExecutionId(), TENANT_ID).compose(jobMonitoring -> jobMonitoringService.updateByJobExecutionId(jobMonitoring.getJobExecutionId(), Timestamp.valueOf(LocalDateTime.now()), true, TENANT_ID)).compose(updated -> jobMonitoringService.getByJobExecutionId(initJobExecutionsRsDto.getParentJobExecutionId(), TENANT_ID)));
    future.onComplete(ar -> {
        context.assertTrue(ar.succeeded());
        Optional<JobMonitoring> optionalJobMonitoring = ar.result();
        context.assertTrue(optionalJobMonitoring.isPresent());
        JobMonitoring savedJobMonitoring = optionalJobMonitoring.get();
        context.assertNotNull(savedJobMonitoring.getId());
        context.assertNotNull(savedJobMonitoring.getJobExecutionId());
        context.assertNotNull(savedJobMonitoring.getLastEventTimestamp());
        context.assertTrue(savedJobMonitoring.getNotificationSent());
        async.complete();
    });
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) OKAPI_TENANT_HEADER(org.folio.rest.util.OkapiConnectionParams.OKAPI_TENANT_HEADER) JobMonitoringDaoImpl(org.folio.dao.JobMonitoringDaoImpl) PostgresClient.convertToPsqlStandard(org.folio.rest.persist.PostgresClient.convertToPsqlStandard) LocalDateTime(java.time.LocalDateTime) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) OKAPI_URL_HEADER(org.folio.dataimport.util.RestUtil.OKAPI_URL_HEADER) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) MockitoAnnotations(org.mockito.MockitoAnnotations) After(org.junit.After) Spy(org.mockito.Spy) InitJobExecutionsRqDto(org.folio.rest.jaxrs.model.InitJobExecutionsRqDto) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) JobMonitoring(org.folio.rest.jaxrs.model.JobMonitoring) Timestamp(java.sql.Timestamp) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) UUID(java.util.UUID) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Future(io.vertx.core.Future) String.format(java.lang.String.format) OkapiConnectionParams(org.folio.dataimport.util.OkapiConnectionParams) List(java.util.List) Rule(org.junit.Rule) File(org.folio.rest.jaxrs.model.File) JobExecutionDaoImpl(org.folio.dao.JobExecutionDaoImpl) Optional(java.util.Optional) OKAPI_TOKEN_HEADER(org.folio.rest.util.OkapiConnectionParams.OKAPI_TOKEN_HEADER) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Collections(java.util.Collections) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) Optional(java.util.Optional) Async(io.vertx.ext.unit.Async) JobMonitoring(org.folio.rest.jaxrs.model.JobMonitoring) Test(org.junit.Test) AbstractRestTest(org.folio.rest.impl.AbstractRestTest)

Example 4 with JobMonitoring

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

the class JobMonitoringServiceImplTest method shouldFindAllJobMonitoring.

@Test
public void shouldFindAllJobMonitoring(TestContext context) {
    Async async = context.async();
    Future<List<JobMonitoring>> future = jobExecutionService.initializeJobExecutions(initJobExecutionsRqDto, params).compose(initJobExecutionsRsDto -> jobMonitoringService.saveNew(initJobExecutionsRsDto.getParentJobExecutionId(), TENANT_ID)).compose(initJobExecutionsRsDto2 -> jobExecutionService.initializeJobExecutions(initJobExecutionsRqDto, params)).compose(initJobExecutionsRsDto2 -> jobMonitoringService.saveNew(initJobExecutionsRsDto2.getParentJobExecutionId(), TENANT_ID)).compose(list -> jobMonitoringService.getAll(TENANT_ID));
    future.onComplete(ar -> {
        context.assertTrue(ar.succeeded());
        List<JobMonitoring> jobMonitors = ar.result();
        context.assertTrue(!jobMonitors.isEmpty());
        context.assertTrue(jobMonitors.size() == 2);
        async.complete();
    });
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) OKAPI_TENANT_HEADER(org.folio.rest.util.OkapiConnectionParams.OKAPI_TENANT_HEADER) JobMonitoringDaoImpl(org.folio.dao.JobMonitoringDaoImpl) PostgresClient.convertToPsqlStandard(org.folio.rest.persist.PostgresClient.convertToPsqlStandard) LocalDateTime(java.time.LocalDateTime) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) OKAPI_URL_HEADER(org.folio.dataimport.util.RestUtil.OKAPI_URL_HEADER) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) MockitoAnnotations(org.mockito.MockitoAnnotations) After(org.junit.After) Spy(org.mockito.Spy) InitJobExecutionsRqDto(org.folio.rest.jaxrs.model.InitJobExecutionsRqDto) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) JobMonitoring(org.folio.rest.jaxrs.model.JobMonitoring) Timestamp(java.sql.Timestamp) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) UUID(java.util.UUID) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Future(io.vertx.core.Future) String.format(java.lang.String.format) OkapiConnectionParams(org.folio.dataimport.util.OkapiConnectionParams) List(java.util.List) Rule(org.junit.Rule) File(org.folio.rest.jaxrs.model.File) JobExecutionDaoImpl(org.folio.dao.JobExecutionDaoImpl) Optional(java.util.Optional) OKAPI_TOKEN_HEADER(org.folio.rest.util.OkapiConnectionParams.OKAPI_TOKEN_HEADER) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Collections(java.util.Collections) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) Async(io.vertx.ext.unit.Async) List(java.util.List) JobMonitoring(org.folio.rest.jaxrs.model.JobMonitoring) Test(org.junit.Test) AbstractRestTest(org.folio.rest.impl.AbstractRestTest)

Example 5 with JobMonitoring

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

the class JobMonitoringServiceImpl method saveNew.

@Override
public Future<JobMonitoring> saveNew(String jobExecutionId, String tenantId) {
    JobMonitoring jobMonitoring = new JobMonitoring();
    jobMonitoring.setId(UUID.randomUUID().toString());
    jobMonitoring.setJobExecutionId(jobExecutionId);
    jobMonitoring.setLastEventTimestamp(new Date());
    jobMonitoring.setNotificationSent(false);
    return jobMonitoringDao.save(jobMonitoring, tenantId).map(jobMonitoring);
}
Also used : JobMonitoring(org.folio.rest.jaxrs.model.JobMonitoring) Date(java.util.Date)

Aggregations

JobMonitoring (org.folio.rest.jaxrs.model.JobMonitoring)11 Async (io.vertx.ext.unit.Async)8 AbstractRestTest (org.folio.rest.impl.AbstractRestTest)8 Test (org.junit.Test)8 Future (io.vertx.core.Future)7 Vertx (io.vertx.core.Vertx)7 TestContext (io.vertx.ext.unit.TestContext)7 RunTestOnContext (io.vertx.ext.unit.junit.RunTestOnContext)7 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)7 Collections (java.util.Collections)7 HashMap (java.util.HashMap)7 UUID (java.util.UUID)7 JobExecutionDaoImpl (org.folio.dao.JobExecutionDaoImpl)7 JobMonitoringDaoImpl (org.folio.dao.JobMonitoringDaoImpl)7 PostgresClientFactory (org.folio.dao.util.PostgresClientFactory)7 OkapiConnectionParams (org.folio.dataimport.util.OkapiConnectionParams)7 OKAPI_URL_HEADER (org.folio.dataimport.util.RestUtil.OKAPI_URL_HEADER)7 File (org.folio.rest.jaxrs.model.File)7 InitJobExecutionsRqDto (org.folio.rest.jaxrs.model.InitJobExecutionsRqDto)7 OKAPI_TENANT_HEADER (org.folio.rest.util.OkapiConnectionParams.OKAPI_TENANT_HEADER)7