Search in sources :

Example 21 with ProcessorDTO

use of com.redhat.service.bridge.infra.models.dto.ProcessorDTO 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 22 with ProcessorDTO

use of com.redhat.service.bridge.infra.models.dto.ProcessorDTO in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeExecutorServiceTest method testBridgeIngressDeletion.

@Test
public void testBridgeIngressDeletion() {
    // Given
    ProcessorDTO dto = TestSupport.newRequestedProcessorDTO();
    // When
    bridgeExecutorService.createBridgeExecutor(dto);
    bridgeExecutorService.deleteBridgeExecutor(dto);
    // Then
    BridgeExecutor bridgeExecutor = kubernetesClient.resources(BridgeExecutor.class).inNamespace(customerNamespaceProvider.resolveName(dto.getCustomerId())).withName(BridgeExecutor.resolveResourceName(dto.getId())).get();
    assertThat(bridgeExecutor).isNull();
}
Also used : ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) BridgeExecutor(com.redhat.service.bridge.shard.operator.resources.BridgeExecutor) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 23 with ProcessorDTO

use of com.redhat.service.bridge.infra.models.dto.ProcessorDTO in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeExecutorServiceTest method testBridgeExecutorCreationTriggersController.

@Test
public void testBridgeExecutorCreationTriggersController() {
    // Given
    ProcessorDTO dto = TestSupport.newRequestedProcessorDTO();
    // When
    bridgeExecutorService.createBridgeExecutor(dto);
    // Then
    Awaitility.await().atMost(Duration.ofMinutes(2)).pollInterval(Duration.ofSeconds(5)).untilAsserted(() -> {
        // The deployment is deployed by the controller
        Deployment deployment = kubernetesClient.apps().deployments().inNamespace(customerNamespaceProvider.resolveName(dto.getCustomerId())).withName(BridgeExecutor.resolveResourceName(dto.getId())).get();
        assertThat(deployment).isNotNull();
        assertThat(deployment.getSpec().getProgressDeadlineSeconds()).isEqualTo(60);
        List<EnvVar> environmentVariables = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv();
        assertThat(environmentVariables.stream().filter(x -> x.getName().equals(Constants.BRIDGE_EXECUTOR_PROCESSOR_DEFINITION_ENV_VAR)).findFirst().get().getValue().length()).isGreaterThan(0);
        assertThat(environmentVariables.stream().filter(x -> x.getName().equals(Constants.BRIDGE_EXECUTOR_WEBHOOK_TECHNICAL_BEARER_TOKEN_ENV_VAR)).findFirst().get().getValue().length()).isGreaterThan(0);
    });
}
Also used : ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 24 with ProcessorDTO

use of com.redhat.service.bridge.infra.models.dto.ProcessorDTO in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeExecutor method toDTO.

public ProcessorDTO toDTO() {
    ProcessorDTO processorDTO = new ProcessorDTO();
    processorDTO.setId(this.getSpec().getId());
    // TODO: think about removing bridgeDTO from the processorDTO and keep only bridgeId and customerId!
    processorDTO.setBridgeId(this.getSpec().getBridgeId());
    processorDTO.setCustomerId(this.getSpec().getCustomerId());
    processorDTO.setName(this.getSpec().getProcessorName());
    if (this.getSpec().getProcessorDefinition() != null) {
        try {
            processorDTO.setDefinition(MAPPER.readValue(this.getSpec().getProcessorDefinition(), ProcessorDefinition.class));
        } catch (JsonProcessingException e) {
            LOGGER.error("Could not deserialize Processor Definition while converting BridgeExecutor to ProcessorDTO", e);
        }
    }
    return processorDTO;
}
Also used : ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) ProcessorDefinition(com.redhat.service.bridge.infra.models.processors.ProcessorDefinition) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 25 with ProcessorDTO

use of com.redhat.service.bridge.infra.models.dto.ProcessorDTO in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ShardBridgesSyncAPITest method getProcessorsWithSendToBridgeAction.

