camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject camel git commit: CAMEL-8700 Camel-OpenShift: Add new operations to available set
Date Sat, 25 Apr 2015 21:25:21 GMT
Repository: camel
Updated Branches:
  refs/heads/master 799d3cbc7 -> 5becebd30


CAMEL-8700 Camel-OpenShift: Add new operations to available set


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

Branch: refs/heads/master
Commit: 5becebd30cc723a23899102350a0de3148804ae9
Parents: 799d3cb
Author: ancosen <ancosen@gmail.com>
Authored: Sat Apr 25 23:23:18 2015 +0200
Committer: ancosen <ancosen@gmail.com>
Committed: Sat Apr 25 23:23:59 2015 +0200

----------------------------------------------------------------------
 .../component/openshift/OpenShiftConstants.java |  1 +
 .../component/openshift/OpenShiftOperation.java |  2 +-
 .../component/openshift/OpenShiftProducer.java  | 91 ++++++++++++++++++++
 .../OpenShiftAddEmbeddedCartridgeTest.java      | 62 +++++++++++++
 .../OpenShiftGetEmbeddedCartridgesTest.java     | 62 +++++++++++++
 .../OpenShiftGetStandaloneCartridgeTest.java    | 62 +++++++++++++
 .../OpenShiftRemoveEmbeddedCartridgeTest.java   | 62 +++++++++++++
 7 files changed, 341 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5becebd3/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 1dd0495..7084885 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
