Search in sources :

Example 1 with Connector

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

the class ProcessorServiceTest method testDeleteConnectorFailureOnExternalConnectorDestruction.

@Test
public void testDeleteConnectorFailureOnExternalConnectorDestruction() {
    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);
    doThrow(new InternalPlatformException(createFailureErrorMessageFor("errorDeletingConnector"), new RuntimeException("error"))).when(connectorsApiClient).deleteConnector(anyString());
    processorService.deleteProcessor(bridge.getId(), processor.getId(), TestConstants.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.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 2 with Connector

use of com.openshift.cloud.api.connector.models.Connector 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 3 with Connector

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

the class ConnectorWorker method deployConnector.

private ConnectorEntity deployConnector(ConnectorEntity connectorEntity) {
    // Creation is performed asynchronously. The returned Connector is a place-holder.
    Connector connector = connectorsApi.createConnector(connectorEntity);
    connectorEntity.setConnectorExternalId(connector.getId());
    return persist(connectorEntity);
}
Also used : Connector(com.openshift.cloud.api.connector.models.Connector)

Example 4 with Connector

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

the class ConnectorWorkerTest method handleWorkProvisioningWithKnownResourceMultiplePasses.

@ParameterizedTest
@EnumSource(value = ManagedResourceStatus.class, names = { "ACCEPTED", "PROVISIONING" })
void handleWorkProvisioningWithKnownResourceMultiplePasses(ManagedResourceStatus status) {
    Work work = new Work();
    work.setManagedResourceId(RESOURCE_ID);
    work.setSubmittedAt(ZonedDateTime.now());
    ConnectorEntity connectorEntity = spy(new ConnectorEntity());
    connectorEntity.setStatus(status);
    Connector connector = new Connector();
    connector.setStatus(new ConnectorStatusStatus().state(ConnectorState.READY));
    when(connectorsDAO.findById(RESOURCE_ID)).thenReturn(connectorEntity);
    when(connectorsDAO.getEntityManager()).thenReturn(entityManager);
    when(entityManager.merge(connectorEntity)).thenReturn(connectorEntity);
    // Managed Connector will not be available immediately
    when(connectorsApi.getConnector(connectorEntity)).thenReturn(null, connector);
    worker.handleWork(work);
    verify(rhoasService).createTopicAndGrantAccessFor(connectorEntity.getTopicName(), RhoasTopicAccessType.PRODUCER);
    verify(connectorsApi).createConnector(connectorEntity);
    assertThat(connectorEntity.getStatus()).isEqualTo(ManagedResourceStatus.PROVISIONING);
    assertThat(connectorEntity.getDependencyStatus()).isEqualTo(ManagedResourceStatus.PROVISIONING);
    // This emulates a subsequent invocation by WorkManager
    worker.handleWork(work);
    verify(rhoasService, times(2)).createTopicAndGrantAccessFor(connectorEntity.getTopicName(), RhoasTopicAccessType.PRODUCER);
    verify(connectorsApi, atMostOnce()).createConnector(connectorEntity);
    assertThat(connectorEntity.getPublishedAt()).isNotNull();
    assertThat(connectorEntity.getStatus()).isEqualTo(ManagedResourceStatus.READY);
    assertThat(connectorEntity.getDependencyStatus()).isEqualTo(ManagedResourceStatus.READY);
    verify(workManager, never()).complete(work);
    verify(connectorEntity, atLeastOnce()).setModifiedAt(any(ZonedDateTime.class));
}
Also used : Connector(com.openshift.cloud.api.connector.models.Connector) ZonedDateTime(java.time.ZonedDateTime) Work(com.redhat.service.bridge.manager.models.Work) ConnectorEntity(com.redhat.service.bridge.manager.models.ConnectorEntity) ConnectorStatusStatus(com.openshift.cloud.api.connector.models.ConnectorStatusStatus) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with Connector

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

the class ConnectorsApiClientTest method testConnector.

private Connector testConnector() {
    Connector connector = new Connector();
    connector.setId(TEST_CONNECTOR_EXTERNAL_ID);
    return connector;
}
Also used : Connector(com.openshift.cloud.api.connector.models.Connector)

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