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/05/05 17:38:54 UTC

camel git commit: Camel-8744 Camel-Openshift: Add Aliases support

Repository: camel
Updated Branches:
  refs/heads/master 0b541c17c -> f1c6f0717


Camel-8744 Camel-Openshift: Add Aliases support


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

Branch: refs/heads/master
Commit: f1c6f0717a91ea4826976bdf8992b7d093f47ff2
Parents: 0b541c1
Author: Andrea Cosentino <an...@gmail.com>
Authored: Tue May 5 09:01:30 2015 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Tue May 5 17:37:20 2015 +0200

----------------------------------------------------------------------
 .../component/openshift/OpenShiftConstants.java |  1 +
 .../component/openshift/OpenShiftOperation.java |  5 +-
 .../component/openshift/OpenShiftProducer.java  | 72 +++++++++++++++++++-
 .../openshift/OpenShiftAddAliasTest.java        | 60 ++++++++++++++++
 .../openshift/OpenShiftGetAliasesTest.java      | 60 ++++++++++++++++
 .../openshift/OpenShiftRemoveAliasTest.java     | 60 ++++++++++++++++
 6 files changed, 256 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f1c6f071/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 049e113..c5005f2 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
@@ -28,6 +28,7 @@ public final class OpenShiftConstants {
     public static final String ENVIRONMENT_VARIABLE_NAME = "CamelOpenShiftEnvironmentVariableName";
     public static final String ENVIRONMENT_VARIABLE_VALUE = "CamelOpenShiftEnvironmentVariableValue";
     public static final String ENVIRONMENT_VARIABLE_MAP = "CamelOpenShiftEnvironmentVariableMap";
+    public static final String APPLICATION_ALIAS = "CamelOpenShiftApplicationAlias";
 
     private OpenShiftConstants() {
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/f1c6f071/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 c1610ca..094a6f7 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
@@ -38,5 +38,8 @@ public enum OpenShiftOperation {
     updateEnvironmentVariable,
     getEnvironmentVariableValue,
     removeEnvironmentVariable,
-    getGearProfile
+    getGearProfile,
+    addAlias,
+    removeAlias,
+    getAliases
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/f1c6f071/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 f85e7cd..c8af106 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
@@ -124,7 +124,16 @@ public class OpenShiftProducer extends DefaultProducer {
             break;
         case getGearProfile:
             doGetGearProfile(exchange, domain);
-            break;            
+            break;
+        case addAlias:
+            doAddAlias(exchange, domain);
+            break;
+        case removeAlias:
+            doRemoveAlias(exchange, domain);
+            break;
+        case getAliases:
+            doGetAliases(exchange, domain);
+            break; 
         case list:
         default:
             // and do list by default
@@ -584,4 +593,65 @@ public class OpenShiftProducer extends DefaultProducer {
             exchange.getIn().setBody(result.getName());
         }
     }
+    
+    protected void doAddAlias(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 {
+            String alias = exchange.getIn().getHeader(OpenShiftConstants.APPLICATION_ALIAS, getEndpoint().getApplication(), String.class);
+            if (!app.canGetEnvironmentVariables()) {
+                throw new CamelExchangeException("The application with id " + name + " can't get Environment Variables", exchange);
+            }
+            if (ObjectHelper.isNotEmpty(alias)) {
+                app.addAlias(alias);
+                exchange.getIn().setBody(alias);
+            } else {
+                throw new CamelExchangeException("Application Alias name not specified", exchange);
+            }
+        }
+    }
+    
+    protected void doRemoveAlias(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 {
+            String alias = exchange.getIn().getHeader(OpenShiftConstants.APPLICATION_ALIAS, getEndpoint().getApplication(), String.class);
+            if (!app.canGetEnvironmentVariables()) {
+                throw new CamelExchangeException("The application with id " + name + " can't get Environment Variables", exchange);
+            }
+            if (ObjectHelper.isNotEmpty(alias)) {
+                app.removeAlias(alias);
+                exchange.getIn().setBody(alias);
+            } else {
+                throw new CamelExchangeException("Application Alias not specified", exchange);
+            }
+        }
+    }
+    
+    protected void doGetAliases(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 {
+            List<String> aliases = app.getAliases();
+            exchange.getIn().setBody(aliases);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/f1c6f071/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftAddAliasTest.java
----------------------------------------------------------------------
diff --git a/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftAddAliasTest.java b/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftAddAliasTest.java
new file mode 100644
index 0000000..b2b235b
--- /dev/null
+++ b/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftAddAliasTest.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 OpenShiftAddAliasTest 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 testAddAlias() 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=addAlias&mode=json&username=%s&password=%s", username, password)
+                    .to("mock:result");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/f1c6f071/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftGetAliasesTest.java
----------------------------------------------------------------------
diff --git a/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftGetAliasesTest.java b/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftGetAliasesTest.java
new file mode 100644
index 0000000..19aa3bd
--- /dev/null
+++ b/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftGetAliasesTest.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 OpenShiftGetAliasesTest 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 testGetAliases() 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=getAliases&mode=json&username=%s&password=%s", username, password)
+                    .to("mock:result");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/f1c6f071/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftRemoveAliasTest.java
----------------------------------------------------------------------
diff --git a/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftRemoveAliasTest.java b/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftRemoveAliasTest.java
new file mode 100644
index 0000000..f13ef44
--- /dev/null
+++ b/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftRemoveAliasTest.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 OpenShiftRemoveAliasTest 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 testRemoveAlias() 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=removeAlias&mode=json&username=%s&password=%s", username, password)
+                    .to("mock:result");
+            }
+        };
+    }
+}