Search in sources :

Example 16 with ProcessorDTO

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

the class ProcessorServiceImpl method toDTO.

@Override
public ProcessorDTO toDTO(Processor processor) {
    ProcessorDefinition definition = processor.getDefinition() != null ? jsonNodeToDefinition(processor.getDefinition()) : null;
    KafkaConnectionDTO kafkaConnectionDTO = new KafkaConnectionDTO(internalKafkaConfigurationProvider.getBootstrapServers(), internalKafkaConfigurationProvider.getClientId(), internalKafkaConfigurationProvider.getClientSecret(), internalKafkaConfigurationProvider.getSecurityProtocol(), bridgesService.getBridgeTopicName(processor.getBridge()));
    return new ProcessorDTO(processor.getId(), processor.getName(), definition, processor.getBridge().getId(), processor.getBridge().getCustomerId(), processor.getStatus(), kafkaConnectionDTO);
}
Also used : KafkaConnectionDTO(com.redhat.service.bridge.infra.models.dto.KafkaConnectionDTO) ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) ProcessorDefinition(com.redhat.service.bridge.infra.models.processors.ProcessorDefinition)

Example 17 with ProcessorDTO

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

the class ShardBridgesSyncAPITest method getProcessorsWithKafkaAction.

@Test
@TestSecurity(user = TestConstants.DEFAULT_CUSTOMER_ID)
public void getProcessorsWithKafkaAction() {
    BridgeResponse bridgeResponse = TestUtils.createBridge(new BridgeRequest(TestConstants.DEFAULT_BRIDGE_NAME)).as(BridgeResponse.class);
    BridgeDTO bridge = new BridgeDTO(bridgeResponse.getId(), bridgeResponse.getName(), TEST_BRIDGE_ENDPOINT, TestConstants.DEFAULT_CUSTOMER_ID, ManagedResourceStatus.READY, new KafkaConnectionDTO());
    Set<BaseFilter> filters = Collections.singleton(new StringEquals("json.key", "value"));
    TestUtils.updateBridge(bridge);
    TestUtils.addProcessorToBridge(bridgeResponse.getId(), new ProcessorRequest(TestConstants.DEFAULT_PROCESSOR_NAME, filters, null, TestUtils.createKafkaAction()));
    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(KafkaTopicAction.TYPE);
    assertThat(processor.getDefinition().getRequestedAction().getParameters()).containsEntry(KafkaTopicAction.TOPIC_PARAM, TestConstants.DEFAULT_KAFKA_TOPIC);
    assertThat(processor.getDefinition().getResolvedAction()).isNotNull();
    assertThat(processor.getDefinition().getResolvedAction().getType()).isEqualTo(KafkaTopicAction.TYPE);
    assertThat(processor.getDefinition().getResolvedAction().getParameters()).containsEntry(KafkaTopicAction.TOPIC_PARAM, TestConstants.DEFAULT_KAFKA_TOPIC);
}
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) 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) BaseFilter(com.redhat.service.bridge.infra.models.filters.BaseFilter) TestSecurity(io.quarkus.test.security.TestSecurity) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 18 with ProcessorDTO

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

the class ShardBridgesSyncAPITest method metricsAreProduced.

@Test
@TestSecurity(user = TestConstants.DEFAULT_CUSTOMER_ID)
public void metricsAreProduced() {
    BridgeResponse bridgeResponse = TestUtils.createBridge(new BridgeRequest(TestConstants.DEFAULT_BRIDGE_NAME)).as(BridgeResponse.class);
    BridgeDTO bridge = new BridgeDTO(bridgeResponse.getId(), bridgeResponse.getName(), TEST_BRIDGE_ENDPOINT, TestConstants.DEFAULT_CUSTOMER_ID, ManagedResourceStatus.READY, new KafkaConnectionDTO());
    TestUtils.updateBridge(bridge);
    TestUtils.addProcessorToBridge(bridgeResponse.getId(), new ProcessorRequest(TestConstants.DEFAULT_PROCESSOR_NAME, TestUtils.createKafkaAction()));
    List<ProcessorDTO> processors = TestUtils.getProcessorsToDeployOrDelete().as(new TypeRef<List<ProcessorDTO>>() {
    });
    ProcessorDTO processor = processors.get(0);
    processor.setStatus(ManagedResourceStatus.READY);
    TestUtils.updateProcessor(processor);
    String metrics = given().filter(new ResponseLoggingFilter()).contentType(ContentType.JSON).when().get("/q/metrics").then().extract().body().asString();
    assertThat(metrics).contains("manager_processor_status_change_total");
    assertThat(metrics).contains("manager_bridge_status_change_total");
}
Also used : 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) ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) ProcessorRequest(com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest) List(java.util.List) ResponseLoggingFilter(io.restassured.filter.log.ResponseLoggingFilter) 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)

Example 19 with ProcessorDTO

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

the class ManagerSyncServiceTest method testProcessorsAreDeployed.

@Test
@WithPrometheus
public void testProcessorsAreDeployed() throws Exception {
    ProcessorDTO processor = TestSupport.newRequestedProcessorDTO();
    stubProcessorsToDeployOrDelete(Collections.singletonList(processor));
    stubProcessorUpdate();
    // Two updates to the manager are expected (1 provisioning + 1 ready)
    CountDownLatch latch = new CountDownLatch(2);
    addProcessorUpdateRequestListener(latch);
    managerSyncService.fetchAndProcessProcessorsToDeployOrDelete().await().atMost(Duration.ofSeconds(5));
    String customerNamespace = customerNamespaceProvider.resolveName(TestSupport.CUSTOMER_ID);
    String sanitizedName = BridgeExecutor.resolveResourceName(processor.getId());
    Awaitility.await().atMost(Duration.ofMinutes(3)).pollInterval(Duration.ofSeconds(5)).untilAsserted(() -> {
        kubernetesResourcePatcher.patchReadyDeploymentAsReady(sanitizedName, customerNamespace);
        kubernetesResourcePatcher.patchReadyService(sanitizedName, customerNamespace);
    });
    assertThat(latch.await(60, TimeUnit.SECONDS)).isTrue();
    processor.setStatus(ManagedResourceStatus.READY);
    // the kafka connection is not included in the shard update for the manager
    processor.setKafkaConnection(null);
    wireMockServer.verify(putRequestedFor(urlEqualTo(APIConstants.SHARD_API_BASE_PATH + "processors")).withRequestBody(equalToJson(objectMapper.writeValueAsString(processor), true, true)).withHeader("Content-Type", equalTo("application/json")));
}
Also used : ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) CountDownLatch(java.util.concurrent.CountDownLatch) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 20 with ProcessorDTO

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

the class ManagerSyncServiceTest method notifyProcessorStatusChange.

@Test
public void notifyProcessorStatusChange() throws Exception {
    ProcessorDTO processor = TestSupport.newRequestedProcessorDTO();
    stubProcessorUpdate();
    // One update to the manager is expected
    CountDownLatch latch = new CountDownLatch(1);
    addProcessorUpdateRequestListener(latch);
    managerSyncService.notifyProcessorStatusChange(processor).await().atMost(Duration.ofSeconds(5));
    assertThat(latch.await(60, TimeUnit.SECONDS)).isTrue();
    wireMockServer.verify(putRequestedFor(urlEqualTo(APIConstants.SHARD_API_BASE_PATH + "processors")).withRequestBody(equalToJson(objectMapper.writeValueAsString(processor), true, true)).withHeader("Content-Type", equalTo("application/json")));
}
Also used : ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) CountDownLatch(java.util.concurrent.CountDownLatch) 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