Search in sources :

Example 31 with Namespace

use of io.fabric8.kubernetes.api.model.Namespace in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method createService.

/**
 * Create Service resource
 *
 * @param openShiftClient       Openshift client
 * @param nonNamespaceOperation NonNamespaceOperation instance
 */
private Service createService(OpenShiftClient openShiftClient, NonNamespaceOperation nonNamespaceOperation) {
    BaseOperation baseOperation = Mockito.mock(BaseOperation.class);
    String serviceName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX + ContainerBasedGatewayConstants.CMS_SERVICE_SUFFIX;
    Mockito.when(openShiftClient.services().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
    Mockito.when(nonNamespaceOperation.withName(serviceName)).thenReturn(baseOperation);
    Mockito.when(baseOperation.get()).thenReturn(null);
    Service service = Mockito.mock(Service.class, Mockito.RETURNS_DEEP_STUBS);
    return service;
}
Also used : Service(io.fabric8.kubernetes.api.model.Service) BaseOperation(io.fabric8.kubernetes.client.dsl.base.BaseOperation)

Example 32 with Namespace

use of io.fabric8.kubernetes.api.model.Namespace in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method createIngress.

/**
 * Create Ingress resource
 *
 * @param openShiftClient       Openshift client
 * @param nonNamespaceOperation NonNamespaceOperation instance
 * @param scalableResource      ScalableResource instance
 */
private Ingress createIngress(OpenShiftClient openShiftClient, NonNamespaceOperation nonNamespaceOperation, ScalableResource scalableResource) {
    String ingressName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX + ContainerBasedGatewayConstants.CMS_INGRESS_SUFFIX;
    Mockito.when(openShiftClient.extensions().ingresses().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
    Mockito.when(nonNamespaceOperation.withName(ingressName)).thenReturn(scalableResource);
    Ingress ingress = Mockito.mock(Ingress.class, Mockito.RETURNS_DEEP_STUBS);
    return ingress;
}
Also used : Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress)

Example 33 with Namespace

use of io.fabric8.kubernetes.api.model.Namespace in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method testCreateServiceResourceForKubernetesClientException.

@Test
public void testCreateServiceResourceForKubernetesClientException() 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());
    NonNamespaceOperation nonNamespaceOperationService = Mockito.mock(NonNamespaceOperation.class);
    BaseOperation baseOperationService = Mockito.mock(BaseOperation.class);
    String serviceName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX + ContainerBasedGatewayConstants.CMS_SERVICE_SUFFIX;
    Mockito.when(openShiftClient.services().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperationService);
    Mockito.when(nonNamespaceOperationService.withName(serviceName)).thenReturn(baseOperationService);
    Mockito.when(baseOperationService.get()).thenThrow(KubernetesClientException.class);
    API api = SampleTestObjectCreator.createDefaultAPI().context("").build();
    try {
        kubernetesGateway.createContainerGateway(ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX, api);
    } catch (ContainerBasedGatewayException e) {
        Assert.assertEquals(e.getErrorHandler(), ExceptionCodes.DEDICATED_CONTAINER_GATEWAY_CREATION_FAILED);
    }
}
Also used : OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) API(org.wso2.carbon.apimgt.core.models.API) BaseOperation(io.fabric8.kubernetes.client.dsl.base.BaseOperation) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Test(org.junit.Test)

Example 34 with Namespace

use of io.fabric8.kubernetes.api.model.Namespace in project camel by apache.

the class KubernetesPodsProducer method doCreatePod.

protected void doCreatePod(Exchange exchange, String operation) throws Exception {
    Pod pod = null;
    String podName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_POD_NAME, String.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    PodSpec podSpec = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_POD_SPEC, PodSpec.class);
    if (ObjectHelper.isEmpty(podName)) {
        LOG.error("Create a specific pod require specify a pod name");
        throw new IllegalArgumentException("Create a specific pod require specify a pod name");
    }
    if (ObjectHelper.isEmpty(namespaceName)) {
        LOG.error("Create a specific pod require specify a namespace name");
        throw new IllegalArgumentException("Create a specific pod require specify a namespace name");
    }
    if (ObjectHelper.isEmpty(podSpec)) {
        LOG.error("Create a specific pod require specify a pod spec bean");
        throw new IllegalArgumentException("Create a specific pod require specify a pod spec bean");
    }
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_PODS_LABELS, Map.class);
    Pod podCreating = new PodBuilder().withNewMetadata().withName(podName).withLabels(labels).endMetadata().withSpec(podSpec).build();
    pod = getEndpoint().getKubernetesClient().pods().inNamespace(namespaceName).create(podCreating);
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(pod);
}
Also used : DoneablePod(io.fabric8.kubernetes.api.model.DoneablePod) Pod(io.fabric8.kubernetes.api.model.Pod) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder)

Example 35 with Namespace

use of io.fabric8.kubernetes.api.model.Namespace in project camel by apache.

the class KubernetesReplicationControllersProducer method doGetReplicationController.

protected void doGetReplicationController(Exchange exchange, String operation) throws Exception {
    ReplicationController rc = null;
    String rcName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_NAME, String.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    if (ObjectHelper.isEmpty(rcName)) {
        LOG.error("Get a specific replication controller require specify a replication controller name");
        throw new IllegalArgumentException("Get a specific replication controller require specify a replication controller name");
    }
    if (ObjectHelper.isEmpty(namespaceName)) {
        LOG.error("Get a specific replication controller require specify a namespace name");
        throw new IllegalArgumentException("Get a specific replication controller require specify a namespace name");
    }
    rc = getEndpoint().getKubernetesClient().replicationControllers().inNamespace(namespaceName).withName(rcName).get();
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(rc);
}
Also used : DoneableReplicationController(io.fabric8.kubernetes.api.model.DoneableReplicationController) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController)

Aggregations

Service (io.fabric8.kubernetes.api.model.Service)12 Test (org.junit.Test)11 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)10 Namespace (io.fabric8.kubernetes.api.model.Namespace)8 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)7 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)7 ContainerBasedGatewayException (org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException)6 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)6 BaseOperation (io.fabric8.kubernetes.client.dsl.base.BaseOperation)5 ArrayList (java.util.ArrayList)5 API (org.wso2.carbon.apimgt.core.models.API)5 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)4 Map (java.util.Map)4 Exchange (org.apache.camel.Exchange)4 Processor (org.apache.camel.Processor)4 DoneableNamespace (io.fabric8.kubernetes.api.model.DoneableNamespace)3 DoneableReplicationController (io.fabric8.kubernetes.api.model.DoneableReplicationController)3 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)3 Ingress (io.fabric8.kubernetes.api.model.extensions.Ingress)3 ScalableResource (io.fabric8.kubernetes.client.dsl.ScalableResource)3