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;
}
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;
}
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);
}
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);
}
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;
}
Aggregations