Search in sources :

Example 11 with ConnectorEntity

use of com.redhat.service.smartevents.manager.models.ConnectorEntity in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ConnectorsServiceImpl method persistConnectorEntity.

private void persistConnectorEntity(Processor processor, String topicName, ConnectorType connectorType, String connectorTypeId, JsonNode connectorPayload) {
    String newConnectorName = resourceNamesProvider.getProcessorConnectorName(processor.getId());
    ConnectorEntity newConnectorEntity = new ConnectorEntity();
    newConnectorEntity.setType(connectorType);
    newConnectorEntity.setName(newConnectorName);
    newConnectorEntity.setStatus(ManagedResourceStatus.ACCEPTED);
    newConnectorEntity.setSubmittedAt(ZonedDateTime.now());
    newConnectorEntity.setProcessor(processor);
    newConnectorEntity.setTopicName(topicName);
    newConnectorEntity.setConnectorTypeId(connectorTypeId);
    newConnectorEntity.setDefinition(connectorPayload);
    connectorsDAO.persist(newConnectorEntity);
}
Also used : ConnectorEntity(com.redhat.service.smartevents.manager.models.ConnectorEntity)

Example 12 with ConnectorEntity

use of com.redhat.service.smartevents.manager.models.ConnectorEntity in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ConnectorsServiceTest method connectorEntityWith.

private static ConnectorEntity connectorEntityWith(Processor processor) {
    ConnectorEntity connectorEntity = new ConnectorEntity();
    connectorEntity.setType(processor.getType() == ProcessorType.SOURCE ? ConnectorType.SOURCE : ConnectorType.SINK);
    connectorEntity.setId(TEST_CONNECTOR_ID);
    connectorEntity.setConnectorExternalId(TEST_CONNECTOR_EXTERNAL_ID);
    connectorEntity.setProcessor(processor);
    return connectorEntity;
}
Also used : ConnectorEntity(com.redhat.service.smartevents.manager.models.ConnectorEntity)

Example 13 with ConnectorEntity

use of com.redhat.service.smartevents.manager.models.ConnectorEntity in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceConnectorTest method waitForConnectorToBeDeleted.

private void waitForConnectorToBeDeleted(final Bridge bridge, final Processor processor) {
    // There will be 2 re-tries at 5s each. Add 5s to be certain everything completes.
    await().atMost(15, SECONDS).untilAsserted(() -> {
        ConnectorEntity foundConnector = connectorsDAO.findByProcessorIdAndName(processor.getId(), TestConstants.DEFAULT_CONNECTOR_NAME);
        assertThat(foundConnector).isNull();
        final Processor processorDeleted = processorService.getProcessor(bridge.getId(), processor.getId(), DEFAULT_CUSTOMER_ID);
        assertThat(processorDeleted.getStatus()).isEqualTo(DEPROVISION);
    });
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) ConnectorEntity(com.redhat.service.smartevents.manager.models.ConnectorEntity)

Example 14 with ConnectorEntity

use of com.redhat.service.smartevents.manager.models.ConnectorEntity in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ConnectorWorkerTest method handleWorkProvisioningWithKnownResourceMultiplePasses.

@Transactional
@ParameterizedTest
@MethodSource("provideArgsForCreateTest")
void handleWorkProvisioningWithKnownResourceMultiplePasses(ManagedResourceStatus resourceStatus, ConnectorState connectorState, boolean useSourceConnectorEntity, RhoasTopicAccessType expectedTopicAccessType, ManagedResourceStatus expectedResourceStatus) {
    Bridge bridge = Fixtures.createBridge();
    Processor processor = Fixtures.createProcessor(bridge, ManagedResourceStatus.READY);
    ConnectorEntity connectorEntity = useSourceConnectorEntity ? Fixtures.createSourceConnector(processor, resourceStatus) : Fixtures.createSinkConnector(processor, resourceStatus);
    // The publishedAt date is set by the Worker so reset that set by the Fixture
    connectorEntity.setPublishedAt(null);
    bridgeDAO.persist(bridge);
    processorDAO.persist(processor);
    connectorsDAO.persist(connectorEntity);
    Work work = workManager.schedule(connectorEntity);
    Connector connector = new Connector();
    connector.setId(TEST_CONNECTOR_EXTERNAL_ID);
    connector.setStatus(new ConnectorStatusStatus().state(connectorState));
    when(connectorsApi.getConnector(TEST_CONNECTOR_EXTERNAL_ID)).thenReturn(null, connector);
    when(connectorsApi.createConnector(connectorEntity)).thenReturn(connector);
    ConnectorEntity refreshed = worker.handleWork(work);
    verify(rhoasService).createTopicAndGrantAccessFor(connectorEntity.getTopicName(), expectedTopicAccessType);
    verify(connectorsApi).createConnector(connectorEntity);
    assertThat(refreshed.getStatus()).isEqualTo(ManagedResourceStatus.PREPARING);
    assertThat(refreshed.getDependencyStatus()).isEqualTo(ManagedResourceStatus.PROVISIONING);
    // This emulates a subsequent invocation by WorkManager
    refreshed = worker.handleWork(work);
    verify(rhoasService, times(2)).createTopicAndGrantAccessFor(connectorEntity.getTopicName(), expectedTopicAccessType);
    verify(connectorsApi, atMostOnce()).createConnector(connectorEntity);
    assertThat(refreshed.getStatus()).isEqualTo(expectedResourceStatus);
    assertThat(refreshed.getDependencyStatus()).isEqualTo(expectedResourceStatus);
    if (expectedResourceStatus == ManagedResourceStatus.READY) {
        assertThat(refreshed.getPublishedAt()).isNotNull();
    } else {
        assertThat(refreshed.getPublishedAt()).isNull();
    }
    assertThat(workManager.exists(work)).isTrue();
}
Also used : Connector(com.openshift.cloud.api.connector.models.Connector) Processor(com.redhat.service.smartevents.manager.models.Processor) ConnectorEntity(com.redhat.service.smartevents.manager.models.ConnectorEntity) Work(com.redhat.service.smartevents.manager.models.Work) Bridge(com.redhat.service.smartevents.manager.models.Bridge) ConnectorStatusStatus(com.openshift.cloud.api.connector.models.ConnectorStatusStatus) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) Transactional(javax.transaction.Transactional)

