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>
<version>1.5</version>
</dependency>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>1.0-rc2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.jclouds.driver</groupId>
<artifactId>jclouds-sshj</artifactId>

View File

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

View File

@ -44,7 +44,7 @@ public class ImageToImage implements Function<org.jclouds.docker.domain.Image, o
@Override
public Image apply(org.jclouds.docker.domain.Image from) {
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);
String osVersion = parseVersion(description);
@ -57,7 +57,7 @@ public class ImageToImage implements Function<org.jclouds.docker.domain.Image, o
.build();
return new ImageBuilder()
.ids(from.getId())
.ids(from.id())
.name(get(Splitter.on(":").split(description), 0))
.description(description)
.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) {
if (inspectedImage.getArchitecture() == null) return true;
return inspectedImage.getArchitecture().matches("x86_64|amd64");
if (inspectedImage.architecture() == null) return true;
return inspectedImage.architecture().matches("x86_64|amd64");
}
/**

View File

@ -32,7 +32,7 @@ public class StateToStatus implements Function<State, Status> {
@Override
public Status apply(final State state) {
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()
.imageId(imageId)
.image(imageId)
.exposedPorts(exposedPorts);
if (templateOptions.getCommands().isPresent()) {
@ -123,7 +123,7 @@ public class DockerComputeServiceAdapter implements
logger.debug(">> creating new container with containerConfig(%s)", 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()
.publishAllPorts(true)
@ -140,13 +140,13 @@ public class DockerComputeServiceAdapter implements
}
HostConfig hostConfig = hostConfigBuilder.build();
api.getRemoteApi().startContainer(container.getId(), hostConfig);
container = api.getRemoteApi().inspectContainer(container.getId());
if (container.getState().getExitCode() != 0) {
destroyNode(container.getId());
throw new IllegalStateException(String.format("Container %s has not started correctly", container.getId()));
api.getRemoteApi().startContainer(container.id(), hostConfig);
container = api.getRemoteApi().inspectContainer(container.id());
if (container.state().exitCode() != 0) {
destroyNode(container.id());
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());
}
@ -166,9 +166,11 @@ public class DockerComputeServiceAdapter implements
Set<Image> images = Sets.newHashSet();
for (Image image : api.getRemoteApi().listImages()) {
// less efficient than just listImages but returns richer json that needs repoTags coming from listImages
Image inspected = api.getRemoteApi().inspectImage(image.getId());
if (inspected.getRepoTags().isEmpty()) {
inspected = Image.builder().fromImage(inspected).repoTags(image.getRepoTags()).build();
Image inspected = api.getRemoteApi().inspectImage(image.id());
if (inspected.repoTags().isEmpty()) {
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);
}
@ -182,7 +184,7 @@ public class DockerComputeServiceAdapter implements
@Override
public boolean apply(Image input) {
return input.getId().equals(imageId);
return input.id().equals(imageId);
}
}, null);
}
@ -192,7 +194,7 @@ public class DockerComputeServiceAdapter implements
Set<Container> containers = Sets.newHashSet();
for (Container container : api.getRemoteApi().listContainers(ListContainerOptions.Builder.all(true))) {
// 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;
}

View File

@ -16,47 +16,35 @@
*/
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.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 java.lang.reflect.Field;
import org.jclouds.json.config.GsonModule;
import javax.inject.Singleton;
import java.lang.reflect.Type;
import java.util.Map;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.FieldNamingStrategy;
import com.google.inject.AbstractModule;
public class DockerParserModule extends AbstractModule {
@Override
protected void configure() {
@Override protected void configure() {
bind(FieldNamingStrategy.class).toInstance(FIELD_NAMING_STRATEGY);
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())
.build();
}
/** When serializing, Most fields are UpperCamelCase, with some exceptions. */
private static final FieldNamingStrategy FIELD_NAMING_STRATEGY = new FieldNamingStrategy() {
private final FieldNamingStrategy delegate = FieldNamingPolicy.UPPER_CAMEL_CASE;
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();
return gson.fromJson(jsonObject, Container.class);
@Override public String translateName(Field f) {
String result = delegate.translateName(f);
// IP not Ip as code wins over docs https://github.com/docker/docker/blob/master/daemon/network_settings.go
if (result.equals("IpAddress")) {
return "IPAddress";
} else if (result.equals("IpPrefixLen")) {
return "IPPrefixLen";
} else if (result.equals("Ip")) {
return "IP";
}
return result;
}
}
};
}

