33import javax .ws .rs .core .MediaType ;
44import 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 ;
610import org .slf4j .Logger ;
711import org .slf4j .LoggerFactory ;
812
913import com .github .dockerjava .client .DockerException ;
1014import 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 ;
1415import com .google .common .base .Preconditions ;
1516import com .sun .jersey .api .client .UniformInterfaceException ;
1617import 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