You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2015/10/18 10:18:53 UTC
[1/7] camel git commit: CAMEL-9085 Create a
Camel-Kubernetes/Openshift v3 Component. Add Camel-Kubernetes Feature
Repository: camel
Updated Branches:
refs/heads/master be3cc2f93 -> 9ab89ccf2
CAMEL-9085 Create a Camel-Kubernetes/Openshift v3 Component. Add Camel-Kubernetes Feature
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e4f23180
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e4f23180
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e4f23180
Branch: refs/heads/master
Commit: e4f231804034964bcfaece288e4c11b7a71967a2
Parents: 03d6484
Author: Andrea Cosentino <an...@gmail.com>
Authored: Sat Oct 17 14:10:57 2015 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Sun Oct 18 09:33:00 2015 +0200
----------------------------------------------------------------------
parent/pom.xml | 3 ++
.../features/src/main/resources/features.xml | 20 ++++++++++
.../camel/itest/karaf/CamelKubernetesTest.java | 40 ++++++++++++++++++++
3 files changed, 63 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/e4f23180/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index d317b6d..f382a92 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -252,6 +252,7 @@
<javax.el-version>2.2.5</javax.el-version>
<javax-inject-bundle-version>1_2</javax-inject-bundle-version>
<javax-mail-version>1.4.7</javax-mail-version>
+ <javax.servlet-api-version>3.1.0</javax.servlet-api-version>
<jaxb-bundle-version>2.2.6_1</jaxb-bundle-version>
<jaxen-version>1.1.6</jaxen-version>
<jbpm-version>6.3.0.Final</jbpm-version>
@@ -325,6 +326,7 @@
<kie-version>6.3.0.Final</kie-version>
<krati-version>0.4.9</krati-version>
<kubernetes-client-version>1.3.52</kubernetes-client-version>
+ <kubernetes-model-version>1.0.29</kubernetes-model-version>
<kxml2-bundle-version>2.3.0_2</kxml2-bundle-version>
<leveldbjni-version>1.8</leveldbjni-version>
<!-- virtual dependency only used by Eclipse m2e -->
@@ -384,6 +386,7 @@
<noggit-bundle-version>0.5_1</noggit-bundle-version>
<!-- should be in-sync with deltaspike -->
<openwebbeans-version>1.2.0</openwebbeans-version>
+ <oauth-provider-bundle-version>20100527_1</oauth-provider-bundle-version>
<olingo2-version>2.0.4</olingo2-version>
<olingo-odata2-core-bundle-version>2.0.4_1</olingo-odata2-core-bundle-version>
<ognl-version>3.0.11</ognl-version>
http://git-wip-us.apache.org/repos/asf/camel/blob/e4f23180/platforms/karaf/features/src/main/resources/features.xml
----------------------------------------------------------------------
diff --git a/platforms/karaf/features/src/main/resources/features.xml b/platforms/karaf/features/src/main/resources/features.xml
index a0a12f5..0906e13 100644
--- a/platforms/karaf/features/src/main/resources/features.xml
+++ b/platforms/karaf/features/src/main/resources/features.xml
@@ -992,6 +992,26 @@
<bundle>mvn:org.apache.camel/camel-krati/${project.version}</bundle>
<feature version='${project.version}'>camel-core</feature>
</feature>
+ <feature name='camel-kubernetes' version='${project.version}' resolver='(obr)' start-level='50'>
+ <bundle dependency='true'>mvn:javax.validation/validation-api/${validation-api-version}</bundle>
+ <bundle dependency='true'>mvn:javax.servlet/javax.servlet-api/${javax.servlet-api-version}</bundle>
+ <bundle dependency='true'>mvn:com.fasterxml.jackson.core/jackson-core/${jackson2-version}</bundle>
+ <bundle dependency='true'>mvn:com.fasterxml.jackson.core/jackson-annotations/${jackson2-version}</bundle>
+ <bundle dependency='true'>mvn:com.fasterxml.jackson.core/jackson-databind/${jackson2-version}</bundle>
+ <bundle dependency='true'>mvn:com.fasterxml.jackson.module/jackson-module-jaxb-annotations/${jackson2-version}</bundle>
+ <bundle dependency='true'>mvn:com.fasterxml.jackson.jaxrs/jackson-jaxrs-base/${jackson2-version}</bundle>
+ <bundle dependency='true'>mvn:com.fasterxml.jackson.jaxrs/jackson-jaxrs-json-provider/${jackson2-version}</bundle>
+ <bundle dependency='true'>mvn:com.fasterxml.jackson.dataformat/jackson-dataformat-yaml/${jackson2-version}</bundle>
+ <bundle dependency='true'>mvn:io.netty/netty/${netty3-version}</bundle>
+ <bundle dependency='true'>mvn:com.ning/async-http-client/${ahc-version}</bundle>
+ <bundle dependency='true'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.oauth-provider/${oauth-provider-bundle-version}</bundle>
+ <bundle dependency='true'>mvn:org.yaml/snakeyaml/${snakeyaml-version}</bundle>
+ <bundle dependency='true'>mvn:io.fabric8/kubernetes-model/${kubernetes-model-version}</bundle>
+ <bundle dependency='true'>mvn:io.fabric8/kubernetes-client/${kubernetes-client-version}</bundle>
+ <bundle dependency='true'>mvn:io.fabric8/openshift-client/${openshift-client-version}</bundle>
+ <bundle>mvn:org.apache.camel/camel-kubernetes/${project.version}</bundle>
+ <feature version='${project.version}'>camel-core</feature>
+ </feature>
<feature name='camel-ldap' version='${project.version}' resolver='(obr)' start-level='50'>
<feature version='${project.version}'>camel-core</feature>
<bundle>mvn:org.apache.camel/camel-ldap/${project.version}</bundle>
http://git-wip-us.apache.org/repos/asf/camel/blob/e4f23180/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelKubernetesTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelKubernetesTest.java b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelKubernetesTest.java
new file mode 100644
index 0000000..eda3cf2
--- /dev/null
+++ b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelKubernetesTest.java
@@ -0,0 +1,40 @@
+/**
+ * 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.itest.karaf;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+
+@RunWith(PaxExam.class)
+public class CamelKubernetesTest extends AbstractFeatureTest {
+
+ public static final String COMPONENT = extractName(CamelKubernetesTest.class);
+
+ @Test
+ public void test() throws Exception {
+ testComponent(COMPONENT);
+ }
+
+ @Configuration
+ public static Option[] configure() {
+ return configure(COMPONENT);
+ }
+
+}
\ No newline at end of file
[7/7] camel git commit: CAMEL-9085 Create a
Camel-Kubernetes/Openshift v3 Component. Completed configuration.
Posted by ac...@apache.org.
CAMEL-9085 Create a Camel-Kubernetes/Openshift v3 Component. Completed configuration.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9ab89ccf
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9ab89ccf
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9ab89ccf
Branch: refs/heads/master
Commit: 9ab89ccf2db0cea672792927bb89a4b97bb5857d
Parents: e4f2318
Author: Andrea Cosentino <an...@gmail.com>
Authored: Sun Oct 18 10:03:19 2015 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Sun Oct 18 10:03:19 2015 +0200
----------------------------------------------------------------------
.../component/kubernetes/KubernetesEndpoint.java | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/9ab89ccf/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesEndpoint.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesEndpoint.java
index 4833a37..3568f9f 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesEndpoint.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesEndpoint.java
@@ -203,6 +203,24 @@ public class KubernetesEndpoint extends DefaultEndpoint {
if (ObjectHelper.isNotEmpty(configuration.getClientCertFile())) {
builder.withClientCertFile(configuration.getClientCertFile());
}
+ if (ObjectHelper.isNotEmpty(configuration.getApiVersion())) {
+ builder.withApiVersion(configuration.getApiVersion());
+ }
+ if (ObjectHelper.isNotEmpty(configuration.getClientKeyAlgo())) {
+ builder.withClientKeyAlgo(configuration.getClientKeyAlgo());
+ }
+ if (ObjectHelper.isNotEmpty(configuration.getClientKeyData())) {
+ builder.withClientKeyData(configuration.getClientKeyData());
+ }
+ if (ObjectHelper.isNotEmpty(configuration.getClientKeyFile())) {
+ builder.withClientKeyFile(configuration.getClientKeyFile());
+ }
+ if (ObjectHelper.isNotEmpty(configuration.getClientKeyPassphrase())) {
+ builder.withClientKeyPassphrase(configuration.getClientKeyPassphrase());
+ }
+ if (ObjectHelper.isNotEmpty(configuration.getTrustCerts())) {
+ builder.withTrustCerts(configuration.getTrustCerts());
+ }
Config conf = builder.build();
[5/7] camel git commit: CAMEL-9085 Create a
Camel-Kubernetes/Openshift v3 Component
Posted by ac...@apache.org.
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/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
new file mode 100644
index 0000000..c926cbf
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesOperations.java
@@ -0,0 +1,96 @@
+/**
+ * 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";
+
+ // 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";
+
+ // 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/a452d0ac/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
new file mode 100644
index 0000000..609a00d
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesPersistentVolumesClaimsProducer.java
@@ -0,0 +1,216 @@
+/**
+ * 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.EditablePersistentVolumeClaim;
+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.KubernetesClient;
+import io.fabric8.kubernetes.client.dsl.ClientNonNamespaceOperation;
+import io.fabric8.kubernetes.client.dsl.ClientOperation;
+import io.fabric8.kubernetes.client.dsl.ClientResource;
+
+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.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)) {
+ ClientNonNamespaceOperation<KubernetesClient, PersistentVolumeClaim, PersistentVolumeClaimList,
+ DoneablePersistentVolumeClaim, ClientResource<PersistentVolumeClaim, DoneablePersistentVolumeClaim>> pvcs;
+ pvcs = getEndpoint().getKubernetesClient().persistentVolumeClaims()
+ .inNamespace(namespaceName);
+ for (Map.Entry<String, String> entry : labels.entrySet()) {
+ pvcs.withLabel(entry.getKey(), entry.getValue());
+ }
+ pvcList = pvcs.list();
+ } else {
+ ClientOperation<KubernetesClient, PersistentVolumeClaim, PersistentVolumeClaimList,
+ DoneablePersistentVolumeClaim, ClientResource<PersistentVolumeClaim, DoneablePersistentVolumeClaim>> pvcs;
+ pvcs = getEndpoint().getKubernetesClient().persistentVolumeClaims();
+ for (Map.Entry<String, String> entry : labels.entrySet()) {
+ pvcs.withLabel(entry.getKey(), entry.getValue());
+ }
+ pvcList = pvcs.list();
+ }
+ 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();
+ 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);
+ EditablePersistentVolumeClaim pvcCreating = new PersistentVolumeClaimBuilder()
+ .withNewMetadata().withName(pvcName).withLabels(labels)
+ .endMetadata().withSpec(pvcSpec).build();
+ pvc = getEndpoint().getKubernetesClient().persistentVolumeClaims()
+ .inNamespace(namespaceName).create(pvcCreating);
+ 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();
+ exchange.getOut().setBody(pvcDeleted);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/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
new file mode 100644
index 0000000..48f2beb
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesPersistentVolumesProducer.java
@@ -0,0 +1,139 @@
+/**
+ * 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.KubernetesClient;
+import io.fabric8.kubernetes.client.dsl.ClientNonNamespaceOperation;
+import io.fabric8.kubernetes.client.dsl.ClientOperation;
+import io.fabric8.kubernetes.client.dsl.ClientResource;
+
+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.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().inAnyNamespace().list();
+ 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);
+ String namespaceName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
+ if (!ObjectHelper.isEmpty(namespaceName)) {
+ ClientNonNamespaceOperation<KubernetesClient, PersistentVolume, PersistentVolumeList, DoneablePersistentVolume, ClientResource<PersistentVolume, DoneablePersistentVolume>> pvs;
+ pvs = getEndpoint().getKubernetesClient().persistentVolumes()
+ .inNamespace(namespaceName);
+ for (Map.Entry<String, String> entry : labels.entrySet()) {
+ pvs.withLabel(entry.getKey(), entry.getValue());
+ }
+ pvList = pvs.list();
+ } else {
+ ClientOperation<KubernetesClient, PersistentVolume, PersistentVolumeList, DoneablePersistentVolume, ClientResource<PersistentVolume, DoneablePersistentVolume>> pvs;
+ pvs = getEndpoint().getKubernetesClient().persistentVolumes();
+ for (Map.Entry<String, String> entry : labels.entrySet()) {
+ pvs.withLabel(entry.getKey(), entry.getValue());
+ }
+ pvList = pvs.list();
+ }
+ 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);
+ String namespaceName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_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");
+ }
+ if (ObjectHelper.isEmpty(namespaceName)) {
+ LOG.error("Get a specific Persistent Volume require specify a namespace name");
+ throw new IllegalArgumentException(
+ "Get a specific Persistent Volume require specify a namespace name");
+ }
+ pv = getEndpoint().getKubernetesClient().persistentVolumes()
+ .inNamespace(namespaceName).withName(pvName).get();
+ exchange.getOut().setBody(pv);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/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
new file mode 100644
index 0000000..1d4e648
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesPodsProducer.java
@@ -0,0 +1,193 @@
+/**
+ * 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.EditablePod;
+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.KubernetesClient;
+import io.fabric8.kubernetes.client.dsl.ClientLoggableResource;
+import io.fabric8.kubernetes.client.dsl.ClientOperation;
+import io.fabric8.kubernetes.client.dsl.ClientResource;
+
+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.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();
+ 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");
+ }
+ ClientOperation<KubernetesClient, Pod, PodList, DoneablePod, ClientLoggableResource<Pod, DoneablePod>> pods;
+ pods = getEndpoint().getKubernetesClient().pods();
+ for (Map.Entry<String, String> entry : labels.entrySet()) {
+ pods.withLabel(entry.getKey(), entry.getValue());
+ }
+ PodList podList = pods.list();
+ 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();
+ 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);
+ EditablePod podCreating = new PodBuilder().withNewMetadata()
+ .withName(podName).withLabels(labels).endMetadata()
+ .withSpec(podSpec).build();
+ pod = getEndpoint().getKubernetesClient().pods()
+ .inNamespace(namespaceName).create(podCreating);
+ 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();
+ exchange.getOut().setBody(podDeleted);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/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
new file mode 100644
index 0000000..5870b09
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesReplicationControllersProducer.java
@@ -0,0 +1,223 @@
+/**
+ * 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.EditableReplicationController;
+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.KubernetesClient;
+import io.fabric8.kubernetes.client.dsl.ClientNonNamespaceOperation;
+import io.fabric8.kubernetes.client.dsl.ClientOperation;
+import io.fabric8.kubernetes.client.dsl.ClientRollableScallableResource;
+
+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.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;
+
+ 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();
+ }
+ 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)) {
+ ClientNonNamespaceOperation<KubernetesClient, ReplicationController, ReplicationControllerList, DoneableReplicationController, ClientRollableScallableResource<ReplicationController,
+ DoneableReplicationController>> replicationControllers;
+ replicationControllers = getEndpoint().getKubernetesClient()
+ .replicationControllers().inNamespace(namespaceName);
+ for (Map.Entry<String, String> entry : labels.entrySet()) {
+ replicationControllers.withLabel(entry.getKey(),
+ entry.getValue());
+ }
+ rcList = replicationControllers.list();
+ } else {
+ ClientOperation<KubernetesClient, ReplicationController, ReplicationControllerList, DoneableReplicationController,
+ ClientRollableScallableResource<ReplicationController, DoneableReplicationController>> replicationControllers;
+ replicationControllers = getEndpoint().getKubernetesClient()
+ .replicationControllers();
+ for (Map.Entry<String, String> entry : labels.entrySet()) {
+ replicationControllers.withLabel(entry.getKey(),
+ entry.getValue());
+ }
+ rcList = replicationControllers.list();
+ }
+ 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();
+ 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);
+ EditableReplicationController rcCreating = new ReplicationControllerBuilder()
+ .withNewMetadata().withName(rcName).withLabels(labels)
+ .endMetadata().withSpec(rcSpec).build();
+ rc = getEndpoint().getKubernetesClient().replicationControllers()
+ .inNamespace(namespaceName).create(rcCreating);
+ 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();
+ exchange.getOut().setBody(rcDeleted);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/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
new file mode 100644
index 0000000..d61f418
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesResourcesQuotaProducer.java
@@ -0,0 +1,210 @@
+/**
+ * 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.EditableResourceQuota;
+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.KubernetesClient;
+import io.fabric8.kubernetes.client.dsl.ClientNonNamespaceOperation;
+import io.fabric8.kubernetes.client.dsl.ClientOperation;
+import io.fabric8.kubernetes.client.dsl.ClientResource;
+
+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.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)) {
+ ClientNonNamespaceOperation<KubernetesClient, ResourceQuota, ResourceQuotaList, DoneableResourceQuota, ClientResource<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 {
+ ClientOperation<KubernetesClient, ResourceQuota, ResourceQuotaList, DoneableResourceQuota, ClientResource<ResourceQuota, DoneableResourceQuota>> resQuota;
+ resQuota = getEndpoint().getKubernetesClient().resourceQuotas();
+ for (Map.Entry<String, String> entry : labels.entrySet()) {
+ resQuota.withLabel(entry.getKey(), entry.getValue());
+ }
+ resList = resQuota.list();
+ }
+ 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();
+ 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);
+ EditableResourceQuota rqCreating = new ResourceQuotaBuilder()
+ .withNewMetadata().withName(rqName).withLabels(labels)
+ .endMetadata().withSpec(rqSpec).build();
+ rq = getEndpoint().getKubernetesClient().resourceQuotas()
+ .inNamespace(namespaceName).create(rqCreating);
+ 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();
+ exchange.getOut().setBody(rqDeleted);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesSecretsProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesSecretsProducer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesSecretsProducer.java
new file mode 100644
index 0000000..5c74dda
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesSecretsProducer.java
@@ -0,0 +1,190 @@
+/**
+ * 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.DoneableSecret;
+import io.fabric8.kubernetes.api.model.Secret;
+import io.fabric8.kubernetes.api.model.SecretList;
+import io.fabric8.kubernetes.client.KubernetesClient;
+import io.fabric8.kubernetes.client.dsl.ClientNonNamespaceOperation;
+import io.fabric8.kubernetes.client.dsl.ClientOperation;
+import io.fabric8.kubernetes.client.dsl.ClientResource;
+
+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.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class KubernetesSecretsProducer extends DefaultProducer {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(KubernetesSecretsProducer.class);
+
+ public KubernetesSecretsProducer(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_SECRETS:
+ doList(exchange, operation);
+ break;
+
+ case KubernetesOperations.LIST_SECRETS_BY_LABELS_OPERATION:
+ doListSecretsByLabels(exchange, operation);
+ break;
+
+ case KubernetesOperations.GET_SECRET_OPERATION:
+ doGetSecret(exchange, operation);
+ break;
+
+ case KubernetesOperations.CREATE_SECRET_OPERATION:
+ doCreateSecret(exchange, operation);
+ break;
+
+ case KubernetesOperations.DELETE_SECRET_OPERATION:
+ doDeleteSecret(exchange, operation);
+ break;
+
+ default:
+ throw new IllegalArgumentException("Unsupported operation "
+ + operation);
+ }
+ }
+
+ protected void doList(Exchange exchange, String operation) throws Exception {
+ SecretList secretsList = getEndpoint().getKubernetesClient().secrets()
+ .list();
+ exchange.getOut().setBody(secretsList.getItems());
+ }
+
+ protected void doListSecretsByLabels(Exchange exchange, String operation)
+ throws Exception {
+ SecretList secretsList = null;
+ Map<String, String> labels = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_SECRETS_LABELS, Map.class);
+ String namespaceName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
+ if (!ObjectHelper.isEmpty(namespaceName)) {
+ ClientNonNamespaceOperation<KubernetesClient, Secret, SecretList, DoneableSecret, ClientResource<Secret, DoneableSecret>> secrets;
+ secrets = getEndpoint().getKubernetesClient().secrets()
+ .inNamespace(namespaceName);
+ for (Map.Entry<String, String> entry : labels.entrySet()) {
+ secrets.withLabel(entry.getKey(), entry.getValue());
+ }
+ secretsList = secrets.list();
+ } else {
+ ClientOperation<KubernetesClient, Secret, SecretList, DoneableSecret, ClientResource<Secret, DoneableSecret>> secrets;
+ secrets = getEndpoint().getKubernetesClient().secrets();
+ for (Map.Entry<String, String> entry : labels.entrySet()) {
+ secrets.withLabel(entry.getKey(), entry.getValue());
+ }
+ secretsList = secrets.list();
+ }
+ exchange.getOut().setBody(secretsList.getItems());
+ }
+
+ 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();
+ exchange.getOut().setBody(secret);
+ }
+
+ 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);
+ exchange.getOut().setBody(secret);
+ }
+
+ protected void doDeleteSecret(Exchange exchange, String operation)
+ throws Exception {
+ 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("Delete a specific secret require specify a secret name");
+ throw new IllegalArgumentException(
+ "Delete a specific secret require specify a secret name");
+ }
+ if (ObjectHelper.isEmpty(namespaceName)) {
+ LOG.error("Delete a specific secret require specify a namespace name");
+ throw new IllegalArgumentException(
+ "Delete a specific secret require specify a namespace name");
+ }
+ boolean secretDeleted = getEndpoint().getKubernetesClient().secrets()
+ .inNamespace(namespaceName).withName(secretName).delete();
+ exchange.getOut().setBody(secretDeleted);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesServiceAccountsProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesServiceAccountsProducer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesServiceAccountsProducer.java
new file mode 100644
index 0000000..9c9a141
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesServiceAccountsProducer.java
@@ -0,0 +1,193 @@
+/**
+ * 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.DoneableSecret;
+import io.fabric8.kubernetes.api.model.DoneableServiceAccount;
+import io.fabric8.kubernetes.api.model.Secret;
+import io.fabric8.kubernetes.api.model.SecretList;
+import io.fabric8.kubernetes.api.model.ServiceAccount;
+import io.fabric8.kubernetes.api.model.ServiceAccountList;
+import io.fabric8.kubernetes.client.KubernetesClient;
+import io.fabric8.kubernetes.client.dsl.ClientNonNamespaceOperation;
+import io.fabric8.kubernetes.client.dsl.ClientOperation;
+import io.fabric8.kubernetes.client.dsl.ClientResource;
+
+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.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class KubernetesServiceAccountsProducer extends DefaultProducer {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(KubernetesServiceAccountsProducer.class);
+
+ public KubernetesServiceAccountsProducer(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_SERVICE_ACCOUNTS:
+ doList(exchange, operation);
+ break;
+
+ case KubernetesOperations.LIST_SERVICE_ACCOUNTS_BY_LABELS_OPERATION:
+ doListServiceAccountsByLabels(exchange, operation);
+ break;
+
+ case KubernetesOperations.GET_SECRET_OPERATION:
+ doGetServiceAccount(exchange, operation);
+ break;
+
+ case KubernetesOperations.CREATE_SERVICE_ACCOUNT_OPERATION:
+ doCreateServiceAccount(exchange, operation);
+ break;
+
+ case KubernetesOperations.DELETE_SERVICE_ACCOUNT_OPERATION:
+ doDeleteServiceAccount(exchange, operation);
+ break;
+
+ default:
+ throw new IllegalArgumentException("Unsupported operation "
+ + operation);
+ }
+ }
+
+ protected void doList(Exchange exchange, String operation) throws Exception {
+ ServiceAccountList saList = getEndpoint().getKubernetesClient().serviceAccounts()
+ .list();
+ exchange.getOut().setBody(saList.getItems());
+ }
+
+ protected void doListServiceAccountsByLabels(Exchange exchange, String operation)
+ throws Exception {
+ ServiceAccountList saList = null;
+ Map<String, String> labels = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_ACCOUNTS_LABELS, Map.class);
+ String namespaceName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
+ if (!ObjectHelper.isEmpty(namespaceName)) {
+ ClientNonNamespaceOperation<KubernetesClient, ServiceAccount, ServiceAccountList, DoneableServiceAccount, ClientResource<ServiceAccount, DoneableServiceAccount>> serviceAccounts;
+ serviceAccounts = getEndpoint().getKubernetesClient().serviceAccounts()
+ .inNamespace(namespaceName);
+ for (Map.Entry<String, String> entry : labels.entrySet()) {
+ serviceAccounts.withLabel(entry.getKey(), entry.getValue());
+ }
+ saList = serviceAccounts.list();
+ } else {
+ ClientOperation<KubernetesClient, ServiceAccount, ServiceAccountList, DoneableServiceAccount, ClientResource<ServiceAccount, DoneableServiceAccount>> serviceAccounts;
+ serviceAccounts = getEndpoint().getKubernetesClient().serviceAccounts();
+ for (Map.Entry<String, String> entry : labels.entrySet()) {
+ serviceAccounts.withLabel(entry.getKey(), entry.getValue());
+ }
+ saList = serviceAccounts.list();
+ }
+ exchange.getOut().setBody(saList.getItems());
+ }
+
+ protected void doGetServiceAccount(Exchange exchange, String operation)
+ throws Exception {
+ ServiceAccount sa = null;
+ String saName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_ACCOUNT_NAME, String.class);
+ String namespaceName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
+ if (ObjectHelper.isEmpty(saName)) {
+ LOG.error("Get a specific Service Account require specify a Service Account name");
+ throw new IllegalArgumentException(
+ "Get a specific Service Account require specify a Service Account name");
+ }
+ if (ObjectHelper.isEmpty(namespaceName)) {
+ LOG.error("Get a specific Service Account require specify a namespace name");
+ throw new IllegalArgumentException(
+ "Get a specific Service Account require specify a namespace name");
+ }
+ sa = getEndpoint().getKubernetesClient().serviceAccounts()
+ .inNamespace(namespaceName).withName(saName).get();
+ exchange.getOut().setBody(sa);
+ }
+
+ protected void doCreateServiceAccount(Exchange exchange, String operation)
+ throws Exception {
+ ServiceAccount sa = null;
+ String namespaceName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
+ ServiceAccount saToCreate = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_ACCOUNT, ServiceAccount.class);
+ if (ObjectHelper.isEmpty(namespaceName)) {
+ LOG.error("Create a specific Service Account require specify a namespace name");
+ throw new IllegalArgumentException(
+ "Create a specific Service Account require specify a namespace name");
+ }
+ if (ObjectHelper.isEmpty(saToCreate)) {
+ LOG.error("Create a specific Service Account require specify a Service Account bean");
+ throw new IllegalArgumentException(
+ "Create a specific Service Account require specify a Service Account bean");
+ }
+ Map<String, String> labels = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_ACCOUNTS_LABELS, Map.class);
+ sa = getEndpoint().getKubernetesClient().serviceAccounts()
+ .inNamespace(namespaceName).create(saToCreate);
+ exchange.getOut().setBody(sa);
+ }
+
+ protected void doDeleteServiceAccount(Exchange exchange, String operation)
+ throws Exception {
+ String saName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_ACCOUNT_NAME, String.class);
+ String namespaceName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
+ if (ObjectHelper.isEmpty(saName)) {
+ LOG.error("Delete a specific Service Account require specify a Service Account name");
+ throw new IllegalArgumentException(
+ "Delete a specific Service Account require specify a Service Account name");
+ }
+ if (ObjectHelper.isEmpty(namespaceName)) {
+ LOG.error("Delete a specific Service Account require specify a namespace name");
+ throw new IllegalArgumentException(
+ "Delete a specific Service Account require specify a namespace name");
+ }
+ boolean saDeleted = getEndpoint().getKubernetesClient().serviceAccounts()
+ .inNamespace(namespaceName).withName(saName).delete();
+ exchange.getOut().setBody(saDeleted);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesServicesProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesServicesProducer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesServicesProducer.java
new file mode 100644
index 0000000..9c2c427
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesServicesProducer.java
@@ -0,0 +1,211 @@
+/**
+ * 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.DoneableService;
+import io.fabric8.kubernetes.api.model.EditableService;
+import io.fabric8.kubernetes.api.model.Service;
+import io.fabric8.kubernetes.api.model.ServiceBuilder;
+import io.fabric8.kubernetes.api.model.ServiceList;
+import io.fabric8.kubernetes.api.model.ServiceSpec;
+import io.fabric8.kubernetes.client.KubernetesClient;
+import io.fabric8.kubernetes.client.dsl.ClientNonNamespaceOperation;
+import io.fabric8.kubernetes.client.dsl.ClientOperation;
+import io.fabric8.kubernetes.client.dsl.ClientResource;
+
+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.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class KubernetesServicesProducer extends DefaultProducer {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(KubernetesServicesProducer.class);
+
+ public KubernetesServicesProducer(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_SERVICES_OPERATION:
+ doList(exchange, operation);
+ break;
+
+ case KubernetesOperations.LIST_SERVICES_BY_LABELS_OPERATION:
+ doListServiceByLabels(exchange, operation);
+ break;
+
+ case KubernetesOperations.GET_SERVICE_OPERATION:
+ doGetService(exchange, operation);
+ break;
+
+ case KubernetesOperations.CREATE_SERVICE_OPERATION:
+ doCreateService(exchange, operation);
+ break;
+
+ case KubernetesOperations.DELETE_SERVICE_OPERATION:
+ doDeleteService(exchange, operation);
+ break;
+
+ default:
+ throw new IllegalArgumentException("Unsupported operation "
+ + operation);
+ }
+ }
+
+ protected void doList(Exchange exchange, String operation) throws Exception {
+ ServiceList servicesList = null;
+ String namespaceName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
+ if (!ObjectHelper.isEmpty(namespaceName)) {
+ servicesList = getEndpoint().getKubernetesClient().services()
+ .inNamespace(namespaceName).list();
+ } else {
+ servicesList = getEndpoint().getKubernetesClient().services()
+ .list();
+ }
+ exchange.getOut().setBody(servicesList.getItems());
+ }
+
+ protected void doListServiceByLabels(Exchange exchange, String operation)
+ throws Exception {
+ ServiceList servicesList = null;
+ Map<String, String> labels = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_LABELS, Map.class);
+ String namespaceName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
+ if (!ObjectHelper.isEmpty(namespaceName)) {
+ ClientNonNamespaceOperation<KubernetesClient, Service, ServiceList, DoneableService, ClientResource<Service, DoneableService>> services;
+ services = getEndpoint().getKubernetesClient().services()
+ .inNamespace(namespaceName);
+ for (Map.Entry<String, String> entry : labels.entrySet()) {
+ services.withLabel(entry.getKey(), entry.getValue());
+ }
+ servicesList = services.list();
+ } else {
+ ClientOperation<KubernetesClient, Service, ServiceList, DoneableService, ClientResource<Service, DoneableService>> services;
+ services = getEndpoint().getKubernetesClient().services();
+ for (Map.Entry<String, String> entry : labels.entrySet()) {
+ services.withLabel(entry.getKey(), entry.getValue());
+ }
+ servicesList = services.list();
+ }
+ exchange.getOut().setBody(servicesList.getItems());
+ }
+
+ protected void doGetService(Exchange exchange, String operation)
+ throws Exception {
+ Service service = null;
+ String serviceName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_NAME, String.class);
+ String namespaceName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
+ if (ObjectHelper.isEmpty(serviceName)) {
+ LOG.error("Get a specific service require specify a service name");
+ throw new IllegalArgumentException(
+ "Get a specific service require specify a service name");
+ }
+ if (ObjectHelper.isEmpty(namespaceName)) {
+ LOG.error("Get a specific service require specify a namespace name");
+ throw new IllegalArgumentException(
+ "Get a specific service require specify a namespace name");
+ }
+ service = getEndpoint().getKubernetesClient().services()
+ .inNamespace(namespaceName).withName(serviceName).get();
+ exchange.getOut().setBody(service);
+ }
+
+ protected void doCreateService(Exchange exchange, String operation)
+ throws Exception {
+ Service service = null;
+ String serviceName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_NAME, String.class);
+ String namespaceName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
+ ServiceSpec serviceSpec = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_SPEC, ServiceSpec.class);
+ if (ObjectHelper.isEmpty(serviceName)) {
+ LOG.error("Create a specific service require specify a service name");
+ throw new IllegalArgumentException(
+ "Create a specific service require specify a service name");
+ }
+ if (ObjectHelper.isEmpty(namespaceName)) {
+ LOG.error("Create a specific service require specify a namespace name");
+ throw new IllegalArgumentException(
+ "Create a specific service require specify a namespace name");
+ }
+ if (ObjectHelper.isEmpty(serviceSpec)) {
+ LOG.error("Create a specific service require specify a service spec bean");
+ throw new IllegalArgumentException(
+ "Create a specific service require specify a service spec bean");
+ }
+ Map<String, String> labels = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_LABELS, Map.class);
+ EditableService serviceCreating = new ServiceBuilder()
+ .withNewMetadata().withName(serviceName).withLabels(labels)
+ .endMetadata().withSpec(serviceSpec).build();
+ service = getEndpoint().getKubernetesClient().services()
+ .inNamespace(namespaceName).create(serviceCreating);
+ exchange.getOut().setBody(service);
+ }
+
+ protected void doDeleteService(Exchange exchange, String operation)
+ throws Exception {
+ String serviceName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_NAME, String.class);
+ String namespaceName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
+ if (ObjectHelper.isEmpty(serviceName)) {
+ LOG.error("Delete a specific service require specify a service name");
+ throw new IllegalArgumentException(
+ "Delete a specific service require specify a service name");
+ }
+ if (ObjectHelper.isEmpty(namespaceName)) {
+ LOG.error("Delete a specific service require specify a namespace name");
+ throw new IllegalArgumentException(
+ "Delete a specific service require specify a namespace name");
+ }
+ boolean serviceDeleted = getEndpoint().getKubernetesClient().services()
+ .inNamespace(namespaceName).withName(serviceName).delete();
+ exchange.getOut().setBody(serviceDeleted);
+ }
+}
[3/7] camel git commit: CAMEL-9085 Create a
Camel-Kubernetes/Openshift v3 Component
Posted by ac...@apache.org.
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesReplicationControllersProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesReplicationControllersProducerTest.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesReplicationControllersProducerTest.java
new file mode 100644
index 0000000..eab26d0
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesReplicationControllersProducerTest.java
@@ -0,0 +1,215 @@
+/**
+ * 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.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import io.fabric8.kubernetes.api.model.EditablePodTemplateSpec;
+import io.fabric8.kubernetes.api.model.PodTemplateSpecBuilder;
+import io.fabric8.kubernetes.api.model.ReplicationController;
+import io.fabric8.kubernetes.api.model.ReplicationControllerSpec;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesTestSupport;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Test;
+
+public class KubernetesReplicationControllersProducerTest extends
+ KubernetesTestSupport {
+
+ @Test
+ public void listTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ List<ReplicationController> result = template.requestBody(
+ "direct:list", "", List.class);
+
+ boolean fabric8Exists = false;
+
+ Iterator<ReplicationController> it = result.iterator();
+ while (it.hasNext()) {
+ ReplicationController rc = (ReplicationController) it.next();
+ if ("fabric8".equalsIgnoreCase(rc.getMetadata().getName())) {
+ fabric8Exists = true;
+ }
+ }
+
+ assertTrue(fabric8Exists);
+ }
+
+ @Test
+ public void listByLabelsTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ Exchange ex = template.request("direct:listByLabels", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("component", "elasticsearch");
+ exchange.getIn()
+ .setHeader(
+ KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLERS_LABELS,
+ labels);
+ }
+ });
+
+ List<ReplicationController> result = ex.getOut().getBody(List.class);
+
+ boolean rcExists = false;
+ Iterator<ReplicationController> it = result.iterator();
+ while (it.hasNext()) {
+ ReplicationController rc = (ReplicationController) it.next();
+ if ("elasticsearch".equalsIgnoreCase(rc.getMetadata().getName())) {
+ rcExists = true;
+ }
+ }
+
+ assertFalse(rcExists);
+ }
+
+ @Test
+ public void getReplicationControllerTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ Exchange ex = template.request("direct:getReplicationController",
+ new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn()
+ .setHeader(
+ KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_NAME,
+ "elasticsearch");
+ }
+ });
+
+ ReplicationController result = ex.getOut().getBody(
+ ReplicationController.class);
+
+ assertNull(result);
+ }
+
+ @Test
+ public void createAndDeleteService() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ Exchange ex = template.request("direct:createReplicationController",
+ new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn()
+ .setHeader(
+ KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_NAME,
+ "test");
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("this", "rocks");
+ exchange.getIn()
+ .setHeader(
+ KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLERS_LABELS,
+ labels);
+ ReplicationControllerSpec rcSpec = new ReplicationControllerSpec();
+ rcSpec.setReplicas(2);
+ PodTemplateSpecBuilder builder = new PodTemplateSpecBuilder();
+ EditablePodTemplateSpec t = builder.withNewMetadata()
+ .withName("nginx-template")
+ .addToLabels("server", "nginx").endMetadata()
+ .withNewSpec().addNewContainer()
+ .withName("wildfly").withImage("jboss/wildfly")
+ .addNewPort().withContainerPort(80).endPort()
+ .endContainer().endSpec().build();
+ rcSpec.setTemplate(t);
+ Map<String, String> selectorMap = new HashMap<String, String>();
+ selectorMap.put("server", "nginx");
+ rcSpec.setSelector(selectorMap);
+ exchange.getIn()
+ .setHeader(
+ KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_SPEC,
+ rcSpec);
+ }
+ });
+
+ ReplicationController rc = ex.getOut().getBody(
+ ReplicationController.class);
+
+ assertEquals(rc.getMetadata().getName(), "test");
+
+ ex = template.request("direct:deleteReplicationController",
+ new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn()
+ .setHeader(
+ KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_NAME,
+ "test");
+ }
+ });
+
+ boolean rcDeleted = ex.getOut().getBody(Boolean.class);
+
+ assertTrue(rcDeleted);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:list")
+ .toF("kubernetes://%s?oauthToken=%s&category=replicationControllers&operation=listReplicationControllers",
+ host, authToken);
+ from("direct:listByLabels")
+ .toF("kubernetes://%s?oauthToken=%s&category=replicationControllers&operation=listReplicationControllersByLabels",
+ host, authToken);
+ from("direct:getReplicationController")
+ .toF("kubernetes://%s?oauthToken=%s&category=replicationControllers&operation=getReplicationController",
+ host, authToken);
+ from("direct:createReplicationController")
+ .toF("kubernetes://%s?oauthToken=%s&category=replicationControllers&operation=createReplicationController",
+ host, authToken);
+ from("direct:deleteReplicationController")
+ .toF("kubernetes://%s?oauthToken=%s&category=replicationControllers&operation=deleteReplicationController",
+ host, authToken);
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesResourcesQuotaProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesResourcesQuotaProducerTest.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesResourcesQuotaProducerTest.java
new file mode 100644
index 0000000..b0fc639
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesResourcesQuotaProducerTest.java
@@ -0,0 +1,142 @@
+/**
+ * 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.List;
+import java.util.Map;
+
+import io.fabric8.kubernetes.api.model.Quantity;
+import io.fabric8.kubernetes.api.model.ResourceQuota;
+import io.fabric8.kubernetes.api.model.ResourceQuotaSpec;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesTestSupport;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Test;
+
+public class KubernetesResourcesQuotaProducerTest extends KubernetesTestSupport {
+
+ @Test
+ public void listTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ List<ResourceQuota> result = template.requestBody("direct:list", "",
+ List.class);
+
+ assertTrue(result.size() == 0);
+ }
+
+ @Test
+ public void createAndDeleteResourceQuota() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ Exchange ex = template.request("direct:create", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_RESOURCES_QUOTA_NAME,
+ "test");
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("this", "rocks");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_RESOURCES_QUOTA_LABELS,
+ labels);
+ ResourceQuotaSpec rsSpec = new ResourceQuotaSpec();
+ Map<String, Quantity> mp = new HashMap<String, Quantity>();
+ mp.put("pods", new Quantity("100"));
+ rsSpec.setHard(mp);
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_RESOURCE_QUOTA_SPEC,
+ rsSpec);
+ }
+ });
+
+ ResourceQuota rs = ex.getOut().getBody(ResourceQuota.class);
+
+ assertEquals(rs.getMetadata().getName(), "test");
+
+ ex = template.request("direct:get", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_RESOURCES_QUOTA_NAME,
+ "test");
+ }
+ });
+
+ ResourceQuota rsGet = ex.getOut().getBody(ResourceQuota.class);
+
+ assertEquals(rsGet.getMetadata().getName(), "test");
+ assertEquals(rsGet.getSpec().getHard().get("pods"), new Quantity("100"));
+
+ ex = template.request("direct:delete", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_RESOURCES_QUOTA_NAME,
+ "test");
+ }
+ });
+
+ boolean rqDeleted = ex.getOut().getBody(Boolean.class);
+
+ assertTrue(rqDeleted);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:list")
+ .toF("kubernetes://%s?oauthToken=%s&category=resourcesQuota&operation=listResourcesQuota",
+ host, authToken);
+ from("direct:listByLabels")
+ .toF("kubernetes://%s?oauthToken=%s&category=resourcesQuota&operation=listResourcesQuotaByLabels",
+ host, authToken);
+ from("direct:get")
+ .toF("kubernetes://%s?oauthToken=%s&category=resourcesQuota&operation=getResourceQuota",
+ host, authToken);
+ from("direct:create")
+ .toF("kubernetes://%s?oauthToken=%s&category=resourcesQuota&operation=createResourceQuota",
+ host, authToken);
+ from("direct:delete")
+ .toF("kubernetes://%s?oauthToken=%s&category=resourcesQuota&operation=deleteResourceQuota",
+ host, authToken);
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesSecretsProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesSecretsProducerTest.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesSecretsProducerTest.java
new file mode 100644
index 0000000..9e3ff96
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesSecretsProducerTest.java
@@ -0,0 +1,170 @@
+/**
+ * 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.List;
+import java.util.Map;
+
+import com.ning.http.util.Base64;
+
+import io.fabric8.kubernetes.api.model.ObjectMeta;
+import io.fabric8.kubernetes.api.model.Secret;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesTestSupport;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Test;
+
+public class KubernetesSecretsProducerTest extends KubernetesTestSupport {
+
+ @Test
+ public void listTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ List<Secret> result = template.requestBody("direct:list", "",
+ List.class);
+
+ assertTrue(result.size() != 0);
+ }
+
+ @Test
+ public void listByLabelsTest() throws Exception {
+ if (authToken == null) {
+ return;
+ }
+ Exchange ex = template.request("direct:listByLabels", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("component", "elasticsearch");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SECRETS_LABELS, labels);
+ }
+ });
+
+ List<Secret> result = ex.getOut().getBody(List.class);
+ }
+
+ @Test
+ public void getSecretTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ Exchange ex = template.request("direct:get", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SECRET_NAME,
+ "builder-token-191oc");
+ }
+ });
+
+ Secret result = ex.getOut().getBody(Secret.class);
+ }
+
+ @Test
+ public void createAndDeleteSecret() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ Exchange ex = template.request("direct:create", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SECRET_NAME, "test");
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("this", "rocks");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SECRETS_LABELS, labels);
+ Secret s = new Secret();
+ s.setKind("Secret");
+ Map<String, String> mp = new HashMap<String, String>();
+ mp.put("username", Base64.encode("pippo".getBytes()));
+ mp.put("password", Base64.encode("password".getBytes()));
+ s.setData(mp);
+
+ ObjectMeta meta = new ObjectMeta();
+ meta.setName("test");
+ s.setMetadata(meta);
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SECRET, s);
+ }
+ });
+
+ Secret sec = ex.getOut().getBody(Secret.class);
+
+ assertEquals(sec.getMetadata().getName(), "test");
+
+ ex = template.request("direct:delete", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SECRET_NAME, "test");
+ }
+ });
+
+ boolean secDeleted = ex.getOut().getBody(Boolean.class);
+
+ assertTrue(secDeleted);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:list")
+ .toF("kubernetes://%s?oauthToken=%s&category=secrets&operation=listSecrets",
+ host, authToken);
+ from("direct:listByLabels")
+ .toF("kubernetes://%s?oauthToken=%s&category=secrets&operation=listSecretsByLabels",
+ host, authToken);
+ from("direct:get")
+ .toF("kubernetes://%s?oauthToken=%s&category=secrets&operation=getSecret",
+ host, authToken);
+ from("direct:create")
+ .toF("kubernetes://%s?oauthToken=%s&category=secrets&operation=createSecret",
+ host, authToken);
+ from("direct:delete")
+ .toF("kubernetes://%s?oauthToken=%s&category=secrets&operation=deleteSecret",
+ host, authToken);
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesServiceAccountsProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesServiceAccountsProducerTest.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesServiceAccountsProducerTest.java
new file mode 100644
index 0000000..6def15d
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesServiceAccountsProducerTest.java
@@ -0,0 +1,161 @@
+/**
+ * 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.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import com.ning.http.util.Base64;
+
+import io.fabric8.kubernetes.api.model.ObjectMeta;
+import io.fabric8.kubernetes.api.model.ServiceAccount;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesTestSupport;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Test;
+
+public class KubernetesServiceAccountsProducerTest extends KubernetesTestSupport {
+
+ @Test
+ public void listTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ List<ServiceAccount> result = template.requestBody("direct:list", "",
+ List.class);
+
+ boolean fabric8Exists = false;
+
+ Iterator<ServiceAccount> it = result.iterator();
+ while (it.hasNext()) {
+ ServiceAccount service = (ServiceAccount) it.next();
+ if ("fabric8".equalsIgnoreCase(service.getMetadata().getName())) {
+ fabric8Exists = true;
+ }
+ }
+
+ assertTrue(fabric8Exists);
+ }
+
+ @Test
+ public void listByLabelsTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ Exchange ex = template.request("direct:listByLabels", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("component", "elasticsearch");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_ACCOUNTS_LABELS, labels);
+ }
+ });
+
+ List<ServiceAccount> result = ex.getOut().getBody(List.class);
+
+ assertTrue(result.size() == 0);
+ }
+
+ @Test
+ public void createAndDeleteServiceAccount() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ Exchange ex = template.request("direct:create", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_ACCOUNT_NAME, "test");
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("this", "rocks");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_ACCOUNTS_LABELS, labels);
+ ServiceAccount s = new ServiceAccount();
+ s.setKind("ServiceAccount");
+ Map<String, String> mp = new HashMap<String, String>();
+ mp.put("username", Base64.encode("pippo".getBytes()));
+ mp.put("password", Base64.encode("password".getBytes()));
+
+ ObjectMeta meta = new ObjectMeta();
+ meta.setName("test");
+ s.setMetadata(meta);
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_ACCOUNT, s);
+ }
+ });
+
+ ServiceAccount sec = ex.getOut().getBody(ServiceAccount.class);
+
+ assertEquals(sec.getMetadata().getName(), "test");
+
+ ex = template.request("direct:delete", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_ACCOUNT_NAME, "test");
+ }
+ });
+
+ boolean secDeleted = ex.getOut().getBody(Boolean.class);
+
+ assertTrue(secDeleted);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:list")
+ .toF("kubernetes://%s?oauthToken=%s&category=serviceAccounts&operation=listServiceAccounts",
+ host, authToken);
+ from("direct:listByLabels")
+ .toF("kubernetes://%s?oauthToken=%s&category=serviceAccounts&operation=listServiceAccountsByLabels",
+ host, authToken);
+ from("direct:getServices")
+ .toF("kubernetes://%s?oauthToken=%s&category=serviceAccounts&operation=getServiceAccount",
+ host, authToken);
+ from("direct:create")
+ .toF("kubernetes://%s?oauthToken=%s&category=serviceAccounts&operation=createServiceAccount",
+ host, authToken);
+ from("direct:delete")
+ .toF("kubernetes://%s?oauthToken=%s&category=serviceAccounts&operation=deleteServiceAccount",
+ host, authToken);
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesServicesProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesServicesProducerTest.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesServicesProducerTest.java
new file mode 100644
index 0000000..375ab91
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesServicesProducerTest.java
@@ -0,0 +1,198 @@
+/**
+ * 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.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import io.fabric8.kubernetes.api.model.IntOrString;
+import io.fabric8.kubernetes.api.model.Service;
+import io.fabric8.kubernetes.api.model.ServicePort;
+import io.fabric8.kubernetes.api.model.ServiceSpec;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesTestSupport;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Test;
+
+public class KubernetesServicesProducerTest extends KubernetesTestSupport {
+
+ @Test
+ public void listTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ List<Service> result = template.requestBody("direct:list", "",
+ List.class);
+
+ boolean fabric8Exists = false;
+
+ Iterator<Service> it = result.iterator();
+ while (it.hasNext()) {
+ Service service = (Service) it.next();
+ if ("fabric8".equalsIgnoreCase(service.getMetadata().getName())) {
+ fabric8Exists = true;
+ }
+ }
+
+ assertTrue(fabric8Exists);
+ }
+
+ @Test
+ public void listByLabelsTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ Exchange ex = template.request("direct:listByLabels", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("component", "elasticsearch");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_LABELS, labels);
+ }
+ });
+
+ List<Service> result = ex.getOut().getBody(List.class);
+
+ boolean serviceExists = false;
+ Iterator<Service> it = result.iterator();
+ while (it.hasNext()) {
+ Service service = (Service) it.next();
+ if ("elasticsearch".equalsIgnoreCase(service.getMetadata()
+ .getName())) {
+ serviceExists = true;
+ }
+ }
+
+ assertFalse(serviceExists);
+ }
+
+ @Test
+ public void getServiceTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ Exchange ex = template.request("direct:getServices", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_NAME,
+ "elasticsearch");
+ }
+ });
+
+ Service result = ex.getOut().getBody(Service.class);
+
+ assertNull(result);
+ }
+
+ @Test
+ public void createAndDeleteService() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ Exchange ex = template.request("direct:createService", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_NAME, "test");
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("this", "rocks");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_LABELS, labels);
+ ServiceSpec serviceSpec = new ServiceSpec();
+ List<ServicePort> lsp = new ArrayList<ServicePort>();
+ ServicePort sp = new ServicePort();
+ sp.setPort(8080);
+ sp.setTargetPort(new IntOrString(8080));
+ sp.setProtocol("TCP");
+ lsp.add(sp);
+ serviceSpec.setPorts(lsp);
+ Map<String, String> selectorMap = new HashMap<String, String>();
+ selectorMap.put("containter", "test");
+ serviceSpec.setSelector(selectorMap);
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_SPEC,
+ serviceSpec);
+ }
+ });
+
+ Service serv = ex.getOut().getBody(Service.class);
+
+ assertEquals(serv.getMetadata().getName(), "test");
+
+ ex = template.request("direct:deleteService", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_NAME, "test");
+ }
+ });
+
+ boolean servDeleted = ex.getOut().getBody(Boolean.class);
+
+ assertTrue(servDeleted);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:list")
+ .toF("kubernetes://%s?oauthToken=%s&category=services&operation=listServices",
+ host, authToken);
+ from("direct:listByLabels")
+ .toF("kubernetes://%s?oauthToken=%s&category=services&operation=listServicesByLabels",
+ host, authToken);
+ from("direct:getServices")
+ .toF("kubernetes://%s?oauthToken=%s&category=services&operation=getService",
+ host, authToken);
+ from("direct:createService")
+ .toF("kubernetes://%s?oauthToken=%s&category=services&operation=createService",
+ host, authToken);
+ from("direct:deleteService")
+ .toF("kubernetes://%s?oauthToken=%s&category=services&operation=deleteService",
+ host, authToken);
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/resources/log4j.properties b/components/camel-kubernetes/src/test/resources/log4j.properties
new file mode 100644
index 0000000..255fe5c
--- /dev/null
+++ b/components/camel-kubernetes/src/test/resources/log4j.properties
@@ -0,0 +1,36 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+#
+# The logging properties used
+#
+log4j.rootLogger=INFO, file
+
+#log4j.logger.org.apache.camel=DEBUG
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+# File appender
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.file.file=target/camel-kubernetes-test.log
+log4j.appender.file.append=true
+
[6/7] camel git commit: CAMEL-9085 Create a
Camel-Kubernetes/Openshift v3 Component
Posted by ac...@apache.org.
CAMEL-9085 Create a Camel-Kubernetes/Openshift v3 Component
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a452d0ac
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a452d0ac
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a452d0ac
Branch: refs/heads/master
Commit: a452d0ac25c34a4cdf06b1cf3491a807c9072c71
Parents: be3cc2f
Author: Andrea Cosentino <an...@gmail.com>
Authored: Mon Sep 14 17:38:54 2015 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Sun Oct 18 09:33:00 2015 +0200
----------------------------------------------------------------------
components/camel-kubernetes/pom.xml | 81 +++++
.../kubernetes/KubernetesCategory.java | 44 +++
.../kubernetes/KubernetesComponent.java | 41 +++
.../kubernetes/KubernetesConfiguration.java | 303 +++++++++++++++++++
.../kubernetes/KubernetesConstants.java | 57 ++++
.../kubernetes/KubernetesEndpoint.java | 212 +++++++++++++
.../consumer/KubernetesPodsConsumer.java | 132 ++++++++
...ubernetesReplicationControllersConsumer.java | 129 ++++++++
.../consumer/KubernetesSecretsConsumer.java | 125 ++++++++
.../consumer/KubernetesServicesConsumer.java | 127 ++++++++
.../kubernetes/consumer/common/PodEvent.java | 32 ++
.../common/ReplicationControllerEvent.java | 33 ++
.../kubernetes/consumer/common/SecretEvent.java | 32 ++
.../consumer/common/ServiceEvent.java | 32 ++
.../KubernetesBuildConfigsProducer.java | 147 +++++++++
.../producer/KubernetesBuildsProducer.java | 143 +++++++++
.../producer/KubernetesNamespacesProducer.java | 159 ++++++++++
.../producer/KubernetesNodesProducer.java | 123 ++++++++
.../producer/KubernetesOperations.java | 96 ++++++
...bernetesPersistentVolumesClaimsProducer.java | 216 +++++++++++++
.../KubernetesPersistentVolumesProducer.java | 139 +++++++++
.../producer/KubernetesPodsProducer.java | 193 ++++++++++++
...ubernetesReplicationControllersProducer.java | 223 ++++++++++++++
.../KubernetesResourcesQuotaProducer.java | 210 +++++++++++++
.../producer/KubernetesSecretsProducer.java | 190 ++++++++++++
.../KubernetesServiceAccountsProducer.java | 193 ++++++++++++
.../producer/KubernetesServicesProducer.java | 211 +++++++++++++
.../src/main/resources/META-INF/LICENSE.txt | 203 +++++++++++++
.../src/main/resources/META-INF/NOTICE.txt | 11 +
.../org/apache/camel/component/kubernetes | 18 ++
.../kubernetes/KubernetesTestSupport.java | 38 +++
.../consumer/KubernetesPodsConsumerTest.java | 158 ++++++++++
...netesReplicationControllersConsumerTest.java | 165 ++++++++++
.../consumer/KubernetesSecretsConsumerTest.java | 141 +++++++++
.../KubernetesServicesConsumerTest.java | 145 +++++++++
.../KubernetesBuildConfigsProducerTest.java | 86 ++++++
.../producer/KubernetesBuildsProducerTest.java | 89 ++++++
.../KubernetesNamespacesProducerTest.java | 210 +++++++++++++
.../producer/KubernetesNodesProducerTest.java | 89 ++++++
...etesPersistentVolumesClaimsProducerTest.java | 191 ++++++++++++
...KubernetesPersistentVolumesProducerTest.java | 86 ++++++
.../producer/KubernetesPodsProducerTest.java | 205 +++++++++++++
...netesReplicationControllersProducerTest.java | 215 +++++++++++++
.../KubernetesResourcesQuotaProducerTest.java | 142 +++++++++
.../producer/KubernetesSecretsProducerTest.java | 170 +++++++++++
.../KubernetesServiceAccountsProducerTest.java | 161 ++++++++++
.../KubernetesServicesProducerTest.java | 198 ++++++++++++
.../src/test/resources/log4j.properties | 36 +++
48 files changed, 6380 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/pom.xml b/components/camel-kubernetes/pom.xml
new file mode 100644
index 0000000..cc70793
--- /dev/null
+++ b/components/camel-kubernetes/pom.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>components</artifactId>
+ <version>2.17-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-kubernetes</artifactId>
+ <packaging>bundle</packaging>
+ <name>Camel :: Kubernetes</name>
+
+ <properties>
+ <camel.osgi.export.pkg>org.apache.camel.component.kubernetes.*</camel.osgi.export.pkg>
+ <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=kubernetes</camel.osgi.export.service>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.fabric8</groupId>
+ <artifactId>kubernetes-client</artifactId>
+ <version>1.3.52</version>
+ </dependency>
+ <dependency>
+ <groupId>io.fabric8</groupId>
+ <artifactId>openshift-client</artifactId>
+ <version>1.3.52</version>
+ </dependency>
+ <!-- testing -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <!-- logging -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <forkCount>1</forkCount>
+ <reuseForks>false</reuseForks>
+ <forkedProcessTimeoutInSeconds>300</forkedProcessTimeoutInSeconds>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesCategory.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesCategory.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesCategory.java
new file mode 100644
index 0000000..faf4a89
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesCategory.java
@@ -0,0 +1,44 @@
+/**
+ * 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;
+
+public interface KubernetesCategory {
+
+ String NAMESPACES = "namespaces";
+
+ String SERVICES = "services";
+
+ String REPLICATION_CONTROLLERS = "replicationControllers";
+
+ String PODS = "pods";
+
+ String PERSISTENT_VOLUMES = "persistentVolumes";
+
+ String PERSISTENT_VOLUMES_CLAIMS = "persistentVolumesClaims";
+
+ String SECRETS = "secrets";
+
+ String RESOURCES_QUOTA = "resourcesQuota";
+
+ String SERVICE_ACCOUNTS = "serviceAccounts";
+
+ String NODES = "nodes";
+
+ String BUILDS = "builds";
+
+ String BUILD_CONFIGS = "buildConfigs";
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesComponent.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesComponent.java
new file mode 100644
index 0000000..028bfaf
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesComponent.java
@@ -0,0 +1,41 @@
+/**
+ * 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;
+
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * Represents the component that manages {@link GitEndpoint}.
+ */
+public class KubernetesComponent extends DefaultComponent {
+
+ protected Endpoint createEndpoint(String uri, String remaining,
+ Map<String, Object> parameters) throws Exception {
+ KubernetesConfiguration config = new KubernetesConfiguration();
+ setProperties(config, parameters);
+ config.setMasterUrl(remaining);
+ if (ObjectHelper.isEmpty(config.getMasterUrl())) {
+ throw new IllegalArgumentException("Master URL must be specified");
+ }
+ KubernetesEndpoint endpoint = new KubernetesEndpoint(uri, this, config);
+ return endpoint;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesConfiguration.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesConfiguration.java
new file mode 100644
index 0000000..9c5696f
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesConfiguration.java
@@ -0,0 +1,303 @@
+/**
+ * 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;
+
+import io.fabric8.kubernetes.client.DefaultKubernetesClient;
+
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriParams;
+import org.apache.camel.spi.UriPath;
+
+@UriParams
+public class KubernetesConfiguration {
+
+ @UriPath
+ @Metadata(required = "true")
+ private String masterUrl;
+
+ @UriParam(enums = "namespaces,services,replicationControllers,pods,persistentVolumes,persistentVolumesClaims,secrets,resourcesQuota,serviceAccounts,nodes,builds,buildConfigs")
+ @Metadata(required = "true")
+ private String category;
+
+ @UriParam
+ private DefaultKubernetesClient kubernetesClient;
+
+ @UriParam
+ private String username;
+
+ @UriParam
+ private String password;
+
+ @UriParam(label = "producer", enums = "listNamespaces,listNamespacesByLabels,getNamespace,createNamespace,deleteNamespace,listServices,listServicesByLabels,getService,createService,"
+ + "deleteService,listReplicationControllers,listReplicationControllersByLabels,getReplicationController,createReplicationController,deleteReplicationController,listPods,"
+ + "listPodsByLabels,getPod,createPod,deletePod,listPersistentVolumes,listPersistentVolumesByLabels,getPersistentVolume,listPersistentVolumesClaims,listPersistentVolumesClaimsByLabels,"
+ + "getPersistentVolumeClaim,createPersistentVolumeClaim,deletePersistentVolumeClaim,listSecrets,listSecretsByLabels,getSecret,createSecret,deleteSecret,listResourcesQuota,"
+ + "listResourcesQuotaByLabels,getResourceQuota,createResourceQuota,deleteResourceQuota,listServiceAccounts,listServiceAccountsByLabels,getServiceAccount,createServiceAccount,"
+ + "deleteServiceAccount,listNodes,listNodesByLabels,getNode,listBuilds,listBuildsByLabels,getBuild,listBuildConfigs,listBuildConfigsByLabels,getBuildConfig")
+ private String operation;
+
+ @UriParam
+ private String apiVersion;
+
+ @UriParam
+ private String caCertData;
+
+ @UriParam
+ private String caCertFile;
+
+ @UriParam
+ private String clientCertData;
+
+ @UriParam
+ private String clientCertFile;
+
+ @UriParam
+ private String clientKeyAlgo;
+
+ @UriParam
+ private String clientKeyData;
+
+ @UriParam
+ private String clientKeyFile;
+
+ @UriParam
+ private String clientKeyPassphrase;
+
+ @UriParam
+ private String oauthToken;
+
+ @UriParam
+ private Boolean trustCerts;
+
+ @UriParam(label = "consumer")
+ private String namespaceName;
+
+ /**
+ * Kubernetes Master url
+ */
+ public String getMasterUrl() {
+ return masterUrl;
+ }
+
+ public void setMasterUrl(String masterUrl) {
+ this.masterUrl = masterUrl;
+ }
+
+ /**
+ * Kubernetes Producer and Consumer category
+ */
+ public String getCategory() {
+ return category;
+ }
+
+ public void setCategory(String category) {
+ this.category = category;
+ }
+
+ /**
+ * Default KubernetesClient to use if provided
+ */
+ public DefaultKubernetesClient getKubernetesClient() {
+ return kubernetesClient;
+ }
+
+ public void setKubernetesClient(DefaultKubernetesClient kubernetesClient) {
+ this.kubernetesClient = kubernetesClient;
+ }
+
+ /**
+ * Username to connect to Kubernetes
+ */
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ /**
+ * Password to connect to Kubernetes
+ */
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ /**
+ * Producer operation to do on Kubernetes
+ */
+ public String getOperation() {
+ return operation;
+ }
+
+ public void setOperation(String operation) {
+ this.operation = operation;
+ }
+
+ /**
+ * The Kubernetes API Version to use
+ */
+ public String getApiVersion() {
+ return apiVersion;
+ }
+
+ public void setApiVersion(String apiVersion) {
+ this.apiVersion = apiVersion;
+ }
+
+ /**
+ * The CA Cert Data
+ */
+ public String getCaCertData() {
+ return caCertData;
+ }
+
+ public void setCaCertData(String caCertData) {
+ this.caCertData = caCertData;
+ }
+
+ /**
+ * The CA Cert File
+ */
+ public String getCaCertFile() {
+ return caCertFile;
+ }
+
+ public void setCaCertFile(String caCertFile) {
+ this.caCertFile = caCertFile;
+ }
+
+ /**
+ * The Client Cert Data
+ */
+ public String getClientCertData() {
+ return clientCertData;
+ }
+
+ public void setClientCertData(String clientCertData) {
+ this.clientCertData = clientCertData;
+ }
+
+ /**
+ * The Client Cert File
+ */
+ public String getClientCertFile() {
+ return clientCertFile;
+ }
+
+ public void setClientCertFile(String clientCertFile) {
+ this.clientCertFile = clientCertFile;
+ }
+
+ /**
+ * The Key Algorithm used by the client
+ */
+ public String getClientKeyAlgo() {
+ return clientKeyAlgo;
+ }
+
+ public void setClientKeyAlgo(String clientKeyAlgo) {
+ this.clientKeyAlgo = clientKeyAlgo;
+ }
+
+ /**
+ * The Client Key data
+ */
+ public String getClientKeyData() {
+ return clientKeyData;
+ }
+
+ public void setClientKeyData(String clientKeyData) {
+ this.clientKeyData = clientKeyData;
+ }
+
+ /**
+ * The Client Key file
+ */
+ public String getClientKeyFile() {
+ return clientKeyFile;
+ }
+
+ public void setClientKeyFile(String clientKeyFile) {
+ this.clientKeyFile = clientKeyFile;
+ }
+
+ /**
+ * The Client Key Passphrase
+ */
+ public String getClientKeyPassphrase() {
+ return clientKeyPassphrase;
+ }
+
+ public void setClientKeyPassphrase(String clientKeyPassphrase) {
+ this.clientKeyPassphrase = clientKeyPassphrase;
+ }
+
+ /**
+ * The Auth Token
+ */
+ public String getOauthToken() {
+ return oauthToken;
+ }
+
+ public void setOauthToken(String oauthToken) {
+ this.oauthToken = oauthToken;
+ }
+
+ /**
+ * Define if the certs we used are trusted anyway or not
+ */
+ public Boolean getTrustCerts() {
+ return trustCerts;
+ }
+
+ public void setTrustCerts(Boolean trustCerts) {
+ this.trustCerts = trustCerts;
+ }
+
+ /**
+ * The namespace name
+ */
+ public String getNamespaceName() {
+ return namespaceName;
+ }
+
+ public void setNamespaceName(String namespaceName) {
+ this.namespaceName = namespaceName;
+ }
+
+ @Override
+ public String toString() {
+ return "KubernetesConfiguration [masterUrl=" + masterUrl
+ + ", category=" + category + ", kubernetesClient="
+ + kubernetesClient + ", username=" + username + ", password="
+ + password + ", operation=" + operation + ", apiVersion="
+ + apiVersion + ", caCertData=" + caCertData + ", caCertFile="
+ + caCertFile + ", clientCertData=" + clientCertData
+ + ", clientCertFile=" + clientCertFile + ", clientKeyAlgo="
+ + clientKeyAlgo + ", clientKeyData=" + clientKeyData
+ + ", clientKeyFile=" + clientKeyFile + ", clientKeyPassphrase="
+ + clientKeyPassphrase + ", oauthToken=" + oauthToken
+ + ", trustCerts=" + trustCerts + ", namespaceName="
+ + namespaceName + "]";
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesConstants.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesConstants.java
new file mode 100644
index 0000000..6fcad8e
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesConstants.java
@@ -0,0 +1,57 @@
+/**
+ * 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;
+
+public interface KubernetesConstants {
+ // Producer
+ String KUBERNETES_OPERATION = "CamelKubernetesOperation";
+ String KUBERNETES_NAMESPACE_NAME = "CamelKubernetesNamespaceName";
+ String KUBERNETES_NAMESPACE_LABELS = "CamelKubernetesNamespaceLabels";
+ String KUBERNETES_SERVICE_LABELS = "CamelKubernetesServiceLabels";
+ String KUBERNETES_SERVICE_NAME = "CamelKubernetesServiceName";
+ String KUBERNETES_SERVICE_SPEC = "CamelKubernetesServiceSpec";
+ String KUBERNETES_REPLICATION_CONTROLLERS_LABELS = "CamelKubernetesReplicationControllersLabels";
+ String KUBERNETES_REPLICATION_CONTROLLER_NAME = "CamelKubernetesReplicationControllerName";
+ String KUBERNETES_REPLICATION_CONTROLLER_SPEC = "CamelKubernetesReplicationControllerSpec";
+ String KUBERNETES_PODS_LABELS = "CamelKubernetesPodsLabels";
+ String KUBERNETES_POD_NAME = "CamelKubernetesPodName";
+ String KUBERNETES_POD_SPEC = "CamelKubernetesPodSpec";
+ String KUBERNETES_PERSISTENT_VOLUMES_LABELS = "CamelKubernetesPersistentVolumesLabels";
+ String KUBERNETES_PERSISTENT_VOLUME_NAME = "CamelKubernetesPersistentVolumeName";
+ String KUBERNETES_PERSISTENT_VOLUMES_CLAIMS_LABELS = "CamelKubernetesPersistentVolumesClaimsLabels";
+ String KUBERNETES_PERSISTENT_VOLUME_CLAIM_NAME = "CamelKubernetesPersistentVolumeClaimName";
+ String KUBERNETES_PERSISTENT_VOLUME_CLAIM_SPEC = "CamelKubernetesPersistentVolumeClaimSpec";
+ String KUBERNETES_SECRETS_LABELS = "CamelKubernetesSecretsLabels";
+ String KUBERNETES_SECRET_NAME = "CamelKubernetesSecretName";
+ String KUBERNETES_SECRET = "CamelKubernetesSecret";
+ String KUBERNETES_RESOURCES_QUOTA_LABELS = "CamelKubernetesResourcesQuotaLabels";
+ String KUBERNETES_RESOURCES_QUOTA_NAME = "CamelKubernetesResourcesQuotaName";
+ String KUBERNETES_RESOURCE_QUOTA_SPEC = "CamelKubernetesResourceQuotaSpec";
+ String KUBERNETES_SERVICE_ACCOUNTS_LABELS = "CamelKubernetesServiceAccountsLabels";
+ String KUBERNETES_SERVICE_ACCOUNT_NAME = "CamelKubernetesServiceAccountName";
+ String KUBERNETES_SERVICE_ACCOUNT = "CamelKubernetesServiceAccount";
+ String KUBERNETES_NODES_LABELS = "CamelKubernetesNodesLabels";
+ String KUBERNETES_NODE_NAME = "CamelKubernetesNodeName";
+ String KUBERNETES_BUILDS_LABELS = "CamelKubernetesBuildsLabels";
+ String KUBERNETES_BUILD_NAME = "CamelKubernetesBuildName";
+ String KUBERNETES_BUILD_CONFIGS_LABELS = "CamelKubernetesBuildConfigsLabels";
+ String KUBERNETES_BUILD_CONFIG_NAME = "CamelKubernetesBuildConfigName";
+
+ // Consumer
+ String KUBERNETES_EVENT_ACTION = "CamelKubernetesEventAction";
+ String KUBERNETES_EVENT_TIMESTAMP = "CamelKubernetesEventTimestamp";
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesEndpoint.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesEndpoint.java
new file mode 100644
index 0000000..4833a37
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesEndpoint.java
@@ -0,0 +1,212 @@
+/**
+ * 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;
+
+import io.fabric8.kubernetes.client.Config;
+import io.fabric8.kubernetes.client.ConfigBuilder;
+import io.fabric8.kubernetes.client.DefaultKubernetesClient;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.component.kubernetes.consumer.KubernetesPodsConsumer;
+import org.apache.camel.component.kubernetes.consumer.KubernetesReplicationControllersConsumer;
+import org.apache.camel.component.kubernetes.consumer.KubernetesSecretsConsumer;
+import org.apache.camel.component.kubernetes.consumer.KubernetesServicesConsumer;
+import org.apache.camel.component.kubernetes.producer.KubernetesNamespacesProducer;
+import org.apache.camel.component.kubernetes.producer.KubernetesPersistentVolumesClaimsProducer;
+import org.apache.camel.component.kubernetes.producer.KubernetesPersistentVolumesProducer;
+import org.apache.camel.component.kubernetes.producer.KubernetesPodsProducer;
+import org.apache.camel.component.kubernetes.KubernetesCategory;
+import org.apache.camel.component.kubernetes.producer.KubernetesBuildConfigsProducer;
+import org.apache.camel.component.kubernetes.producer.KubernetesBuildsProducer;
+import org.apache.camel.component.kubernetes.producer.KubernetesNodesProducer;
+import org.apache.camel.component.kubernetes.producer.KubernetesReplicationControllersProducer;
+import org.apache.camel.component.kubernetes.producer.KubernetesResourcesQuotaProducer;
+import org.apache.camel.component.kubernetes.producer.KubernetesSecretsProducer;
+import org.apache.camel.component.kubernetes.producer.KubernetesServiceAccountsProducer;
+import org.apache.camel.component.kubernetes.producer.KubernetesServicesProducer;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@UriEndpoint(scheme = "kubernetes", title = "Kubernetes", syntax = "kubernetes:master", label = "cloud,paas")
+public class KubernetesEndpoint extends DefaultEndpoint {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(KubernetesEndpoint.class);
+
+ @UriParam
+ private KubernetesConfiguration configuration;
+
+ private DefaultKubernetesClient client;
+
+ public KubernetesEndpoint(String uri, KubernetesComponent component,
+ KubernetesConfiguration config) {
+ super(uri, component);
+ this.configuration = config;
+ }
+
+ @Override
+ public Producer createProducer() throws Exception {
+ if (ObjectHelper.isEmpty(configuration.getCategory())) {
+ throw new IllegalArgumentException(
+ "A producer category must be specified");
+ } else {
+ String category = configuration.getCategory();
+
+ switch (category) {
+
+ case KubernetesCategory.NAMESPACES:
+ return new KubernetesNamespacesProducer(this);
+
+ case KubernetesCategory.SERVICES:
+ return new KubernetesServicesProducer(this);
+
+ case KubernetesCategory.REPLICATION_CONTROLLERS:
+ return new KubernetesReplicationControllersProducer(this);
+
+ case KubernetesCategory.PODS:
+ return new KubernetesPodsProducer(this);
+
+ case KubernetesCategory.PERSISTENT_VOLUMES:
+ return new KubernetesPersistentVolumesProducer(this);
+
+ case KubernetesCategory.PERSISTENT_VOLUMES_CLAIMS:
+ return new KubernetesPersistentVolumesClaimsProducer(this);
+
+ case KubernetesCategory.SECRETS:
+ return new KubernetesSecretsProducer(this);
+
+ case KubernetesCategory.RESOURCES_QUOTA:
+ return new KubernetesResourcesQuotaProducer(this);
+
+ case KubernetesCategory.SERVICE_ACCOUNTS:
+ return new KubernetesServiceAccountsProducer(this);
+
+ case KubernetesCategory.NODES:
+ return new KubernetesNodesProducer(this);
+
+ case KubernetesCategory.BUILDS:
+ return new KubernetesBuildsProducer(this);
+
+ case KubernetesCategory.BUILD_CONFIGS:
+ return new KubernetesBuildConfigsProducer(this);
+
+ default:
+ throw new IllegalArgumentException("The " + category
+ + " producer category doesn't exist");
+ }
+ }
+ }
+
+ @Override
+ public Consumer createConsumer(Processor processor) throws Exception {
+ if (ObjectHelper.isEmpty(configuration.getCategory())) {
+ throw new IllegalArgumentException(
+ "A consumer category must be specified");
+ } else {
+ String category = configuration.getCategory();
+
+ switch (category) {
+
+ case KubernetesCategory.PODS:
+ return new KubernetesPodsConsumer(this, processor);
+
+ case KubernetesCategory.SERVICES:
+ return new KubernetesServicesConsumer(this, processor);
+
+ case KubernetesCategory.REPLICATION_CONTROLLERS:
+ return new KubernetesReplicationControllersConsumer(this, processor);
+
+ case KubernetesCategory.SECRETS:
+ return new KubernetesSecretsConsumer(this, processor);
+
+ default:
+ throw new IllegalArgumentException("The " + category
+ + " consumer category doesn't exist");
+ }
+ }
+ }
+
+ @Override
+ public boolean isSingleton() {
+ return false;
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+
+ client = configuration.getKubernetesClient() != null ? configuration
+ .getKubernetesClient() : createKubernetesClient();
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ super.doStop();
+ client.close();
+ }
+
+ public DefaultKubernetesClient getKubernetesClient() {
+ return client;
+ }
+
+
+ /**
+ * The kubernetes Configuration
+ */
+ public KubernetesConfiguration getKubernetesConfiguration() {
+ return configuration;
+ }
+
+ private DefaultKubernetesClient createKubernetesClient() {
+ LOG.debug("Create Kubernetes client with the following Configuration: " + configuration.toString());
+
+ DefaultKubernetesClient kubeClient = new DefaultKubernetesClient();
+ ConfigBuilder builder = new ConfigBuilder();
+ builder.withMasterUrl(configuration.getMasterUrl());
+ if ((ObjectHelper.isNotEmpty(configuration.getUsername()) && ObjectHelper
+ .isNotEmpty(configuration.getPassword()))
+ && ObjectHelper.isEmpty(configuration.getOauthToken())) {
+ builder.withUsername(configuration.getUsername());
+ builder.withPassword(configuration.getPassword());
+ } else {
+ builder.withOauthToken(configuration.getOauthToken());
+ }
+ if (ObjectHelper.isNotEmpty(configuration.getCaCertData())) {
+ builder.withCaCertData(configuration.getCaCertData());
+ }
+ if (ObjectHelper.isNotEmpty(configuration.getCaCertFile())) {
+ builder.withCaCertFile(configuration.getCaCertFile());
+ }
+ if (ObjectHelper.isNotEmpty(configuration.getClientCertData())) {
+ builder.withClientCertData(configuration.getClientCertData());
+ }
+ if (ObjectHelper.isNotEmpty(configuration.getClientCertFile())) {
+ builder.withClientCertFile(configuration.getClientCertFile());
+ }
+
+ Config conf = builder.build();
+
+ kubeClient = new DefaultKubernetesClient(conf);
+ return kubeClient;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesPodsConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesPodsConsumer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesPodsConsumer.java
new file mode 100644
index 0000000..9524f71
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesPodsConsumer.java
@@ -0,0 +1,132 @@
+/**
+ * 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.consumer;
+
+import io.fabric8.kubernetes.api.model.Pod;
+import io.fabric8.kubernetes.client.KubernetesClientException;
+import io.fabric8.kubernetes.client.Watcher;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesEndpoint;
+import org.apache.camel.component.kubernetes.consumer.common.PodEvent;
+import org.apache.camel.impl.ScheduledPollConsumer;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class KubernetesPodsConsumer extends ScheduledPollConsumer {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(KubernetesPodsConsumer.class);
+
+ private ConcurrentMap<Long, PodEvent> map;
+
+ public KubernetesPodsConsumer(KubernetesEndpoint endpoint,
+ Processor processor) {
+ super(endpoint, processor);
+ }
+
+ @Override
+ public KubernetesEndpoint getEndpoint() {
+ return (KubernetesEndpoint) super.getEndpoint();
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+ map = new ConcurrentHashMap<Long, PodEvent>();
+
+ if (ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration()
+ .getOauthToken())) {
+ if (ObjectHelper.isNotEmpty(getEndpoint()
+ .getKubernetesConfiguration().getNamespaceName())) {
+ getEndpoint()
+ .getKubernetesClient()
+ .pods()
+ .inNamespace(
+ getEndpoint().getKubernetesConfiguration()
+ .getNamespaceName())
+ .watch(new Watcher<Pod>() {
+
+ @Override
+ public void eventReceived(
+ io.fabric8.kubernetes.client.Watcher.Action action,
+ Pod resource) {
+ PodEvent pe = new PodEvent(action, resource);
+ map.put(System.currentTimeMillis(), pe);
+ }
+
+ @Override
+ public void onClose(KubernetesClientException cause) {
+ if (cause != null) {
+ LOG.error(cause.getMessage(), cause);
+ }
+
+ }
+ });
+ } else {
+ getEndpoint().getKubernetesClient().pods()
+ .watch(new Watcher<Pod>() {
+
+ @Override
+ public void eventReceived(
+ io.fabric8.kubernetes.client.Watcher.Action action,
+ Pod resource) {
+ PodEvent pe = new PodEvent(action, resource);
+ map.put(System.currentTimeMillis(), pe);
+ }
+
+ @Override
+ public void onClose(KubernetesClientException cause) {
+ if (cause != null) {
+ LOG.error(cause.getMessage(), cause);
+ }
+ }
+ });
+ }
+ }
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ super.doStop();
+ map.clear();
+ }
+
+ @Override
+ protected int poll() throws Exception {
+ int mapSize = map.size();
+ for (ConcurrentMap.Entry<Long, PodEvent> entry : map.entrySet()) {
+ PodEvent podEvent = (PodEvent) entry.getValue();
+ Exchange e = getEndpoint().createExchange();
+ e.getIn().setBody(podEvent.getPod());
+ e.getIn().setHeader(KubernetesConstants.KUBERNETES_EVENT_ACTION,
+ podEvent.getAction());
+ e.getIn().setHeader(KubernetesConstants.KUBERNETES_EVENT_TIMESTAMP,
+ entry.getKey());
+ getProcessor().process(e);
+ map.remove(entry.getKey());
+ }
+ return mapSize;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesReplicationControllersConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesReplicationControllersConsumer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesReplicationControllersConsumer.java
new file mode 100644
index 0000000..574a8f7
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesReplicationControllersConsumer.java
@@ -0,0 +1,129 @@
+/**
+ * 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.consumer;
+
+import io.fabric8.kubernetes.api.model.ReplicationController;
+import io.fabric8.kubernetes.api.model.Service;
+import io.fabric8.kubernetes.client.KubernetesClientException;
+import io.fabric8.kubernetes.client.Watcher;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesEndpoint;
+import org.apache.camel.component.kubernetes.consumer.common.ReplicationControllerEvent;
+import org.apache.camel.component.kubernetes.consumer.common.ServiceEvent;
+import org.apache.camel.impl.ScheduledPollConsumer;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class KubernetesReplicationControllersConsumer extends ScheduledPollConsumer {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(KubernetesReplicationControllersConsumer.class);
+
+ private ConcurrentMap<Long, ReplicationControllerEvent> map;
+
+ public KubernetesReplicationControllersConsumer(KubernetesEndpoint endpoint,
+ Processor processor) {
+ super(endpoint, processor);
+ }
+
+ @Override
+ public KubernetesEndpoint getEndpoint() {
+ return (KubernetesEndpoint) super.getEndpoint();
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+ map = new ConcurrentHashMap<Long, ReplicationControllerEvent>();
+
+ if (ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration().getOauthToken())) {
+ if (ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration().getNamespaceName())) {
+ getEndpoint().getKubernetesClient().replicationControllers().inNamespace(getEndpoint().getKubernetesConfiguration().getNamespaceName())
+ .watch(new Watcher<ReplicationController>() {
+
+ @Override
+ public void eventReceived(
+ io.fabric8.kubernetes.client.Watcher.Action action,
+ ReplicationController resource) {
+ ReplicationControllerEvent rce = new ReplicationControllerEvent(action, resource);
+ map.put(System.currentTimeMillis(), rce);
+
+ }
+
+ @Override
+ public void onClose(KubernetesClientException cause) {
+ if (cause != null) {
+ LOG.error(cause.getMessage(), cause);
+ }
+ }
+
+
+ });
+ } else {
+ getEndpoint().getKubernetesClient().replicationControllers()
+ .watch(new Watcher<ReplicationController>() {
+
+
+ @Override
+ public void eventReceived(
+ io.fabric8.kubernetes.client.Watcher.Action action,
+ ReplicationController resource) {
+ ReplicationControllerEvent se = new ReplicationControllerEvent(action, resource);
+ map.put(System.currentTimeMillis(), se);
+
+ }
+
+ @Override
+ public void onClose(KubernetesClientException cause) {
+ if (cause != null) {
+ LOG.error(cause.getMessage(), cause);
+ }
+ }
+ });
+ }
+ }
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ super.doStop();
+ map.clear();
+ }
+
+ @Override
+ protected int poll() throws Exception {
+ int mapSize = map.size();
+ for (ConcurrentMap.Entry<Long, ReplicationControllerEvent> entry : map.entrySet()) {
+ ReplicationControllerEvent serviceEvent = (ReplicationControllerEvent) entry.getValue();
+ Exchange e = getEndpoint().createExchange();
+ e.getIn().setBody(serviceEvent.getReplicationController());
+ e.getIn().setHeader(KubernetesConstants.KUBERNETES_EVENT_ACTION, serviceEvent.getAction());
+ e.getIn().setHeader(KubernetesConstants.KUBERNETES_EVENT_TIMESTAMP, entry.getKey());
+ getProcessor().process(e);
+ map.remove(entry.getKey());
+ }
+ return mapSize;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesSecretsConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesSecretsConsumer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesSecretsConsumer.java
new file mode 100644
index 0000000..4d68a35
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesSecretsConsumer.java
@@ -0,0 +1,125 @@
+/**
+ * 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.consumer;
+
+import io.fabric8.kubernetes.api.model.Pod;
+import io.fabric8.kubernetes.api.model.Secret;
+import io.fabric8.kubernetes.client.KubernetesClientException;
+import io.fabric8.kubernetes.client.Watcher;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesEndpoint;
+import org.apache.camel.component.kubernetes.consumer.common.PodEvent;
+import org.apache.camel.component.kubernetes.consumer.common.SecretEvent;
+import org.apache.camel.impl.ScheduledPollConsumer;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class KubernetesSecretsConsumer extends ScheduledPollConsumer {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(KubernetesSecretsConsumer.class);
+
+ private ConcurrentMap<Long, SecretEvent> map;
+
+ public KubernetesSecretsConsumer(KubernetesEndpoint endpoint,
+ Processor processor) {
+ super(endpoint, processor);
+ }
+
+ @Override
+ public KubernetesEndpoint getEndpoint() {
+ return (KubernetesEndpoint) super.getEndpoint();
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+ map = new ConcurrentHashMap<Long, SecretEvent>();
+
+ if (ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration().getOauthToken())) {
+ if (ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration().getNamespaceName())) {
+ getEndpoint().getKubernetesClient().secrets().inNamespace(getEndpoint().getKubernetesConfiguration().getNamespaceName())
+ .watch(new Watcher<Secret>() {
+
+ @Override
+ public void eventReceived(
+ io.fabric8.kubernetes.client.Watcher.Action action,
+ Secret resource) {
+ SecretEvent se = new SecretEvent(action, resource);
+ map.put(System.currentTimeMillis(), se);
+ }
+
+ @Override
+ public void onClose(KubernetesClientException cause) {
+ if (cause != null) {
+ LOG.error(cause.getMessage(), cause);
+ }
+
+ }
+ });
+ } else {
+ getEndpoint().getKubernetesClient().secrets()
+ .watch(new Watcher<Secret>() {
+
+ @Override
+ public void eventReceived(
+ io.fabric8.kubernetes.client.Watcher.Action action,
+ Secret resource) {
+ SecretEvent se = new SecretEvent(action, resource);
+ map.put(System.currentTimeMillis(), se);
+ }
+
+ @Override
+ public void onClose(KubernetesClientException cause) {
+ if (cause != null) {
+ LOG.error(cause.getMessage(), cause);
+ }
+ }
+ });
+ }
+ }
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ super.doStop();
+ map.clear();
+ }
+
+ @Override
+ protected int poll() throws Exception {
+ int mapSize = map.size();
+ for (ConcurrentMap.Entry<Long, SecretEvent> entry : map.entrySet()) {
+ SecretEvent podEvent = (SecretEvent) entry.getValue();
+ Exchange e = getEndpoint().createExchange();
+ e.getIn().setBody(podEvent.getSecret());
+ e.getIn().setHeader(KubernetesConstants.KUBERNETES_EVENT_ACTION, podEvent.getAction());
+ e.getIn().setHeader(KubernetesConstants.KUBERNETES_EVENT_TIMESTAMP, entry.getKey());
+ getProcessor().process(e);
+ map.remove(entry.getKey());
+ }
+ return mapSize;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesServicesConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesServicesConsumer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesServicesConsumer.java
new file mode 100644
index 0000000..de25388
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesServicesConsumer.java
@@ -0,0 +1,127 @@
+/**
+ * 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.consumer;
+
+import io.fabric8.kubernetes.api.model.Service;
+import io.fabric8.kubernetes.client.KubernetesClientException;
+import io.fabric8.kubernetes.client.Watcher;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesEndpoint;
+import org.apache.camel.component.kubernetes.consumer.common.ServiceEvent;
+import org.apache.camel.impl.ScheduledPollConsumer;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class KubernetesServicesConsumer extends ScheduledPollConsumer {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(KubernetesServicesConsumer.class);
+
+ private ConcurrentMap<Long, ServiceEvent> map;
+
+ public KubernetesServicesConsumer(KubernetesEndpoint endpoint,
+ Processor processor) {
+ super(endpoint, processor);
+ }
+
+ @Override
+ public KubernetesEndpoint getEndpoint() {
+ return (KubernetesEndpoint) super.getEndpoint();
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+ map = new ConcurrentHashMap<Long, ServiceEvent>();
+
+ if (ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration().getOauthToken())) {
+ if (ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration().getNamespaceName())) {
+ getEndpoint().getKubernetesClient().services().inNamespace(getEndpoint().getKubernetesConfiguration().getNamespaceName())
+ .watch(new Watcher<Service>() {
+
+ @Override
+ public void eventReceived(
+ io.fabric8.kubernetes.client.Watcher.Action action,
+ Service resource) {
+ ServiceEvent se = new ServiceEvent(action, resource);
+ map.put(System.currentTimeMillis(), se);
+
+ }
+
+ @Override
+ public void onClose(KubernetesClientException cause) {
+ if (cause != null) {
+ LOG.error(cause.getMessage(), cause);
+ }
+ }
+
+
+ });
+ } else {
+ getEndpoint().getKubernetesClient().services()
+ .watch(new Watcher<Service>() {
+
+
+ @Override
+ public void eventReceived(
+ io.fabric8.kubernetes.client.Watcher.Action action,
+ Service resource) {
+ ServiceEvent se = new ServiceEvent(action, resource);
+ map.put(System.currentTimeMillis(), se);
+
+ }
+
+ @Override
+ public void onClose(KubernetesClientException cause) {
+ if (cause != null) {
+ LOG.error(cause.getMessage(), cause);
+ }
+ }
+ });
+ }
+ }
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ super.doStop();
+ map.clear();
+ }
+
+ @Override
+ protected int poll() throws Exception {
+ int mapSize = map.size();
+ for (ConcurrentMap.Entry<Long, ServiceEvent> entry : map.entrySet()) {
+ ServiceEvent serviceEvent = (ServiceEvent) entry.getValue();
+ Exchange e = getEndpoint().createExchange();
+ e.getIn().setBody(serviceEvent.getService());
+ e.getIn().setHeader(KubernetesConstants.KUBERNETES_EVENT_ACTION, serviceEvent.getAction());
+ e.getIn().setHeader(KubernetesConstants.KUBERNETES_EVENT_TIMESTAMP, entry.getKey());
+ getProcessor().process(e);
+ map.remove(entry.getKey());
+ }
+ return mapSize;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/common/PodEvent.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/common/PodEvent.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/common/PodEvent.java
new file mode 100644
index 0000000..7b87b48
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/common/PodEvent.java
@@ -0,0 +1,32 @@
+package org.apache.camel.component.kubernetes.consumer.common;
+
+import io.fabric8.kubernetes.api.model.Pod;
+import io.fabric8.kubernetes.client.Watcher.Action;
+
+public class PodEvent {
+ private io.fabric8.kubernetes.client.Watcher.Action action;
+
+ private Pod pod;
+
+ public PodEvent(Action action, Pod pod) {
+ super();
+ this.action = action;
+ this.pod = pod;
+ }
+
+ public io.fabric8.kubernetes.client.Watcher.Action getAction() {
+ return action;
+ }
+
+ public void setAction(io.fabric8.kubernetes.client.Watcher.Action action) {
+ this.action = action;
+ }
+
+ public Pod getPod() {
+ return pod;
+ }
+
+ public void setPod(Pod pod) {
+ this.pod = pod;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/common/ReplicationControllerEvent.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/common/ReplicationControllerEvent.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/common/ReplicationControllerEvent.java
new file mode 100644
index 0000000..dda946d
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/common/ReplicationControllerEvent.java
@@ -0,0 +1,33 @@
+package org.apache.camel.component.kubernetes.consumer.common;
+
+import io.fabric8.kubernetes.api.model.ReplicationController;
+import io.fabric8.kubernetes.api.model.Service;
+import io.fabric8.kubernetes.client.Watcher.Action;
+
+public class ReplicationControllerEvent {
+ private io.fabric8.kubernetes.client.Watcher.Action action;
+
+ private ReplicationController replicationController;
+
+ public ReplicationControllerEvent(Action action, ReplicationController rc) {
+ super();
+ this.action = action;
+ this.replicationController = rc;
+ }
+
+ public io.fabric8.kubernetes.client.Watcher.Action getAction() {
+ return action;
+ }
+
+ public void setAction(io.fabric8.kubernetes.client.Watcher.Action action) {
+ this.action = action;
+ }
+
+ public ReplicationController getReplicationController() {
+ return replicationController;
+ }
+
+ public void setReplicationController(ReplicationController replicationController) {
+ this.replicationController = replicationController;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/common/SecretEvent.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/common/SecretEvent.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/common/SecretEvent.java
new file mode 100644
index 0000000..048a478
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/common/SecretEvent.java
@@ -0,0 +1,32 @@
+package org.apache.camel.component.kubernetes.consumer.common;
+
+import io.fabric8.kubernetes.api.model.Secret;
+import io.fabric8.kubernetes.client.Watcher.Action;
+
+public class SecretEvent {
+ private io.fabric8.kubernetes.client.Watcher.Action action;
+
+ private Secret secret;
+
+ public SecretEvent(Action action, Secret secret) {
+ super();
+ this.action = action;
+ this.secret = secret;
+ }
+
+ public io.fabric8.kubernetes.client.Watcher.Action getAction() {
+ return action;
+ }
+
+ public void setAction(io.fabric8.kubernetes.client.Watcher.Action action) {
+ this.action = action;
+ }
+
+ public Secret getSecret() {
+ return secret;
+ }
+
+ public void setSecret(Secret secret) {
+ this.secret = secret;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/common/ServiceEvent.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/common/ServiceEvent.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/common/ServiceEvent.java
new file mode 100644
index 0000000..199ee44
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/common/ServiceEvent.java
@@ -0,0 +1,32 @@
+package org.apache.camel.component.kubernetes.consumer.common;
+
+import io.fabric8.kubernetes.api.model.Service;
+import io.fabric8.kubernetes.client.Watcher.Action;
+
+public class ServiceEvent {
+ private io.fabric8.kubernetes.client.Watcher.Action action;
+
+ private Service service;
+
+ public ServiceEvent(Action action, Service service) {
+ super();
+ this.action = action;
+ this.service = service;
+ }
+
+ public io.fabric8.kubernetes.client.Watcher.Action getAction() {
+ return action;
+ }
+
+ public void setAction(io.fabric8.kubernetes.client.Watcher.Action action) {
+ this.action = action;
+ }
+
+ public Service getService() {
+ return service;
+ }
+
+ public void setService(Service service) {
+ this.service = service;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesBuildConfigsProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesBuildConfigsProducer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesBuildConfigsProducer.java
new file mode 100644
index 0000000..9eb23dc
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesBuildConfigsProducer.java
@@ -0,0 +1,147 @@
+/**
+ * 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.KubernetesClient;
+import io.fabric8.kubernetes.client.dsl.ClientNonNamespaceOperation;
+import io.fabric8.kubernetes.client.dsl.ClientOperation;
+import io.fabric8.kubernetes.client.dsl.ClientResource;
+import io.fabric8.openshift.api.model.Build;
+import io.fabric8.openshift.api.model.BuildConfig;
+import io.fabric8.openshift.api.model.BuildConfigList;
+import io.fabric8.openshift.api.model.BuildList;
+import io.fabric8.openshift.api.model.DoneableBuild;
+import io.fabric8.openshift.api.model.DoneableBuildConfig;
+import io.fabric8.openshift.client.OpenShiftClient;
+import io.fabric8.openshift.client.dsl.ClientBuildConfigResource;
+
+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.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class KubernetesBuildConfigsProducer extends DefaultProducer {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(KubernetesBuildConfigsProducer.class);
+
+ public KubernetesBuildConfigsProducer(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_CONFIGS:
+ doList(exchange, operation);
+ break;
+
+ case KubernetesOperations.LIST_BUILD_CONFIGS_BY_LABELS_OPERATION:
+ doListBuildConfigsByLabels(exchange, operation);
+ break;
+
+ case KubernetesOperations.GET_BUILD_CONFIG_OPERATION:
+ doGetBuildConfig(exchange, operation);
+ break;
+
+ default:
+ throw new IllegalArgumentException("Unsupported operation "
+ + operation);
+ }
+ }
+
+ protected void doList(Exchange exchange, String operation) throws Exception {
+ BuildConfigList buildConfigsList = getEndpoint()
+ .getKubernetesClient().adapt(OpenShiftClient.class).buildConfigs().list();
+ exchange.getOut().setBody(buildConfigsList.getItems());
+ }
+
+ protected void doListBuildConfigsByLabels(Exchange exchange,
+ String operation) throws Exception {
+ BuildConfigList buildConfigsList = null;
+ Map<String, String> labels = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_BUILD_CONFIGS_LABELS,
+ Map.class);
+ String namespaceName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
+ if (!ObjectHelper.isEmpty(namespaceName)) {
+ ClientNonNamespaceOperation<OpenShiftClient, BuildConfig, BuildConfigList, DoneableBuildConfig, ClientBuildConfigResource<BuildConfig, DoneableBuildConfig, Void, Void>> buildConfigs;
+ buildConfigs = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).buildConfigs()
+ .inNamespace(namespaceName);
+ for (Map.Entry<String, String> entry : labels.entrySet()) {
+ buildConfigs.withLabel(entry.getKey(), entry.getValue());
+ }
+ buildConfigsList = buildConfigs.list();
+ } else {
+ ClientOperation<OpenShiftClient, BuildConfig, BuildConfigList, DoneableBuildConfig, ClientBuildConfigResource<BuildConfig, DoneableBuildConfig, Void, Void>> buildConfigs;
+ buildConfigs = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).buildConfigs();
+ for (Map.Entry<String, String> entry : labels.entrySet()) {
+ buildConfigs.withLabel(entry.getKey(), entry.getValue());
+ }
+ buildConfigsList = buildConfigs.list();
+ }
+ exchange.getOut().setBody(buildConfigsList.getItems());
+ }
+
+ protected void doGetBuildConfig(Exchange exchange, String operation)
+ throws Exception {
+ BuildConfig buildConfig = null;
+ String buildConfigName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_BUILD_CONFIG_NAME,
+ String.class);
+ String namespaceName = exchange.getIn().getHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
+ if (ObjectHelper.isEmpty(buildConfigName)) {
+ LOG.error("Get a specific Build Config require specify a Build Config name");
+ throw new IllegalArgumentException(
+ "Get a specific Build Config require specify a Build Config name");
+ }
+ if (ObjectHelper.isEmpty(namespaceName)) {
+ LOG.error("Get a specific Build Config require specify a namespace name");
+ throw new IllegalArgumentException(
+ "Get a specific Build Config require specify a namespace name");
+ }
+ buildConfig = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).buildConfigs()
+ .inNamespace(namespaceName).withName(buildConfigName).get();
+ exchange.getOut().setBody(buildConfig);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/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
new file mode 100644
index 0000000..bd54f32
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesBuildsProducer.java
@@ -0,0 +1,143 @@
+/**
+ * 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.KubernetesClient;
+import io.fabric8.kubernetes.client.dsl.ClientNonNamespaceOperation;
+import io.fabric8.kubernetes.client.dsl.ClientOperation;
+import io.fabric8.kubernetes.client.dsl.ClientResource;
+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 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.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)) {
+ ClientNonNamespaceOperation<OpenShiftClient, Build, BuildList, DoneableBuild, ClientResource<Build, DoneableBuild>> builds;
+ 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 {
+ ClientOperation<OpenShiftClient, Build, BuildList, DoneableBuild, ClientResource<Build, DoneableBuild>> builds;
+ builds = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).builds();
+ for (Map.Entry<String, String> entry : labels.entrySet()) {
+ builds.withLabel(entry.getKey(), entry.getValue());
+ }
+ buildList = builds.list();
+ }
+ 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();
+ exchange.getOut().setBody(build);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/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
new file mode 100644
index 0000000..0db6cc5
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesNamespacesProducer.java
@@ -0,0 +1,159 @@
+/**
+ * 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.EditableNamespace;
+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.KubernetesClient;
+import io.fabric8.kubernetes.client.dsl.ClientNonNamespaceOperation;
+import io.fabric8.kubernetes.client.dsl.ClientResource;
+
+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.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");
+ }
+ ClientNonNamespaceOperation<KubernetesClient, Namespace, NamespaceList, DoneableNamespace, ClientResource<Namespace, DoneableNamespace>> namespaces;
+ namespaces = getEndpoint().getKubernetesClient().namespaces();
+ for (Map.Entry<String, String> entry : labels.entrySet()) {
+ namespaces.withLabel(entry.getKey(), entry.getValue());
+ }
+ NamespaceList namespace = namespaces.list();
+ 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();
+ 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);
+ EditableNamespace ns = new NamespaceBuilder().withNewMetadata()
+ .withName(namespaceName).withLabels(labels).endMetadata()
+ .build();
+ Namespace namespace = getEndpoint().getKubernetesClient().namespaces()
+ .create(ns);
+ 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();
+ exchange.getOut().setBody(namespace);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/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
new file mode 100644
index 0000000..cae957b
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesNodesProducer.java
@@ -0,0 +1,123 @@
+/**
+ * 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.DoneablePersistentVolume;
+import io.fabric8.kubernetes.api.model.Node;
+import io.fabric8.kubernetes.api.model.NodeList;
+import io.fabric8.kubernetes.api.model.PersistentVolume;
+import io.fabric8.kubernetes.api.model.PersistentVolumeList;
+import io.fabric8.kubernetes.client.KubernetesClient;
+import io.fabric8.kubernetes.client.dsl.ClientNonNamespaceOperation;
+import io.fabric8.kubernetes.client.dsl.ClientOperation;
+import io.fabric8.kubernetes.client.dsl.ClientResource;
+
+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.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();
+ 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);
+ ClientNonNamespaceOperation<KubernetesClient, Node, NodeList, DoneableNode, ClientResource<Node, DoneableNode>> nodes;
+ nodes = getEndpoint().getKubernetesClient().nodes();
+ for (Map.Entry<String, String> entry : labels.entrySet()) {
+ nodes.withLabel(entry.getKey(), entry.getValue());
+ }
+ nodeList = nodes.list();
+ 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();
+
+ exchange.getOut().setBody(node);
+ }
+}
[2/7] camel git commit: CAMEL-9085 Create a
Camel-Kubernetes/Openshift v3 Component. Add Camel-Kubernetes to kit
Posted by ac...@apache.org.
CAMEL-9085 Create a Camel-Kubernetes/Openshift v3 Component. Add Camel-Kubernetes to kit
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/03d64843
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/03d64843
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/03d64843
Branch: refs/heads/master
Commit: 03d64843fe1acc7ae2f4a441cd38a16bcbfa378b
Parents: a452d0a
Author: Andrea Cosentino <an...@gmail.com>
Authored: Sat Oct 17 13:44:05 2015 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Sun Oct 18 09:33:00 2015 +0200
----------------------------------------------------------------------
apache-camel/pom.xml | 4 ++++
apache-camel/src/main/descriptors/common-bin.xml | 1 +
components/camel-kubernetes/pom.xml | 4 ++--
components/pom.xml | 1 +
parent/pom.xml | 7 +++++++
5 files changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/03d64843/apache-camel/pom.xml
----------------------------------------------------------------------
diff --git a/apache-camel/pom.xml b/apache-camel/pom.xml
index c7d8632..11660fe 100644
--- a/apache-camel/pom.xml
+++ b/apache-camel/pom.xml
@@ -480,6 +480,10 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-kubernetes</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-kura</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/camel/blob/03d64843/apache-camel/src/main/descriptors/common-bin.xml
----------------------------------------------------------------------
diff --git a/apache-camel/src/main/descriptors/common-bin.xml b/apache-camel/src/main/descriptors/common-bin.xml
index 3b7aa4b..205ceb3 100644
--- a/apache-camel/src/main/descriptors/common-bin.xml
+++ b/apache-camel/src/main/descriptors/common-bin.xml
@@ -132,6 +132,7 @@
<include>org.apache.camel:camel-kestrel</include>
<include>org.apache.camel:camel-krati</include>
<include>org.apache.camel:camel-kura</include>
+ <include>org.apache.camel:camel-kubernetes</include>
<include>org.apache.camel:camel-ldap</include>
<include>org.apache.camel:camel-leveldb</include>
<include>org.apache.camel:camel-linkedin-api</include>
http://git-wip-us.apache.org/repos/asf/camel/blob/03d64843/components/camel-kubernetes/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/pom.xml b/components/camel-kubernetes/pom.xml
index cc70793..681f67f 100644
--- a/components/camel-kubernetes/pom.xml
+++ b/components/camel-kubernetes/pom.xml
@@ -36,12 +36,12 @@
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
- <version>1.3.52</version>
+ <version>${kubernetes-client-version}</version>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>openshift-client</artifactId>
- <version>1.3.52</version>
+ <version>${openshift-client-version}</version>
</dependency>
<!-- testing -->
<dependency>
http://git-wip-us.apache.org/repos/asf/camel/blob/03d64843/components/pom.xml
----------------------------------------------------------------------
diff --git a/components/pom.xml b/components/pom.xml
index 43159d6..8c0f342 100644
--- a/components/pom.xml
+++ b/components/pom.xml
@@ -152,6 +152,7 @@
<module>camel-kafka</module>
<module>camel-kestrel</module>
<module>camel-krati</module>
+ <module>camel-kubernetes</module>
<module>camel-kura</module>
<module>camel-ldap</module>
<module>camel-leveldb</module>
http://git-wip-us.apache.org/repos/asf/camel/blob/03d64843/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 02a3ec7..d317b6d 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -324,6 +324,7 @@
<karaf3-version>3.0.2</karaf3-version>
<kie-version>6.3.0.Final</kie-version>
<krati-version>0.4.9</krati-version>
+ <kubernetes-client-version>1.3.52</kubernetes-client-version>
<kxml2-bundle-version>2.3.0_2</kxml2-bundle-version>
<leveldbjni-version>1.8</leveldbjni-version>
<!-- virtual dependency only used by Eclipse m2e -->
@@ -391,6 +392,7 @@
<openejb-version>4.7.2</openejb-version>
<openjpa-version>2.4.0</openjpa-version>
<openshift-java-client-version>2.7.0.Final</openshift-java-client-version>
+ <openshift-client-version>1.3.52</openshift-client-version>
<optaplanner-version>6.3.0.Final</optaplanner-version>
<oro-bundle-version>2.0.8_6</oro-bundle-version>
<oscache-bundle-version>2.4_5</oscache-bundle-version>
@@ -1170,6 +1172,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-kubernetes</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-lucene</artifactId>
<version>${project.version}</version>
</dependency>
[4/7] camel git commit: CAMEL-9085 Create a
Camel-Kubernetes/Openshift v3 Component
Posted by ac...@apache.org.
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/main/resources/META-INF/LICENSE.txt
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/resources/META-INF/LICENSE.txt b/components/camel-kubernetes/src/main/resources/META-INF/LICENSE.txt
new file mode 100644
index 0000000..6b0b127
--- /dev/null
+++ b/components/camel-kubernetes/src/main/resources/META-INF/LICENSE.txt
@@ -0,0 +1,203 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
+
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/main/resources/META-INF/NOTICE.txt
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/resources/META-INF/NOTICE.txt b/components/camel-kubernetes/src/main/resources/META-INF/NOTICE.txt
new file mode 100644
index 0000000..2e215bf
--- /dev/null
+++ b/components/camel-kubernetes/src/main/resources/META-INF/NOTICE.txt
@@ -0,0 +1,11 @@
+ =========================================================================
+ == NOTICE file corresponding to the section 4 d of ==
+ == the Apache License, Version 2.0, ==
+ == in this case for the Apache Camel distribution. ==
+ =========================================================================
+
+ This product includes software developed by
+ The Apache Software Foundation (http://www.apache.org/).
+
+ Please read the different LICENSE files present in the licenses directory of
+ this distribution.
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/main/resources/META-INF/services/org/apache/camel/component/kubernetes
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/resources/META-INF/services/org/apache/camel/component/kubernetes b/components/camel-kubernetes/src/main/resources/META-INF/services/org/apache/camel/component/kubernetes
new file mode 100644
index 0000000..4d2f23e
--- /dev/null
+++ b/components/camel-kubernetes/src/main/resources/META-INF/services/org/apache/camel/component/kubernetes
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.component.kubernetes.KubernetesComponent
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/KubernetesTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/KubernetesTestSupport.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/KubernetesTestSupport.java
new file mode 100644
index 0000000..79ed5e8
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/KubernetesTestSupport.java
@@ -0,0 +1,38 @@
+/**
+ * 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;
+
+import org.apache.camel.test.junit4.CamelTestSupport;
+
+public class KubernetesTestSupport extends CamelTestSupport{
+
+ protected String authToken;
+ protected String host;
+
+ // The Camel-Kubernetes tests are based on vagrant fabric8-image
+ // https://github.com/fabric8io/fabric8-installer/tree/master/vagrant/openshift
+ // by running the vagrant image you'll have an environment with
+ // Openshift/Kubernetes installed
+
+ @Override
+ public void setUp() throws Exception {
+ // INSERT credentials and host here
+ authToken = "";
+ host = "https://172.28.128.4:8443";
+ super.setUp();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/KubernetesPodsConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/KubernetesPodsConsumerTest.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/KubernetesPodsConsumerTest.java
new file mode 100644
index 0000000..08d1929
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/KubernetesPodsConsumerTest.java
@@ -0,0 +1,158 @@
+/**
+ * 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.consumer;
+
+import io.fabric8.kubernetes.api.model.Container;
+import io.fabric8.kubernetes.api.model.ContainerPort;
+import io.fabric8.kubernetes.api.model.Pod;
+import io.fabric8.kubernetes.api.model.PodSpec;
+import io.fabric8.kubernetes.client.Config;
+import io.fabric8.kubernetes.client.ConfigBuilder;
+import io.fabric8.kubernetes.client.DefaultKubernetesClient;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesTestSupport;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Test;
+
+public class KubernetesPodsConsumerTest extends KubernetesTestSupport {
+
+ @EndpointInject(uri = "mock:result")
+ protected MockEndpoint mockResultEndpoint;
+
+
+ @Test
+ public void createAndDeletePod() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+
+ mockResultEndpoint.expectedMessageCount(3);
+ mockResultEndpoint.expectedHeaderValuesReceivedInAnyOrder(KubernetesConstants.KUBERNETES_EVENT_ACTION, "ADDED", "MODIFIED", "DELETED");
+ Exchange ex = template.request("direct:createPod", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_POD_NAME, "test");
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("this", "rocks");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_PODS_LABELS, labels);
+ PodSpec podSpec = new PodSpec();
+ podSpec.setHost("172.28.128.4");
+ Container cont = new Container();
+ cont.setImage("docker.io/jboss/wildfly:latest");
+ cont.setName("pippo");
+
+ List<ContainerPort> containerPort = new ArrayList<ContainerPort>();
+ ContainerPort port = new ContainerPort();
+ port.setHostIP("0.0.0.0");
+ port.setHostPort(8080);
+ port.setContainerPort(8080);
+
+ containerPort.add(port);
+
+ cont.setPorts(containerPort);
+
+ List<Container> list = new ArrayList<Container>();
+ list.add(cont);
+
+ podSpec.setContainers(list);
+
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_POD_SPEC, podSpec);
+ }
+ });
+
+ Pod pod = ex.getOut().getBody(Pod.class);
+
+ assertEquals(pod.getMetadata().getName(), "test");
+
+ ex = template.request("direct:deletePod", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_POD_NAME, "test");
+ }
+ });
+
+ boolean podDeleted = ex.getOut().getBody(Boolean.class);
+
+ assertTrue(podDeleted);
+
+ Thread.sleep(1*1000);
+
+ mockResultEndpoint.assertIsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:list")
+ .toF("kubernetes://%s?oauthToken=%s&category=pods&operation=listPods",
+ host, authToken);
+ from("direct:listByLabels")
+ .toF("kubernetes://%s?oauthToken=%s&category=pods&operation=listPodsByLabels",
+ host, authToken);
+ from("direct:getPod")
+ .toF("kubernetes://%s?oauthToken=%s&category=pods&operation=getPod",
+ host, authToken);
+ from("direct:createPod")
+ .toF("kubernetes://%s?oauthToken=%s&category=pods&operation=createPod",
+ host, authToken);
+ from("direct:deletePod")
+ .toF("kubernetes://%s?oauthToken=%s&category=pods&operation=deletePod",
+ host, authToken);
+ fromF("kubernetes://%s?oauthToken=%s&category=pods", host, authToken)
+ .process(new KubernertesProcessor())
+ .to(mockResultEndpoint);
+ }
+ };
+ }
+
+ public class KubernertesProcessor implements Processor {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ Message in = exchange.getIn();
+ log.info("Got event with body: " + in.getBody() + " and action " + in.getHeader(KubernetesConstants.KUBERNETES_EVENT_ACTION));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/KubernetesReplicationControllersConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/KubernetesReplicationControllersConsumerTest.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/KubernetesReplicationControllersConsumerTest.java
new file mode 100644
index 0000000..e9df6dc
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/KubernetesReplicationControllersConsumerTest.java
@@ -0,0 +1,165 @@
+/**
+ * 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.consumer;
+
+import io.fabric8.kubernetes.api.model.EditablePodTemplateSpec;
+import io.fabric8.kubernetes.api.model.IntOrString;
+import io.fabric8.kubernetes.api.model.PodTemplateSpecBuilder;
+import io.fabric8.kubernetes.api.model.ReplicationController;
+import io.fabric8.kubernetes.api.model.ReplicationControllerSpec;
+import io.fabric8.kubernetes.api.model.Service;
+import io.fabric8.kubernetes.api.model.ServicePort;
+import io.fabric8.kubernetes.api.model.ServiceSpec;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesTestSupport;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Test;
+
+public class KubernetesReplicationControllersConsumerTest extends
+ KubernetesTestSupport {
+
+ @EndpointInject(uri = "mock:result")
+ protected MockEndpoint mockResultEndpoint;
+
+ @Test
+ public void createAndDeleteReplicationController() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+
+ mockResultEndpoint
+ .expectedHeaderValuesReceivedInAnyOrder(
+ KubernetesConstants.KUBERNETES_EVENT_ACTION, "ADDED",
+ "DELETED", "MODIFIED", "MODIFIED", "MODIFIED");
+ Exchange ex = template.request("direct:createReplicationController",
+ new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn()
+ .setHeader(
+ KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_NAME,
+ "test");
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("this", "rocks");
+ exchange.getIn()
+ .setHeader(
+ KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLERS_LABELS,
+ labels);
+ ReplicationControllerSpec rcSpec = new ReplicationControllerSpec();
+ rcSpec.setReplicas(2);
+ PodTemplateSpecBuilder builder = new PodTemplateSpecBuilder();
+ EditablePodTemplateSpec t = builder.withNewMetadata()
+ .withName("nginx-template")
+ .addToLabels("server", "nginx").endMetadata()
+ .withNewSpec().addNewContainer()
+ .withName("wildfly").withImage("jboss/wildfly")
+ .addNewPort().withContainerPort(80).endPort()
+ .endContainer().endSpec().build();
+ rcSpec.setTemplate(t);
+ Map<String, String> selectorMap = new HashMap<String, String>();
+ selectorMap.put("server", "nginx");
+ rcSpec.setSelector(selectorMap);
+ exchange.getIn()
+ .setHeader(
+ KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_SPEC,
+ rcSpec);
+ }
+ });
+
+ ReplicationController rc = ex.getOut().getBody(
+ ReplicationController.class);
+
+ assertEquals(rc.getMetadata().getName(), "test");
+
+ ex = template.request("direct:deleteReplicationController",
+ new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn()
+ .setHeader(
+ KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_NAME,
+ "test");
+ }
+ });
+
+ boolean rcDeleted = ex.getOut().getBody(Boolean.class);
+
+ assertTrue(rcDeleted);
+
+ Thread.sleep(1 * 1000);
+
+ mockResultEndpoint.assertIsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:list")
+ .toF("kubernetes://%s?oauthToken=%s&category=replicationControllers&operation=listReplicationControllers",
+ host, authToken);
+ from("direct:listByLabels")
+ .toF("kubernetes://%s?oauthToken=%s&category=replicationControllers&operation=listReplicationControllersByLabels",
+ host, authToken);
+ from("direct:getReplicationController")
+ .toF("kubernetes://%s?oauthToken=%s&category=replicationControllers&operation=getReplicationController",
+ host, authToken);
+ from("direct:createReplicationController")
+ .toF("kubernetes://%s?oauthToken=%s&category=replicationControllers&operation=createReplicationController",
+ host, authToken);
+ from("direct:deleteReplicationController")
+ .toF("kubernetes://%s?oauthToken=%s&category=replicationControllers&operation=deleteReplicationController",
+ host, authToken);
+ fromF(
+ "kubernetes://%s?oauthToken=%s&category=replicationControllers",
+ host, authToken).process(new KubernertesProcessor())
+ .to(mockResultEndpoint);
+ }
+ };
+ }
+
+ public class KubernertesProcessor implements Processor {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ Message in = exchange.getIn();
+ log.info("Got event with body: " + in.getBody() + " and action "
+ + in.getHeader(KubernetesConstants.KUBERNETES_EVENT_ACTION));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/KubernetesSecretsConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/KubernetesSecretsConsumerTest.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/KubernetesSecretsConsumerTest.java
new file mode 100644
index 0000000..e19ce67
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/KubernetesSecretsConsumerTest.java
@@ -0,0 +1,141 @@
+/**
+ * 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.consumer;
+
+import io.fabric8.kubernetes.api.model.ObjectMeta;
+import io.fabric8.kubernetes.api.model.Secret;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesTestSupport;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Test;
+
+import com.ning.http.util.Base64;
+
+public class KubernetesSecretsConsumerTest extends KubernetesTestSupport {
+
+ @EndpointInject(uri = "mock:result")
+ protected MockEndpoint mockResultEndpoint;
+
+ @Test
+ public void createAndDeleteSecrets() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+
+ mockResultEndpoint.expectedHeaderValuesReceivedInAnyOrder(
+ KubernetesConstants.KUBERNETES_EVENT_ACTION, "ADDED",
+ "DELETED");
+ Exchange ex = template.request("direct:create", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SECRET_NAME, "test");
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("this", "rocks");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SECRETS_LABELS, labels);
+ Secret s = new Secret();
+ s.setKind("Secret");
+ Map<String, String> mp = new HashMap<String, String>();
+ mp.put("username", Base64.encode("pippo".getBytes()));
+ mp.put("password", Base64.encode("password".getBytes()));
+ s.setData(mp);
+
+ ObjectMeta meta = new ObjectMeta();
+ meta.setName("test");
+ s.setMetadata(meta);
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SECRET, s);
+ }
+ });
+
+ Secret sec = ex.getOut().getBody(Secret.class);
+
+ assertEquals(sec.getMetadata().getName(), "test");
+
+ ex = template.request("direct:delete", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SECRET_NAME, "test");
+ }
+ });
+
+ boolean secDeleted = ex.getOut().getBody(Boolean.class);
+
+ assertTrue(secDeleted);
+
+ Thread.sleep(1 * 1000);
+
+ mockResultEndpoint.assertIsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:list")
+ .toF("kubernetes://%s?oauthToken=%s&category=secrets&operation=listSecrets",
+ host, authToken);
+ from("direct:listByLabels")
+ .toF("kubernetes://%s?oauthToken=%s&category=secrets&operation=listSecretsByLabels",
+ host, authToken);
+ from("direct:get")
+ .toF("kubernetes://%s?oauthToken=%s&category=secrets&operation=getSecret",
+ host, authToken);
+ from("direct:create")
+ .toF("kubernetes://%s?oauthToken=%s&category=secrets&operation=createSecret",
+ host, authToken);
+ from("direct:delete")
+ .toF("kubernetes://%s?oauthToken=%s&category=secrets&operation=deleteSecret",
+ host, authToken);
+ fromF("kubernetes://%s?oauthToken=%s&category=secrets", host,
+ authToken).process(new KubernertesProcessor()).to(
+ mockResultEndpoint);
+ }
+ };
+ }
+
+ public class KubernertesProcessor implements Processor {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ Message in = exchange.getIn();
+ log.info("Got event with body: " + in.getBody() + " and action "
+ + in.getHeader(KubernetesConstants.KUBERNETES_EVENT_ACTION));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/KubernetesServicesConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/KubernetesServicesConsumerTest.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/KubernetesServicesConsumerTest.java
new file mode 100644
index 0000000..098069e
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/KubernetesServicesConsumerTest.java
@@ -0,0 +1,145 @@
+/**
+ * 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.consumer;
+
+import io.fabric8.kubernetes.api.model.IntOrString;
+import io.fabric8.kubernetes.api.model.Service;
+import io.fabric8.kubernetes.api.model.ServicePort;
+import io.fabric8.kubernetes.api.model.ServiceSpec;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesTestSupport;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Test;
+
+public class KubernetesServicesConsumerTest extends KubernetesTestSupport {
+
+ @EndpointInject(uri = "mock:result")
+ protected MockEndpoint mockResultEndpoint;
+
+ @Test
+ public void createAndDeleteService() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+
+ mockResultEndpoint.expectedMessageCount(2);
+ mockResultEndpoint.expectedHeaderValuesReceivedInAnyOrder(KubernetesConstants.KUBERNETES_EVENT_ACTION, "ADDED", "DELETED");
+ Exchange ex = template.request("direct:createService", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_NAME, "test");
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("this", "rocks");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_LABELS, labels);
+ ServiceSpec serviceSpec = new ServiceSpec();
+ List<ServicePort> lsp = new ArrayList<ServicePort>();
+ ServicePort sp = new ServicePort();
+ sp.setPort(8080);
+ sp.setTargetPort(new IntOrString(8080));
+ sp.setProtocol("TCP");
+ lsp.add(sp);
+ serviceSpec.setPorts(lsp);
+ Map<String, String> selectorMap = new HashMap<String, String>();
+ selectorMap.put("containter", "test");
+ serviceSpec.setSelector(selectorMap);
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_SPEC,
+ serviceSpec);
+ }
+ });
+
+ Service serv = ex.getOut().getBody(Service.class);
+
+ assertEquals(serv.getMetadata().getName(), "test");
+
+ ex = template.request("direct:deleteService", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_SERVICE_NAME, "test");
+ }
+ });
+
+ boolean servDeleted = ex.getOut().getBody(Boolean.class);
+
+ assertTrue(servDeleted);
+
+ Thread.sleep(1*1000);
+
+ mockResultEndpoint.assertIsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:list")
+ .toF("kubernetes://%s?oauthToken=%s&category=services&operation=listServices",
+ host, authToken);
+ from("direct:listByLabels")
+ .toF("kubernetes://%s?oauthToken=%s&category=services&operation=listServicesByLabels",
+ host, authToken);
+ from("direct:getServices")
+ .toF("kubernetes://%s?oauthToken=%s&category=services&operation=getService",
+ host, authToken);
+ from("direct:createService")
+ .toF("kubernetes://%s?oauthToken=%s&category=services&operation=createService",
+ host, authToken);
+ from("direct:deleteService")
+ .toF("kubernetes://%s?oauthToken=%s&category=services&operation=deleteService",
+ host, authToken);
+ fromF("kubernetes://%s?oauthToken=%s&category=services",
+ host, authToken)
+ .process(new KubernertesProcessor())
+ .to(mockResultEndpoint);
+ }
+ };
+ }
+
+ public class KubernertesProcessor implements Processor {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ Message in = exchange.getIn();
+ log.info("Got event with body: " + in.getBody() + " and action "
+ + in.getHeader(KubernetesConstants.KUBERNETES_EVENT_ACTION));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesBuildConfigsProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesBuildConfigsProducerTest.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesBuildConfigsProducerTest.java
new file mode 100644
index 0000000..ab0e907
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesBuildConfigsProducerTest.java
@@ -0,0 +1,86 @@
+/**
+ * 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.List;
+import java.util.Map;
+
+import io.fabric8.openshift.api.model.BuildConfig;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Test;
+
+public class KubernetesBuildConfigsProducerTest extends KubernetesTestSupport {
+
+ @Test
+ public void listTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ List<BuildConfig> result = template.requestBody("direct:list", "",
+ List.class);
+
+ assertTrue(result.size() == 0);
+ }
+
+ @Test
+ public void listByLabelsTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ Exchange ex = template.request("direct:listByLabels", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("component", "elasticsearch");
+ exchange.getIn()
+ .setHeader(
+ KubernetesConstants.KUBERNETES_BUILD_CONFIGS_LABELS,
+ labels);
+ }
+ });
+
+ List<BuildConfig> result = ex.getOut().getBody(List.class);
+
+ assertTrue(result.size() == 0);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:list")
+ .toF("kubernetes://%s?oauthToken=%s&category=buildConfigs&operation=listBuildConfigs",
+ host, authToken);
+ from("direct:listByLabels")
+ .toF("kubernetes://%s?oauthToken=%s&category=buildConfigs&operation=listBuildConfigsByLabels",
+ host, authToken);
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesBuildsProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesBuildsProducerTest.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesBuildsProducerTest.java
new file mode 100644
index 0000000..5e68906
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesBuildsProducerTest.java
@@ -0,0 +1,89 @@
+/**
+ * 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.List;
+import java.util.Map;
+
+import io.fabric8.kubernetes.api.model.PersistentVolume;
+import io.fabric8.openshift.api.model.Build;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesTestSupport;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class KubernetesBuildsProducerTest extends KubernetesTestSupport {
+
+ @Test
+ public void listTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ List<Build> result = template.requestBody("direct:list", "",
+ List.class);
+
+ assertTrue(result.size() == 0);
+ }
+
+ @Test
+ public void listByLabelsTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ Exchange ex = template.request("direct:listByLabels", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("component", "elasticsearch");
+ exchange.getIn()
+ .setHeader(
+ KubernetesConstants.KUBERNETES_BUILDS_LABELS,
+ labels);
+ }
+ });
+
+ List<Build> result = ex.getOut().getBody(List.class);
+
+ assertTrue(result.size() == 0);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:list")
+ .toF("kubernetes://%s?oauthToken=%s&category=builds&operation=listBuilds",
+ host, authToken);
+ from("direct:listByLabels")
+ .toF("kubernetes://%s?oauthToken=%s&category=builds&operation=listBuildsByLabels",
+ host, authToken);
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesNamespacesProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesNamespacesProducerTest.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesNamespacesProducerTest.java
new file mode 100644
index 0000000..21e84d1
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesNamespacesProducerTest.java
@@ -0,0 +1,210 @@
+/**
+ * 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.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import io.fabric8.kubernetes.api.model.Namespace;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesTestSupport;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Test;
+
+public class KubernetesNamespacesProducerTest extends KubernetesTestSupport {
+
+ @Test
+ public void listTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ List<Namespace> result = template.requestBody("direct:list", "",
+ List.class);
+
+ boolean defaultExists = false;
+
+ Iterator<Namespace> it = result.iterator();
+ while (it.hasNext()) {
+ Namespace namespace = (Namespace) it.next();
+ if ("default".equalsIgnoreCase(namespace.getMetadata().getName())) {
+ defaultExists = true;
+ }
+ }
+
+ assertTrue(defaultExists);
+ }
+
+ @Test
+ public void getNamespace() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ Exchange ex = template.request("direct:getNs", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ }
+ });
+
+ Namespace ns = ex.getOut().getBody(Namespace.class);
+
+ assertEquals(ns.getMetadata().getName(), "default");
+
+ }
+
+ @Test
+ public void createAndDeleteNamespace() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ Exchange ex = template.request("direct:createNamespace",
+ new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "test");
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("this", "rocks");
+ exchange.getIn()
+ .setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_LABELS,
+ labels);
+ }
+ });
+
+ Namespace ns = ex.getOut().getBody(Namespace.class);
+
+ assertEquals(ns.getMetadata().getName(), "test");
+
+
+ ex = template.request("direct:deleteNamespace", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "test");
+ }
+ });
+
+ boolean nsDeleted = ex.getOut().getBody(Boolean.class);
+
+ assertTrue(nsDeleted);
+ }
+
+ @Test
+ public void createListByLabelsAndDeleteNamespace() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ Exchange ex = template.request("direct:createNamespace",
+ new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "test");
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("this", "rocks");
+ exchange.getIn()
+ .setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_LABELS,
+ labels);
+ }
+ });
+
+ Namespace ns = ex.getOut().getBody(Namespace.class);
+
+ assertEquals(ns.getMetadata().getName(), "test");
+
+ ex = template.request("direct:listByLabels", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("this", "rocks");
+ exchange.getIn()
+ .setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_LABELS,
+ labels);
+ }
+ });
+
+ List<Namespace> result = ex.getOut().getBody(List.class);
+
+ boolean testExists = false;
+
+ Iterator<Namespace> it = result.iterator();
+ while (it.hasNext()) {
+ Namespace namespace = (Namespace) it.next();
+ if ("test".equalsIgnoreCase(namespace.getMetadata().getName())) {
+ testExists = true;
+ }
+ }
+
+ assertTrue(testExists);
+
+ ex = template.request("direct:deleteNamespace", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "test");
+ }
+ });
+
+ boolean nsDeleted = ex.getOut().getBody(Boolean.class);
+
+ assertTrue(nsDeleted);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:list")
+ .toF("kubernetes://%s?oauthToken=%s&category=namespaces&operation=listNamespaces",
+ host, authToken);
+ from("direct:listByLabels")
+ .toF("kubernetes://%s?oauthToken=%s&category=namespaces&operation=listNamespacesByLabels",
+ host, authToken);
+ from("direct:getNs")
+ .toF("kubernetes://%s?oauthToken=%s&category=namespaces&operation=getNamespace",
+ host, authToken);
+ from("direct:createNamespace")
+ .toF("kubernetes://%s?oauthToken=%s&category=namespaces&operation=createNamespace",
+ host, authToken);
+ from("direct:deleteNamespace")
+ .toF("kubernetes://%s?oauthToken=%s&category=namespaces&operation=deleteNamespace",
+ host, authToken);
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesNodesProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesNodesProducerTest.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesNodesProducerTest.java
new file mode 100644
index 0000000..6d12321
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesNodesProducerTest.java
@@ -0,0 +1,89 @@
+/**
+ * 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.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import io.fabric8.kubernetes.api.model.Node;
+import io.fabric8.kubernetes.api.model.PersistentVolume;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesTestSupport;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class KubernetesNodesProducerTest extends KubernetesTestSupport {
+
+ @Test
+ public void listTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ List<Node> result = template.requestBody("direct:list", "",
+ List.class);
+
+ assertTrue(result.size() == 1);
+ }
+
+ @Test
+ public void listByLabelsTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ Exchange ex = template.request("direct:listByLabels", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("kubernetes.io/hostname", "172.28.128.4");
+ exchange.getIn()
+ .setHeader(
+ KubernetesConstants.KUBERNETES_NODES_LABELS,
+ labels);
+ }
+ });
+
+ List<Node> result = ex.getOut().getBody(List.class);
+
+ Node node = result.get(0);
+
+ assertTrue(node.getStatus().getCapacity().get("pods").getAmount().equals("40"));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:list")
+ .toF("kubernetes://%s?oauthToken=%s&category=nodes&operation=listNodes",
+ host, authToken);
+ from("direct:listByLabels")
+ .toF("kubernetes://%s?oauthToken=%s&category=nodes&operation=listNodesByLabels",
+ host, authToken);
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesPersistentVolumesClaimsProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesPersistentVolumesClaimsProducerTest.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesPersistentVolumesClaimsProducerTest.java
new file mode 100644
index 0000000..cc6a4e8
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesPersistentVolumesClaimsProducerTest.java
@@ -0,0 +1,191 @@
+/**
+ * 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.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import io.fabric8.kubernetes.api.model.PersistentVolume;
+import io.fabric8.kubernetes.api.model.PersistentVolumeClaim;
+import io.fabric8.kubernetes.api.model.PersistentVolumeClaimSpec;
+import io.fabric8.kubernetes.api.model.Quantity;
+import io.fabric8.kubernetes.api.model.ResourceRequirements;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesTestSupport;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Test;
+
+public class KubernetesPersistentVolumesClaimsProducerTest extends
+ KubernetesTestSupport {
+
+ @Test
+ public void listTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ List<PersistentVolumeClaim> result = template.requestBody(
+ "direct:list", "", List.class);
+
+ assertTrue(result.size() == 0);
+ }
+
+ @Test
+ public void listByLabelsTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ Exchange ex = template.request("direct:listByLabels", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("component", "elasticsearch");
+ exchange.getIn()
+ .setHeader(
+ KubernetesConstants.KUBERNETES_PERSISTENT_VOLUMES_CLAIMS_LABELS,
+ labels);
+ }
+ });
+
+ List<PersistentVolume> result = ex.getOut().getBody(List.class);
+ }
+
+ @Test
+ public void createListAndDeletePersistentVolumeClaim() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ Exchange ex = template.request("direct:create", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn()
+ .setHeader(
+ KubernetesConstants.KUBERNETES_PERSISTENT_VOLUME_CLAIM_NAME,
+ "test");
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("this", "rocks");
+ exchange.getIn()
+ .setHeader(
+ KubernetesConstants.KUBERNETES_PERSISTENT_VOLUMES_CLAIMS_LABELS,
+ labels);
+ PersistentVolumeClaimSpec pvcSpec = new PersistentVolumeClaimSpec();
+ ResourceRequirements rr = new ResourceRequirements();
+ Map<String, Quantity> mp = new HashMap<String, Quantity>();
+ mp.put("storage", new Quantity("100"));
+ rr.setLimits(mp);
+ Map<String, Quantity> req = new HashMap<String, Quantity>();
+ req.put("storage", new Quantity("100"));
+ rr.setRequests(req);
+ pvcSpec.setResources(rr);
+ pvcSpec.setVolumeName("vol001");
+ List<String> access = new ArrayList<String>();
+ access.add("ReadWriteOnce");
+ pvcSpec.setAccessModes(access);
+ exchange.getIn()
+ .setHeader(
+ KubernetesConstants.KUBERNETES_PERSISTENT_VOLUME_CLAIM_SPEC,
+ pvcSpec);
+ }
+ });
+
+ PersistentVolumeClaim pvc = ex.getOut().getBody(
+ PersistentVolumeClaim.class);
+
+ assertEquals(pvc.getMetadata().getName(), "test");
+
+ ex = template.request("direct:listByLabels", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("this", "rocks");
+ exchange.getIn()
+ .setHeader(
+ KubernetesConstants.KUBERNETES_PERSISTENT_VOLUMES_CLAIMS_LABELS,
+ labels);
+ }
+ });
+
+ List<PersistentVolumeClaim> result = ex.getOut().getBody(List.class);
+
+ boolean pvcExists = false;
+ Iterator<PersistentVolumeClaim> it = result.iterator();
+ while (it.hasNext()) {
+ PersistentVolumeClaim pvcLocal = (PersistentVolumeClaim) it.next();
+ if ("test".equalsIgnoreCase(pvcLocal.getMetadata().getName())) {
+ pvcExists = true;
+ }
+ }
+
+ assertTrue(pvcExists);
+
+ ex = template.request("direct:delete", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn()
+ .setHeader(
+ KubernetesConstants.KUBERNETES_PERSISTENT_VOLUME_CLAIM_NAME,
+ "test");
+ }
+ });
+
+ boolean pvcDeleted = ex.getOut().getBody(Boolean.class);
+
+ assertTrue(pvcDeleted);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:list")
+ .toF("kubernetes://%s?oauthToken=%s&category=persistentVolumesClaims&operation=listPersistentVolumesClaims",
+ host, authToken);
+ from("direct:listByLabels")
+ .toF("kubernetes://%s?oauthToken=%s&category=persistentVolumesClaims&operation=listPersistentVolumesClaimsByLabels",
+ host, authToken);
+ from("direct:create")
+ .toF("kubernetes://%s?oauthToken=%s&category=persistentVolumesClaims&operation=createPersistentVolumeClaim",
+ host, authToken);
+ from("direct:delete")
+ .toF("kubernetes://%s?oauthToken=%s&category=persistentVolumesClaims&operation=deletePersistentVolumeClaim",
+ host, authToken);
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesPersistentVolumesProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesPersistentVolumesProducerTest.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesPersistentVolumesProducerTest.java
new file mode 100644
index 0000000..1ffb9a5
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesPersistentVolumesProducerTest.java
@@ -0,0 +1,86 @@
+/**
+ * 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.List;
+import java.util.Map;
+
+import io.fabric8.kubernetes.api.model.PersistentVolume;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesTestSupport;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class KubernetesPersistentVolumesProducerTest extends KubernetesTestSupport {
+
+ @Test
+ public void listTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ List<PersistentVolume> result = template.requestBody("direct:list", "",
+ List.class);
+
+ assertTrue(result.size() == 1);
+ }
+
+ @Test
+ public void listByLabelsTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ Exchange ex = template.request("direct:listByLabels", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("component", "elasticsearch");
+ exchange.getIn()
+ .setHeader(
+ KubernetesConstants.KUBERNETES_PERSISTENT_VOLUMES_LABELS,
+ labels);
+ }
+ });
+
+ List<PersistentVolume> result = ex.getOut().getBody(List.class);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:list")
+ .toF("kubernetes://%s?oauthToken=%s&category=persistentVolumes&operation=listPersistentVolumes",
+ host, authToken);
+ from("direct:listByLabels")
+ .toF("kubernetes://%s?oauthToken=%s&category=persistentVolumes&operation=listPersistentVolumesByLabels",
+ host, authToken);
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a452d0ac/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesPodsProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesPodsProducerTest.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesPodsProducerTest.java
new file mode 100644
index 0000000..fc88dd5
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesPodsProducerTest.java
@@ -0,0 +1,205 @@
+/**
+ * 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.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import io.fabric8.kubernetes.api.model.Container;
+import io.fabric8.kubernetes.api.model.ContainerPort;
+import io.fabric8.kubernetes.api.model.Pod;
+import io.fabric8.kubernetes.api.model.PodSpec;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.KubernetesTestSupport;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Test;
+
+public class KubernetesPodsProducerTest extends KubernetesTestSupport {
+
+ @Test
+ public void listTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ List<Pod> result = template.requestBody("direct:list", "", List.class);
+
+ boolean defaultExists = false;
+
+ Iterator<Pod> it = result.iterator();
+ while (it.hasNext()) {
+ Pod pod = (Pod) it.next();
+ if ((pod.getMetadata().getName()).contains("fabric8")) {
+ defaultExists = true;
+ }
+ }
+
+ assertTrue(defaultExists);
+ }
+
+ @Test
+ public void listByLabelsTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ Exchange ex = template.request("direct:listByLabels", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("component", "elasticsearch");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_PODS_LABELS, labels);
+ }
+ });
+
+ List<Pod> result = ex.getOut().getBody(List.class);
+
+ boolean podExists = false;
+ Iterator<Pod> it = result.iterator();
+ while (it.hasNext()) {
+ Pod pod = (Pod) it.next();
+ if (pod.getMetadata().getLabels().containsValue("elasticsearch")) {
+ podExists = true;
+ }
+ }
+
+ assertFalse(podExists);
+ }
+
+ @Test
+ public void getPodTest() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ Exchange ex = template.request("direct:getPod", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_POD_NAME,
+ "elasticsearch-7015o");
+ }
+ });
+
+ Pod result = ex.getOut().getBody(Pod.class);
+
+ assertNull(result);
+ }
+
+ @Test
+ public void createAndDeletePod() throws Exception {
+ if (ObjectHelper.isEmpty(authToken)) {
+ return;
+ }
+ Exchange ex = template.request("direct:createPod", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_POD_NAME, "test");
+ Map<String, String> labels = new HashMap<String, String>();
+ labels.put("this", "rocks");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_PODS_LABELS, labels);
+ PodSpec podSpec = new PodSpec();
+ podSpec.setHost("172.28.128.4");
+ Container cont = new Container();
+ cont.setImage("docker.io/jboss/wildfly:latest");
+ cont.setName("pippo");
+
+ List<ContainerPort> containerPort = new ArrayList<ContainerPort>();
+ ContainerPort port = new ContainerPort();
+ port.setHostIP("0.0.0.0");
+ port.setHostPort(8080);
+ port.setContainerPort(8080);
+
+ containerPort.add(port);
+
+ cont.setPorts(containerPort);
+
+ List<Container> list = new ArrayList<Container>();
+ list.add(cont);
+
+ podSpec.setContainers(list);
+
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_POD_SPEC, podSpec);
+ }
+ });
+
+ Pod pod = ex.getOut().getBody(Pod.class);
+
+ assertEquals(pod.getMetadata().getName(), "test");
+
+ ex = template.request("direct:deletePod", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_NAMESPACE_NAME,
+ "default");
+ exchange.getIn().setHeader(
+ KubernetesConstants.KUBERNETES_POD_NAME, "test");
+ }
+ });
+
+ boolean podDeleted = ex.getOut().getBody(Boolean.class);
+
+ assertTrue(podDeleted);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:list")
+ .toF("kubernetes://%s?oauthToken=%s&category=pods&operation=listPods",
+ host, authToken);
+ from("direct:listByLabels")
+ .toF("kubernetes://%s?oauthToken=%s&category=pods&operation=listPodsByLabels",
+ host, authToken);
+ from("direct:getPod")
+ .toF("kubernetes://%s?oauthToken=%s&category=pods&operation=getPod",
+ host, authToken);
+ from("direct:createPod")
+ .toF("kubernetes://%s?oauthToken=%s&category=pods&operation=createPod",
+ host, authToken);
+ from("direct:deletePod")
+ .toF("kubernetes://%s?oauthToken=%s&category=pods&operation=deletePod",
+ host, authToken);
+ }
+ };
+ }
+}