Skip to content

Commit b44a091

Browse files
author
Marcus Linke
committed
Merge branch 'master' of https://github.com/cdancy/docker-java into cdancy-master
2 parents ab9a242 + 6dd3c76 commit b44a091

File tree

5 files changed

+111
-1
lines changed

5 files changed

+111
-1
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.github.dockerjava.api.model.ExposedPort;
1111
import com.github.dockerjava.api.model.HostConfig;
1212
import com.github.dockerjava.api.model.Link;
13+
import com.github.dockerjava.api.model.LogConfig;
1314
import com.github.dockerjava.api.model.LxcConf;
1415
import com.github.dockerjava.api.model.PortBinding;
1516
import com.github.dockerjava.api.model.Ports;
@@ -88,6 +89,8 @@ public static interface Exec extends DockerCmdSyncExec<CreateContainerCmd, Creat
8889
public Link[] getLinks();
8990

9091
public LxcConf[] getLxcConf();
92+
93+
public LogConfig getLogConfig();
9194

9295
public String getMacAddress();
9396

@@ -224,6 +227,8 @@ public static interface Exec extends DockerCmdSyncExec<CreateContainerCmd, Creat
224227

225228
public CreateContainerCmd withLxcConf(LxcConf... lxcConf);
226229

230+
public CreateContainerCmd withLogConfig(LogConfig logConfig);
231+
227232
public CreateContainerCmd withMemoryLimit(long memoryLimit);
228233

229234
public CreateContainerCmd withMemorySwap(long memorySwap);

