You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2014/06/05 09:01:24 UTC
[2/6] Docker IaaS support initial implementation
http://git-wip-us.apache.org/repos/asf/stratos/blob/d45ad99a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/handlers/DockerErrorHandler.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/handlers/DockerErrorHandler.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/handlers/DockerErrorHandler.java
new file mode 100644
index 0000000..964a958
--- /dev/null
+++ b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/handlers/DockerErrorHandler.java
@@ -0,0 +1,108 @@
+/*
+ * 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.jclouds.docker.handlers;
+
+import com.google.common.base.Throwables;
+import com.google.common.io.Closeables;
+import org.jclouds.http.HttpCommand;
+import org.jclouds.http.HttpErrorHandler;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.http.HttpResponseException;
+import org.jclouds.logging.Logger;
+import org.jclouds.rest.AuthorizationException;
+import org.jclouds.rest.ResourceNotFoundException;
+import org.jclouds.util.Strings2;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+
+/**
+ * This will parse and set an appropriate exception on the command object.
+ * <p/>
+ * <p/>
+ * Errors are returned with an appropriate HTTP status code, an X-Elastic- Error header specifying
+ * the error type, and a text description in the HTTP body.
+ *
+ * @author Andrea Turli
+ */
+public class DockerErrorHandler implements HttpErrorHandler {
+ @Resource
+ protected Logger logger = Logger.NULL;
+
+ public void handleError(HttpCommand command, HttpResponse response) {
+ // it is important to always read fully and close streams
+ String message = parseMessage(response);
+ Exception exception = message != null ? new HttpResponseException(command, response, message)
+ : new HttpResponseException(command, response);
+ try {
+ message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(),
+ response.getStatusLine());
+ switch (response.getStatusCode()) {
+ case 400:
+ if ((command.getCurrentRequest().getEndpoint().getPath().endsWith("/info"))
+ || (message != null && message.indexOf("could not be found") != -1))
+ exception = new ResourceNotFoundException(message, exception);
+ else if (message != null && message.indexOf("currently in use") != -1)
+ exception = new IllegalStateException(message, exception);
+ else
+ exception = new IllegalArgumentException(message, exception);
+ break;
+ case 401:
+ exception = new AuthorizationException(message, exception);
+ break;
+ case 402:
+ exception = new IllegalStateException(message, exception);
+ break;
+ case 404:
+ if (!command.getCurrentRequest().getMethod().equals("DELETE")) {
+ exception = new ResourceNotFoundException(message, exception);
+ }
+ break;
+ case 405:
+ exception = new IllegalArgumentException(message, exception);
+ break;
+ case 409:
+ exception = new IllegalStateException(message, exception);
+ break;
+ }
+ } finally {
+ try {
+ Closeables.close(response.getPayload(), true);
+ } catch (IOException e) {
+ // This code will never be reached
+ throw Throwables.propagate(e);
+ }
+ command.setException(exception);
+ }
+ }
+
+ public String parseMessage(HttpResponse response) {
+ if (response.getPayload() == null)
+ return null;
+ try {
+ return Strings2.toString(response.getPayload());
+ } catch (IOException e) {
+ throw Throwables.propagate(e);
+ } finally {
+ try {
+ response.getPayload().getInput().close();
+ } catch (IOException e) {
+ throw Throwables.propagate(e);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/d45ad99a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/BuildOptions.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/BuildOptions.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/BuildOptions.java
new file mode 100644
index 0000000..8a8bc05
--- /dev/null
+++ b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/BuildOptions.java
@@ -0,0 +1,73 @@
+/*
+ * 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.jclouds.docker.options;
+
+import org.jclouds.http.options.BaseHttpRequestOptions;
+
+/**
+ * Options to customize image builder.
+ *
+ * @author Andrea Turli
+ */
+public class BuildOptions extends BaseHttpRequestOptions {
+
+ public static final BuildOptions NONE = new BuildOptions();
+
+ public BuildOptions tag(String tag) {
+ this.queryParameters.put("tag", tag);
+ return this;
+ }
+
+ public BuildOptions verbose(Boolean verbose) {
+ this.queryParameters.put("verbose", verbose.toString());
+ return this;
+ }
+
+ public BuildOptions nocache(Boolean nocache) {
+ this.queryParameters.put("nocache", nocache.toString());
+ return this;
+ }
+
+ public static class Builder {
+
+ /**
+ * @see BuildOptions#tag
+ */
+ public static BuildOptions tag(String tag) {
+ BuildOptions options = new BuildOptions();
+ return options.tag(tag);
+ }
+
+ /**
+ * @see BuildOptions#verbose(Boolean)
+ */
+ public static BuildOptions verbose(Boolean verbose) {
+ BuildOptions options = new BuildOptions();
+ return options.verbose(verbose);
+ }
+
+ /**
+ * @see BuildOptions#nocache(Boolean)
+ */
+ public static BuildOptions nocache(Boolean nocache) {
+ BuildOptions options = new BuildOptions();
+ return options.nocache(nocache);
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/d45ad99a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/CommitOptions.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/CommitOptions.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/CommitOptions.java
new file mode 100644
index 0000000..7f058d4
--- /dev/null
+++ b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/CommitOptions.java
@@ -0,0 +1,111 @@
+/*
+ * 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.jclouds.docker.options;
+
+import org.jclouds.http.options.BaseHttpRequestOptions;
+
+/**
+ * Options to customize image commit.
+ *
+ * @author Andrea Turli
+ */
+public class CommitOptions extends BaseHttpRequestOptions {
+
+ public static final CommitOptions NONE = new CommitOptions();
+
+ public CommitOptions containerId(String containerId) {
+ this.queryParameters.put("containerId", containerId);
+ return this;
+ }
+
+ public CommitOptions repository(String repository) {
+ this.queryParameters.put("repository", repository);
+ return this;
+ }
+
+ public CommitOptions tag(String tag) {
+ this.queryParameters.put("tag", tag);
+ return this;
+ }
+
+ public CommitOptions message(String message) {
+ this.queryParameters.put("message", message);
+ return this;
+ }
+
+ public CommitOptions author(String author) {
+ this.queryParameters.put("author", author);
+ return this;
+ }
+
+ public CommitOptions run(String run) {
+ this.queryParameters.put("run", run);
+ return this;
+ }
+
+ public static class Builder {
+
+ /**
+ * @see CommitOptions#containerId
+ */
+ public static CommitOptions containerId(String containerId) {
+ CommitOptions options = new CommitOptions();
+ return options.containerId(containerId);
+ }
+
+ /**
+ * @see CommitOptions#repository
+ */
+ public static CommitOptions repository(String repository) {
+ CommitOptions options = new CommitOptions();
+ return options.repository(repository);
+ }
+
+ /**
+ * @see CommitOptions#tag
+ */
+ public static CommitOptions tag(String tag) {
+ CommitOptions options = new CommitOptions();
+ return options.tag(tag);
+ }
+
+ /**
+ * @see CommitOptions#message
+ */
+ public static CommitOptions message(String message) {
+ CommitOptions options = new CommitOptions();
+ return options.message(message);
+ }
+
+ /**
+ * @see CommitOptions#author
+ */
+ public static CommitOptions author(String author) {
+ CommitOptions options = new CommitOptions();
+ return options.author(author);
+ }
+
+ /**
+ * @see CommitOptions#run
+ */
+ public static CommitOptions run(String run) {
+ CommitOptions options = new CommitOptions();
+ return options.run(run);
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/d45ad99a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/CreateImageOptions.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/CreateImageOptions.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/CreateImageOptions.java
new file mode 100644
index 0000000..5ff65af
--- /dev/null
+++ b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/CreateImageOptions.java
@@ -0,0 +1,129 @@
+/*
+ * 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.jclouds.docker.options;
+
+import org.jclouds.http.options.BaseHttpRequestOptions;
+
+/**
+ * Options to customize container creation.
+ *
+ * @author Andrea Turli
+ */
+public class CreateImageOptions extends BaseHttpRequestOptions {
+
+ /*
+ private final String fromImage;
+ private final String fromSrc;
+ private final String repo;
+ private final String tag;
+ private final String registry;
+
+ public CreateImageOptions(String fromImage, String fromSrc, String repo, String tag, String registry) {
+ this.fromImage = fromImage;
+ this.fromSrc = fromSrc;
+ this.repo = repo;
+ this.tag = tag;
+ this.registry = registry;
+
+ if (fromImage != null) {
+ queryParameters.put("fromImage", fromImage);
+ }
+ if (fromSrc != null) {
+ queryParameters.put("fromSrc", fromSrc);
+ }
+ if (repo != null) {
+ queryParameters.put("repo", repo);
+ }
+ if (tag != null) {
+ queryParameters.put("tag", tag);
+ }
+ if (registry != null) {
+ queryParameters.put("registry", registry);
+ }
+ }
+ */
+
+ public static final CreateImageOptions NONE = new CreateImageOptions();
+
+ public CreateImageOptions fromImage(String fromImage) {
+ this.queryParameters.put("fromImage", fromImage);
+ return this;
+ }
+
+ public CreateImageOptions fromSrc(String fromSrc) {
+ this.queryParameters.put("fromSrc", fromSrc);
+ return this;
+ }
+
+ public CreateImageOptions repo(String repo) {
+ this.queryParameters.put("repo", repo);
+ return this;
+ }
+
+ public CreateImageOptions tag(String tag) {
+ this.queryParameters.put("tag", tag);
+ return this;
+ }
+
+ public CreateImageOptions registry(String registry) {
+ this.queryParameters.put("registry", registry);
+ return this;
+ }
+
+ public static class Builder {
+ /**
+ * @see CreateImageOptions#fromImage
+ */
+ public static CreateImageOptions fromImage(String fromImage) {
+ CreateImageOptions options = new CreateImageOptions();
+ return options.fromImage(fromImage);
+ }
+
+ /**
+ * @see CreateImageOptions#fromSrc
+ */
+ public static CreateImageOptions fromSrc(String fromSrc) {
+ CreateImageOptions options = new CreateImageOptions();
+ return options.fromSrc(fromSrc);
+ }
+
+ /**
+ * @see CreateImageOptions#repo
+ */
+ public static CreateImageOptions repo(String repo) {
+ CreateImageOptions options = new CreateImageOptions();
+ return options.repo(repo);
+ }
+
+ /**
+ * @see CreateImageOptions#tag
+ */
+ public static CreateImageOptions tag(String tag) {
+ CreateImageOptions options = new CreateImageOptions();
+ return options.tag(tag);
+ }
+
+ /**
+ * @see CreateImageOptions#registry
+ */
+ public static CreateImageOptions registry(String registry) {
+ CreateImageOptions options = new CreateImageOptions();
+ return options.registry(registry);
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/d45ad99a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/DeleteImageOptions.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/DeleteImageOptions.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/DeleteImageOptions.java
new file mode 100644
index 0000000..767dc7d
--- /dev/null
+++ b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/DeleteImageOptions.java
@@ -0,0 +1,46 @@
+/*
+ * 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.jclouds.docker.options;
+
+import org.jclouds.http.options.BaseHttpRequestOptions;
+
+/**
+ * Options to customize image deletion.
+ *
+ * @author Andrea Turli
+ */
+public class DeleteImageOptions extends BaseHttpRequestOptions {
+
+ public static final DeleteImageOptions NONE = new DeleteImageOptions();
+
+ public DeleteImageOptions force(Boolean force) {
+ this.queryParameters.put("force", force.toString());
+ return this;
+ }
+
+ public static class Builder {
+
+ /**
+ * @see DeleteImageOptions#force
+ */
+ public static DeleteImageOptions force(Boolean force) {
+ DeleteImageOptions options = new DeleteImageOptions();
+ return options.force(force);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/d45ad99a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/ListContainerOptions.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/ListContainerOptions.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/ListContainerOptions.java
new file mode 100644
index 0000000..6e9f129
--- /dev/null
+++ b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/ListContainerOptions.java
@@ -0,0 +1,97 @@
+/*
+ * 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.jclouds.docker.options;
+
+import org.jclouds.http.options.BaseHttpRequestOptions;
+
+/**
+ * @author Andrea Turli
+ */
+public class ListContainerOptions extends BaseHttpRequestOptions {
+
+ public static final ListContainerOptions NONE = new ListContainerOptions();
+
+ public ListContainerOptions all(Boolean all) {
+ this.queryParameters.put("all", all.toString());
+ return this;
+ }
+
+ public ListContainerOptions limit(Integer limit) {
+ this.queryParameters.put("limit", limit.toString());
+ return this;
+ }
+
+ public ListContainerOptions since(Integer since) {
+ this.queryParameters.put("since", since.toString());
+ return this;
+ }
+
+ public ListContainerOptions before(Integer before) {
+ this.queryParameters.put("before", before.toString());
+ return this;
+ }
+
+ public ListContainerOptions size(Integer size) {
+ this.queryParameters.put("size", size.toString());
+ return this;
+ }
+
+ public static class Builder {
+
+ /**
+ * @see ListContainerOptions#all
+ */
+ public static ListContainerOptions all(Boolean all) {
+ ListContainerOptions options = new ListContainerOptions();
+ return options.all(all);
+ }
+
+ /**
+ * @see ListContainerOptions#limit(Integer)
+ */
+ public static ListContainerOptions limit(Integer limit) {
+ ListContainerOptions options = new ListContainerOptions();
+ return options.limit(limit);
+ }
+
+ /**
+ * @see ListContainerOptions#since(Integer)
+ */
+ public static ListContainerOptions since(Integer since) {
+ ListContainerOptions options = new ListContainerOptions();
+ return options.since(since);
+ }
+
+ /**
+ * @see ListContainerOptions#before(Integer)
+ */
+ public static ListContainerOptions before(Integer before) {
+ ListContainerOptions options = new ListContainerOptions();
+ return options.before(before);
+ }
+
+ /**
+ * @see ListContainerOptions#limit(Integer)
+ */
+ public static ListContainerOptions size(Integer size) {
+ ListContainerOptions options = new ListContainerOptions();
+ return options.size(size);
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/d45ad99a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/ListImageOptions.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/ListImageOptions.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/ListImageOptions.java
new file mode 100644
index 0000000..510fae2
--- /dev/null
+++ b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/ListImageOptions.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.jclouds.docker.options;
+
+import org.jclouds.http.options.BaseHttpRequestOptions;
+
+/**
+ * @author Andrea Turli
+ */
+public class ListImageOptions extends BaseHttpRequestOptions {
+
+ public static final ListImageOptions NONE = new ListImageOptions();
+
+ public ListImageOptions all(Boolean all) {
+ this.queryParameters.put("all", all.toString());
+ return this;
+ }
+
+ public static class Builder {
+ /**
+ * @see ListImageOptions#all
+ */
+ public static ListImageOptions all(Boolean all) {
+ ListImageOptions options = new ListImageOptions();
+ return options.all(all);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/d45ad99a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/RemoveContainerOptions.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/RemoveContainerOptions.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/RemoveContainerOptions.java
new file mode 100644
index 0000000..636b352
--- /dev/null
+++ b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/options/RemoveContainerOptions.java
@@ -0,0 +1,57 @@
+/*
+ * 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.jclouds.docker.options;
+
+import org.jclouds.http.options.BaseHttpRequestOptions;
+
+/**
+ * Options to customize container removal.
+ *
+ * @author Andrea Turli
+ */
+public class RemoveContainerOptions extends BaseHttpRequestOptions {
+
+ public static final RemoveContainerOptions NONE = new RemoveContainerOptions();
+
+ public RemoveContainerOptions verbose(Boolean verbose) {
+ this.queryParameters.put("verbose", verbose.toString());
+ return this;
+ }
+
+ public RemoveContainerOptions force(Boolean force) {
+ this.queryParameters.put("force", force.toString());
+ return this;
+ }
+
+ public static class Builder {
+ /**
+ * @see RemoveContainerOptions#verbose
+ */
+ public static RemoveContainerOptions verbose(Boolean verbose) {
+ RemoveContainerOptions options = new RemoveContainerOptions();
+ return options.verbose(verbose);
+ }
+
+ /**
+ * @see RemoveContainerOptions#force
+ */
+ public static RemoveContainerOptions force(Boolean force) {
+ RemoveContainerOptions options = new RemoveContainerOptions();
+ return options.force(force);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/d45ad99a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata
new file mode 100644
index 0000000..ca1a6cb
--- /dev/null
+++ b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata
@@ -0,0 +1 @@
+org.jclouds.docker.DockerApiMetadata
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/stratos/blob/d45ad99a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/resources/centos/Dockerfile
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/resources/centos/Dockerfile b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/resources/centos/Dockerfile
new file mode 100644
index 0000000..1318715
--- /dev/null
+++ b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/resources/centos/Dockerfile
@@ -0,0 +1,29 @@
+#
+# 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.
+#
+
+FROM centos:6.4
+MAINTAINER Andrea Turli <an...@gmail.com>
+
+# RUN yum -y groupinstall 'Development Tools'
+RUN yum -y install openssh-server openssh-clients
+
+RUN chkconfig sshd on
+RUN service sshd start
+RUN echo 'root:password' | chpasswd
+
+EXPOSE 22
+CMD ["/usr/sbin/sshd", "-D"]
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/stratos/blob/d45ad99a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/resources/ubuntu/Dockerfile
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/resources/ubuntu/Dockerfile b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/resources/ubuntu/Dockerfile
new file mode 100644
index 0000000..fe21ef4
--- /dev/null
+++ b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/resources/ubuntu/Dockerfile
@@ -0,0 +1,30 @@
+#
+# 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.
+#
+
+FROM ubuntu:12.04
+MAINTAINER Andrea Turli <an...@gmail.com>
+
+RUN apt-get update
+RUN apt-get install -y openssh-server
+
+RUN mkdir /var/run/sshd
+RUN /usr/sbin/sshd
+
+RUN echo 'root:password' | chpasswd
+
+EXPOSE 22
+CMD ["/usr/sbin/sshd", "-D"]
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/stratos/blob/d45ad99a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/DockerApiMetadataTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/DockerApiMetadataTest.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/DockerApiMetadataTest.java
new file mode 100644
index 0000000..a8e325b
--- /dev/null
+++ b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/DockerApiMetadataTest.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.jclouds.docker;
+
+import org.jclouds.apis.ApiMetadata;
+import org.jclouds.apis.Apis;
+import org.jclouds.compute.internal.BaseComputeServiceApiMetadataTest;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+/**
+ * Unit tests for the {@link DockerApiMetadata} class.
+ *
+ * @author Andrea Turli
+ */
+@Test(groups = "unit", testName = "AbiquoApiMetadataTest")
+public class DockerApiMetadataTest extends BaseComputeServiceApiMetadataTest {
+
+ public DockerApiMetadataTest() {
+ super(new DockerApiMetadata());
+ }
+
+ public void testDockerApiRegistered() {
+ ApiMetadata api = Apis.withId("docker");
+
+ assertNotNull(api);
+ assertTrue(api instanceof DockerApiMetadata);
+ assertEquals(api.getId(), "docker");
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/stratos/blob/d45ad99a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/BaseDockerApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/BaseDockerApiLiveTest.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/BaseDockerApiLiveTest.java
new file mode 100644
index 0000000..cfafe41
--- /dev/null
+++ b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/BaseDockerApiLiveTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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.jclouds.docker.compute;
+
+import com.google.common.base.Charsets;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.io.CharStreams;
+import com.google.common.io.Closeables;
+import com.google.common.io.Files;
+import com.google.common.io.Resources;
+import com.google.inject.Module;
+import org.jclouds.Constants;
+import org.jclouds.apis.BaseApiLiveTest;
+import org.jclouds.docker.DockerApi;
+import org.jclouds.docker.compute.features.internal.Archives;
+import org.jclouds.io.Payload;
+import org.jclouds.io.Payloads;
+import org.jclouds.sshj.config.SshjSshClientModule;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import javax.ws.rs.core.MediaType;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.Properties;
+
+/**
+ * @author Andrea Turli
+ */
+@Test(groups = "live", singleThreaded = true)
+public class BaseDockerApiLiveTest extends BaseApiLiveTest<DockerApi> {
+
+ public BaseDockerApiLiveTest() {
+ provider = "docker";
+ }
+
+ @Override
+ protected Iterable<Module> setupModules() {
+ return ImmutableSet.<Module>of(getLoggingModule(), new SshjSshClientModule());
+ }
+
+ @Override
+ protected Properties setupProperties() {
+ Properties overrides = new Properties();
+ overrides.setProperty(Constants.PROPERTY_MAX_RETRIES, "15");
+ overrides.setProperty("jclouds.ssh.retry-auth", "true");
+ endpoint = setIfTestSystemPropertyPresent(overrides, provider + ".endpoint");
+ return overrides;
+ }
+
+ protected String consumeStream(InputStream stream, boolean swallowIOException) {
+ String result = null;
+ try {
+ result = CharStreams.toString(new InputStreamReader(stream, Charsets.UTF_8));
+ Closeables.close(stream, swallowIOException);
+ } catch (IOException e) {
+ Assert.fail();
+ }
+ return result;
+ }
+
+ protected Payload createPayload() throws IOException {
+ String folderPath = System.getProperty("user.dir") + "/docker/src/test/resources";
+ File parentDir = new File(folderPath + "/archive");
+ parentDir.mkdirs();
+ URL url = Resources.getResource("Dockerfile");
+ String content = Resources.toString(url, Charsets.UTF_8);
+ final File dockerfile = new File(parentDir.getAbsolutePath() + File.separator + "Dockerfile");
+ Files.write(content.getBytes(), dockerfile);
+ File archive = Archives.tar(parentDir, folderPath + "/archive/archive.tar");
+ FileInputStream data = new FileInputStream(archive);
+ Payload payload = Payloads.newInputStreamPayload(data);
+ payload.getContentMetadata().setContentLength(data.getChannel().size());
+ payload.getContentMetadata().setContentType(MediaType.TEXT_PLAIN);
+ return payload;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/d45ad99a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/DockerComputeServiceAdapterLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/DockerComputeServiceAdapterLiveTest.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/DockerComputeServiceAdapterLiveTest.java
new file mode 100644
index 0000000..9ae95aa
--- /dev/null
+++ b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/DockerComputeServiceAdapterLiveTest.java
@@ -0,0 +1,138 @@
+/*
+ * 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.jclouds.docker.compute;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+import com.google.common.net.HostAndPort;
+import com.google.inject.Injector;
+import com.google.inject.Module;
+import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials;
+import org.jclouds.compute.domain.ExecResponse;
+import org.jclouds.compute.domain.Hardware;
+import org.jclouds.compute.domain.OsFamily;
+import org.jclouds.compute.domain.Template;
+import org.jclouds.compute.domain.TemplateBuilder;
+import org.jclouds.compute.functions.DefaultCredentialsFromImageOrOverridingCredentials;
+import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate;
+import org.jclouds.docker.DockerApi;
+import org.jclouds.docker.compute.strategy.DockerComputeServiceAdapter;
+import org.jclouds.docker.domain.Container;
+import org.jclouds.domain.LoginCredentials;
+import org.jclouds.ssh.SshClient;
+import org.jclouds.ssh.SshClient.Factory;
+import org.jclouds.sshj.config.SshjSshClientModule;
+import org.testng.annotations.AfterGroups;
+import org.testng.annotations.Test;
+
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Random;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+
+@Test(groups = "live", singleThreaded = true, testName = "DockerComputeServiceAdapterLiveTest")
+public class DockerComputeServiceAdapterLiveTest extends BaseDockerApiLiveTest {
+
+ private DockerComputeServiceAdapter adapter;
+ private TemplateBuilder templateBuilder;
+ private Factory sshFactory;
+ private NodeAndInitialCredentials<Container> guest;
+ private URI endpoint;
+
+ @Override
+ protected DockerApi create(Properties props, Iterable<Module> modules) {
+ Injector injector = newBuilder().modules(modules).overrides(props).buildInjector();
+ adapter = injector.getInstance(DockerComputeServiceAdapter.class);
+ templateBuilder = injector.getInstance(TemplateBuilder.class);
+ sshFactory = injector.getInstance(SshClient.Factory.class);
+ endpoint = URI.create(props.getProperty("docker.endpoint"));
+ return injector.getInstance(DockerApi.class);
+ }
+
+ @Test
+ public void testListImages() {
+ assertFalse(Iterables.isEmpty(adapter.listImages()), "images must not be empty");
+ }
+
+ private static final PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate = new PrioritizeCredentialsFromTemplate(
+ new DefaultCredentialsFromImageOrOverridingCredentials());
+
+ @Test
+ public void testCreateNodeWithGroupEncodedIntoNameThenStoreCredentials() {
+ String group = "foo";
+ String name = "container-" + new Random().nextInt();
+
+ Template template = templateBuilder.smallest().osFamily(OsFamily.UBUNTU).os64Bit(true)
+ .osDescriptionMatches("jclouds/ubuntu:latest").build();
+
+ guest = adapter.createNodeWithGroupEncodedIntoName(group, name, template);
+ assertEquals(guest.getNodeId(), guest.getNode().getId() + "");
+ doConnectViaSsh(guest.getNode(), prioritizeCredentialsFromTemplate.apply(template, guest.getCredentials()));
+ }
+
+ protected void doConnectViaSsh(Container guest, LoginCredentials creds) {
+ // todo this is an hack as I'm using host-only IF
+ Map<String, List<Map<String, String>>> portBindings = guest.getHostConfig().getPortBindings();
+ int loginPort = Integer.parseInt(portBindings.get("22/tcp").get(0).get("HostPort"));
+ SshClient ssh = sshFactory.create(HostAndPort.fromParts(endpoint.getHost(), loginPort), creds);
+ try {
+ ssh.connect();
+ ExecResponse hello = ssh.exec("echo hello");
+ assertEquals(hello.getOutput().trim(), "hello");
+ System.err.println(ssh.exec("mount").getOutput());
+ System.err.println(ssh.exec("uname -a").getOutput());
+ } finally {
+ if (ssh != null)
+ ssh.disconnect();
+ }
+ }
+
+ @Test
+ public void testListHardwareProfiles() {
+ Iterable<Hardware> profiles = adapter.listHardwareProfiles();
+ assertFalse(Iterables.isEmpty(profiles));
+
+ for (Hardware profile : profiles) {
+ assertNotNull(profile);
+ }
+ }
+
+ @AfterGroups(groups = "live")
+ protected void tearDown() {
+ if (guest != null) {
+ adapter.destroyNode(guest.getNode().getId() + "");
+ }
+ super.tearDown();
+ }
+
+ @Override
+ protected Iterable<Module> setupModules() {
+ return ImmutableSet.<Module>of(getLoggingModule(), new SshjSshClientModule());
+ }
+
+ @Override
+ protected Properties setupProperties() {
+ Properties properties = super.setupProperties();
+ properties.setProperty("jclouds.ssh.max-retries", "10");
+ return properties;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/d45ad99a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/DockerExperimentLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/DockerExperimentLiveTest.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/DockerExperimentLiveTest.java
new file mode 100644
index 0000000..1476c9f
--- /dev/null
+++ b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/DockerExperimentLiveTest.java
@@ -0,0 +1,144 @@
+/*
+ * 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.jclouds.docker.compute;
+
+import com.beust.jcommander.internal.Maps;
+import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableSet;
+import com.google.inject.Module;
+import org.jclouds.ContextBuilder;
+import org.jclouds.compute.ComputeService;
+import org.jclouds.compute.ComputeServiceContext;
+import org.jclouds.compute.RunNodesException;
+import org.jclouds.compute.domain.ExecResponse;
+import org.jclouds.compute.domain.NodeMetadata;
+import org.jclouds.compute.domain.OsFamily;
+import org.jclouds.compute.domain.Template;
+import org.jclouds.compute.reference.ComputeServiceConstants;
+import org.jclouds.docker.compute.options.DockerTemplateOptions;
+import org.jclouds.logging.Logger;
+import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
+import org.jclouds.scriptbuilder.domain.Statement;
+import org.jclouds.scriptbuilder.statements.login.AdminAccess;
+import org.jclouds.ssh.SshClient;
+import org.jclouds.sshj.config.SshjSshClientModule;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import javax.annotation.Resource;
+import javax.inject.Named;
+import java.io.IOException;
+import java.util.Map;
+import java.util.Set;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+/**
+ * @author Andrea Turli
+ */
+@Test(groups = "live", singleThreaded = true, testName = "DockerExperimentLiveTest")
+public class DockerExperimentLiveTest extends BaseDockerApiLiveTest {
+
+ public static final String TEST_LAUNCH_CLUSTER = "jclouds";
+ @Resource
+ @Named(ComputeServiceConstants.COMPUTE_LOGGER)
+ protected Logger logger = Logger.NULL;
+
+ ComputeServiceContext context;
+
+ @BeforeMethod
+ public void setUp() throws IOException {
+ context = ContextBuilder.newBuilder("docker")
+ .overrides(super.setupProperties())
+ .modules(ImmutableSet.<Module>of(new SLF4JLoggingModule(), new SshjSshClientModule()))
+ .build(ComputeServiceContext.class);
+ }
+
+ @AfterMethod
+ public void tearDown() {
+ context.close();
+ }
+
+ @Test
+ public void testLaunchUbuntuServerWithInboundPorts() throws RunNodesException {
+ int numNodes = 1;
+ ComputeService compute = context.getComputeService();
+
+ Template template = compute.templateBuilder().smallest()
+ .osFamily(OsFamily.UBUNTU).os64Bit(true)
+ .osDescriptionMatches("jclouds/ubuntu:latest")
+ .build();
+ Statement bootInstructions = AdminAccess.standard();
+
+ DockerTemplateOptions templateOptions = template.getOptions().as(DockerTemplateOptions.class);
+
+ Map<String,String> volumes = Maps.newHashMap();
+ volumes.put("/var/lib/docker", "/root");
+ templateOptions.volumes(volumes).runScript(bootInstructions)
+ .inboundPorts(22, 80, 8080);
+
+ Set<? extends NodeMetadata> nodes = context.getComputeService().createNodesInGroup(TEST_LAUNCH_CLUSTER, numNodes, template);
+ assertEquals(numNodes, nodes.size(), "wrong number of nodes");
+ for (NodeMetadata node : nodes) {
+ assertTrue(node.getGroup().equals(TEST_LAUNCH_CLUSTER));
+ logger.debug("Created Node: %s", node);
+ SshClient client = context.utils().sshForNode().apply(node);
+ client.connect();
+ ExecResponse hello = client.exec("echo hello");
+ assertEquals(hello.getOutput().trim(), "hello");
+ }
+ context.getComputeService().destroyNodesMatching(new Predicate<NodeMetadata>() {
+ @Override
+ public boolean apply(NodeMetadata input) {
+ return input.getGroup().contains(TEST_LAUNCH_CLUSTER);
+ }
+ });
+ }
+
+ public void testLaunchUbuntuCluster() throws RunNodesException {
+ int numNodes = 1;
+ ComputeService compute = context.getComputeService();
+ Template template = compute.templateBuilder()
+ .smallest().osFamily(OsFamily.UBUNTU)
+ .os64Bit(true)
+ .osDescriptionMatches("jclouds/ubuntu:latest")
+ .build();
+ Statement bootInstructions = AdminAccess.standard();
+ template.getOptions().runScript(bootInstructions)
+ .inboundPorts(22);
+
+ Set<? extends NodeMetadata> nodes = context.getComputeService().createNodesInGroup(TEST_LAUNCH_CLUSTER, numNodes, template);
+ assertEquals(numNodes, nodes.size(), "wrong number of nodes");
+ for (NodeMetadata node : nodes) {
+ assertTrue(node.getGroup().equals(TEST_LAUNCH_CLUSTER));
+ logger.debug("Created Node: %s", node);
+ SshClient client = context.utils().sshForNode().apply(node);
+ client.connect();
+ ExecResponse hello = client.exec("echo hello");
+ assertEquals(hello.getOutput().trim(), "hello");
+ }
+ context.getComputeService().destroyNodesMatching(new Predicate<NodeMetadata>() {
+ @Override
+ public boolean apply(NodeMetadata input) {
+ return input.getGroup().contains(TEST_LAUNCH_CLUSTER);
+ }
+ });
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/d45ad99a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/features/RemoteApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/features/RemoteApiLiveTest.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/features/RemoteApiLiveTest.java
new file mode 100644
index 0000000..2b48f64
--- /dev/null
+++ b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/features/RemoteApiLiveTest.java
@@ -0,0 +1,136 @@
+/*
+ * 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.jclouds.docker.compute.features;
+
+import com.google.common.base.Splitter;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+import com.google.common.io.Resources;
+import org.jclouds.docker.compute.BaseDockerApiLiveTest;
+import org.jclouds.docker.domain.Config;
+import org.jclouds.docker.domain.Container;
+import org.jclouds.docker.domain.Image;
+import org.jclouds.docker.options.BuildOptions;
+import org.jclouds.docker.options.CreateImageOptions;
+import org.jclouds.docker.options.DeleteImageOptions;
+import org.jclouds.rest.ResourceNotFoundException;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URISyntaxException;
+
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+
+/**
+ * @author Andrea Turli
+ */
+public class RemoteApiLiveTest extends BaseDockerApiLiveTest {
+
+ private static final String BUSYBOX_IMAGE = "busybox";
+ private Container container = null;
+ private Image image = null;
+
+ @BeforeClass
+ private void init() {
+ setupProperties();
+ CreateImageOptions options = CreateImageOptions.Builder.fromImage(BUSYBOX_IMAGE);
+ InputStream createImageStream = api().createImage(options);
+ consumeStream(createImageStream, false);
+ }
+
+ @Test
+ public void testVersion() {
+ Assert.assertEquals(api().getVersion().getVersion(), "0.9.0");
+ }
+
+ @Test(dependsOnMethods = "testVersion")
+ public void testCreateImage() throws IOException, InterruptedException {
+ CreateImageOptions options = CreateImageOptions.Builder.fromImage(BUSYBOX_IMAGE);
+ InputStream createImageStream = api().createImage(options);
+ consumeStream(createImageStream, false);
+ image = api().inspectImage(BUSYBOX_IMAGE);
+ assertNotNull(image);
+ }
+
+ @Test(dependsOnMethods = "testCreateImage")
+ public void testListImages() {
+ Assert.assertNotNull(api().listImages());
+ }
+
+ @Test(dependsOnMethods = "testListImages")
+ public void testCreateContainer() throws IOException, InterruptedException {
+ if(image == null) Assert.fail();
+ Config config = Config.builder().imageId(image.getId())
+ .cmd(ImmutableList.of("/bin/sh", "-c", "while true; do echo hello world; sleep 1; done"))
+ .build();
+ container = api().createContainer("testCreateContainer", config);
+ assertNotNull(container);
+ assertNotNull(container.getId());
+ }
+
+ @Test(dependsOnMethods = "testCreateContainer")
+ public void testStartContainer() throws IOException, InterruptedException {
+ if(container == null) Assert.fail();
+ api().startContainer(container.getId());
+ Assert.assertTrue(api().inspectContainer(container.getId()).getState().isRunning());
+ }
+
+ @Test(dependsOnMethods = "testStartContainer")
+ public void testStopContainer() {
+ if(container == null) Assert.fail();
+ api().stopContainer(container.getId());
+ Assert.assertFalse(api().inspectContainer(container.getId()).getState().isRunning());
+ }
+
+ @Test(dependsOnMethods = "testStopContainer", expectedExceptions = NullPointerException.class)
+ public void testRemoveContainer() {
+ if(container == null) Assert.fail();
+ api().removeContainer(container.getId());
+ Assert.assertFalse(api().inspectContainer(container.getId()).getState().isRunning());
+ }
+
+ @Test(dependsOnMethods = "testRemoveContainer", expectedExceptions = ResourceNotFoundException.class)
+ public void testDeleteImage() {
+ InputStream deleteImageStream = api().deleteImage(image.getId());
+ consumeStream(deleteImageStream, false);
+ assertNull(api().inspectImage(image.getId()));
+ }
+
+ @Test(dependsOnMethods = "testDeleteImage")
+ public void testBuildImage() throws IOException, InterruptedException, URISyntaxException {
+ BuildOptions options = BuildOptions.Builder.tag("testBuildImage").verbose(false).nocache(false);
+ InputStream buildImageStream = api().build(new File(Resources.getResource("centos/Dockerfile").toURI()), options);
+ String buildStream = consumeStream(buildImageStream, false);
+ Iterable<String> splitted = Splitter.on("\n").split(buildStream.replace("\r", "").trim());
+ String lastStreamedLine = Iterables.getLast(splitted).trim();
+ String rawImageId = Iterables.getLast(Splitter.on("Successfully built ").split(lastStreamedLine));
+ String imageId = rawImageId.substring(0, 11);
+ Image image = api().inspectImage(imageId);
+ api().removeContainer(image.getContainer());
+ api().deleteImage(imageId, DeleteImageOptions.Builder.force(true));
+ }
+
+ private RemoteApi api() {
+ return api.getRemoteApi();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/d45ad99a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/features/RemoteApiMockTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/features/RemoteApiMockTest.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/features/RemoteApiMockTest.java
new file mode 100644
index 0000000..8fb0ffe
--- /dev/null
+++ b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/features/RemoteApiMockTest.java
@@ -0,0 +1,358 @@
+/*
+ * 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.jclouds.docker.compute.features;
+
+import com.google.common.base.Charsets;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMultimap;
+import com.google.common.io.Files;
+import com.squareup.okhttp.mockwebserver.MockResponse;
+import com.squareup.okhttp.mockwebserver.MockWebServer;
+import org.jclouds.docker.DockerApi;
+import org.jclouds.docker.domain.Config;
+import org.jclouds.docker.domain.Container;
+import org.jclouds.docker.internal.BaseDockerMockTest;
+import org.jclouds.docker.options.BuildOptions;
+import org.jclouds.docker.options.CreateImageOptions;
+import org.jclouds.docker.options.ListContainerOptions;
+import org.jclouds.rest.ResourceNotFoundException;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Set;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.AssertJUnit.fail;
+
+/**
+ * Mock tests for the {@link org.jclouds.docker.DockerApi} class.
+ *
+ * @author Andrea Turli
+ */
+@Test(groups = "unit", testName = "RemoteApiMockTest")
+public class RemoteApiMockTest extends BaseDockerMockTest {
+
+ public void testListContainers() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/containers.json")));
+
+ DockerApi api = api(server.getUrl("/"));
+ RemoteApi remoteApi = api.getRemoteApi();
+
+ try {
+ Set<Container> containers = remoteApi.listContainers();
+ assertRequestHasCommonFields(server.takeRequest(), "/containers/json");
+ assertEquals(containers.size(), 1);
+ } finally {
+ api.close();
+ server.shutdown();
+ }
+ }
+
+ public void testListAllContainers() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/containers.json")));
+
+ DockerApi api = api(server.getUrl("/"));
+ RemoteApi remoteApi = api.getRemoteApi();
+
+ try {
+ Set<Container> containers = remoteApi.listContainers(ListContainerOptions.Builder.all(true));
+ assertRequestHasParameters(server.takeRequest(), "/containers/json", ImmutableMultimap.of("all",
+ "true"));
+ assertEquals(containers.size(), 1);
+ } finally {
+ api.close();
+ server.shutdown();
+ }
+ }
+
+ public void testGetContainer() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/container.json")));
+ DockerApi api = api(server.getUrl("/"));
+ RemoteApi remoteApi = api.getRemoteApi();
+ String containerId = "6d35806c1bd2b25cd92bba2d2c2c5169dc2156f53ab45c2b62d76e2d2fee14a9";
+ try {
+ Container container = remoteApi.inspectContainer(containerId);
+ assertRequestHasCommonFields(server.takeRequest(), "/containers/" + containerId + "/json");
+ assertNotNull(container);
+ assertNotNull(container.getConfig());
+ assertNotNull(container.getHostConfig());
+ assertEquals(container.getName(), "/hopeful_mclean");
+ assertEquals(container.getState().isRunning(), true);
+ } finally {
+ api.close();
+ server.shutdown();
+ }
+ }
+
+ public void testGetNonExistingContainer() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setResponseCode(404));
+ DockerApi api = api(server.getUrl("/"));
+ RemoteApi remoteApi = api.getRemoteApi();
+ String containerId = "notExisting";
+ try {
+ Container container = remoteApi.inspectContainer(containerId);
+ assertRequestHasCommonFields(server.takeRequest(), "/containers/" + containerId + "/json");
+ assertNull(container);
+ } finally {
+ api.close();
+ server.shutdown();
+ }
+ }
+
+ public void testCreateContainer() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/container-creation.json")));
+
+ DockerApi api = api(server.getUrl("/"));
+ RemoteApi remoteApi = api.getRemoteApi();
+ Config config = Config.builder().cmd(ImmutableList.of("date"))
+ .attachStdin(false)
+ .attachStderr(true)
+ .attachStdout(true)
+ .tty(false)
+ .imageId("base")
+ .build();
+ try {
+ Container container = remoteApi.createContainer("test", config);
+ assertNotNull(container);
+ assertEquals(container.getId(), "c6c74153ae4b1d1633d68890a68d89c40aa5e284a1ea016cbc6ef0e634ee37b2");
+ } finally {
+ api.close();
+ server.shutdown();
+ }
+ }
+
+ public void testRemoveContainer() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setResponseCode(204));
+
+ DockerApi api = api(server.getUrl("/"));
+ RemoteApi remoteApi = api.getRemoteApi();
+ String containerId = "6d35806c1bd2b25cd92bba2d2c2c5169dc2156f53ab45c2b62d76e2d2fee14a9";
+
+ try {
+ remoteApi.removeContainer(containerId);
+ assertRequestHasCommonFields(server.takeRequest(), "DELETE", "/containers/"+containerId);
+ } finally {
+ api.close();
+ server.shutdown();
+ }
+ }
+
+ public void testRemoveNonExistingContainer() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setResponseCode(404));
+ DockerApi api = api(server.getUrl("/"));
+ RemoteApi remoteApi = api.getRemoteApi();
+ String containerId = "nonExisting";
+ try {
+ remoteApi.removeContainer(containerId);
+ } catch (ResourceNotFoundException ex) {
+ // Expected exception
+ assertRequestHasCommonFields(server.takeRequest(), "DELETE", "/containers/"+containerId);
+ } finally {
+ api.close();
+ server.shutdown();
+ }
+ }
+
+ public void testStartContainer() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setResponseCode(200));
+ DockerApi api = api(server.getUrl("/"));
+ RemoteApi remoteApi = api.getRemoteApi();
+ try {
+ remoteApi.startContainer("1");
+ assertRequestHasCommonFields(server.takeRequest(), "POST", "/containers/1/start");
+ } finally {
+ api.close();
+ server.shutdown();
+ }
+ }
+
+ public void testStartNonExistingContainer() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setResponseCode(204));
+ DockerApi api = api(server.getUrl("/"));
+ RemoteApi remoteApi = api.getRemoteApi();
+ try {
+ try {
+ remoteApi.startContainer("1");
+ } catch (ResourceNotFoundException ex) {
+ // Expected exception
+ }
+ assertRequestHasCommonFields(server.takeRequest(), "POST", "/containers/1/start");
+ } finally {
+ api.close();
+ server.shutdown();
+ }
+ }
+
+ public void testStopContainer() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setResponseCode(200));
+ DockerApi api = api(server.getUrl("/"));
+ RemoteApi remoteApi = api.getRemoteApi();
+ try {
+ remoteApi.stopContainer("1");
+ assertRequestHasCommonFields(server.takeRequest(), "POST", "/containers/1/stop");
+ } finally {
+ api.close();
+ server.shutdown();
+ }
+ }
+
+ public void testStopNonExistingContainer() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setResponseCode(204));
+ DockerApi api = api(server.getUrl("/"));
+ RemoteApi remoteApi = api.getRemoteApi();
+ try {
+ remoteApi.stopContainer("1");
+ } catch (ResourceNotFoundException ex) {
+ // Expected exception
+ assertRequestHasCommonFields(server.takeRequest(), "POST", "/containers/1/stop");
+ } finally {
+ api.close();
+ server.shutdown();
+ }
+ }
+
+ public void testCreateImage() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setResponseCode(200));
+ DockerApi api = api(server.getUrl("/"));
+ RemoteApi remoteApi = api.getRemoteApi();
+ try {
+ remoteApi.createImage(CreateImageOptions.Builder.fromImage("base"));
+ assertRequestHasParameters(server.takeRequest(), "POST", "/images/create", ImmutableMultimap.of("fromImage",
+ "base"));
+ } finally {
+ api.close();
+ server.shutdown();
+ }
+ }
+
+ public void testCreateImageFailure() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setResponseCode(404));
+ DockerApi api = api(server.getUrl("/"));
+ RemoteApi remoteApi = api.getRemoteApi();
+ try {
+ remoteApi.createImage(CreateImageOptions.Builder.fromImage("base"));
+ assertRequestHasParameters(server.takeRequest(), "POST", "/images/create", ImmutableMultimap.of("fromImage",
+ "base"));
+ } catch (ResourceNotFoundException ex) {
+ // Expected exception
+ assertRequestHasParameters(server.takeRequest(), "POST", "/images/create", ImmutableMultimap.of("fromImage",
+ "base"));
+ } finally {
+ api.close();
+ server.shutdown();
+ }
+ }
+
+ public void testDeleteImage() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setResponseCode(204));
+ DockerApi api = api(server.getUrl("/"));
+ RemoteApi remoteApi = api.getRemoteApi();
+ try {
+ remoteApi.deleteImage("1");
+ assertRequestHasCommonFields(server.takeRequest(), "DELETE", "/images/1");
+ } finally {
+ api.close();
+ server.shutdown();
+ }
+ }
+
+ public void testDeleteNotExistingImage() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setResponseCode(404));
+ DockerApi api = api(server.getUrl("/"));
+ RemoteApi remoteApi = api.getRemoteApi();
+ try {
+ remoteApi.deleteImage("1");
+ } catch (ResourceNotFoundException ex) {
+ // Expected exception
+ assertRequestHasCommonFields(server.takeRequest(), "DELETE", "/images/1");
+ } finally {
+ api.close();
+ server.shutdown();
+ }
+ }
+
+ public void testBuildContainer() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setResponseCode(200));
+ DockerApi api = api(server.getUrl("/"));
+ RemoteApi remoteApi = api.getRemoteApi();
+ String content = new String(payloadFromResource("/Dockerfile"));
+ File dockerFile = createDockerFile(content);
+ try {
+ remoteApi.build(dockerFile, BuildOptions.NONE);
+ assertRequestHasCommonFields(server.takeRequest(), "POST", "/build");
+ } finally {
+ dockerFile.deleteOnExit();
+ api.close();
+ server.shutdown();
+ }
+ }
+
+ public void testBuildNonexistentContainer() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setResponseCode(404));
+
+ DockerApi api = api(server.getUrl("/"));
+ RemoteApi remoteApi = api.getRemoteApi();
+
+ String content = new String(payloadFromResource("/Dockerfile"));
+ File dockerFile = createDockerFile(content);
+ try {
+ try {
+ remoteApi.build(dockerFile, BuildOptions.NONE);
+ fail("Build container should fail on 404");
+ } catch (ResourceNotFoundException ex) {
+ // Expected exception
+ }
+ assertRequestHasCommonFields(server.takeRequest(), "POST", "/build");
+ } finally {
+ dockerFile.deleteOnExit();
+ api.close();
+ server.shutdown();
+ }
+ }
+
+ private File createDockerFile(String content) {
+ File newTempDir = Files.createTempDir();
+ File dockerFile = new File(newTempDir + "/dockerFile");
+ try {
+ Files.write(content, dockerFile, Charsets.UTF_8);
+ } catch(IOException e) {
+ Assert.fail();
+ }
+ return dockerFile;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/d45ad99a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/functions/ContainerToNodeMetadataTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/functions/ContainerToNodeMetadataTest.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/functions/ContainerToNodeMetadataTest.java
new file mode 100644
index 0000000..3394cde
--- /dev/null
+++ b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/functions/ContainerToNodeMetadataTest.java
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * work for additional information regarding copyright ownership.
+ * The ASF licenses file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use 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.jclouds.docker.compute.functions;
+
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.testng.Assert.assertEquals;
+import java.util.List;
+import java.util.Map;
+
+import org.easymock.EasyMock;
+import org.jclouds.compute.domain.NodeMetadata;
+import org.jclouds.compute.functions.GroupNamingConvention;
+import org.jclouds.docker.domain.Config;
+import org.jclouds.docker.domain.Container;
+import org.jclouds.docker.domain.HostConfig;
+import org.jclouds.docker.domain.NetworkSettings;
+import org.jclouds.docker.domain.Port;
+import org.jclouds.docker.domain.State;
+import org.jclouds.providers.ProviderMetadata;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.inject.Guice;
+
+/**
+ * Unit tests for the {@link org.jclouds.docker.compute.functions.ContainerToNodeMetadata} class.
+ *
+ * @author Andrea Turli
+ */
+@Test(groups = "unit", testName = "ContainerToNodeMetadataTest")
+public class ContainerToNodeMetadataTest {
+ private ContainerToNodeMetadata function;
+
+ private Container container;
+
+ @BeforeMethod
+ public void setup() {
+ Config config = Config.builder()
+ .hostname("6d35806c1bd2")
+ .domainName("")
+ .user("")
+ .memory(0)
+ .memorySwap(0)
+ .cpuShares(0)
+ .attachStdin(false)
+ .attachStdout(false)
+ .attachStderr(false)
+ .exposedPorts(ImmutableMap.of("22/tcp", ImmutableMap.of()))
+ .tty(false)
+ .openStdin(false)
+ .stdinOnce(false)
+ .env(null)
+ .cmd(ImmutableList.of("/usr/sbin/sshd", "-D"))
+ .imageId("jclouds/ubuntu")
+ .volumesFrom("")
+ .workingDir("")
+ .entrypoint(null)
+ .networkDisabled(false)
+ .onBuild(null)
+ .build();
+ State state = State.builder()
+ .pid(3626)
+ .running(true)
+ .exitCode(0)
+ .startedAt("2014-03-24T20:28:37.537659054Z")
+ .finishedAt("0001-01-01T00:00:00Z")
+ .ghost(false)
+ .build();
+ container = Container.builder()
+ .id("6d35806c1bd2b25cd92bba2d2c2c5169dc2156f53ab45c2b62d76e2d2fee14a9")
+ .name("/hopeful_mclean")
+ .created("2014-03-22T07:16:45.784120972Z")
+ .path("/usr/sbin/sshd")
+ .args(new String[] {"-D"})
+ .config(config)
+ .state(state)
+ .image("af0f59f1c19eef9471c3b8c8d587c39b8f130560b54f3766931b37d76d5de4b6")
+ .networkSettings(NetworkSettings.builder()
+ .ipAddress("172.17.0.2")
+ .ipPrefixLen(16)
+ .gateway("172.17.42.1")
+ .bridge("docker0")
+ .ports(ImmutableMap.<String, List<Map<String, String>>>of("22/tcp",
+ ImmutableList.<Map<String, String>>of(ImmutableMap.of("HostIp", "0.0.0.0", "HostPort",
+ "49199"))))
+ .build())
+ .resolvConfPath("/etc/resolv.conf")
+ .driver("aufs")
+ .execDriver("native-0.1")
+ .volumes(ImmutableMap.<String, String>of())
+ .volumesRw(ImmutableMap.<String, Boolean>of())
+ .command("")
+ .status("")
+ .hostConfig(HostConfig.builder().publishAllPorts(true).build())
+ .ports(ImmutableList.<Port>of())
+ .build();
+ ProviderMetadata providerMetadata = EasyMock.createMock(ProviderMetadata.class);
+ expect(providerMetadata.getEndpoint()).andReturn("http://127.0.0.1:4243");
+ replay(providerMetadata);
+
+ GroupNamingConvention.Factory namingConvention = Guice.createInjector().getInstance(GroupNamingConvention.Factory.class);
+
+ function = new ContainerToNodeMetadata(providerMetadata, toPortableStatus(), namingConvention);
+ }
+
+ private Function<State, NodeMetadata.Status> toPortableStatus() {
+ StateToStatus function = EasyMock.createMock(StateToStatus.class);
+ expect(function.apply(anyObject(State.class))).andReturn(NodeMetadata.Status.RUNNING);
+ replay(function);
+ return function;
+ }
+
+ public void testVirtualMachineToNodeMetadata() {
+ Container mockContainer = mockContainer();
+
+ NodeMetadata node = function.apply(mockContainer);
+
+ verify(mockContainer);
+
+ assertEquals(node.getId(), "6d35806c1bd2b25cd92bba2d2c2c5169dc2156f53ab45c2b62d76e2d2fee14a9");
+ assertEquals(node.getGroup(), "hopeful_mclean");
+ assertEquals(node.getImageId(), "af0f59f1c19eef9471c3b8c8d587c39b8f130560b54f3766931b37d76d5de4b6");
+ assertEquals(node.getLoginPort(), 49199);
+ assertEquals(node.getPrivateAddresses().size(), 1);
+ assertEquals(node.getPublicAddresses().size(), 1);
+ }
+
+ @SuppressWarnings("unchecked")
+ private Container mockContainer() {
+ Container mockContainer = EasyMock.createMock(Container.class);
+
+ expect(mockContainer.getId()).andReturn(container.getId());
+ expect(mockContainer.getName()).andReturn(container.getName());
+ expect(mockContainer.getConfig()).andReturn(container.getConfig()).anyTimes();
+ expect(mockContainer.getNetworkSettings()).andReturn(container.getNetworkSettings()).anyTimes();
+ expect(mockContainer.getState()).andReturn(container.getState());
+ expect(mockContainer.getImage()).andReturn(container.getImage());
+ replay(mockContainer);
+
+ return mockContainer;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/d45ad99a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/functions/ImageToImageTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/functions/ImageToImageTest.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/functions/ImageToImageTest.java
new file mode 100644
index 0000000..c46bdb1
--- /dev/null
+++ b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/functions/ImageToImageTest.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * work for additional information regarding copyright ownership.
+ * The ASF licenses file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use 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.jclouds.docker.compute.functions;
+
+import com.google.common.collect.ImmutableList;
+import org.easymock.EasyMock;
+import org.jclouds.compute.domain.Image;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.testng.Assert.assertEquals;
+
+/**
+ * Unit tests for the {@link org.jclouds.docker.compute.functions.ImageToImage} class.
+ *
+ * @author Andrea Turli
+ */
+@Test(groups = "unit", testName = "ImageToImageTest")
+public class ImageToImageTest {
+ private ImageToImage function;
+
+ private org.jclouds.docker.domain.Image image;
+
+ @BeforeMethod
+ public void setup() {
+ image = org.jclouds.docker.domain.Image.builder()
+ .id("id")
+ .parent("parent")
+ .created("created")
+ .architecture("x86_64")
+ .repoTags(ImmutableList.of("repoTag1:version"))
+ .size(0l)
+ .build();
+ function = new ImageToImage();
+ }
+
+ public void testImageToImage() {
+ org.jclouds.docker.domain.Image mockImage = mockImage();
+
+ Image image = function.apply(mockImage);
+
+ verify(mockImage);
+
+ assertEquals(mockImage.getId(), image.getId().toString());
+ }
+
+ @SuppressWarnings("unchecked")
+ private org.jclouds.docker.domain.Image mockImage() {
+ org.jclouds.docker.domain.Image mockImage = EasyMock.createMock(org.jclouds.docker.domain.Image.class);
+
+ expect(mockImage.getId()).andReturn(image.getId()).anyTimes();
+ expect(mockImage.getRepoTags()).andReturn(image.getRepoTags()).anyTimes();
+ expect(mockImage.getArchitecture()).andReturn(image.getArchitecture()).anyTimes();
+ replay(mockImage);
+
+ return mockImage;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/d45ad99a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/functions/StateToStatusTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/functions/StateToStatusTest.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/functions/StateToStatusTest.java
new file mode 100644
index 0000000..c1a8002
--- /dev/null
+++ b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/test/java/org/jclouds/docker/compute/functions/StateToStatusTest.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * work for additional information regarding copyright ownership.
+ * The ASF licenses file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use 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.jclouds.docker.compute.functions;
+
+import org.easymock.EasyMock;
+import org.jclouds.compute.domain.NodeMetadata;
+import org.jclouds.docker.domain.State;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.testng.Assert.assertEquals;
+
+/**
+ * Unit tests for the {@link StateToStatus} class.
+ *
+ * @author Andrea Turli
+ */
+@Test(groups = "unit", testName = "StateToStatusTest")
+public class StateToStatusTest {
+ private StateToStatus function;
+
+ @BeforeMethod
+ public void setup() {
+ function = new StateToStatus();
+ }
+
+ public void testStateRunningToStatusRunning() {
+ State mockState = mockStateRunning();
+
+ NodeMetadata.Status status = function.apply(mockState);
+
+ verify(mockState);
+
+ assertEquals(mockState.isRunning(), true);
+ assertEquals(status, NodeMetadata.Status.RUNNING);
+ }
+
+ public void testStateNotRunningToStatusSuspended() {
+ State mockState = mockStateNotRunning();
+
+ NodeMetadata.Status status = function.apply(mockState);
+
+ verify(mockState);
+
+ assertEquals(mockState.isRunning(), false);
+ assertEquals(status, NodeMetadata.Status.SUSPENDED);
+ }
+
+ private State mockStateRunning() {
+ State mockState = EasyMock.createMock(State.class);
+
+ expect(mockState.isRunning()).andReturn(true).anyTimes();
+ replay(mockState);
+
+ return mockState;
+ }
+
+ private State mockStateNotRunning() {
+ State mockState = EasyMock.createMock(State.class);
+
+ expect(mockState.isRunning()).andReturn(false).anyTimes();
+ replay(mockState);
+
+ return mockState;
+ }
+}