Search in sources :

Example 21 with Connector

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

the class ConnectorsApiClientTest method doCreateConnectorApi.

@Test
void doCreateConnectorApi() throws ApiException {
    when(connectorsApi.createConnector(any(), any())).thenReturn(testConnector());
    Connector connector = connectorsApiClient.createConnector(testConnectorEntity());
    assertThat(connector).isNotNull();
    assertThat(connector.getId()).isEqualTo(TEST_CONNECTOR_EXTERNAL_ID);
    ArgumentCaptor<ConnectorRequest> requestArgumentCaptor = ArgumentCaptor.forClass(ConnectorRequest.class);
    verify(connectorsApi).createConnector(eq(true), requestArgumentCaptor.capture());
    ConnectorRequest connectorRequest = requestArgumentCaptor.getValue();
    assertThat(connectorRequest).isNotNull();
    assertThat(connectorRequest.getName()).isEqualTo(TEST_CONNECTOR_NAME);
    assertThat(connectorRequest.getDeploymentLocation().getKind()).isEqualTo("addon");
    assertThat(connectorRequest.getDeploymentLocation().getClusterId()).isEqualTo(mcClusterId);
    assertThat(connectorRequest.getConnectorTypeId()).isEqualTo(TEST_CONNECTOR_TYPE);
    assertThat(connectorRequest.getServiceAccount().getClientId()).isEqualTo(serviceAccountId);
    assertThat(connectorRequest.getServiceAccount().getClientSecret()).isEqualTo(serviceAccountSecret);
}
Also used : Connector(com.openshift.cloud.api.connector.models.Connector) ConnectorRequest(com.openshift.cloud.api.connector.models.ConnectorRequest) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 22 with Connector

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

the class ConnectorWorkerTest method handleWorkDeletingWithKnownResourceMultiplePasses.

