JCLOUDS-750 AutoValue all Docker value types.

This commit is contained in:
Adrian Cole 2014-10-26 12:28:39 -07:00 committed by Adrian Cole
parent 6121757377
commit 7bdff3f9ca
23 changed files with 425 additions and 1458 deletions

View File

@ -63,7 +63,12 @@
<artifactId>commons-compress</artifactId> <artifactId>commons-compress</artifactId>
<version>1.5</version> <version>1.5</version>
</dependency> </dependency>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>1.0-rc2</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>org.apache.jclouds.driver</groupId> <groupId>org.apache.jclouds.driver</groupId>
<artifactId>jclouds-sshj</artifactId> <artifactId>jclouds-sshj</artifactId>

View File

@ -76,26 +76,25 @@ public class ContainerToNodeMetadata implements Function<Container, NodeMetadata
@Override @Override
public NodeMetadata apply(Container container) { public NodeMetadata apply(Container container) {
String name = cleanUpName(container.getName()); String name = cleanUpName(container.name());
String group = nodeNamingConvention.extractGroup(name); String group = nodeNamingConvention.extractGroup(name);
NodeMetadataBuilder builder = new NodeMetadataBuilder(); NodeMetadataBuilder builder = new NodeMetadataBuilder();
builder.ids(container.getId()) builder.ids(container.id())
.name(name) .name(name)
.group(group) .group(group)
.hostname(container.getContainerConfig().getHostname()) .hostname(container.config().hostname())
// TODO Set up hardware // TODO Set up hardware
.hardware(new HardwareBuilder() .hardware(new HardwareBuilder()
.id("") .id("")
.ram(container.getContainerConfig().getMemory()) .ram(container.config().memory())
.processor(new Processor(container.getContainerConfig().getCpuShares(), container.getContainerConfig().getCpuShares())) .processor(new Processor(container.config().cpuShares(), container.config().cpuShares()))
.build()); .build());
builder.status(toPortableStatus.apply(container.getState())); builder.status(toPortableStatus.apply(container.state()));
builder.imageId(container.getImage());
builder.loginPort(getLoginPort(container)); builder.loginPort(getLoginPort(container));
builder.publicAddresses(getPublicIpAddresses()); builder.publicAddresses(getPublicIpAddresses());
builder.privateAddresses(getPrivateIpAddresses(container)); builder.privateAddresses(getPrivateIpAddresses(container));
builder.location(Iterables.getOnlyElement(locations.get())); builder.location(Iterables.getOnlyElement(locations.get()));
String imageId = container.getImage(); String imageId = container.image();
builder.imageId(imageId); builder.imageId(imageId);
if (images.get().containsKey(imageId)) { if (images.get().containsKey(imageId)) {
Image image = images.get().get(imageId); Image image = images.get().get(imageId);
@ -110,8 +109,8 @@ public class ContainerToNodeMetadata implements Function<Container, NodeMetadata
} }
private Iterable<String> getPrivateIpAddresses(Container container) { private Iterable<String> getPrivateIpAddresses(Container container) {
if (container.getNetworkSettings() == null) return ImmutableList.of(); if (container.networkSettings() == null) return ImmutableList.of();
return ImmutableList.of(container.getNetworkSettings().getIpAddress()); return ImmutableList.of(container.networkSettings().ipAddress());
} }
private List<String> getPublicIpAddresses() { private List<String> getPublicIpAddresses() {
@ -120,16 +119,16 @@ public class ContainerToNodeMetadata implements Function<Container, NodeMetadata
} }
protected static int getLoginPort(Container container) { protected static int getLoginPort(Container container) {
if (container.getNetworkSettings() != null) { if (container.networkSettings() != null) {
Map<String, List<Map<String, String>>> ports = container.getNetworkSettings().getPorts(); Map<String, List<Map<String, String>>> ports = container.networkSettings().ports();
if (ports != null && ports.containsKey("22/tcp")) { if (ports != null && ports.containsKey("22/tcp")) {
return Integer.parseInt(getOnlyElement(ports.get("22/tcp")).get("HostPort")); return Integer.parseInt(getOnlyElement(ports.get("22/tcp")).get("HostPort"));
} }
// this is needed in case the container list is coming from listContainers // this is needed in case the container list is coming from listContainers
} else if (container.getPorts() != null) { } else if (container.ports() != null) {
for (Port port : container.getPorts()) { for (Port port : container.ports()) {
if (port.getPrivatePort() == 22) { if (port.privatePort() == 22) {
return port.getPublicPort(); return port.publicPort();
} }
} }
} }

View File

@ -44,7 +44,7 @@ public class ImageToImage implements Function<org.jclouds.docker.domain.Image, o
@Override @Override
public Image apply(org.jclouds.docker.domain.Image from) { public Image apply(org.jclouds.docker.domain.Image from) {
checkNotNull(from, "image"); checkNotNull(from, "image");
String description = checkNotNull(Iterables.getFirst(from.getRepoTags(), "image must have at least one repo tag")); String description = checkNotNull(Iterables.getFirst(from.repoTags(), "image must have at least one repo tag"));
OsFamily osFamily = osFamily().apply(description); OsFamily osFamily = osFamily().apply(description);
String osVersion = parseVersion(description); String osVersion = parseVersion(description);
@ -57,7 +57,7 @@ public class ImageToImage implements Function<org.jclouds.docker.domain.Image, o
.build(); .build();
return new ImageBuilder() return new ImageBuilder()
.ids(from.getId()) .ids(from.id())
.name(get(Splitter.on(":").split(description), 0)) .name(get(Splitter.on(":").split(description), 0))
.description(description) .description(description)
.operatingSystem(os) .operatingSystem(os)
@ -66,8 +66,8 @@ public class ImageToImage implements Function<org.jclouds.docker.domain.Image, o
} }
private boolean is64bit(org.jclouds.docker.domain.Image inspectedImage) { private boolean is64bit(org.jclouds.docker.domain.Image inspectedImage) {
if (inspectedImage.getArchitecture() == null) return true; if (inspectedImage.architecture() == null) return true;
return inspectedImage.getArchitecture().matches("x86_64|amd64"); return inspectedImage.architecture().matches("x86_64|amd64");
} }
/** /**

View File

@ -32,7 +32,7 @@ public class StateToStatus implements Function<State, Status> {
@Override @Override
public Status apply(final State state) { public Status apply(final State state) {
if (state == null) return Status.UNRECOGNIZED; if (state == null) return Status.UNRECOGNIZED;
return state.isRunning() ? Status.RUNNING : Status.TERMINATED; return state.running() ? Status.RUNNING : Status.TERMINATED;
} }
} }

View File

@ -89,7 +89,7 @@ public class DockerComputeServiceAdapter implements
} }
Config.Builder containerConfigBuilder = Config.builder() Config.Builder containerConfigBuilder = Config.builder()
.imageId(imageId) .image(imageId)
.exposedPorts(exposedPorts); .exposedPorts(exposedPorts);
if (templateOptions.getCommands().isPresent()) { if (templateOptions.getCommands().isPresent()) {
@ -123,7 +123,7 @@ public class DockerComputeServiceAdapter implements
logger.debug(">> creating new container with containerConfig(%s)", containerConfig); logger.debug(">> creating new container with containerConfig(%s)", containerConfig);
Container container = api.getRemoteApi().createContainer(name, containerConfig); Container container = api.getRemoteApi().createContainer(name, containerConfig);
logger.trace("<< container(%s)", container.getId()); logger.trace("<< container(%s)", container.id());
HostConfig.Builder hostConfigBuilder = HostConfig.builder() HostConfig.Builder hostConfigBuilder = HostConfig.builder()
.publishAllPorts(true) .publishAllPorts(true)
@ -140,13 +140,13 @@ public class DockerComputeServiceAdapter implements
} }
HostConfig hostConfig = hostConfigBuilder.build(); HostConfig hostConfig = hostConfigBuilder.build();
api.getRemoteApi().startContainer(container.getId(), hostConfig); api.getRemoteApi().startContainer(container.id(), hostConfig);
container = api.getRemoteApi().inspectContainer(container.getId()); container = api.getRemoteApi().inspectContainer(container.id());
if (container.getState().getExitCode() != 0) { if (container.state().exitCode() != 0) {
destroyNode(container.getId()); destroyNode(container.id());
throw new IllegalStateException(String.format("Container %s has not started correctly", container.getId())); throw new IllegalStateException(String.format("Container %s has not started correctly", container.id()));
} }
return new NodeAndInitialCredentials<Container>(container, container.getId(), return new NodeAndInitialCredentials<Container>(container, container.id(),
LoginCredentials.builder().user(loginUser).password(loginUserPassword).build()); LoginCredentials.builder().user(loginUser).password(loginUserPassword).build());
} }
@ -166,9 +166,11 @@ public class DockerComputeServiceAdapter implements
Set<Image> images = Sets.newHashSet(); Set<Image> images = Sets.newHashSet();
for (Image image : api.getRemoteApi().listImages()) { for (Image image : api.getRemoteApi().listImages()) {
// less efficient than just listImages but returns richer json that needs repoTags coming from listImages // less efficient than just listImages but returns richer json that needs repoTags coming from listImages
Image inspected = api.getRemoteApi().inspectImage(image.getId()); Image inspected = api.getRemoteApi().inspectImage(image.id());
if (inspected.getRepoTags().isEmpty()) { if (inspected.repoTags().isEmpty()) {
inspected = Image.builder().fromImage(inspected).repoTags(image.getRepoTags()).build(); inspected = Image.create(inspected.id(), inspected.parent(), inspected.created(), inspected.container(),
inspected.dockerVersion(), inspected.architecture(), inspected.os(), inspected.size(),
inspected.virtualSize(), image.repoTags());
} }
images.add(inspected); images.add(inspected);
} }
@ -182,7 +184,7 @@ public class DockerComputeServiceAdapter implements
@Override @Override
public boolean apply(Image input) { public boolean apply(Image input) {
return input.getId().equals(imageId); return input.id().equals(imageId);
} }
}, null); }, null);
} }
@ -192,7 +194,7 @@ public class DockerComputeServiceAdapter implements
Set<Container> containers = Sets.newHashSet(); Set<Container> containers = Sets.newHashSet();
for (Container container : api.getRemoteApi().listContainers(ListContainerOptions.Builder.all(true))) { for (Container container : api.getRemoteApi().listContainers(ListContainerOptions.Builder.all(true))) {
// less efficient than just listNodes but returns richer json // less efficient than just listNodes but returns richer json
containers.add(api.getRemoteApi().inspectContainer(container.getId())); containers.add(api.getRemoteApi().inspectContainer(container.id()));
} }
return containers; return containers;
} }

View File

@ -16,47 +16,35 @@
*/ */
package org.jclouds.docker.config; package org.jclouds.docker.config;
import com.google.common.collect.ImmutableMap; import java.lang.reflect.Field;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
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.json.config.GsonModule; import org.jclouds.json.config.GsonModule;
import javax.inject.Singleton; import com.google.gson.FieldNamingPolicy;
import java.lang.reflect.Type; import com.google.gson.FieldNamingStrategy;
import java.util.Map; import com.google.inject.AbstractModule;
public class DockerParserModule extends AbstractModule { public class DockerParserModule extends AbstractModule {
@Override protected void configure() {
@Override bind(FieldNamingStrategy.class).toInstance(FIELD_NAMING_STRATEGY);
protected void configure() {
bind(GsonModule.DateAdapter.class).to(GsonModule.Iso8601DateAdapter.class); bind(GsonModule.DateAdapter.class).to(GsonModule.Iso8601DateAdapter.class);
} }
@Provides /** When serializing, Most fields are UpperCamelCase, with some exceptions. */
@Singleton private static final FieldNamingStrategy FIELD_NAMING_STRATEGY = new FieldNamingStrategy() {
public Map<Type, Object> provideCustomAdapterBindings() { private final FieldNamingStrategy delegate = FieldNamingPolicy.UPPER_CAMEL_CASE;
return new ImmutableMap.Builder<Type, Object>()
.put(Container.class, new ContainerTypeAdapter())
.build();
}
protected static class ContainerTypeAdapter implements JsonDeserializer<Container> { @Override public String translateName(Field f) {
String result = delegate.translateName(f);
@Override // IP not Ip as code wins over docs https://github.com/docker/docker/blob/master/daemon/network_settings.go
public Container deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws if (result.equals("IpAddress")) {
JsonParseException { return "IPAddress";
Gson gson = new GsonBuilder().serializeNulls().create(); } else if (result.equals("IpPrefixLen")) {
final JsonObject jsonObject = json.getAsJsonObject(); return "IPPrefixLen";
return gson.fromJson(jsonObject, Container.class); } else if (result.equals("Ip")) {
return "IP";
} }
return result;
} }
};
} }

View File

@ -17,260 +17,78 @@
package org.jclouds.docker.domain; package org.jclouds.docker.domain;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.docker.internal.NullSafeCopies.copyOf;
import java.beans.ConstructorProperties;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;
import com.google.common.base.Objects; import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.gson.annotations.SerializedName;
public class Config { @AutoValue
public abstract class Config {
@Nullable public abstract String hostname();
@SerializedName("Hostname") @Nullable public abstract String domainname();
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 List<String> onBuild;
@Nullable public abstract String user();
@ConstructorProperties({ "Hostname", "Domainname", "User", "Memory", "MemorySwap", "CpuShares", "AttachStdin", public abstract int memory();
"AttachStdout", "AttachStderr", "ExposedPorts", "Tty", "OpenStdin", "StdinOnce", "Env", "Cmd",
"Dns", "Image", "Volumes", "VolumesFrom", "WorkingDir", "Entrypoint", "NetworkDisabled", "OnBuild" })
protected 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, @Nullable Map<String, ?> volumes,
@Nullable String volumesFrom, @Nullable String workingDir, @Nullable List<String> entrypoint,
@Nullable boolean networkDisabled, @Nullable List<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(env) : 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 != null ? ImmutableList.copyOf(onBuild) : ImmutableList.<String> of();
}
public String getHostname() { public abstract int memorySwap();
return hostname;
}
public String getDomainName() { public abstract int cpuShares();
return domainName;
}
public String getUser() { public abstract boolean attachStdin();
return user;
}
public int getMemory() { public abstract boolean attachStdout();
return memory;
}
public int getMemorySwap() { public abstract boolean attachStderr();
return memorySwap;
}
public int getCpuShares() { public abstract Map<String, ?> exposedPorts();
return cpuShares;
}
public boolean isAttachStdin() { public abstract boolean tty();
return attachStdin;
}
public boolean isAttachStdout() { public abstract boolean openStdin();
return attachStdout;
}
public boolean isAttachStderr() { public abstract boolean stdinOnce();
return attachStderr;
}
public Map<String, ?> getExposedPorts() { public abstract List<String> env();
return exposedPorts;
}
public boolean isTty() { public abstract List<String> cmd();
return tty;
}
public boolean isOpenStdin() { public abstract List<String> dns();
return openStdin;
}
public boolean isStdinOnce() { public abstract String image();
return stdinOnce;
}
public List<String> getEnv() { public abstract Map<String, ?> volumes();
return env;
}
public List<String> getCmd() { @Nullable public abstract String volumesFrom();
return cmd;
}
public List<String> getDns() { @Nullable public abstract String workingDir();
return dns;
}
public String getImageId() { public abstract List<String> entrypoint();
return imageId;
}
public Map<String, ?> getVolumes() { public abstract boolean networkDisabled();
return volumes;
}
public String getVolumesFrom() { public abstract List<String> onBuild();
return volumesFrom;
}
public String getWorkingDir() { @SerializedNames(
return workingDir; { "Hostname", "Domainname", "User", "Memory", "MemorySwap", "CpuShares", "AttachStdin", "AttachStdout",
} "AttachStderr", "ExposedPorts", "Tty", "OpenStdin", "StdinOnce", "Env", "Cmd", "Dns", "Image", "Volumes",
"VolumesFrom", "WorkingDir", "Entrypoint", "NetworkDisabled", "OnBuild" })
public List<String> getEntrypoint() { public static Config create(String hostname, String domainname, String user, int memory, int memorySwap,
return entrypoint; int cpuShares, boolean attachStdin, boolean attachStdout, boolean attachStderr, Map<String, ?> exposedPorts,
} boolean tty, boolean openStdin, boolean stdinOnce, List<String> env, List<String> cmd, List<String> dns,
String image, Map<String, ?> volumes, String volumesFrom, String workingDir, List<String> entrypoint,
public boolean isNetworkDisabled() { boolean networkDisabled, List<String> onBuild) {
return networkDisabled; return new AutoValue_Config(hostname, domainname, user, memory, memorySwap, cpuShares, attachStdin, attachStdout,
} attachStderr, copyOf(exposedPorts), tty, openStdin, stdinOnce, copyOf(env), copyOf(cmd), copyOf(dns), image,
copyOf(volumes), volumesFrom, workingDir, copyOf(entrypoint), networkDisabled, copyOf(onBuild));
public List<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() { public static Builder builder() {
@ -283,7 +101,7 @@ public class Config {
public static final class Builder { public static final class Builder {
private String hostname; private String hostname;
private String domainName; private String domainname;
private String user; private String user;
private int memory; private int memory;
private int memorySwap; private int memorySwap;
@ -298,7 +116,7 @@ public class Config {
private boolean stdinOnce; private boolean stdinOnce;
private List<String> cmd = ImmutableList.of(); private List<String> cmd = ImmutableList.of();
private List<String> dns = ImmutableList.of(); private List<String> dns = ImmutableList.of();
private String imageId; private String image;
private Map<String, ?> volumes = ImmutableMap.of(); private Map<String, ?> volumes = ImmutableMap.of();
private String volumesFrom; private String volumesFrom;
private String workingDir; private String workingDir;
@ -311,8 +129,8 @@ public class Config {
return this; return this;
} }
public Builder domainName(String domainName) { public Builder domainname(String domainname) {
this.domainName = domainName; this.domainname = domainname;
return this; return this;
} }
@ -386,8 +204,8 @@ public class Config {
return this; return this;
} }
public Builder imageId(String imageId) { public Builder image(String image) {
this.imageId = imageId; this.image = image;
return this; return this;
} }
@ -422,36 +240,19 @@ public class Config {
} }
public Config build() { public Config build() {
return new Config(hostname, domainName, user, memory, memorySwap, cpuShares, attachStdin, attachStdout, return Config.create(hostname, domainname, user, memory, memorySwap, cpuShares, attachStdin, attachStdout,
attachStderr, exposedPorts, tty, openStdin, stdinOnce, env, cmd, dns, imageId, volumes, attachStderr, exposedPorts, tty, openStdin, stdinOnce, env, cmd, dns, image, volumes, volumesFrom,
volumesFrom, workingDir, entrypoint, networkDisabled, onBuild); workingDir, entrypoint, networkDisabled, onBuild);
} }
public Builder fromConfig(Config in) { public Builder fromConfig(Config in) {
return this return hostname(in.hostname()).domainname(in.domainname()).user(in.user()).memory(in.memory())
.hostname(in.getHostname()) .memorySwap(in.memorySwap()).cpuShares(in.cpuShares()).attachStdin(in.attachStdin())
.domainName(in.getDomainName()) .attachStdout(in.attachStdout()).attachStderr(in.attachStderr()).exposedPorts(in.exposedPorts())
.user(in.getUser()) .tty(in.tty()).openStdin(in.openStdin()).stdinOnce(in.stdinOnce()).env(in.env()).cmd(in.cmd())
.memory(in.getMemory()) .dns(in.dns()).image(in.image()).volumes(in.volumes()).volumesFrom(in.volumesFrom())
.memorySwap(in.getMemorySwap()) .workingDir(in.workingDir()).entrypoint(in.entrypoint()).networkDisabled(in.networkDisabled())
.cpuShares(in.getCpuShares()) .onBuild(in.onBuild());
.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());
} }
} }

View File

@ -16,222 +16,69 @@
*/ */
package org.jclouds.docker.domain; package org.jclouds.docker.domain;
import com.google.common.base.Objects; import static org.jclouds.docker.internal.NullSafeCopies.copyOf;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.gson.annotations.SerializedName;
import org.jclouds.javax.annotation.Nullable;
import java.beans.ConstructorProperties;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static com.google.common.base.Preconditions.checkNotNull; import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;
public class Container { import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@SerializedName("Id") @AutoValue
private final String id; public abstract class Container {
@SerializedName("Name") public abstract String id();
private final String name;
@SerializedName("Created")
private final String created;
@SerializedName("Path")
private final String path;
@SerializedName("Args")
private final String[] args;
@SerializedName("Config")
private final Config containerConfig;
@SerializedName("State")
private final State state;
@SerializedName("Image")
private final String image;
@SerializedName("NetworkSettings")
private final NetworkSettings networkSettings;
@SerializedName("ResolvConfPath")
private final String resolvConfPath;
@SerializedName("Driver")
private final String driver;
@SerializedName("ExecDriver")
private final String execDriver;
@SerializedName("Volumes")
private final Map<String, String> volumes;
@SerializedName("VolumesRW")
private final Map<String, Boolean> volumesRW;
@SerializedName("Command")
private final String command;
@SerializedName("Status")
private final String status;
@SerializedName("HostConfig")
private final HostConfig hostConfig;
@SerializedName("Ports")
private final List<Port> ports;
@SerializedName("HostnamePath")
private final String hostnamePath;
@ConstructorProperties({ "Id", "Name", "Created", "Path", "Args", "Config", "State", "Image", "NetworkSettings", @Nullable public abstract String name();
"ResolvConfPath", "Driver", "ExecDriver", "Volumes", "VolumesRW", "Command", "Status", "HostConfig",
"Ports", "HostnamePath" })
protected Container(String id, @Nullable String name, @Nullable String created, @Nullable String path, @Nullable String[] args,
@Nullable Config containerConfig, @Nullable State state, @Nullable String image, @Nullable NetworkSettings networkSettings,
@Nullable String resolvConfPath, @Nullable String driver, @Nullable String execDriver, @Nullable Map<String, String> volumes,
@Nullable Map<String, Boolean> volumesRW, @Nullable String command, @Nullable String status,
@Nullable HostConfig hostConfig, @Nullable List<Port> ports, @Nullable String hostnamePath) {
this.id = checkNotNull(id, "id");
this.name = name;
this.created = created;
this.path = path;
this.args = args;
this.containerConfig = containerConfig;
this.state = state;
this.image = image;
this.networkSettings = networkSettings;
this.resolvConfPath = resolvConfPath;
this.driver = driver;
this.execDriver = execDriver;
this.volumes = volumes != null ? ImmutableMap.copyOf(volumes) : ImmutableMap.<String, String>of();
this.volumesRW = volumesRW != null ? ImmutableMap.copyOf(volumesRW) : ImmutableMap.<String, Boolean>of();
this.command = command;
this.status = status;
this.hostConfig = hostConfig;
this.ports = ports != null ? ImmutableList.copyOf(ports) : ImmutableList.<Port>of();
this.hostnamePath = hostnamePath;
}
public String getId() { @Nullable public abstract String created();
return id;
}
public String getName() { @Nullable public abstract String path();
return name;
}
public String getCreated() { public abstract List<String> args();
return created;
}
public String getPath() { @Nullable public abstract Config config();
return path;
}
public String[] getArgs() { @Nullable public abstract State state();
return args;
}
public Config getContainerConfig() { @Nullable public abstract String image();
return containerConfig;
}
public State getState() { @Nullable public abstract NetworkSettings networkSettings();
return state;
}
public String getImage() { @Nullable public abstract String resolvConfPath();
return image;
}
public NetworkSettings getNetworkSettings() { @Nullable public abstract String driver();
return networkSettings;
}
public String getResolvConfPath() { @Nullable public abstract String execDriver();
return resolvConfPath;
}
public String getDriver() { public abstract Map<String, String> volumes();
return driver;
}
public String getExecDriver() { public abstract Map<String, Boolean> volumesRW();
return execDriver;
}
public Map<String, String> getVolumes() { @Nullable public abstract String command();
return volumes;
}
public Map<String, Boolean> getvolumesRW() { @Nullable public abstract String status();
return volumesRW;
}
public String getCommand() { @Nullable public abstract HostConfig hostConfig();
return command;
}
public String getStatus() { public abstract List<Port> ports();
return status;
}
public HostConfig getHostConfig() { @Nullable public abstract String hostnamePath();
return hostConfig;
}
public List<Port> getPorts() { @SerializedNames(
return ports; { "Id", "Name", "Created", "Path", "Args", "Config", "State", "Image", "NetworkSettings", "ResolvConfPath",
} "Driver", "ExecDriver", "Volumes", "VolumesRW", "Command", "Status", "HostConfig", "Ports",
"HostnamePath" })
public String getHostnamePath() { public static Container create(String id, String name, String created, String path, List<String> args, Config config,
return hostnamePath; State state, String image, NetworkSettings networkSettings, String resolvConfPath, String driver,
} String execDriver, Map<String, String> volumes, Map<String, Boolean> volumesRW, String command, String status,
HostConfig hostConfig, List<Port> ports, String hostnamePath) {
@Override return new AutoValue_Container(id, name, created, path, copyOf(args), config, state, image, networkSettings,
public boolean equals(Object o) { resolvConfPath, driver, execDriver, copyOf(volumes), copyOf(volumesRW), command, status, hostConfig,
if (this == o) return true; copyOf(ports), hostnamePath);
if (o == null || getClass() != o.getClass()) return false;
Container that = (Container) o;
return Objects.equal(this.id, that.id) &&
Objects.equal(this.name, that.name) &&
Objects.equal(this.created, that.created) &&
Objects.equal(this.path, that.path) &&
Arrays.equals(this.args, that.args) &&
Objects.equal(this.containerConfig, that.containerConfig) &&
Objects.equal(this.state, that.state) &&
Objects.equal(this.image, that.image) &&
Objects.equal(this.networkSettings, that.networkSettings) &&
Objects.equal(this.resolvConfPath, that.resolvConfPath) &&
Objects.equal(this.driver, that.driver) &&
Objects.equal(this.execDriver, that.execDriver) &&
Objects.equal(this.volumes, that.volumes) &&
Objects.equal(this.volumesRW, that.volumesRW) &&
Objects.equal(this.command, that.command) &&
Objects.equal(this.status, that.status) &&
Objects.equal(this.hostConfig, that.hostConfig) &&
Objects.equal(this.ports, that.ports) &&
Objects.equal(this.hostnamePath, that.hostnamePath);
}
@Override
public int hashCode() {
return Objects.hashCode(id, name, created, path, args, containerConfig, state, image, networkSettings, resolvConfPath,
driver, execDriver, volumes, volumesRW, command, status, hostConfig, ports, hostnamePath);
}
@Override
public String toString() {
return Objects.toStringHelper(this)
.add("id", id)
.add("name", name)
.add("created", created)
.add("path", path)
.add("args", args)
.add("containerConfig", containerConfig)
.add("state", state)
.add("image", image)
.add("networkSettings", networkSettings)
.add("resolvConfPath", resolvConfPath)
.add("driver", driver)
.add("execDriver", execDriver)
.add("volumes", volumes)
.add("volumesRW", volumesRW)
.add("command", command)
.add("status", status)
.add("hostConfig", hostConfig)
.add("ports", ports)
.add("hostnamePath", hostnamePath)
.toString();
} }
public static Builder builder() { public static Builder builder() {
@ -248,8 +95,8 @@ public class Container {
private String name; private String name;
private String created; private String created;
private String path; private String path;
private String[] args; private List<String> args;
private Config containerConfig; private Config config;
private State state; private State state;
private String image; private String image;
private NetworkSettings networkSettings; private NetworkSettings networkSettings;
@ -284,13 +131,13 @@ public class Container {
return this; return this;
} }
public Builder args(String[] args) { public Builder args(List<String> args) {
this.args = args; this.args = args;
return this; return this;
} }
public Builder containerConfig(Config containerConfig) { public Builder config(Config config) {
this.containerConfig = containerConfig; this.config = config;
return this; return this;
} }
@ -360,31 +207,16 @@ public class Container {
} }
public Container build() { public Container build() {
return new Container(id, name, created, path, args, containerConfig, state, image, networkSettings, resolvConfPath, return Container.create(id, name, created, path, args, config, state, image, networkSettings, resolvConfPath,
driver, execDriver, volumes, volumesRW, command, status, hostConfig, ports, hostnamePath); driver, execDriver, volumes, volumesRW, command, status, hostConfig, ports, hostnamePath);
} }
public Builder fromContainer(Container in) { public Builder fromContainer(Container in) {
return this return this.id(in.id()).name(in.name()).created(in.created()).path(in.path()).args(in.args())
.id(in.getId()) .config(in.config()).state(in.state()).image(in.image()).networkSettings(in.networkSettings())
.name(in.getName()) .resolvConfPath(in.resolvConfPath()).driver(in.driver()).execDriver(in.execDriver())
.created(in.getCreated()) .volumes(in.volumes()).volumesRW(in.volumesRW()).command(in.command()).status(in.status())
.path(in.getPath()) .hostConfig(in.hostConfig()).ports(in.ports()).hostnamePath(in.hostnamePath());
.args(in.getArgs())
.containerConfig(in.getContainerConfig())
.state(in.getState())
.image(in.getImage())
.networkSettings(in.getNetworkSettings())
.resolvConfPath(in.getResolvConfPath())
.driver(in.getDriver())
.execDriver(in.getExecDriver())
.volumes(in.getVolumes())
.volumesRW(in.getvolumesRW())
.command(in.getCommand())
.status(in.getStatus())
.hostConfig(in.getHostConfig())
.ports(in.getPorts())
.hostnamePath(in.getHostnamePath());
} }
} }
} }

View File

@ -16,91 +16,22 @@
*/ */
package org.jclouds.docker.domain; package org.jclouds.docker.domain;
import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.docker.internal.NullSafeCopies.copyOf;
import java.beans.ConstructorProperties;
import java.util.Set;
import org.jclouds.javax.annotation.Nullable; import java.util.List;
import com.google.common.base.Objects; import org.jclouds.json.SerializedNames;
import com.google.common.collect.ImmutableSet;
import com.google.gson.annotations.SerializedName;
public class ExposedPorts { import com.google.auto.value.AutoValue;
@SerializedName("PortAndProtocol") @AutoValue
private final String portAndProtocol; public abstract class ExposedPorts {
@SerializedName("HostPorts") public abstract String portAndProtocol();
private final Set<String> hostPorts;
@ConstructorProperties({ "PortAndProtocol", "HostPorts" }) public abstract List<String> hostPorts();
protected ExposedPorts(String portAndProtocol, @Nullable Set<String> hostPorts) {
this.portAndProtocol = checkNotNull(portAndProtocol, "portAndProtocol");
this.hostPorts = hostPorts != null ? ImmutableSet.copyOf(hostPorts) : ImmutableSet.<String> of();
}
public String getPortAndProtocol() { @SerializedNames({ "PortAndProtocol", "HostPorts" })
return portAndProtocol; public static ExposedPorts create(String portAndProtocol, List<String> hostPorts) {
} return new AutoValue_ExposedPorts(portAndProtocol, copyOf(hostPorts));
public Set<String> getHostPorts() {
return hostPorts;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ExposedPorts that = (ExposedPorts) o;
return Objects.equal(this.portAndProtocol, that.portAndProtocol) &&
Objects.equal(this.hostPorts, that.hostPorts);
}
@Override
public int hashCode() {
return Objects.hashCode(portAndProtocol, hostPorts);
}
@Override
public String toString() {
return Objects.toStringHelper(this)
.add("portAndProtocol", portAndProtocol)
.add("hostPorts", hostPorts)
.toString();
}
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return builder().fromExposedPorts(this);
}
public static final class Builder {
private String portAndProtocol;
private Set<String> hostPorts = ImmutableSet.of();
public Builder portAndProtocol(String portAndProtocol) {
this.portAndProtocol = portAndProtocol;
return this;
}
public Builder hostPorts(Set<String> hostPorts) {
this.hostPorts = ImmutableSet.copyOf(checkNotNull(hostPorts, "hostPorts"));
return this;
}
public ExposedPorts build() {
return new ExposedPorts(portAndProtocol, hostPorts);
}
public Builder fromExposedPorts(ExposedPorts in) {
return this.portAndProtocol(in.getPortAndProtocol())
.hostPorts(in.getHostPorts());
}
} }
} }

View File

@ -17,136 +17,47 @@
package org.jclouds.docker.domain; package org.jclouds.docker.domain;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties; import static org.jclouds.docker.internal.NullSafeCopies.copyOf;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;
import com.google.common.base.Objects; import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.gson.annotations.SerializedName;
public class HostConfig { @AutoValue
public abstract class HostConfig {
@Nullable public abstract String containerIDFile();
@SerializedName("ContainerIDFile") public abstract List<String> binds();
private final String containerIDFile;
@SerializedName("Binds")
private final List<String> binds;
@SerializedName("LxcConf")
private final Map<String, String> lxcConf;
@SerializedName("Privileged")
private final boolean privileged;
@SerializedName("Dns")
private final String dns;
@SerializedName("DnsSearch")
private final String dnsSearch;
@SerializedName("PortBindings")
private final Map<String, List<Map<String, String>>> portBindings;
@SerializedName("Links")
private final List<String> links;
@SerializedName("PublishAllPorts")
private final boolean publishAllPorts;
@SerializedName("VolumesFrom")
private final List<String> volumesFrom;
@ConstructorProperties({ "ContainerIDFile", "Binds", "LxcConf", "Privileged", "Dns", "DnsSearch", "PortBindings", public abstract Map<String, String> lxcConf();
public abstract boolean privileged();
@Nullable public abstract String dns();
@Nullable public abstract String dnsSearch();
public abstract Map<String, List<Map<String, String>>> portBindings();
public abstract List<String> links();
public abstract boolean publishAllPorts();
public abstract List<String> volumesFrom();
@SerializedNames({ "ContainerIDFile", "Binds", "LxcConf", "Privileged", "Dns", "DnsSearch", "PortBindings",
"Links", "PublishAllPorts", "VolumesFrom" }) "Links", "PublishAllPorts", "VolumesFrom" })
protected HostConfig(@Nullable String containerIDFile, @Nullable List<String> binds, public static HostConfig create(String containerIDFile, List<String> binds, Map<String, String> lxcConf,
Map<String, String> lxcConf, boolean privileged, @Nullable String dns, boolean privileged, String dns, String dnsSearch, Map<String, List<Map<String, String>>> portBindings,
@Nullable String dnsSearch, @Nullable Map<String, List<Map<String, String>>> portBindings, List<String> links, boolean publishAllPorts, List<String> volumesFrom) {
@Nullable List<String> links, boolean publishAllPorts, @Nullable List<String> volumesFrom) { return new AutoValue_HostConfig(containerIDFile, copyOf(binds), copyOf(lxcConf), privileged, dns, dnsSearch,
this.containerIDFile = containerIDFile; copyOf(portBindings), copyOf(links), publishAllPorts, copyOf(volumesFrom));
this.binds = binds != null ? ImmutableList.copyOf(binds) : ImmutableList.<String> of();
this.lxcConf = lxcConf != null ? ImmutableMap.copyOf(lxcConf) : ImmutableMap.<String, String> of();
this.privileged = checkNotNull(privileged, "privileged");
this.dns = dns;
this.dnsSearch = dnsSearch;
this.portBindings = portBindings != null ? ImmutableMap.copyOf(portBindings) : ImmutableMap.<String, List<Map<String, String>>> of();
this.links = links != null ? ImmutableList.copyOf(links) : ImmutableList.<String> of();
this.publishAllPorts = checkNotNull(publishAllPorts, "publishAllPorts");
this.volumesFrom = volumesFrom != null ? ImmutableList.copyOf(volumesFrom) : ImmutableList.<String> of();
}
public String getContainerIDFile() {
return containerIDFile;
}
public List<String> getBinds() {
return binds;
}
public Map<String, String> getLxcConf() {
return lxcConf;
}
public boolean isPrivileged() {
return privileged;
}
public String getDns() { return dns; }
public String getDnsSearch() { return dnsSearch; }
public Map<String, List<Map<String, String>>> getPortBindings() {
return portBindings;
}
@Nullable
public List<String> getLinks() {
return links;
}
public boolean isPublishAllPorts() {
return publishAllPorts;
}
public List<String> getVolumesFrom() {
return volumesFrom;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
HostConfig that = (HostConfig) o;
return Objects.equal(this.containerIDFile, that.containerIDFile) &&
Objects.equal(this.binds, that.binds) &&
Objects.equal(this.lxcConf, that.lxcConf) &&
Objects.equal(this.privileged, that.privileged) &&
Objects.equal(this.dns, that.dns) &&
Objects.equal(this.dnsSearch, that.dnsSearch) &&
Objects.equal(this.portBindings, that.portBindings) &&
Objects.equal(this.links, that.links) &&
Objects.equal(this.publishAllPorts, that.publishAllPorts) &&
Objects.equal(this.volumesFrom, that.volumesFrom);
}
@Override
public int hashCode() {
return Objects.hashCode(containerIDFile, binds, lxcConf, privileged, dns, dnsSearch, portBindings, links,
publishAllPorts, volumesFrom);
}
@Override
public String toString() {
return Objects.toStringHelper(this)
.add("containerIDFile", containerIDFile)
.add("binds", binds)
.add("lxcConf", lxcConf)
.add("privileged", privileged)
.add("dns", dns)
.add("dnsSearch", dnsSearch)
.add("portBindings", portBindings)
.add("links", links)
.add("publishAllPorts", publishAllPorts)
.add("volumesFrom", volumesFrom)
.toString();
} }
public static Builder builder() { public static Builder builder() {
@ -221,22 +132,14 @@ public class HostConfig {
} }
public HostConfig build() { public HostConfig build() {
return new HostConfig(containerIDFile, binds, lxcConf, privileged, dns, dnsSearch, portBindings, links, return HostConfig.create(containerIDFile, binds, lxcConf, privileged, dns, dnsSearch, portBindings, links,
publishAllPorts, volumesFrom); publishAllPorts, volumesFrom);
} }
public Builder fromHostConfig(HostConfig in) { public Builder fromHostConfig(HostConfig in) {
return this return this.containerIDFile(in.containerIDFile()).binds(in.binds()).lxcConf(in.lxcConf())
.containerIDFile(in.getContainerIDFile()) .privileged(in.privileged()).dns(in.dns()).dnsSearch(in.dnsSearch()).links(in.links())
.binds(in.getBinds()) .portBindings(in.portBindings()).publishAllPorts(in.publishAllPorts()).volumesFrom(in.volumesFrom());
.lxcConf(in.getLxcConf())
.privileged(in.isPrivileged())
.dns(in.getDns())
.dnsSearch(in.getDnsSearch())
.links(in.getLinks())
.portBindings(in.getPortBindings())
.publishAllPorts(in.isPublishAllPorts())
.volumesFrom(in.getVolumesFrom());
} }
} }
} }

View File

@ -16,224 +16,42 @@
*/ */
package org.jclouds.docker.domain; package org.jclouds.docker.domain;
import com.google.common.base.Objects; import static org.jclouds.docker.internal.NullSafeCopies.copyOf;
import com.google.common.collect.ImmutableList;
import com.google.gson.annotations.SerializedName;
import org.jclouds.javax.annotation.Nullable;
import java.beans.ConstructorProperties;
import java.util.List; import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull; import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;
public class Image { import com.google.auto.value.AutoValue;
@SerializedName("Id") @AutoValue
private final String id; public abstract class Image {
@SerializedName("Parent") public abstract String id();
private final String parent;
@SerializedName("Created")
private final String created;
@SerializedName("Container")
private final String container;
@SerializedName("DockerVersion")
private final String dockerVersion;
@SerializedName("Architecture")
private final String architecture;
@SerializedName("Os")
private final String os;
@SerializedName("Size")
private final long size;
@SerializedName("VirtualSize")
private final long virtualSize;
@SerializedName("RepoTags")
private final List<String> repoTags;
@ConstructorProperties({ "Id", "Parent", "Created", "Container", "DockerVersion", "Architecture", "Os", "Size", @Nullable public abstract String parent();
@Nullable public abstract String created();
@Nullable public abstract String container();
@Nullable public abstract String dockerVersion();
@Nullable public abstract String architecture();
@Nullable public abstract String os();
public abstract long size();
@Nullable public abstract long virtualSize();
public abstract List<String> repoTags();
@SerializedNames({ "Id", "Parent", "Created", "Container", "DockerVersion", "Architecture", "Os", "Size",
"VirtualSize", "RepoTags", "Architecture" }) "VirtualSize", "RepoTags", "Architecture" })
protected Image(String id, @Nullable String parent, @Nullable String created, @Nullable String container, public static Image create(String id, String parent, String created, String container, String dockerVersion,
@Nullable String dockerVersion, @Nullable String architecture, @Nullable String os, long size, String architecture, String os, long size, long virtualSize, List<String> repoTags) {
@Nullable long virtualSize, @Nullable List<String> repoTags) { return new AutoValue_Image(id, parent, created, container, dockerVersion, architecture, os, size, virtualSize,
this.id = checkNotNull(id, "id"); copyOf(repoTags));
this.parent = parent;
this.created = created;
this.container = container;
this.dockerVersion = dockerVersion;
this.architecture = architecture;
this.os = os;
this.size = size;
this.virtualSize = virtualSize;
this.repoTags = repoTags != null ? ImmutableList.copyOf(repoTags) : ImmutableList.<String> of();
}
public String getId() {
return id;
}
public String getParent() {
return parent;
}
public String getCreated() {
return created;
}
public String getContainer() {
return container;
}
public String getDockerVersion() {
return dockerVersion;
}
public String getArchitecture() {
return architecture;
}
public String getOs() {
return os;
}
public long getSize() {
return size;
}
public long getVirtualSize() {
return virtualSize;
}
public List<String> getRepoTags() {
return repoTags;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Image that = (Image) o;
return Objects.equal(this.id, that.id) &&
Objects.equal(this.parent, that.parent) &&
Objects.equal(this.created, that.created) &&
Objects.equal(this.container, that.container) &&
Objects.equal(this.dockerVersion, that.dockerVersion) &&
Objects.equal(this.architecture, that.architecture) &&
Objects.equal(this.os, that.os) &&
Objects.equal(this.size, that.size) &&
Objects.equal(this.virtualSize, that.virtualSize);
}
@Override
public int hashCode() {
return Objects.hashCode(id, parent, created, container, dockerVersion, architecture, os, size,
virtualSize);
}
@Override
public String toString() {
return Objects.toStringHelper(this)
.add("id", id)
.add("parent", parent)
.add("created", created)
.add("container", container)
.add("dockerVersion", dockerVersion)
.add("architecture", architecture)
.add("os", os)
.add("size", size)
.add("virtualSize", virtualSize)
.add("repoTags", repoTags)
.toString();
}
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return builder().fromImage(this);
}
public static final class Builder {
private String id;
private String parent;
private String created;
private String container;
private String dockerVersion;
private String architecture;
private String os;
private long size;
private long virtualSize;
private List<String> repoTags = ImmutableList.of();
public Builder id(String id) {
this.id = id;
return this;
}
public Builder parent(String parent) {
this.parent = parent;
return this;
}
public Builder created(String created) {
this.created = created;
return this;
}
public Builder container(String container) {
this.container = container;
return this;
}
public Builder dockerVersion(String dockerVersion) {
this.dockerVersion = dockerVersion;
return this;
}
public Builder architecture(String architecture) {
this.architecture = architecture;
return this;
}
public Builder os(String os) {
this.os = os;
return this;
}
public Builder size(long size) {
this.size = size;
return this;
}
public Builder virtualSize(long virtualSize) {
this.virtualSize = virtualSize;
return this;
}
public Builder repoTags(List<String> repoTags) {
this.repoTags = ImmutableList.copyOf(checkNotNull(repoTags, "repoTags"));
return this;
}
public Image build() {
return new Image(id, parent, created, container, dockerVersion, architecture, os, size,
virtualSize, repoTags);
}
public Builder fromImage(Image in) {
return this
.id(in.getId())
.parent(in.getParent())
.created(in.getCreated())
.container(in.getContainer())
.dockerVersion(in.getDockerVersion())
.architecture(in.getArchitecture())
.os(in.getOs())
.size(in.getSize())
.virtualSize(in.getVirtualSize());
//DO NOT add .repoTags(in.getRepoTags());
}
} }
} }

View File

@ -16,97 +16,36 @@
*/ */
package org.jclouds.docker.domain; package org.jclouds.docker.domain;
import com.google.common.base.Objects; import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.ImmutableMap; import static org.jclouds.docker.internal.NullSafeCopies.copyOf;
import com.google.gson.annotations.SerializedName;
import org.jclouds.javax.annotation.Nullable;
import java.beans.ConstructorProperties;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static com.google.common.base.Preconditions.checkNotNull; import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;
public class NetworkSettings { import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableMap;
@SerializedName("IPAddress") @AutoValue
private final String ipAddress; public abstract class NetworkSettings {
@SerializedName("IPPrefixLen") public abstract String ipAddress();
private final int ipPrefixLen;
@SerializedName("Gateway")
private final String gateway;
@SerializedName("Bridge")
private final String bridge;
@SerializedName("PortMapping")
private final String portMapping;
@SerializedName("Ports")
private final Map<String, List<Map<String, String>>> ports;
@ConstructorProperties({ "IPAddress", "IPPrefixLen", "Gateway", "Bridge", "PortMapping", "Ports" }) public abstract int ipPrefixLen();
protected NetworkSettings(String ipAddress, int ipPrefixLen, String gateway, String bridge,
@Nullable String portMapping, @Nullable Map<String, List<Map<String, String>>> ports) {
this.ipAddress = checkNotNull(ipAddress, "ipAddress");
this.ipPrefixLen = checkNotNull(ipPrefixLen, "ipPrefixLen");
this.gateway = checkNotNull(gateway, "gateway");
this.bridge = checkNotNull(bridge, "bridge");
this.portMapping = portMapping;
this.ports = ports != null ? ImmutableMap.copyOf(ports) : ImmutableMap.<String, List<Map<String, String>>> of();
}
public String getIpAddress() { public abstract String gateway();
return ipAddress;
}
public int getIpPrefixLen() { public abstract String bridge();
return ipPrefixLen;
}
public String getGateway() { @Nullable public abstract String portMapping();
return gateway;
}
public String getBridge() { public abstract Map<String, List<Map<String, String>>> ports();
return bridge;
}
public String getPortMapping() { @SerializedNames({ "IPAddress", "IPPrefixLen", "Gateway", "Bridge", "PortMapping", "Ports" })
return portMapping; public static NetworkSettings create(String ipAddress, int ipPrefixLen, String gateway, String bridge,
} String portMapping, Map<String, List<Map<String, String>>> ports) {
return new AutoValue_NetworkSettings(ipAddress, ipPrefixLen, gateway, bridge, portMapping, copyOf(ports));
public Map<String, List<Map<String, String>>> getPorts() {
return ports;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NetworkSettings that = (NetworkSettings) o;
return Objects.equal(this.ipAddress, that.ipAddress) &&
Objects.equal(this.ipPrefixLen, that.ipPrefixLen) &&
Objects.equal(this.gateway, that.gateway) &&
Objects.equal(this.bridge, that.bridge) &&
Objects.equal(this.portMapping, that.portMapping) &&
Objects.equal(this.ports, that.ports);
}
@Override
public int hashCode() {
return Objects.hashCode(ipAddress, ipPrefixLen, gateway, bridge, portMapping, ports);
}
@Override
public String toString() {
return Objects.toStringHelper(this)
.add("ipAddress", ipAddress)
.add("ipPrefixLen", ipPrefixLen)
.add("gateway", gateway)
.add("bridge", bridge)
.add("portMapping", portMapping)
.add("ports", ports)
.toString();
} }
public static Builder builder() { public static Builder builder() {
@ -157,19 +96,13 @@ public class NetworkSettings {
} }
public NetworkSettings build() { public NetworkSettings build() {
return new NetworkSettings(ipAddress, ipPrefixLen, gateway, bridge, portMapping, ports); return NetworkSettings.create(ipAddress, ipPrefixLen, gateway, bridge, portMapping, ports);
} }
public Builder fromNetworkSettings(NetworkSettings in) { public Builder fromNetworkSettings(NetworkSettings in) {
return this return this.ipAddress(in.ipAddress()).ipPrefixLen(in.ipPrefixLen()).gateway(in.gateway()).bridge(in.bridge())
.ipAddress(in.getIpAddress()) .portMapping(in.portMapping()).ports(in.ports());
.ipPrefixLen(in.getIpPrefixLen())
.gateway(in.getGateway())
.bridge(in.getBridge())
.portMapping(in.getPortMapping())
.ports(in.getPorts());
} }
} }
} }

View File

@ -16,73 +16,22 @@
*/ */
package org.jclouds.docker.domain; package org.jclouds.docker.domain;
import com.google.common.base.Objects; import org.jclouds.json.SerializedNames;
import com.google.gson.annotations.SerializedName;
import java.beans.ConstructorProperties; import com.google.auto.value.AutoValue;
import static com.google.common.base.Preconditions.checkNotNull; @AutoValue
public abstract class Port {
public abstract String ip();
public class Port { public abstract int privatePort();
@SerializedName("PrivatePort") public abstract int publicPort();
private final int privatePort;
@SerializedName("PublicPort")
private final int publicPort;
@SerializedName("Type")
private final String type;
@SerializedName("IP")
private final String ip;
@ConstructorProperties({ "PrivatePort", "PublicPort", "Type", "IP" }) public abstract String type();
protected Port(int privatePort, int publicPort, String type, String ip) {
this.privatePort = checkNotNull(privatePort, "privatePort");
this.publicPort = checkNotNull(publicPort, "publicPort");
this.type = checkNotNull(type, "type");
this.ip = checkNotNull(ip, "ip");
}
public int getPrivatePort() { @SerializedNames({ "IP", "PrivatePort", "PublicPort", "Type" })
return privatePort; public static Port create(String ip, int privatePort, int publicPort, String type) {
} return new AutoValue_Port(ip, privatePort, publicPort, type);
public int getPublicPort() {
return publicPort;
}
public String getType() {
return type;
}
public String getIp() {
return ip;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Port that = (Port) o;
return Objects.equal(this.privatePort, that.privatePort) &&
Objects.equal(this.publicPort, that.publicPort) &&
Objects.equal(this.type, that.type) &&
Objects.equal(this.ip, that.ip);
}
@Override
public int hashCode() {
return Objects.hashCode(privatePort, publicPort, type, ip);
}
@Override
public String toString() {
return Objects.toStringHelper(this)
.add("privatePort", privatePort)
.add("publicPort", publicPort)
.add("type", type)
.add("ip", ip)
.toString();
} }
} }

View File

@ -16,151 +16,27 @@
*/ */
package org.jclouds.docker.domain; package org.jclouds.docker.domain;
import static com.google.common.base.Preconditions.checkNotNull; import org.jclouds.json.SerializedNames;
import java.beans.ConstructorProperties;
import com.google.common.base.Objects; import com.google.auto.value.AutoValue;
import com.google.gson.annotations.SerializedName;
public class State { @AutoValue
@SerializedName("Pid") public abstract class State {
private final int pid; public abstract int pid();
@SerializedName("Running")
private final boolean running;
@SerializedName("ExitCode")
private final int exitCode;
@SerializedName("StartedAt")
private final String startedAt;
@SerializedName("FinishedAt")
private final String finishedAt;
@SerializedName("Ghost")
private final boolean ghost;
@ConstructorProperties({ "Pid", "Running", "ExitCode", "StartedAt", "FinishedAt", "Ghost" }) public abstract boolean running();
protected State(int pid, boolean running, int exitCode, String startedAt, String finishedAt, boolean ghost) {
this.pid = checkNotNull(pid, "pid");
this.running = checkNotNull(running, "running");
this.exitCode = checkNotNull(exitCode, "exitCode");
this.startedAt = checkNotNull(startedAt, "startedAt");
this.finishedAt = checkNotNull(finishedAt, "finishedAt");
this.ghost = checkNotNull(ghost, "ghost");
}
public int getPid() { public abstract int exitCode();
return pid;
}
public boolean isRunning() { public abstract String startedAt();
return running;
}
public int getExitCode() { public abstract String finishedAt();
return exitCode;
}
public String getStartedAt() { public abstract boolean ghost();
return startedAt;
}
public String getFinishedAt() { @SerializedNames({ "Pid", "Running", "ExitCode", "StartedAt", "FinishedAt", "Ghost" })
return finishedAt; public static State create(int pid, boolean running, int exitCode, String startedAt, String finishedAt,
} boolean ghost) {
return new AutoValue_State(pid, running, exitCode, startedAt, finishedAt, ghost);
public boolean isGhost() {
return ghost;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
State that = (State) o;
return Objects.equal(this.pid, that.pid) &&
Objects.equal(this.running, that.running) &&
Objects.equal(this.exitCode, that.exitCode) &&
Objects.equal(this.startedAt, that.startedAt) &&
Objects.equal(this.finishedAt, that.finishedAt) &&
Objects.equal(this.ghost, that.ghost);
}
@Override
public int hashCode() {
return Objects.hashCode(pid, running, exitCode, startedAt, finishedAt, ghost);
}
@Override
public String toString() {
return Objects.toStringHelper(this)
.add("pid", pid)
.add("running", running)
.add("exitCode", exitCode)
.add("startedAt", startedAt)
.add("finishedAt", finishedAt)
.add("ghost", ghost)
.toString();
}
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return builder().fromState(this);
}
public static final class Builder {
private int pid;
private boolean running;
private int exitCode;
private String startedAt;
private String finishedAt;
private boolean ghost;
public Builder pid(int pid) {
this.pid = pid;
return this;
}
public Builder running(boolean running) {
this.running = running;
return this;
}
public Builder exitCode(int exitCode) {
this.exitCode = exitCode;
return this;
}
public Builder startedAt(String startedAt) {
this.startedAt = startedAt;
return this;
}
public Builder finishedAt(String finishedAt) {
this.finishedAt = finishedAt;
return this;
}
public Builder ghost(boolean ghost) {
this.ghost = ghost;
return this;
}
public State build() {
return new State(pid, running, exitCode, startedAt, finishedAt, ghost);
}
public Builder fromState(State in) {
return this
.pid(in.getPid())
.running(in.isRunning())
.exitCode(in.getExitCode())
.startedAt(in.getStartedAt())
.finishedAt(in.getFinishedAt())
.ghost(in.isGhost());
}
} }
} }

