Search in sources :

Example 11 with ProcessorDefinition

use of com.redhat.service.bridge.infra.models.processors.ProcessorDefinition 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}}";
    BaseAction a = new BaseAction();
    a.setType(KafkaTopicAction.TYPE);
    Map<String, String> params = new HashMap<>();
    params.put(KafkaTopicAction.TOPIC_PARAM, "myTopic");
    a.setParameters(params);
    ProcessorDefinition definition = new ProcessorDefinition(filters, transformationTemplate, a);
    return new ProcessorDTO(PROCESSOR_ID, PROCESSOR_NAME, definition, BRIDGE_ID, CUSTOMER_ID, ManagedResourceStatus.ACCEPTED, KAFKA_CONNECTION_DTO);
}
Also used : StringEquals(com.redhat.service.bridge.infra.models.filters.StringEquals) HashMap(java.util.HashMap) ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) ProcessorDefinition(com.redhat.service.bridge.infra.models.processors.ProcessorDefinition) BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) BaseFilter(com.redhat.service.bridge.infra.models.filters.BaseFilter) HashSet(java.util.HashSet)

Example 12 with ProcessorDefinition

use of com.redhat.service.bridge.infra.models.processors.ProcessorDefinition in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ConnectorsDAOTest method createProcessor.

private Processor createProcessor(Bridge bridge, String name) {
    Processor p = new Processor();
    p.setBridge(bridge);
    p.setName(name);
    p.setStatus(ManagedResourceStatus.ACCEPTED);
    p.setSubmittedAt(ZonedDateTime.now());
    p.setPublishedAt(ZonedDateTime.now());
    BaseAction a = new BaseAction();
    a.setType(KafkaTopicAction.TYPE);
    Map<String, String> params = new HashMap<>();
    params.put(KafkaTopicAction.TOPIC_PARAM, TestConstants.DEFAULT_KAFKA_TOPIC);
    a.setParameters(params);
    ProcessorDefinition definition = new ProcessorDefinition(Collections.emptySet(), null, a);
    p.setDefinition(mapper.valueToTree(definition));
    processorDAO.persist(p);
    return p;
}
Also used : Processor(com.redhat.service.bridge.manager.models.Processor) HashMap(java.util.HashMap) ProcessorDefinition(com.redhat.service.bridge.infra.models.processors.ProcessorDefinition) BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction)

Example 13 with ProcessorDefinition

use of com.redhat.service.bridge.infra.models.processors.ProcessorDefinition in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class KafkaTopicActionValidatorTest method createProcessorWithActionForTopic.

private ProcessorDTO createProcessorWithActionForTopic(String topicName) {
    BaseAction b = new BaseAction();
    b.setType(KafkaTopicAction.TYPE);
    Map<String, String> params = new HashMap<>();
    params.put(KafkaTopicAction.TOPIC_PARAM, topicName);
    b.setParameters(params);
    ProcessorDTO p = new ProcessorDTO();
    p.setId("myProcessor");
    p.setDefinition(new ProcessorDefinition(null, null, b));
    p.setBridgeId("myBridge");
    return p;
}
Also used : HashMap(java.util.HashMap) ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) ProcessorDefinition(com.redhat.service.bridge.infra.models.processors.ProcessorDefinition) BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction)

Example 14 with ProcessorDefinition

use of com.redhat.service.bridge.infra.models.processors.ProcessorDefinition in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ExecutorTest method testMetricsAreProduced.