@@ -23,6 +23,7 @@ public final class OpenShiftConstants {
     public static final String EVENT_TYPE = "CamelOpenShiftEventType";
     public static final String EVENT_OLD_STATE = "CamelOpenShiftEventOldState";
     public static final String EVENT_NEW_STATE = "CamelOpenShiftEventNewState";
+    public static final String EMBEDDED_CARTRIDGE_NAME = "CamelOpenShiftEmbeddedCartridgeName";
 
     private OpenShiftConstants() {
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/5becebd3/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 2fd7b8d..6b90841 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,6 @@ package org.apache.camel.component.openshift;
 
 public enum OpenShiftOperation {
 
-    list, start, stop, restart, state
+    list, start, stop, restart, state, getStandaloneCartridge, getEmbeddedCartridges, addEmbeddedCartridge,
removeEmbeddedCartridge
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/5becebd3/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 cd35cf4..ac9a5d5 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
@@ -25,11 +25,16 @@ import com.openshift.client.IApplication;
 import com.openshift.client.IDomain;
 import com.openshift.client.IGear;
 import com.openshift.client.IGearGroup;
+import com.openshift.client.cartridge.IDeployedStandaloneCartridge;
+import com.openshift.client.cartridge.IEmbeddableCartridge;
 import com.openshift.client.cartridge.IEmbeddedCartridge;
+import com.openshift.client.cartridge.query.LatestEmbeddableCartridge;
+
 import org.apache.camel.CamelExchangeException;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
 
 public class OpenShiftProducer extends DefaultProducer {
 
@@ -67,6 +72,18 @@ public class OpenShiftProducer extends DefaultProducer {
         case state:
             doState(exchange, domain);
             break;
+        case getStandaloneCartridge:
+            doGetStandaloneCartridge(exchange, domain);
+            break;
+        case getEmbeddedCartridges:
+            doGetEmbeddedCartridges(exchange, domain);
+            break;
+        case addEmbeddedCartridge:
+            doAddEmbeddedCartridge(exchange, domain);
+            break;
+        case removeEmbeddedCartridge:
+            doRemoveEmbeddedCartridge(exchange, domain);
+            break;
         case list:
         default:
             // and do list by default
@@ -213,5 +230,79 @@ public class OpenShiftProducer extends DefaultProducer {
             exchange.getIn().setBody(state);
         }
     }
+    
+    protected void doGetStandaloneCartridge(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 {
+            IDeployedStandaloneCartridge p = app.getCartridge();
+            exchange.getIn().setBody(p.getDisplayName());
+        }
+    }
+
+    protected void doGetEmbeddedCartridges(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<IEmbeddedCartridge> p = app.getEmbeddedCartridges();
+            exchange.getIn().setBody(p);
+        }
+    }
+    
+    protected void doAddEmbeddedCartridge(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 embeddedCartridgeName = exchange.getIn().getHeader(OpenShiftConstants.EMBEDDED_CARTRIDGE_NAME,
getEndpoint().getApplication(), String.class);
+            if (!ObjectHelper.isEmpty(embeddedCartridgeName) && embeddedCartridgeName
!= null) {
+                IEmbeddedCartridge p = app.addEmbeddableCartridge((new LatestEmbeddableCartridge(embeddedCartridgeName)).get(app));
+                exchange.getIn().setBody(p.getDisplayName());
+            } else {
+                throw new CamelExchangeException("Cartridge not specified", exchange);
+            }
+        }
+    }
+    
+    protected void doRemoveEmbeddedCartridge(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 embeddedCartridgeName = exchange.getIn().getHeader(OpenShiftConstants.EMBEDDED_CARTRIDGE_NAME,
getEndpoint().getApplication(), String.class);
+            if (!ObjectHelper.isEmpty(embeddedCartridgeName) && embeddedCartridgeName
!= null) {
+                IEmbeddableCartridge removingCartridge = (new LatestEmbeddableCartridge(embeddedCartridgeName)).get(app);
+                for (IEmbeddedCartridge cartridge : app.getEmbeddedCartridges()) {
+                    if (cartridge.equals(removingCartridge)) {
+                        cartridge.destroy();
+                        exchange.getIn().setBody(cartridge.getDisplayName());
+                    }
+                }
+            } else {
+                throw new CamelExchangeException("Cartridge not specified", exchange);
+            }
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/5becebd3/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftAddEmbeddedCartridgeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftAddEmbeddedCartridgeTest.java
b/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftAddEmbeddedCartridgeTest.java
new file mode 100644
index 0000000..769b254
--- /dev/null
+++ b/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftAddEmbeddedCartridgeTest.java
@@ -0,0 +1,62 @@
+/**
+ * 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 OpenShiftAddEmbeddedCartridgeTest extends CamelTestSupport {
+
+    private String username;
+    private String password;
+    private String application;
+
+    @Override
+    public void setUp() throws Exception {
+        // INSERT credentials here
+        username = null;
+        password = null;
+        application = "myapp";
+        super.setUp();
+    }
+
+    @Test
+    public void testAddEmbeddedCartridge() throws Exception {
+        if (username == null) {
+            return;
+        }
+
+        getMockEndpoint("mock:result").expectedBodiesReceived("started");
+
+        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=getEmbeddedCartridges&application=%s&username=%s&password=%s",
application, username, password)
+                    .to("mock:result");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/5becebd3/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftGetEmbeddedCartridgesTest.java
----------------------------------------------------------------------
diff --git a/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftGetEmbeddedCartridgesTest.java
b/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftGetEmbeddedCartridgesTest.java
new file mode 100644
index 0000000..12a4eb1
--- /dev/null
+++ b/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftGetEmbeddedCartridgesTest.java
@@ -0,0 +1,62 @@
+/**
+ * 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 OpenShiftGetEmbeddedCartridgesTest extends CamelTestSupport {
+
+    private String username;
+    private String password;
+    private String application;
+
+    @Override
+    public void setUp() throws Exception {
+        // INSERT credentials here
+        username = null;
+        password = null;
+        application = "myapp";
+        super.setUp();
+    }
+
+    @Test
+    public void testGetEmbeddedCartridges() throws Exception {
+        if (username == null) {
+            return;
+        }
+
+        getMockEndpoint("mock:result").expectedBodiesReceived("started");
+
+        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=getEmbeddedCartridges&application=%s&username=%s&password=%s",
application, username, password)
+                    .to("mock:result");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/5becebd3/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftGetStandaloneCartridgeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftGetStandaloneCartridgeTest.java
b/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftGetStandaloneCartridgeTest.java
new file mode 100644
index 0000000..8e0f830
--- /dev/null
+++ b/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftGetStandaloneCartridgeTest.java
@@ -0,0 +1,62 @@
+/**
+ * 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 OpenShiftGetStandaloneCartridgeTest extends CamelTestSupport {
+
+    private String username;
+    private String password;
+    private String application;
+
+    @Override
+    public void setUp() throws Exception {
+        // INSERT credentials here
+        username = null;
+        password = null;
+        application = "myapp";
+        super.setUp();
+    }
+
+    @Test
+    public void testGetStandaloneCartridge() throws Exception {
+        if (username == null) {
+            return;
+        }
+
+        getMockEndpoint("mock:result").expectedBodiesReceived("started");
+
+        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=getStandaloneCartridge&application=%s&username=%s&password=%s",
application, username, password)
+                    .to("mock:result");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/5becebd3/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftRemoveEmbeddedCartridgeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftRemoveEmbeddedCartridgeTest.java
b/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftRemoveEmbeddedCartridgeTest.java
new file mode 100644
index 0000000..e4b9db9
--- /dev/null
+++ b/components/camel-openshift/src/test/java/org/apache/camel/component/openshift/OpenShiftRemoveEmbeddedCartridgeTest.java
@@ -0,0 +1,62 @@
+/**
+ * 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 OpenShiftRemoveEmbeddedCartridgeTest extends CamelTestSupport {
+
+    private String username;
+    private String password;
+    private String application;
+
+    @Override
+    public void setUp() throws Exception {
+        // INSERT credentials here
+        username = null;
+        password = null;
+        application = "myapp";
+        super.setUp();
+    }
+
+    @Test
+    public void testRemoveEmbeddedCartridge() throws Exception {
+        if (username == null) {
+            return;
+        }
+
+        getMockEndpoint("mock:result").expectedBodiesReceived("started");
+
+        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=removeEmbeddedCartridge&application=%s&username=%s&password=%s",
application, username, password)
+                    .to("mock:result");
+            }
+        };
+    }
+}


Mime
View raw message