use of com.redhat.service.smartevents.infra.models.gateways.Action in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ConnectorsServiceTest method processorWith.
private static Processor processorWith(Gateway gateway) {
Processor processor = new Processor();
processor.setBridge(new Bridge());
ProcessorDefinition processorDefinition = new ProcessorDefinition();
if (gateway instanceof Action) {
processorDefinition.setRequestedAction((Action) gateway);
processor.setType(ProcessorType.SINK);
} else {
processorDefinition.setRequestedSource((Source) gateway);
processor.setType(ProcessorType.SOURCE);
}
processor.setId(TEST_PROCESSOR_ID);
processor.setName(TEST_PROCESSOR_NAME);
processor.setDefinition(processorDefinition);
return processor;
}
use of com.redhat.service.smartevents.infra.models.gateways.Action in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ConnectorsServiceTest method webhookAction.
private static Action webhookAction() {
Action action = new Action();
action.setType(WebhookAction.TYPE);
action.setMapParameters(Map.of(WebhookAction.ENDPOINT_PARAM, TEST_ACTION_WEBHOOK));
return action;
}
use of com.redhat.service.smartevents.infra.models.gateways.Action in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ConnectorsDAOTest method createPersistProcessor.
private Processor createPersistProcessor(Bridge bridge) {
Processor p = Fixtures.createProcessor(bridge, ManagedResourceStatus.ACCEPTED);
Action a = new Action();
a.setType(KafkaTopicAction.TYPE);
Map<String, String> params = new HashMap<>();
params.put(KafkaTopicAction.TOPIC_PARAM, TestConstants.DEFAULT_KAFKA_TOPIC);
a.setMapParameters(params);
ProcessorDefinition definition = new ProcessorDefinition(Collections.emptySet(), null, a);
p.setDefinition(definition);
processorDAO.persist(p);
return p;
}
use of com.redhat.service.smartevents.infra.models.gateways.Action in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class BridgeWorker method createErrorHandlerProcessor.
/**
* Creates error handler processor if required
*
* @param bridge input bridge
* @return true if the work can proceed (either the error handler processor
* is not required or it's created and ready), false otherwise.
*/
private void createErrorHandlerProcessor(Bridge bridge) {
// If an ErrorHandler is not needed, consider it ready
Action errorHandlerAction = bridge.getDefinition().getErrorHandler();
boolean errorHandlerProcessorIsNotRequired = Objects.isNull(errorHandlerAction);
if (errorHandlerProcessorIsNotRequired) {
return;
}
String bridgeId = bridge.getId();
String customerId = bridge.getCustomerId();
ListResult<Processor> processors = processorService.getHiddenProcessors(bridgeId, customerId);
// This assumes we can only have one ErrorHandler Processor per Bridge
if (processors.getTotal() > 0) {
return;
}
// create error handler processor if not present
String errorHandlerName = String.format("Back-channel for Bridge '%s'", bridge.getId());
ProcessorRequest errorHandlerProcessor = new ProcessorRequest(errorHandlerName, errorHandlerAction);
processorService.createErrorHandlerProcessor(bridge.getId(), bridge.getCustomerId(), bridge.getOwner(), errorHandlerProcessor);
}
use of com.redhat.service.smartevents.infra.models.gateways.Action 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();
}
Aggregations