Search in sources :

Example 21 with NonNamespaceOperation

use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project camel by apache.

the class KubernetesReplicationControllersProducer method doListReplicationControllersByLabels.

protected void doListReplicationControllersByLabels(Exchange exchange, String operation) throws Exception {
    ReplicationControllerList rcList = null;
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLERS_LABELS, Map.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    if (!ObjectHelper.isEmpty(namespaceName)) {
        NonNamespaceOperation<ReplicationController, ReplicationControllerList, DoneableReplicationController, RollableScallableResource<ReplicationController, DoneableReplicationController>> replicationControllers;
        replicationControllers = getEndpoint().getKubernetesClient().replicationControllers().inNamespace(namespaceName);
        for (Map.Entry<String, String> entry : labels.entrySet()) {
            replicationControllers.withLabel(entry.getKey(), entry.getValue());
        }
        rcList = replicationControllers.list();
    } else {
        MixedOperation<ReplicationController, ReplicationControllerList, DoneableReplicationController, RollableScallableResource<ReplicationController, DoneableReplicationController>> replicationControllers;
        replicationControllers = getEndpoint().getKubernetesClient().replicationControllers();
        for (Map.Entry<String, String> entry : labels.entrySet()) {
            replicationControllers.withLabel(entry.getKey(), entry.getValue());
        }
        rcList = replicationControllers.list();
    }
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(rcList.getItems());
}
Also used : DoneableReplicationController(io.fabric8.kubernetes.api.model.DoneableReplicationController) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) RollableScallableResource(io.fabric8.kubernetes.client.dsl.RollableScallableResource) Map(java.util.Map) ReplicationControllerList(io.fabric8.kubernetes.api.model.ReplicationControllerList) DoneableReplicationController(io.fabric8.kubernetes.api.model.DoneableReplicationController)

Example 22 with NonNamespaceOperation

use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project camel by apache.

the class KubernetesResourcesQuotaProducer method doListResourceQuotasByLabels.

protected void doListResourceQuotasByLabels(Exchange exchange, String operation) throws Exception {
    ResourceQuotaList resList = null;
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_RESOURCES_QUOTA_LABELS, Map.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    if (!ObjectHelper.isEmpty(namespaceName)) {
        NonNamespaceOperation<ResourceQuota, ResourceQuotaList, DoneableResourceQuota, Resource<ResourceQuota, DoneableResourceQuota>> resQuota;
        resQuota = getEndpoint().getKubernetesClient().resourceQuotas().inNamespace(namespaceName);
        for (Map.Entry<String, String> entry : labels.entrySet()) {
            resQuota.withLabel(entry.getKey(), entry.getValue());
        }
        resList = resQuota.list();
    } else {
        MixedOperation<ResourceQuota, ResourceQuotaList, DoneableResourceQuota, Resource<ResourceQuota, DoneableResourceQuota>> resQuota;
        resQuota = getEndpoint().getKubernetesClient().resourceQuotas();
        for (Map.Entry<String, String> entry : labels.entrySet()) {
            resQuota.withLabel(entry.getKey(), entry.getValue());
        }
        resList = resQuota.list();
    }
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(resList.getItems());
}
Also used : ResourceQuotaList(io.fabric8.kubernetes.api.model.ResourceQuotaList) DoneableResourceQuota(io.fabric8.kubernetes.api.model.DoneableResourceQuota) ResourceQuota(io.fabric8.kubernetes.api.model.ResourceQuota) Resource(io.fabric8.kubernetes.client.dsl.Resource) DoneableResourceQuota(io.fabric8.kubernetes.api.model.DoneableResourceQuota) Map(java.util.Map)

Example 23 with NonNamespaceOperation

use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project camel by apache.

the class KubernetesServicesProducer method doListServiceByLabels.

protected void doListServiceByLabels(Exchange exchange, String operation) throws Exception {
    ServiceList servicesList = null;
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_SERVICE_LABELS, Map.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    if (!ObjectHelper.isEmpty(namespaceName)) {
        NonNamespaceOperation<Service, ServiceList, DoneableService, Resource<Service, DoneableService>> services;
        services = getEndpoint().getKubernetesClient().services().inNamespace(namespaceName);
        for (Map.Entry<String, String> entry : labels.entrySet()) {
            services.withLabel(entry.getKey(), entry.getValue());
        }
        servicesList = services.list();
    } else {
        MixedOperation<Service, ServiceList, DoneableService, Resource<Service, DoneableService>> services;
        services = getEndpoint().getKubernetesClient().services();
        for (Map.Entry<String, String> entry : labels.entrySet()) {
            services.withLabel(entry.getKey(), entry.getValue());
        }
        servicesList = services.list();
    }
    exchange.getOut().setBody(servicesList.getItems());
}
Also used : DoneableService(io.fabric8.kubernetes.api.model.DoneableService) ServiceList(io.fabric8.kubernetes.api.model.ServiceList) Resource(io.fabric8.kubernetes.client.dsl.Resource) DoneableService(io.fabric8.kubernetes.api.model.DoneableService) Service(io.fabric8.kubernetes.api.model.Service) Map(java.util.Map)

