Search in sources :

Example 6 with Connector

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

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

the class ManagedConnectorServiceApplication method main.

public static void main(String[] args) throws Exception {
    if (args.length != 6) {
        System.out.println("Usage: arg <OFFLINE_TOKEN> " + "<MC_BASE_URL> " + "<KAFKA_URL> " + "<SERVICE_ACCOUNT_ID> " + "<SERVICE_ACCOUNT_SECRET> " + "<SLACK_WEBHOOK_URL>");
        System.exit(1);
    }
    ManagedConnectorServiceApplication managedConnectorServiceApplication = new ManagedConnectorServiceApplication();
    managedConnectorServiceApplication.offlineToken = args[0];
    managedConnectorServiceApplication.baseUrl = args[1];
    managedConnectorServiceApplication.kafkaUrl = args[2];
    managedConnectorServiceApplication.serviceAccountId = args[3];
    managedConnectorServiceApplication.serviceAccountSecret = args[4];
    managedConnectorServiceApplication.webhookUrl = args[5];
    managedConnectorServiceApplication.bearerToken = managedConnectorServiceApplication.bearerTokenFromOfflineToken(managedConnectorServiceApplication.offlineToken);
    Connector slackConnector = managedConnectorServiceApplication.createSlackConnector();
    do {
        slackConnector = managedConnectorServiceApplication.pollSlackConnector(slackConnector);
    } while (!"ready".equals(slackConnector.getStatus()));
}
Also used : SlackConnector(com.redhat.service.dto.request.SlackConnector) Connector(com.openshift.cloud.api.connector.models.Connector)

Example 8 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.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 9 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 10 with Connector

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

the class ConnectorWorker method createDependencies.

@Override
public ConnectorEntity createDependencies(Work work, ConnectorEntity connectorEntity) {
    LOGGER.info("Creating dependencies for '{}' [{}]", connectorEntity.getName(), connectorEntity.getId());
    // Transition resource to PREPARING status.
    // There is no work handled by the Operator. Connectors move from PREPARING to READY.
    connectorEntity.setStatus(ManagedResourceStatus.PREPARING);
    // This is idempotent as it gets overridden later depending on actual state
    connectorEntity.setDependencyStatus(ManagedResourceStatus.PROVISIONING);
    connectorEntity = persist(connectorEntity);
    // Step 1 - Create Kafka Topic
    LOGGER.debug("Creating Kafka Topic for '{}' [{}]", connectorEntity.getName(), connectorEntity.getId());
    rhoasService.createTopicAndGrantAccessFor(connectorEntity.getTopicName(), connectorTopicAccessType(connectorEntity));
    // Step 2 - Create Connector
    LOGGER.debug("Creating Managed Connector for '{}' [{}]", connectorEntity.getName(), connectorEntity.getId());
    Optional<Connector> optConnector = Optional.of(connectorEntity).filter(ce -> Objects.nonNull(ce.getConnectorExternalId()) && !ce.getConnectorExternalId().isBlank()).map(ConnectorEntity::getConnectorExternalId).map(connectorsApi::getConnector);
    if (optConnector.isEmpty()) {
        LOGGER.debug("Managed Connector for '{}' [{}] not found. Provisioning...", connectorEntity.getName(), connectorEntity.getId());
        // This is an asynchronous operation so exit and wait for it's READY state to be detected on the next poll.
        return deployConnector(connectorEntity);
    }
    // Step 3 - Check it has been provisioned
    Connector connector = optConnector.get();
    ConnectorStatusStatus status = connector.getStatus();
    if (Objects.isNull(status)) {
        LOGGER.debug("Managed Connector status for '{}' [{}] is undetermined.", connectorEntity.getName(), connectorEntity.getId());
        return connectorEntity;
    }
    if (status.getState() == ConnectorState.READY) {
        LOGGER.debug("Managed Connector for '{}' [{}] is ready.", connectorEntity.getName(), connectorEntity.getId());
        // Connector is ready. We can proceed with the deployment of the Processor in the Shard
        // The Processor will be provisioned by the Shard when it is in ACCEPTED state *and* Connectors are READY (or null).
        connectorEntity.setStatus(ManagedResourceStatus.READY);
        connectorEntity.setPublishedAt(ZonedDateTime.now(ZoneOffset.UTC));
        connectorEntity.setDependencyStatus(ManagedResourceStatus.READY);
        return persist(connectorEntity);
    }
    if (status.getState() == ConnectorState.FAILED) {
        LOGGER.debug("Creating Managed Connector for '{}' [{}] failed. Error: {}", connectorEntity.getName(), connectorEntity.getId(), status.getError());
        // Deployment of the Connector has failed. Bubble FAILED state up to ProcessorWorker.
        connectorEntity.setStatus(ManagedResourceStatus.FAILED);
        connectorEntity.setDependencyStatus(ManagedResourceStatus.FAILED);
        return persist(connectorEntity);
    }
    return connectorEntity;
}
Also used : Connector(com.openshift.cloud.api.connector.models.Connector) ConnectorStatusStatus(com.openshift.cloud.api.connector.models.ConnectorStatusStatus)

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