View File

@ -16,151 +16,27 @@
*/ */
package org.jclouds.docker.domain; package org.jclouds.docker.domain;
import static com.google.common.base.Preconditions.checkNotNull; import org.jclouds.json.SerializedNames;
import java.beans.ConstructorProperties;
import com.google.common.base.Objects; import com.google.auto.value.AutoValue;
import com.google.gson.annotations.SerializedName;
public class Version { @AutoValue
@SerializedName("Arch") public abstract class Version {
private final String arch; public abstract String arch();
@SerializedName("GitCommit")
private final String gitCommit;
@SerializedName("GoVersion")
private final String goVersion;
@SerializedName("KernelVersion")
private final String kernelVersion;
@SerializedName("Os")
private final String os;
@SerializedName("Version")
private final String version;
@ConstructorProperties({ "Arch", "GitCommit", "GoVersion", "KernelVersion", "Os", "Version" }) public abstract String gitCommit();
protected Version(String arch, String gitCommit, String goVersion, String kernelVersion, String os, String version) {
this.arch = checkNotNull(arch, "arch");
this.gitCommit = checkNotNull(gitCommit, "gitCommit");
this.goVersion = checkNotNull(goVersion, "goVersion");
this.kernelVersion = checkNotNull(kernelVersion, "kernelVersion");
this.os = checkNotNull(os, "os");
this.version = checkNotNull(version, "version");
}
public String getArch() { public abstract String goVersion();
return arch;
}
public String getGitCommit() { public abstract String kernelVersion();
return gitCommit;
}
public String getGoVersion() { public abstract String os();
return goVersion;
}
public String getKernelVersion() { public abstract String version();
return kernelVersion;
}
public String getOs() { @SerializedNames({ "Arch", "GitCommit", "GoVersion", "KernelVersion", "Os", "Version" })
return os; public static Version create(String arch, String gitCommit, String goVersion, String kernelVersion, String os,
} String version) {
return new AutoValue_Version(arch, gitCommit, goVersion, kernelVersion, os, version);
public String getVersion() {
return version;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Version that = (Version) o;
return Objects.equal(this.arch, that.arch) &&
Objects.equal(this.gitCommit, that.gitCommit) &&
Objects.equal(this.goVersion, that.goVersion) &&
Objects.equal(this.kernelVersion, that.kernelVersion) &&
Objects.equal(this.os, that.os) &&
Objects.equal(this.version, that.version);
}
@Override
public int hashCode() {
return Objects.hashCode(arch, gitCommit, goVersion, kernelVersion, os, version);
}
@Override
public String toString() {
return Objects.toStringHelper(this)
.add("arch", arch)
.add("gitCommit", gitCommit)
.add("goVersion", goVersion)
.add("kernelVersion", kernelVersion)
.add("os", os)
.add("version", version)
.toString();
}
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return builder().fromVersion(this);
}
public static final class Builder {
private String arch;
private String gitCommit;
private String goVersion;
private String kernelVersion;
private String os;
private String version;
public Builder arch(String arch) {
this.arch = arch;
return this;
}
public Builder gitCommit(String gitCommit) {
this.gitCommit = gitCommit;
return this;
}
public Builder goVersion(String goVersion) {
this.goVersion = goVersion;
return this;
}
public Builder kernelVersion(String kernelVersion) {
this.kernelVersion = kernelVersion;
return this;
}
public Builder os(String os) {
this.os = os;
return this;
}
public Builder version(String version) {
this.version = version;
return this;
}
public Version build() {
return new Version(arch, gitCommit, goVersion, kernelVersion, os, version);
}
public Builder fromVersion(Version in) {
return this
.arch(in.getArch())
.gitCommit(in.getGitCommit())
.goVersion(in.getGoVersion())
.kernelVersion(in.getKernelVersion())
.os(in.getOs())
.version(in.getVersion());
}
} }
} }

