Search in sources :

Example 11 with Connector

use of com.openshift.cloud.api.connector.models.Connector in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ConnectorWorker method deleteDependencies.

@Override
public ConnectorEntity deleteDependencies(Work work, ConnectorEntity connectorEntity) {
    LOGGER.info("Destroying dependencies for '{}' [{}]", connectorEntity.getName(), connectorEntity.getId());
    // This is idempotent as it gets overridden later depending on actual state
    connectorEntity.setStatus(ManagedResourceStatus.DELETING);
    connectorEntity.setDependencyStatus(ManagedResourceStatus.DELETING);
    connectorEntity = persist(connectorEntity);
    // Steps, in reverse order...
    // Step 3 - Connector has been deleted and does not exist: Clean up Kafka Topic
    String connectorExternalId = connectorEntity.getConnectorExternalId();
    if (Objects.isNull(connectorExternalId)) {
        return deleteTopic(connectorEntity);
    }
    Connector connector = connectorsApi.getConnector(connectorExternalId);
    if (Objects.isNull(connector)) {
        return deleteTopic(connectorEntity);
    }
    ConnectorStatusStatus status = connector.getStatus();
    if (Objects.isNull(status)) {
        return connectorEntity;
    }
    if (status.getState() == ConnectorState.DELETED) {
        LOGGER.debug("Managed Connector for '{}' [{}] has status 'DELETED'. Continuing with deletion of Kafka Topic..", connectorEntity.getName(), connectorEntity.getId());
        return deleteTopic(connectorEntity);
    }
    // Step 2 - Delete Connector
    LOGGER.debug("Deleting Managed Connector for '{}' [{}]", connectorEntity.getName(), connectorEntity.getId());
    connectorsApi.deleteConnector(connectorEntity.getConnectorExternalId());
    return connectorEntity;
}
Also used : Connector(com.openshift.cloud.api.connector.models.Connector) ConnectorStatusStatus(com.openshift.cloud.api.connector.models.ConnectorStatusStatus)

Example 12 with Connector

use of com.openshift.cloud.api.connector.models.Connector in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceConnectorTest method testDeleteConnectorFailureOnKafkaTopicDeletion.

@Test
void testDeleteConnectorFailureOnKafkaTopicDeletion() {
    Bridge bridge = createPersistBridge(READY);
    Processor processor = createPersistProcessor(bridge, READY);
    createPersistentConnector(processor, READY);
    // 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(RhoasServiceImpl.createFailureErrorMessageFor("errorTopic"), new RuntimeException("error"))).when(rhoasService).deleteTopicAndRevokeAccessFor(anyString(), any());
    processorService.deleteProcessor(bridge.getId(), processor.getId(), DEFAULT_CUSTOMER_ID);
    reloadAssertProcessorIsInStatus(processor, DEPROVISION);
    waitForProcessorAndConnectorToFail(processor);
    verify(rhoasService, atLeast(1)).deleteTopicAndRevokeAccessFor(TestConstants.DEFAULT_KAFKA_TOPIC, RhoasTopicAccessType.PRODUCER);
    verify(connectorsApiClient, atLeast(1)).deleteConnector(anyString());
    assertShardAsksForProcessorToBeDeletedDoesNotInclude(processor);
}
Also used : Connector(com.openshift.cloud.api.connector.models.Connector) Processor(com.redhat.service.smartevents.manager.models.Processor) InternalPlatformException(com.redhat.service.smartevents.infra.exceptions.definitions.platform.InternalPlatformException) Bridge(com.redhat.service.smartevents.manager.models.Bridge) ConnectorStatusStatus(com.openshift.cloud.api.connector.models.ConnectorStatusStatus) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 13 with Connector

use of com.openshift.cloud.api.connector.models.Connector in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceConnectorTest method testDeleteConnectorFailureOnExternalConnectorDestruction.

@Test
void testDeleteConnectorFailureOnExternalConnectorDestruction() {
    Bridge bridge = createPersistBridge(READY);
    Processor processor = createPersistProcessor(bridge, READY);
    createPersistentConnector(processor, READY);
    // 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);
    doThrow(new InternalPlatformException(RhoasServiceImpl.createFailureErrorMessageFor("errorDeletingConnector"), new RuntimeException("error"))).when(connectorsApiClient).deleteConnector(anyString());
    processorService.deleteProcessor(bridge.getId(), processor.getId(), DEFAULT_CUSTOMER_ID);
    reloadAssertProcessorIsInStatus(processor, DEPROVISION);
    waitForProcessorAndConnectorToFail(processor);
    verify(rhoasService, never()).deleteTopicAndRevokeAccessFor(any(), any());
    verify(connectorsApiClient, atLeast(1)).deleteConnector(anyString());
    assertShardAsksForProcessorToBeDeletedDoesNotInclude(processor);
}
Also used : Connector(com.openshift.cloud.api.connector.models.Connector) Processor(com.redhat.service.smartevents.manager.models.Processor) InternalPlatformException(com.redhat.service.smartevents.infra.exceptions.definitions.platform.InternalPlatformException) Bridge(com.redhat.service.smartevents.manager.models.Bridge) ConnectorStatusStatus(com.openshift.cloud.api.connector.models.ConnectorStatusStatus) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 14 with Connector

use of com.openshift.cloud.api.connector.models.Connector in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceConnectorTest method createConnectorSuccess.