View File

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

View File

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

View File

@ -16,91 +16,22 @@
*/
package org.jclouds.docker.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.util.Set;
import static org.jclouds.docker.internal.NullSafeCopies.copyOf;
import org.jclouds.javax.annotation.Nullable;
import java.util.List;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import com.google.gson.annotations.SerializedName;
import org.jclouds.json.SerializedNames;
public class ExposedPorts {
import com.google.auto.value.AutoValue;
@SerializedName("PortAndProtocol")
private final String portAndProtocol;
@SerializedName("HostPorts")
private final Set<String> hostPorts;
@AutoValue
public abstract class ExposedPorts {
public abstract String portAndProtocol();
@ConstructorProperties({ "PortAndProtocol", "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 abstract List<String> hostPorts();
public String getPortAndProtocol() {
return portAndProtocol;
}
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());
}
@SerializedNames({ "PortAndProtocol", "HostPorts" })
public static ExposedPorts create(String portAndProtocol, List<String> hostPorts) {
return new AutoValue_ExposedPorts(portAndProtocol, copyOf(hostPorts));
}
}

View File

@ -17,136 +17,47 @@
package org.jclouds.docker.domain;
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.Map;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.auto.value.AutoValue;
import com.google.common.collect.Lists;
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")
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;
public abstract List<String> binds();
@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" })
protected HostConfig(@Nullable String containerIDFile, @Nullable List<String> binds,
Map<String, String> lxcConf, boolean privileged, @Nullable String dns,
@Nullable String dnsSearch, @Nullable Map<String, List<Map<String, String>>> portBindings,
@Nullable List<String> links, boolean publishAllPorts, @Nullable List<String> volumesFrom) {
this.containerIDFile = containerIDFile;
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 HostConfig create(String containerIDFile, List<String> binds, Map<String, String> lxcConf,
boolean privileged, String dns, String dnsSearch, Map<String, List<Map<String, String>>> portBindings,
List<String> links, boolean publishAllPorts, List<String> volumesFrom) {
return new AutoValue_HostConfig(containerIDFile, copyOf(binds), copyOf(lxcConf), privileged, dns, dnsSearch,
copyOf(portBindings), copyOf(links), publishAllPorts, copyOf(volumesFrom));
}
public static Builder builder() {
@ -221,22 +132,14 @@ public class HostConfig {
}
public HostConfig build() {
return new HostConfig(containerIDFile, binds, lxcConf, privileged, dns, dnsSearch, portBindings, links,
publishAllPorts, volumesFrom);
return HostConfig.create(containerIDFile, binds, lxcConf, privileged, dns, dnsSearch, portBindings, links,
publishAllPorts, volumesFrom);
}
public Builder fromHostConfig(HostConfig in) {
return this
.containerIDFile(in.getContainerIDFile())
.binds(in.getBinds())
.lxcConf(in.getLxcConf())
.privileged(in.isPrivileged())
.dns(in.getDns())
.dnsSearch(in.getDnsSearch())
.links(in.getLinks())
.portBindings(in.getPortBindings())
.publishAllPorts(in.isPublishAllPorts())
.volumesFrom(in.getVolumesFrom());
return this.containerIDFile(in.containerIDFile()).binds(in.binds()).lxcConf(in.lxcConf())
.privileged(in.privileged()).dns(in.dns()).dnsSearch(in.dnsSearch()).links(in.links())
.portBindings(in.portBindings()).publishAllPorts(in.publishAllPorts()).volumesFrom(in.volumesFrom());
}
}
}

View File

@ -16,224 +16,42 @@
*/
package org.jclouds.docker.domain;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import com.google.gson.annotations.SerializedName;
import org.jclouds.javax.annotation.Nullable;
import static org.jclouds.docker.internal.NullSafeCopies.copyOf;
import java.beans.ConstructorProperties;
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")
private final String id;
@SerializedName("Parent")
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;
@AutoValue
public abstract class Image {
public abstract String id();
@ConstructorProperties({ "Id", "Parent", "Created", "Container", "DockerVersion", "Architecture", "Os", "Size",
"VirtualSize", "RepoTags", "Architecture" })
protected Image(String id, @Nullable String parent, @Nullable String created, @Nullable String container,
@Nullable String dockerVersion, @Nullable String architecture, @Nullable String os, long size,
@Nullable long virtualSize, @Nullable List<String> repoTags) {
this.id = checkNotNull(id, "id");
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();
}
@Nullable public abstract String parent();
public String getId() {
return id;
}
@Nullable public abstract String created();
public String getParent() {
return parent;
}
@Nullable public abstract String container();
public String getCreated() {
return created;
}
@Nullable public abstract String dockerVersion();
public String getContainer() {
return container;
}
@Nullable public abstract String architecture();
public String getDockerVersion() {
return dockerVersion;
}
@Nullable public abstract String os();
public String getArchitecture() {
return architecture;
}
public abstract long size();
public String getOs() {
return os;
}
@Nullable public abstract long virtualSize();
public long getSize() {
return size;
}
public abstract List<String> repoTags();
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());
}
@SerializedNames({ "Id", "Parent", "Created", "Container", "DockerVersion", "Architecture", "Os", "Size",
"VirtualSize", "RepoTags", "Architecture" })
public static Image create(String id, String parent, String created, String container, String dockerVersion,
String architecture, String os, long size, long virtualSize, List<String> repoTags) {
return new AutoValue_Image(id, parent, created, container, dockerVersion, architecture, os, size, virtualSize,
copyOf(repoTags));
}
}

