Search in sources :

Example 1 with BridgeDefinition

use of com.redhat.service.smartevents.infra.models.bridges.BridgeDefinition in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorDAOTest method createBridge.

private Bridge createBridge() {
    Bridge b = new Bridge();
    b.setName(TestConstants.DEFAULT_BRIDGE_NAME);
    b.setCustomerId(TestConstants.DEFAULT_CUSTOMER_ID);
    b.setOrganisationId(TestConstants.DEFAULT_CUSTOMER_ID);
    b.setOwner(TestConstants.DEFAULT_USER_NAME);
    b.setStatus(ManagedResourceStatus.READY);
    b.setSubmittedAt(ZonedDateTime.now());
    b.setPublishedAt(ZonedDateTime.now());
    b.setShardId(TestConstants.SHARD_ID);
    b.setDefinition(new BridgeDefinition());
    bridgeDAO.persist(b);
    return b;
}
Also used : BridgeDefinition(com.redhat.service.smartevents.infra.models.bridges.BridgeDefinition) Bridge(com.redhat.service.smartevents.manager.models.Bridge)

Example 2 with BridgeDefinition

use of com.redhat.service.smartevents.infra.models.bridges.BridgeDefinition in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class Fixtures method createBridge.

public static Bridge createBridge() {
    Bridge b = new Bridge();
    b.setPublishedAt(ZonedDateTime.now());
    b.setCustomerId(TestConstants.DEFAULT_CUSTOMER_ID);
    b.setOrganisationId(TestConstants.DEFAULT_ORGANISATION_ID);
    b.setOwner(TestConstants.DEFAULT_USER_NAME);
    b.setStatus(ManagedResourceStatus.READY);
    b.setName(TestConstants.DEFAULT_BRIDGE_NAME);
    b.setSubmittedAt(ZonedDateTime.now());
    b.setEndpoint("https://bridge.redhat.com");
    b.setDefinition(new BridgeDefinition());
    return b;
}
Also used : BridgeDefinition(com.redhat.service.smartevents.infra.models.bridges.BridgeDefinition) Bridge(com.redhat.service.smartevents.manager.models.Bridge)

Example 3 with BridgeDefinition

use of com.redhat.service.smartevents.infra.models.bridges.BridgeDefinition in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeWorkerTest method doTestProvisionworkWithKnownResourceAndErrorHandler.

private void doTestProvisionworkWithKnownResourceAndErrorHandler(ManagedResourceStatus status, ManagedResourceStatus dependencyStatusWhenComplete, boolean throwRhoasError, boolean isWorkComplete, boolean errorHandlerProcessorPresent) {
    Bridge bridge = Fixtures.createBridge();
    bridge.setId(TestConstants.DEFAULT_BRIDGE_ID);
    bridge.setStatus(status);
    bridge.setDefinition(new BridgeDefinition(createWebhookAction()));
    bridgeDAO.persist(bridge);
    Work work = workManager.schedule(bridge);
    List<Processor> processors = errorHandlerProcessorPresent ? List.of(createErrorHandlerProcessor(bridge)) : Collections.emptyList();
    when(processorServiceMock.getHiddenProcessors(TestConstants.DEFAULT_BRIDGE_ID, TestConstants.DEFAULT_CUSTOMER_ID)).thenReturn(new ListResult<>(processors, 0, processors.size()));
    if (throwRhoasError) {
        when(rhoasServiceMock.createTopicAndGrantAccessFor(any(), any())).thenThrow(new InternalPlatformException("error"));
    }
    Bridge refreshed = worker.handleWork(work);
    verify(rhoasServiceMock).createTopicAndGrantAccessFor(TEST_TOPIC_NAME, RhoasTopicAccessType.CONSUMER_AND_PRODUCER);
    verify(rhoasServiceMock, times(throwRhoasError ? 0 : 1)).createTopicAndGrantAccessFor(TEST_ERROR_HANDLER_TOPIC_NAME, RhoasTopicAccessType.CONSUMER_AND_PRODUCER);
    verify(processorServiceMock, times(throwRhoasError || errorHandlerProcessorPresent ? 0 : 1)).createErrorHandlerProcessor(eq(bridge.getId()), eq(TestConstants.DEFAULT_CUSTOMER_ID), eq(TestConstants.DEFAULT_USER_NAME), any());
    assertThat(refreshed.getDependencyStatus()).isEqualTo(dependencyStatusWhenComplete);
    assertThat(workManager.exists(work)).isNotEqualTo(isWorkComplete);
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) InternalPlatformException(com.redhat.service.smartevents.infra.exceptions.definitions.platform.InternalPlatformException) Work(com.redhat.service.smartevents.manager.models.Work) BridgeDefinition(com.redhat.service.smartevents.infra.models.bridges.BridgeDefinition) Bridge(com.redhat.service.smartevents.manager.models.Bridge)

Example 4 with BridgeDefinition

use of com.redhat.service.smartevents.infra.models.bridges.BridgeDefinition in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeWorkerTest method testDeletionWorkWithKnownResourceAndErrorHandler.