@Test
void createConnectorSuccess() {
    Bridge b = createPersistBridge(READY);
    Action slackAction = createSlackAction();
    ProcessorRequest processorRequest = new ProcessorRequest("ManagedConnectorProcessor", slackAction);
    // Emulate successful External Connector creation
    Connector externalConnector = stubbedExternalConnector("connectorExternalId");
    ConnectorStatusStatus externalConnectorStatus = new ConnectorStatusStatus();
    externalConnectorStatus.setState(ConnectorState.READY);
    externalConnector.setStatus(externalConnectorStatus);
    when(connectorsApiClient.getConnector(any())).thenReturn(externalConnector);
    when(connectorsApiClient.createConnector(any(ConnectorEntity.class))).thenCallRealMethod();
    when(connectorsApiClient.createConnector(any(ConnectorRequest.class))).thenReturn(externalConnector);
    when(rhoasService.createTopicAndGrantAccessFor(anyString(), any())).thenReturn(new Topic());
    Processor processor = processorService.createProcessor(b.getId(), b.getCustomerId(), b.getOwner(), processorRequest);
    // There will be 2 re-tries at 5s each. Add 5s to be certain everything completes.
    await().atMost(15, SECONDS).untilAsserted(() -> {
        ConnectorEntity connector = connectorsDAO.findByProcessorIdAndName(processor.getId(), resourceNamesProvider.getProcessorConnectorName(processor.getId()));
        assertThat(connector).isNotNull();
        assertThat(connector.getError()).isNullOrEmpty();
        assertThat(connector.getStatus()).isEqualTo(READY);
    });
    verify(rhoasService, atLeast(1)).createTopicAndGrantAccessFor(anyString(), eq(RhoasTopicAccessType.PRODUCER));
    ArgumentCaptor<ConnectorRequest> connectorCaptor = ArgumentCaptor.forClass(ConnectorRequest.class);
    verify(connectorsApiClient).createConnector(connectorCaptor.capture());
    ConnectorRequest calledConnector = connectorCaptor.getValue();
    assertThat(calledConnector.getKafka()).isNotNull();
}
Also used : Connector(com.openshift.cloud.api.connector.models.Connector) Action(com.redhat.service.smartevents.infra.models.gateways.Action) SlackAction(com.redhat.service.smartevents.processor.actions.slack.SlackAction) ConnectorRequest(com.openshift.cloud.api.connector.models.ConnectorRequest) Processor(com.redhat.service.smartevents.manager.models.Processor) ProcessorRequest(com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest) ConnectorEntity(com.redhat.service.smartevents.manager.models.ConnectorEntity) Topic(com.openshift.cloud.api.kas.auth.models.Topic) Bridge(com.redhat.service.smartevents.manager.models.Bridge) ConnectorStatusStatus(com.openshift.cloud.api.connector.models.ConnectorStatusStatus) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 15 with Connector

use of com.openshift.cloud.api.connector.models.Connector in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceConnectorTest method testDeleteRequestedConnectorSuccess.

@Test
void testDeleteRequestedConnectorSuccess() {
    Bridge bridge = createPersistBridge(READY);
    Processor processor = createPersistProcessor(bridge, READY);
    createPersistentConnector(processor, READY);
    // 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());
    processorService.deleteProcessor(bridge.getId(), processor.getId(), DEFAULT_CUSTOMER_ID);
    reloadAssertProcessorIsInStatus(processor, DEPROVISION);
    waitForConnectorToBeDeleted(bridge, processor);
    verify(rhoasService).deleteTopicAndRevokeAccessFor(TestConstants.DEFAULT_KAFKA_TOPIC, RhoasTopicAccessType.PRODUCER);
    verify(connectorsApiClient).deleteConnector("connectorExternalId");
    assertShardAsksForProcessorToBeDeletedIncludes(processor);
}
Also used : Connector(com.openshift.cloud.api.connector.models.Connector) Processor(com.redhat.service.smartevents.manager.models.Processor) Bridge(com.redhat.service.smartevents.manager.models.Bridge) ConnectorStatusStatus(com.openshift.cloud.api.connector.models.ConnectorStatusStatus) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Aggregations

Connector (com.openshift.cloud.api.connector.models.Connector)29 ConnectorStatusStatus (com.openshift.cloud.api.connector.models.ConnectorStatusStatus)16 QuarkusTest (io.quarkus.test.junit.QuarkusTest)12 Test (org.junit.jupiter.api.Test)12 Bridge (com.redhat.service.smartevents.manager.models.Bridge)7 Processor (com.redhat.service.smartevents.manager.models.Processor)7 ConnectorRequest (com.openshift.cloud.api.connector.models.ConnectorRequest)6 ConnectorEntity (com.redhat.service.bridge.manager.models.ConnectorEntity)6 Bridge (com.redhat.service.bridge.manager.models.Bridge)5 Processor (com.redhat.service.bridge.manager.models.Processor)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 InternalPlatformException (com.redhat.service.bridge.infra.exceptions.definitions.platform.InternalPlatformException)3 SlackConnector (com.redhat.service.dto.request.SlackConnector)3 InternalPlatformException (com.redhat.service.smartevents.infra.exceptions.definitions.platform.InternalPlatformException)3 ConnectorEntity (com.redhat.service.smartevents.manager.models.ConnectorEntity)3 ConnectorsApi (com.openshift.cloud.api.connector.ConnectorsApi)2 Topic (com.openshift.cloud.api.kas.auth.models.Topic)2 BaseAction (com.redhat.service.bridge.infra.models.actions.BaseAction)2 ProcessorRequest (com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest)2 Work (com.redhat.service.bridge.manager.models.Work)2