http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/config/DockerComputeServiceContextModule.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/config/DockerComputeServiceContextModule.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/config/DockerComputeServiceContextModule.java deleted file mode 100644 index 7368299..0000000 --- a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/config/DockerComputeServiceContextModule.java +++ /dev/null @@ -1,73 +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.jclouds.docker.compute.config; - -import com.google.common.base.Function; -import com.google.common.base.Optional; -import com.google.inject.Injector; -import com.google.inject.TypeLiteral; -import org.jclouds.compute.ComputeServiceAdapter; -import org.jclouds.compute.config.ComputeServiceAdapterContextModule; -import org.jclouds.compute.domain.Hardware; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.extensions.ImageExtension; -import org.jclouds.compute.options.TemplateOptions; -import org.jclouds.docker.compute.extensions.DockerImageExtension; -import org.jclouds.docker.compute.functions.ContainerToNodeMetadata; -import org.jclouds.docker.compute.functions.ImageToImage; -import org.jclouds.docker.compute.functions.StateToStatus; -import org.jclouds.docker.compute.options.DockerTemplateOptions; -import org.jclouds.docker.compute.strategy.DockerComputeServiceAdapter; -import org.jclouds.docker.domain.Container; -import org.jclouds.docker.domain.Image; -import org.jclouds.docker.domain.State; -import org.jclouds.domain.Location; -import org.jclouds.functions.IdentityFunction; - -/** - * @author Andrea Turli - */ -public class DockerComputeServiceContextModule extends - ComputeServiceAdapterContextModule<Container, Hardware, Image, Location> { - - @Override - protected void configure() { - super.configure(); - bind(new TypeLiteral<ComputeServiceAdapter<Container, Hardware, Image, Location>>() { - }).to(DockerComputeServiceAdapter.class); - bind(new TypeLiteral<Function<Container, NodeMetadata>>() { - }).to(ContainerToNodeMetadata.class); - bind(new TypeLiteral<Function<Image, org.jclouds.compute.domain.Image>>() { - }).to(ImageToImage.class); - bind(new TypeLiteral<Function<Hardware, Hardware>>() { - }).to(Class.class.cast(IdentityFunction.class)); - bind(new TypeLiteral<Function<Location, Location>>() { - }).to(Class.class.cast(IdentityFunction.class)); - bind(new TypeLiteral<Function<State, NodeMetadata.Status>>() { - }).to(StateToStatus.class); - bind(TemplateOptions.class).to(DockerTemplateOptions.class); - - bind(new TypeLiteral<ImageExtension>() { - }).to(DockerImageExtension.class); - } - - @Override - protected Optional<ImageExtension> provideImageExtension(Injector i) { - return Optional.of(i.getInstance(ImageExtension.class)); - } - -}
http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/extensions/DockerImageExtension.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/extensions/DockerImageExtension.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/extensions/DockerImageExtension.java deleted file mode 100644 index 8b4820d..0000000 --- a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/extensions/DockerImageExtension.java +++ /dev/null @@ -1,120 +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.jclouds.docker.compute.extensions; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_IMAGE_AVAILABLE; -import java.util.NoSuchElementException; -import java.util.concurrent.Callable; -import java.util.concurrent.atomic.AtomicReference; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.Constants; -import org.jclouds.compute.domain.CloneImageTemplate; -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.ImageTemplate; -import org.jclouds.compute.domain.ImageTemplateBuilder; -import org.jclouds.compute.extensions.ImageExtension; -import org.jclouds.compute.reference.ComputeServiceConstants; -import org.jclouds.docker.DockerApi; -import org.jclouds.docker.compute.functions.ImageToImage; -import org.jclouds.docker.domain.Container; -import org.jclouds.docker.options.CommitOptions; -import org.jclouds.logging.Logger; - -import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableList; -import com.google.common.util.concurrent.Atomics; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.common.util.concurrent.UncheckedTimeoutException; - -/** - * Docker implementation of {@link org.jclouds.compute.extensions.ImageExtension} - * - * @author Andrea Turli - */ -@Singleton -public class DockerImageExtension implements ImageExtension { - - @Resource - @Named(ComputeServiceConstants.COMPUTE_LOGGER) - private Logger logger = Logger.NULL; - private final DockerApi api; - private final ListeningExecutorService userExecutor; - private final Predicate<AtomicReference<Image>> imageAvailablePredicate; - - @Inject - public DockerImageExtension(DockerApi api, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService - userExecutor, @Named(TIMEOUT_IMAGE_AVAILABLE) Predicate<AtomicReference<Image>> imageAvailablePredicate) { - this.api = checkNotNull(api, "api"); - this.userExecutor = checkNotNull(userExecutor, "userExecutor"); - this.imageAvailablePredicate = checkNotNull(imageAvailablePredicate, "imageAvailablePredicate"); - } - - @Override - public ImageTemplate buildImageTemplateFromNode(String name, final String id) { - Container container = api.getRemoteApi().inspectContainer(id); - if (container == null) - throw new NoSuchElementException("Cannot find container with id: " + id); - CloneImageTemplate template = new ImageTemplateBuilder.CloneImageTemplateBuilder().nodeId(id).name(name).build(); - return template; - } - - @Override - public ListenableFuture<Image> createImage(ImageTemplate template) { - checkArgument(template instanceof CloneImageTemplate, - " docker only currently supports creating images through cloning."); - CloneImageTemplate cloneTemplate = (CloneImageTemplate) template; - - Container container = api.getRemoteApi().inspectContainer(cloneTemplate.getSourceNodeId()); - CommitOptions options = CommitOptions.Builder.containerId(container.getId()).tag(cloneTemplate.getName()); - org.jclouds.docker.domain.Image dockerImage = api.getRemoteApi().commit(options); - - dockerImage = org.jclouds.docker.domain.Image.builder().fromImage(dockerImage) - .repoTags(ImmutableList.of(cloneTemplate.getName() + ":latest")) - .build(); - - logger.info(">> Registered new image %s, waiting for it to become available.", dockerImage.getId()); - final AtomicReference<Image> image = Atomics.newReference(new ImageToImage().apply(dockerImage)); - return userExecutor.submit(new Callable<Image>() { - @Override - public Image call() throws Exception { - if (imageAvailablePredicate.apply(image)) - return image.get(); - throw new UncheckedTimeoutException("Image was not created within the time limit: " + image.get()); - } - }); - } - - @Override - public boolean deleteImage(String id) { - try { - api.getRemoteApi().deleteImage(id); - } catch (Exception e) { - logger.error(e, "Could not delete image with id %s ", id); - return false; - } - return true; - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/features/RemoteApi.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/features/RemoteApi.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/features/RemoteApi.java deleted file mode 100644 index bc4abff..0000000 --- a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/features/RemoteApi.java +++ /dev/null @@ -1,275 +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.jclouds.docker.compute.features; - -import java.io.Closeable; -import java.io.File; -import java.io.InputStream; -import java.util.Set; - -import javax.inject.Named; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; - -import org.jclouds.Fallbacks; -import org.jclouds.docker.binders.BindInputStreamToRequest; -import org.jclouds.docker.domain.Config; -import org.jclouds.docker.domain.Container; -import org.jclouds.docker.domain.HostConfig; -import org.jclouds.docker.domain.Image; -import org.jclouds.docker.domain.Version; -import org.jclouds.docker.options.BuildOptions; -import org.jclouds.docker.options.CommitOptions; -import org.jclouds.docker.options.CreateImageOptions; -import org.jclouds.docker.options.DeleteImageOptions; -import org.jclouds.docker.options.ListContainerOptions; -import org.jclouds.docker.options.ListImageOptions; -import org.jclouds.docker.options.RemoveContainerOptions; -import org.jclouds.io.Payload; -import org.jclouds.rest.annotations.BinderParam; -import org.jclouds.rest.annotations.Fallback; -import org.jclouds.rest.annotations.Headers; -import org.jclouds.rest.binders.BindToJsonPayload; - -/** - * @author Andrea Turli - */ -@Consumes(MediaType.APPLICATION_JSON) -public interface RemoteApi extends Closeable { - - /** - * Get the information of the current docker version. - * - * @return The information of the current docker version. - */ - @Named("version") - @GET - @Path("/version") - Version getVersion(); - - /** - * List all running containers - * - * @return a set of containers - */ - @Named("containers:list") - @GET - @Path("/containers/json") - @Fallback(Fallbacks.EmptySetOnNotFoundOr404.class) - Set<Container> listContainers(); - - /** - * List all running containers - * - * @param options the options to list the containers (@see ListContainerOptions) - * @return a set of containers - */ - @Named("containers:list") - @GET - @Path("/containers/json") - @Fallback(Fallbacks.EmptySetOnNotFoundOr404.class) - Set<Container> listContainers(ListContainerOptions options); - - /** - * Create a container - * - * @param name the name for the new container. Must match /?[a-zA-Z0-9_-]+. - * @param config the containerâs configuration (@see BindToJsonPayload) - * @return a new container - */ - @Named("container:create") - @POST - @Path("/containers/create") - Container createContainer(@QueryParam("name") String name, @BinderParam(BindToJsonPayload.class) Config config); - - /** - * Return low-level information on the container id - * @param containerId The id of the container to get. - * @return The details of the container or <code>null</code> if the container with the given id doesn't exist. - */ - @Named("container:inspect") - @GET - @Path("/containers/{id}/json") - @Fallback(Fallbacks.NullOnNotFoundOr404.class) - Container inspectContainer(@PathParam("id") String containerId); - - /** - * Remove the container by id from the filesystem - * - * @param containerId The id of the container to be removed. - */ - @Named("container:delete") - @DELETE - @Path("/containers/{id}") - void removeContainer(@PathParam("id") String containerId); - - /** - * Remove the container by id from the filesystem - * - * @param containerId The id of the container to be removed. - * @param options the operationâs configuration (@see RemoveContainerOptions) - */ - @Named("container:delete") - @DELETE - @Path("/containers/{id}") - void removeContainer(@PathParam("id") String containerId, RemoveContainerOptions options); - - /** - * Start a container by id. - * - * @param containerId The id of the container to be started. - */ - @Named("container:start") - @POST - @Path("/containers/{id}/start") - void startContainer(@PathParam("id") String containerId); - - /** - * Start a container. - * - * @param containerId The id of the container to be started. - * @param hostConfig the containerâs host configuration - */ - @Named("container:start") - @POST - @Path("/containers/{id}/start") - void startContainer(@PathParam("id") String containerId, @BinderParam(BindToJsonPayload.class) HostConfig hostConfig); - - /** - * Stop a container by id. - * - * @param containerId The id of the container to be stopped. - * @return the stream of the stop execution. - */ - @Named("container:stop") - @POST - @Path("/containers/{id}/stop") - void stopContainer(@PathParam("id") String containerId); - - /** - * Create a new image from a containerâs changes - * - * @param options the commitâs configuration (@see CommitOptions) - * @return a new image created from the current container's status. - */ - @Named("container:commit") - @POST - @Path("/commit") - Image commit(CommitOptions options); - - /** - * List images - * - * @return the images available. - */ - @Named("images:list") - @GET - @Path("/images/json") - @Fallback(Fallbacks.EmptySetOnNotFoundOr404.class) - Set<Image> listImages(); - - /** - * List images - * - * @param options the configuration to list images (@see ListImageOptions) - * @return the images available. - */ - @Named("images:list") - @GET - @Path("/images/json") - @Fallback(Fallbacks.EmptySetOnNotFoundOr404.class) - Set<Image> listImages(ListImageOptions options); - - /** - * Inspect an image - * - * @param imageId The id of the image to inspect. - * @return low-level information on the image name - */ - @Named("image:inspect") - @GET - @Path("/images/{name}/json") - Image inspectImage(@PathParam("name") String imageName); - - /** - * Create an image, either by pull it from the registry or by importing it - * - * @param options the configuration to create an image (@see CreateImageOptions) - * @return a stream of the image creation. - */ - @Named("image:create") - @POST - @Path("/images/create") - InputStream createImage(CreateImageOptions options); - - /** - * Delete an image. - * - * @param name the image name to be deleted - * @return the stream of the deletion execution. - */ - @Named("image:delete") - @DELETE - @Path("/images/{name}") - InputStream deleteImage(@PathParam("name") String name); - - /** - * Remove the image from the filesystem by name - * - * @param name the name of the image to be removed - * @param options the image deletion's options (@see DeleteImageOptions) - * @return the stream of the deletion execution. - */ - @Named("image:delete") - @DELETE - @Path("/images/{name}") - InputStream deleteImage(@PathParam("name") String name, DeleteImageOptions options); - - /** - * Build an image from Dockerfile via stdin - * - * @param inputStream The stream must be a tar archive compressed with one of the following algorithms: identity - * (no compression), gzip, bzip2, xz. - * @param options the image build's options (@see BuildOptions) - * @return a stream of the build execution - */ - @Named("image:build") - @POST - @Path("/build") - @Headers(keys = "Content-Type", values = "application/tar") - InputStream build(Payload inputStream, BuildOptions options); - - /** - * Build an image from Dockerfile via stdin - * - * @param dockerFile The file to be compressed with one of the following algorithms: identity, gzip, bzip2, xz.* - * @param options the image build's options (@see BuildOptions) - * @return a stream of the build execution - */ - @Named("image:build") - @POST - @Path("/build") - @Headers(keys = "Content-Type", values = "application/tar") - InputStream build(@BinderParam(BindInputStreamToRequest.class) File dockerFile, BuildOptions options); - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/features/internal/Archives.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/features/internal/Archives.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/features/internal/Archives.java deleted file mode 100644 index 49641b9..0000000 --- a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/features/internal/Archives.java +++ /dev/null @@ -1,96 +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.jclouds.docker.compute.features.internal; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.collect.Iterables.getLast; -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; - -import org.apache.commons.compress.archivers.tar.TarArchiveEntry; -import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; - -import com.google.common.base.Splitter; - -/** - * @author Andrea Turli - */ -public class Archives { - - public static File tar(File baseDir, String archivePath) throws IOException { - // Check that the directory is a directory, and get its contents - checkArgument(baseDir.isDirectory(), "%s is not a directory", baseDir); - File[] files = baseDir.listFiles(); - File tarFile = new File(archivePath); - - String token = getLast(Splitter.on("/").split(archivePath.substring(0, archivePath.lastIndexOf("/")))); - - byte[] buf = new byte[1024]; - int len; - TarArchiveOutputStream tos = new TarArchiveOutputStream(new FileOutputStream(tarFile)); - tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); - for (File file : files) { - TarArchiveEntry tarEntry = new TarArchiveEntry(file); - tarEntry.setName("/" + getLast(Splitter.on(token).split(file.toString()))); - tos.putArchiveEntry(tarEntry); - if (!file.isDirectory()) { - FileInputStream fin = new FileInputStream(file); - BufferedInputStream in = new BufferedInputStream(fin); - while ((len = in.read(buf)) != -1) { - tos.write(buf, 0, len); - } - in.close(); - } - tos.closeArchiveEntry(); - } - tos.close(); - return tarFile; - } - - public static File tar(File baseDir, File tarFile) throws IOException { - // Check that the directory is a directory, and get its contents - checkArgument(baseDir.isDirectory(), "%s is not a directory", baseDir); - File[] files = baseDir.listFiles(); - - String token = getLast(Splitter.on("/").split(baseDir.getAbsolutePath())); - - byte[] buf = new byte[1024]; - int len; - TarArchiveOutputStream tos = new TarArchiveOutputStream(new FileOutputStream(tarFile)); - tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); - for (File file : files) { - TarArchiveEntry tarEntry = new TarArchiveEntry(file); - tarEntry.setName("/" + getLast(Splitter.on(token).split(file.toString()))); - tos.putArchiveEntry(tarEntry); - if (!file.isDirectory()) { - FileInputStream fin = new FileInputStream(file); - BufferedInputStream in = new BufferedInputStream(fin); - while ((len = in.read(buf)) != -1) { - tos.write(buf, 0, len); - } - in.close(); - } - tos.closeArchiveEntry(); - } - tos.close(); - return tarFile; - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/functions/ContainerToNodeMetadata.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/functions/ContainerToNodeMetadata.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/functions/ContainerToNodeMetadata.java deleted file mode 100644 index 8cbcd6c..0000000 --- a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/functions/ContainerToNodeMetadata.java +++ /dev/null @@ -1,131 +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.jclouds.docker.compute.functions; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.getOnlyElement; -import java.net.URI; -import java.util.List; -import java.util.Map; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; - -import org.jclouds.compute.domain.HardwareBuilder; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.NodeMetadataBuilder; -import org.jclouds.compute.domain.OperatingSystem; -import org.jclouds.compute.domain.OsFamily; -import org.jclouds.compute.domain.Processor; -import org.jclouds.compute.functions.GroupNamingConvention; -import org.jclouds.compute.reference.ComputeServiceConstants; -import org.jclouds.docker.domain.Container; -import org.jclouds.docker.domain.Port; -import org.jclouds.docker.domain.State; -import org.jclouds.domain.LocationBuilder; -import org.jclouds.domain.LocationScope; -import org.jclouds.logging.Logger; -import org.jclouds.providers.ProviderMetadata; - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableList; -import com.google.inject.Singleton; - -/** - * @author Andrea Turli - */ -@Singleton -public class ContainerToNodeMetadata implements Function<Container, NodeMetadata> { - - @Resource - @Named(ComputeServiceConstants.COMPUTE_LOGGER) - protected Logger logger = Logger.NULL; - - private final ProviderMetadata providerMetadata; - private final Function<State, NodeMetadata.Status> toPortableStatus; - private final GroupNamingConvention nodeNamingConvention; - - @Inject - public ContainerToNodeMetadata(ProviderMetadata providerMetadata, Function<State, - NodeMetadata.Status> toPortableStatus, GroupNamingConvention.Factory namingConvention) { - this.providerMetadata = checkNotNull(providerMetadata, "providerMetadata"); - this.toPortableStatus = checkNotNull(toPortableStatus, "toPortableStatus cannot be null"); - this.nodeNamingConvention = checkNotNull(namingConvention, "namingConvention").createWithoutPrefix(); - } - - @Override - public NodeMetadata apply(Container container) { - String name = cleanUpName(container.getName()); - String group = nodeNamingConvention.extractGroup(name); - NodeMetadataBuilder builder = new NodeMetadataBuilder(); - builder.ids(container.getId()) - .name(name) - .group(group) - .hostname(container.getConfig().getHostname()) - // TODO Set up hardware - .hardware(new HardwareBuilder() - .id("") - .ram(container.getConfig().getMemory()) - .processor(new Processor(container.getConfig().getCpuShares(), container.getConfig().getCpuShares())) - .build()); - // TODO Set up location properly - LocationBuilder locationBuilder = new LocationBuilder(); - locationBuilder.description(""); - locationBuilder.id(""); - locationBuilder.scope(LocationScope.HOST); - builder.location(locationBuilder.build()); - builder.status(toPortableStatus.apply(container.getState())); - builder.imageId(container.getImage()); - builder.loginPort(getLoginPort(container)); - builder.publicAddresses(getPublicIpAddresses()); - builder.privateAddresses(getPrivateIpAddresses(container)); - builder.operatingSystem(OperatingSystem.builder().description("linux").family(OsFamily.LINUX).build()); - return builder.build(); - } - - private String cleanUpName(String name) { - return name.startsWith("/") ? name.substring(1) : name; - } - - private Iterable<String> getPrivateIpAddresses(Container container) { - if (container.getNetworkSettings() == null) return ImmutableList.of(); - return ImmutableList.of(container.getNetworkSettings().getIpAddress()); - } - - private List<String> getPublicIpAddresses() { - String dockerIpAddress = URI.create(providerMetadata.getEndpoint()).getHost(); - return ImmutableList.of(dockerIpAddress); - } - - protected static int getLoginPort(Container container) { - if (container.getNetworkSettings() != null) { - Map<String, List<Map<String,String>>> ports = container.getNetworkSettings().getPorts(); - if(ports != null) { - return Integer.parseInt(getOnlyElement(ports.get("22/tcp")).get("HostPort")); - } - // this is needed in case the container list is coming from listContainers - } else if (container.getPorts() != null) { - for (Port port : container.getPorts()) { - if (port.getPrivatePort() == 22) { - return port.getPublicPort(); - } - } - } - throw new IllegalStateException("Cannot determine the login port for " + container.getId()); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/functions/ImageToImage.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/functions/ImageToImage.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/functions/ImageToImage.java deleted file mode 100644 index bcbc53f..0000000 --- a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/functions/ImageToImage.java +++ /dev/null @@ -1,104 +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.jclouds.docker.compute.functions; - -import com.google.common.base.Function; -import com.google.common.base.Splitter; -import com.google.common.collect.Iterables; -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.ImageBuilder; -import org.jclouds.compute.domain.OperatingSystem; -import org.jclouds.compute.domain.OsFamily; -import org.jclouds.compute.reference.ComputeServiceConstants; -import org.jclouds.logging.Logger; - -import javax.annotation.Resource; -import javax.inject.Named; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.get; - -/** - * @author Andrea Turli - */ -public class ImageToImage implements Function<org.jclouds.docker.domain.Image, org.jclouds.compute.domain.Image> { - - private static final String CENTOS = "centos"; - private static final String UBUNTU = "ubuntu"; - - @Resource - @Named(ComputeServiceConstants.COMPUTE_LOGGER) - protected Logger logger = Logger.NULL; - - @Override - public Image apply(org.jclouds.docker.domain.Image from) { - checkNotNull(from, "image"); - String description = checkNotNull(Iterables.getFirst(from.getRepoTags(), null)); - - OsFamily osFamily = osFamily().apply(description); - String osVersion = parseVersion(description); - - OperatingSystem os = OperatingSystem.builder() - .description(description) - .family(osFamily) - .version(osVersion) - .is64Bit(is64bit(from)) - .build(); - - return new ImageBuilder() - .ids(from.getId()) - .name(get(Splitter.on(":").split(description), 0)) - .description(description) - .operatingSystem(os) - .status(Image.Status.AVAILABLE) - .build(); - } - - private boolean is64bit(org.jclouds.docker.domain.Image inspectedImage) { - if(inspectedImage.getArchitecture() == null) return true; - return inspectedImage.getArchitecture().matches("x86_64|amd64"); - } - - /** - * Parses the item description to determine the OSFamily - * - * @return the @see OsFamily or OsFamily.UNRECOGNIZED - */ - private Function<String, OsFamily> osFamily() { - return new Function<String, OsFamily>() { - OsFamily osFamily = OsFamily.UNRECOGNIZED; - - @Override - public OsFamily apply(final String description) { - if (description != null) { - if (description.contains(CENTOS)) osFamily = OsFamily.CENTOS; - else if (description.contains(UBUNTU)) - osFamily = OsFamily.UBUNTU; - } - logger.debug("os family for item: %s is %s", description, osFamily); - return osFamily; - } - }; - } - - private String parseVersion(String description) { - String version = get(Splitter.on(":").split(description), 1); - logger.debug("os version for item: %s is %s", description, version); - return version; - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/functions/StateToStatus.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/functions/StateToStatus.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/functions/StateToStatus.java deleted file mode 100644 index d2df146..0000000 --- a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/functions/StateToStatus.java +++ /dev/null @@ -1,40 +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.jclouds.docker.compute.functions; - -import com.google.common.base.Function; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.NodeMetadata.Status; -import org.jclouds.docker.domain.State; - -import javax.inject.Singleton; - -/** - * Transforms an {@link org.jclouds.docker.domain.Container} to the jclouds portable model. - * - * @author Andrea Turli - */ -@Singleton -public class StateToStatus implements Function<State, Status> { - - @Override - public Status apply(final State state) { - if (state == null) return Status.UNRECOGNIZED; - return state.isRunning() ? NodeMetadata.Status.RUNNING : NodeMetadata.Status.SUSPENDED; - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/options/DockerTemplateOptions.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/options/DockerTemplateOptions.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/options/DockerTemplateOptions.java deleted file mode 100644 index 1303756..0000000 --- a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/options/DockerTemplateOptions.java +++ /dev/null @@ -1,365 +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.jclouds.docker.compute.options; - -import static com.google.common.base.Objects.equal; -import java.util.Map; - -import org.jclouds.compute.options.TemplateOptions; -import org.jclouds.domain.LoginCredentials; -import org.jclouds.scriptbuilder.domain.Statement; - -import com.google.common.base.Objects; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableMap; - -/** - * Contains options supported in the {@code ComputeService#runNode} operation on the - * "docker" provider. <h2>Usage</h2> The recommended way to instantiate a - * DockerTemplateOptions object is to statically import DockerTemplateOptions.* and invoke a static - * creation method followed by an instance mutator (if needed): - * <p/> - * <code> - * import static org.jclouds.aws.ec2.compute.options.DockerTemplateOptions.Builder.*; - * <p/> - * ComputeService api = // get connection - * templateBuilder.options(inboundPorts(22, 80, 8080, 443)); - * Set<? extends NodeMetadata> set = api.createNodesInGroup(tag, 2, templateBuilder.build()); - * <code> - * - * @author Andrea Turli - */ -public class DockerTemplateOptions extends TemplateOptions implements Cloneable { - @Override - public DockerTemplateOptions clone() { - DockerTemplateOptions options = new DockerTemplateOptions(); - copyTo(options); - return options; - } - - @Override - public void copyTo(TemplateOptions to) { - super.copyTo(to); - if (to instanceof DockerTemplateOptions) { - DockerTemplateOptions eTo = DockerTemplateOptions.class.cast(to); - if (getVolumes().isPresent()) { - eTo.volumes(getVolumes().get()); - } - } - } - - protected Optional<Map<String, String>> volumes = Optional.absent(); - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - DockerTemplateOptions that = DockerTemplateOptions.class.cast(o); - return super.equals(that) && equal(this.volumes, that.volumes); - } - - @Override - public int hashCode() { - return Objects.hashCode(super.hashCode(), volumes); - } - - @Override - public Objects.ToStringHelper string() { - Objects.ToStringHelper toString = super.string(); - if (volumes.isPresent()) - toString.add("volumes", volumes.get()); - return toString; - } - - public static final DockerTemplateOptions NONE = new DockerTemplateOptions(); - - public DockerTemplateOptions volumes(Map<String, String> volumes) { - this.volumes = Optional.<Map<String, String>> of(ImmutableMap.copyOf(volumes)); - return this; - } - - public Optional<Map<String, String>> getVolumes() { - return volumes; - } - - public static class Builder { - - /** - * @see DockerTemplateOptions#volumes(java.util.Map) - */ - public static DockerTemplateOptions volumes(Map<String, String> volumes) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return DockerTemplateOptions.class.cast(options.volumes(volumes)); - } - - // methods that only facilitate returning the correct object type - - /** - * @see TemplateOptions#inboundPorts - */ - public static DockerTemplateOptions inboundPorts(int... ports) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return DockerTemplateOptions.class.cast(options.inboundPorts(ports)); - } - - /** - * @see TemplateOptions#port - */ - public static DockerTemplateOptions blockOnPort(int port, int seconds) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return DockerTemplateOptions.class.cast(options.blockOnPort(port, seconds)); - } - - /** - * @see TemplateOptions#installPrivateKey - */ - public static DockerTemplateOptions installPrivateKey(String rsaKey) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return DockerTemplateOptions.class.cast(options.installPrivateKey(rsaKey)); - } - - /** - * @see TemplateOptions#authorizePublicKey - */ - public static DockerTemplateOptions authorizePublicKey(String rsaKey) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return DockerTemplateOptions.class.cast(options.authorizePublicKey(rsaKey)); - } - - /** - * @see TemplateOptions#userMetadata - */ - public static DockerTemplateOptions userMetadata(Map<String, String> userMetadata) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return DockerTemplateOptions.class.cast(options.userMetadata(userMetadata)); - } - - /** - * @see TemplateOptions#nodeNames(Iterable) - */ - public static DockerTemplateOptions nodeNames(Iterable<String> nodeNames) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return DockerTemplateOptions.class.cast(options.nodeNames(nodeNames)); - } - - /** - * @see TemplateOptions#networks(Iterable) - */ - public static DockerTemplateOptions networks(Iterable<String> networks) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return DockerTemplateOptions.class.cast(options.networks(networks)); - } - - /** - * @see TemplateOptions#overrideLoginUser - */ - public static DockerTemplateOptions overrideLoginUser(String user) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.overrideLoginUser(user); - } - - /** - * @see TemplateOptions#overrideLoginPassword - */ - public static DockerTemplateOptions overrideLoginPassword(String password) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.overrideLoginPassword(password); - } - - /** - * @see TemplateOptions#overrideLoginPrivateKey - */ - public static DockerTemplateOptions overrideLoginPrivateKey(String privateKey) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.overrideLoginPrivateKey(privateKey); - } - - /** - * @see TemplateOptions#overrideAuthenticateSudo - */ - public static DockerTemplateOptions overrideAuthenticateSudo(boolean authenticateSudo) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.overrideAuthenticateSudo(authenticateSudo); - } - - /** - * @see TemplateOptions#overrideLoginCredentials - */ - public static DockerTemplateOptions overrideLoginCredentials(LoginCredentials credentials) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.overrideLoginCredentials(credentials); - } - - /** - * @see TemplateOptions#blockUntilRunning - */ - public static DockerTemplateOptions blockUntilRunning(boolean blockUntilRunning) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.blockUntilRunning(blockUntilRunning); - } - - } - - // methods that only facilitate returning the correct object type - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions blockOnPort(int port, int seconds) { - return DockerTemplateOptions.class.cast(super.blockOnPort(port, seconds)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions inboundPorts(int... ports) { - return DockerTemplateOptions.class.cast(super.inboundPorts(ports)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions authorizePublicKey(String publicKey) { - return DockerTemplateOptions.class.cast(super.authorizePublicKey(publicKey)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions installPrivateKey(String privateKey) { - return DockerTemplateOptions.class.cast(super.installPrivateKey(privateKey)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions blockUntilRunning(boolean blockUntilRunning) { - return DockerTemplateOptions.class.cast(super.blockUntilRunning(blockUntilRunning)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions dontAuthorizePublicKey() { - return DockerTemplateOptions.class.cast(super.dontAuthorizePublicKey()); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions nameTask(String name) { - return DockerTemplateOptions.class.cast(super.nameTask(name)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions runAsRoot(boolean runAsRoot) { - return DockerTemplateOptions.class.cast(super.runAsRoot(runAsRoot)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions runScript(Statement script) { - return DockerTemplateOptions.class.cast(super.runScript(script)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions overrideLoginCredentials(LoginCredentials overridingCredentials) { - return DockerTemplateOptions.class.cast(super.overrideLoginCredentials(overridingCredentials)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions overrideLoginPassword(String password) { - return DockerTemplateOptions.class.cast(super.overrideLoginPassword(password)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions overrideLoginPrivateKey(String privateKey) { - return DockerTemplateOptions.class.cast(super.overrideLoginPrivateKey(privateKey)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions overrideLoginUser(String loginUser) { - return DockerTemplateOptions.class.cast(super.overrideLoginUser(loginUser)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions overrideAuthenticateSudo(boolean authenticateSudo) { - return DockerTemplateOptions.class.cast(super.overrideAuthenticateSudo(authenticateSudo)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions userMetadata(Map<String, String> userMetadata) { - return DockerTemplateOptions.class.cast(super.userMetadata(userMetadata)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions userMetadata(String key, String value) { - return DockerTemplateOptions.class.cast(super.userMetadata(key, value)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions nodeNames(Iterable<String> nodeNames) { - return DockerTemplateOptions.class.cast(super.nodeNames(nodeNames)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions networks(Iterable<String> networks) { - return DockerTemplateOptions.class.cast(super.networks(networks)); - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/strategy/DockerComputeServiceAdapter.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/strategy/DockerComputeServiceAdapter.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/strategy/DockerComputeServiceAdapter.java deleted file mode 100644 index 5646054..0000000 --- a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/compute/strategy/DockerComputeServiceAdapter.java +++ /dev/null @@ -1,223 +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.jclouds.docker.compute.strategy; - -import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; -import org.jclouds.compute.ComputeServiceAdapter; -import org.jclouds.compute.domain.Hardware; -import org.jclouds.compute.domain.HardwareBuilder; -import org.jclouds.compute.domain.Template; -import org.jclouds.compute.reference.ComputeServiceConstants; -import org.jclouds.docker.DockerApi; -import org.jclouds.docker.compute.options.DockerTemplateOptions; -import org.jclouds.docker.domain.Config; -import org.jclouds.docker.domain.Container; -import org.jclouds.docker.domain.HostConfig; -import org.jclouds.docker.domain.Image; -import org.jclouds.domain.Location; -import org.jclouds.domain.LoginCredentials; -import org.jclouds.logging.Logger; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.contains; -import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.find; - -/** - * defines the connection between the {@link org.jclouds.docker.DockerApi} implementation and - * the jclouds {@link org.jclouds.compute.ComputeService} - */ -@Singleton -public class DockerComputeServiceAdapter implements - ComputeServiceAdapter<Container, Hardware, Image, Location> { - - @Resource - @Named(ComputeServiceConstants.COMPUTE_LOGGER) - protected Logger logger = Logger.NULL; - - private final DockerApi api; - - @Inject - public DockerComputeServiceAdapter(DockerApi api) { - this.api = checkNotNull(api, "api"); - } - - @Override - public NodeAndInitialCredentials<Container> createNodeWithGroupEncodedIntoName(String group, String name, - Template template) { - checkNotNull(template, "template was null"); - checkNotNull(template.getOptions(), "template options was null"); - DockerTemplateOptions templateOptions = DockerTemplateOptions.class.cast(template.getOptions()); - - String imageId = checkNotNull(template.getImage().getId(), "template image id must not be null"); - String loginUser = template.getImage().getDefaultCredentials().getUser(); - String loginUserPassword = template.getImage().getDefaultCredentials().getPassword(); - - Map<String, Object> exposedPorts = Maps.newHashMap(); - int[] inboundPorts = template.getOptions().getInboundPorts(); - for (int inboundPort : inboundPorts) { - exposedPorts.put(inboundPort + "/tcp", Maps.newHashMap()); - } - - Config.Builder configBuilder = Config.builder() - .imageId(template.getImage().getName()) - //.cmd(ImmutableList.of("/usr/sbin/sshd", "-D")) - .attachStdout(true) - .attachStderr(true) - .exposedPorts(exposedPorts); - - if (templateOptions.getVolumes().isPresent()) { - Map<String, Object> volumes = Maps.newLinkedHashMap(); - for (String containerDir : templateOptions.getVolumes().get().values()) { - volumes.put(containerDir, Maps.newHashMap()); - } - configBuilder.volumes(volumes); - } - Config config = configBuilder.build(); - - logger.debug(">> creating new container with config(%s)", config); - Container container = api.getRemoteApi().createContainer(name, config); - logger.trace("<< container(%s)", container.getId()); - - // set up for port bindings - Map<String, List<Map<String, String>>> portBindings = Maps.newHashMap(); - HostConfig.Builder hostConfigBuilder = HostConfig.builder() - .portBindings(portBindings) - .publishAllPorts(true) - .privileged(true); - - // set up for volume bindings - if (templateOptions.getVolumes().isPresent()) { - for (Map.Entry<String,String> entry : templateOptions.getVolumes().get().entrySet()) { - hostConfigBuilder.binds(ImmutableList.of(entry.getKey() + ":" + entry.getValue())); - } - } - HostConfig hostConfig = hostConfigBuilder.build(); - - api.getRemoteApi().startContainer(container.getId(), hostConfig); - container = api.getRemoteApi().inspectContainer(container.getId()); - if (!container.getState().isRunning()) { - destroyNode(container.getId()); - throw new IllegalStateException(String.format("Container %s has not started correctly", container.getId())); - } - return new NodeAndInitialCredentials<Container>(container, container.getId(), - LoginCredentials.builder().user(loginUser).password(loginUserPassword).build()); - } - - @Override - public Iterable<Hardware> listHardwareProfiles() { - Set<Hardware> hardware = Sets.newLinkedHashSet(); - // todo they are only placeholders at the moment - hardware.add(new HardwareBuilder().ids("micro").hypervisor("lxc").name("micro").ram(512).build()); - hardware.add(new HardwareBuilder().ids("small").hypervisor("lxc").name("small").ram(1024).build()); - hardware.add(new HardwareBuilder().ids("medium").hypervisor("lxc").name("medium").ram(2048).build()); - hardware.add(new HardwareBuilder().ids("large").hypervisor("lxc").name("large").ram(3072).build()); - return hardware; - } - - @Override - public Set<Image> listImages() { - //return api.getRemoteApi().listImages(); - Set<Image> images = Sets.newHashSet(); - for (Image image : api.getRemoteApi().listImages()) { - // less efficient than just listNodes but returns richer json that needs repoTags coming from listImages - Image inspected = api.getRemoteApi().inspectImage(image.getId()); - if(image.getRepoTags() != null) { - inspected = Image.builder().fromImage(inspected).repoTags(image.getRepoTags()).build(); - } - images.add(inspected); - } - return images; - } - - @Override - public Image getImage(final String imageId) { - return find(listImages(), new Predicate<Image>() { - - @Override - public boolean apply(Image input) { - return input.getId().equals(imageId); - } - - }, null); - } - - @Override - public Iterable<Container> listNodes() { - Set<Container> containers = Sets.newHashSet(); - for (Container container : api.getRemoteApi().listContainers()) { - // less efficient than just listNodes but returns richer json - containers.add(api.getRemoteApi().inspectContainer(container.getId())); - } - return containers; - } - - @Override - public Iterable<Container> listNodesByIds(final Iterable<String> ids) { - return filter(listNodes(), new Predicate<Container>() { - - @Override - public boolean apply(Container server) { - return contains(ids, server.getId()); - } - }); - } - - @Override - public Iterable<Location> listLocations() { - return ImmutableSet.of(); - } - - @Override - public Container getNode(String id) { - return api.getRemoteApi().inspectContainer(id); - } - - @Override - public void destroyNode(String id) { - api.getRemoteApi().stopContainer(id); - api.getRemoteApi().removeContainer(id); - } - - @Override - public void rebootNode(String id) { - api.getRemoteApi().startContainer(id); - } - - @Override - public void resumeNode(String id) { - api.getRemoteApi().startContainer(id); - } - - @Override - public void suspendNode(String id) { - api.getRemoteApi().stopContainer(id); - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/config/DockerHttpApiModule.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/config/DockerHttpApiModule.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/config/DockerHttpApiModule.java deleted file mode 100644 index 464eb8d..0000000 --- a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/config/DockerHttpApiModule.java +++ /dev/null @@ -1,42 +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.jclouds.docker.config; - -import org.jclouds.docker.DockerApi; -import org.jclouds.docker.handlers.DockerErrorHandler; -import org.jclouds.http.HttpErrorHandler; -import org.jclouds.http.annotation.ClientError; -import org.jclouds.http.annotation.Redirection; -import org.jclouds.http.annotation.ServerError; -import org.jclouds.rest.ConfiguresHttpApi; -import org.jclouds.rest.config.HttpApiModule; - -/** - * Configures the Docker connection. - * - * @author Andrea Turli - */ -@ConfiguresHttpApi -public class DockerHttpApiModule extends HttpApiModule<DockerApi> { - - @Override - protected void bindErrorHandlers() { - bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(DockerErrorHandler.class); - bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(DockerErrorHandler.class); - bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(DockerErrorHandler.class); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/config/DockerParserModule.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/config/DockerParserModule.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/config/DockerParserModule.java deleted file mode 100644 index abdeea3..0000000 --- a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/config/DockerParserModule.java +++ /dev/null @@ -1,101 +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.jclouds.docker.config; - -import com.google.common.collect.ImmutableMap; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonArray; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.inject.AbstractModule; -import com.google.inject.Provides; -import org.jclouds.docker.domain.Container; -import org.jclouds.docker.domain.Image; -import org.jclouds.json.config.GsonModule; - -import javax.inject.Singleton; -import java.lang.reflect.Type; -import java.util.Map; - -/** - * @author Andrea Turli - */ -public class DockerParserModule extends AbstractModule { - - @Override - protected void configure() { - bind(GsonModule.DateAdapter.class).to(GsonModule.Iso8601DateAdapter.class); - } - - @Provides - @Singleton - public Map<Type, Object> provideCustomAdapterBindings() { - return new ImmutableMap.Builder<Type, Object>() - .put(Container.class, new ContainerTypeAdapter()) - .put(Image.class, new ImageTypeAdapter()) - .build(); - } - - protected static class ContainerTypeAdapter implements JsonDeserializer<Container> { - - @Override - public Container deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws - JsonParseException { - Gson gson = new GsonBuilder().serializeNulls().create(); - final JsonObject jsonObject = json.getAsJsonObject(); - - // container:inspect returns ID instead of Id as listContainers - if (jsonObject.has("ID")) { - JsonElement id = jsonObject.get("ID"); - jsonObject.remove("ID"); - jsonObject.add("Id", id); - } - // container:inspect returns Name instead of Names as listContainers - if (jsonObject.has("Names")) { - final JsonArray jsonNamesArray = jsonObject.getAsJsonArray("Names"); - jsonObject.remove("Names"); - jsonObject.add("Name", jsonNamesArray.get(0)); - } - return gson.fromJson(jsonObject, Container.class); - } - - } - - protected static class ImageTypeAdapter implements JsonDeserializer<Image> { - - @Override - public Image deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws - JsonParseException { - Gson gson = new GsonBuilder().serializeNulls().create(); - final JsonObject jsonObject = json.getAsJsonObject(); - - // image:inspect returns id instead of Id as listImages - if (jsonObject.has("Id")) { - JsonElement id = jsonObject.get("Id"); - jsonObject.remove("Id"); - jsonObject.add("id", id); - } - return gson.fromJson(jsonObject, Image.class); - } - - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/config/DockerProperties.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/config/DockerProperties.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/config/DockerProperties.java deleted file mode 100644 index 487b19b..0000000 --- a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/config/DockerProperties.java +++ /dev/null @@ -1,29 +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.jclouds.docker.config; - -/** - * @author Andrea Turli - */ -public class DockerProperties { - - /** - * default Docker host password - */ - public static final String HOST_PASSWORD = "jclouds.docker.host.password"; - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/397d9926/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/domain/Config.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/domain/Config.java b/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/domain/Config.java deleted file mode 100644 index 91dd47e..0000000 --- a/dependencies/jclouds/apis/docker/1.7.1-stratos/src/main/java/org/jclouds/docker/domain/Config.java +++ /dev/null @@ -1,460 +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.jclouds.docker.domain; - -import static com.google.common.base.Preconditions.checkNotNull; -import java.beans.ConstructorProperties; -import java.util.List; -import java.util.Map; - -import org.jclouds.javax.annotation.Nullable; - -import com.google.common.base.Objects; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.gson.annotations.SerializedName; - -/** - * @author Andrea Turli - */ -public class Config { - - @SerializedName("Hostname") - private final String hostname; - @SerializedName("Domainname") - private final String domainName; - @SerializedName("User") - private final String user; - @SerializedName("Memory") - private final int memory; - @SerializedName("MemorySwap") - private final int memorySwap; - @SerializedName("CpuShares") - private final int cpuShares; - @SerializedName("AttachStdin") - private final boolean attachStdin; - @SerializedName("AttachStdout") - private final boolean attachStdout; - @SerializedName("AttachStderr") - private final boolean attachStderr; - @SerializedName("ExposedPorts") - private final Map<String, ?> exposedPorts; - @SerializedName("Tty") - private final boolean tty; - @SerializedName("OpenStdin") - private final boolean openStdin; - @SerializedName("StdinOnce") - private final boolean stdinOnce; - @SerializedName("Env") - private final List<String> env; - @SerializedName("Cmd") - private final List<String> cmd; - @SerializedName("Dns") - private final List<String> dns; - @SerializedName("Image") - private final String imageId; - @SerializedName("Volumes") - private final Map<String, ?> volumes; - @SerializedName("VolumesFrom") - private final String volumesFrom; - @SerializedName("WorkingDir") - private final String workingDir; - @SerializedName("Entrypoint") - private final List<String> entrypoint; - @SerializedName("NetworkDisabled") - private final boolean networkDisabled; - @SerializedName("OnBuild") - private final String onBuild; - - - @ConstructorProperties({ "Hostname", "Domainname", "User", "Memory", "MemorySwap", "CpuShares", "AttachStdin", - "AttachStdout", "AttachStderr", "PortSpecs", "ExposedPorts", "Tty", "OpenStdin", "StdinOnce", "Env", "Cmd", - "Dns", "Image", "Volumes", "VolumesFrom", "WorkingDir", "Entrypoint", "NetworkDisabled", "OnBuild" }) - Config(@Nullable String hostname, @Nullable String domainName, @Nullable String user, int memory, int memorySwap, - int cpuShares, boolean attachStdin, boolean attachStdout, boolean attachStderr, - Map<String, ?> exposedPorts, boolean tty, boolean openStdin, boolean stdinOnce, - @Nullable List<String> env, @Nullable List<String> cmd, @Nullable List<String> dns, String imageId, - Map<String, ?> volumes, @Nullable String volumesFrom, @Nullable String workingDir, - @Nullable List<String> entrypoint, @Nullable boolean networkDisabled, @Nullable String onBuild) { - this.hostname = hostname; - this.domainName = domainName; - this.user = user; - this.memory = checkNotNull(memory, "memory"); - this.memorySwap = checkNotNull(memorySwap, "memorySwap"); - this.cpuShares = checkNotNull(cpuShares, "cpuShares"); - this.attachStdin = checkNotNull(attachStdin, "attachStdin"); - this.attachStdout = checkNotNull(attachStdout, "attachStdout"); - this.attachStderr = checkNotNull(attachStderr, "attachStderr"); - this.exposedPorts = exposedPorts != null ? ImmutableMap.copyOf(exposedPorts) : ImmutableMap.<String, Object> of(); - this.tty = checkNotNull(tty, "tty"); - this.openStdin = checkNotNull(openStdin, "openStdin"); - this.stdinOnce = checkNotNull(stdinOnce, "stdinOnce"); - this.env = env != null ? ImmutableList.copyOf(cmd) : ImmutableList.<String> of(); - this.cmd = cmd != null ? ImmutableList.copyOf(cmd) : ImmutableList.<String> of(); - this.dns = dns != null ? ImmutableList.copyOf(dns) : ImmutableList.<String> of(); - this.imageId = checkNotNull(imageId, "imageId"); - this.volumes = volumes != null ? ImmutableMap.copyOf(volumes) : ImmutableMap.<String, Object> of(); - this.volumesFrom = volumesFrom; - this.workingDir = workingDir; - this.entrypoint = entrypoint; - this.networkDisabled = networkDisabled; - this.onBuild = onBuild; - } - - public String getHostname() { - return hostname; - } - - public String getDomainName() { - return domainName; - } - - public String getUser() { - return user; - } - - public int getMemory() { - return memory; - } - - public int getMemorySwap() { - return memorySwap; - } - - public int getCpuShares() { - return cpuShares; - } - - public boolean isAttachStdin() { - return attachStdin; - } - - public boolean isAttachStdout() { - return attachStdout; - } - - public boolean isAttachStderr() { - return attachStderr; - } - - public Map<String, ?> getExposedPorts() { - return exposedPorts; - } - - public boolean isTty() { - return tty; - } - - public boolean isOpenStdin() { - return openStdin; - } - - public boolean isStdinOnce() { - return stdinOnce; - } - - public List<String> getEnv() { - return env; - } - - public List<String> getCmd() { - return cmd; - } - - public List<String> getDns() { - return dns; - } - - public String getImageId() { - return imageId; - } - - public Map<String, ?> getVolumes() { - return volumes; - } - - public String getVolumesFrom() { - return volumesFrom; - } - - public String getWorkingDir() { - return workingDir; - } - - public List<String> getEntrypoint() { - return entrypoint; - } - - public boolean isNetworkDisabled() { - return networkDisabled; - } - - public String getOnBuild() { - return onBuild; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Config that = (Config) o; - - return Objects.equal(this.hostname, that.hostname) && - Objects.equal(this.domainName, that.domainName) && - Objects.equal(this.user, that.user) && - Objects.equal(this.memory, that.memory) && - Objects.equal(this.memorySwap, that.memorySwap) && - Objects.equal(this.cpuShares, that.cpuShares) && - Objects.equal(this.attachStdin, that.attachStdin) && - Objects.equal(this.attachStdout, that.attachStdout) && - Objects.equal(this.attachStderr, that.attachStderr) && - Objects.equal(this.exposedPorts, that.exposedPorts) && - Objects.equal(this.tty, that.tty) && - Objects.equal(this.openStdin, that.openStdin) && - Objects.equal(this.stdinOnce, that.stdinOnce) && - Objects.equal(this.env, that.env) && - Objects.equal(this.cmd, that.cmd) && - Objects.equal(this.dns, that.dns) && - Objects.equal(this.imageId, that.imageId) && - Objects.equal(this.volumes, that.volumes) && - Objects.equal(this.volumesFrom, that.volumesFrom) && - Objects.equal(this.workingDir, that.workingDir) && - Objects.equal(this.entrypoint, that.entrypoint) && - Objects.equal(this.onBuild, that.onBuild); - } - - @Override - public int hashCode() { - return Objects.hashCode(hostname, domainName, user, memory, memorySwap, cpuShares, attachStdin, attachStdout, - attachStderr, exposedPorts, tty, openStdin, stdinOnce, env, cmd, dns, imageId, volumes, - volumesFrom, workingDir, entrypoint, networkDisabled, onBuild); - } - - @Override - public String toString() { - return Objects.toStringHelper(this) - .add("hostname", hostname) - .add("domainName", domainName) - .add("user", user) - .add("memory", memory) - .add("memorySwap", memorySwap) - .add("cpuShares", cpuShares) - .add("attachStdin", attachStdin) - .add("attachStdout", attachStdout) - .add("attachStderr", attachStderr) - .add("exposedPorts", exposedPorts) - .add("tty", tty) - .add("openStdin", openStdin) - .add("stdinOnce", stdinOnce) - .add("env", env) - .add("cmd", cmd) - .add("dns", dns) - .add("imageId", imageId) - .add("volumes", volumes) - .add("volumesFrom", volumesFrom) - .add("workingDir", workingDir) - .add("entrypoint", entrypoint) - .add("networkDisabled", networkDisabled) - .add("onBuild", onBuild) - .toString(); - } - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return builder().fromConfig(this); - } - - public static final class Builder { - private String hostname; - private String domainName; - private String user; - private int memory; - private int memorySwap; - private int cpuShares; - private boolean attachStdin; - private boolean attachStdout; - private boolean attachStderr; - private Map<String, ?> portSpecs = ImmutableMap.of(); - private Map<String, ?> exposedPorts = ImmutableMap.of(); - private boolean tty; - private boolean openStdin; - private boolean stdinOnce; - private List<String> env = ImmutableList.of(); - private List<String> cmd = ImmutableList.of(); - private List<String> dns = ImmutableList.of(); - private String imageId; - private Map<String, ?> volumes = ImmutableMap.of(); - private String volumesFrom; - private String workingDir; - private List<String> entrypoint = ImmutableList.of(); - private boolean networkDisabled; - private String onBuild; - - public Builder hostname(String hostname) { - this.hostname = hostname; - return this; - } - - public Builder domainName(String domainName) { - this.domainName = domainName; - return this; - } - - public Builder user(String user) { - this.user = user; - return this; - } - - public Builder memory(int memory) { - this.memory = memory; - return this; - } - - public Builder memorySwap(int memorySwap) { - this.memorySwap = memorySwap; - return this; - } - - public Builder cpuShares(int cpuShares) { - this.cpuShares = cpuShares; - return this; - } - - public Builder attachStdin(boolean attachStdin) { - this.attachStdin = attachStdin; - return this; - } - - public Builder attachStdout(boolean attachStdout) { - this.attachStdout = attachStdout; - return this; - } - - public Builder attachStderr(boolean attachStderr) { - this.attachStderr = attachStderr; - return this; - } - - public Builder exposedPorts(Map<String, ?> exposedPorts) { - this.exposedPorts = ImmutableMap.copyOf(checkNotNull(exposedPorts, "exposedPorts")); - return this; - } - - public Builder tty(boolean tty) { - this.tty = tty; - return this; - } - - public Builder openStdin(boolean openStdin) { - this.openStdin = openStdin; - return this; - } - - public Builder stdinOnce(boolean stdinOnce) { - this.stdinOnce = stdinOnce; - return this; - } - - public Builder env(List<String> env) { - this.env = env; - return this; - } - - public Builder cmd(List<String> cmd) { - this.cmd = ImmutableList.copyOf(checkNotNull(cmd, "cmd")); - return this; - } - - public Builder dns(List<String> dns) { - this.dns = ImmutableList.copyOf(checkNotNull(dns, "dns")); - return this; - } - - public Builder imageId(String imageId) { - this.imageId = imageId; - return this; - } - - public Builder volumes(Map<String, ?> volumes) { - this.volumes = ImmutableMap.copyOf(checkNotNull(volumes, "volumes")); - return this; - } - - public Builder volumesFrom(String volumesFrom) { - this.volumesFrom = volumesFrom; - return this; - } - - public Builder workingDir(String workingDir) { - this.workingDir = workingDir; - return this; - } - - public Builder entrypoint(List<String> entrypoint) { - this.entrypoint = entrypoint; - return this; - } - - public Builder networkDisabled(boolean networkDisabled) { - this.networkDisabled = networkDisabled; - return this; - } - - public Builder onBuild(String onBuild) { - this.onBuild = onBuild; - return this; - } - - public Config build() { - return new Config(hostname, domainName, user, memory, memorySwap, cpuShares, attachStdin, attachStdout, - attachStderr, exposedPorts, tty, openStdin, stdinOnce, env, cmd, dns, imageId, volumes, - volumesFrom, workingDir, entrypoint, networkDisabled, onBuild); - } - - public Builder fromConfig(Config in) { - return this - .hostname(in.getHostname()) - .domainName(in.getDomainName()) - .user(in.getUser()) - .memory(in.getMemory()) - .memorySwap(in.getMemorySwap()) - .cpuShares(in.getCpuShares()) - .attachStdin(in.isAttachStdin()) - .attachStdout(in.isAttachStdout()) - .attachStderr(in.isAttachStderr()) - .exposedPorts(in.getExposedPorts()) - .tty(in.isTty()) - .openStdin(in.isOpenStdin()) - .stdinOnce(in.isStdinOnce()) - .env(in.getEnv()) - .cmd(in.getCmd()) - .dns(in.getDns()) - .imageId(in.getImageId()) - .volumes(in.getVolumes()) - .volumesFrom(in.getVolumesFrom()) - .workingDir(in.getWorkingDir()) - .entrypoint(in.getEntrypoint()) - .networkDisabled(in.isNetworkDisabled()) - .onBuild(in.getOnBuild()); - } - - } -}
