Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Moves more Config objects into their assoc Cmds
This effectively hides the config objects from the public API, as I
expect they'll either go away or get simplified.
  • Loading branch information
mfulgo committed Aug 1, 2014
commit f8e3d3ad5847eae79367ec0ff5435c91d1b26318
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import javax.ws.rs.core.MediaType;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.dockerjava.client.DockerException;
import com.github.dockerjava.client.model.CopyConfig;
import com.google.common.base.Preconditions;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.UniformInterfaceException;
Expand Down Expand Up @@ -82,4 +84,63 @@ protected ClientResponse impl() throws DockerException {
}
}
}

/**
* Configuration object for copy command.
* @author Victor Lyuboslavsky
*/
@JsonIgnoreProperties(ignoreUnknown = true)
private static class CopyConfig {

@JsonProperty("HostPath")
private String hostPath;

@JsonProperty("Resource")
private String resource;

/**
* Constructor.
*/
public CopyConfig() {
hostPath = ".";
}

/**
* Retrieves the 'resource' variable.
* @return the 'resource' variable value
*/
public String getResource() {
return resource;
}

/**
* Sets the 'resource' variable.
* @param resource the new 'resource' variable value to set
*/
public void setResource(String resource) {
this.resource = resource;
}

/**
* Retrieves the 'hostPath' variable.
* @return the 'hostPath' variable value
*/
public String getHostPath() {
return hostPath;
}

/**
* Sets the 'hostPath' variable.
* @param hostPath the new 'hostPath' variable value to set
*/
public void setHostPath(String hostPath) {
this.hostPath = hostPath;
}

@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.dockerjava.client.model.*;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.dockerjava.client.DockerException;
import com.github.dockerjava.client.NotFoundException;
import com.github.dockerjava.client.model.CreateContainerConfig;
import com.github.dockerjava.client.model.ExposedPort;
import com.github.dockerjava.client.model.Volume;
import com.google.common.base.Preconditions;
import com.sun.jersey.api.client.UniformInterfaceException;
import com.sun.jersey.api.client.WebResource;
Expand All @@ -35,7 +36,7 @@ public CreateContainerCmd(String image) {
this.containerCreateConfig.withImage(image);
}

public CreateContainerCmd(CreateContainerConfig config) {
private CreateContainerCmd(CreateContainerConfig config) {
Preconditions.checkNotNull(config, "config was not specified");
this.containerCreateConfig = config;
}
Expand Down Expand Up @@ -125,4 +126,251 @@ protected CreateContainerResponse impl() {
}
}
}

