Repository: camel
Updated Branches:
  refs/heads/master 4fac6a0bc -> c8c60933e


CAMEL-8726 Camel-Openshift: Add multiple environment variables to application


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

Branch: refs/heads/master
Commit: 35827b4601b404b12b64d985bbd7ce76360da171
Parents: 4fac6a0
Author: Andrea Cosentino <anco...@gmail.com>
Authored: Fri May 1 10:15:47 2015 +0200
Committer: Andrea Cosentino <anco...@gmail.com>
Committed: Fri May 1 10:25:34 2015 +0200

----------------------------------------------------------------------
 .../component/openshift/OpenShiftConstants.java |  1 +
 .../component/openshift/OpenShiftOperation.java |  1 +
 .../component/openshift/OpenShiftProducer.java  | 26 +++++++++
 ...hiftAddMultipleEnvironmentVariablesTest.java | 60 ++++++++++++++++++++
 4 files changed, 88 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/35827b46/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftConstants.java
----------------------------------------------------------------------
diff --git 
a/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftConstants.java
 
b/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftConstants.java
index e390fe0..049e113 100644
--- 
a/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftConstants.java
+++ 
b/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftConstants.java
@@ -27,6 +27,7 @@ public final class OpenShiftConstants {
     public static final String DEPLOYMENT_TYPE = 
"CamelOpenShiftDeploymentType";
     public static final String ENVIRONMENT_VARIABLE_NAME = 
"CamelOpenShiftEnvironmentVariableName";
     public static final String ENVIRONMENT_VARIABLE_VALUE = 
"CamelOpenShiftEnvironmentVariableValue";
+    public static final String ENVIRONMENT_VARIABLE_MAP = 
"CamelOpenShiftEnvironmentVariableMap";
 
     private OpenShiftConstants() {
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/35827b46/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftOperation.java
----------------------------------------------------------------------
diff --git 
a/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftOperation.java
 
b/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftOperation.java
index 3295565..c1610ca 100644
--- 
a/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftOperation.java
+++ 
b/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftOperation.java
@@ -34,6 +34,7 @@ public enum OpenShiftOperation {
     setDeploymentType,
     getAllEnvironmentVariables,
     addEnvironmentVariable,
+    addMultipleEnvironmentVariables,
     updateEnvironmentVariable,
     getEnvironmentVariableValue,
     removeEnvironmentVariable,

http://git-wip-us.apache.org/repos/asf/camel/blob/35827b46/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftProducer.java
----------------------------------------------------------------------
diff --git 
a/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftProducer.java
 
b/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftProducer.java
index cb52efc..23026c7 100644
--- 
a/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftProducer.java
+++ 
b/components/camel-openshift/src/main/java/org/apache/camel/component/openshift/OpenShiftProducer.java
@@ -107,6 +107,9 @@ public class OpenShiftProducer extends DefaultProducer {
         case addEnvironmentVariable:
             doAddEnvironmentVariable(exchange, domain);
             break;
+        case addMultipleEnvironmentVariables:
+            doAddMultipleEnvironmentVariables(exchange, domain);
+            break;
         case updateEnvironmentVariable:
             doUpdateEnvironmentVariable(exchange, domain);
             break;
@@ -459,6 +462,29 @@ public class OpenShiftProducer extends DefaultProducer {
         }
     }
     
+    protected void doAddMultipleEnvironmentVariables(Exchange exchange, 
IDomain domain) throws CamelExchangeException {
+        String name = 
exchange.getIn().getHeader(OpenShiftConstants.APPLICATION, 
getEndpoint().getApplication(), String.class);
+        if (name == null) {
+            throw new CamelExchangeException("Application not specified", 
exchange);
+        }
+
+        IApplication app = domain.getApplicationByName(name);
+        if (app == null) {
+            throw new CamelExchangeException("Application with id " + name + " 
not found.", exchange);
+        } else {
+            Map environmentVariables = 
exchange.getIn().getHeader(OpenShiftConstants.ENVIRONMENT_VARIABLE_MAP, 
getEndpoint().getApplication(), Map.class);
+            if (!app.canUpdateEnvironmentVariables()) {
+                throw new CamelExchangeException("The application with id " + 
name + " can't update Environment Variables", exchange);
+            }
+            if ((!ObjectHelper.isEmpty(environmentVariables) && 
environmentVariables != null)) {
+                Map<String, IEnvironmentVariable> result = 
app.addEnvironmentVariables(environmentVariables);
+                exchange.getIn().setBody(result);
+            } else {
+                throw new CamelExchangeException("Environment variables not 
correctly specified", exchange);
+            }
+        }
+    }
+    
     protected void doUpdateEnvironmentVariable(Exchange exchange, IDomain 
domain) throws CamelExchangeException {
         String name = 
exchange.getIn().getHeader(OpenShiftConstants.APPLICATION, 
getEndpoint().getApplication(), String.class);
         if (name == null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/35827b46/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftAddMultipleEnvironmentVariablesTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftAddMultipleEnvironmentVariablesTest.java
 
b/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftAddMultipleEnvironmentVariablesTest.java
new file mode 100644
index 0000000..51f4388
--- /dev/null
+++ 
b/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftAddMultipleEnvironmentVariablesTest.java
@@ -0,0 +1,60 @@
+/**
+ * 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.openshift;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class OpenShiftAddMultipleEnvironmentVariablesTest extends 
CamelTestSupport {
+
+    private String username;
+    private String password;
+
+    @Override
+    public void setUp() throws Exception {
+        // INSERT credentials here
+        username = null;
+        password = null;
+        super.setUp();
+    }
+
+    @Test
+    public void testAddEnvironmentVariable() throws Exception {
+        if (username == null) {
+            return;
+        }
+
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    
.toF("openshift:myApp?operation=addMultipleEnvironmentVariables&mode=json&username=%s&password=%s",
 username, password)
+                    .to("mock:result");
+            }
+        };
+    }
+}

Reply via email to