Search in sources :

Example 46 with BaseAction

use of com.redhat.service.bridge.infra.models.actions.BaseAction in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class SlackActionTransformerTest method testTransform.

@Test
void testTransform() {
    BaseAction baseAction = buildTestAction();
    BaseAction transformedAction = slackActionTransformer.transform(baseAction, TEST_BRIDGE_ID, TEST_CUSTOMER_ID, TEST_PROCESSOR_ID);
    assertThat(transformedAction.getType()).isEqualTo(KafkaTopicAction.TYPE);
    Map<String, String> transformedActionParameter = transformedAction.getParameters();
    assertThat(transformedActionParameter).containsEntry(SlackAction.CHANNEL_PARAMETER, TEST_CHANNEL_PARAM).containsEntry(SlackAction.WEBHOOK_URL_PARAMETER, TEST_WEBHOOK_PARAM).containsEntry(KafkaTopicAction.TOPIC_PARAM, internalKafkaConfigurationProvider.getTopicPrefix() + TEST_PROCESSOR_ID);
}
Also used : BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 47 with BaseAction

use of com.redhat.service.bridge.infra.models.actions.BaseAction in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceImpl method createProcessor.

@Override
public Processor createProcessor(String bridgeId, String customerId, ProcessorRequest processorRequest) {
    /* We cannot deploy Processors to a Bridge that is not Available */
    Bridge bridge = bridgesService.getReadyBridge(bridgeId, customerId);
    if (processorDAO.findByBridgeIdAndName(bridgeId, processorRequest.getName()) != null) {
        throw new AlreadyExistingItemException("Processor with name '" + processorRequest.getName() + "' already exists for bridge with id '" + bridgeId + "' for customer '" + customerId + "'");
    }
    Processor newProcessor = new Processor();
    Set<BaseFilter> requestedFilters = processorRequest.getFilters();
    String requestedTransformationTemplate = processorRequest.getTransformationTemplate();
    BaseAction requestedAction = processorRequest.getAction();
    ActionProvider actionProvider = actionProviderFactory.getActionProvider(requestedAction.getType());
    BaseAction resolvedAction = actionProviderFactory.resolve(requestedAction, bridge.getId(), customerId, newProcessor.getId());
    newProcessor.setName(processorRequest.getName());
    newProcessor.setSubmittedAt(ZonedDateTime.now());
    newProcessor.setStatus(ManagedResourceStatus.ACCEPTED);
    newProcessor.setBridge(bridge);
    newProcessor.setShardId(shardService.getAssignedShardId(newProcessor.getId()));
    ProcessorDefinition definition = new ProcessorDefinition(requestedFilters, requestedTransformationTemplate, requestedAction, resolvedAction);
    newProcessor.setDefinition(definitionToJsonNode(definition));
    LOGGER.info("Processor with id '{}' for customer '{}' on bridge '{}' has been marked for creation", newProcessor.getId(), newProcessor.getBridge().getCustomerId(), newProcessor.getBridge().getId());
    createProcessorConnectorEntity(newProcessor, actionProvider, resolvedAction);
    workManager.schedule(newProcessor);
    return newProcessor;
}
Also used : ActionProvider(com.redhat.service.bridge.actions.ActionProvider) Processor(com.redhat.service.bridge.manager.models.Processor) ProcessorDefinition(com.redhat.service.bridge.infra.models.processors.ProcessorDefinition) BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) Bridge(com.redhat.service.bridge.manager.models.Bridge) BaseFilter(com.redhat.service.bridge.infra.models.filters.BaseFilter) AlreadyExistingItemException(com.redhat.service.bridge.infra.exceptions.definitions.user.AlreadyExistingItemException)

Example 48 with BaseAction

use of com.redhat.service.bridge.infra.models.actions.BaseAction in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class SlackActionTransformer method transform.

@Override
public BaseAction transform(BaseAction action, String bridgeId, String customerId, String processorId) {
    BaseAction resolvedAction = new BaseAction();
    Map<String, String> newParameters = resolvedAction.getParameters();
    newParameters.putAll(action.getParameters());
    resolvedAction.setType(KafkaTopicAction.TYPE);
    newParameters.put(KafkaTopicAction.TOPIC_PARAM, generateKafkaTopicName(processorId));
    return resolvedAction;
}
Also used : BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction)

Aggregations

BaseAction (com.redhat.service.bridge.infra.models.actions.BaseAction)48 Test (org.junit.jupiter.api.Test)20 QuarkusTest (io.quarkus.test.junit.QuarkusTest)15 ProcessorDefinition (com.redhat.service.bridge.infra.models.processors.ProcessorDefinition)13 HashMap (java.util.HashMap)13 ProcessorDTO (com.redhat.service.bridge.infra.models.dto.ProcessorDTO)10 BaseFilter (com.redhat.service.bridge.infra.models.filters.BaseFilter)10 StringEquals (com.redhat.service.bridge.infra.models.filters.StringEquals)9 ProcessorRequest (com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest)9 Processor (com.redhat.service.bridge.manager.models.Processor)7 Bridge (com.redhat.service.bridge.manager.models.Bridge)6 HashSet (java.util.HashSet)6 CloudEvent (io.cloudevents.CloudEvent)5 ProcessorResponse (com.redhat.service.bridge.manager.api.models.responses.ProcessorResponse)4 ValidationResult (com.redhat.service.bridge.actions.ValidationResult)3 BridgeResponse (com.redhat.service.bridge.manager.api.models.responses.BridgeResponse)3 TestSecurity (io.quarkus.test.security.TestSecurity)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 Connector (com.openshift.cloud.api.connector.models.Connector)2 ConnectorRequest (com.openshift.cloud.api.connector.models.ConnectorRequest)2