[camel] branch master updated (3575d80 -> d846e21)

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[camel] branch master updated (3575d80 -> d846e21)

acosentino
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 3575d80  Upgrade Xchange to version 4.4.0
     new 57fc601  CAMEL-13978 - Create ConfigMap Watch feature in Kubernetes Component
     new 032f4cb  CAMEL-13978 - Create ConfigMap Watch feature in Kubernetes Component, added test
     new e320010  CAMEL-13978 - Docs
     new d846e21  CAMEL-13978 - Fixed CS

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../docs/kubernetes-config-maps-component.adoc     |  2 +-
 .../KubernetesConfigMapsConsumer.java}             | 44 +++++++--------
 .../config_maps/KubernetesConfigMapsEndpoint.java  |  2 +-
 .../common/{PodEvent.java => ConfigMapEvent.java}  | 18 +++----
 ....java => KubernetesConfigMapsConsumerTest.java} | 63 +++++++---------------
 5 files changed, 51 insertions(+), 78 deletions(-)
 copy components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/{nodes/KubernetesNodesConsumer.java => config_maps/KubernetesConfigMapsConsumer.java} (73%)
 copy components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/common/{PodEvent.java => ConfigMapEvent.java} (77%)
 copy components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/{KubernetesPodsConsumerTest.java => KubernetesConfigMapsConsumerTest.java} (56%)

Reply | Threaded
Open this post in threaded view
|

[camel] 01/04: CAMEL-13978 - Create ConfigMap Watch feature in Kubernetes Component

acosentino
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 57fc601efbbd27d70231582dddb277a9bd6eeed6
Author: Andrea Cosentino <[hidden email]>
AuthorDate: Mon Sep 16 08:49:26 2019 +0200

    CAMEL-13978 - Create ConfigMap Watch feature in Kubernetes Component
---
 .../config_maps/KubernetesConfigMapsConsumer.java  | 132 +++++++++++++++++++++
 .../config_maps/KubernetesConfigMapsEndpoint.java  |   2 +-
 .../kubernetes/consumer/common/ConfigMapEvent.java |  47 ++++++++
 3 files changed, 180 insertions(+), 1 deletion(-)

diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/config_maps/KubernetesConfigMapsConsumer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/config_maps/KubernetesConfigMapsConsumer.java
new file mode 100644
index 0000000..bbc489e
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/config_maps/KubernetesConfigMapsConsumer.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.config_maps;
+
+import java.util.concurrent.ExecutorService;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.kubernetes.AbstractKubernetesEndpoint;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.consumer.common.ConfigMapEvent;
+import org.apache.camel.support.DefaultConsumer;
+import org.apache.camel.util.ObjectHelper;
+
+import io.fabric8.kubernetes.api.model.ConfigMap;
+import io.fabric8.kubernetes.api.model.ConfigMapList;
+import io.fabric8.kubernetes.api.model.DoneableConfigMap;
+import io.fabric8.kubernetes.client.KubernetesClientException;
+import io.fabric8.kubernetes.client.Watch;
+import io.fabric8.kubernetes.client.Watcher;
+import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
+import io.fabric8.kubernetes.client.dsl.Resource;
+
+public class KubernetesConfigMapsConsumer extends DefaultConsumer {
+
+    private final Processor processor;
+    private ExecutorService executor;
+    private ConfigMapsConsumerTask configMapWatcher;
+
+    public KubernetesConfigMapsConsumer(AbstractKubernetesEndpoint endpoint, Processor processor) {
+        super(endpoint, processor);
+        this.processor = processor;
+    }
+
+    @Override
+    public AbstractKubernetesEndpoint getEndpoint() {
+        return (AbstractKubernetesEndpoint)super.getEndpoint();
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+        executor = getEndpoint().createExecutor();
+
+        configMapWatcher = new ConfigMapsConsumerTask();
+        executor.submit(configMapWatcher);
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        super.doStop();
+
+        log.debug("Stopping Kubernetes ConfigMap Consumer");
+        if (executor != null) {
+            if (getEndpoint() != null && getEndpoint().getCamelContext() != null) {
+                if (configMapWatcher != null) {
+                    configMapWatcher.getWatch().close();
+                }
+                getEndpoint().getCamelContext().getExecutorServiceManager().shutdownNow(executor);
+            } else {
+                if (configMapWatcher != null) {
+                    configMapWatcher.getWatch().close();
+                }
+                executor.shutdownNow();
+            }
+        }
+        executor = null;
+    }
+
+    class ConfigMapsConsumerTask implements Runnable {
+
+        private Watch watch;
+
+        @Override
+        public void run() {
+            NonNamespaceOperation<ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> w = getEndpoint().getKubernetesClient().configMaps();
+            if (ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration().getLabelKey())
+                && ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration().getLabelValue())) {
+                w.withLabel(getEndpoint().getKubernetesConfiguration().getLabelKey(), getEndpoint().getKubernetesConfiguration().getLabelValue());
+            }
+            if (ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration().getResourceName())) {
+                w.withName(getEndpoint().getKubernetesConfiguration().getResourceName());
+            }
+            watch = w.watch(new Watcher<ConfigMap>() {
+
+                @Override
+                public void eventReceived(io.fabric8.kubernetes.client.Watcher.Action action, ConfigMap resource) {
+                    ConfigMapEvent de = new ConfigMapEvent(action, resource);
+                    Exchange exchange = getEndpoint().createExchange();
+                    exchange.getIn().setBody(de.getConfigMap());
+                    exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_EVENT_ACTION, de.getAction());
+                    exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_EVENT_TIMESTAMP, System.currentTimeMillis());
+                    try {
+                        processor.process(exchange);
+                    } catch (Exception e) {
+                        getExceptionHandler().handleException("Error during processing", exchange, e);
+                    }
+                }
+
+                @Override
+                public void onClose(KubernetesClientException cause) {
+                    if (cause != null) {
+                        log.error(cause.getMessage(), cause);
+                    }
+
+                }
+            });
+        }
+
+        public Watch getWatch() {
+            return watch;
+        }
+
+        public void setWatch(Watch watch) {
+            this.watch = watch;
+        }
+    }
+}
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/config_maps/KubernetesConfigMapsEndpoint.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/config_maps/KubernetesConfigMapsEndpoint.java
index 616dbfc..26dc3c9 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/config_maps/KubernetesConfigMapsEndpoint.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/config_maps/KubernetesConfigMapsEndpoint.java
@@ -43,7 +43,7 @@ public class KubernetesConfigMapsEndpoint extends AbstractKubernetesEndpoint {
 
     @Override
     public Consumer createConsumer(Processor processor) throws Exception {
-        throw new IllegalArgumentException("The kubernetes-configmaps doesn't support consumer");
+        return new KubernetesConfigMapsConsumer(this, processor);
     }
 
 }
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/common/ConfigMapEvent.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/common/ConfigMapEvent.java
new file mode 100644
index 0000000..d225219
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/common/ConfigMapEvent.java
@@ -0,0 +1,47 @@
+/*
+ * 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.common;
+
+import io.fabric8.kubernetes.api.model.ConfigMap;
+import io.fabric8.kubernetes.client.Watcher.Action;
+
+public class ConfigMapEvent {
+    private io.fabric8.kubernetes.client.Watcher.Action action;
+
+    private ConfigMap configMap;
+
+    public ConfigMapEvent(Action action, ConfigMap configMap) {
+        this.action = action;
+        this.configMap = configMap;
+    }
+
+    public io.fabric8.kubernetes.client.Watcher.Action getAction() {
+        return action;
+    }
+
+    public void setAction(io.fabric8.kubernetes.client.Watcher.Action action) {
+        this.action = action;
+    }
+
+    public ConfigMap getConfigMap() {
+        return configMap;
+    }
+
+    public void setConfigMap(ConfigMap configMap) {
+        this.configMap = configMap;
+    }
+}

Reply | Threaded
Open this post in threaded view
|

[camel] 02/04: CAMEL-13978 - Create ConfigMap Watch feature in Kubernetes Component, added test

acosentino
In reply to this post by acosentino
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 032f4cb337f48a3c7e739accfaeab992ef767e19
Author: Andrea Cosentino <[hidden email]>
AuthorDate: Mon Sep 16 08:48:32 2019 +0200

    CAMEL-13978 - Create ConfigMap Watch feature in Kubernetes Component, added test
---
 .../consumer/KubernetesConfigMapsConsumerTest.java | 104 +++++++++++++++++++++
 1 file changed, 104 insertions(+)

diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/KubernetesConfigMapsConsumerTest.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/KubernetesConfigMapsConsumerTest.java
new file mode 100644
index 0000000..3bd59af
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/KubernetesConfigMapsConsumerTest.java
@@ -0,0 +1,104 @@
+/*
+ * 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 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.util.ObjectHelper;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import io.fabric8.kubernetes.api.model.ConfigMap;
+
+@Ignore("Requires a running Kubernetes Cluster")
+public class KubernetesConfigMapsConsumerTest extends KubernetesTestSupport {
+
+    @EndpointInject("mock:result")
+    protected MockEndpoint mockResultEndpoint;
+
+    @Test
+    public void createAndDeleteConfigMap() throws Exception {
+        if (ObjectHelper.isEmpty(authToken)) {
+            return;
+        }
+
+        mockResultEndpoint.expectedMessageCount(3);
+        mockResultEndpoint.expectedHeaderValuesReceivedInAnyOrder(KubernetesConstants.KUBERNETES_EVENT_ACTION, "ADDED", "MODIFIED", "MODIFIED");
+        Exchange ex = template.request("direct:createConfigmap", new Processor() {
+
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
+                exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_CONFIGMAP_NAME, "test");
+                Map<String, String> labels = new HashMap<>();
+                labels.put("this", "rocks");
+                exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_CONFIGMAPS_LABELS, labels);
+                HashMap<String, String> configMapData = new HashMap<>();
+                configMapData.put("test", "test");
+                exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_CONFIGMAP_DATA, configMapData);
+            }
+        });
+
+        ex = template.request("direct:deleteConfigmap", new Processor() {
+
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
+                exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_CONFIGMAP_NAME, "test");
+            }
+        });
+
+        boolean cmDeleted = ex.getOut().getBody(Boolean.class);
+
+        assertTrue(cmDeleted);
+
+        Thread.sleep(3000);
+
+        mockResultEndpoint.assertIsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:createConfigmap").toF("kubernetes-config-maps://%s?oauthToken=%s&operation=createConfigMap", host, authToken);
+                from("direct:deleteConfigmap").toF("kubernetes-config-maps://%s?oauthToken=%s&operation=deleteConfigMap", host, authToken);
+                fromF("kubernetes-config-maps://%s?oauthToken=%s&namespace=myproject&labelKey=this&labelValue=rocks", host, authToken).process(new KubernertesProcessor())
+                    .to(mockResultEndpoint);
+            }
+        };
+    }
+
+    public class KubernertesProcessor implements Processor {
+        @Override
+        public void process(Exchange exchange) throws Exception {
+            Message in = exchange.getIn();
+            ConfigMap cm = exchange.getIn().getBody(ConfigMap.class);
+            log.info("Got event with configmap name: " + cm.getMetadata().getName() + " and action " + in.getHeader(KubernetesConstants.KUBERNETES_EVENT_ACTION));
+        }
+    }
+}

Reply | Threaded
Open this post in threaded view
|

[camel] 03/04: CAMEL-13978 - Docs

acosentino
In reply to this post by acosentino
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit e320010fbda1fce9c0fc588d4951a22166fc05d5
Author: Andrea Cosentino <[hidden email]>
AuthorDate: Mon Sep 16 08:51:55 2019 +0200

    CAMEL-13978 - Docs
---
 .../src/main/docs/kubernetes-config-maps-component.adoc                 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/components/camel-kubernetes/src/main/docs/kubernetes-config-maps-component.adoc b/components/camel-kubernetes/src/main/docs/kubernetes-config-maps-component.adoc
index 33d1dba..98fe261 100644
--- a/components/camel-kubernetes/src/main/docs/kubernetes-config-maps-component.adoc
+++ b/components/camel-kubernetes/src/main/docs/kubernetes-config-maps-component.adoc
@@ -4,7 +4,7 @@
 *Available as of Camel version 2.17*
 
 The Kubernetes ConfigMap component is one of xref:kubernetes.adoc[Kubernetes Components] which
-provides a producer to execute kubernetes ConfigMap operations.
+provides a producer to execute kubernetes ConfigMap operations and a consumer to consume events related to Config maps.
 
 
 == Component Options

Reply | Threaded
Open this post in threaded view
|

[camel] 04/04: CAMEL-13978 - Fixed CS

acosentino
In reply to this post by acosentino
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit d846e21f34506d17b5004227ef46cf3d81c41ec3
Author: Andrea Cosentino <[hidden email]>
AuthorDate: Mon Sep 16 08:55:46 2019 +0200

    CAMEL-13978 - Fixed CS
---
 .../config_maps/KubernetesConfigMapsConsumer.java        | 16 ++++++++--------
 .../consumer/KubernetesConfigMapsConsumerTest.java       |  4 ++--
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/config_maps/KubernetesConfigMapsConsumer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/config_maps/KubernetesConfigMapsConsumer.java
index bbc489e..f8b4e80 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/config_maps/KubernetesConfigMapsConsumer.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/config_maps/KubernetesConfigMapsConsumer.java
@@ -18,14 +18,6 @@ package org.apache.camel.component.kubernetes.config_maps;
 
 import java.util.concurrent.ExecutorService;
 
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
-import org.apache.camel.component.kubernetes.AbstractKubernetesEndpoint;
-import org.apache.camel.component.kubernetes.KubernetesConstants;
-import org.apache.camel.component.kubernetes.consumer.common.ConfigMapEvent;
-import org.apache.camel.support.DefaultConsumer;
-import org.apache.camel.util.ObjectHelper;
-
 import io.fabric8.kubernetes.api.model.ConfigMap;
 import io.fabric8.kubernetes.api.model.ConfigMapList;
 import io.fabric8.kubernetes.api.model.DoneableConfigMap;
@@ -35,6 +27,14 @@ import io.fabric8.kubernetes.client.Watcher;
 import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
 import io.fabric8.kubernetes.client.dsl.Resource;
 
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.kubernetes.AbstractKubernetesEndpoint;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.component.kubernetes.consumer.common.ConfigMapEvent;
+import org.apache.camel.support.DefaultConsumer;
+import org.apache.camel.util.ObjectHelper;
+
 public class KubernetesConfigMapsConsumer extends DefaultConsumer {
 
     private final Processor processor;
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/KubernetesConfigMapsConsumerTest.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/KubernetesConfigMapsConsumerTest.java
index 3bd59af..0a53a0e 100644
--- a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/KubernetesConfigMapsConsumerTest.java
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/KubernetesConfigMapsConsumerTest.java
@@ -19,6 +19,8 @@ package org.apache.camel.component.kubernetes.consumer;
 import java.util.HashMap;
 import java.util.Map;
 
+import io.fabric8.kubernetes.api.model.ConfigMap;
+
 import org.apache.camel.EndpointInject;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
@@ -31,8 +33,6 @@ import org.apache.camel.util.ObjectHelper;
 import org.junit.Ignore;
 import org.junit.Test;
 
-import io.fabric8.kubernetes.api.model.ConfigMap;
-
 @Ignore("Requires a running Kubernetes Cluster")
 public class KubernetesConfigMapsConsumerTest extends KubernetesTestSupport {