Search in sources :

Example 1 with ConnectorsApi

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

the class ManagedConnectorServiceApplication method pollSlackConnector.

private Connector pollSlackConnector(Connector connector) throws InterruptedException, ApiException {
    ApiClient defaultClient = Configuration.getDefaultApiClient();
    defaultClient.setBasePath(baseUrl);
    HttpBearerAuth Bearer = (HttpBearerAuth) defaultClient.getAuthentication("Bearer");
    Bearer.setBearerToken(bearerToken);
    ConnectorsApi connectorsAPI = createConnectorsAPI();
    Connector fetchedConnector = connectorsAPI.getConnector(connector.getId(), "");
    System.out.println(fetchedConnector.getStatus());
    Thread.sleep(5000);
    return fetchedConnector;
}
Also used : SlackConnector(com.redhat.service.dto.request.SlackConnector) Connector(com.openshift.cloud.api.connector.models.Connector) HttpBearerAuth(com.openshift.cloud.api.connector.invoker.auth.HttpBearerAuth) ConnectorsApi(com.openshift.cloud.api.connector.ConnectorsApi) ApiClient(com.openshift.cloud.api.connector.invoker.ApiClient)

Example 2 with ConnectorsApi

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

the class ManagedConnectorServiceApplication method createConnectorsAPI.

private ConnectorsApi createConnectorsAPI() {
    ApiClient defaultClient = Configuration.getDefaultApiClient();
    defaultClient.setBasePath(baseUrl);
    HttpBearerAuth Bearer = (HttpBearerAuth) defaultClient.getAuthentication("Bearer");
    Bearer.setBearerToken(bearerToken);
    return new ConnectorsApi(defaultClient);
}
Also used : HttpBearerAuth(com.openshift.cloud.api.connector.invoker.auth.HttpBearerAuth) ConnectorsApi(com.openshift.cloud.api.connector.ConnectorsApi) ApiClient(com.openshift.cloud.api.connector.invoker.ApiClient)

Example 3 with ConnectorsApi

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

Aggregations

ConnectorsApi (com.openshift.cloud.api.connector.ConnectorsApi)3 ApiClient (com.openshift.cloud.api.connector.invoker.ApiClient)2 HttpBearerAuth (com.openshift.cloud.api.connector.invoker.auth.HttpBearerAuth)2 Connector (com.openshift.cloud.api.connector.models.Connector)2 SlackConnector (com.redhat.service.dto.request.SlackConnector)2 AddonClusterTarget (com.openshift.cloud.api.connector.models.AddonClusterTarget)1 ConnectorAllOfMetadata (com.openshift.cloud.api.connector.models.ConnectorAllOfMetadata)1 KafkaConnectionSettings (com.openshift.cloud.api.connector.models.KafkaConnectionSettings)1 ConnectorSpec (com.redhat.service.dto.request.ConnectorSpec)1 ConnectorSpecKafka (com.redhat.service.dto.request.ConnectorSpecKafka)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HttpResponse (java.net.http.HttpResponse)1 Scanner (java.util.Scanner)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Response (javax.ws.rs.core.Response)1