X Tutup
Skip to content

Commit 8466344

Browse files
committed
Merge pull request #9 from getvictor/master
Fixes for HostConfig and LxcConf. Added DockerClient.logContainerStream method.
2 parents 914777f + f8edfff commit 8466344

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

src/main/java/com/kpelykh/docker/client/DockerClient.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.kpelykh.docker.client.utils.CompressArchiveUtil;
66
import com.kpelykh.docker.client.utils.JsonClientFilter;
77
import com.sun.jersey.api.client.*;
8+
import com.sun.jersey.api.client.WebResource.Builder;
89
import com.sun.jersey.api.client.config.ClientConfig;
910
import com.sun.jersey.api.client.config.DefaultClientConfig;
1011
import com.sun.jersey.api.json.JSONConfiguration;
@@ -343,7 +344,12 @@ public void startContainer(String containerId, HostConfig hostConfig) throws Doc
343344

344345
try {
345346
LOGGER.trace("POST: " + webResource.toString());
346-
webResource.accept(MediaType.TEXT_PLAIN).post(hostConfig);
347+
Builder builder = webResource.accept(MediaType.TEXT_PLAIN);
348+
if (hostConfig != null) {
349+
builder.type(MediaType.APPLICATION_JSON).post(hostConfig);
350+
} else {
351+
builder.post((HostConfig) null);
352+
}
347353
} catch (UniformInterfaceException exception) {
348354
if (exception.getResponse().getStatus() == 404) {
349355
throw new DockerException(String.format("No such container %s", containerId));
@@ -437,11 +443,21 @@ public int waitContainer(String containerId) throws DockerException {
437443

438444

439445
public ClientResponse logContainer(String containerId) throws DockerException {
446+
return logContainer(containerId, false);
447+
}
448+
449+
public ClientResponse logContainerStream(String containerId) throws DockerException {
450+
return logContainer(containerId, true);
451+
}
452+
453+
private ClientResponse logContainer(String containerId, boolean stream) throws DockerException {
440454
MultivaluedMap<String,String> params = new MultivaluedMapImpl();
441455
params.add("logs", "1");
442456
params.add("stdout", "1");
443457
params.add("stderr", "1");
444-
//params.add("stream", "1"); this parameter keeps stream open indindefinitely
458+
if (stream) {
459+
params.add("stream", "1"); // this parameter keeps stream open indefinitely
460+
}
445461

446462
WebResource webResource = client.resource(restEndpointUrl + String.format("/containers/%s/attach", containerId))
447463
.queryParams(params);

src/main/java/com/kpelykh/docker/client/model/HostConfig.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class HostConfig {
1616
public String containerIDFile;
1717

1818
@JsonProperty("LxcConf")
19-
public String[] lxcConf = new String[]{};
19+
public LxcConf[] lxcConf;
2020

2121
public HostConfig(String[] binds) {
2222
this.binds = binds;
@@ -38,11 +38,36 @@ public void setContainerIDFile(String containerIDFile) {
3838
this.containerIDFile = containerIDFile;
3939
}
4040

41-
public String[] getLxcConf() {
41+
public LxcConf[] getLxcConf() {
4242
return lxcConf;
4343
}
4444

45-
public void setLxcConf(String[] lxcConf) {
45+
public void setLxcConf(LxcConf[] lxcConf) {
4646
this.lxcConf = lxcConf;
4747
}
48+
49+
public class LxcConf {
50+
@JsonProperty("Key")
51+
public String key;
52+
53+
@JsonProperty("Value")
54+
public String value;
55+
56+
public String getKey() {
57+
return key;
58+
}
59+
60+
public void setKey(String key) {
61+
this.key = key;
62+
}
63+
64+
public String getValue() {
65+
return value;
66+
}
67+
68+
public void setValue(String value) {
69+
this.value = value;
70+
}
71+
72+
}
4873
}

0 commit comments

Comments
 (0)
X Tutup