Example 24 with NonNamespaceOperation

use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method testCreateContainerGateway.

@Test
public void testCreateContainerGateway() throws Exception {
    OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
    KubernetesGatewayImpl kubernetesGateway = getKubernetesGatewayImpl(openShiftClient);
    Mockito.when(openShiftClient.load(Mockito.any()).get()).thenReturn(getServiceResources(), getDeploymentResources(), getIngressResources());
    NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
    ScalableResource scalableResource = Mockito.mock(ScalableResource.class);
    Mockito.when(scalableResource.get()).thenReturn(null);
    Service service = createService(openShiftClient, nonNamespaceOperation);
    Deployment deployment = createDeployment(openShiftClient, nonNamespaceOperation, scalableResource);
    Ingress ingress = createIngress(openShiftClient, nonNamespaceOperation, scalableResource);
    Mockito.when(nonNamespaceOperation.create(Mockito.any())).thenReturn(service, deployment, ingress);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    kubernetesGateway.createContainerGateway(ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX, api);
    Mockito.verify(openShiftClient, Mockito.times(4)).load(Mockito.any());
    Mockito.verify(openShiftClient, Mockito.times(3)).services();
    Mockito.verify(openShiftClient, Mockito.times(6)).extensions();
}
Also used : ScalableResource(io.fabric8.kubernetes.client.dsl.ScalableResource) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Service(io.fabric8.kubernetes.api.model.Service) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress) API(org.wso2.carbon.apimgt.core.models.API) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Test(org.junit.Test)

Example 25 with NonNamespaceOperation

use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method testCreateDeploymentResourceForInvalidResource.

@Test
public void testCreateDeploymentResourceForInvalidResource() throws Exception {
    OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
    KubernetesGatewayImpl kubernetesGateway = getKubernetesGatewayImpl(openShiftClient);
    HasMetadata invalidMetadata = Mockito.mock(Service.class);
    List<HasMetadata> deploymentResources = new ArrayList<>();
    deploymentResources.add(invalidMetadata);
    Mockito.when(openShiftClient.load(Mockito.any()).get()).thenReturn(getServiceResources(), deploymentResources);
    NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
    ScalableResource scalableResource = Mockito.mock(ScalableResource.class);
    Mockito.when(scalableResource.get()).thenReturn(null);
    Service service = createService(openShiftClient, nonNamespaceOperation);
    Mockito.when(nonNamespaceOperation.create(Mockito.any())).thenReturn(service);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    try {
        kubernetesGateway.createContainerGateway(ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX, api);
    } catch (ContainerBasedGatewayException e) {
        Assert.assertEquals(e.getErrorHandler(), ExceptionCodes.LOADED_RESOURCE_DEFINITION_IS_NOT_VALID);
    }
}
Also used : ScalableResource(io.fabric8.kubernetes.client.dsl.ScalableResource) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) ArrayList(java.util.ArrayList) Service(io.fabric8.kubernetes.api.model.Service) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) API(org.wso2.carbon.apimgt.core.models.API) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Test(org.junit.Test)

Aggregations

OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)17 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)15 Map (java.util.Map)12 Resource (io.fabric8.kubernetes.client.dsl.Resource)9 Service (io.fabric8.kubernetes.api.model.Service)8 Test (org.junit.Test)8 API (org.wso2.carbon.apimgt.core.models.API)8 BeforeTest (org.testng.annotations.BeforeTest)7 Test (org.testng.annotations.Test)7 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)7 ScalableResource (io.fabric8.kubernetes.client.dsl.ScalableResource)6 BaseOperation (io.fabric8.kubernetes.client.dsl.base.BaseOperation)6 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)5 URL (java.net.URL)5 ContainerBasedGatewayException (org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException)5 Ingress (io.fabric8.kubernetes.api.model.extensions.Ingress)3 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 ArrayList (java.util.ArrayList)2 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)1 ConfigMapList (io.fabric8.kubernetes.api.model.ConfigMapList)1