Search in sources :

Example 6 with Source

use of com.redhat.service.smartevents.infra.models.gateways.Source in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class AbstractSourceTest method sourceWith.

protected Source sourceWith(Map<String, String> params) {
    Source source = new Source();
    source.setType(getSourceType());
    source.setMapParameters(params);
    return source;
}
Also used : Source(com.redhat.service.smartevents.infra.models.gateways.Source)

Example 7 with Source

use of com.redhat.service.smartevents.infra.models.gateways.Source in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ExecutorTestUtils method createSourceProcessor.

public static ProcessorDTO createSourceProcessor() {
    Source requestedSource = new Source();
    requestedSource.setType(SlackSource.TYPE);
    Action resolvedAction = new Action();
    resolvedAction.setType(WebhookAction.TYPE);
    return createProcessor(ProcessorType.SOURCE, new ProcessorDefinition(null, null, requestedSource, resolvedAction));
}
Also used : Action(com.redhat.service.smartevents.infra.models.gateways.Action) KafkaTopicAction(com.redhat.service.smartevents.processor.actions.kafkatopic.KafkaTopicAction) SendToBridgeAction(com.redhat.service.smartevents.processor.actions.sendtobridge.SendToBridgeAction) WebhookAction(com.redhat.service.smartevents.processor.actions.webhook.WebhookAction) ProcessorDefinition(com.redhat.service.smartevents.infra.models.processors.ProcessorDefinition) SlackSource(com.redhat.service.smartevents.processor.sources.slack.SlackSource) Source(com.redhat.service.smartevents.infra.models.gateways.Source)

Example 8 with Source

use of com.redhat.service.smartevents.infra.models.gateways.Source in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceImpl method updateProcessor.

@Override
@Transactional
public Processor updateProcessor(String bridgeId, String processorId, String customerId, ProcessorRequest processorRequest) {
    // Attempt to load the Bridge. We cannot update a Processor if the Bridge is not available.
    bridgesService.getReadyBridge(bridgeId, customerId);
    // Extract existing definition
    Processor existingProcessor = getProcessor(bridgeId, processorId, customerId);
    if (existingProcessor.getType() == ProcessorType.ERROR_HANDLER) {
        throw new BadRequestException("It is not possible to update this Processor.");
    }
    if (!isProcessorActionable(existingProcessor)) {
        throw new ProcessorLifecycleException(String.format("Processor with id '%s' for customer '%s' is not in an actionable state.", processorId, customerId));
    }
    ProcessorDefinition existingDefinition = existingProcessor.getDefinition();
    Action existingAction = existingDefinition.getRequestedAction();
    Action existingResolvedAction = existingDefinition.getResolvedAction();
    Source existingSource = existingDefinition.getRequestedSource();
    // Name cannot be updated.
    if (!Objects.equals(existingProcessor.getName(), processorRequest.getName())) {
        throw new BadRequestException("It is not possible to update the Processor's name.");
    }
    if (!Objects.equals(existingProcessor.getType(), processorRequest.getType())) {
        throw new BadRequestException("It is not possible to update the Processor's Type.");
    }
    // See https://issues.redhat.com/browse/MGDOBR-516 for updating Action support
    if (!Objects.equals(existingAction, processorRequest.getAction())) {
        throw new BadRequestException("It is not possible to update the Processor's Action.");
    }
    if (!Objects.equals(existingSource, processorRequest.getSource())) {
        throw new BadRequestException("It is not possible to update the Processor's Source.");
    }
    // Construct updated definition
    Set<BaseFilter> updatedFilters = processorRequest.getFilters();
    String updatedTransformationTemplate = processorRequest.getTransformationTemplate();
    ProcessorDefinition updatedDefinition = existingProcessor.getType() == ProcessorType.SOURCE ? new ProcessorDefinition(updatedFilters, updatedTransformationTemplate, existingSource, existingResolvedAction) : new ProcessorDefinition(updatedFilters, updatedTransformationTemplate, existingAction, existingResolvedAction);
    // No need to update CRD if the definition is unchanged
    if (existingDefinition.equals(updatedDefinition)) {
        return existingProcessor;
    }
    // Create new definition copying existing properties
    existingProcessor.setModifiedAt(ZonedDateTime.now());
    existingProcessor.setStatus(ManagedResourceStatus.ACCEPTED);
    existingProcessor.setDefinition(updatedDefinition);
    // Processor and Work should always be created in the same transaction
    // Since updates to the Action are unsupported we do not need to update the Connector record.
    workManager.schedule(existingProcessor);
    metricsService.onOperationStart(existingProcessor, MetricsOperation.MODIFY);
    LOGGER.info("Processor with id '{}' for customer '{}' on bridge '{}' has been marked for update", existingProcessor.getId(), existingProcessor.getBridge().getCustomerId(), existingProcessor.getBridge().getId());
    return existingProcessor;
}
Also used : ProcessorLifecycleException(com.redhat.service.smartevents.infra.exceptions.definitions.user.ProcessorLifecycleException) Action(com.redhat.service.smartevents.infra.models.gateways.Action) Processor(com.redhat.service.smartevents.manager.models.Processor) ProcessorDefinition(com.redhat.service.smartevents.infra.models.processors.ProcessorDefinition) BadRequestException(com.redhat.service.smartevents.infra.exceptions.definitions.user.BadRequestException) Source(com.redhat.service.smartevents.infra.models.gateways.Source) BaseFilter(com.redhat.service.smartevents.infra.models.filters.BaseFilter) Transactional(javax.transaction.Transactional)

