Search in sources :

Example 6 with BridgeDTO

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

the class BridgeIngressController method notifyManager.

private void notifyManager(BridgeIngress bridgeIngress, ManagedResourceStatus status) {
    BridgeDTO dto = bridgeIngress.toDTO();
    dto.setStatus(status);
    managerSyncService.notifyBridgeStatusChange(dto).subscribe().with(success -> LOGGER.info("Updating Bridge with id '{}' done", dto.getId()), failure -> LOGGER.error("Updating Bridge with id '{}' FAILED", dto.getId()));
}
Also used : BridgeDTO(com.redhat.service.bridge.infra.models.dto.BridgeDTO)

Example 7 with BridgeDTO

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

the class ShardBridgesSyncAPITest method testNotifyDeletion.

@Test
@TestSecurity(user = TestConstants.DEFAULT_CUSTOMER_ID)
public void testNotifyDeletion() {
    TestUtils.createBridge(new BridgeRequest(TestConstants.DEFAULT_BRIDGE_NAME));
    List<BridgeDTO> bridgesToDeploy = TestUtils.getBridgesToDeployOrDelete().as(new TypeRef<List<BridgeDTO>>() {
    });
    BridgeDTO bridge = bridgesToDeploy.get(0);
    TestUtils.deleteBridge(bridge.getId()).then().statusCode(202);
    BridgeResponse bridgeResponse = TestUtils.getBridge(bridge.getId()).as(BridgeResponse.class);
    assertThat(bridgeResponse.getStatus()).isEqualTo(ManagedResourceStatus.DEPROVISION);
    bridge.setStatus(ManagedResourceStatus.DELETED);
    TestUtils.updateBridge(bridge).then().statusCode(200);
    TestUtils.getBridge(bridge.getId()).then().statusCode(404);
}
Also used : BridgeRequest(com.redhat.service.bridge.manager.api.models.requests.BridgeRequest) BridgeDTO(com.redhat.service.bridge.infra.models.dto.BridgeDTO) 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)

Example 8 with BridgeDTO

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

the class ServiceMonitorServiceTest method fetchOrCreateServiceMonitor.

@Test
@WithPrometheus
void fetchOrCreateServiceMonitor() {
    // Given
    final BridgeDTO bridge = TestSupport.newAvailableBridgeDTO();
    final BridgeIngress bridgeIngress = BridgeIngress.fromDTO(bridge, "default", TestSupport.INGRESS_IMAGE);
    final Secret secretMock = new SecretBuilder().withMetadata(new ObjectMetaBuilder().withName(bridgeIngress.getMetadata().getName()).build()).build();
    final Deployment deployment = bridgeIngressService.fetchOrCreateBridgeIngressDeployment(bridgeIngress, secretMock);
    final Service service = bridgeIngressService.fetchOrCreateBridgeIngressService(bridgeIngress, deployment);
    // When
    final Optional<ServiceMonitor> serviceMonitor = serviceMonitorService.fetchOrCreateServiceMonitor(bridgeIngress, service, "ingress");
    // Then
    assertThat(serviceMonitor).isPresent();
    // check: https://prometheus-operator.dev/docs/operator/troubleshooting/#overview-of-servicemonitor-tagging-and-related-elements
    assertThat(serviceMonitor.get().getSpec().getSelector().getMatchLabels()).containsEntry(LabelsBuilder.INSTANCE_LABEL, deployment.getMetadata().getName());
    assertThat(serviceMonitor.get().getMetadata().getLabels()).containsEntry(LabelsBuilder.INSTANCE_LABEL, deployment.getMetadata().getName());
    assertThat(serviceMonitor.get().getMetadata().getLabels()).containsEntry(LabelsBuilder.MANAGED_BY_LABEL, LabelsBuilder.OPERATOR_NAME);
    assertThat(serviceMonitor.get().getMetadata().getLabels()).containsEntry(LabelsBuilder.CREATED_BY_LABEL, LabelsBuilder.OPERATOR_NAME);
    assertThat(serviceMonitor.get().getMetadata().getLabels()).containsEntry(LabelsBuilder.COMPONENT_LABEL, "ingress");
    assertThat(service.getMetadata().getLabels()).containsEntry(LabelsBuilder.INSTANCE_LABEL, deployment.getMetadata().getName());
}
Also used : BridgeIngress(com.redhat.service.bridge.shard.operator.resources.BridgeIngress) Secret(io.fabric8.kubernetes.api.model.Secret) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) BridgeDTO(com.redhat.service.bridge.infra.models.dto.BridgeDTO) ServiceMonitor(io.fabric8.openshift.api.model.monitoring.v1.ServiceMonitor) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) BridgeIngressService(com.redhat.service.bridge.shard.operator.BridgeIngressService) Service(io.fabric8.kubernetes.api.model.Service) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) WithPrometheus(com.redhat.service.bridge.shard.operator.WithPrometheus)