View File

@ -16,97 +16,36 @@
*/
package org.jclouds.docker.domain;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableMap;
import com.google.gson.annotations.SerializedName;
import org.jclouds.javax.annotation.Nullable;
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.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")
private final String ipAddress;
@SerializedName("IPPrefixLen")
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;
@AutoValue
public abstract class NetworkSettings {
public abstract String ipAddress();
@ConstructorProperties({ "IPAddress", "IPPrefixLen", "Gateway", "Bridge", "PortMapping", "Ports" })
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 abstract int ipPrefixLen();
public String getIpAddress() {
return ipAddress;
}
public abstract String gateway();
public int getIpPrefixLen() {
return ipPrefixLen;
}
public abstract String bridge();
public String getGateway() {
return gateway;
}
@Nullable public abstract String portMapping();
public String getBridge() {
return bridge;
}
public abstract Map<String, List<Map<String, String>>> ports();
public String getPortMapping() {
return portMapping;
}
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();
@SerializedNames({ "IPAddress", "IPPrefixLen", "Gateway", "Bridge", "PortMapping", "Ports" })
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 static Builder builder() {
@ -157,19 +96,13 @@ public class NetworkSettings {
}
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) {
return this
.ipAddress(in.getIpAddress())
.ipPrefixLen(in.getIpPrefixLen())
.gateway(in.getGateway())
.bridge(in.getBridge())
.portMapping(in.getPortMapping())
.ports(in.getPorts());
return this.ipAddress(in.ipAddress()).ipPrefixLen(in.ipPrefixLen()).gateway(in.gateway()).bridge(in.bridge())
.portMapping(in.portMapping()).ports(in.ports());
}
}
}

View File

@ -16,73 +16,22 @@
*/
package org.jclouds.docker.domain;
import com.google.common.base.Objects;
import com.google.gson.annotations.SerializedName;
import org.jclouds.json.SerializedNames;
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")
private final int privatePort;
@SerializedName("PublicPort")
private final int publicPort;
@SerializedName("Type")
private final String type;
@SerializedName("IP")
private final String ip;
public abstract int publicPort();
@ConstructorProperties({ "PrivatePort", "PublicPort", "Type", "IP" })
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 abstract String type();
public int getPrivatePort() {
return privatePort;
}
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();
@SerializedNames({ "IP", "PrivatePort", "PublicPort", "Type" })
public static Port create(String ip, int privatePort, int publicPort, String type) {
return new AutoValue_Port(ip, privatePort, publicPort, type);
}
}

View File