src/main/java/com/github/dockerjava/api/model/HostConfig.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public class HostConfig {
1717

1818
@JsonProperty("LxcConf")
1919
private LxcConf[] lxcConf;
20+
21+
@JsonProperty("LogConfig")
22+
private LogConfig logConfig;
2023

2124
@JsonProperty("PortBindings")
2225
private Ports portBindings;
@@ -66,13 +69,14 @@ public class HostConfig {
6669
public HostConfig() {
6770
}
6871

69-
public HostConfig(Bind[] binds, Link[] links, LxcConf[] lxcConf, Ports portBindings, boolean publishAllPorts,
72+
public HostConfig(Bind[] binds, Link[] links, LxcConf[] lxcConf, LogConfig logConfig, Ports portBindings, boolean publishAllPorts,
7073
boolean privileged, boolean readonlyRootfs, String[] dns, String[] dnsSearch, VolumesFrom[] volumesFrom,
7174
String containerIDFile, Capability[] capAdd, Capability[] capDrop, RestartPolicy restartPolicy,
7275
String networkMode, Device[] devices, String[] extraHosts, Ulimit[] ulimits) {
7376
this.binds = new Binds(binds);
7477
this.links = new Links(links);
7578
this.lxcConf = lxcConf;
79+
this.logConfig = logConfig;
7680
this.portBindings = portBindings;
7781
this.publishAllPorts = publishAllPorts;
7882
this.privileged = privileged;
@@ -98,6 +102,11 @@ public Bind[] getBinds() {
98102
public LxcConf[] getLxcConf() {
99103
return lxcConf;
100104
}
105+
106+
@JsonIgnore
107+
public LogConfig getLogConfig() {
108+
return (logConfig == null) ? new LogConfig() : logConfig;
109+
}
101110

102111
public Ports getPortBindings() {
103112
return portBindings;
@@ -177,6 +186,11 @@ public void setLinks(Link... links) {
177186
public void setLxcConf(LxcConf[] lxcConf) {
178187
this.lxcConf = lxcConf;
179188
}
189+
190+
@JsonIgnore
191+
public void setLogConfig(LogConfig logConfig) {
192+
this.logConfig = logConfig;
193+
}
180194

181195
public void setPortBindings(Ports portBindings) {
182196
this.portBindings = portBindings;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.github.dockerjava.api.model;
2+
3+
import java.util.Map;
4+
5+
import com.fasterxml.jackson.annotation.JsonIgnore;
6+
import com.fasterxml.jackson.annotation.JsonProperty;
7+
8+
/**
9+
* Log driver to use for a created/running container. The
10+
* available types are:
11+
*
12+
* json-file (default)
13+
* syslog
14+
* journald
15+
* none
16+
*
17+
* If a driver is specified that is NOT supported,docker
18+
* will default to null. If configs are supplied that are
19+
* not supported by the type docker will ignore them. In most
20+
* cases setting the config option to null will suffice. Consult
21+
* the docker remote API for a more detailed and up-to-date
22+
* explanation of the available types and their options.
23+
*/
24+
public class LogConfig {
25+
26+
@JsonProperty("Type")
27+
public String type;
28+
29+
@JsonProperty("Config")
30+
public Map<String, String> config;
31+
32+
public LogConfig(String type, Map<String, String> config) {
33+
this.type = type;
34+
this.config = config;
35+
}
36+
37+
public LogConfig() {
38+
}
39+
40+
public String getType() {
41+
return type;
42+
}
43+
44+
public LogConfig setType(String type) {
45+
this.type = type;
46+
return this;
47+
}
48+
49+
@JsonIgnore
50+
public Map<String, String> getConfig() {
51+
return config;
52+
}
53+
54+
@JsonIgnore
55+
public LogConfig setConfig(Map<String, String> config) {
56+
this.config = config;
57+
return this;
58+
}
59+
}

src/main/java/com/github/dockerjava/core/command/CreateContainerCmdImpl.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.github.dockerjava.api.model.ExposedPorts;
2020
import com.github.dockerjava.api.model.HostConfig;
2121
import com.github.dockerjava.api.model.Link;
22+
import com.github.dockerjava.api.model.LogConfig;
2223
import com.github.dockerjava.api.model.LxcConf;
2324
import com.github.dockerjava.api.model.PortBinding;
2425
import com.github.dockerjava.api.model.Ports;
@@ -269,6 +270,12 @@ public Map<String, String> getLabels() {
269270
public LxcConf[] getLxcConf() {
270271
return hostConfig.getLxcConf();
271272
}
273+
274+
@Override
275+
@JsonIgnore
276+
public LogConfig getLogConfig() {
277+
return hostConfig.getLogConfig();
278+
}
272279

273280
public String getMacAddress() {
274281
return macAddress;
@@ -558,6 +565,13 @@ public CreateContainerCmd withLxcConf(LxcConf... lxcConf) {
558565
this.hostConfig.setLxcConf(lxcConf);
559566
return this;
560567
}
568+
569+
@Override
570+
public CreateContainerCmd withLogConfig(LogConfig logConfig) {
571+
checkNotNull(logConfig, "logConfig was not specified");
572+
this.hostConfig.setLogConfig(logConfig);
573+
return this;
574+
}
561575

562576
@Override
563577
public CreateContainerCmdImpl withMacAddress(String macAddress) {

src/test/java/com/github/dockerjava/core/command/CreateContainerCmdImplTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import com.github.dockerjava.api.model.ExposedPort;
3939
import com.github.dockerjava.api.model.HostConfig;
4040
import com.github.dockerjava.api.model.Link;
41+
import com.github.dockerjava.api.model.LogConfig;
4142
import com.github.dockerjava.api.model.Ports;
4243
import com.github.dockerjava.api.model.RestartPolicy;
4344
import com.github.dockerjava.api.model.Ulimit;
@@ -534,4 +535,21 @@ public void createContainerWithLabels() throws DockerException {
534535
labels.put("com.github.dockerjava.null", "");
535536
assertThat(inspectContainerResponse.getConfig().getLabels(), is(equalTo(labels)));
536537
}
538+
539+
@Test(groups = "ignoreInCircleCi")
540+
public void createContainerWithLogConfig() throws DockerException {
541+
542+
LogConfig logConfig = new LogConfig("none", null);
543+
CreateContainerResponse container = dockerClient.createContainerCmd("busybox").
544+
withLogConfig(logConfig).exec();
545+
546+
LOG.info("Created container {}", container.toString());
547+
548+
assertThat(container.getId(), not(isEmptyString()));
549+
550+
InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec();
551+
552+
// null becomes empty string
553+
assertEquals(inspectContainerResponse.getHostConfig().getLogConfig().type, logConfig.type);
554+
}
537555
}

0 commit comments

Comments
 (0)