Example 9 with BridgeDTO

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

the class CustomerNamespaceProviderImplTest method testNamespaceDeletedWhenEmpty.

@Test
void testNamespaceDeletedWhenEmpty() {
    final BridgeDTO dto = TestSupport.newRequestedBridgeDTO();
    dto.setCustomerId("hofstadter");
    bridgeIngressService.createBridgeIngress(dto);
    // Wait until BridgeIngress is really created, can take some time due to client caching - https://issues.redhat.com/browse/MGDOBR-308
    Awaitility.await().atMost(Duration.ofSeconds(5)).until(() -> kubernetesClient.resources(BridgeIngress.class).inNamespace(customerNamespaceProvider.resolveName(dto.getCustomerId())).withName(BridgeIngress.resolveResourceName(dto.getId())).get() != null);
    // there's only one bridge there
    bridgeIngressService.deleteBridgeIngress(dto);
    Awaitility.await().atMost(Duration.ofSeconds(60)).until(() -> kubernetesClient.resources(BridgeIngress.class).withName(BridgeIngress.resolveResourceName(dto.getId())).get() == null);
    customerNamespaceProvider.cleanUpEmptyNamespaces();
    Awaitility.await().atMost(Duration.ofSeconds(60)).until(() -> kubernetesClient.namespaces().withName(customerNamespaceProvider.resolveName(dto.getCustomerId())).get() == null);
}
Also used : BridgeIngress(com.redhat.service.bridge.shard.operator.resources.BridgeIngress) BridgeDTO(com.redhat.service.bridge.infra.models.dto.BridgeDTO) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 10 with BridgeDTO

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

the class CustomerNamespaceProviderImplTest method testNamespaceNotDeletedWithBridges.

@Test
void testNamespaceNotDeletedWithBridges() {
    final BridgeDTO dto = TestSupport.newRequestedBridgeDTO();
    dto.setCustomerId("cooper");
    bridgeIngressService.createBridgeIngress(dto);
    // Wait until BridgeIngress is really created, can take some time due to client caching
    Awaitility.await().atMost(Duration.ofSeconds(5)).until(() -> kubernetesClient.resources(BridgeIngress.class).inNamespace(customerNamespaceProvider.resolveName(dto.getCustomerId())).withName(BridgeIngress.resolveResourceName(dto.getId())).get() != null);
    // try to delete the namespace...
    customerNamespaceProvider.deleteNamespaceIfEmpty(kubernetesClient.namespaces().withName("ob-cooper").get());
    final Namespace namespace = kubernetesClient.namespaces().withName(customerNamespaceProvider.resolveName(dto.getCustomerId())).get();
    assertThat(namespace).isNotNull();
}
Also used : BridgeIngress(com.redhat.service.bridge.shard.operator.resources.BridgeIngress) BridgeDTO(com.redhat.service.bridge.infra.models.dto.BridgeDTO) Namespace(io.fabric8.kubernetes.api.model.Namespace) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Aggregations

BridgeDTO (com.redhat.service.bridge.infra.models.dto.BridgeDTO)29 Test (org.junit.jupiter.api.Test)24 QuarkusTest (io.quarkus.test.junit.QuarkusTest)23 TestSecurity (io.quarkus.test.security.TestSecurity)11 BridgeRequest (com.redhat.service.bridge.manager.api.models.requests.BridgeRequest)10 BridgeResponse (com.redhat.service.bridge.manager.api.models.responses.BridgeResponse)10 KafkaConnectionDTO (com.redhat.service.bridge.infra.models.dto.KafkaConnectionDTO)9 ProcessorDTO (com.redhat.service.bridge.infra.models.dto.ProcessorDTO)9 List (java.util.List)9 ProcessorRequest (com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest)8 BridgeIngress (com.redhat.service.bridge.shard.operator.resources.BridgeIngress)6 BaseFilter (com.redhat.service.bridge.infra.models.filters.BaseFilter)5 StringEquals (com.redhat.service.bridge.infra.models.filters.StringEquals)5 BaseAction (com.redhat.service.bridge.infra.models.actions.BaseAction)4 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)4 TypeRef (io.restassured.common.mapper.TypeRef)4 ResponseLoggingFilter (io.restassured.filter.log.ResponseLoggingFilter)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 KafkaTopicAction (com.redhat.service.bridge.actions.kafkatopic.KafkaTopicAction)3 WebhookAction (com.redhat.service.bridge.actions.webhook.WebhookAction)3