@ParameterizedTest
@EnumSource(value = ManagedResourceStatus.class, names = { "DEPROVISION", "DELETING" })
void handleWorkDeletingWithKnownResourceMultiplePasses(ManagedResourceStatus status) {
    Work work = new Work();
    work.setManagedResourceId(RESOURCE_ID);
    work.setSubmittedAt(ZonedDateTime.now());
    ConnectorEntity connectorEntity = spy(new ConnectorEntity());
    connectorEntity.setStatus(status);
    connectorEntity.setTopicName("topicName");
    connectorEntity.setConnectorExternalId("connectorExternalId");
    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 initially be available before it is deleted
    when(connectorsApi.getConnector(connectorEntity)).thenReturn(connector, null);
    worker.handleWork(work);
    assertThat(connectorEntity.getStatus()).isEqualTo(ManagedResourceStatus.DELETING);
    assertThat(connectorEntity.getDependencyStatus()).isEqualTo(ManagedResourceStatus.DELETING);
    verify(rhoasService, never()).deleteTopicAndRevokeAccessFor(connectorEntity.getTopicName(), RhoasTopicAccessType.PRODUCER);
    verify(connectorsApi).deleteConnector(connectorEntity.getConnectorExternalId());
    // This emulates a subsequent invocation by WorkManager
    worker.handleWork(work);
    assertThat(connectorEntity.getStatus()).isEqualTo(ManagedResourceStatus.DELETED);
    assertThat(connectorEntity.getDependencyStatus()).isEqualTo(ManagedResourceStatus.DELETED);
    verify(rhoasService).deleteTopicAndRevokeAccessFor(connectorEntity.getTopicName(), RhoasTopicAccessType.PRODUCER);
    verify(connectorsDAO).deleteById(connectorEntity.getId());
    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 23 with Connector

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

the class ManagedConnectorServiceApplication method createSlackConnector.

private Connector createSlackConnector() throws Exception {
    ConnectorsApi apiInstance = createConnectorsAPI();
    // Boolean | Perform the action in an asynchronous manner
    // Connector | Connector data
    Connector createConnectorRequest = new Connector();
    ConnectorAllOfMetadata metadata = new ConnectorAllOfMetadata();
    metadata.setName("openbridge-slack-connector");
    metadata.setKafkaId("kafkaId-ignored");
    createConnectorRequest.setMetadata(metadata);
    AddonClusterTarget deploymentLocation = new AddonClusterTarget();
    deploymentLocation.setKind("addon");
    deploymentLocation.setClusterId("c4ovtrsldcav5gaeqkn0");
    createConnectorRequest.setDeploymentLocation(deploymentLocation);
    createConnectorRequest.setConnectorTypeId("slack_sink_0.1");
    KafkaConnectionSettings kafka = new KafkaConnectionSettings();
    kafka.setBootstrapServer(kafkaUrl);
    kafka.setClientId(serviceAccountId);
    kafka.setClientSecret(serviceAccountSecret);
    createConnectorRequest.setKafka(kafka);
    ConnectorSpec connectorSpec = new ConnectorSpec();
    ConnectorSpecKafka connectorSpecKafka = new ConnectorSpecKafka();
    connectorSpecKafka.setTopic("slacktopic");
    connectorSpec.setConnectorSpecKafka(connectorSpecKafka);
    SlackConnector connector = new SlackConnector();
    connector.setChannel("mc");
    connector.setWebhookUrl(webhookUrl);
    connectorSpec.setConnector(connector);
    createConnectorRequest.setConnectorSpec(connectorSpec);
    try {
        Connector connectorResult = apiInstance.createConnector(true, createConnectorRequest);
        System.out.println("Connector created: " + connectorResult);
        return connectorResult;
    } catch (WebApplicationException e) {
        Response response = e.getResponse();
        System.out.println("Error code: " + response.getStatus());
        ByteArrayInputStream arrayInputStream = (ByteArrayInputStream) response.getEntity();
        Scanner scanner = new Scanner(arrayInputStream);
        // To read all scanner content in one String
        scanner.useDelimiter("\\Z");
        String data = "";
        if (scanner.hasNext()) {
            data = scanner.next();
        }
        System.out.println(data);
        throw e;
    }
}
Also used : SlackConnector(com.redhat.service.dto.request.SlackConnector) Connector(com.openshift.cloud.api.connector.models.Connector) Scanner(java.util.Scanner) ConnectorAllOfMetadata(com.openshift.cloud.api.connector.models.ConnectorAllOfMetadata) ConnectorSpecKafka(com.redhat.service.dto.request.ConnectorSpecKafka) WebApplicationException(javax.ws.rs.WebApplicationException) ConnectorsApi(com.openshift.cloud.api.connector.ConnectorsApi) ConnectorSpec(com.redhat.service.dto.request.ConnectorSpec) HttpResponse(java.net.http.HttpResponse) Response(javax.ws.rs.core.Response) SlackConnector(com.redhat.service.dto.request.SlackConnector) ByteArrayInputStream(java.io.ByteArrayInputStream) AddonClusterTarget(com.openshift.cloud.api.connector.models.AddonClusterTarget) KafkaConnectionSettings(com.openshift.cloud.api.connector.models.KafkaConnectionSettings)

Example 24 with Connector

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

the class ProcessorServiceTest method createConnectorFailureOnKafkaTopicCreation.

@Test
public void createConnectorFailureOnKafkaTopicCreation() {
    Bridge b = createPersistBridge(ManagedResourceStatus.READY);
    BaseAction slackAction = createSlackAction();
    ProcessorRequest processorRequest = new ProcessorRequest("ManagedConnectorProcessor", slackAction);
    when(rhoasService.createTopicAndGrantAccessFor(anyString(), any())).thenThrow(new InternalPlatformException(createFailureErrorMessageFor("errorTopic"), new RuntimeException("error")));
    when(connectorsApiClient.createConnector(any(ConnectorRequest.class))).thenReturn(new Connector());
    Processor processor = processorService.createProcessor(b.getId(), b.getCustomerId(), processorRequest);
    waitForProcessorAndConnectorToFail(processor);
    verify(rhoasService, atLeast(1)).createTopicAndGrantAccessFor(anyString(), eq(RhoasTopicAccessType.PRODUCER));
    verify(connectorsApiClient, never()).createConnector(any(ConnectorRequest.class));
}
Also used : Connector(com.openshift.cloud.api.connector.models.Connector) ConnectorRequest(com.openshift.cloud.api.connector.models.ConnectorRequest) Processor(com.redhat.service.bridge.manager.models.Processor) InternalPlatformException(com.redhat.service.bridge.infra.exceptions.definitions.platform.InternalPlatformException) ProcessorRequest(com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest) BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) Bridge(com.redhat.service.bridge.manager.models.Bridge) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 25 with Connector

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

the class ProcessorServiceTest method createConnectorSuccess.

@Test
void createConnectorSuccess() {
    Bridge b = createPersistBridge(ManagedResourceStatus.READY);
    BaseAction 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);
    // Emulate the connector not being found when first looked up, to force provisioning
    when(connectorsApiClient.getConnector(any())).thenReturn(null, 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(), 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(), String.format("OpenBridge-slack_sink_0.1-%s", processor.getId()));
        assertThat(connector).isNotNull();
        assertThat(connector.getError()).isNullOrEmpty();
        assertThat(connector.getStatus()).isEqualTo(ManagedResourceStatus.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) ConnectorRequest(com.openshift.cloud.api.connector.models.ConnectorRequest) Processor(com.redhat.service.bridge.manager.models.Processor) ProcessorRequest(com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest) ConnectorEntity(com.redhat.service.bridge.manager.models.ConnectorEntity) BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) Topic(com.openshift.cloud.api.kas.auth.models.Topic) 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)

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