Search in sources :

Example 6 with BaseFilter

use of com.redhat.service.smartevents.infra.models.filters.BaseFilter in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceTest method testUpdateProcessorWithFilter.

@ParameterizedTest
@MethodSource("updateProcessorParams")
void testUpdateProcessorWithFilter(ProcessorRequest request) {
    Processor existingProcessor = createReadyProcessorFromRequest(request);
    when(processorDAO.findByIdBridgeIdAndCustomerId(DEFAULT_BRIDGE_ID, DEFAULT_PROCESSOR_ID, DEFAULT_CUSTOMER_ID)).thenReturn(existingProcessor);
    Set<BaseFilter> updatedFilters = Collections.singleton(new StringEquals("key", "value"));
    request.setFilters(updatedFilters);
    Processor updatedProcessor = processorService.updateProcessor(DEFAULT_BRIDGE_ID, DEFAULT_PROCESSOR_ID, DEFAULT_CUSTOMER_ID, request);
    ProcessorResponse updatedResponse = processorService.toResponse(updatedProcessor);
    assertThat(updatedResponse.getStatus()).isEqualTo(ACCEPTED);
    assertThat(updatedResponse.getFilters()).hasSize(1);
    BaseFilter updatedFilter = updatedResponse.getFilters().iterator().next();
    assertThat(updatedFilter.getKey()).isEqualTo("key");
    assertThat(updatedFilter.getValue()).isEqualTo("value");
    assertThat(updatedResponse.getTransformationTemplate()).isNull();
}
Also used : StringEquals(com.redhat.service.smartevents.infra.models.filters.StringEquals) Processor(com.redhat.service.smartevents.manager.models.Processor) ProcessorResponse(com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse) BaseFilter(com.redhat.service.smartevents.infra.models.filters.BaseFilter) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with BaseFilter

use of com.redhat.service.smartevents.infra.models.filters.BaseFilter in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ShardBridgesSyncAPITest method getProcessorsWithSendToBridgeAction.

@Test
@TestSecurity(user = DEFAULT_CUSTOMER_ID)
public void getProcessorsWithSendToBridgeAction() {
    BridgeResponse bridgeResponse = TestUtils.createBridge(new BridgeRequest(DEFAULT_BRIDGE_NAME)).as(BridgeResponse.class);
    String bridgeId = bridgeResponse.getId();
    // Emulate the Shard having deployed the Bridge
    BridgeDTO bridge = new BridgeDTO(bridgeId, bridgeResponse.getName(), TEST_BRIDGE_ENDPOINT, DEFAULT_CUSTOMER_ID, DEFAULT_USER_NAME, READY, new KafkaConnectionDTO());
    TestUtils.updateBridge(bridge);
    // Create a Processor for the Bridge
    Set<BaseFilter> filters = Collections.singleton(new StringEquals("json.key", "value"));
    Action action = TestUtils.createSendToBridgeAction(bridgeId);
    TestUtils.addProcessorToBridge(bridgeResponse.getId(), new ProcessorRequest(DEFAULT_PROCESSOR_NAME, filters, null, action));
    final List<ProcessorDTO> processors = new ArrayList<>();
    await().atMost(5, SECONDS).untilAsserted(() -> {
        processors.clear();
        processors.addAll(TestUtils.getProcessorsToDeployOrDelete().as(new TypeRef<List<ProcessorDTO>>() {
        }));
        assertThat(processors.size()).isEqualTo(1);
    });
    ProcessorDTO processor = processors.get(0);
    assertThat(processor.getName()).isEqualTo(DEFAULT_PROCESSOR_NAME);
    assertThat(processor.getStatus()).isEqualTo(PREPARING);
    assertThat(processor.getDefinition().getFilters().size()).isEqualTo(1);
    assertThat(processor.getDefinition().getRequestedAction()).isNotNull();
    assertThat(processor.getDefinition().getRequestedAction().getType()).isEqualTo(SendToBridgeAction.TYPE);
    assertThat(processor.getDefinition().getRequestedAction().getParameter(SendToBridgeAction.BRIDGE_ID_PARAM)).isEqualTo(bridgeId);
    assertThat(processor.getDefinition().getResolvedAction()).isNotNull();
    assertThat(processor.getDefinition().getResolvedAction().getType()).isEqualTo(WebhookAction.TYPE);
    assertThat(processor.getDefinition().getResolvedAction().getParameter(WebhookAction.ENDPOINT_PARAM)).isEqualTo(TEST_BRIDGE_WEBHOOK);
}
Also used : StringEquals(com.redhat.service.smartevents.infra.models.filters.StringEquals) BridgeRequest(com.redhat.service.smartevents.manager.api.models.requests.BridgeRequest) BridgeDTO(com.redhat.service.smartevents.infra.models.dto.BridgeDTO) Action(com.redhat.service.smartevents.infra.models.gateways.Action) WebhookAction(com.redhat.service.smartevents.processor.actions.webhook.WebhookAction) KafkaTopicAction(com.redhat.service.smartevents.processor.actions.kafkatopic.KafkaTopicAction) SendToBridgeAction(com.redhat.service.smartevents.processor.actions.sendtobridge.SendToBridgeAction) KafkaConnectionDTO(com.redhat.service.smartevents.infra.models.dto.KafkaConnectionDTO) TypeRef(io.restassured.common.mapper.TypeRef) ArrayList(java.util.ArrayList) BaseFilter(com.redhat.service.smartevents.infra.models.filters.BaseFilter) ProcessorDTO(com.redhat.service.smartevents.infra.models.dto.ProcessorDTO) ProcessorRequest(com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest) BridgeResponse(com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse) TestSecurity(io.quarkus.test.security.TestSecurity) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 8 with BaseFilter

