Search in sources :

Example 1 with BridgeLifecycleException

use of com.redhat.service.smartevents.infra.exceptions.definitions.user.BridgeLifecycleException in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class SendToBridgeActionResolverTest method beforeEach.

@BeforeEach
void beforeEach() {
    reset(gatewayConfiguratorServiceMock);
    when(gatewayConfiguratorServiceMock.getBridgeEndpoint(BRIDGE_ID, TEST_CUSTOMER_ID)).thenReturn(BRIDGE_ENDPOINT);
    when(gatewayConfiguratorServiceMock.getBridgeEndpoint(OTHER_BRIDGE_ID, TEST_CUSTOMER_ID)).thenReturn(OTHER_BRIDGE_ENDPOINT);
    when(gatewayConfiguratorServiceMock.getBridgeEndpoint(UNAVAILABLE_BRIDGE_ID, TEST_CUSTOMER_ID)).thenThrow(new BridgeLifecycleException("Unavailable bridge"));
    when(gatewayConfiguratorServiceMock.getBridgeEndpoint(not(or(eq(UNAVAILABLE_BRIDGE_ID), or(eq(BRIDGE_ID), eq(OTHER_BRIDGE_ID)))), eq(TEST_CUSTOMER_ID))).thenThrow(new ItemNotFoundException("Bridge not found"));
    when(gatewayConfiguratorServiceMock.getBridgeEndpoint(any(), not(eq(TEST_CUSTOMER_ID)))).thenThrow(new ItemNotFoundException("Customer not found"));
}
Also used : BridgeLifecycleException(com.redhat.service.smartevents.infra.exceptions.definitions.user.BridgeLifecycleException) ItemNotFoundException(com.redhat.service.smartevents.infra.exceptions.definitions.user.ItemNotFoundException) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with BridgeLifecycleException

use of com.redhat.service.smartevents.infra.exceptions.definitions.user.BridgeLifecycleException in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgesServiceImpl method deleteBridge.

@Override
@Transactional
public void deleteBridge(String id, String customerId) {
    Long processorsCount = processorService.getProcessorsCount(id, customerId);
    ListResult<Processor> hiddenProcessors = processorService.getHiddenProcessors(id, customerId);
    if (processorsCount != hiddenProcessors.getTotal()) {
        // See https://issues.redhat.com/browse/MGDOBR-43
        throw new BridgeLifecycleException("It is not possible to delete a Bridge instance with active Processors.");
    }
    Bridge bridge = findByIdAndCustomerId(id, customerId);
    if (!isBridgeDeletable(bridge)) {
        throw new BridgeLifecycleException("Bridge could only be deleted if its in READY/FAILED state.");
    }
    hiddenProcessors.getItems().forEach(p -> processorService.deleteProcessor(id, p.getId(), customerId));
    LOGGER.info("Bridge with id '{}' for customer '{}' has been marked for deletion", bridge.getId(), bridge.getCustomerId());
    // Bridge deletion and related Work creation should always be in the same transaction
    bridge.setStatus(ManagedResourceStatus.DEPROVISION);
    bridge.setDeletionRequestedAt(ZonedDateTime.now());
    workManager.schedule(bridge);
    metricsService.onOperationStart(bridge, MetricsOperation.DELETE);
    LOGGER.info("Bridge with id '{}' for customer '{}' has been marked for deletion", bridge.getId(), bridge.getCustomerId());
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) BridgeLifecycleException(com.redhat.service.smartevents.infra.exceptions.definitions.user.BridgeLifecycleException) Bridge(com.redhat.service.smartevents.manager.models.Bridge) Transactional(javax.transaction.Transactional)

Example 3 with BridgeLifecycleException

use of com.redhat.service.smartevents.infra.exceptions.definitions.user.BridgeLifecycleException in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceTest method cleanUp.

