http://git-wip-us.apache.org/repos/asf/camel/blob/89eee3b9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesBuildsProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesBuildsProducer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesBuildsProducer.java deleted file mode 100644 index 5b24ecd..0000000 --- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesBuildsProducer.java +++ /dev/null @@ -1,129 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.kubernetes.producer; - -import java.util.Map; - -import io.fabric8.kubernetes.client.dsl.LogWatch; -import io.fabric8.kubernetes.client.dsl.MixedOperation; -import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation; -import io.fabric8.openshift.api.model.Build; -import io.fabric8.openshift.api.model.BuildList; -import io.fabric8.openshift.api.model.DoneableBuild; -import io.fabric8.openshift.client.OpenShiftClient; -import io.fabric8.openshift.client.dsl.BuildResource; - -import org.apache.camel.Exchange; -import org.apache.camel.component.kubernetes.KubernetesConstants; -import org.apache.camel.component.kubernetes.KubernetesEndpoint; -import org.apache.camel.impl.DefaultProducer; -import org.apache.camel.util.MessageHelper; -import org.apache.camel.util.ObjectHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class KubernetesBuildsProducer extends DefaultProducer { - - private static final Logger LOG = LoggerFactory.getLogger(KubernetesBuildsProducer.class); - - public KubernetesBuildsProducer(KubernetesEndpoint endpoint) { - super(endpoint); - } - - @Override - public KubernetesEndpoint getEndpoint() { - return (KubernetesEndpoint) super.getEndpoint(); - } - - @Override - public void process(Exchange exchange) throws Exception { - String operation; - - if (ObjectHelper.isEmpty(getEndpoint().getKubernetesConfiguration().getOperation())) { - operation = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_OPERATION, String.class); - } else { - operation = getEndpoint().getKubernetesConfiguration().getOperation(); - } - - switch (operation) { - - case KubernetesOperations.LIST_BUILD: - doList(exchange, operation); - break; - - case KubernetesOperations.LIST_BUILD_BY_LABELS_OPERATION: - doListBuildByLabels(exchange, operation); - break; - - case KubernetesOperations.GET_BUILD_OPERATION: - doGetBuild(exchange, operation); - break; - - default: - throw new IllegalArgumentException("Unsupported operation " + operation); - } - } - - protected void doList(Exchange exchange, String operation) throws Exception { - BuildList buildList = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).builds().list(); - exchange.getOut().setBody(buildList.getItems()); - } - - protected void doListBuildByLabels(Exchange exchange, String operation) throws Exception { - BuildList buildList = null; - Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_BUILDS_LABELS, - Map.class); - String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - if (!ObjectHelper.isEmpty(namespaceName)) { - NonNamespaceOperation<Build, BuildList, DoneableBuild, BuildResource<Build, DoneableBuild, String, LogWatch>> builds = getEndpoint().getKubernetesClient(). - adapt(OpenShiftClient.class).builds() - .inNamespace(namespaceName); - for (Map.Entry<String, String> entry : labels.entrySet()) { - builds.withLabel(entry.getKey(), entry.getValue()); - } - buildList = builds.list(); - } else { - MixedOperation<Build, BuildList, DoneableBuild, BuildResource<Build, DoneableBuild, String, LogWatch>> builds = getEndpoint().getKubernetesClient(). - adapt(OpenShiftClient.class).builds(); - for (Map.Entry<String, String> entry : labels.entrySet()) { - builds.withLabel(entry.getKey(), entry.getValue()); - } - buildList = builds.list(); - } - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(buildList.getItems()); - } - - protected void doGetBuild(Exchange exchange, String operation) throws Exception { - Build build = null; - String buildName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_BUILD_NAME, String.class); - String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - if (ObjectHelper.isEmpty(buildName)) { - LOG.error("Get a specific Build require specify a Build name"); - throw new IllegalArgumentException("Get a specific Build require specify a Build name"); - } - if (ObjectHelper.isEmpty(namespaceName)) { - LOG.error("Get a specific Build require specify a namespace name"); - throw new IllegalArgumentException("Get a specific Build require specify a namespace name"); - } - build = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).builds().inNamespace(namespaceName) - .withName(buildName).get(); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(build); - } -}
http://git-wip-us.apache.org/repos/asf/camel/blob/89eee3b9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesConfigMapsProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesConfigMapsProducer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesConfigMapsProducer.java deleted file mode 100644 index ff93b87..0000000 --- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesConfigMapsProducer.java +++ /dev/null @@ -1,174 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.kubernetes.producer; - -import java.util.HashMap; -import java.util.Map; - -import io.fabric8.kubernetes.api.model.ConfigMap; -import io.fabric8.kubernetes.api.model.ConfigMapBuilder; -import io.fabric8.kubernetes.api.model.ConfigMapList; -import io.fabric8.kubernetes.api.model.DoneableConfigMap; -import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation; -import io.fabric8.kubernetes.client.dsl.Resource; - -import org.apache.camel.Exchange; -import org.apache.camel.component.kubernetes.KubernetesConstants; -import org.apache.camel.component.kubernetes.KubernetesEndpoint; -import org.apache.camel.impl.DefaultProducer; -import org.apache.camel.util.MessageHelper; -import org.apache.camel.util.ObjectHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class KubernetesConfigMapsProducer extends DefaultProducer { - - private static final Logger LOG = LoggerFactory.getLogger(KubernetesConfigMapsProducer.class); - - public KubernetesConfigMapsProducer(KubernetesEndpoint endpoint) { - super(endpoint); - } - - @Override - public KubernetesEndpoint getEndpoint() { - return (KubernetesEndpoint) super.getEndpoint(); - } - - @Override - public void process(Exchange exchange) throws Exception { - String operation; - - if (ObjectHelper.isEmpty(getEndpoint().getKubernetesConfiguration().getOperation())) { - operation = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_OPERATION, String.class); - } else { - operation = getEndpoint().getKubernetesConfiguration().getOperation(); - } - - switch (operation) { - - case KubernetesOperations.LIST_CONFIGMAPS: - doList(exchange, operation); - break; - - case KubernetesOperations.LIST_CONFIGMAPS_BY_LABELS_OPERATION: - doListConfigMapsByLabels(exchange, operation); - break; - - case KubernetesOperations.GET_CONFIGMAP_OPERATION: - doGetConfigMap(exchange, operation); - break; - - case KubernetesOperations.CREATE_CONFIGMAP_OPERATION: - doCreateConfigMap(exchange, operation); - break; - - case KubernetesOperations.DELETE_CONFIGMAP_OPERATION: - doDeleteConfigMap(exchange, operation); - break; - - default: - throw new IllegalArgumentException("Unsupported operation " + operation); - } - } - - protected void doList(Exchange exchange, String operation) throws Exception { - ConfigMapList configMapsList = getEndpoint().getKubernetesClient().configMaps().list(); - exchange.getOut().setBody(configMapsList.getItems()); - } - - protected void doListConfigMapsByLabels(Exchange exchange, String operation) throws Exception { - ConfigMapList configMapsList = null; - Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_CONFIGMAPS_LABELS, Map.class); - NonNamespaceOperation<ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> configMaps = getEndpoint().getKubernetesClient().configMaps(); - for (Map.Entry<String, String> entry : labels.entrySet()) { - configMaps.withLabel(entry.getKey(), entry.getValue()); - } - configMapsList = configMaps.list(); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(configMapsList.getItems()); - } - - protected void doGetConfigMap(Exchange exchange, String operation) throws Exception { - ConfigMap configMap = null; - String cfMapName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_CONFIGMAP_NAME, String.class); - if (ObjectHelper.isEmpty(cfMapName)) { - LOG.error("Get a specific ConfigMap require specify a ConfigMap name"); - throw new IllegalArgumentException("Get a specific ConfigMap require specify a ConfigMap name"); - } - configMap = getEndpoint().getKubernetesClient().configMaps().withName(cfMapName).get(); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(configMap); - } - - protected void doCreateConfigMap(Exchange exchange, String operation) throws Exception { - ConfigMap configMap = null; - String cfMapName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_CONFIGMAP_NAME, String.class); - String namespaceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - HashMap<String, String> configMapData = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_CONFIGMAP_DATA, HashMap.class); - if (ObjectHelper.isEmpty(cfMapName)) { - LOG.error("Create a specific configMap require specify a configMap name"); - throw new IllegalArgumentException( - "Create a specific configMap require specify a configMap name"); - } - if (ObjectHelper.isEmpty(namespaceName)) { - LOG.error("Create a specific configMap require specify a namespace name"); - throw new IllegalArgumentException( - "Create a specific configMap require specify a namespace name"); - } - if (ObjectHelper.isEmpty(configMapData)) { - LOG.error("Create a specific configMap require specify a data map"); - throw new IllegalArgumentException( - "Create a specific configMap require specify a data map"); - } - Map<String, String> labels = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_CONFIGMAPS_LABELS, Map.class); - ConfigMap cfMapCreating = new ConfigMapBuilder().withNewMetadata().withName(cfMapName) - .withLabels(labels).endMetadata().withData(configMapData).build(); - configMap = getEndpoint().getKubernetesClient().configMaps() - .inNamespace(namespaceName).create(cfMapCreating); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(configMap); - } - - protected void doDeleteConfigMap(Exchange exchange, String operation) throws Exception { - String configMapName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_CONFIGMAP_NAME, String.class); - String namespaceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - if (ObjectHelper.isEmpty(configMapName)) { - LOG.error("Delete a specific config map require specify a config map name"); - throw new IllegalArgumentException( - "Delete a specific config map require specify a config map name"); - } - if (ObjectHelper.isEmpty(namespaceName)) { - LOG.error("Delete a specific config map require specify a namespace name"); - throw new IllegalArgumentException( - "Delete a specific config map require specify a namespace name"); - } - boolean cfMapDeleted = getEndpoint().getKubernetesClient().configMaps() - .inNamespace(namespaceName).withName(configMapName).delete(); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(cfMapDeleted); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/89eee3b9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesNamespacesProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesNamespacesProducer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesNamespacesProducer.java deleted file mode 100644 index 74842ab..0000000 --- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesNamespacesProducer.java +++ /dev/null @@ -1,165 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.kubernetes.producer; - -import java.util.Map; - -import io.fabric8.kubernetes.api.model.DoneableNamespace; -import io.fabric8.kubernetes.api.model.Namespace; -import io.fabric8.kubernetes.api.model.NamespaceBuilder; -import io.fabric8.kubernetes.api.model.NamespaceList; -import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation; -import io.fabric8.kubernetes.client.dsl.Resource; - -import org.apache.camel.Exchange; -import org.apache.camel.component.kubernetes.KubernetesConstants; -import org.apache.camel.component.kubernetes.KubernetesEndpoint; -import org.apache.camel.impl.DefaultProducer; -import org.apache.camel.util.MessageHelper; -import org.apache.camel.util.ObjectHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class KubernetesNamespacesProducer extends DefaultProducer { - - private static final Logger LOG = LoggerFactory - .getLogger(KubernetesNamespacesProducer.class); - - public KubernetesNamespacesProducer(KubernetesEndpoint endpoint) { - super(endpoint); - } - - @Override - public KubernetesEndpoint getEndpoint() { - return (KubernetesEndpoint) super.getEndpoint(); - } - - @Override - public void process(Exchange exchange) throws Exception { - String operation; - - if (ObjectHelper.isEmpty(getEndpoint().getKubernetesConfiguration() - .getOperation())) { - operation = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_OPERATION, String.class); - } else { - operation = getEndpoint().getKubernetesConfiguration() - .getOperation(); - } - - switch (operation) { - - case KubernetesOperations.LIST_NAMESPACE_OPERATION: - doList(exchange, operation); - break; - - case KubernetesOperations.LIST_NAMESPACE_BY_LABELS_OPERATION: - doListNamespaceByLabel(exchange, operation); - break; - - case KubernetesOperations.GET_NAMESPACE_OPERATION: - doGetNamespace(exchange, operation); - break; - - case KubernetesOperations.CREATE_NAMESPACE_OPERATION: - doCreateNamespace(exchange, operation); - break; - - case KubernetesOperations.DELETE_NAMESPACE_OPERATION: - doDeleteNamespace(exchange, operation); - break; - - default: - throw new IllegalArgumentException("Unsupported operation " - + operation); - } - } - - protected void doList(Exchange exchange, String operation) throws Exception { - NamespaceList namespacesList = getEndpoint().getKubernetesClient() - .namespaces().list(); - exchange.getOut().setBody(namespacesList.getItems()); - } - - protected void doListNamespaceByLabel(Exchange exchange, String operation) { - Map<String, String> labels = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_LABELS, Map.class); - if (ObjectHelper.isEmpty(labels)) { - LOG.error("Get a specific namespace by labels require specify a labels set"); - throw new IllegalArgumentException( - "Get a specific namespace by labels require specify a labels set"); - } - NonNamespaceOperation<Namespace, NamespaceList, DoneableNamespace, Resource<Namespace, DoneableNamespace>> namespaces = getEndpoint().getKubernetesClient().namespaces(); - for (Map.Entry<String, String> entry : labels.entrySet()) { - namespaces.withLabel(entry.getKey(), entry.getValue()); - } - NamespaceList namespace = namespaces.list(); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(namespace.getItems()); - } - - protected void doGetNamespace(Exchange exchange, String operation) { - String namespaceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - if (ObjectHelper.isEmpty(namespaceName)) { - LOG.error("Get a specific namespace require specify a namespace name"); - throw new IllegalArgumentException( - "Get a specific namespace require specify a namespace name"); - } - Namespace namespace = getEndpoint().getKubernetesClient().namespaces() - .withName(namespaceName).get(); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(namespace); - } - - protected void doCreateNamespace(Exchange exchange, String operation) { - String namespaceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - if (ObjectHelper.isEmpty(namespaceName)) { - LOG.error("Create a specific namespace require specify a namespace name"); - throw new IllegalArgumentException( - "Create a specific namespace require specify a namespace name"); - } - Map<String, String> labels = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_LABELS, Map.class); - Namespace ns = new NamespaceBuilder().withNewMetadata() - .withName(namespaceName).withLabels(labels).endMetadata() - .build(); - Namespace namespace = getEndpoint().getKubernetesClient().namespaces() - .create(ns); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(namespace); - } - - protected void doDeleteNamespace(Exchange exchange, String operation) { - String namespaceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - if (ObjectHelper.isEmpty(namespaceName)) { - LOG.error("Delete a specific namespace require specify a namespace name"); - throw new IllegalArgumentException( - "Delete a specific namespace require specify a namespace name"); - } - Boolean namespace = getEndpoint().getKubernetesClient().namespaces() - .withName(namespaceName).delete(); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(namespace); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/89eee3b9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesNodesProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesNodesProducer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesNodesProducer.java deleted file mode 100644 index 720aef2..0000000 --- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesNodesProducer.java +++ /dev/null @@ -1,110 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.kubernetes.producer; - -import java.util.Map; - -import io.fabric8.kubernetes.api.model.DoneableNode; -import io.fabric8.kubernetes.api.model.Node; -import io.fabric8.kubernetes.api.model.NodeList; -import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation; -import io.fabric8.kubernetes.client.dsl.Resource; - -import org.apache.camel.Exchange; -import org.apache.camel.component.kubernetes.KubernetesConstants; -import org.apache.camel.component.kubernetes.KubernetesEndpoint; -import org.apache.camel.impl.DefaultProducer; -import org.apache.camel.util.MessageHelper; -import org.apache.camel.util.ObjectHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class KubernetesNodesProducer extends DefaultProducer { - - private static final Logger LOG = LoggerFactory.getLogger(KubernetesNodesProducer.class); - - public KubernetesNodesProducer(KubernetesEndpoint endpoint) { - super(endpoint); - } - - @Override - public KubernetesEndpoint getEndpoint() { - return (KubernetesEndpoint) super.getEndpoint(); - } - - @Override - public void process(Exchange exchange) throws Exception { - String operation; - - if (ObjectHelper.isEmpty(getEndpoint().getKubernetesConfiguration().getOperation())) { - operation = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_OPERATION, String.class); - } else { - operation = getEndpoint().getKubernetesConfiguration().getOperation(); - } - - switch (operation) { - - case KubernetesOperations.LIST_NODES: - doList(exchange, operation); - break; - - case KubernetesOperations.LIST_NODES_BY_LABELS_OPERATION: - doListNodesByLabels(exchange, operation); - break; - - case KubernetesOperations.GET_NODE_OPERATION: - doGetNode(exchange, operation); - break; - - default: - throw new IllegalArgumentException("Unsupported operation " + operation); - } - } - - protected void doList(Exchange exchange, String operation) throws Exception { - NodeList nodeList = getEndpoint().getKubernetesClient().nodes().list(); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(nodeList.getItems()); - } - - protected void doListNodesByLabels(Exchange exchange, String operation) throws Exception { - NodeList nodeList = null; - Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NODES_LABELS, Map.class); - NonNamespaceOperation<Node, NodeList, DoneableNode, Resource<Node, DoneableNode>> nodes = getEndpoint().getKubernetesClient().nodes(); - for (Map.Entry<String, String> entry : labels.entrySet()) { - nodes.withLabel(entry.getKey(), entry.getValue()); - } - nodeList = nodes.list(); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(nodeList.getItems()); - } - - protected void doGetNode(Exchange exchange, String operation) throws Exception { - Node node = null; - String pvName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NODE_NAME, String.class); - if (ObjectHelper.isEmpty(pvName)) { - LOG.error("Get a specific Node require specify a Node name"); - throw new IllegalArgumentException("Get a specific Node require specify a Node name"); - } - node = getEndpoint().getKubernetesClient().nodes().withName(pvName).get(); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(node); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/89eee3b9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesOperations.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesOperations.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesOperations.java deleted file mode 100644 index f9437b7..0000000 --- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesOperations.java +++ /dev/null @@ -1,104 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.kubernetes.producer; - -public interface KubernetesOperations { - - // Namespaces - String LIST_NAMESPACE_OPERATION = "listNamespaces"; - String LIST_NAMESPACE_BY_LABELS_OPERATION = "listNamespacesByLabels"; - String GET_NAMESPACE_OPERATION = "getNamespace"; - String CREATE_NAMESPACE_OPERATION = "createNamespace"; - String DELETE_NAMESPACE_OPERATION = "deleteNamespace"; - - // Services - String LIST_SERVICES_OPERATION = "listServices"; - String LIST_SERVICES_BY_LABELS_OPERATION = "listServicesByLabels"; - String GET_SERVICE_OPERATION = "getService"; - String CREATE_SERVICE_OPERATION = "createService"; - String DELETE_SERVICE_OPERATION = "deleteService"; - - // Replication Controllers - String LIST_REPLICATION_CONTROLLERS_OPERATION = "listReplicationControllers"; - String LIST_REPLICATION_CONTROLLERS_BY_LABELS_OPERATION = "listReplicationControllersByLabels"; - String GET_REPLICATION_CONTROLLER_OPERATION = "getReplicationController"; - String CREATE_REPLICATION_CONTROLLER_OPERATION = "createReplicationController"; - String DELETE_REPLICATION_CONTROLLER_OPERATION = "deleteReplicationController"; - String SCALE_REPLICATION_CONTROLLER_OPERATION = "scaleReplicationController"; - - // Pods - String LIST_PODS_OPERATION = "listPods"; - String LIST_PODS_BY_LABELS_OPERATION = "listPodsByLabels"; - String GET_POD_OPERATION = "getPod"; - String CREATE_POD_OPERATION = "createPod"; - String DELETE_POD_OPERATION = "deletePod"; - - // Persistent Volumes - String LIST_PERSISTENT_VOLUMES = "listPersistentVolumes"; - String LIST_PERSISTENT_VOLUMES_BY_LABELS_OPERATION = "listPersistentVolumesByLabels"; - String GET_PERSISTENT_VOLUME_OPERATION = "getPersistentVolume"; - - // Persistent Volumes Claims - String LIST_PERSISTENT_VOLUMES_CLAIMS = "listPersistentVolumesClaims"; - String LIST_PERSISTENT_VOLUMES_CLAIMS_BY_LABELS_OPERATION = "listPersistentVolumesClaimsByLabels"; - String GET_PERSISTENT_VOLUME_CLAIM_OPERATION = "getPersistentVolumeClaim"; - String CREATE_PERSISTENT_VOLUME_CLAIM_OPERATION = "createPersistentVolumeClaim"; - String DELETE_PERSISTENT_VOLUME_CLAIM_OPERATION = "deletePersistentVolumeClaim"; - - // Secrets - String LIST_SECRETS = "listSecrets"; - String LIST_SECRETS_BY_LABELS_OPERATION = "listSecretsByLabels"; - String GET_SECRET_OPERATION = "getSecret"; - String CREATE_SECRET_OPERATION = "createSecret"; - String DELETE_SECRET_OPERATION = "deleteSecret"; - - // Resources quota - String LIST_RESOURCES_QUOTA = "listResourcesQuota"; - String LIST_RESOURCES_QUOTA_BY_LABELS_OPERATION = "listResourcesQuotaByLabels"; - String GET_RESOURCE_QUOTA_OPERATION = "getResourceQuota"; - String CREATE_RESOURCE_QUOTA_OPERATION = "createResourceQuota"; - String DELETE_RESOURCE_QUOTA_OPERATION = "deleteResourceQuota"; - - // Service Accounts - String LIST_SERVICE_ACCOUNTS = "listServiceAccounts"; - String LIST_SERVICE_ACCOUNTS_BY_LABELS_OPERATION = "listServiceAccountsByLabels"; - String GET_SERVICE_ACCOUNT_OPERATION = "getServiceAccount"; - String CREATE_SERVICE_ACCOUNT_OPERATION = "createServiceAccount"; - String DELETE_SERVICE_ACCOUNT_OPERATION = "deleteServiceAccount"; - - // Nodes - String LIST_NODES = "listNodes"; - String LIST_NODES_BY_LABELS_OPERATION = "listNodesByLabels"; - String GET_NODE_OPERATION = "getNode"; - - // Config Maps - String LIST_CONFIGMAPS = "listConfigMaps"; - String LIST_CONFIGMAPS_BY_LABELS_OPERATION = "listConfigMapsByLabels"; - String GET_CONFIGMAP_OPERATION = "getConfigMap"; - String CREATE_CONFIGMAP_OPERATION = "createConfigMap"; - String DELETE_CONFIGMAP_OPERATION = "deleteConfigMap"; - - // Builds - String LIST_BUILD = "listBuilds"; - String LIST_BUILD_BY_LABELS_OPERATION = "listBuildsByLabels"; - String GET_BUILD_OPERATION = "getBuild"; - - // Build Configs - String LIST_BUILD_CONFIGS = "listBuildConfigs"; - String LIST_BUILD_CONFIGS_BY_LABELS_OPERATION = "listBuildConfigsByLabels"; - String GET_BUILD_CONFIG_OPERATION = "getBuildConfig"; -} http://git-wip-us.apache.org/repos/asf/camel/blob/89eee3b9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesPersistentVolumesClaimsProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesPersistentVolumesClaimsProducer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesPersistentVolumesClaimsProducer.java deleted file mode 100644 index 650f145..0000000 --- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesPersistentVolumesClaimsProducer.java +++ /dev/null @@ -1,221 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.kubernetes.producer; - -import java.util.Map; - -import io.fabric8.kubernetes.api.model.DoneablePersistentVolumeClaim; -import io.fabric8.kubernetes.api.model.PersistentVolumeClaim; -import io.fabric8.kubernetes.api.model.PersistentVolumeClaimBuilder; -import io.fabric8.kubernetes.api.model.PersistentVolumeClaimList; -import io.fabric8.kubernetes.api.model.PersistentVolumeClaimSpec; -import io.fabric8.kubernetes.client.dsl.MixedOperation; -import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation; -import io.fabric8.kubernetes.client.dsl.Resource; - -import org.apache.camel.Exchange; -import org.apache.camel.component.kubernetes.KubernetesConstants; -import org.apache.camel.component.kubernetes.KubernetesEndpoint; -import org.apache.camel.impl.DefaultProducer; -import org.apache.camel.util.MessageHelper; -import org.apache.camel.util.ObjectHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class KubernetesPersistentVolumesClaimsProducer extends DefaultProducer { - - private static final Logger LOG = LoggerFactory - .getLogger(KubernetesPersistentVolumesClaimsProducer.class); - - public KubernetesPersistentVolumesClaimsProducer(KubernetesEndpoint endpoint) { - super(endpoint); - } - - @Override - public KubernetesEndpoint getEndpoint() { - return (KubernetesEndpoint) super.getEndpoint(); - } - - @Override - public void process(Exchange exchange) throws Exception { - String operation; - - if (ObjectHelper.isEmpty(getEndpoint().getKubernetesConfiguration() - .getOperation())) { - operation = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_OPERATION, String.class); - } else { - operation = getEndpoint().getKubernetesConfiguration() - .getOperation(); - } - - switch (operation) { - - case KubernetesOperations.LIST_PERSISTENT_VOLUMES_CLAIMS: - doList(exchange, operation); - break; - - case KubernetesOperations.LIST_PERSISTENT_VOLUMES_CLAIMS_BY_LABELS_OPERATION: - doListPersistentVolumesClaimsByLabels(exchange, operation); - break; - - case KubernetesOperations.GET_PERSISTENT_VOLUME_CLAIM_OPERATION: - doGetPersistentVolumeClaim(exchange, operation); - break; - - case KubernetesOperations.CREATE_PERSISTENT_VOLUME_CLAIM_OPERATION: - doCreatePersistentVolumeClaim(exchange, operation); - break; - - case KubernetesOperations.DELETE_PERSISTENT_VOLUME_CLAIM_OPERATION: - doDeletePersistentVolumeClaim(exchange, operation); - break; - - default: - throw new IllegalArgumentException("Unsupported operation " - + operation); - } - } - - protected void doList(Exchange exchange, String operation) throws Exception { - PersistentVolumeClaimList persistentVolumeClaimList = getEndpoint() - .getKubernetesClient().persistentVolumeClaims().list(); - exchange.getOut().setBody(persistentVolumeClaimList.getItems()); - } - - protected void doListPersistentVolumesClaimsByLabels(Exchange exchange, - String operation) throws Exception { - PersistentVolumeClaimList pvcList = null; - Map<String, String> labels = exchange - .getIn() - .getHeader( - KubernetesConstants.KUBERNETES_PERSISTENT_VOLUMES_CLAIMS_LABELS, - Map.class); - String namespaceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - if (!ObjectHelper.isEmpty(namespaceName)) { - NonNamespaceOperation<PersistentVolumeClaim, PersistentVolumeClaimList, DoneablePersistentVolumeClaim, - Resource<PersistentVolumeClaim, DoneablePersistentVolumeClaim>> pvcs = getEndpoint().getKubernetesClient().persistentVolumeClaims() - .inNamespace(namespaceName); - for (Map.Entry<String, String> entry : labels.entrySet()) { - pvcs.withLabel(entry.getKey(), entry.getValue()); - } - pvcList = pvcs.list(); - } else { - MixedOperation<PersistentVolumeClaim, PersistentVolumeClaimList, DoneablePersistentVolumeClaim, - Resource<PersistentVolumeClaim, DoneablePersistentVolumeClaim>> pvcs = getEndpoint().getKubernetesClient().persistentVolumeClaims(); - for (Map.Entry<String, String> entry : labels.entrySet()) { - pvcs.withLabel(entry.getKey(), entry.getValue()); - } - pvcList = pvcs.list(); - } - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(pvcList.getItems()); - } - - protected void doGetPersistentVolumeClaim(Exchange exchange, - String operation) throws Exception { - PersistentVolumeClaim pvc = null; - String pvcName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_PERSISTENT_VOLUME_CLAIM_NAME, - String.class); - String namespaceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - if (ObjectHelper.isEmpty(pvcName)) { - LOG.error("Get a specific Persistent Volume Claim require specify a Persistent Volume Claim name"); - throw new IllegalArgumentException( - "Get a specific Persistent Volume Claim require specify a Persistent Volume Claim name"); - } - if (ObjectHelper.isEmpty(namespaceName)) { - LOG.error("Get a specific Persistent Volume Claim require specify a namespace name"); - throw new IllegalArgumentException( - "Get a specific Persistent Volume Claim require specify a namespace name"); - } - pvc = getEndpoint().getKubernetesClient().persistentVolumeClaims() - .inNamespace(namespaceName).withName(pvcName).get(); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(pvc); - } - - protected void doCreatePersistentVolumeClaim(Exchange exchange, - String operation) throws Exception { - PersistentVolumeClaim pvc = null; - String pvcName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_PERSISTENT_VOLUME_CLAIM_NAME, - String.class); - String namespaceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - PersistentVolumeClaimSpec pvcSpec = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_PERSISTENT_VOLUME_CLAIM_SPEC, - PersistentVolumeClaimSpec.class); - if (ObjectHelper.isEmpty(pvcName)) { - LOG.error("Create a specific Persistent Volume Claim require specify a Persistent Volume Claim name"); - throw new IllegalArgumentException( - "Create a specific Persistent Volume Claim require specify a Persistent Volume Claim name"); - } - if (ObjectHelper.isEmpty(namespaceName)) { - LOG.error("Create a specific Persistent Volume Claim require specify a namespace name"); - throw new IllegalArgumentException( - "Create a specific Persistent Volume Claim require specify a namespace name"); - } - if (ObjectHelper.isEmpty(pvcSpec)) { - LOG.error("Create a specific Persistent Volume Claim require specify a Persistent Volume Claim spec bean"); - throw new IllegalArgumentException( - "Create a specific Persistent Volume Claim require specify a Persistent Volume Claim spec bean"); - } - Map<String, String> labels = exchange - .getIn() - .getHeader( - KubernetesConstants.KUBERNETES_PERSISTENT_VOLUMES_CLAIMS_LABELS, - Map.class); - PersistentVolumeClaim pvcCreating = new PersistentVolumeClaimBuilder() - .withNewMetadata().withName(pvcName).withLabels(labels) - .endMetadata().withSpec(pvcSpec).build(); - pvc = getEndpoint().getKubernetesClient().persistentVolumeClaims() - .inNamespace(namespaceName).create(pvcCreating); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(pvc); - } - - protected void doDeletePersistentVolumeClaim(Exchange exchange, - String operation) throws Exception { - String pvcName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_PERSISTENT_VOLUME_CLAIM_NAME, - String.class); - String namespaceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - if (ObjectHelper.isEmpty(pvcName)) { - LOG.error("Delete a specific Persistent Volume Claim require specify a Persistent Volume Claim name"); - throw new IllegalArgumentException( - "Delete a specific Persistent Volume Claim require specify a Persistent Volume Claim name"); - } - if (ObjectHelper.isEmpty(namespaceName)) { - LOG.error("Delete a specific Persistent Volume Claim require specify a namespace name"); - throw new IllegalArgumentException( - "Delete a specific Persistent Volume Claim require specify a namespace name"); - } - boolean pvcDeleted = getEndpoint().getKubernetesClient() - .persistentVolumeClaims().inNamespace(namespaceName) - .withName(pvcName).delete(); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(pvcDeleted); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/89eee3b9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesPersistentVolumesProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesPersistentVolumesProducer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesPersistentVolumesProducer.java deleted file mode 100644 index f23fdac..0000000 --- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesPersistentVolumesProducer.java +++ /dev/null @@ -1,124 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.kubernetes.producer; - -import java.util.Map; - -import io.fabric8.kubernetes.api.model.DoneablePersistentVolume; -import io.fabric8.kubernetes.api.model.PersistentVolume; -import io.fabric8.kubernetes.api.model.PersistentVolumeList; -import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation; -import io.fabric8.kubernetes.client.dsl.Resource; - -import org.apache.camel.Exchange; -import org.apache.camel.component.kubernetes.KubernetesConstants; -import org.apache.camel.component.kubernetes.KubernetesEndpoint; -import org.apache.camel.impl.DefaultProducer; -import org.apache.camel.util.MessageHelper; -import org.apache.camel.util.ObjectHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class KubernetesPersistentVolumesProducer extends DefaultProducer { - - private static final Logger LOG = LoggerFactory - .getLogger(KubernetesPersistentVolumesProducer.class); - - public KubernetesPersistentVolumesProducer(KubernetesEndpoint endpoint) { - super(endpoint); - } - - @Override - public KubernetesEndpoint getEndpoint() { - return (KubernetesEndpoint) super.getEndpoint(); - } - - @Override - public void process(Exchange exchange) throws Exception { - String operation; - - if (ObjectHelper.isEmpty(getEndpoint().getKubernetesConfiguration() - .getOperation())) { - operation = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_OPERATION, String.class); - } else { - operation = getEndpoint().getKubernetesConfiguration() - .getOperation(); - } - - switch (operation) { - - case KubernetesOperations.LIST_PERSISTENT_VOLUMES: - doList(exchange, operation); - break; - - case KubernetesOperations.LIST_PERSISTENT_VOLUMES_BY_LABELS_OPERATION: - doListPersistentVolumesByLabels(exchange, operation); - break; - - case KubernetesOperations.GET_PERSISTENT_VOLUME_OPERATION: - doGetPersistentVolume(exchange, operation); - break; - - default: - throw new IllegalArgumentException("Unsupported operation " - + operation); - } - } - - protected void doList(Exchange exchange, String operation) throws Exception { - PersistentVolumeList persistentVolumeList = getEndpoint() - .getKubernetesClient().persistentVolumes().list(); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(persistentVolumeList.getItems()); - } - - protected void doListPersistentVolumesByLabels(Exchange exchange, - String operation) throws Exception { - PersistentVolumeList pvList = null; - Map<String, String> labels = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_PERSISTENT_VOLUMES_LABELS, - Map.class); - NonNamespaceOperation<PersistentVolume, PersistentVolumeList, DoneablePersistentVolume, Resource<PersistentVolume, DoneablePersistentVolume>> pvs; - pvs = getEndpoint().getKubernetesClient().persistentVolumes(); - for (Map.Entry<String, String> entry : labels.entrySet()) { - pvs.withLabel(entry.getKey(), entry.getValue()); - } - pvList = pvs.list(); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(pvList.getItems()); - } - - protected void doGetPersistentVolume(Exchange exchange, String operation) - throws Exception { - PersistentVolume pv = null; - String pvName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_PERSISTENT_VOLUME_NAME, - String.class); - if (ObjectHelper.isEmpty(pvName)) { - LOG.error("Get a specific Persistent Volume require specify a Persistent Volume name"); - throw new IllegalArgumentException( - "Get a specific Persistent Volume require specify a Persistent Volume name"); - } - pv = getEndpoint().getKubernetesClient().persistentVolumes().withName(pvName).get(); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(pv); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/89eee3b9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesPodsProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesPodsProducer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesPodsProducer.java deleted file mode 100644 index 0457887..0000000 --- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesPodsProducer.java +++ /dev/null @@ -1,201 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.kubernetes.producer; - -import java.util.Map; - -import io.fabric8.kubernetes.api.model.DoneablePod; -import io.fabric8.kubernetes.api.model.Pod; -import io.fabric8.kubernetes.api.model.PodBuilder; -import io.fabric8.kubernetes.api.model.PodList; -import io.fabric8.kubernetes.api.model.PodSpec; -import io.fabric8.kubernetes.client.dsl.MixedOperation; -import io.fabric8.kubernetes.client.dsl.PodResource; - -import org.apache.camel.Exchange; -import org.apache.camel.component.kubernetes.KubernetesConstants; -import org.apache.camel.component.kubernetes.KubernetesEndpoint; -import org.apache.camel.impl.DefaultProducer; -import org.apache.camel.util.MessageHelper; -import org.apache.camel.util.ObjectHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class KubernetesPodsProducer extends DefaultProducer { - - private static final Logger LOG = LoggerFactory - .getLogger(KubernetesPodsProducer.class); - - public KubernetesPodsProducer(KubernetesEndpoint endpoint) { - super(endpoint); - } - - @Override - public KubernetesEndpoint getEndpoint() { - return (KubernetesEndpoint) super.getEndpoint(); - } - - @Override - public void process(Exchange exchange) throws Exception { - String operation; - - if (ObjectHelper.isEmpty(getEndpoint().getKubernetesConfiguration() - .getOperation())) { - operation = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_OPERATION, String.class); - } else { - operation = getEndpoint().getKubernetesConfiguration() - .getOperation(); - } - - switch (operation) { - - case KubernetesOperations.LIST_PODS_OPERATION: - doList(exchange, operation); - break; - - case KubernetesOperations.LIST_PODS_BY_LABELS_OPERATION: - doListPodsByLabel(exchange, operation); - break; - - case KubernetesOperations.GET_POD_OPERATION: - doGetPod(exchange, operation); - break; - - case KubernetesOperations.CREATE_POD_OPERATION: - doCreatePod(exchange, operation); - break; - - case KubernetesOperations.DELETE_POD_OPERATION: - doDeletePod(exchange, operation); - break; - - default: - throw new IllegalArgumentException("Unsupported operation " - + operation); - } - } - - protected void doList(Exchange exchange, String operation) throws Exception { - PodList podList = getEndpoint().getKubernetesClient().pods().list(); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(podList.getItems()); - } - - protected void doListPodsByLabel(Exchange exchange, String operation) { - Map<String, String> labels = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_PODS_LABELS, Map.class); - if (ObjectHelper.isEmpty(labels)) { - LOG.error("Get pods by labels require specify a labels set"); - throw new IllegalArgumentException( - "Get pods by labels require specify a labels set"); - } - - MixedOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> pods = getEndpoint().getKubernetesClient().pods(); - for (Map.Entry<String, String> entry : labels.entrySet()) { - pods.withLabel(entry.getKey(), entry.getValue()); - } - PodList podList = pods.list(); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(podList.getItems()); - } - - 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); - } - - 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); - } - - protected void doDeletePod(Exchange exchange, String operation) - throws Exception { - 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("Delete a specific pod require specify a pod name"); - throw new IllegalArgumentException( - "Delete a specific pod require specify a pod name"); - } - if (ObjectHelper.isEmpty(namespaceName)) { - LOG.error("Delete a specific pod require specify a namespace name"); - throw new IllegalArgumentException( - "Delete a specific pod require specify a namespace name"); - } - boolean podDeleted = getEndpoint().getKubernetesClient().pods() - .inNamespace(namespaceName).withName(podName).delete(); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(podDeleted); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/89eee3b9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesReplicationControllersProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesReplicationControllersProducer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesReplicationControllersProducer.java deleted file mode 100644 index 8275d9c..0000000 --- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesReplicationControllersProducer.java +++ /dev/null @@ -1,268 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.kubernetes.producer; - -import java.util.Map; - -import io.fabric8.kubernetes.api.model.DoneableReplicationController; -import io.fabric8.kubernetes.api.model.ReplicationController; -import io.fabric8.kubernetes.api.model.ReplicationControllerBuilder; -import io.fabric8.kubernetes.api.model.ReplicationControllerList; -import io.fabric8.kubernetes.api.model.ReplicationControllerSpec; -import io.fabric8.kubernetes.client.dsl.MixedOperation; -import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation; -import io.fabric8.kubernetes.client.dsl.RollableScalableResource; - -import org.apache.camel.Exchange; -import org.apache.camel.component.kubernetes.KubernetesConstants; -import org.apache.camel.component.kubernetes.KubernetesEndpoint; -import org.apache.camel.impl.DefaultProducer; -import org.apache.camel.util.MessageHelper; -import org.apache.camel.util.ObjectHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class KubernetesReplicationControllersProducer extends DefaultProducer { - - private static final Logger LOG = LoggerFactory - .getLogger(KubernetesReplicationControllersProducer.class); - - public KubernetesReplicationControllersProducer(KubernetesEndpoint endpoint) { - super(endpoint); - } - - @Override - public KubernetesEndpoint getEndpoint() { - return (KubernetesEndpoint) super.getEndpoint(); - } - - @Override - public void process(Exchange exchange) throws Exception { - String operation; - - if (ObjectHelper.isEmpty(getEndpoint().getKubernetesConfiguration() - .getOperation())) { - operation = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_OPERATION, String.class); - } else { - operation = getEndpoint().getKubernetesConfiguration() - .getOperation(); - } - - switch (operation) { - - case KubernetesOperations.LIST_REPLICATION_CONTROLLERS_OPERATION: - doList(exchange, operation); - break; - - case KubernetesOperations.LIST_REPLICATION_CONTROLLERS_BY_LABELS_OPERATION: - doListReplicationControllersByLabels(exchange, operation); - break; - - case KubernetesOperations.GET_REPLICATION_CONTROLLER_OPERATION: - doGetReplicationController(exchange, operation); - break; - - case KubernetesOperations.CREATE_REPLICATION_CONTROLLER_OPERATION: - doCreateReplicationController(exchange, operation); - break; - - case KubernetesOperations.DELETE_REPLICATION_CONTROLLER_OPERATION: - doDeleteReplicationController(exchange, operation); - break; - - case KubernetesOperations.SCALE_REPLICATION_CONTROLLER_OPERATION: - doScaleReplicationController(exchange, operation); - break; - - default: - throw new IllegalArgumentException("Unsupported operation " - + operation); - } - } - - protected void doList(Exchange exchange, String operation) throws Exception { - ReplicationControllerList rcList = null; - String namespaceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - if (!ObjectHelper.isEmpty(namespaceName)) { - rcList = getEndpoint().getKubernetesClient() - .replicationControllers().inNamespace(namespaceName).list(); - } else { - rcList = getEndpoint().getKubernetesClient() - .replicationControllers().list(); - } - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(rcList.getItems()); - } - - 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, - RollableScalableResource<ReplicationController, DoneableReplicationController>> 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, - RollableScalableResource<ReplicationController, DoneableReplicationController>> 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()); - - } - - 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); - } - - protected void doCreateReplicationController(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); - ReplicationControllerSpec rcSpec = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_SPEC, - ReplicationControllerSpec.class); - if (ObjectHelper.isEmpty(rcName)) { - LOG.error("Create a specific replication controller require specify a replication controller name"); - throw new IllegalArgumentException( - "Create a specific replication controller require specify a replication controller name"); - } - if (ObjectHelper.isEmpty(namespaceName)) { - LOG.error("Create a specific replication controller require specify a namespace name"); - throw new IllegalArgumentException( - "Create a specific replication controller require specify a namespace name"); - } - if (ObjectHelper.isEmpty(rcSpec)) { - LOG.error("Create a specific replication controller require specify a replication controller spec bean"); - throw new IllegalArgumentException( - "Create a specific replication controller require specify a replication controller spec bean"); - } - Map<String, String> labels = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLERS_LABELS, - Map.class); - ReplicationController rcCreating = new ReplicationControllerBuilder() - .withNewMetadata().withName(rcName).withLabels(labels) - .endMetadata().withSpec(rcSpec).build(); - rc = getEndpoint().getKubernetesClient().replicationControllers() - .inNamespace(namespaceName).create(rcCreating); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(rc); - } - - protected void doDeleteReplicationController(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); - if (ObjectHelper.isEmpty(rcName)) { - LOG.error("Delete a specific replication controller require specify a replication controller name"); - throw new IllegalArgumentException( - "Delete a specific replication controller require specify a replication controller name"); - } - if (ObjectHelper.isEmpty(namespaceName)) { - LOG.error("Delete a specific replication controller require specify a namespace name"); - throw new IllegalArgumentException( - "Delete a specific replication controller require specify a namespace name"); - } - boolean rcDeleted = getEndpoint().getKubernetesClient() - .replicationControllers().inNamespace(namespaceName) - .withName(rcName).delete(); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(rcDeleted); - } - - 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()); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/89eee3b9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesResourcesQuotaProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesResourcesQuotaProducer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesResourcesQuotaProducer.java deleted file mode 100644 index 73b806d..0000000 --- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesResourcesQuotaProducer.java +++ /dev/null @@ -1,217 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.kubernetes.producer; - -import java.util.Map; - -import io.fabric8.kubernetes.api.model.DoneableResourceQuota; -import io.fabric8.kubernetes.api.model.ResourceQuota; -import io.fabric8.kubernetes.api.model.ResourceQuotaBuilder; -import io.fabric8.kubernetes.api.model.ResourceQuotaList; -import io.fabric8.kubernetes.api.model.ResourceQuotaSpec; -import io.fabric8.kubernetes.client.dsl.MixedOperation; -import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation; -import io.fabric8.kubernetes.client.dsl.Resource; - -import org.apache.camel.Exchange; -import org.apache.camel.component.kubernetes.KubernetesConstants; -import org.apache.camel.component.kubernetes.KubernetesEndpoint; -import org.apache.camel.impl.DefaultProducer; -import org.apache.camel.util.MessageHelper; -import org.apache.camel.util.ObjectHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class KubernetesResourcesQuotaProducer extends DefaultProducer { - - private static final Logger LOG = LoggerFactory - .getLogger(KubernetesResourcesQuotaProducer.class); - - public KubernetesResourcesQuotaProducer(KubernetesEndpoint endpoint) { - super(endpoint); - } - - @Override - public KubernetesEndpoint getEndpoint() { - return (KubernetesEndpoint) super.getEndpoint(); - } - - @Override - public void process(Exchange exchange) throws Exception { - String operation; - - if (ObjectHelper.isEmpty(getEndpoint().getKubernetesConfiguration() - .getOperation())) { - operation = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_OPERATION, String.class); - } else { - operation = getEndpoint().getKubernetesConfiguration() - .getOperation(); - } - - switch (operation) { - - case KubernetesOperations.LIST_RESOURCES_QUOTA: - doList(exchange, operation); - break; - - case KubernetesOperations.LIST_SECRETS_BY_LABELS_OPERATION: - doListResourceQuotasByLabels(exchange, operation); - break; - - case KubernetesOperations.GET_RESOURCE_QUOTA_OPERATION: - doGetResourceQuota(exchange, operation); - break; - - case KubernetesOperations.CREATE_RESOURCE_QUOTA_OPERATION: - doCreateResourceQuota(exchange, operation); - break; - - case KubernetesOperations.DELETE_RESOURCE_QUOTA_OPERATION: - doDeleteResourceQuota(exchange, operation); - break; - - default: - throw new IllegalArgumentException("Unsupported operation " - + operation); - } - } - - protected void doList(Exchange exchange, String operation) throws Exception { - ResourceQuotaList resList = getEndpoint().getKubernetesClient() - .resourceQuotas().list(); - exchange.getOut().setBody(resList.getItems()); - } - - 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()); - } - - 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); - } - - protected void doCreateResourceQuota(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); - ResourceQuotaSpec rqSpec = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_RESOURCE_QUOTA_SPEC, - ResourceQuotaSpec.class); - if (ObjectHelper.isEmpty(rqName)) { - LOG.error("Create a specific resource quota require specify a resource quota name"); - throw new IllegalArgumentException( - "Create a specific resource quota require specify a resource quota name"); - } - if (ObjectHelper.isEmpty(namespaceName)) { - LOG.error("Create a specific resource quota require specify a namespace name"); - throw new IllegalArgumentException( - "Create a specific resource quota require specify a namespace name"); - } - if (ObjectHelper.isEmpty(rqSpec)) { - LOG.error("Create a specific resource quota require specify a resource quota spec bean"); - throw new IllegalArgumentException( - "Create a specific resource quota require specify a resource quota spec bean"); - } - Map<String, String> labels = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_RESOURCES_QUOTA_LABELS, - Map.class); - ResourceQuota rqCreating = new ResourceQuotaBuilder() - .withNewMetadata().withName(rqName).withLabels(labels) - .endMetadata().withSpec(rqSpec).build(); - rq = getEndpoint().getKubernetesClient().resourceQuotas() - .inNamespace(namespaceName).create(rqCreating); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(rq); - } - - protected void doDeleteResourceQuota(Exchange exchange, String operation) - throws Exception { - 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("Delete a specific resource quota require specify a resource quota name"); - throw new IllegalArgumentException( - "Delete a specific resource quota require specify a resource quota name"); - } - if (ObjectHelper.isEmpty(namespaceName)) { - LOG.error("Delete a specific resource quota require specify a namespace name"); - throw new IllegalArgumentException( - "Delete a specific resource quota require specify a namespace name"); - } - boolean rqDeleted = getEndpoint().getKubernetesClient() - .resourceQuotas().inNamespace(namespaceName).withName(rqName) - .delete(); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(rqDeleted); - } -}
