You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by st...@apache.org on 2016/06/22 17:11:45 UTC

[1/5] incubator-taverna-common-activities git commit: Adding initial project structure for docker activity.

Repository: incubator-taverna-common-activities
Updated Branches:
  refs/heads/docker 57e10e1de -> bebc1f292


Adding initial project structure for docker activity.


Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/commit/fbc9e2a8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/tree/fbc9e2a8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/diff/fbc9e2a8

Branch: refs/heads/docker
Commit: fbc9e2a81eee5736ed943caba5942202a9fa8127
Parents: 57e10e1
Author: Nadeesh Dilanga <na...@gmail.com>
Authored: Mon Jun 13 02:08:33 2016 -0400
Committer: Nadeesh Dilanga <na...@gmail.com>
Committed: Mon Jun 13 02:08:33 2016 -0400

----------------------------------------------------------------------
 taverna-docker-activity/pom.xml                 | 46 ++++++++++++++++++-
 .../activities/docker/DockerActivity.java       | 48 ++++++++++++++++++++
 .../taverna/activities/docker/RESTUtil.java     | 23 ++++++++++
 3 files changed, 116 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/fbc9e2a8/taverna-docker-activity/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/pom.xml b/taverna-docker-activity/pom.xml
index f69d078..d972584 100644
--- a/taverna-docker-activity/pom.xml
+++ b/taverna-docker-activity/pom.xml
@@ -68,8 +68,52 @@
 			<artifactId>jackson-databind</artifactId>
 			<version>${jackson.version}</version>
 		</dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient-osgi</artifactId>
+            <version>${apache.httpclient.version}</version>
+            <exclusions>
+                <!-- These are all embedded within httpclient-osgi -->
+                <exclusion>
+                    <groupId>org.apache.httpcomponents</groupId>
+                    <artifactId>httpclient</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>commons-codec</groupId>
+                    <artifactId>commons-codec</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.apache.httpcomponents</groupId>
+                    <artifactId>httpmime</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.apache.httpcomponents</groupId>
+                    <artifactId>httpclient-cache</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.apache.httpcomponents</groupId>
+                    <artifactId>fluent-hc</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpcore-osgi</artifactId>
+            <version>${apache.httpcore.version}</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.apache.httpcomponents</groupId>
+                    <artifactId>httpcore</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.apache.httpcomponents</groupId>
+                    <artifactId>httpcore-nio</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
 