Example 15 with ConnectorEntity

use of com.redhat.service.smartevents.manager.models.ConnectorEntity in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorWorkerTest method handleWorkProvisioningWithKnownResourceWithConnector.

@Transactional
@ParameterizedTest
@MethodSource("srcHandleWorkProvisioningWithKnownResourceWithConnector")
void handleWorkProvisioningWithKnownResourceWithConnector(ManagedResourceStatus status, ManagedResourceStatus statusWhenComplete, ManagedResourceStatus dependencyStatusWhenComplete, boolean isWorkComplete) {
    Bridge bridge = Fixtures.createBridge();
    Processor processor = Fixtures.createProcessor(bridge, ManagedResourceStatus.READY);
    processor.setStatus(status);
    ConnectorEntity connectorEntity = Fixtures.createSinkConnector(processor, ManagedResourceStatus.ACCEPTED);
    connectorEntity.setStatus(ManagedResourceStatus.ACCEPTED);
    bridgeDAO.persist(bridge);
    processorDAO.persist(processor);
    connectorsDAO.persist(connectorEntity);
    Work work = workManager.schedule(processor);
    doAnswer((i) -> {
        // Emulate ConnectorWorker completing work
        connectorEntity.setStatus(dependencyStatusWhenComplete);
        return connectorEntity;
    }).when(connectorWorker).handleWork(any(Work.class));
    Processor refreshed = worker.handleWork(work);
    assertThat(refreshed.getStatus()).isEqualTo(statusWhenComplete);
    assertThat(refreshed.getDependencyStatus()).isEqualTo(dependencyStatusWhenComplete);
    ArgumentCaptor<Work> workArgumentCaptor = ArgumentCaptor.forClass(Work.class);
    verify(connectorWorker).handleWork(workArgumentCaptor.capture());
    Work connectorWork = workArgumentCaptor.getValue();
    assertThat(connectorWork).isNotNull();
    assertThat(connectorWork.getId()).isEqualTo(work.getId());
    assertThat(connectorWork.getManagedResourceId()).isEqualTo(connectorEntity.getId());
    assertThat(connectorWork.getSubmittedAt()).isEqualTo(work.getSubmittedAt());
    assertThat(workManager.exists(work)).isNotEqualTo(isWorkComplete);
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) ConnectorEntity(com.redhat.service.smartevents.manager.models.ConnectorEntity) Work(com.redhat.service.smartevents.manager.models.Work) Bridge(com.redhat.service.smartevents.manager.models.Bridge) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) Transactional(javax.transaction.Transactional)

Aggregations

ConnectorEntity (com.redhat.service.smartevents.manager.models.ConnectorEntity)16 Processor (com.redhat.service.smartevents.manager.models.Processor)8 Bridge (com.redhat.service.smartevents.manager.models.Bridge)7 Transactional (javax.transaction.Transactional)6 Work (com.redhat.service.smartevents.manager.models.Work)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 MethodSource (org.junit.jupiter.params.provider.MethodSource)5 Connector (com.openshift.cloud.api.connector.models.Connector)3 ConnectorStatusStatus (com.openshift.cloud.api.connector.models.ConnectorStatusStatus)3 QuarkusTest (io.quarkus.test.junit.QuarkusTest)3 Test (org.junit.jupiter.api.Test)3 TextNode (com.fasterxml.jackson.databind.node.TextNode)1 ConnectorRequest (com.openshift.cloud.api.connector.models.ConnectorRequest)1 Topic (com.openshift.cloud.api.kas.auth.models.Topic)1 Action (com.redhat.service.smartevents.infra.models.gateways.Action)1 ProcessorRequest (com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest)1 SlackAction (com.redhat.service.smartevents.processor.actions.slack.SlackAction)1