@Transactional
@ParameterizedTest
@MethodSource("deletionWorkWithKnownResourceParams")
void testDeletionWorkWithKnownResourceAndErrorHandler(ManagedResourceStatus status, ManagedResourceStatus dependencyStatusWhenComplete, boolean throwRhoasError, boolean isWorkComplete) {
    Bridge bridge = Fixtures.createBridge();
    bridge.setId(TestConstants.DEFAULT_BRIDGE_ID);
    bridge.setStatus(status);
    bridge.setDefinition(new BridgeDefinition(createWebhookAction()));
    bridgeDAO.persist(bridge);
    Work work = workManager.schedule(bridge);
    when(processorServiceMock.getHiddenProcessors(TestConstants.DEFAULT_BRIDGE_ID, TestConstants.DEFAULT_CUSTOMER_ID)).thenReturn(new ListResult<>(List.of(createErrorHandlerProcessor(bridge)), 0, 1));
    Bridge refreshed = worker.handleWork(work);
    assertThat(refreshed.getDependencyStatus()).isNotEqualTo(dependencyStatusWhenComplete);
    assertThat(workManager.exists(work)).isTrue();
    when(processorServiceMock.getHiddenProcessors(TestConstants.DEFAULT_BRIDGE_ID, TestConstants.DEFAULT_CUSTOMER_ID)).thenReturn(new ListResult<>(Collections.emptyList(), 0, 0));
    if (throwRhoasError) {
        doThrow(new InternalPlatformException("error")).when(rhoasServiceMock).deleteTopicAndRevokeAccessFor(any(), any());
        Bridge refreshed2 = worker.handleWork(work);
        verify(rhoasServiceMock).deleteTopicAndRevokeAccessFor(TEST_TOPIC_NAME, RhoasTopicAccessType.CONSUMER_AND_PRODUCER);
        verify(rhoasServiceMock, never()).deleteTopicAndRevokeAccessFor(TEST_ERROR_HANDLER_TOPIC_NAME, RhoasTopicAccessType.CONSUMER_AND_PRODUCER);
        assertThat(refreshed2.getDependencyStatus()).isEqualTo(dependencyStatusWhenComplete);
    } else {
        Bridge refreshed2 = worker.handleWork(work);
        verify(rhoasServiceMock).deleteTopicAndRevokeAccessFor(TEST_TOPIC_NAME, RhoasTopicAccessType.CONSUMER_AND_PRODUCER);
        verify(rhoasServiceMock).deleteTopicAndRevokeAccessFor(TEST_ERROR_HANDLER_TOPIC_NAME, RhoasTopicAccessType.CONSUMER_AND_PRODUCER);
        assertThat(refreshed2.getDependencyStatus()).isEqualTo(dependencyStatusWhenComplete);
    }
    assertThat(workManager.exists(work)).isNotEqualTo(isWorkComplete);
}
Also used : InternalPlatformException(com.redhat.service.smartevents.infra.exceptions.definitions.platform.InternalPlatformException) Work(com.redhat.service.smartevents.manager.models.Work) BridgeDefinition(com.redhat.service.smartevents.infra.models.bridges.BridgeDefinition) 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)

Example 5 with BridgeDefinition

use of com.redhat.service.smartevents.infra.models.bridges.BridgeDefinition in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgesServiceImpl method createBridge.

@Override
@Transactional
public Bridge createBridge(String customerId, String organisationId, String owner, BridgeRequest bridgeRequest) {
    if (bridgeDAO.findByNameAndCustomerId(bridgeRequest.getName(), customerId) != null) {
        throw new AlreadyExistingItemException(String.format("Bridge with name '%s' already exists for customer with id '%s'", bridgeRequest.getName(), customerId));
    }
    Bridge bridge = bridgeRequest.toEntity();
    bridge.setStatus(ManagedResourceStatus.ACCEPTED);
    bridge.setSubmittedAt(ZonedDateTime.now(ZoneOffset.UTC));
    bridge.setCustomerId(customerId);
    bridge.setOrganisationId(organisationId);
    bridge.setOwner(owner);
    bridge.setShardId(shardService.getAssignedShardId(bridge.getId()));
    // Ensure we connect the ErrorHandler Action to the ErrorHandler back-channel
    Action errorHandler = bridgeRequest.getErrorHandler();
    bridge.setDefinition(new BridgeDefinition(Objects.nonNull(errorHandler) ? errorHandler : null));
    // Bridge and Work creation should always be in the same transaction
    bridgeDAO.persist(bridge);
    workManager.schedule(bridge);
    metricsService.onOperationStart(bridge, MetricsOperation.PROVISION);
    LOGGER.info("Bridge with id '{}' has been created for customer '{}'", bridge.getId(), bridge.getCustomerId());
    return bridge;
}
Also used : Action(com.redhat.service.smartevents.infra.models.gateways.Action) BridgeDefinition(com.redhat.service.smartevents.infra.models.bridges.BridgeDefinition) Bridge(com.redhat.service.smartevents.manager.models.Bridge) AlreadyExistingItemException(com.redhat.service.smartevents.infra.exceptions.definitions.user.AlreadyExistingItemException) Transactional(javax.transaction.Transactional)

Aggregations

BridgeDefinition (com.redhat.service.smartevents.infra.models.bridges.BridgeDefinition)6 Bridge (com.redhat.service.smartevents.manager.models.Bridge)6 InternalPlatformException (com.redhat.service.smartevents.infra.exceptions.definitions.platform.InternalPlatformException)2 Work (com.redhat.service.smartevents.manager.models.Work)2 Transactional (javax.transaction.Transactional)2 AlreadyExistingItemException (com.redhat.service.smartevents.infra.exceptions.definitions.user.AlreadyExistingItemException)1 Action (com.redhat.service.smartevents.infra.models.gateways.Action)1 Processor (com.redhat.service.smartevents.manager.models.Processor)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1