@Test
public void testMetricsAreProduced() throws JsonProcessingException {
    Set<BaseFilter> filters = new HashSet<>();
    filters.add(new StringEquals("data.key", "value"));
    BaseAction action = new BaseAction();
    action.setType(KafkaTopicAction.TYPE);
    String transformationTemplate = "{\"test\": \"{data.key}\"}";
    ProcessorDTO processorDTO = createProcessor(new ProcessorDefinition(filters, transformationTemplate, action));
    Executor executor = new Executor(processorDTO, filterEvaluatorFactory, transformationEvaluatorFactory, actionProviderFactoryMock, meterRegistry);
    CloudEvent cloudEvent = createCloudEvent();
    executor.onEvent(cloudEvent);
    assertThat(meterRegistry.getMeters().stream().anyMatch(x -> x.getId().getName().equals(MetricsConstants.PROCESSOR_PROCESSING_TIME_METRIC_NAME))).isTrue();
    assertThat(meterRegistry.getMeters().stream().anyMatch(x -> x.getId().getName().equals(MetricsConstants.FILTER_PROCESSING_TIME_METRIC_NAME))).isTrue();
    assertThat(meterRegistry.getMeters().stream().anyMatch(x -> x.getId().getName().equals(MetricsConstants.TRANSFORMATION_PROCESSING_TIME_METRIC_NAME))).isTrue();
    assertThat(meterRegistry.getMeters().stream().anyMatch(x -> x.getId().getName().equals(MetricsConstants.ACTION_PROCESSING_TIME_METRIC_NAME))).isTrue();
}
Also used : StringEquals(com.redhat.service.bridge.infra.models.filters.StringEquals) ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) ProcessorDefinition(com.redhat.service.bridge.infra.models.processors.ProcessorDefinition) BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) BaseFilter(com.redhat.service.bridge.infra.models.filters.BaseFilter) CloudEvent(io.cloudevents.CloudEvent) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 15 with ProcessorDefinition

use of com.redhat.service.bridge.infra.models.processors.ProcessorDefinition in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceImpl method toResponse.

@Override
public ProcessorResponse toResponse(Processor processor) {
    ProcessorResponse processorResponse = new ProcessorResponse();
    processorResponse.setId(processor.getId());
    processorResponse.setName(processor.getName());
    processorResponse.setStatus(processor.getStatus());
    processorResponse.setPublishedAt(processor.getPublishedAt());
    processorResponse.setSubmittedAt(processor.getSubmittedAt());
    if (processor.getDefinition() != null) {
        ProcessorDefinition definition = jsonNodeToDefinition(processor.getDefinition());
        processorResponse.setFilters(definition.getFilters());
        processorResponse.setTransformationTemplate(definition.getTransformationTemplate());
        processorResponse.setAction(definition.getRequestedAction());
    }
    if (processor.getBridge() != null) {
        processorResponse.setHref(APIConstants.USER_API_BASE_PATH + processor.getBridge().getId() + "/processors/" + processor.getId());
    }
    return processorResponse;
}
Also used : ProcessorResponse(com.redhat.service.bridge.manager.api.models.responses.ProcessorResponse) ProcessorDefinition(com.redhat.service.bridge.infra.models.processors.ProcessorDefinition)

Aggregations

ProcessorDefinition (com.redhat.service.bridge.infra.models.processors.ProcessorDefinition)16 BaseAction (com.redhat.service.bridge.infra.models.actions.BaseAction)13 ProcessorDTO (com.redhat.service.bridge.infra.models.dto.ProcessorDTO)10 BaseFilter (com.redhat.service.bridge.infra.models.filters.BaseFilter)7 Test (org.junit.jupiter.api.Test)7 StringEquals (com.redhat.service.bridge.infra.models.filters.StringEquals)6 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 Processor (com.redhat.service.bridge.manager.models.Processor)5 CloudEvent (io.cloudevents.CloudEvent)5 Bridge (com.redhat.service.bridge.manager.models.Bridge)3 ProcessorResponse (com.redhat.service.bridge.manager.api.models.responses.ProcessorResponse)2 QuarkusTest (io.quarkus.test.junit.QuarkusTest)2 ActionProvider (com.redhat.service.bridge.actions.ActionProvider)1 AlreadyExistingItemException (com.redhat.service.bridge.infra.exceptions.definitions.user.AlreadyExistingItemException)1 KafkaConnectionDTO (com.redhat.service.bridge.infra.models.dto.KafkaConnectionDTO)1 ProcessorRequest (com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest)1