Search in sources :

Example 1 with ConnectorRequest

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

the class ConnectorsApiClientImpl method createConnector.

@Override
public Connector createConnector(ConnectorEntity connectorEntity) {
    ConnectorRequest createConnectorRequest = new ConnectorRequest();
    String newConnectorName = connectorEntity.getName();
    createConnectorRequest.setName(newConnectorName);
    DeploymentLocation deploymentLocation = new DeploymentLocation();
    deploymentLocation.setKind("addon");
    deploymentLocation.setClusterId(mcClusterId);
    createConnectorRequest.setDeploymentLocation(deploymentLocation);
    String connectorType = connectorEntity.getConnectorType();
    JsonNode payload = connectorEntity.getDefinition();
    createConnectorRequest.setConnectorTypeId(connectorType);
    createConnectorRequest.setConnector(payload);
    ServiceAccount serviceAccount = new ServiceAccount();
    serviceAccount.setClientId(serviceAccountId);
    serviceAccount.setClientSecret(serviceAccountSecret);
    createConnectorRequest.setServiceAccount(serviceAccount);
    KafkaConnectionSettings kafka = new KafkaConnectionSettings();
    kafka.setUrl(kafkaBootstrapServer);
    // https://issues.redhat.com/browse/MGDOBR-198
    // this is currently ignored in the Connectors API
    kafka.setId(KAFKA_ID_IGNORED);
    createConnectorRequest.setKafka(kafka);
    return createConnector(createConnectorRequest);
}
Also used : ServiceAccount(com.openshift.cloud.api.connector.models.ServiceAccount) ConnectorRequest(com.openshift.cloud.api.connector.models.ConnectorRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) DeploymentLocation(com.openshift.cloud.api.connector.models.DeploymentLocation) KafkaConnectionSettings(com.openshift.cloud.api.connector.models.KafkaConnectionSettings)

Example 2 with ConnectorRequest

use of com.openshift.cloud.api.connector.models.ConnectorRequest 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.getNamespaceId()).isEqualTo(mcNamespaceId);
    assertThat(connectorRequest.getConnectorTypeId()).isEqualTo(TEST_CONNECTOR_TYPE_ID);
    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 3 with ConnectorRequest

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

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

the class ConnectorsApiClientImpl method createConnector.

@Override
public Connector createConnector(ConnectorEntity connectorEntity) {
    ConnectorRequest createConnectorRequest = new ConnectorRequest();
    String newConnectorName = connectorEntity.getName();
    createConnectorRequest.setName(newConnectorName);
    createConnectorRequest.setNamespaceId(mcNamespaceId);
    String connectorTypeId = connectorEntity.getConnectorTypeId();
    JsonNode payload = connectorEntity.getDefinition();
    createConnectorRequest.setConnectorTypeId(connectorTypeId);
    createConnectorRequest.setConnector(payload);
    ServiceAccount serviceAccount = new ServiceAccount();
    serviceAccount.setClientId(serviceAccountId);
    serviceAccount.setClientSecret(serviceAccountSecret);
    createConnectorRequest.setServiceAccount(serviceAccount);
    KafkaConnectionSettings kafka = new KafkaConnectionSettings();
    kafka.setUrl(kafkaBootstrapServer);
    // https://issues.redhat.com/browse/MGDOBR-198
    // this is currently ignored in the Connectors API
    kafka.setId(KAFKA_ID_IGNORED);
    createConnectorRequest.setKafka(kafka);
    return createConnector(createConnectorRequest);
}
Also used : ServiceAccount(com.openshift.cloud.api.connector.models.ServiceAccount) ConnectorRequest(com.openshift.cloud.api.connector.models.ConnectorRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) KafkaConnectionSettings(com.openshift.cloud.api.connector.models.KafkaConnectionSettings)

Example 5 with ConnectorRequest

use of com.openshift.cloud.api.connector.models.ConnectorRequest 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)

Aggregations

ConnectorRequest (com.openshift.cloud.api.connector.models.ConnectorRequest)6 Connector (com.openshift.cloud.api.connector.models.Connector)4 QuarkusTest (io.quarkus.test.junit.QuarkusTest)4 Test (org.junit.jupiter.api.Test)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ConnectorStatusStatus (com.openshift.cloud.api.connector.models.ConnectorStatusStatus)2 KafkaConnectionSettings (com.openshift.cloud.api.connector.models.KafkaConnectionSettings)2 ServiceAccount (com.openshift.cloud.api.connector.models.ServiceAccount)2 Topic (com.openshift.cloud.api.kas.auth.models.Topic)2 DeploymentLocation (com.openshift.cloud.api.connector.models.DeploymentLocation)1 BaseAction (com.redhat.service.bridge.infra.models.actions.BaseAction)1 ProcessorRequest (com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest)1 Bridge (com.redhat.service.bridge.manager.models.Bridge)1 ConnectorEntity (com.redhat.service.bridge.manager.models.ConnectorEntity)1 Processor (com.redhat.service.bridge.manager.models.Processor)1 Action (com.redhat.service.smartevents.infra.models.gateways.Action)1 ProcessorRequest (com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest)1 Bridge (com.redhat.service.smartevents.manager.models.Bridge)1 ConnectorEntity (com.redhat.service.smartevents.manager.models.ConnectorEntity)1 Processor (com.redhat.service.smartevents.manager.models.Processor)1