View File

@ -0,0 +1,39 @@
/*
* 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.internal;
import java.util.List;
import java.util.Map;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
public class NullSafeCopies {
public static <K, V> Map<K, V> copyOf(@Nullable Map<K, V> map) {
return map != null ? ImmutableMap.copyOf(map) : ImmutableMap.<K, V>of();
}
public static <E> List<E> copyOf(@Nullable List<E> list) {
return list != null ? ImmutableList.copyOf(list) : ImmutableList.<E>of();
}
private NullSafeCopies() {
}
}

View File

@ -61,7 +61,7 @@ public class DockerComputeServiceAdapterLiveTest extends BaseDockerApiLiveTest {
.osDescriptionMatches("jclouds/default:latest").build(); .osDescriptionMatches("jclouds/default:latest").build();
guest = adapter.createNodeWithGroupEncodedIntoName(group, name, template); guest = adapter.createNodeWithGroupEncodedIntoName(group, name, template);
assertEquals(guest.getNodeId(), guest.getNode().getId() + ""); assertEquals(guest.getNodeId(), guest.getNode().id() + "");
} }
public void testListHardwareProfiles() { public void testListHardwareProfiles() {
@ -76,7 +76,7 @@ public class DockerComputeServiceAdapterLiveTest extends BaseDockerApiLiveTest {
@AfterGroups(groups = "live") @AfterGroups(groups = "live")
protected void tearDown() { protected void tearDown() {
if (guest != null) { if (guest != null) {
adapter.destroyNode(guest.getNode().getId() + ""); adapter.destroyNode(guest.getNode().id() + "");
} }
super.tearDown(); super.tearDown();
} }

View File

@ -21,6 +21,8 @@ import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify; import static org.easymock.EasyMock.verify;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -65,7 +67,7 @@ public class ContainerToNodeMetadataTest {
public void setup() { public void setup() {
Config containerConfig = Config.builder() Config containerConfig = Config.builder()
.hostname("6d35806c1bd2") .hostname("6d35806c1bd2")
.domainName("") .domainname("")
.user("") .user("")
.memory(0) .memory(0)
.memorySwap(0) .memorySwap(0)
@ -79,27 +81,27 @@ public class ContainerToNodeMetadataTest {
.stdinOnce(false) .stdinOnce(false)
.env(null) .env(null)
.cmd(ImmutableList.of("/usr/sbin/sshd", "-D")) .cmd(ImmutableList.of("/usr/sbin/sshd", "-D"))
.imageId("jclouds/ubuntu") .image("jclouds/ubuntu")
.volumesFrom("") .volumesFrom("")
.workingDir("") .workingDir("")
.entrypoint(null) .entrypoint(null)
.networkDisabled(false) .networkDisabled(false)
.build(); .build();
State state = State.builder() State state = State.create( //
.pid(3626) 3626, // pid
.running(true) true, // running
.exitCode(0) 0, // exitCode
.startedAt("2014-03-24T20:28:37.537659054Z") "2014-03-24T20:28:37.537659054Z", // startedAt
.finishedAt("0001-01-01T00:00:00Z") "0001-01-01T00:00:00Z", // finishedAt
.ghost(false) false // ghost
.build(); );
container = Container.builder() container = Container.builder()
.id("6d35806c1bd2b25cd92bba2d2c2c5169dc2156f53ab45c2b62d76e2d2fee14a9") .id("6d35806c1bd2b25cd92bba2d2c2c5169dc2156f53ab45c2b62d76e2d2fee14a9")
.name("/hopeful_mclean") .name("/hopeful_mclean")
.created("2014-03-22T07:16:45.784120972Z") .created("2014-03-22T07:16:45.784120972Z")
.path("/usr/sbin/sshd") .path("/usr/sbin/sshd")
.args(new String[] {"-D"}) .args(Arrays.asList("-D"))
.containerConfig(containerConfig) .config(containerConfig)
.state(state) .state(state)
.image("af0f59f1c19eef9471c3b8c8d587c39b8f130560b54f3766931b37d76d5de4b6") .image("af0f59f1c19eef9471c3b8c8d587c39b8f130560b54f3766931b37d76d5de4b6")
.networkSettings(NetworkSettings.builder() .networkSettings(NetworkSettings.builder()
@ -190,12 +192,12 @@ public class ContainerToNodeMetadataTest {
private Container mockContainer() { private Container mockContainer() {
Container mockContainer = EasyMock.createMock(Container.class); Container mockContainer = EasyMock.createMock(Container.class);
expect(mockContainer.getId()).andReturn(container.getId()); expect(mockContainer.id()).andReturn(container.id());
expect(mockContainer.getName()).andReturn(container.getName()); expect(mockContainer.name()).andReturn(container.name());
expect(mockContainer.getContainerConfig()).andReturn(container.getContainerConfig()).anyTimes(); expect(mockContainer.config()).andReturn(container.config()).anyTimes();
expect(mockContainer.getNetworkSettings()).andReturn(container.getNetworkSettings()).anyTimes(); expect(mockContainer.networkSettings()).andReturn(container.networkSettings()).anyTimes();
expect(mockContainer.getState()).andReturn(container.getState()); expect(mockContainer.state()).andReturn(container.state());
expect(mockContainer.getImage()).andReturn(container.getImage()).anyTimes(); expect(mockContainer.image()).andReturn(container.image()).anyTimes();
replay(mockContainer); replay(mockContainer);
return mockContainer; return mockContainer;

View File

@ -39,14 +39,18 @@ public class ImageToImageTest {
@BeforeMethod @BeforeMethod
public void setup() { public void setup() {
image = org.jclouds.docker.domain.Image.builder() image = org.jclouds.docker.domain.Image.create(
.id("id") "id", // id
.parent("parent") "parent", // parent
.created("created") "created", // created
.architecture("x86_64") null, // container
.repoTags(ImmutableList.of("repoTag1:version")) null, // dockerVersion
.size(0l) "x86_64", // architecture
.build(); null, // os
0l, // size
0l, // virtualSize
ImmutableList.of("repoTag1:version") // repoTags
);
function = new ImageToImage(); function = new ImageToImage();
} }
@ -57,15 +61,15 @@ public class ImageToImageTest {
verify(mockImage); verify(mockImage);
assertEquals(mockImage.getId(), image.getId().toString()); assertEquals(mockImage.id(), image.getId().toString());
} }
private org.jclouds.docker.domain.Image mockImage() { private org.jclouds.docker.domain.Image mockImage() {
org.jclouds.docker.domain.Image mockImage = EasyMock.createMock(org.jclouds.docker.domain.Image.class); org.jclouds.docker.domain.Image mockImage = EasyMock.createMock(org.jclouds.docker.domain.Image.class);
expect(mockImage.getId()).andReturn(image.getId()).anyTimes(); expect(mockImage.id()).andReturn(image.id()).anyTimes();
expect(mockImage.getRepoTags()).andReturn(image.getRepoTags()).anyTimes(); expect(mockImage.repoTags()).andReturn(image.repoTags()).anyTimes();
expect(mockImage.getArchitecture()).andReturn(image.getArchitecture()).anyTimes(); expect(mockImage.architecture()).andReturn(image.architecture()).anyTimes();
replay(mockImage); replay(mockImage);
return mockImage; return mockImage;

View File

@ -46,7 +46,7 @@ public class StateToStatusTest {
verify(mockState); verify(mockState);
assertEquals(mockState.isRunning(), true); assertEquals(mockState.running(), true);
assertEquals(status, NodeMetadata.Status.RUNNING); assertEquals(status, NodeMetadata.Status.RUNNING);
} }
@ -57,14 +57,14 @@ public class StateToStatusTest {
verify(mockState); verify(mockState);
assertEquals(mockState.isRunning(), false); assertEquals(mockState.running(), false);
assertEquals(status, NodeMetadata.Status.TERMINATED); assertEquals(status, NodeMetadata.Status.TERMINATED);
} }
private State mockStateRunning() { private State mockStateRunning() {
State mockState = EasyMock.createMock(State.class); State mockState = EasyMock.createMock(State.class);
expect(mockState.isRunning()).andReturn(true).anyTimes(); expect(mockState.running()).andReturn(true).anyTimes();
replay(mockState); replay(mockState);
return mockState; return mockState;
@ -73,7 +73,7 @@ public class StateToStatusTest {
private State mockStateNotRunning() { private State mockStateNotRunning() {
State mockState = EasyMock.createMock(State.class); State mockState = EasyMock.createMock(State.class);
expect(mockState.isRunning()).andReturn(false).anyTimes(); expect(mockState.running()).andReturn(false).anyTimes();
replay(mockState); replay(mockState);
return mockState; return mockState;

View File

@ -16,37 +16,46 @@
*/ */
package org.jclouds.docker.config; package org.jclouds.docker.config;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.jclouds.docker.domain.Container;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.jclouds.docker.config.DockerParserModule.ContainerTypeAdapter;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import org.jclouds.docker.domain.Container;
import org.jclouds.docker.domain.NetworkSettings;
import org.jclouds.docker.domain.Port;
import org.jclouds.json.Json;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Guice;
/** /**
* Unit tests for the {@link org.jclouds.docker.config.DockerParserModule} class. * Unit tests for the {@link org.jclouds.docker.config.DockerParserModule} class.
*/ */
@Test(groups = "unit", testName = "DockerParserModuleTest") @Test(groups = "unit", testName = "DockerParserModuleTest")
public class DockerParserModuleTest { public class DockerParserModuleTest {
private Gson gson; private Json json = Guice.createInjector(new GsonModule(), new DockerParserModule()).getInstance(Json.class);
@BeforeMethod
public void setup() {
gson = new GsonBuilder()
.registerTypeAdapter(Container.class, new ContainerTypeAdapter())
.create();
}
@Test
public void testContainerWithVolumesNull() { public void testContainerWithVolumesNull() {
Container container = gson.fromJson( Container container = json.fromJson("{ \"Id\": \"foo\", \"Volumes\": null }", Container.class);
"{ \"Volumes\": null }", Container.class);
assertNotNull(container); assertNotNull(container);
assertEquals(container.getVolumes(), null); assertEquals(container.id(), "foo");
assertEquals(container.volumes(), ImmutableMap.of());
} }
public void port() {
// Note IP, not Ip
String text = "{\"IP\":\"0.0.0.0\",\"PrivatePort\":4567,\"PublicPort\":49155,\"Type\":\"tcp\"}";
Port port = Port.create("0.0.0.0", 4567, 49155, "tcp");
assertEquals(json.fromJson(text, Port.class), port);
assertEquals(json.toJson(port), text);
}
public void networkSettings() {
String text = "{\"IPAddress\":\"XX.XX.206.98\",\"IPPrefixLen\":27,\"Gateway\":\"XX.XX.206.105\",\"Bridge\":\"public\",\"Ports\":{}}";
NetworkSettings settings = NetworkSettings.create("XX.XX.206.98", 27, "XX.XX.206.105", "public", null, null);
assertEquals(json.fromJson(text, NetworkSettings.class), settings);
assertEquals(json.toJson(settings), text);
}
} }

