Search in sources :

Example 1 with ConnectorStatusStatus

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

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

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

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

Example 5 with ConnectorStatusStatus

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

the class ConnectorWorker method deleteDependencies.

@Override
public ConnectorEntity deleteDependencies(Work work, ConnectorEntity connectorEntity) {
    LOGGER.info("Destroying dependencies for '{}' [{}]", connectorEntity.getName(), connectorEntity.getId());
    // This is idempotent as it gets overridden later depending on actual state
    connectorEntity.setStatus(ManagedResourceStatus.DELETING);
    connectorEntity.setDependencyStatus(ManagedResourceStatus.DELETING);
    connectorEntity = persist(connectorEntity);
    // Steps, in reverse order...
    // Step 3 - Connector has been deleted and does not exist: Clean up Kafka Topic
    String connectorExternalId = connectorEntity.getConnectorExternalId();
    if (Objects.isNull(connectorExternalId)) {
        return deleteTopic(connectorEntity);
    }
    Connector connector = connectorsApi.getConnector(connectorExternalId);
    if (Objects.isNull(connector)) {
        return deleteTopic(connectorEntity);
    }
    ConnectorStatusStatus status = connector.getStatus();
    if (Objects.isNull(status)) {
        return connectorEntity;
    }
    if (status.getState() == ConnectorState.DELETED) {
        LOGGER.debug("Managed Connector for '{}' [{}] has status 'DELETED'. Continuing with deletion of Kafka Topic..", connectorEntity.getName(), connectorEntity.getId());
        return deleteTopic(connectorEntity);
    }
    // Step 2 - Delete Connector
    LOGGER.debug("Deleting Managed Connector for '{}' [{}]", connectorEntity.getName(), connectorEntity.getId());
    connectorsApi.deleteConnector(connectorEntity.getConnectorExternalId());
    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)16 ConnectorStatusStatus (com.openshift.cloud.api.connector.models.ConnectorStatusStatus)16 QuarkusTest (io.quarkus.test.junit.QuarkusTest)8 Test (org.junit.jupiter.api.Test)8 ConnectorEntity (com.redhat.service.bridge.manager.models.ConnectorEntity)6 Bridge (com.redhat.service.smartevents.manager.models.Bridge)6 Processor (com.redhat.service.smartevents.manager.models.Processor)6 Bridge (com.redhat.service.bridge.manager.models.Bridge)4 Processor (com.redhat.service.bridge.manager.models.Processor)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 ConnectorEntity (com.redhat.service.smartevents.manager.models.ConnectorEntity)3 ConnectorRequest (com.openshift.cloud.api.connector.models.ConnectorRequest)2 Topic (com.openshift.cloud.api.kas.auth.models.Topic)2 InternalPlatformException (com.redhat.service.bridge.infra.exceptions.definitions.platform.InternalPlatformException)2 Work (com.redhat.service.bridge.manager.models.Work)2 InternalPlatformException (com.redhat.service.smartevents.infra.exceptions.definitions.platform.InternalPlatformException)2 Work (com.redhat.service.smartevents.manager.models.Work)2 ZonedDateTime (java.time.ZonedDateTime)2 Transactional (javax.transaction.Transactional)2 EnumSource (org.junit.jupiter.params.provider.EnumSource)2