Example 9 with Source

use of com.redhat.service.smartevents.infra.models.gateways.Source in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorGatewayConstraintValidator method isValid.

@Override
public boolean isValid(ProcessorRequest value, ConstraintValidatorContext context) {
    Action action = value.getAction();
    Source source = value.getSource();
    if (action == null && source == null) {
        addConstraintViolation(context, MISSING_GATEWAY_ERROR, Collections.emptyMap());
        return false;
    }
    if (action != null && source != null) {
        addConstraintViolation(context, MULTIPLE_GATEWAY_ERROR, Collections.emptyMap());
        return false;
    }
    // Currently, source processors don't support transformation
    if (value.getType() == ProcessorType.SOURCE && value.getTransformationTemplate() != null) {
        addConstraintViolation(context, SOURCE_PROCESSOR_WITH_TRANSFORMATION_ERROR, Collections.emptyMap());
        return false;
    }
    return action != null ? isValidGateway(action, context, gatewayConfigurator::getActionValidator) : isValidGateway(source, context, gatewayConfigurator::getSourceValidator);
}
Also used : Action(com.redhat.service.smartevents.infra.models.gateways.Action) Source(com.redhat.service.smartevents.infra.models.gateways.Source)

Example 10 with Source

use of com.redhat.service.smartevents.infra.models.gateways.Source in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorGatewayConstraintValidatorTest method beforeEach.

@BeforeEach
public void beforeEach() {
    lenient().when(actionValidatorMock.isValid(any(Action.class))).thenReturn(ValidationResult.valid());
    lenient().when(sourceValidatorMock.isValid(any(Source.class))).thenReturn(ValidationResult.valid());
    lenient().when(gatewayConfiguratorMock.getActionValidator(TEST_ACTION_TYPE)).thenReturn(actionValidatorMock);
    lenient().when(gatewayConfiguratorMock.getActionValidator(not(eq(TEST_ACTION_TYPE)))).thenThrow(new GatewayProviderException("No action provider found"));
    lenient().when(gatewayConfiguratorMock.getSourceValidator(TEST_SOURCE_TYPE)).thenReturn(sourceValidatorMock);
    lenient().when(gatewayConfiguratorMock.getSourceValidator(not(eq(TEST_SOURCE_TYPE)))).thenThrow(new GatewayProviderException("No source provider found"));
    lenient().when(validatorContextMock.buildConstraintViolationWithTemplate(any(String.class))).thenReturn(builderMock);
    lenient().when(validatorContextMock.unwrap(HibernateConstraintValidatorContext.class)).thenReturn(validatorContextMock);
    constraintValidator = new ProcessorGatewayConstraintValidator(gatewayConfiguratorMock);
}
Also used : Action(com.redhat.service.smartevents.infra.models.gateways.Action) GatewayProviderException(com.redhat.service.smartevents.infra.exceptions.definitions.user.GatewayProviderException) MethodSource(org.junit.jupiter.params.provider.MethodSource) Source(com.redhat.service.smartevents.infra.models.gateways.Source) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Source (com.redhat.service.smartevents.infra.models.gateways.Source)15 SlackSource (com.redhat.service.smartevents.processor.sources.slack.SlackSource)10 Action (com.redhat.service.smartevents.infra.models.gateways.Action)7 MethodSource (org.junit.jupiter.params.provider.MethodSource)6 BadRequestException (com.redhat.service.smartevents.infra.exceptions.definitions.user.BadRequestException)3 Processor (com.redhat.service.smartevents.manager.models.Processor)3 KafkaTopicAction (com.redhat.service.smartevents.processor.actions.kafkatopic.KafkaTopicAction)3 QuarkusTest (io.quarkus.test.junit.QuarkusTest)3 Test (org.junit.jupiter.api.Test)3 GatewayProviderException (com.redhat.service.smartevents.infra.exceptions.definitions.user.GatewayProviderException)2 ProcessorDefinition (com.redhat.service.smartevents.infra.models.processors.ProcessorDefinition)2 WebhookAction (com.redhat.service.smartevents.processor.actions.webhook.WebhookAction)2 HashMap (java.util.HashMap)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ProcessorLifecycleException (com.redhat.service.smartevents.infra.exceptions.definitions.user.ProcessorLifecycleException)1 BaseFilter (com.redhat.service.smartevents.infra.models.filters.BaseFilter)1 SendToBridgeAction (com.redhat.service.smartevents.processor.actions.sendtobridge.SendToBridgeAction)1 Transactional (javax.transaction.Transactional)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1