View File

@ -50,7 +50,7 @@ public class RemoteApiLiveTest extends BaseDockerApiLiveTest {
@Test @Test
public void testVersion() { public void testVersion() {
assertEquals(api().getVersion().getVersion(), "1.0.0"); assertEquals(api().getVersion().version(), "1.0.0");
} }
@Test(dependsOnMethods = "testVersion") @Test(dependsOnMethods = "testVersion")
@ -69,37 +69,37 @@ public class RemoteApiLiveTest extends BaseDockerApiLiveTest {
@Test(dependsOnMethods = "testListImages") @Test(dependsOnMethods = "testListImages")
public void testCreateContainer() throws IOException, InterruptedException { public void testCreateContainer() throws IOException, InterruptedException {
Config containerConfig = Config.builder().imageId(image.getId()) Config containerConfig = Config.builder().image(image.id())
.cmd(ImmutableList.of("/bin/sh", "-c", "while true; do echo hello world; sleep 1; done")) .cmd(ImmutableList.of("/bin/sh", "-c", "while true; do echo hello world; sleep 1; done"))
.build(); .build();
container = api().createContainer("testCreateContainer", containerConfig); container = api().createContainer("testCreateContainer", containerConfig);
assertNotNull(container); assertNotNull(container);
assertNotNull(container.getId()); assertNotNull(container.id());
} }
@Test(dependsOnMethods = "testCreateContainer") @Test(dependsOnMethods = "testCreateContainer")
public void testStartContainer() throws IOException, InterruptedException { public void testStartContainer() throws IOException, InterruptedException {
api().startContainer(container.getId()); api().startContainer(container.id());
assertTrue(api().inspectContainer(container.getId()).getState().isRunning()); assertTrue(api().inspectContainer(container.id()).state().running());
} }
@Test(dependsOnMethods = "testStartContainer") @Test(dependsOnMethods = "testStartContainer")
public void testStopContainer() { public void testStopContainer() {
api().stopContainer(container.getId()); api().stopContainer(container.id());
assertFalse(api().inspectContainer(container.getId()).getState().isRunning()); assertFalse(api().inspectContainer(container.id()).state().running());
} }
@Test(dependsOnMethods = "testStopContainer", expectedExceptions = NullPointerException.class) @Test(dependsOnMethods = "testStopContainer", expectedExceptions = NullPointerException.class)
public void testRemoveContainer() { public void testRemoveContainer() {
api().removeContainer(container.getId()); api().removeContainer(container.id());
assertFalse(api().inspectContainer(container.getId()).getState().isRunning()); assertFalse(api().inspectContainer(container.id()).state().running());
} }
@Test(dependsOnMethods = "testRemoveContainer", expectedExceptions = ResourceNotFoundException.class) @Test(dependsOnMethods = "testRemoveContainer", expectedExceptions = ResourceNotFoundException.class)
public void testDeleteImage() { public void testDeleteImage() {
InputStream deleteImageStream = api().deleteImage(image.getId()); InputStream deleteImageStream = api().deleteImage(image.id());
consumeStream(deleteImageStream, false); consumeStream(deleteImageStream, false);
assertNull(api().inspectImage(image.getId())); assertNull(api().inspectImage(image.id()));
} }
public void testBuildImage() throws IOException, InterruptedException, URISyntaxException { public void testBuildImage() throws IOException, InterruptedException, URISyntaxException {
@ -111,7 +111,7 @@ public class RemoteApiLiveTest extends BaseDockerApiLiveTest {
String rawImageId = Iterables.getLast(Splitter.on("Successfully built ").split(lastStreamedLine)); String rawImageId = Iterables.getLast(Splitter.on("Successfully built ").split(lastStreamedLine));
String imageId = rawImageId.substring(0, 11); String imageId = rawImageId.substring(0, 11);
Image image = api().inspectImage(imageId); Image image = api().inspectImage(imageId);
api().deleteImage(image.getId(), DeleteImageOptions.Builder.force(true)); api().deleteImage(image.id(), DeleteImageOptions.Builder.force(true));
} }
private RemoteApi api() { private RemoteApi api() {

View File

@ -108,11 +108,11 @@ public class RemoteApiMockTest extends BaseDockerMockTest {
Container container = remoteApi.inspectContainer(containerId); Container container = remoteApi.inspectContainer(containerId);
assertRequestHasCommonFields(server.takeRequest(), "/containers/" + containerId + "/json"); assertRequestHasCommonFields(server.takeRequest(), "/containers/" + containerId + "/json");
assertNotNull(container); assertNotNull(container);
assertNotNull(container.getId(), containerId); assertNotNull(container.id(), containerId);
assertNotNull(container.getContainerConfig()); assertNotNull(container.config());
assertNotNull(container.getHostConfig()); assertNotNull(container.hostConfig());
assertEquals(container.getName(), "/tender_lumiere"); assertEquals(container.name(), "/tender_lumiere");
assertEquals(container.getState().isRunning(), true); assertEquals(container.state().running(), true);
} finally { } finally {
api.close(); api.close();
server.shutdown(); server.shutdown();
@ -126,7 +126,7 @@ public class RemoteApiMockTest extends BaseDockerMockTest {
RemoteApi remoteApi = api.getRemoteApi(); RemoteApi remoteApi = api.getRemoteApi();
String containerId = "notExisting"; String containerId = "notExisting";
try { try {
Container container = remoteApi.inspectContainer(containerId); remoteApi.inspectContainer(containerId);
assertRequestHasCommonFields(server.takeRequest(), "/containers/" + containerId + "/json"); assertRequestHasCommonFields(server.takeRequest(), "/containers/" + containerId + "/json");
} finally { } finally {
api.close(); api.close();
@ -145,13 +145,13 @@ public class RemoteApiMockTest extends BaseDockerMockTest {
.attachStderr(true) .attachStderr(true)
.attachStdout(true) .attachStdout(true)
.tty(false) .tty(false)
.imageId("base") .image("base")
.build(); .build();
try { try {
Container container = remoteApi.createContainer("test", containerConfig); Container container = remoteApi.createContainer("test", containerConfig);
assertRequestHasCommonFields(server.takeRequest(), "POST", "/containers/create?name=test"); assertRequestHasCommonFields(server.takeRequest(), "POST", "/containers/create?name=test");
assertNotNull(container); assertNotNull(container);
assertEquals(container.getId(), "c6c74153ae4b1d1633d68890a68d89c40aa5e284a1ea016cbc6ef0e634ee37b2"); assertEquals(container.id(), "c6c74153ae4b1d1633d68890a68d89c40aa5e284a1ea016cbc6ef0e634ee37b2");
} finally { } finally {
api.close(); api.close();
server.shutdown(); server.shutdown();