Search in sources :

Example 11 with Namespace

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

the class KubernetesPodsProducer method doGetPod.

protected void doGetPod(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);
    if (ObjectHelper.isEmpty(podName)) {
        LOG.error("Get a specific pod require specify a pod name");
        throw new IllegalArgumentException("Get a specific pod require specify a pod name");
    }
    if (ObjectHelper.isEmpty(namespaceName)) {
        LOG.error("Get a specific pod require specify a namespace name");
        throw new IllegalArgumentException("Get a specific pod require specify a namespace name");
    }
    pod = getEndpoint().getKubernetesClient().pods().inNamespace(namespaceName).withName(podName).get();
    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)

Example 12 with Namespace

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

the class KubernetesReplicationControllersProducer method doScaleReplicationController.

protected void doScaleReplicationController(Exchange exchange, String operation) throws Exception {
    String rcName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_NAME, String.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    Integer replicasNumber = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_REPLICAS, Integer.class);
    if (ObjectHelper.isEmpty(rcName)) {
        LOG.error("Scale a specific replication controller require specify a replication controller name");
        throw new IllegalArgumentException("Scale a specific replication controller require specify a replication controller name");
    }
    if (ObjectHelper.isEmpty(namespaceName)) {
        LOG.error("Scale a specific replication controller require specify a namespace name");
        throw new IllegalArgumentException("Scale a specific replication controller require specify a namespace name");
    }
    if (ObjectHelper.isEmpty(replicasNumber)) {
        LOG.error("Scale a specific replication controller require specify a replicas number");
        throw new IllegalArgumentException("Scale a specific replication controller require specify a replicas number");
    }
    ReplicationController rcScaled = getEndpoint().getKubernetesClient().replicationControllers().inNamespace(namespaceName).withName(rcName).scale(replicasNumber, true);
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(rcScaled.getStatus().getReplicas());
}
Also used : DoneableReplicationController(io.fabric8.kubernetes.api.model.DoneableReplicationController) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController)

Example 13 with Namespace

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

the class KubernetesResourcesQuotaProducer method doGetResourceQuota.

protected void doGetResourceQuota(Exchange exchange, String operation) throws Exception {
    ResourceQuota rq = null;
    String rqName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_RESOURCES_QUOTA_NAME, String.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    if (ObjectHelper.isEmpty(rqName)) {
        LOG.error("Get a specific Resource Quota require specify a Resource Quota name");
        throw new IllegalArgumentException("Get a specific Resource Quota require specify a Resource Quota name");
    }
    if (ObjectHelper.isEmpty(namespaceName)) {
        LOG.error("Get a specific Resource Quota require specify a namespace name");
        throw new IllegalArgumentException("Get a specific Resource Quota require specify a namespace name");
    }
    rq = getEndpoint().getKubernetesClient().resourceQuotas().inNamespace(namespaceName).withName(rqName).get();
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(rq);
}
Also used : DoneableResourceQuota(io.fabric8.kubernetes.api.model.DoneableResourceQuota) ResourceQuota(io.fabric8.kubernetes.api.model.ResourceQuota)

Example 14 with Namespace

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

the class KubernetesSecretsProducer method doCreateSecret.

protected void doCreateSecret(Exchange exchange, String operation) throws Exception {
    Secret secret = null;
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    Secret secretToCreate = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_SECRET, Secret.class);
    if (ObjectHelper.isEmpty(namespaceName)) {
        LOG.error("Create a specific secret require specify a namespace name");
        throw new IllegalArgumentException("Create a specific secret require specify a namespace name");
    }
    if (ObjectHelper.isEmpty(secretToCreate)) {
        LOG.error("Create a specific secret require specify a secret bean");
        throw new IllegalArgumentException("Create a specific secret require specify a secret bean");
    }
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_SECRETS_LABELS, Map.class);
    secret = getEndpoint().getKubernetesClient().secrets().inNamespace(namespaceName).create(secretToCreate);
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(secret);
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) DoneableSecret(io.fabric8.kubernetes.api.model.DoneableSecret)

Example 15 with Namespace

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

the class KubernetesSecretsProducer method doGetSecret.

protected void doGetSecret(Exchange exchange, String operation) throws Exception {
    Secret secret = null;
    String secretName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_SECRET_NAME, String.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    if (ObjectHelper.isEmpty(secretName)) {
        LOG.error("Get a specific Secret require specify a Secret name");
        throw new IllegalArgumentException("Get a specific Secret require specify a Secret name");
    }
    if (ObjectHelper.isEmpty(namespaceName)) {
        LOG.error("Get a specific Secret require specify a namespace name");
        throw new IllegalArgumentException("Get a specific Secret require specify a namespace name");
    }
    secret = getEndpoint().getKubernetesClient().secrets().inNamespace(namespaceName).withName(secretName).get();
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(secret);
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) DoneableSecret(io.fabric8.kubernetes.api.model.DoneableSecret)

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