X Tutup
Skip to content

Commit f8e3d3a

Browse files
committed
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.
1 parent 14f911e commit f8e3d3a

File tree

6 files changed

+423
-443
lines changed

6 files changed

+423
-443
lines changed

src/main/java/com/github/dockerjava/client/command/CopyFileFromContainerCmd.java

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
import javax.ws.rs.core.MediaType;
44

5+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
6+
import com.fasterxml.jackson.annotation.JsonProperty;
7+
import org.apache.commons.lang.builder.ToStringBuilder;
58
import org.slf4j.Logger;
69
import org.slf4j.LoggerFactory;
710

811
import com.github.dockerjava.client.DockerException;
9-
import com.github.dockerjava.client.model.CopyConfig;
1012
import com.google.common.base.Preconditions;
1113
import com.sun.jersey.api.client.ClientResponse;
1214
import com.sun.jersey.api.client.UniformInterfaceException;
@@ -82,4 +84,63 @@ protected ClientResponse impl() throws DockerException {
8284
}
8385
}
8486
}
87+
88+
/**
89+
* Configuration object for copy command.
90+
* @author Victor Lyuboslavsky
91+
*/
92+
@JsonIgnoreProperties(ignoreUnknown = true)
93+
private static class CopyConfig {
94+
95+
@JsonProperty("HostPath")
96+
private String hostPath;
97+
98+
@JsonProperty("Resource")
99+
private String resource;
100+
101+
/**
102+
* Constructor.
103+
*/
104+
public CopyConfig() {
105+
hostPath = ".";
106+
}
107+
108+
/**
109+
* Retrieves the 'resource' variable.
110+
* @return the 'resource' variable value
111+
*/
112+
public String getResource() {
113+
return resource;
114+
}
115+
116+
/**
117+
* Sets the 'resource' variable.
118+
* @param resource the new 'resource' variable value to set
119+
*/
120+
public void setResource(String resource) {
121+
this.resource = resource;
122+
}
123+
124+
/**
125+
* Retrieves the 'hostPath' variable.
126+
* @return the 'hostPath' variable value
127+
*/
128+
public String getHostPath() {
129+
return hostPath;
130+
}
131+
132+
/**
133+
* Sets the 'hostPath' variable.
134+
* @param hostPath the new 'hostPath' variable value to set
135+
*/
136+
public void setHostPath(String hostPath) {
137+
this.hostPath = hostPath;
138+
}
139+
140+
@Override
141+
public String toString() {
142+
return ToStringBuilder.reflectionToString(this);
143+
}
144+
145+
}
85146
}

src/main/java/com/github/dockerjava/client/command/CreateContainerCmd.java

Lines changed: 252 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import javax.ws.rs.core.MediaType;
44
import javax.ws.rs.core.MultivaluedMap;
55

6+
import com.fasterxml.jackson.annotation.JsonIgnore;
7+
import com.fasterxml.jackson.annotation.JsonProperty;
8+
import com.github.dockerjava.client.model.*;
9+
import org.apache.commons.lang.builder.ToStringBuilder;
610
import org.slf4j.Logger;
711
import org.slf4j.LoggerFactory;
812

913
import com.github.dockerjava.client.DockerException;
1014
import com.github.dockerjava.client.NotFoundException;
11-
import com.github.dockerjava.client.model.CreateContainerConfig;
12-
import com.github.dockerjava.client.model.ExposedPort;
13-
import com.github.dockerjava.client.model.Volume;
1415
import com.google.common.base.Preconditions;
1516
import com.sun.jersey.api.client.UniformInterfaceException;
1617
import com.sun.jersey.api.client.WebResource;
@@ -35,7 +36,7 @@ public CreateContainerCmd(String image) {
3536
this.containerCreateConfig.withImage(image);
3637
}
3738

