Search in sources :

Example 1 with Work

use of com.redhat.service.bridge.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class WorkManagerImpl method schedule.

@Override
public Work schedule(ManagedResource managedResource) {
    Work w = workDAO.findByManagedResource(managedResource);
    if (w == null) {
        w = Work.forResource(managedResource, workerIdProvider.getWorkerId());
        workDAO.persist(w);
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info(String.format("Scheduling work for '%s' [%s]", w.getManagedResourceId(), w.getType()));
        }
        fireEvent(w);
    }
    return w;
}
Also used : Work(com.redhat.service.bridge.manager.models.Work)

Example 2 with Work

use of com.redhat.service.bridge.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class WorkManagerImpl method recordAttempt.

@Override
@Transactional
public void recordAttempt(Work work) {
    if (!exists(work)) {
        return;
    }
    // Work has been serialised by VertX at this point and has therefore lost all affinity with
    // a JPA session. We therefore need to first retrieve the entity before updating it.
    Work w = workDAO.findById(work.getId());
    w.setModifiedAt(ZonedDateTime.now());
    w.setAttempts(w.getAttempts() + 1);
}
Also used : Work(com.redhat.service.bridge.manager.models.Work) Transactional(javax.transaction.Transactional)

Example 3 with Work

use of com.redhat.service.bridge.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorWorker method delegate.

private Processor delegate(Work work, Processor processor) {
    // Get Processor's Connector for which work needs completing
    final ConnectorEntity connectorEntity = getConnectorEntity(processor);
    // Delegate to the ConnectorWorker however mimic that the Work originated from the Processor.
    Work connectorEntityWork = Work.forDependentResource(connectorEntity, work);
    ConnectorEntity updatedConnectorEntity = connectorWorker.handleWork(connectorEntityWork);
    processor.setDependencyStatus(updatedConnectorEntity.getStatus());
    return persist(processor);
}
Also used : ConnectorEntity(com.redhat.service.bridge.manager.models.ConnectorEntity) Work(com.redhat.service.bridge.manager.models.Work)

Example 4 with Work

use of com.redhat.service.bridge.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class WorkManagerImplTest method completeWhenExists.

@Test
void completeWhenExists() {
    Work work = new Work();
    work.setAttempts(0);
    when(workDAO.findById(anyString())).thenReturn(work);
    manager.complete(work);
    verify(workDAO).deleteById(work.getId());
}
Also used : Work(com.redhat.service.bridge.manager.models.Work) Test(org.junit.jupiter.api.Test)

Example 5 with Work

use of com.redhat.service.bridge.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class WorkManagerImplTest method existsForExistingWork.

@Test
void existsForExistingWork() {
    Work existing = mock(Work.class);
    when(workDAO.findById(anyString())).thenReturn(existing);
    assertThat(manager.exists(new Work())).isTrue();
}
Also used : Work(com.redhat.service.bridge.manager.models.Work) Test(org.junit.jupiter.api.Test)

Aggregations

Work (com.redhat.service.bridge.manager.models.Work)18 Test (org.junit.jupiter.api.Test)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 ConnectorEntity (com.redhat.service.bridge.manager.models.ConnectorEntity)5 Processor (com.redhat.service.bridge.manager.models.Processor)5 ZonedDateTime (java.time.ZonedDateTime)4 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 Connector (com.openshift.cloud.api.connector.models.Connector)2 ConnectorStatusStatus (com.openshift.cloud.api.connector.models.ConnectorStatusStatus)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 Transactional (javax.transaction.Transactional)1