Search in sources :

Example 16 with Processor

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

the class ProcessorServiceImpl method getProcessor.

@Transactional
@Override
public Processor getProcessor(String processorId, String bridgeId, String customerId) {
    Bridge bridge = bridgesService.getBridge(bridgeId, customerId);
    Processor processor = processorDAO.findByIdBridgeIdAndCustomerId(processorId, bridge.getId(), bridge.getCustomerId());
    if (processor == null) {
        throw new ItemNotFoundException(String.format("Processor with id '%s' does not exist on Bridge '%s' for customer '%s'", processorId, bridgeId, customerId));
    }
    return processor;
}
Also used : Processor(com.redhat.service.bridge.manager.models.Processor) Bridge(com.redhat.service.bridge.manager.models.Bridge) ItemNotFoundException(com.redhat.service.bridge.infra.exceptions.definitions.user.ItemNotFoundException) Transactional(javax.transaction.Transactional)

Example 17 with Processor

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

the class ProcessorServiceImpl method doDeleteProcessor.

@Transactional
protected Processor doDeleteProcessor(String bridgeId, String processorId, String customerId) {
    Processor processor = processorDAO.findByIdBridgeIdAndCustomerId(processorId, bridgeId, customerId);
    if (processor == null) {
        throw new ItemNotFoundException(String.format("Processor with id '%s' does not exist on bridge '%s' for customer '%s'", processorId, bridgeId, customerId));
    }
    processor.setStatus(ManagedResourceStatus.DEPROVISION);
    LOGGER.info("Processor with id '{}' for customer '{}' on bridge '{}' has been marked for deletion", processor.getId(), processor.getBridge().getCustomerId(), processor.getBridge().getId());
    connectorService.deleteConnectorEntity(processor);
    return processor;
}
Also used : Processor(com.redhat.service.bridge.manager.models.Processor) ItemNotFoundException(com.redhat.service.bridge.infra.exceptions.definitions.user.ItemNotFoundException) Transactional(javax.transaction.Transactional)

Example 18 with Processor

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

the class ProcessorServiceImpl method updateProcessorStatus.

@Transactional
@Override
public Processor updateProcessorStatus(ProcessorDTO processorDTO) {
    Bridge bridge = bridgesService.getBridge(processorDTO.getBridgeId());
    Processor p = processorDAO.findById(processorDTO.getId());
    if (p == null) {
        throw new ItemNotFoundException(String.format("Processor with id '%s' does not exist for Bridge '%s' for customer '%s'", bridge.getId(), bridge.getCustomerId(), processorDTO.getCustomerId()));
    }
    p.setStatus(processorDTO.getStatus());
    p.setModifiedAt(ZonedDateTime.now());
    if (processorDTO.getStatus().equals(ManagedResourceStatus.DELETED)) {
        processorDAO.deleteById(processorDTO.getId());
    }
    if (processorDTO.getStatus().equals(ManagedResourceStatus.READY) && Objects.isNull(p.getPublishedAt())) {
        p.setPublishedAt(ZonedDateTime.now());
    }
    // Update metrics
    meterRegistry.counter("manager.processor.status.change", Collections.singletonList(Tag.of("status", processorDTO.getStatus().toString()))).increment();
    return p;
}
Also used : Processor(com.redhat.service.bridge.manager.models.Processor) Bridge(com.redhat.service.bridge.manager.models.Bridge) ItemNotFoundException(com.redhat.service.bridge.infra.exceptions.definitions.user.ItemNotFoundException) Transactional(javax.transaction.Transactional)

Example 19 with Processor

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

the class ProcessorServiceImpl method deleteProcessor.

@Override
public void deleteProcessor(String bridgeId, String processorId, String customerId) {
    Processor processor = doDeleteProcessor(bridgeId, processorId, customerId);
    workManager.schedule(processor);
}
Also used : Processor(com.redhat.service.bridge.manager.models.Processor)

Example 20 with Processor

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

the class ProcessorWorkerTest method handleWorkProvisioningWithKnownResourceWithConnector.

@ParameterizedTest
@MethodSource("srcHandleWorkProvisioningWithKnownResourceWithConnector")
void handleWorkProvisioningWithKnownResourceWithConnector(ManagedResourceStatus status, ManagedResourceStatus connectorStatusWhenComplete, boolean isWorkComplete) {
    Work work = new Work();
    work.setManagedResourceId(RESOURCE_ID);
    work.setSubmittedAt(ZonedDateTime.now());
    Processor processor = new Processor();
    processor.setStatus(status);
    ConnectorEntity connector = new ConnectorEntity();
    connector.setStatus(ManagedResourceStatus.ACCEPTED);
    when(processorDAO.findById(RESOURCE_ID)).thenReturn(processor);
    when(processorDAO.getEntityManager()).thenReturn(entityManager);
    when(entityManager.merge(processor)).thenReturn(processor);
    when(connectorsDAO.findByProcessorId(processor.getId())).thenReturn(connector);
    doAnswer((i) -> {
        // Emulate ConnectorWorker completing work
        connector.setStatus(connectorStatusWhenComplete);
        return connector;
    }).when(connectorWorker).handleWork(any(Work.class));
    worker.handleWork(work);
    assertThat(processor.getDependencyStatus()).isEqualTo(connectorStatusWhenComplete);
    verify(connectorWorker).handleWork(workArgumentCaptor.capture());
    Work connectorWork = workArgumentCaptor.getValue();
    assertThat(connectorWork).isNotNull();
    assertThat(connectorWork.getId()).isEqualTo(work.getId());
    assertThat(connectorWork.getManagedResourceId()).isEqualTo(connector.getId());
    assertThat(connectorWork.getSubmittedAt()).isEqualTo(work.getSubmittedAt());
    verify(workManager, times(isWorkComplete ? 1 : 0)).complete(any(Work.class));
}
Also used : Processor(com.redhat.service.bridge.manager.models.Processor) Work(com.redhat.service.bridge.manager.models.Work) ConnectorEntity(com.redhat.service.bridge.manager.models.ConnectorEntity) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

Processor (com.redhat.service.bridge.manager.models.Processor)52 Bridge (com.redhat.service.bridge.manager.models.Bridge)34 QuarkusTest (io.quarkus.test.junit.QuarkusTest)32 Test (org.junit.jupiter.api.Test)32 ProcessorRequest (com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest)14 ConnectorEntity (com.redhat.service.bridge.manager.models.ConnectorEntity)9 BaseAction (com.redhat.service.bridge.infra.models.actions.BaseAction)7 ItemNotFoundException (com.redhat.service.bridge.infra.exceptions.definitions.user.ItemNotFoundException)6 QueryInfo (com.redhat.service.bridge.infra.models.QueryInfo)6 Transactional (javax.transaction.Transactional)6 Connector (com.openshift.cloud.api.connector.models.Connector)5 ProcessorDefinition (com.redhat.service.bridge.infra.models.processors.ProcessorDefinition)5 ConnectorStatusStatus (com.openshift.cloud.api.connector.models.ConnectorStatusStatus)4 InternalPlatformException (com.redhat.service.bridge.infra.exceptions.definitions.platform.InternalPlatformException)4 Work (com.redhat.service.bridge.manager.models.Work)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 ZonedDateTime (java.time.ZonedDateTime)3 ConnectorRequest (com.openshift.cloud.api.connector.models.ConnectorRequest)2 AlreadyExistingItemException (com.redhat.service.bridge.infra.exceptions.definitions.user.AlreadyExistingItemException)2 ProcessorDTO (com.redhat.service.bridge.infra.models.dto.ProcessorDTO)2