@ -16,151 +16,27 @@
*/
package org.jclouds.docker.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import org.jclouds.json.SerializedNames;
import com.google.common.base.Objects;
import com.google.gson.annotations.SerializedName;
import com.google.auto.value.AutoValue;
public class State {
@SerializedName("Pid")
private final 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;
@AutoValue
public abstract class State {
public abstract int pid();
@ConstructorProperties({ "Pid", "Running", "ExitCode", "StartedAt", "FinishedAt", "Ghost" })
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 abstract boolean running();
public int getPid() {
return pid;
}
public abstract int exitCode();
public boolean isRunning() {
return running;
}
public abstract String startedAt();
public int getExitCode() {
return exitCode;
}
public abstract String finishedAt();
public String getStartedAt() {
return startedAt;
}
public abstract boolean ghost();
public String getFinishedAt() {
return finishedAt;
}
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());
}
@SerializedNames({ "Pid", "Running", "ExitCode", "StartedAt", "FinishedAt", "Ghost" })
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);
}
}

View File

@ -16,151 +16,27 @@
*/
package org.jclouds.docker.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import org.jclouds.json.SerializedNames;
import com.google.common.base.Objects;
import com.google.gson.annotations.SerializedName;
import com.google.auto.value.AutoValue;
public class Version {
@SerializedName("Arch")
private final 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;
@AutoValue
public abstract class Version {
public abstract String arch();
@ConstructorProperties({ "Arch", "GitCommit", "GoVersion", "KernelVersion", "Os", "Version" })
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 abstract String gitCommit();
public String getArch() {
return arch;
}
public abstract String goVersion();
public String getGitCommit() {
return gitCommit;
}
public abstract String kernelVersion();
public String getGoVersion() {
return goVersion;
}
public abstract String os();
public String getKernelVersion() {
return kernelVersion;
}
public abstract String version();
public String getOs() {
return os;
}
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());
}
@SerializedNames({ "Arch", "GitCommit", "GoVersion", "KernelVersion", "Os", "Version" })
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);
}
}

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

View File

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

View File

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

View File

@ -16,37 +16,46 @@
*/
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.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.
*/
@Test(groups = "unit", testName = "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() {
Container container = gson.fromJson(
"{ \"Volumes\": null }", Container.class);
Container container = json.fromJson("{ \"Id\": \"foo\", \"Volumes\": null }", Container.class);
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
public void testVersion() {
assertEquals(api().getVersion().getVersion(), "1.0.0");
assertEquals(api().getVersion().version(), "1.0.0");
}
@Test(dependsOnMethods = "testVersion")
@ -69,37 +69,37 @@ public class RemoteApiLiveTest extends BaseDockerApiLiveTest {
@Test(dependsOnMethods = "testListImages")
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"))
.build();
container = api().createContainer("testCreateContainer", containerConfig);
assertNotNull(container);
assertNotNull(container.getId());
assertNotNull(container.id());
}
@Test(dependsOnMethods = "testCreateContainer")
public void testStartContainer() throws IOException, InterruptedException {
api().startContainer(container.getId());
assertTrue(api().inspectContainer(container.getId()).getState().isRunning());
api().startContainer(container.id());
assertTrue(api().inspectContainer(container.id()).state().running());
}
@Test(dependsOnMethods = "testStartContainer")
public void testStopContainer() {
api().stopContainer(container.getId());
assertFalse(api().inspectContainer(container.getId()).getState().isRunning());
api().stopContainer(container.id());
assertFalse(api().inspectContainer(container.id()).state().running());
}
@Test(dependsOnMethods = "testStopContainer", expectedExceptions = NullPointerException.class)
public void testRemoveContainer() {
api().removeContainer(container.getId());
assertFalse(api().inspectContainer(container.getId()).getState().isRunning());
api().removeContainer(container.id());
assertFalse(api().inspectContainer(container.id()).state().running());
}
@Test(dependsOnMethods = "testRemoveContainer", expectedExceptions = ResourceNotFoundException.class)
public void testDeleteImage() {
InputStream deleteImageStream = api().deleteImage(image.getId());
InputStream deleteImageStream = api().deleteImage(image.id());
consumeStream(deleteImageStream, false);
assertNull(api().inspectImage(image.getId()));
assertNull(api().inspectImage(image.id()));
}
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 imageId = rawImageId.substring(0, 11);
Image image = api().inspectImage(imageId);
api().deleteImage(image.getId(), DeleteImageOptions.Builder.force(true));
api().deleteImage(image.id(), DeleteImageOptions.Builder.force(true));
}
private RemoteApi api() {

View File

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