/**
*
* @author Konstantin Pelykh (kpelykh@gmail.com)
*
* "Hostname":"",
"User":"",
"Memory":0,
"MemorySwap":0,
"AttachStdin":false,
"AttachStdout":true,
"AttachStderr":true,
"PortSpecs":null,
"Tty":false,
"OpenStdin":false,
"StdinOnce":false,
"Env":null,
"Cmd":[
"date"
],
"Dns":null,
"Image":"base",
"Volumes":{
"/tmp": {}
},
"VolumesFrom":"",
"WorkingDir":"",
"DisableNetwork": false,
"ExposedPorts":{
"22/tcp": {}
}
*
*
*/
private static class CreateContainerConfig {

@JsonProperty("Hostname") private String hostName = "";
@JsonProperty("User") private String user = "";
@JsonProperty("Memory") private long memoryLimit = 0;
@JsonProperty("MemorySwap") private long memorySwap = 0;
@JsonProperty("AttachStdin") private boolean attachStdin = false;
@JsonProperty("AttachStdout") private boolean attachStdout = false;
@JsonProperty("AttachStderr") private boolean attachStderr = false;
@JsonProperty("PortSpecs") private String[] portSpecs;
@JsonProperty("Tty") private boolean tty = false;
@JsonProperty("OpenStdin") private boolean stdinOpen = false;
@JsonProperty("StdinOnce") private boolean stdInOnce = false;
@JsonProperty("Env") private String[] env;
@JsonProperty("Cmd") private String[] cmd;
@JsonProperty("Dns") private String[] dns;
@JsonProperty("Image") private String image;
@JsonProperty("Volumes") private Volumes volumes = new Volumes();
@JsonProperty("VolumesFrom") private String[] volumesFrom = new String[]{};
@JsonProperty("WorkingDir") private String workingDir = "";
@JsonProperty("DisableNetwork") private boolean disableNetwork = false;
@JsonProperty("ExposedPorts") private ExposedPorts exposedPorts = new ExposedPorts();

public CreateContainerConfig withExposedPorts(ExposedPort[] exposedPorts) {
this.exposedPorts = new ExposedPorts(exposedPorts);
return this;
}

@JsonIgnore
public ExposedPort[] getExposedPorts() {
return exposedPorts.getExposedPorts();
}


public boolean isDisableNetwork() {
return disableNetwork;
}

public String getWorkingDir() { return workingDir; }

public CreateContainerConfig withWorkingDir(String workingDir) {
this.workingDir = workingDir;
return this;
}


public String getHostName() {
return hostName;
}

public CreateContainerConfig withDisableNetwork(boolean disableNetwork) {
this.disableNetwork = disableNetwork;
return this;
}

public CreateContainerConfig withHostName(String hostName) {
this.hostName = hostName;
return this;
}

public String[] getPortSpecs() {
return portSpecs;
}

public CreateContainerConfig withPortSpecs(String[] portSpecs) {
this.portSpecs = portSpecs;
return this;
}

public String getUser() {
return user;
}

public CreateContainerConfig withUser(String user) {
this.user = user;
return this;
}

public boolean isTty() {
return tty;
}

public CreateContainerConfig withTty(boolean tty) {
this.tty = tty;
return this;
}

public boolean isStdinOpen() {
return stdinOpen;
}

public CreateContainerConfig withStdinOpen(boolean stdinOpen) {
this.stdinOpen = stdinOpen;
return this;
}

public boolean isStdInOnce() {
return stdInOnce;
}

public CreateContainerConfig withStdInOnce(boolean stdInOnce) {
this.stdInOnce = stdInOnce;
return this;
}

public long getMemoryLimit() {
return memoryLimit;
}

public CreateContainerConfig withMemoryLimit(long memoryLimit) {
this.memoryLimit = memoryLimit;
return this;
}

public long getMemorySwap() {
return memorySwap;
}

public CreateContainerConfig withMemorySwap(long memorySwap) {
this.memorySwap = memorySwap;
return this;
}


public boolean isAttachStdin() {
return attachStdin;
}

public CreateContainerConfig withAttachStdin(boolean attachStdin) {
this.attachStdin = attachStdin;
return this;
}

public boolean isAttachStdout() {
return attachStdout;
}

public CreateContainerConfig withAttachStdout(boolean attachStdout) {
this.attachStdout = attachStdout;
return this;
}

public boolean isAttachStderr() {
return attachStderr;
}

public CreateContainerConfig withAttachStderr(boolean attachStderr) {
this.attachStderr = attachStderr;
return this;
}

public String[] getEnv() {
return env;
}

public CreateContainerConfig withEnv(String[] env) {
this.env = env;
return this;
}

public String[] getCmd() {
return cmd;
}

public CreateContainerConfig withCmd(String[] cmd) {
this.cmd = cmd;
return this;
}

public String[] getDns() {
return dns;
}

public CreateContainerConfig withDns(String[] dns) {
this.dns = dns;
return this;
}

public String getImage() {
return image;
}

public CreateContainerConfig withImage(String image) {
this.image = image;
return this;
}

@JsonIgnore
public Volume[] getVolumes() {
return volumes.getVolumes();
}

public CreateContainerConfig withVolumes(Volume[] volumes) {
this.volumes = new Volumes(volumes);
return this;
}

public String[] getVolumesFrom() {
return volumesFrom;
}

public CreateContainerConfig withVolumesFrom(String[] volumesFrom) {
this.volumesFrom = volumesFrom;
return this;
}

@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}


}
}
Loading