@Test
@TestSecurity(user = TestConstants.DEFAULT_CUSTOMER_ID)
public void getProcessorsWithSendToBridgeAction() {
    BridgeResponse bridgeResponse = TestUtils.createBridge(new BridgeRequest(TestConstants.DEFAULT_BRIDGE_NAME)).as(BridgeResponse.class);
    String bridgeId = bridgeResponse.getId();
    BridgeDTO bridge = new BridgeDTO(bridgeId, bridgeResponse.getName(), TEST_BRIDGE_ENDPOINT, TestConstants.DEFAULT_CUSTOMER_ID, ManagedResourceStatus.READY, new KafkaConnectionDTO());
    Set<BaseFilter> filters = Collections.singleton(new StringEquals("json.key", "value"));
    BaseAction action = TestUtils.createSendToBridgeAction(bridgeId);
    TestUtils.updateBridge(bridge);
    TestUtils.addProcessorToBridge(bridgeResponse.getId(), new ProcessorRequest(TestConstants.DEFAULT_PROCESSOR_NAME, filters, null, action));
    List<ProcessorDTO> processors = TestUtils.getProcessorsToDeployOrDelete().as(new TypeRef<List<ProcessorDTO>>() {
    });
    assertThat(processors.size()).isEqualTo(1);
    ProcessorDTO processor = processors.get(0);
    assertThat(processor.getName()).isEqualTo(TestConstants.DEFAULT_PROCESSOR_NAME);
    assertThat(processor.getStatus()).isEqualTo(ManagedResourceStatus.ACCEPTED);
    assertThat(processor.getDefinition().getFilters().size()).isEqualTo(1);
    assertThat(processor.getDefinition().getRequestedAction()).isNotNull();
    assertThat(processor.getDefinition().getRequestedAction().getType()).isEqualTo(SendToBridgeAction.TYPE);
    assertThat(processor.getDefinition().getRequestedAction().getParameters()).containsEntry(SendToBridgeAction.BRIDGE_ID_PARAM, bridgeId);
    assertThat(processor.getDefinition().getResolvedAction()).isNotNull();
    assertThat(processor.getDefinition().getResolvedAction().getType()).isEqualTo(WebhookAction.TYPE);
    assertThat(processor.getDefinition().getResolvedAction().getParameters()).containsEntry(WebhookAction.ENDPOINT_PARAM, TEST_BRIDGE_WEBHOOK);
}
Also used : StringEquals(com.redhat.service.bridge.infra.models.filters.StringEquals) BridgeRequest(com.redhat.service.bridge.manager.api.models.requests.BridgeRequest) BridgeDTO(com.redhat.service.bridge.infra.models.dto.BridgeDTO) KafkaConnectionDTO(com.redhat.service.bridge.infra.models.dto.KafkaConnectionDTO) BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) BaseFilter(com.redhat.service.bridge.infra.models.filters.BaseFilter) ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) ProcessorRequest(com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest) List(java.util.List) BridgeResponse(com.redhat.service.bridge.manager.api.models.responses.BridgeResponse) TestSecurity(io.quarkus.test.security.TestSecurity) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Aggregations

ProcessorDTO (com.redhat.service.bridge.infra.models.dto.ProcessorDTO)39 Test (org.junit.jupiter.api.Test)28 QuarkusTest (io.quarkus.test.junit.QuarkusTest)21 ProcessorDefinition (com.redhat.service.bridge.infra.models.processors.ProcessorDefinition)11 BaseAction (com.redhat.service.bridge.infra.models.actions.BaseAction)10 BaseFilter (com.redhat.service.bridge.infra.models.filters.BaseFilter)8 StringEquals (com.redhat.service.bridge.infra.models.filters.StringEquals)8 BridgeDTO (com.redhat.service.bridge.infra.models.dto.BridgeDTO)6 HashSet (java.util.HashSet)6 KafkaConnectionDTO (com.redhat.service.bridge.infra.models.dto.KafkaConnectionDTO)5 ProcessorRequest (com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest)5 CloudEvent (io.cloudevents.CloudEvent)5 TestSecurity (io.quarkus.test.security.TestSecurity)5 BridgeRequest (com.redhat.service.bridge.manager.api.models.requests.BridgeRequest)4 BridgeResponse (com.redhat.service.bridge.manager.api.models.responses.BridgeResponse)4 HashMap (java.util.HashMap)4 List (java.util.List)4 ActionInvoker (com.redhat.service.bridge.actions.ActionInvoker)2 ValidationResult (com.redhat.service.bridge.actions.ValidationResult)2 ActionProviderException (com.redhat.service.bridge.infra.exceptions.definitions.user.ActionProviderException)2