@BeforeEach
public void cleanUp() {
    reset(bridgesServiceMock);
    reset(processorDAO);
    Bridge bridge = createReadyBridge();
    Processor processor = createReadyProcessor();
    Processor provisioningProcessor = createProvisioningProcessor();
    Processor failedProcessor = createFailedProcessor();
    Processor errorHandlerProcessor = createErrorHandlerProcessor();
    when(bridgesServiceMock.getBridge(DEFAULT_BRIDGE_ID)).thenReturn(bridge);
    when(bridgesServiceMock.getBridge(not(eq(DEFAULT_BRIDGE_ID)))).thenThrow(new ItemNotFoundException("Bridge not found"));
    when(bridgesServiceMock.getBridge(DEFAULT_BRIDGE_ID, DEFAULT_CUSTOMER_ID)).thenReturn(bridge);
    when(bridgesServiceMock.getBridge(not(eq(DEFAULT_BRIDGE_ID)), eq(DEFAULT_CUSTOMER_ID))).thenThrow(new ItemNotFoundException("Bridge not found"));
    when(bridgesServiceMock.getBridge(any(), not(eq(DEFAULT_CUSTOMER_ID)))).thenThrow(new ItemNotFoundException("Bridge not found"));
    when(bridgesServiceMock.getReadyBridge(DEFAULT_BRIDGE_ID, DEFAULT_CUSTOMER_ID)).thenReturn(bridge);
    when(bridgesServiceMock.getReadyBridge(NOT_READY_BRIDGE_ID, DEFAULT_CUSTOMER_ID)).thenThrow(new BridgeLifecycleException("Bridge not ready"));
    when(bridgesServiceMock.getReadyBridge(not(or(eq(DEFAULT_BRIDGE_ID), eq(NOT_READY_BRIDGE_ID))), eq(DEFAULT_CUSTOMER_ID))).thenThrow(new ItemNotFoundException("Bridge not found"));
    when(processorDAO.findById(DEFAULT_PROCESSOR_ID)).thenReturn(processor);
    when(processorDAO.findByBridgeIdAndName(DEFAULT_BRIDGE_ID, DEFAULT_PROCESSOR_NAME)).thenReturn(processor);
    when(processorDAO.findByIdBridgeIdAndCustomerId(DEFAULT_BRIDGE_ID, DEFAULT_PROCESSOR_ID, DEFAULT_CUSTOMER_ID)).thenReturn(processor);
    when(processorDAO.findByIdBridgeIdAndCustomerId(DEFAULT_BRIDGE_ID, PROVISIONING_PROCESSOR_ID, DEFAULT_CUSTOMER_ID)).thenReturn(provisioningProcessor);
    when(processorDAO.findByIdBridgeIdAndCustomerId(DEFAULT_BRIDGE_ID, FAILED_PROCESSOR_ID, DEFAULT_CUSTOMER_ID)).thenReturn(failedProcessor);
    when(processorDAO.findByIdBridgeIdAndCustomerId(DEFAULT_BRIDGE_ID, ERROR_HANDLER_PROCESSOR_ID, DEFAULT_CUSTOMER_ID)).thenReturn(errorHandlerProcessor);
    when(processorDAO.findUserVisibleByBridgeIdAndCustomerId(eq(DEFAULT_BRIDGE_ID), eq(DEFAULT_CUSTOMER_ID), any())).thenReturn(new ListResult<>(List.of(processor, provisioningProcessor, failedProcessor), 0, 3));
    when(processorDAO.countByBridgeIdAndCustomerId(DEFAULT_BRIDGE_ID, DEFAULT_CUSTOMER_ID)).thenReturn(3L);
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) BridgeLifecycleException(com.redhat.service.smartevents.infra.exceptions.definitions.user.BridgeLifecycleException) Bridge(com.redhat.service.smartevents.manager.models.Bridge) ItemNotFoundException(com.redhat.service.smartevents.infra.exceptions.definitions.user.ItemNotFoundException) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

BridgeLifecycleException (com.redhat.service.smartevents.infra.exceptions.definitions.user.BridgeLifecycleException)3 ItemNotFoundException (com.redhat.service.smartevents.infra.exceptions.definitions.user.ItemNotFoundException)2 Bridge (com.redhat.service.smartevents.manager.models.Bridge)2 Processor (com.redhat.service.smartevents.manager.models.Processor)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Transactional (javax.transaction.Transactional)1