Repository: camel
Updated Branches:
  refs/heads/master d1be10d7f -> d9ae20ba7


CAMEL-8703 Camel-Openshift: Scaling management operations and gitUrl feature


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

Branch: refs/heads/master
Commit: d9ae20ba7d8d41a9604cd624addf354ea6df06cd
Parents: d1be10d
Author: Andrea Cosentino <anco...@gmail.com>
Authored: Sun Apr 26 14:43:01 2015 +0200
Committer: Andrea Cosentino <anco...@gmail.com>
Committed: Sun Apr 26 14:43:01 2015 +0200

----------------------------------------------------------------------
 .../component/openshift/OpenShiftOperation.java | 14 +++-
 .../component/openshift/OpenShiftProducer.java  | 67 ++++++++++++++++++++
 .../openshift/OpenShiftGetGitUrlTest.java       | 60 ++++++++++++++++++
 .../openshift/OpenShiftScaleDownTest.java       | 60 ++++++++++++++++++
 .../openshift/OpenShiftScaleUpTest.java         | 60 ++++++++++++++++++
 5 files changed, 259 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d9ae20ba/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 6b90841..8ba9a0c 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
@@ -18,6 +18,16 @@ package org.apache.camel.component.openshift;
 
 public enum OpenShiftOperation {
 
-    list, start, stop, restart, state, getStandaloneCartridge, 
getEmbeddedCartridges, addEmbeddedCartridge, removeEmbeddedCartridge
-
+    list,
+    start,
+    stop,
+    restart,
+    state,
+    getStandaloneCartridge,
+    getEmbeddedCartridges,
+    addEmbeddedCartridge,
+    removeEmbeddedCartridge,
+    scaleUp,
+    scaleDown,
+    getGitUrl
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/d9ae20ba/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 ac9a5d5..7f80251 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
@@ -21,10 +21,12 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 
+import com.openshift.client.ApplicationScale;
 import com.openshift.client.IApplication;
 import com.openshift.client.IDomain;
 import com.openshift.client.IGear;
 import com.openshift.client.IGearGroup;
+import com.openshift.client.OpenShiftException;
 import com.openshift.client.cartridge.IDeployedStandaloneCartridge;
 import com.openshift.client.cartridge.IEmbeddableCartridge;
 import com.openshift.client.cartridge.IEmbeddedCartridge;
@@ -78,12 +80,21 @@ public class OpenShiftProducer extends DefaultProducer {
         case getEmbeddedCartridges:
             doGetEmbeddedCartridges(exchange, domain);
             break;
+        case getGitUrl:
+            doGetGitUrl(exchange, domain);
+            break;
         case addEmbeddedCartridge:
             doAddEmbeddedCartridge(exchange, domain);
             break;
         case removeEmbeddedCartridge:
             doRemoveEmbeddedCartridge(exchange, domain);
             break;
+        case scaleUp:
+            doScaleUp(exchange, domain);
+            break;
+        case scaleDown:
+            doScaleDown(exchange, domain);
+            break;
         case list:
         default:
             // and do list by default
@@ -305,4 +316,60 @@ public class OpenShiftProducer extends DefaultProducer {
             }
         }
     }
+    
+    protected void doScaleUp(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 {
+            try {
+                app.scaleUp();
+                ApplicationScale result = app.getApplicationScale();
+                exchange.getIn().setBody(result.getValue());
+            } catch (OpenShiftException e) {
+                throw new CamelExchangeException("Application with id " + name 
+ " is not scalable", exchange);
+            }
+        }
+    }
+    
+    protected void doScaleDown(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 {
+            ApplicationScale scale = app.getApplicationScale();
+            if (scale.getValue().equals(ApplicationScale.NO_SCALE.getValue())) 
{
+                log.info("Scaling on application with id " + name + " is not 
enabled");
+            } else {
+                app.scaleDown();
+                ApplicationScale result = app.getApplicationScale();
+                exchange.getIn().setBody(result.getValue());
+            }
+        }
+    }
+    
+    protected void doGetGitUrl(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 gitUrl = app.getGitUrl();
+            exchange.getIn().setBody(gitUrl);
+        }
+    }
 }

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

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

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

Reply via email to