-	</dependencies>
+
+    </dependencies>
 
 
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/fbc9e2a8/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivity.java
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivity.java b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivity.java
new file mode 100644
index 0000000..2760546
--- /dev/null
+++ b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivity.java
@@ -0,0 +1,48 @@
+/*
+* 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.taverna.activities.docker;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.taverna.reference.T2Reference;
+import org.apache.taverna.workflowmodel.processor.activity.AbstractAsynchronousActivity;
+import org.apache.taverna.workflowmodel.processor.activity.ActivityConfigurationException;
+import org.apache.taverna.workflowmodel.processor.activity.AsynchronousActivityCallback;
+
+import java.util.Map;
+
+/**
+ * Docker activity class responsible of handling tasks that are related to creating/invoking an external docker container.
+ */
+public class DockerActivity extends AbstractAsynchronousActivity<JsonNode> {
+
+    @Override
+    public void configure(JsonNode jsonNode) throws ActivityConfigurationException {
+
+    }
+
+    @Override
+    public JsonNode getConfiguration() {
+        return null;
+    }
+
+    @Override
+    public void executeAsynch(Map<String, T2Reference> map, AsynchronousActivityCallback asynchronousActivityCallback) {
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/fbc9e2a8/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/RESTUtil.java
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/RESTUtil.java b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/RESTUtil.java
new file mode 100644
index 0000000..460f275
--- /dev/null
+++ b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/RESTUtil.java
@@ -0,0 +1,23 @@
+/*
+* 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.taverna.activities.docker;
+
+public class RESTUtil {
+}


[2/5] incubator-taverna-common-activities git commit: Implementing rest utilities to invoke Docker.

Posted by st...@apache.org.
Implementing rest utilities to invoke Docker.


Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/commit/9f0eb33c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/tree/9f0eb33c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/diff/9f0eb33c

Branch: refs/heads/docker
Commit: 9f0eb33cd40e56f4294afb9d6e832f44dd0a7f97
Parents: fbc9e2a
Author: Nadeesh Dilanga <na...@gmail.com>
Authored: Wed Jun 15 03:42:37 2016 -0400
Committer: Nadeesh Dilanga <na...@gmail.com>
Committed: Wed Jun 15 03:42:37 2016 -0400

----------------------------------------------------------------------
 .../activities/docker/DockerActivity.java       |  22 ++-
 .../taverna/activities/docker/DockerConfig.java |  77 +++++++++
 .../activities/docker/DockerHttpResponse.java   |  49 ++++++
 .../taverna/activities/docker/RESTUtil.java     | 157 +++++++++++++++++++
 .../docker/test/TestCreateContainer.java        |  43 +++++
 5 files changed, 343 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/9f0eb33c/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivity.java
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivity.java b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivity.java
index 2760546..c81e9de 100644
--- a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivity.java
+++ b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivity.java
@@ -19,6 +19,8 @@
 package org.apache.taverna.activities.docker;
 
 import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.taverna.invocation.InvocationContext;
+import org.apache.taverna.reference.ReferenceService;
 import org.apache.taverna.reference.T2Reference;
 import org.apache.taverna.workflowmodel.processor.activity.AbstractAsynchronousActivity;
 import org.apache.taverna.workflowmodel.processor.activity.ActivityConfigurationException;
@@ -31,18 +33,28 @@ import java.util.Map;
  */
 public class DockerActivity extends AbstractAsynchronousActivity<JsonNode> {
 
-    @Override
-    public void configure(JsonNode jsonNode) throws ActivityConfigurationException {
+    private JsonNode activityConfig;
 
+    @Override
+    public void configure(JsonNode activityConfig) throws ActivityConfigurationException {
+      this.activityConfig = activityConfig;
     }
 
     @Override
     public JsonNode getConfiguration() {
-        return null;
+        return activityConfig;
     }
 
     @Override
-    public void executeAsynch(Map<String, T2Reference> map, AsynchronousActivityCallback asynchronousActivityCallback) {
-
+    public void executeAsynch(Map<String, T2Reference> map, final AsynchronousActivityCallback callback) {
+        callback.requestRun(new Runnable() {
+            @Override
+            public void run() {
+                InvocationContext context = callback.getContext();
+                ReferenceService referenceService = context.getReferenceService();
+                //TODO invoke container remote api and set final response result to callback.receiveResult();
+
+            }
+        });
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/9f0eb33c/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerConfig.java
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerConfig.java b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerConfig.java
new file mode 100644
index 0000000..30d12c5
--- /dev/null
+++ b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerConfig.java
@@ -0,0 +1,77 @@
+/*
+* 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.taverna.activities.docker;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+public class DockerConfig {
+
+    /**
+     * Hold the hostname of the docker container.
+     */
+    private String containerHost;
+
+    /**
+     * Remote REST API port exposed by Docker
+     */
+    private int remoteAPIPort = 443;
+
+    /**
+     * JSON payload to invoke create container REST API.
+     */
+    private JsonNode createContainerPayload;
+
+    /**
+     * Complete HTTP URL for create container
+     */
+    private final String createContainerURL;
+
+    /**
+     * Docker remote REST resource path for creating a container
+     */
+    public static final String CREATE_CONTAINER_RESOURCE_PATH = "/containers/create";
+
+    /**
+     * Transport protocol
+     */
+    public static final String PROTOCOL = "https";
+
+    public DockerConfig(String containerHost, int remoteAPIPort, JsonNode createContainerPayload) {
+        this.containerHost = containerHost;
+        this.remoteAPIPort = remoteAPIPort;
+        this.createContainerPayload = createContainerPayload;
+        this.createContainerURL = PROTOCOL + "://" + containerHost +  ":" + remoteAPIPort + CREATE_CONTAINER_RESOURCE_PATH ;
+    }
+
+    public String getContainerHost() {
+        return containerHost;
+    }
+
+    public int getRemoteAPIPort() {
+        return remoteAPIPort;
+    }
+
+    public JsonNode getCreateContainerPayload() {
+        return createContainerPayload;
+    }
+
+    public String getCreateContainerURL() {
+        return createContainerURL;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/9f0eb33c/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerHttpResponse.java
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerHttpResponse.java b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerHttpResponse.java
new file mode 100644
index 0000000..336bca9
--- /dev/null
+++ b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerHttpResponse.java
@@ -0,0 +1,49 @@
+/*
+* 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.taverna.activities.docker;
+
+import org.apache.http.Header;
+
+public class DockerHttpResponse {
+
+    private Header[] headers;
+
+    private int statusCode;
+
+    private String body;
+
+    public DockerHttpResponse(Header[] headers, int statusCode, String body) {
+        this.headers = headers;
+        this.statusCode = statusCode;
+        this.body = body;
+    }
+
+    public Header[] getHeaders() {
+        return headers;
+    }
+
+    public int getStatusCode() {
+        return statusCode;
+    }
+
+    public String getBody() {
+        return body;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/9f0eb33c/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/RESTUtil.java
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/RESTUtil.java b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/RESTUtil.java
index 460f275..99fff51 100644
--- a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/RESTUtil.java
+++ b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/RESTUtil.java
@@ -19,5 +19,162 @@
 
 package org.apache.taverna.activities.docker;
 
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.SingleClientConnManager;
+import org.apache.http.message.BasicHeader;
+import org.apache.http.ssl.SSLContexts;
+import org.apache.log4j.Logger;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.security.cert.CertificateException;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.KeyManagementException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
 public class RESTUtil {
+
+    /**
+     * Http header name for content type
+     */
+    private static final String CONTENT_TYPE = "Content-Type";
+
+    /**
+     * Http content type value for JSON messages.
+     */
+    private static final String JSON_CONTENT_TYPE = "application/json";
+
+    /**
+     * Logger
+     */
+    private static Logger LOG = Logger.getLogger(RESTUtil.class);
+
+
+    public static boolean createContainer(DockerConfig dockerConfig) {
+        try {
+            URL url = new URL(dockerConfig.getCreateContainerURL());
+            org.apache.http.conn.ssl.SSLSocketFactory factory = new org.apache.http.conn.ssl.SSLSocketFactory(SSLContext.getDefault());
+            Scheme https = new Scheme(DockerConfig.PROTOCOL,factory , url.getPort());
+            SchemeRegistry schemeRegistry = new SchemeRegistry();
+            schemeRegistry.register(https);
+            ClientConnectionManager connectionManager = new SingleClientConnManager(null, schemeRegistry);
+            Map<String,String> headers = new HashMap<String,String>();
+            headers.put(CONTENT_TYPE, JSON_CONTENT_TYPE);
+            DockerHttpResponse response = doPost(connectionManager,dockerConfig.getCreateContainerURL(), headers, dockerConfig.getCreateContainerPayload());
+            if(response.getStatusCode() == 201){
+                JsonNode node = getJson(response.getBody());
+                LOG.info(String.format("Successfully created Docker container id: %s ", getDockerId(node)));
+                return true;
+            }
+
+        } catch (MalformedURLException e1) {
+            LOG.error(String.format("Malformed URL encountered. This can be due to invalid URL parts. " +
+                            "Docker Host=%s, Port=%d and Resource Path=%s",
+                    dockerConfig.getContainerHost(),
+                    dockerConfig.getRemoteAPIPort(),
+                    DockerConfig.CREATE_CONTAINER_RESOURCE_PATH), e1);
+        } catch (NoSuchAlgorithmException e2) {
+            LOG.error("Failed to create SSLContext for invoking the REST service over https.", e2);
+        } catch (IOException e3) {
+            LOG.error("Error occurred while reading the docker http response", e3);
+        }
+        return false;
+    }
+
+    private static DockerHttpResponse doPost(ClientConnectionManager connectionManager, String url, Map<String, String> headers, JsonNode payload) {
+        DefaultHttpClient httpClient = null;
+        CloseableHttpResponse response = null;
+        DockerHttpResponse dockerResponse = null;
+        HttpPost httpPost = null;
+        try {
+            httpPost = new HttpPost(url);
+            HttpEntity entity = new StringEntity(payload.toString());
+            httpPost.setEntity(entity);
+            for (Map.Entry<String, String> entry : headers.entrySet()) {
+                httpPost.setHeader(new BasicHeader(entry.getKey(), entry.getValue()));
+            }
+            httpClient = new DefaultHttpClient(connectionManager, null);
+            response = httpClient.execute(httpPost);
+            if (response != null) {
+                dockerResponse = new DockerHttpResponse(response.getAllHeaders(), response.getStatusLine().getStatusCode(),readBody(response.getEntity()).toString());
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+            LOG.error("Failed to complete Http POST invocation", e);
+            dockerResponse = new DockerHttpResponse(new Header[]{new BasicHeader(
+                    CONTENT_TYPE, JSON_CONTENT_TYPE)},
+                    500,
+                    "{\"error\":\"internal server error\", \"message\":\""+ e.getMessage() +"\"}");
+        } finally {
+            if(httpPost != null){
+              httpPost.releaseConnection();
+            }
+            if (httpClient != null) {
+                httpClient.close();
+            }
+            if (response != null) {
+                try {
+                    response.close();
+                } catch (IOException ignore) {}
+            }
+        }
+      return dockerResponse;
+    }
+
+    private static StringBuilder readBody(HttpEntity entity) throws IOException {
+        String charset = null;
+        String contentType = entity.getContentType().getValue().toLowerCase();
+        String[] contentTypeParts = contentType.split(";");
+        for (String contentTypePart : contentTypeParts) {
+            contentTypePart = contentTypePart.trim();
+            if (contentTypePart.startsWith("charset=")) {
+                charset = contentTypePart.substring("charset=".length());
+            }
+        }
+        BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent(), charset != null ? charset : "UTF-8"));
+        String str;
+        StringBuilder responseBuilder = new StringBuilder();
+        while ((str = reader.readLine()) != null) {
+            responseBuilder.append(str + "\n");
+         }
+        return responseBuilder;
+    }
+
+    private static JsonNode getJson(String s) throws IOException {
+        ObjectMapper mapper = new ObjectMapper();
+        return mapper.readTree(s);
+    }
+
+    private static String getDockerId(JsonNode node){
+        String dockerId = null;
+        Iterator<JsonNode> itr = node.elements();
+        while(itr.hasNext()){
+            JsonNode child = itr.next();
+            if("id".equalsIgnoreCase(child.textValue())){
+                dockerId =  child.textValue();
+                break;
+            }
+        }
+        return dockerId;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/9f0eb33c/taverna-docker-activity/src/test/java/org/apache/taverna/activities/docker/test/TestCreateContainer.java
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/src/test/java/org/apache/taverna/activities/docker/test/TestCreateContainer.java b/taverna-docker-activity/src/test/java/org/apache/taverna/activities/docker/test/TestCreateContainer.java
new file mode 100644
index 0000000..bd68abb
--- /dev/null
+++ b/taverna-docker-activity/src/test/java/org/apache/taverna/activities/docker/test/TestCreateContainer.java
@@ -0,0 +1,43 @@
+/*
+* 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.taverna.activities.docker.test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.taverna.activities.docker.DockerConfig;
+import org.apache.taverna.activities.docker.RESTUtil;
+import org.junit.Test;
+
+import java.io.IOException;
+
+public class TestCreateContainer{
+
+//    @Test
+//    public void testCreateContainer(){
+//        try {
+//            String payload = "{\"Hostname\":\"foo.com\", \"User\":\"foo\", \"Memory\":0, \"MemorySwap\":0,\"AttachStdin\":false, \"AttachStdout\":true,\"Attachstderr\":true,\"PortSpecs\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":null, \"Cmd\":[\"date\"], \"Image\":\"ubuntu\",\"Tag\":\"latest\",\"Volumes\":{\"/tmp\":{} },\"WorkingDir\":\"\",\"DisableNetwork\":false, \"ExposedPorts\":{\"22/tcp\": {} }}";
+//            DockerConfig config = new DockerConfig("192.168.99.100",2376, new ObjectMapper().readTree(payload));
+//            boolean res = RESTUtil.createContainer(config);
+//            System.out.println(">>>" + res);
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        }
+//
+//    }
+}


[4/5] incubator-taverna-common-activities git commit: Implementing Configurable

Posted by st...@apache.org.
Implementing Configurable


Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/commit/d4e585bb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/tree/d4e585bb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/diff/d4e585bb

Branch: refs/heads/docker
Commit: d4e585bbea04f21e24801f3efcafa3546f37d9f0
Parents: 7da6ffe
Author: Nadeesh Dilanga <na...@gmail.com>
Authored: Tue Jun 21 03:03:15 2016 -0400
Committer: Nadeesh Dilanga <na...@gmail.com>
Committed: Tue Jun 21 03:03:15 2016 -0400

----------------------------------------------------------------------
 taverna-docker-activity/pom.xml                 |   7 +-
 .../activities/docker/DockerActivity.java       |   4 +-
 .../docker/DockerActivityFactory.java           |  60 ---------
 .../docker/DockerContainerConfiguration.java    |  87 -------------
 .../DockerContainerConfigurationImpl.java       | 124 +++++++++++++++++++
 .../taverna/activities/docker/RESTUtil.java     |  18 +--
 .../spring/docker-activity-context-osgi.xml     |   3 +-
 .../META-INF/spring/docker-activity-context.xml |   7 +-
 .../docker/test/TestCreateContainer.java        |  25 ++--
 9 files changed, 160 insertions(+), 175 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/d4e585bb/taverna-docker-activity/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/pom.xml b/taverna-docker-activity/pom.xml
index d972584..5daed36 100644
--- a/taverna-docker-activity/pom.xml
+++ b/taverna-docker-activity/pom.xml
@@ -45,7 +45,12 @@
 			<artifactId>taverna-app-configuration-api</artifactId>
 			<version>${taverna.osgi.version}</version>
 		</dependency>
-		<dependency>
+        <dependency>
+            <groupId>org.apache.taverna.osgi</groupId>
+            <artifactId>taverna-configuration-api</artifactId>
+            <version>${taverna.osgi.version}</version>
+        </dependency>
+        <dependency>
 			<groupId>junit</groupId>
 			<artifactId>junit</artifactId>
 			<version>${junit.version}</version>

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/d4e585bb/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivity.java
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivity.java b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivity.java
index 902eaac..4cae049 100644
--- a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivity.java
+++ b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivity.java
@@ -36,9 +36,9 @@ import java.util.Map;
 public class DockerActivity extends AbstractAsynchronousActivity<JsonNode> {
 
     private JsonNode activityConfig;
-    private DockerContainerConfiguration containerConfiguration;
+    private DockerContainerConfigurationImpl containerConfiguration;
 
-    public DockerActivity(DockerContainerConfiguration containerConfiguration) {
+    public DockerActivity(DockerContainerConfigurationImpl containerConfiguration) {
         this.containerConfiguration = containerConfiguration;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/d4e585bb/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivityFactory.java
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivityFactory.java b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivityFactory.java
deleted file mode 100644
index 7dea3e8..0000000
--- a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivityFactory.java
+++ /dev/null
@@ -1,60 +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.taverna.activities.docker;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import org.apache.taverna.workflowmodel.processor.activity.*;
-
-import java.net.URI;
-import java.util.Set;
-
-public class DockerActivityFactory implements ActivityFactory {
-
-    private DockerContainerConfiguration containerConfiguration;
-
-    @Override
-    public Activity<?> createActivity() {
-        return new DockerActivity(containerConfiguration);
-    }
-
-    @Override
-    public URI getActivityType() {
-        return null;
-    }
-
-    @Override
-    public JsonNode getActivityConfigurationSchema() {
-        return null;
-    }
-
-    @Override
-    public Set<ActivityInputPort> getInputPorts(JsonNode jsonNode) throws ActivityConfigurationException {
-        return null;
-    }
-
-    @Override
-    public Set<ActivityOutputPort> getOutputPorts(JsonNode jsonNode) throws ActivityConfigurationException {
-        return null;
-    }
-
-
-    public void setDockerConfigurationManagerManager(DockerContainerConfiguration dockerContainerConfiguration) {
-        this.containerConfiguration = containerConfiguration;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/d4e585bb/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerContainerConfiguration.java
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerContainerConfiguration.java b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerContainerConfiguration.java
deleted file mode 100644
index 3d8346f..0000000
--- a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerContainerConfiguration.java
+++ /dev/null
@@ -1,87 +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.taverna.activities.docker;
-
-import com.fasterxml.jackson.databind.JsonNode;
-
-public class DockerContainerConfiguration {
-
-    /**
-     * Hold the hostname of the docker container.
-     */
-    private String containerHost;
-
-    /**
-     * Remote REST API port exposed by Docker
-     */
-    private int remoteAPIPort = 443;
-
-    /**
-     * JSON payload to invoke create container REST API.
-     */
-    private JsonNode createContainerPayload;
-
-    /**
-     * Complete HTTP URL for create container
-     */
-    private final String createContainerURL;
-
-    /**
-     * Docker remote REST resource path for creating a container
-     */
-    public static final String CREATE_CONTAINER_RESOURCE_PATH = "/containers/create";
-
-    /**
-     * Identifier for Http over SSL protocol
-     */
-    public static final String HTTP_OVER_SSL = "https";
-
-    /**
-     * Transport protocol
-     */
-    private String protocol = "http";
-
-    public DockerContainerConfiguration(String containerHost, int remoteAPIPort, String protocol, JsonNode createContainerPayload) {
-        this.containerHost = containerHost;
-        this.remoteAPIPort = remoteAPIPort;
-        this.protocol = protocol;
-        this.createContainerPayload = createContainerPayload;
-        this.createContainerURL = protocol + "://" + containerHost +  ":" + remoteAPIPort + CREATE_CONTAINER_RESOURCE_PATH ;
-    }
-
-    public String getContainerHost() {
-        return containerHost;
-    }
-
-    public String getProtocol() {
-        return protocol;
-    }
-
-    public int getRemoteAPIPort() {
-        return remoteAPIPort;
-    }
-
-    public JsonNode getCreateContainerPayload() {
-        return createContainerPayload;
-    }
-
-    public String getCreateContainerURL() {
-        return createContainerURL;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/d4e585bb/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerContainerConfigurationImpl.java
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerContainerConfigurationImpl.java b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerContainerConfigurationImpl.java
new file mode 100644
index 0000000..8a4a379
--- /dev/null
+++ b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerContainerConfigurationImpl.java
@@ -0,0 +1,124 @@
+/*
+* 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.taverna.activities.docker;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.taverna.configuration.AbstractConfigurable;
+import org.apache.taverna.configuration.Configurable;
+import org.apache.taverna.configuration.ConfigurationManager;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class DockerContainerConfigurationImpl extends AbstractConfigurable {
+
+    /**
+     * Key for Remote host
+     */
+    public static final String CONTAINER_REMOTE_HOST = "key-cnt-host";
+
+    /**
+     * Key for transport protocol
+     */
+    public static final String PROTOCOL = "key-cnt-protocol";
+
+    /**
+     * Key for Remote port
+     */
+    public static final String CONTAINER_REMOTE_PORT = "key-cnt-port";
+
+    /**
+     * Key for create container payload. Here we accept entire JSON payload as the value of this key in hash map.
+     */
+    public static final String CONTAINER_CREATE_PAYLOAD = "key-cnt-create-payload";
+
+    /**
+     * Docker remote REST resource path for creating a container
+     */
+    public static final String CREATE_CONTAINER_RESOURCE_PATH = "/containers/create";
+
+    /**
+     * Identifier for Http over SSL protocol
+     */
+    public static final String HTTP_OVER_SSL = "https";
+
+    /**
+     * Transport protocol
+     */
+    private String protocol = "http";
+
+
+
+    public DockerContainerConfigurationImpl(ConfigurationManager configurationManager){
+        super(configurationManager);
+
+    }
+
+    public String getContainerHost() {
+        return getInternalPropertyMap().get(CONTAINER_REMOTE_HOST);
+    }
+
+    public String getProtocol() {
+        return getInternalPropertyMap().get(PROTOCOL);
+    }
+
+    public int getRemoteAPIPort() {
+        return Integer.parseInt(getInternalPropertyMap().get(CONTAINER_REMOTE_PORT));
+    }
+
+    public JsonNode getCreateContainerPayload() throws IOException {
+      return new ObjectMapper().readTree(getInternalPropertyMap().get(CONTAINER_CREATE_PAYLOAD));
+    }
+
+    public String getCreateContainerURL() {
+       return getProtocol() + "://" + getContainerHost() +  ":" + getRemoteAPIPort() + CREATE_CONTAINER_RESOURCE_PATH;
+    }
+
+    @Override
+    public Map<String, String> getDefaultPropertyMap() {
+        Map<String,String> defaultMap = new HashMap<String,String>();
+        return defaultMap;
+    }
+
+    @Override
+    public String getUUID() {
+        return "6BR3F5C1-DK8D-4893-8D9B-2F46FA1DDB87";
+    }
+
+    @Override
+    public String getDisplayName() {
+        return "Docker Config";
+    }
+
+    @Override
+    public String getFilePrefix() {
+        return "Docker";
+    }
+
+    @Override
+    public String getCategory() {
+        return null;
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/d4e585bb/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/RESTUtil.java
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/RESTUtil.java b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/RESTUtil.java
index b052fdb..0c24859 100644
--- a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/RESTUtil.java
+++ b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/RESTUtil.java
@@ -73,14 +73,14 @@ public class RESTUtil {
     private static Logger LOG = Logger.getLogger(RESTUtil.class);
 
 
-    public static DockerHttpResponse createContainer(DockerContainerConfiguration dockerContainerConfiguration) {
+    public static DockerHttpResponse createContainer(DockerContainerConfigurationImpl dockerContainerConfigurationImpl) {
         String errMsg;
         try {
             ClientConnectionManager connectionManager = null;
-            URL url = new URL(dockerContainerConfiguration.getCreateContainerURL());
-            if(DockerContainerConfiguration.HTTP_OVER_SSL.equalsIgnoreCase(dockerContainerConfiguration.getProtocol())) {
+            URL url = new URL(dockerContainerConfigurationImpl.getCreateContainerURL());
+            if(DockerContainerConfigurationImpl.HTTP_OVER_SSL.equalsIgnoreCase(dockerContainerConfigurationImpl.getProtocol())) {
                 org.apache.http.conn.ssl.SSLSocketFactory factory = new org.apache.http.conn.ssl.SSLSocketFactory(SSLContext.getDefault());
-                Scheme https = new Scheme(dockerContainerConfiguration.getProtocol(), factory, url.getPort());
+                Scheme https = new Scheme(dockerContainerConfigurationImpl.getProtocol(), factory, url.getPort());
                 SchemeRegistry schemeRegistry = new SchemeRegistry();
                 schemeRegistry.register(https);
                 connectionManager = new SingleClientConnManager(null, schemeRegistry);
@@ -88,7 +88,7 @@ public class RESTUtil {
 
             Map<String,String> headers = new HashMap<String,String>();
             headers.put(CONTENT_TYPE, JSON_CONTENT_TYPE);
-            DockerHttpResponse response = doPost(connectionManager, dockerContainerConfiguration.getCreateContainerURL(), headers, dockerContainerConfiguration.getCreateContainerPayload());
+            DockerHttpResponse response = doPost(connectionManager, dockerContainerConfigurationImpl.getCreateContainerURL(), headers, dockerContainerConfigurationImpl.getCreateContainerPayload());
             if(response.getStatusCode() == DockerHttpResponse.HTTP_201_CODE){
                 JsonNode node = getJson(response.getBody());
                 LOG.info(String.format("Successfully created Docker container id: %s ", getDockerId(node)));
@@ -98,13 +98,13 @@ public class RESTUtil {
         } catch (MalformedURLException e1) {
             errMsg = String.format("Malformed URL encountered. This can be due to invalid URL parts. " +
                             "Docker Host=%s, Port=%d and Resource Path=%s",
-                    dockerContainerConfiguration.getContainerHost(),
-                    dockerContainerConfiguration.getRemoteAPIPort(),
-                    DockerContainerConfiguration.CREATE_CONTAINER_RESOURCE_PATH);
+                    dockerContainerConfigurationImpl.getContainerHost(),
+                    dockerContainerConfigurationImpl.getRemoteAPIPort(),
+                    DockerContainerConfigurationImpl.CREATE_CONTAINER_RESOURCE_PATH);
             LOG.error(errMsg, e1);
         } catch (NoSuchAlgorithmException e2) {
             errMsg = "Failed to create SSLContext for invoking the REST service over https." + e2.getMessage();
-            LOG.error(dockerContainerConfiguration);
+            LOG.error(dockerContainerConfigurationImpl);
         } catch (IOException e3) {
             errMsg = "Error occurred while reading the docker http response " + e3.getMessage();
             LOG.error(errMsg, e3);

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/d4e585bb/taverna-docker-activity/src/main/resources/META-INF/spring/docker-activity-context-osgi.xml
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/src/main/resources/META-INF/spring/docker-activity-context-osgi.xml b/taverna-docker-activity/src/main/resources/META-INF/spring/docker-activity-context-osgi.xml
index fa93613..6875bfb 100755
--- a/taverna-docker-activity/src/main/resources/META-INF/spring/docker-activity-context-osgi.xml
+++ b/taverna-docker-activity/src/main/resources/META-INF/spring/docker-activity-context-osgi.xml
@@ -24,5 +24,6 @@
                       http://www.springframework.org/schema/osgi
                       http://www.springframework.org/schema/osgi/spring-osgi.xsd">
 
-	<reference id="dockerContainerConfiguration" interface="org.apache.taverna.activities.docker.DockerContainerConfiguration" />
+    <reference id="configurationManager" interface="org.apache.taverna.configuration.ConfigurationManager" />
+
 </beans:beans>

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/d4e585bb/taverna-docker-activity/src/main/resources/META-INF/spring/docker-activity-context.xml
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/src/main/resources/META-INF/spring/docker-activity-context.xml b/taverna-docker-activity/src/main/resources/META-INF/spring/docker-activity-context.xml
index 0378064..c3bb871 100755
--- a/taverna-docker-activity/src/main/resources/META-INF/spring/docker-activity-context.xml
+++ b/taverna-docker-activity/src/main/resources/META-INF/spring/docker-activity-context.xml
@@ -21,8 +21,9 @@
 	xsi:schemaLocation="http://www.springframework.org/schema/beans
                       http://www.springframework.org/schema/beans/spring-beans.xsd">
 
-	<bean id="dockerActivityFactory" class="org.apache.taverna.activities.docker.DockerActivityFactory">
-		<property name="dockerContainerConfiguration" ref="dockerContainerConfiguration" />
-	</bean>
+    <bean id="dockerConfiguration"
+          class="org.apache.taverna.activities.docker.DockerContainerConfigurationImpl">
+        <constructor-arg name="configurationManager" ref="configurationManager" />
+    </bean>
 
 </beans>

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/d4e585bb/taverna-docker-activity/src/test/java/org/apache/taverna/activities/docker/test/TestCreateContainer.java
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/src/test/java/org/apache/taverna/activities/docker/test/TestCreateContainer.java b/taverna-docker-activity/src/test/java/org/apache/taverna/activities/docker/test/TestCreateContainer.java
index b54fd13..a82c746 100644
--- a/taverna-docker-activity/src/test/java/org/apache/taverna/activities/docker/test/TestCreateContainer.java
+++ b/taverna-docker-activity/src/test/java/org/apache/taverna/activities/docker/test/TestCreateContainer.java
@@ -20,7 +20,7 @@
 package org.apache.taverna.activities.docker.test;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.taverna.activities.docker.DockerContainerConfiguration;
+import org.apache.taverna.activities.docker.DockerContainerConfigurationImpl;
 import org.apache.taverna.activities.docker.DockerHttpResponse;
 import org.apache.taverna.activities.docker.RESTUtil;
 import org.junit.Test;
@@ -29,15 +29,16 @@ import java.io.IOException;
 
 public class TestCreateContainer{
 
-    @Test
-    public void testCreateContainer(){
-        try {
-            String payload = "{\"Hostname\":\"192.168.99.100\", \"User\":\"foo\", \"Memory\":0, \"MemorySwap\":0,\"AttachStdin\":false, \"AttachStdout\":true,\"Attachstderr\":true,\"PortSpecs\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":null, \"Cmd\":[\"date\"], \"Image\":\"ubuntu\",\"Tag\":\"latest\",\"Volumes\":{\"/tmp\":{} },\"WorkingDir\":\"\",\"DisableNetwork\":false, \"ExposedPorts\":{\"22/tcp\": {} }}";
-            DockerContainerConfiguration config = new DockerContainerConfiguration("192.168.99.100",2376,"https",new ObjectMapper().readTree(payload));
-            DockerHttpResponse res = RESTUtil.createContainer(config);
-            System.out.println(">>>" + res.toString());
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-    }
+
+//    @Test
+//    public void testCreateContainer(){
+//        try {
+//             String payload = "{\"Image\":\"6fae60ef3446\", \"ExposedPorts\":{\"8080/tcp\":{}}}";
+//             DockerContainerConfigurationImpl config = new DockerContainerConfigurationImpl("192.168.99.100",2376,"https",new ObjectMapper().readTree(payload));
+//            DockerHttpResponse res = RESTUtil.createContainer(config);
+//            System.out.println(">>>" + res.toString());
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        }
+//    }
 }


[3/5] incubator-taverna-common-activities git commit: Spring enabled configuration for docker container creation phase1.

Posted by st...@apache.org.
Spring enabled configuration for docker container creation phase1.


Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/commit/7da6ffef
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/tree/7da6ffef
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/diff/7da6ffef

Branch: refs/heads/docker
Commit: 7da6ffef0bdc8d042867fa29db48443a9019d6f4
Parents: 9f0eb33
Author: Nadeesh Dilanga <na...@gmail.com>
Authored: Sat Jun 18 02:47:22 2016 -0400
Committer: Nadeesh Dilanga <na...@gmail.com>
Committed: Sat Jun 18 02:47:22 2016 -0400

----------------------------------------------------------------------
 .../activities/docker/DockerActivity.java       | 26 +++++-
 .../docker/DockerActivityFactory.java           | 60 ++++++++++++++
 .../taverna/activities/docker/DockerConfig.java | 77 -----------------
 .../docker/DockerContainerConfiguration.java    | 87 ++++++++++++++++++++
 .../activities/docker/DockerHttpResponse.java   |  2 +
 .../taverna/activities/docker/RESTUtil.java     | 78 +++++++++++-------
 .../spring/docker-activity-context-osgi.xml     | 28 +++++++
 .../META-INF/spring/docker-activity-context.xml | 28 +++++++
 .../docker/test/TestCreateContainer.java        | 26 +++---
 9 files changed, 293 insertions(+), 119 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/7da6ffef/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivity.java
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivity.java b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivity.java
index c81e9de..902eaac 100644
--- a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivity.java
+++ b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivity.java
@@ -20,12 +20,14 @@ package org.apache.taverna.activities.docker;
 
 import com.fasterxml.jackson.databind.JsonNode;
 import org.apache.taverna.invocation.InvocationContext;
+import org.apache.taverna.reference.ErrorDocument;
 import org.apache.taverna.reference.ReferenceService;
 import org.apache.taverna.reference.T2Reference;
 import org.apache.taverna.workflowmodel.processor.activity.AbstractAsynchronousActivity;
 import org.apache.taverna.workflowmodel.processor.activity.ActivityConfigurationException;
 import org.apache.taverna.workflowmodel.processor.activity.AsynchronousActivityCallback;
 
+import java.util.HashMap;
 import java.util.Map;
 
 /**
@@ -34,6 +36,11 @@ import java.util.Map;
 public class DockerActivity extends AbstractAsynchronousActivity<JsonNode> {
 
     private JsonNode activityConfig;
+    private DockerContainerConfiguration containerConfiguration;
+
+    public DockerActivity(DockerContainerConfiguration containerConfiguration) {
+        this.containerConfiguration = containerConfiguration;
+    }
 
     @Override
     public void configure(JsonNode activityConfig) throws ActivityConfigurationException {
@@ -50,9 +57,26 @@ public class DockerActivity extends AbstractAsynchronousActivity<JsonNode> {
         callback.requestRun(new Runnable() {
             @Override
             public void run() {
+                Map<String, T2Reference> outputs = new HashMap<String, T2Reference>();
+                T2Reference responseBodyRef = null;
+
                 InvocationContext context = callback.getContext();
                 ReferenceService referenceService = context.getReferenceService();
-                //TODO invoke container remote api and set final response result to callback.receiveResult();
+
+                DockerHttpResponse response = RESTUtil.createContainer(containerConfiguration);
+                if(response != null && response.getStatusCode() == DockerHttpResponse.HTTP_201_CODE){
+                    responseBodyRef = referenceService.register(response.getBody(), 0, true, context);
+                } else {
+                    ErrorDocument errorDocument = referenceService.getErrorDocumentService().registerError(response.getBody(),0,context);
+                    responseBodyRef = referenceService.register(errorDocument, 0, true, context);
+                }
+
+                outputs.put("response_body", responseBodyRef);
+                T2Reference statusRef = referenceService.register(response.getStatusCode(), 0, true, context);
+                outputs.put("response_code", statusRef);
+                //TODO add any more useful parameters to the output
+
+                callback.receiveResult(outputs, new int[0]);
 
             }
         });

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/7da6ffef/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivityFactory.java
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivityFactory.java b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivityFactory.java
new file mode 100644
index 0000000..7dea3e8
--- /dev/null
+++ b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerActivityFactory.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.taverna.activities.docker;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.taverna.workflowmodel.processor.activity.*;
+
+import java.net.URI;
+import java.util.Set;
+
+public class DockerActivityFactory implements ActivityFactory {
+
+    private DockerContainerConfiguration containerConfiguration;
+
+    @Override
+    public Activity<?> createActivity() {
+        return new DockerActivity(containerConfiguration);
+    }
+
+    @Override
+    public URI getActivityType() {
+        return null;
+    }
+
+    @Override
+    public JsonNode getActivityConfigurationSchema() {
+        return null;
+    }
+
+    @Override
+    public Set<ActivityInputPort> getInputPorts(JsonNode jsonNode) throws ActivityConfigurationException {
+        return null;
+    }
+
+    @Override
+    public Set<ActivityOutputPort> getOutputPorts(JsonNode jsonNode) throws ActivityConfigurationException {
+        return null;
+    }
+
+
+    public void setDockerConfigurationManagerManager(DockerContainerConfiguration dockerContainerConfiguration) {
+        this.containerConfiguration = containerConfiguration;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/7da6ffef/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerConfig.java
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerConfig.java b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerConfig.java
deleted file mode 100644
index 30d12c5..0000000
--- a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerConfig.java
+++ /dev/null
@@ -1,77 +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.taverna.activities.docker;
-
-import com.fasterxml.jackson.databind.JsonNode;
-
-public class DockerConfig {
-
-    /**
-     * Hold the hostname of the docker container.
-     */
-    private String containerHost;
-
-    /**
-     * Remote REST API port exposed by Docker
-     */
-    private int remoteAPIPort = 443;
-
-    /**
-     * JSON payload to invoke create container REST API.
-     */
-    private JsonNode createContainerPayload;
-
-    /**
-     * Complete HTTP URL for create container
-     */
-    private final String createContainerURL;
-
-    /**
-     * Docker remote REST resource path for creating a container
-     */
-    public static final String CREATE_CONTAINER_RESOURCE_PATH = "/containers/create";
-
-    /**
-     * Transport protocol
-     */
-    public static final String PROTOCOL = "https";
-
-    public DockerConfig(String containerHost, int remoteAPIPort, JsonNode createContainerPayload) {
-        this.containerHost = containerHost;
-        this.remoteAPIPort = remoteAPIPort;
-        this.createContainerPayload = createContainerPayload;
-        this.createContainerURL = PROTOCOL + "://" + containerHost +  ":" + remoteAPIPort + CREATE_CONTAINER_RESOURCE_PATH ;
-    }
-
-    public String getContainerHost() {
-        return containerHost;
-    }
-
-    public int getRemoteAPIPort() {
-        return remoteAPIPort;
-    }
-
-    public JsonNode getCreateContainerPayload() {
-        return createContainerPayload;
-    }
-
-    public String getCreateContainerURL() {
-        return createContainerURL;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/7da6ffef/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerContainerConfiguration.java
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerContainerConfiguration.java b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerContainerConfiguration.java
new file mode 100644
index 0000000..3d8346f
--- /dev/null
+++ b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerContainerConfiguration.java
@@ -0,0 +1,87 @@
+/*
+* 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.taverna.activities.docker;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+public class DockerContainerConfiguration {
+
+    /**
+     * Hold the hostname of the docker container.
+     */
+    private String containerHost;
+
+    /**
+     * Remote REST API port exposed by Docker
+     */
+    private int remoteAPIPort = 443;
+
+    /**
+     * JSON payload to invoke create container REST API.
+     */
+    private JsonNode createContainerPayload;
+
+    /**
+     * Complete HTTP URL for create container
+     */
+    private final String createContainerURL;
+
+    /**
+     * Docker remote REST resource path for creating a container
+     */
+    public static final String CREATE_CONTAINER_RESOURCE_PATH = "/containers/create";
+
+    /**
+     * Identifier for Http over SSL protocol
+     */
+    public static final String HTTP_OVER_SSL = "https";
+
+    /**
+     * Transport protocol
+     */
+    private String protocol = "http";
+
+    public DockerContainerConfiguration(String containerHost, int remoteAPIPort, String protocol, JsonNode createContainerPayload) {
+        this.containerHost = containerHost;
+        this.remoteAPIPort = remoteAPIPort;
+        this.protocol = protocol;
+        this.createContainerPayload = createContainerPayload;
+        this.createContainerURL = protocol + "://" + containerHost +  ":" + remoteAPIPort + CREATE_CONTAINER_RESOURCE_PATH ;
+    }
+
+    public String getContainerHost() {
+        return containerHost;
+    }
+
+    public String getProtocol() {
+        return protocol;
+    }
+
+    public int getRemoteAPIPort() {
+        return remoteAPIPort;
+    }
+
+    public JsonNode getCreateContainerPayload() {
+        return createContainerPayload;
+    }
+
+    public String getCreateContainerURL() {
+        return createContainerURL;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/7da6ffef/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerHttpResponse.java
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerHttpResponse.java b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerHttpResponse.java
index 336bca9..5ac5b8e 100644
--- a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerHttpResponse.java
+++ b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerHttpResponse.java
@@ -23,6 +23,8 @@ import org.apache.http.Header;
 
 public class DockerHttpResponse {
 
+    public static final int HTTP_201_CODE = 201;
+
     private Header[] headers;
 
     private int statusCode;

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/7da6ffef/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/RESTUtil.java
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/RESTUtil.java b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/RESTUtil.java
index 99fff51..b052fdb 100644
--- a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/RESTUtil.java
+++ b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/RESTUtil.java
@@ -23,29 +23,27 @@ import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.http.Header;
 import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.conn.ClientConnectionManager;
 import org.apache.http.conn.scheme.Scheme;
 import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
 import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.HttpClients;
 import org.apache.http.impl.conn.SingleClientConnManager;
 import org.apache.http.message.BasicHeader;
-import org.apache.http.ssl.SSLContexts;
 import org.apache.log4j.Logger;
 
 import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSocketFactory;
-import javax.security.cert.CertificateException;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.security.KeyManagementException;
-import java.security.KeyStoreException;
 import java.security.NoSuchAlgorithmException;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -64,45 +62,59 @@ public class RESTUtil {
     private static final String JSON_CONTENT_TYPE = "application/json";
 
     /**
+     *
+     */
+    private static final String DEFAULT_ERROR_MSG= "{\"type\";\"Internal server error\"}";
+
+
+    /**
      * Logger
      */
     private static Logger LOG = Logger.getLogger(RESTUtil.class);
 
 
-    public static boolean createContainer(DockerConfig dockerConfig) {
+    public static DockerHttpResponse createContainer(DockerContainerConfiguration dockerContainerConfiguration) {
+        String errMsg;
         try {
-            URL url = new URL(dockerConfig.getCreateContainerURL());
-            org.apache.http.conn.ssl.SSLSocketFactory factory = new org.apache.http.conn.ssl.SSLSocketFactory(SSLContext.getDefault());
-            Scheme https = new Scheme(DockerConfig.PROTOCOL,factory , url.getPort());
-            SchemeRegistry schemeRegistry = new SchemeRegistry();
-            schemeRegistry.register(https);
-            ClientConnectionManager connectionManager = new SingleClientConnManager(null, schemeRegistry);
+            ClientConnectionManager connectionManager = null;
+            URL url = new URL(dockerContainerConfiguration.getCreateContainerURL());
+            if(DockerContainerConfiguration.HTTP_OVER_SSL.equalsIgnoreCase(dockerContainerConfiguration.getProtocol())) {
+                org.apache.http.conn.ssl.SSLSocketFactory factory = new org.apache.http.conn.ssl.SSLSocketFactory(SSLContext.getDefault());
+                Scheme https = new Scheme(dockerContainerConfiguration.getProtocol(), factory, url.getPort());
+                SchemeRegistry schemeRegistry = new SchemeRegistry();
+                schemeRegistry.register(https);
+                connectionManager = new SingleClientConnManager(null, schemeRegistry);
+            }
+
             Map<String,String> headers = new HashMap<String,String>();
             headers.put(CONTENT_TYPE, JSON_CONTENT_TYPE);
-            DockerHttpResponse response = doPost(connectionManager,dockerConfig.getCreateContainerURL(), headers, dockerConfig.getCreateContainerPayload());
-            if(response.getStatusCode() == 201){
+            DockerHttpResponse response = doPost(connectionManager, dockerContainerConfiguration.getCreateContainerURL(), headers, dockerContainerConfiguration.getCreateContainerPayload());
+            if(response.getStatusCode() == DockerHttpResponse.HTTP_201_CODE){
                 JsonNode node = getJson(response.getBody());
                 LOG.info(String.format("Successfully created Docker container id: %s ", getDockerId(node)));
-                return true;
+                return response;
             }
 
         } catch (MalformedURLException e1) {
-            LOG.error(String.format("Malformed URL encountered. This can be due to invalid URL parts. " +
+            errMsg = String.format("Malformed URL encountered. This can be due to invalid URL parts. " +
                             "Docker Host=%s, Port=%d and Resource Path=%s",
-                    dockerConfig.getContainerHost(),
-                    dockerConfig.getRemoteAPIPort(),
-                    DockerConfig.CREATE_CONTAINER_RESOURCE_PATH), e1);
+                    dockerContainerConfiguration.getContainerHost(),
+                    dockerContainerConfiguration.getRemoteAPIPort(),
+                    DockerContainerConfiguration.CREATE_CONTAINER_RESOURCE_PATH);
+            LOG.error(errMsg, e1);
         } catch (NoSuchAlgorithmException e2) {
-            LOG.error("Failed to create SSLContext for invoking the REST service over https.", e2);
+            errMsg = "Failed to create SSLContext for invoking the REST service over https." + e2.getMessage();
+            LOG.error(dockerContainerConfiguration);
         } catch (IOException e3) {
-            LOG.error("Error occurred while reading the docker http response", e3);
+            errMsg = "Error occurred while reading the docker http response " + e3.getMessage();
+            LOG.error(errMsg, e3);
         }
-        return false;
+        return null;
     }
 
     private static DockerHttpResponse doPost(ClientConnectionManager connectionManager, String url, Map<String, String> headers, JsonNode payload) {
-        DefaultHttpClient httpClient = null;
-        CloseableHttpResponse response = null;
+        HttpClient httpClient = null;
+        HttpResponse response = null;
         DockerHttpResponse dockerResponse = null;
         HttpPost httpPost = null;
         try {
@@ -112,7 +124,8 @@ public class RESTUtil {
             for (Map.Entry<String, String> entry : headers.entrySet()) {
                 httpPost.setHeader(new BasicHeader(entry.getKey(), entry.getValue()));
             }
-            httpClient = new DefaultHttpClient(connectionManager, null);
+            httpClient = connectionManager != null ? new DefaultHttpClient(connectionManager, null):HttpClients.createDefault();;
+
             response = httpClient.execute(httpPost);
             if (response != null) {
                 dockerResponse = new DockerHttpResponse(response.getAllHeaders(), response.getStatusLine().getStatusCode(),readBody(response.getEntity()).toString());
@@ -125,15 +138,24 @@ public class RESTUtil {
                     500,
                     "{\"error\":\"internal server error\", \"message\":\""+ e.getMessage() +"\"}");
         } finally {
+
             if(httpPost != null){
               httpPost.releaseConnection();
             }
             if (httpClient != null) {
-                httpClient.close();
+                if(httpClient instanceof DefaultHttpClient) {
+                    ((DefaultHttpClient) httpClient).close();
+                } else if(httpClient instanceof CloseableHttpClient){
+                    try {
+                        ((CloseableHttpClient) httpClient).close();
+                    } catch (IOException ignore) {}
+                }
             }
             if (response != null) {
                 try {
-                    response.close();
+                    if(response instanceof CloseableHttpResponse) {
+                        ((CloseableHttpResponse)response).close();
+                    }
                 } catch (IOException ignore) {}
             }
         }

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/7da6ffef/taverna-docker-activity/src/main/resources/META-INF/spring/docker-activity-context-osgi.xml
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/src/main/resources/META-INF/spring/docker-activity-context-osgi.xml b/taverna-docker-activity/src/main/resources/META-INF/spring/docker-activity-context-osgi.xml
new file mode 100755
index 0000000..fa93613
--- /dev/null
+++ b/taverna-docker-activity/src/main/resources/META-INF/spring/docker-activity-context-osgi.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<beans:beans xmlns="http://www.springframework.org/schema/osgi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xmlns:beans="http://www.springframework.org/schema/beans"
+	xsi:schemaLocation="http://www.springframework.org/schema/beans
+                      http://www.springframework.org/schema/beans/spring-beans.xsd
+                      http://www.springframework.org/schema/osgi
+                      http://www.springframework.org/schema/osgi/spring-osgi.xsd">
+
+	<reference id="dockerContainerConfiguration" interface="org.apache.taverna.activities.docker.DockerContainerConfiguration" />
+</beans:beans>

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/7da6ffef/taverna-docker-activity/src/main/resources/META-INF/spring/docker-activity-context.xml
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/src/main/resources/META-INF/spring/docker-activity-context.xml b/taverna-docker-activity/src/main/resources/META-INF/spring/docker-activity-context.xml
new file mode 100755
index 0000000..0378064
--- /dev/null
+++ b/taverna-docker-activity/src/main/resources/META-INF/spring/docker-activity-context.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://www.springframework.org/schema/beans
+                      http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+	<bean id="dockerActivityFactory" class="org.apache.taverna.activities.docker.DockerActivityFactory">
+		<property name="dockerContainerConfiguration" ref="dockerContainerConfiguration" />
+	</bean>
+
+</beans>

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/7da6ffef/taverna-docker-activity/src/test/java/org/apache/taverna/activities/docker/test/TestCreateContainer.java
----------------------------------------------------------------------
diff --git a/taverna-docker-activity/src/test/java/org/apache/taverna/activities/docker/test/TestCreateContainer.java b/taverna-docker-activity/src/test/java/org/apache/taverna/activities/docker/test/TestCreateContainer.java
index bd68abb..b54fd13 100644
--- a/taverna-docker-activity/src/test/java/org/apache/taverna/activities/docker/test/TestCreateContainer.java
+++ b/taverna-docker-activity/src/test/java/org/apache/taverna/activities/docker/test/TestCreateContainer.java
@@ -20,7 +20,8 @@
 package org.apache.taverna.activities.docker.test;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.taverna.activities.docker.DockerConfig;
+import org.apache.taverna.activities.docker.DockerContainerConfiguration;
+import org.apache.taverna.activities.docker.DockerHttpResponse;
 import org.apache.taverna.activities.docker.RESTUtil;
 import org.junit.Test;
 
@@ -28,16 +29,15 @@ import java.io.IOException;
 
 public class TestCreateContainer{
 
-//    @Test
-//    public void testCreateContainer(){
-//        try {
-//            String payload = "{\"Hostname\":\"foo.com\", \"User\":\"foo\", \"Memory\":0, \"MemorySwap\":0,\"AttachStdin\":false, \"AttachStdout\":true,\"Attachstderr\":true,\"PortSpecs\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":null, \"Cmd\":[\"date\"], \"Image\":\"ubuntu\",\"Tag\":\"latest\",\"Volumes\":{\"/tmp\":{} },\"WorkingDir\":\"\",\"DisableNetwork\":false, \"ExposedPorts\":{\"22/tcp\": {} }}";
-//            DockerConfig config = new DockerConfig("192.168.99.100",2376, new ObjectMapper().readTree(payload));
-//            boolean res = RESTUtil.createContainer(config);
-//            System.out.println(">>>" + res);
-//        } catch (IOException e) {
-//            e.printStackTrace();
-//        }
-//
-//    }
+    @Test
+    public void testCreateContainer(){
+        try {
+            String payload = "{\"Hostname\":\"192.168.99.100\", \"User\":\"foo\", \"Memory\":0, \"MemorySwap\":0,\"AttachStdin\":false, \"AttachStdout\":true,\"Attachstderr\":true,\"PortSpecs\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":null, \"Cmd\":[\"date\"], \"Image\":\"ubuntu\",\"Tag\":\"latest\",\"Volumes\":{\"/tmp\":{} },\"WorkingDir\":\"\",\"DisableNetwork\":false, \"ExposedPorts\":{\"22/tcp\": {} }}";
+            DockerContainerConfiguration config = new DockerContainerConfiguration("192.168.99.100",2376,"https",new ObjectMapper().readTree(payload));
+            DockerHttpResponse res = RESTUtil.createContainer(config);
+            System.out.println(">>>" + res.toString());
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
 }


[5/5] incubator-taverna-common-activities git commit: Merge remote-tracking branch 'nadeesh/docker' into docker

Posted by st...@apache.org.
Merge remote-tracking branch 'nadeesh/docker' into docker

First draft of Docker Activity

Contributed by NadeeshDilanga

This closes #5.
This closes #3.


Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/commit/bebc1f29
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/tree/bebc1f29
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/diff/bebc1f29

Branch: refs/heads/docker
Commit: bebc1f292e2ef2c118f77fabe9dcc85970fb7fa1
Parents: 57e10e1 d4e585b
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Jun 22 18:10:21 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Jun 22 18:10:21 2016 +0100

----------------------------------------------------------------------
 taverna-docker-activity/pom.xml                 |  53 ++++-
 .../activities/docker/DockerActivity.java       |  84 ++++++++
 .../DockerContainerConfigurationImpl.java       | 124 ++++++++++++
 .../activities/docker/DockerHttpResponse.java   |  51 +++++
 .../taverna/activities/docker/RESTUtil.java     | 202 +++++++++++++++++++
 .../spring/docker-activity-context-osgi.xml     |  29 +++
 .../META-INF/spring/docker-activity-context.xml |  29 +++
 .../docker/test/TestCreateContainer.java        |  44 ++++
 8 files changed, 614 insertions(+), 2 deletions(-)
----------------------------------------------------------------------