38-
public CreateContainerCmd(CreateContainerConfig config) {
39+
private CreateContainerCmd(CreateContainerConfig config) {
3940
Preconditions.checkNotNull(config, "config was not specified");
4041
this.containerCreateConfig = config;
4142
}
@@ -125,4 +126,251 @@ protected CreateContainerResponse impl() {
125126
}
126127
}
127128
}
129+
130+
/**
131+
*
132+
* @author Konstantin Pelykh (kpelykh@gmail.com)
133+
*
134+
* "Hostname":"",
135+
"User":"",
136+
"Memory":0,
137+
"MemorySwap":0,
138+
"AttachStdin":false,
139+
"AttachStdout":true,
140+
"AttachStderr":true,
141+
"PortSpecs":null,
142+
"Tty":false,
143+
"OpenStdin":false,
144+
"StdinOnce":false,
145+
"Env":null,
146+
"Cmd":[
147+
"date"
148+
],
149+
"Dns":null,
150+
"Image":"base",
151+
"Volumes":{
152+
"/tmp": {}
153+
},
154+
"VolumesFrom":"",
155+
"WorkingDir":"",
156+
"DisableNetwork": false,
157+
"ExposedPorts":{
158+
"22/tcp": {}
159+
}
160+
*
161+
*
162+
*/
163+
private static class CreateContainerConfig {
164+
165+
@JsonProperty("Hostname") private String hostName = "";
166+
@JsonProperty("User") private String user = "";
167+
@JsonProperty("Memory") private long memoryLimit = 0;
168+
@JsonProperty("MemorySwap") private long memorySwap = 0;
169+
@JsonProperty("AttachStdin") private boolean attachStdin = false;
170+
@JsonProperty("AttachStdout") private boolean attachStdout = false;
171+
@JsonProperty("AttachStderr") private boolean attachStderr = false;
172+
@JsonProperty("PortSpecs") private String[] portSpecs;
173+
@JsonProperty("Tty") private boolean tty = false;
174+
@JsonProperty("OpenStdin") private boolean stdinOpen = false;
175+
@JsonProperty("StdinOnce") private boolean stdInOnce = false;
176+
@JsonProperty("Env") private String[] env;
177+
@JsonProperty("Cmd") private String[] cmd;
178+
@JsonProperty("Dns") private String[] dns;
179+
@JsonProperty("Image") private String image;
180+
@JsonProperty("Volumes") private Volumes volumes = new Volumes();
181+
@JsonProperty("VolumesFrom") private String[] volumesFrom = new String[]{};
182+
@JsonProperty("WorkingDir") private String workingDir = "";
183+
@JsonProperty("DisableNetwork") private boolean disableNetwork = false;
184+
@JsonProperty("ExposedPorts") private ExposedPorts exposedPorts = new ExposedPorts();
185+
186+
public CreateContainerConfig withExposedPorts(ExposedPort[] exposedPorts) {
187+
this.exposedPorts = new ExposedPorts(exposedPorts);
188+
return this;
189+
}
190+
191+
@JsonIgnore
192+
public ExposedPort[] getExposedPorts() {
193+
return exposedPorts.getExposedPorts();
194+
}
195+
196+
197+
public boolean isDisableNetwork() {
198+
return disableNetwork;
199+
}
200+
201+
public String getWorkingDir() { return workingDir; }
202+
203+
public CreateContainerConfig withWorkingDir(String workingDir) {
204+
this.workingDir = workingDir;
205+
return this;
206+
}
207+
208+
209+
public String getHostName() {
210+
return hostName;
211+
}
212+
213+
public CreateContainerConfig withDisableNetwork(boolean disableNetwork) {
214+
this.disableNetwork = disableNetwork;
215+
return this;
216+
}
217+
218+
public CreateContainerConfig withHostName(String hostName) {
219+
this.hostName = hostName;
220+
return this;
221+
}
222+
223+
public String[] getPortSpecs() {
224+
return portSpecs;
225+
}
226+
227+
public CreateContainerConfig withPortSpecs(String[] portSpecs) {
228+
this.portSpecs = portSpecs;
229+
return this;
230+
}
231+
232+
public String getUser() {
233+
return user;
234+
}
235+
236+
public CreateContainerConfig withUser(String user) {
237+
this.user = user;
238+
return this;
239+
}
240+
241+
public boolean isTty() {
242+
return tty;
243+
}
244+
245+
public CreateContainerConfig withTty(boolean tty) {
246+
this.tty = tty;
247+
return this;
248+
}
249+
250+
public boolean isStdinOpen() {
251+
return stdinOpen;
252+
}
253+
254+
public CreateContainerConfig withStdinOpen(boolean stdinOpen) {
255+
this.stdinOpen = stdinOpen;
256+
return this;
257+
}
258+
259+
public boolean isStdInOnce() {
260+
return stdInOnce;
261+
}
262+
263+
public CreateContainerConfig withStdInOnce(boolean stdInOnce) {
264+
this.stdInOnce = stdInOnce;
265+
return this;
266+
}
267+
268+
public long getMemoryLimit() {
269+
return memoryLimit;
270+
}
271+
272+
public CreateContainerConfig withMemoryLimit(long memoryLimit) {
273+
this.memoryLimit = memoryLimit;
274+
return this;
275+
}
276+
277+
public long getMemorySwap() {
278+
return memorySwap;
279+
}
280+
281+
public CreateContainerConfig withMemorySwap(long memorySwap) {
282+
this.memorySwap = memorySwap;
283+
return this;
284+
}
285+
286+
287+
public boolean isAttachStdin() {
288+
return attachStdin;
289+
}
290+
291+
public CreateContainerConfig withAttachStdin(boolean attachStdin) {
292+
this.attachStdin = attachStdin;
293+
return this;
294+
}
295+
296+
public boolean isAttachStdout() {
297+
return attachStdout;
298+
}
299+
300+
public CreateContainerConfig withAttachStdout(boolean attachStdout) {
301+
this.attachStdout = attachStdout;
302+
return this;
303+
}
304+
305+
public boolean isAttachStderr() {
306+
return attachStderr;
307+
}
308+
309+
public CreateContainerConfig withAttachStderr(boolean attachStderr) {
310+
this.attachStderr = attachStderr;
311+
return this;
312+
}
313+
314+
public String[] getEnv() {
315+
return env;
316+
}
317+
318+
public CreateContainerConfig withEnv(String[] env) {
319+
this.env = env;
320+
return this;
321+
}
322+
323+
public String[] getCmd() {
324+
return cmd;
325+
}
326+
327+
public CreateContainerConfig withCmd(String[] cmd) {
328+
this.cmd = cmd;
329+
return this;
330+
}
331+
332+
public String[] getDns() {
333+
return dns;
334+
}
335+
336+
public CreateContainerConfig withDns(String[] dns) {
337+
this.dns = dns;
338+
return this;
339+
}
340+
341+
public String getImage() {
342+
return image;
343+
}
344+
345+
public CreateContainerConfig withImage(String image) {
346+
this.image = image;
347+
return this;
348+
}
349+
350+
@JsonIgnore
351+
public Volume[] getVolumes() {
352+
return volumes.getVolumes();
353+
}
354+
355+
public CreateContainerConfig withVolumes(Volume[] volumes) {
356+
this.volumes = new Volumes(volumes);
357+
return this;
358+
}
359+
360+
public String[] getVolumesFrom() {
361+
return volumesFrom;
362+
}
363+
364+
public CreateContainerConfig withVolumesFrom(String[] volumesFrom) {
365+
this.volumesFrom = volumesFrom;
366+
return this;
367+
}
368+
369+
@Override
370+
public String toString() {
371+
return ToStringBuilder.reflectionToString(this);
372+
}
373+
374+
375+
}
128376
}

0 commit comments

Comments
 (0)
X Tutup