Search in sources :

Example 6 with ConnectorEntity

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

the class ProcessorServiceConnectorTest method createPersistentConnector.

private ConnectorEntity createPersistentConnector(Processor processor, ManagedResourceStatus status) {
    ConnectorEntity connector = Fixtures.createSinkConnector(processor, status);
    connectorsDAO.persist(connector);
    return connector;
}
Also used : ConnectorEntity(com.redhat.service.smartevents.manager.models.ConnectorEntity)

Example 7 with ConnectorEntity

use of com.redhat.service.smartevents.manager.models.ConnectorEntity 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 8 with ConnectorEntity

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

the class ProcessorDAOTest method findProcessorsToBeDeployedOrDeleteWithConnectors.

@Test
@Transactional
public void findProcessorsToBeDeployedOrDeleteWithConnectors() {
    Bridge b = createBridge();
    // To be provisioned
    Processor withProvisionedConnectors = createProcessor(b, "withProvisionedConnectors");
    withProvisionedConnectors.setStatus(ManagedResourceStatus.PREPARING);
    withProvisionedConnectors.setDependencyStatus(ManagedResourceStatus.READY);
    processorDAO.getEntityManager().merge(withProvisionedConnectors);
    ConnectorEntity provisionedConnector = Fixtures.createSinkConnector(withProvisionedConnectors, ManagedResourceStatus.READY);
    provisionedConnector.setName("connectorProvisioned");
    processorDAO.getEntityManager().merge(provisionedConnector);
    // Not to be provisioned as Connector is not ready
    Processor nonProvisioned = createProcessor(b, "withUnprovisionedConnector");
    nonProvisioned.setStatus(ManagedResourceStatus.PREPARING);
    nonProvisioned.setDependencyStatus(ManagedResourceStatus.PROVISIONING);
    processorDAO.getEntityManager().merge(nonProvisioned);
    ConnectorEntity nonProvisionedConnector = Fixtures.createSinkConnector(nonProvisioned, ManagedResourceStatus.PROVISIONING);
    nonProvisionedConnector.setName("nonProvisionedConnector");
    processorDAO.getEntityManager().merge(nonProvisionedConnector);
    // Not to be de-provisioned as there's a connector yet to be deleted
    Processor toBeDeleted = createProcessor(b, "notToBeDeletedYet");
    toBeDeleted.setStatus(ManagedResourceStatus.DEPROVISION);
    toBeDeleted.setDependencyStatus(ManagedResourceStatus.DELETING);
    processorDAO.getEntityManager().merge(nonProvisioned);
    ConnectorEntity toBeDeletedConnector = Fixtures.createSinkConnector(toBeDeleted, ManagedResourceStatus.DELETING);
    toBeDeletedConnector.setName("toBeDeletedConnector");
    processorDAO.getEntityManager().merge(toBeDeletedConnector);
    List<Processor> processors = processorDAO.findByShardIdWithReadyDependencies(TestConstants.SHARD_ID);
    assertThat(processors.stream().map(Processor::getName)).contains("withProvisionedConnectors");
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) ConnectorEntity(com.redhat.service.smartevents.manager.models.ConnectorEntity) Bridge(com.redhat.service.smartevents.manager.models.Bridge) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) Transactional(javax.transaction.Transactional)

Example 9 with ConnectorEntity

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

the class ConnectorWorkerTest method handleWorkDeletingWithKnownResourceMultiplePasses.

@Transactional
@ParameterizedTest
@MethodSource("provideArgsForDeleteTest")
void handleWorkDeletingWithKnownResourceMultiplePasses(ManagedResourceStatus resourceStatus, ConnectorState connectorState, boolean useSourceConnectorEntity, RhoasTopicAccessType expectedTopicAccessType) {
    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.setStatus(new ConnectorStatusStatus().state(connectorState));
    // Managed Connector will initially be available before it is deleted
    when(connectorsApi.getConnector(connectorEntity.getConnectorExternalId())).thenReturn(connector, (Connector) null);
    ConnectorEntity refreshed = worker.handleWork(work);
    if (connectorState != ConnectorState.DELETED) {
        assertThat(refreshed.getStatus()).isEqualTo(ManagedResourceStatus.DELETING);
        assertThat(refreshed.getDependencyStatus()).isEqualTo(ManagedResourceStatus.DELETING);
        verify(rhoasService, never()).deleteTopicAndRevokeAccessFor(connectorEntity.getTopicName(), RhoasTopicAccessType.PRODUCER);
        verify(connectorsApi).deleteConnector(connectorEntity.getConnectorExternalId());
        // This emulates a subsequent invocation by WorkManager
        refreshed = worker.handleWork(work);
    }
    verify(rhoasService).deleteTopicAndRevokeAccessFor(connectorEntity.getTopicName(), expectedTopicAccessType);
    assertThat(connectorsDAO.findById(connectorEntity.getId())).isNull();
    assertThat(refreshed.getStatus()).isEqualTo(ManagedResourceStatus.DELETED);
    assertThat(refreshed.getDependencyStatus()).isEqualTo(ManagedResourceStatus.DELETED);
    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 10 with ConnectorEntity

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

the class ProcessorWorkerTest method handleWorkDeletingWithKnownResourceWithConnector.

@Transactional
@ParameterizedTest
@MethodSource("srcHandleWorkDeletingWithKnownResourceWithConnector")
void handleWorkDeletingWithKnownResourceWithConnector(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