use of com.redhat.service.smartevents.infra.models.filters.BaseFilter in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class TestSupport method newRequestedProcessorDTO.

public static ProcessorDTO newRequestedProcessorDTO() {
    Set<BaseFilter> filters = new HashSet<>();
    filters.add(new StringEquals("key", "value"));
    String transformationTemplate = "{\"test\": {key}}";
    Action a = new Action();
    a.setType(KafkaTopicAction.TYPE);
    Map<String, String> params = new HashMap<>();
    params.put(KafkaTopicAction.TOPIC_PARAM, "myTopic");
    a.setMapParameters(params);
    ProcessorDefinition definition = new ProcessorDefinition(filters, transformationTemplate, a);
    ProcessorDTO dto = new ProcessorDTO();
    dto.setType(PROCESSOR_TYPE);
    dto.setId(PROCESSOR_ID);
    dto.setName(PROCESSOR_NAME);
    dto.setDefinition(definition);
    dto.setBridgeId(BRIDGE_ID);
    dto.setCustomerId(CUSTOMER_ID);
    dto.setOwner(USER_NAME);
    dto.setStatus(PREPARING);
    dto.setKafkaConnection(KAFKA_CONNECTION_DTO);
    return dto;
}
Also used : StringEquals(com.redhat.service.smartevents.infra.models.filters.StringEquals) Action(com.redhat.service.smartevents.infra.models.gateways.Action) KafkaTopicAction(com.redhat.service.smartevents.processor.actions.kafkatopic.KafkaTopicAction) HashMap(java.util.HashMap) ProcessorDTO(com.redhat.service.smartevents.infra.models.dto.ProcessorDTO) ProcessorDefinition(com.redhat.service.smartevents.infra.models.processors.ProcessorDefinition) BaseFilter(com.redhat.service.smartevents.infra.models.filters.BaseFilter) HashSet(java.util.HashSet)

Example 9 with BaseFilter

use of com.redhat.service.smartevents.infra.models.filters.BaseFilter 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 10 with BaseFilter

