camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [4/4] camel git commit: CAMEL-10134: Camel-Kubernetes: Add the ability to consume events from Resources filtered by labels and/or name - Removed Secrets consumer, it doesn't really make sense
Date Mon, 11 Jul 2016 08:48:35 GMT
CAMEL-10134: Camel-Kubernetes: Add the ability to consume events from Resources filtered by
labels and/or name - Removed Secrets consumer, it doesn't really make sense


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/22a4f28e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/22a4f28e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/22a4f28e

Branch: refs/heads/master
Commit: 22a4f28e5910ad95631c6d9dab994b6746f0b446
Parents: bef891e
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Mon Jul 11 10:44:32 2016 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Mon Jul 11 10:44:32 2016 +0200

----------------------------------------------------------------------
 .../kubernetes/KubernetesEndpoint.java          |   4 -
 .../consumer/KubernetesSecretsConsumer.java     | 138 -------------------
 .../kubernetes/consumer/common/SecretEvent.java |  47 -------
 .../consumer/KubernetesSecretsConsumerTest.java | 125 -----------------
 .../KubernetesConfigMapsProducerTest.java       |   8 +-
 5 files changed, 1 insertion(+), 321 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/22a4f28e/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 8a81bdf..f710e77 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
@@ -28,7 +28,6 @@ import org.apache.camel.Producer;
 import org.apache.camel.component.kubernetes.consumer.KubernetesNamespacesConsumer;
 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.KubernetesBuildConfigsProducer;
 import org.apache.camel.component.kubernetes.producer.KubernetesBuildsProducer;
@@ -139,9 +138,6 @@ public class KubernetesEndpoint extends DefaultEndpoint {
 
             case KubernetesCategory.REPLICATION_CONTROLLERS:
                 return new KubernetesReplicationControllersConsumer(this, processor);
-
-            case KubernetesCategory.SECRETS:
-                return new KubernetesSecretsConsumer(this, processor);
                 
             case KubernetesCategory.NAMESPACES:
                 return new KubernetesNamespacesConsumer(this, processor);

http://git-wip-us.apache.org/repos/asf/camel/blob/22a4f28e/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
deleted file mode 100644
index a677945..0000000
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesSecretsConsumer.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.kubernetes.consumer;
-
-import java.util.concurrent.ExecutorService;
-
-import io.fabric8.kubernetes.api.model.Secret;
-import io.fabric8.kubernetes.client.KubernetesClientException;
-import io.fabric8.kubernetes.client.Watcher;
-
-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.SecretEvent;
-import org.apache.camel.impl.DefaultConsumer;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class KubernetesSecretsConsumer extends DefaultConsumer {
-
-    private static final Logger LOG = LoggerFactory.getLogger(KubernetesSecretsConsumer.class);
-
-    private final Processor processor;
-    private ExecutorService executor;
-
-    public KubernetesSecretsConsumer(KubernetesEndpoint endpoint, Processor processor) {
-        super(endpoint, processor);
-        this.processor = processor;
-    }
-
-    @Override
-    public KubernetesEndpoint getEndpoint() {
-        return (KubernetesEndpoint) super.getEndpoint();
-    }
-
-    @Override
-    protected void doStart() throws Exception {
-        super.doStart();
-        executor = getEndpoint().createExecutor();
-
-        executor.submit(new SecretsConsumerTask());       
-
-    }
-
-    @Override
-    protected void doStop() throws Exception {
-        super.doStop();
-        
-        LOG.debug("Stopping Kubernetes Secrets Consumer");
-        if (executor != null) {
-            if (getEndpoint() != null && getEndpoint().getCamelContext() != null)
{
-                getEndpoint().getCamelContext().getExecutorServiceManager().shutdownNow(executor);
-            } else {
-                executor.shutdownNow();
-            }
-        }
-        executor = null;
-    }
-    
-    class SecretsConsumerTask implements Runnable {
-        
-        @Override
-        public void run() {
-            if (ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration().getOauthToken()))
{
-                if (ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration().getNamespace()))
{
-                    getEndpoint().getKubernetesClient().secrets()
-                            .inNamespace(getEndpoint().getKubernetesConfiguration().getNamespace())
-                            .watch(new Watcher<Secret>() {
-
-                                @Override
-                                public void eventReceived(io.fabric8.kubernetes.client.Watcher.Action
action,
-                                        Secret resource) {
-                                    SecretEvent se = new SecretEvent(action, resource);
-                                    Exchange exchange = getEndpoint().createExchange();
-                                    exchange.getIn().setBody(se.getSecret());
-                                    exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_EVENT_ACTION,
se.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);
-                                    }
-
-                                }
-                            });
-                } 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);
-                            Exchange exchange = getEndpoint().createExchange();
-                            exchange.getIn().setBody(se.getSecret());
-                            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_EVENT_ACTION,
se.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);
-                            }
-                        }
-                    });
-                }
-            }
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/22a4f28e/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
deleted file mode 100644
index 913da10..0000000
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/common/SecretEvent.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.kubernetes.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) {
-        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/22a4f28e/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
deleted file mode 100644
index ac576aa..0000000
--- a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/consumer/KubernetesSecretsConsumerTest.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.kubernetes.consumer;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import io.fabric8.kubernetes.api.model.ObjectMeta;
-import io.fabric8.kubernetes.api.model.Secret;
-
-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.apache.commons.codec.binary.Base64;
-import org.junit.Test;
-
-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.encodeBase64String("pippo".getBytes()));
-                mp.put("password", Base64.encodeBase64String("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(3000);
-
-        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/22a4f28e/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesConfigMapsProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesConfigMapsProducerTest.java
b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesConfigMapsProducerTest.java
index 47c2e63..9b26a7e 100644
--- a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesConfigMapsProducerTest.java
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/producer/KubernetesConfigMapsProducerTest.java
@@ -16,17 +16,12 @@
  */
 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.ConfigMap;
-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;
@@ -44,8 +39,7 @@ public class KubernetesConfigMapsProducerTest extends KubernetesTestSupport
{
             return;
         }
         List<ConfigMap> result = template.requestBody("direct:list", "", List.class);
-
-        assertEquals(0, result.size());
+        assertEquals(1, result.size());
     }
 
     @Test


Mime
View raw message