Search in sources :

Example 16 with Bridge

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

the class ProcessorServiceTest method testDeleteConnectorFailureOnKafkaTopicDeletion.

@Test
public void testDeleteConnectorFailureOnKafkaTopicDeletion() {
    Bridge bridge = createPersistBridge(ManagedResourceStatus.READY);
    Processor processor = Fixtures.createProcessor(bridge, "bridgeTestDelete", ManagedResourceStatus.READY);
    ConnectorEntity connector = Fixtures.createConnector(processor, "connectorToBeDeleted", ManagedResourceStatus.READY, "topicName");
    processorDAO.persist(processor);
    connectorsDAO.persist(connector);
    // Emulate successful External Connector creation
    Connector externalConnector = new Connector();
    final ConnectorStatusStatus externalConnectorStatus = new ConnectorStatusStatus();
    externalConnectorStatus.setState(ConnectorState.READY);
    externalConnector.setStatus(externalConnectorStatus);
    when(connectorsApiClient.getConnector(any())).thenReturn(externalConnector);
    // Emulate successful External Connector deletion
    doAnswer(i -> {
        externalConnectorStatus.setState(ConnectorState.DELETED);
        return null;
    }).when(connectorsApiClient).deleteConnector(any());
    doThrow(new InternalPlatformException(createFailureErrorMessageFor("errorTopic"), new RuntimeException("error"))).when(rhoasService).deleteTopicAndRevokeAccessFor(anyString(), any());
    processorService.deleteProcessor(bridge.getId(), processor.getId(), TestConstants.DEFAULT_CUSTOMER_ID);
    reloadAssertProcessorIsInStatus(processor, DEPROVISION);
    waitForProcessorAndConnectorToFail(processor);
    verify(rhoasService, atLeast(1)).deleteTopicAndRevokeAccessFor(eq("topicName"), eq(RhoasTopicAccessType.PRODUCER));
    verify(connectorsApiClient, atLeast(1)).deleteConnector(anyString());
    assertShardAsksForProcessorToBeDeletedDoesNotInclude(processor);
}
Also used : Connector(com.openshift.cloud.api.connector.models.Connector) Processor(com.redhat.service.bridge.manager.models.Processor) InternalPlatformException(com.redhat.service.bridge.infra.exceptions.definitions.platform.InternalPlatformException) ConnectorEntity(com.redhat.service.bridge.manager.models.ConnectorEntity) Bridge(com.redhat.service.bridge.manager.models.Bridge) ConnectorStatusStatus(com.openshift.cloud.api.connector.models.ConnectorStatusStatus) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 17 with Bridge

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

the class BridgesServiceImpl method createBridge.

@Transactional
@Override
public Bridge createBridge(String customerId, BridgeRequest bridgeRequest) {
    if (bridgeDAO.findByNameAndCustomerId(bridgeRequest.getName(), customerId) != null) {
        throw new AlreadyExistingItemException(String.format("Bridge with name '%s' already exists for customer with id '%s'", bridgeRequest.getName(), customerId));
    }
    Bridge bridge = bridgeRequest.toEntity();
    bridge.setStatus(ManagedResourceStatus.ACCEPTED);
    bridge.setSubmittedAt(ZonedDateTime.now(ZoneOffset.UTC));
    bridge.setCustomerId(customerId);
    bridge.setShardId(shardService.getAssignedShardId(bridge.getId()));
    bridgeDAO.persist(bridge);
    rhoasService.createTopicAndGrantAccessFor(getBridgeTopicName(bridge), RhoasTopicAccessType.CONSUMER_AND_PRODUCER);
    LOGGER.info("Bridge with id '{}' has been created for customer '{}'", bridge.getId(), bridge.getCustomerId());
    return bridge;
}
Also used : Bridge(com.redhat.service.bridge.manager.models.Bridge) AlreadyExistingItemException(com.redhat.service.bridge.infra.exceptions.definitions.user.AlreadyExistingItemException) Transactional(javax.transaction.Transactional)

Example 18 with Bridge

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

the class BridgesServiceImpl method deleteBridge.

@Transactional
@Override
public void deleteBridge(String id, String customerId) {
    Long processorsCount = processorService.getProcessorsCount(id, customerId);
    if (processorsCount > 0) {
        // 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);
    bridge.setStatus(ManagedResourceStatus.DEPROVISION);
    LOGGER.info("Bridge with id '{}' for customer '{}' has been marked for deletion", bridge.getId(), bridge.getCustomerId());
}
Also used : BridgeLifecycleException(com.redhat.service.bridge.infra.exceptions.definitions.user.BridgeLifecycleException) Bridge(com.redhat.service.bridge.manager.models.Bridge) Transactional(javax.transaction.Transactional)

Example 19 with Bridge

use of com.redhat.service.bridge.manager.models.Bridge 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 20 with Bridge

use of com.redhat.service.bridge.manager.models.Bridge 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)

Aggregations

Bridge (com.redhat.service.bridge.manager.models.Bridge)60 QuarkusTest (io.quarkus.test.junit.QuarkusTest)46 Test (org.junit.jupiter.api.Test)46 Processor (com.redhat.service.bridge.manager.models.Processor)34 ProcessorRequest (com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest)15 QueryInfo (com.redhat.service.bridge.infra.models.QueryInfo)11 Transactional (javax.transaction.Transactional)8 BridgeRequest (com.redhat.service.bridge.manager.api.models.requests.BridgeRequest)7 ItemNotFoundException (com.redhat.service.bridge.infra.exceptions.definitions.user.ItemNotFoundException)6 BaseAction (com.redhat.service.bridge.infra.models.actions.BaseAction)6 ConnectorEntity (com.redhat.service.bridge.manager.models.ConnectorEntity)6 Connector (com.openshift.cloud.api.connector.models.Connector)5 ConnectorStatusStatus (com.openshift.cloud.api.connector.models.ConnectorStatusStatus)4 InternalPlatformException (com.redhat.service.bridge.infra.exceptions.definitions.platform.InternalPlatformException)4 AlreadyExistingItemException (com.redhat.service.bridge.infra.exceptions.definitions.user.AlreadyExistingItemException)3 ProcessorDefinition (com.redhat.service.bridge.infra.models.processors.ProcessorDefinition)3 ConnectorRequest (com.openshift.cloud.api.connector.models.ConnectorRequest)2 BridgeLifecycleException (com.redhat.service.bridge.infra.exceptions.definitions.user.BridgeLifecycleException)2 BaseFilter (com.redhat.service.bridge.infra.models.filters.BaseFilter)2 ZonedDateTime (java.time.ZonedDateTime)2