use of com.redhat.service.smartevents.infra.models.filters.BaseFilter in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceImpl method doCreateProcessor.

private Processor doCreateProcessor(Bridge bridge, String customerId, String owner, ProcessorType processorType, ProcessorRequest processorRequest) {
    String bridgeId = bridge.getId();
    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();
    newProcessor.setType(processorType);
    newProcessor.setName(processorRequest.getName());
    newProcessor.setSubmittedAt(ZonedDateTime.now());
    newProcessor.setStatus(ManagedResourceStatus.ACCEPTED);
    newProcessor.setBridge(bridge);
    newProcessor.setShardId(shardService.getAssignedShardId(newProcessor.getId()));
    newProcessor.setOwner(owner);
    Set<BaseFilter> requestedFilters = processorRequest.getFilters();
    String requestedTransformationTemplate = processorRequest.getTransformationTemplate();
    Action resolvedAction = processorType == ProcessorType.SOURCE ? resolveSource(processorRequest.getSource(), customerId, bridge.getId(), newProcessor.getId()) : resolveAction(processorRequest.getAction(), customerId, bridge.getId(), newProcessor.getId());
    ProcessorDefinition definition = processorType == ProcessorType.SOURCE ? new ProcessorDefinition(requestedFilters, requestedTransformationTemplate, processorRequest.getSource(), resolvedAction) : new ProcessorDefinition(requestedFilters, requestedTransformationTemplate, processorRequest.getAction(), resolvedAction);
    newProcessor.setDefinition(definition);
    // Processor, Connector and Work should always be created in the same transaction
    processorDAO.persist(newProcessor);
    connectorService.createConnectorEntity(newProcessor);
    workManager.schedule(newProcessor);
    metricsService.onOperationStart(newProcessor, MetricsOperation.PROVISION);
    LOGGER.info("Processor with id '{}' for customer '{}' on bridge '{}' has been marked for creation", newProcessor.getId(), newProcessor.getBridge().getCustomerId(), newProcessor.getBridge().getId());
    return newProcessor;
}
Also used : 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) BaseFilter(com.redhat.service.smartevents.infra.models.filters.BaseFilter) AlreadyExistingItemException(com.redhat.service.smartevents.infra.exceptions.definitions.user.AlreadyExistingItemException)

Aggregations

BaseFilter (com.redhat.service.smartevents.infra.models.filters.BaseFilter)16 StringEquals (com.redhat.service.smartevents.infra.models.filters.StringEquals)14 ProcessorRequest (com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest)11 BridgeResponse (com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse)11 QuarkusTest (io.quarkus.test.junit.QuarkusTest)11 TestSecurity (io.quarkus.test.security.TestSecurity)11 Test (org.junit.jupiter.api.Test)11 ProcessorResponse (com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse)10 ProcessorListResponse (com.redhat.service.smartevents.manager.api.models.responses.ProcessorListResponse)9 Response (io.restassured.response.Response)9 Action (com.redhat.service.smartevents.infra.models.gateways.Action)7 Processor (com.redhat.service.smartevents.manager.models.Processor)5 KafkaTopicAction (com.redhat.service.smartevents.processor.actions.kafkatopic.KafkaTopicAction)5 Bridge (com.redhat.service.smartevents.manager.models.Bridge)4 BridgeDTO (com.redhat.service.smartevents.infra.models.dto.BridgeDTO)3 ProcessorDTO (com.redhat.service.smartevents.infra.models.dto.ProcessorDTO)3 ProcessorDefinition (com.redhat.service.smartevents.infra.models.processors.ProcessorDefinition)3 BridgeRequest (com.redhat.service.smartevents.manager.api.models.requests.BridgeRequest)3 SendToBridgeAction (com.redhat.service.smartevents.processor.actions.sendtobridge.SendToBridgeAction)3 TypeRef (io.restassured.common.mapper.TypeRef)3