Search in sources :

Example 1 with ItemNotFoundException

use of com.redhat.service.smartevents.infra.exceptions.definitions.user.ItemNotFoundException 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()));
    }
    if (ManagedResourceStatus.DELETED == processorDTO.getStatus()) {
        p.setStatus(ManagedResourceStatus.DELETED);
        processorDAO.deleteById(processorDTO.getId());
        metricsService.onOperationComplete(p, MetricsOperation.DELETE);
        return p;
    }
    boolean provisioningCallback = p.getStatus() == ManagedResourceStatus.PROVISIONING;
    p.setStatus(processorDTO.getStatus());
    if (ManagedResourceStatus.READY == processorDTO.getStatus()) {
        if (provisioningCallback) {
            if (p.getPublishedAt() == null) {
                p.setPublishedAt(ZonedDateTime.now());
                metricsService.onOperationComplete(p, MetricsOperation.PROVISION);
            } else {
                metricsService.onOperationComplete(p, MetricsOperation.MODIFY);
            }
        }
    }
    return p;
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) Bridge(com.redhat.service.smartevents.manager.models.Bridge) ItemNotFoundException(com.redhat.service.smartevents.infra.exceptions.definitions.user.ItemNotFoundException) Transactional(javax.transaction.Transactional)

Example 2 with ItemNotFoundException

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

the class ProcessorServiceImpl method getProcessor.

@Transactional
@Override
public Processor getProcessor(String bridgeId, String processorId, String customerId) {
    Bridge bridge = bridgesService.getBridge(bridgeId, customerId);
    Processor processor = processorDAO.findByIdBridgeIdAndCustomerId(bridge.getId(), processorId, 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.smartevents.manager.models.Processor) Bridge(com.redhat.service.smartevents.manager.models.Bridge) ItemNotFoundException(com.redhat.service.smartevents.infra.exceptions.definitions.user.ItemNotFoundException) Transactional(javax.transaction.Transactional)

Example 3 with ItemNotFoundException

use of com.redhat.service.smartevents.infra.exceptions.definitions.user.ItemNotFoundException 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 4 with ItemNotFoundException

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

the class SourceResolverTest method beforeEach.

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

Example 5 with ItemNotFoundException

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

the class ProcessorServiceImpl method deleteProcessor.

@Override
@Transactional
public void deleteProcessor(String bridgeId, String processorId, String customerId) {
    Processor processor = processorDAO.findByIdBridgeIdAndCustomerId(bridgeId, processorId, 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));
    }
    if (!isProcessorActionable(processor)) {
        throw new ProcessorLifecycleException("Processor could only be deleted if its in READY/FAILED state.");
    }
    // Processor and Connector deletion and related Work creation should always be in the same transaction
    processor.setStatus(ManagedResourceStatus.DEPROVISION);
    processor.setDeletionRequestedAt(ZonedDateTime.now());
    connectorService.deleteConnectorEntity(processor);
    workManager.schedule(processor);
    metricsService.onOperationStart(processor, MetricsOperation.DELETE);
    LOGGER.info("Processor with id '{}' for customer '{}' on bridge '{}' has been marked for deletion", processor.getId(), processor.getBridge().getCustomerId(), processor.getBridge().getId());
}
Also used : ProcessorLifecycleException(com.redhat.service.smartevents.infra.exceptions.definitions.user.ProcessorLifecycleException) Processor(com.redhat.service.smartevents.manager.models.Processor) ItemNotFoundException(com.redhat.service.smartevents.infra.exceptions.definitions.user.ItemNotFoundException) Transactional(javax.transaction.Transactional)

Aggregations

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