Skip to content

Commit a0a41ab

Browse files
author
Marcus Linke
committed
Merge branch 'merge'
2 parents 933525f + 7e6bfd4 commit a0a41ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2446
-2241
lines changed

.gitattributes

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto
3+
4+
# Unix shell files use Unix line endings
5+
*.sh text eol=lf
6+
7+
# Standard to msysgit
8+
*.doc diff=astextplain
9+
*.DOC diff=astextplain
10+
*.docx diff=astextplain
11+
*.DOCX diff=astextplain
12+
*.dot diff=astextplain
13+
*.DOT diff=astextplain
14+
*.pdf diff=astextplain
15+
*.PDF diff=astextplain
16+
*.rtf diff=astextplain
17+
*.RTF diff=astextplain

src/main/java/com/github/dockerjava/client/DockerClient.java

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import com.sun.jersey.api.client.WebResource;
5555
import com.sun.jersey.api.client.config.ClientConfig;
5656
import com.sun.jersey.api.client.config.DefaultClientConfig;
57-
import com.sun.jersey.api.client.filter.LoggingFilter;
5857
import com.sun.jersey.client.apache4.ApacheHttpClient4;
5958
import com.sun.jersey.client.apache4.ApacheHttpClient4Handler;
6059

@@ -63,7 +62,7 @@
6362
*/
6463
public class DockerClient {
6564

66-
private Client client;
65+
private Client client;
6766
private WebResource baseResource;
6867
private AuthConfig authConfig;
6968

@@ -83,11 +82,8 @@ private static Config configWithServerUrl(String serverUrl)
8382
}
8483

8584
private DockerClient(Config config) {
86-
// restEndpointUrl = config.url + "/v" + config.version;
8785
ClientConfig clientConfig = new DefaultClientConfig();
88-
// clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING,
89-
// Boolean.TRUE);
90-
86+
9187
SchemeRegistry schemeRegistry = new SchemeRegistry();
9288
schemeRegistry.register(new Scheme("http", config.url.getPort(),
9389
PlainSocketFactory.getSocketFactory()));
@@ -106,11 +102,9 @@ private DockerClient(Config config) {
106102
null, false), clientConfig);
107103

108104
client.setReadTimeout(10000);
109-
// Experimental support for unix sockets:
110-
// client = new UnixSocketClient(clientConfig);
111-
105+
112106
client.addFilter(new JsonClientFilter());
113-
client.addFilter(new LoggingFilter());
107+
client.addFilter(new SelectiveLoggingFilter());
114108

115109
baseResource = client.resource(config.url + "/v" + config.version);
116110
}
@@ -202,54 +196,22 @@ public ImportImageCmd importImageCmd(String repository,
202196
.withBaseResource(baseResource);
203197
}
204198

205-
// public ImageCreateResponse importImage(String repository,
206-
// InputStream imageStream) {
207-
// return execute(importImageCmd(repository, imageStream));
208-
// }
209-
210199
public SearchImagesCmd searchImagesCmd(String term) {
211200
return new SearchImagesCmd(term).withBaseResource(baseResource);
212201
}
213202

214-
// public List<SearchItem> searchImages(String term) {
215-
// return execute(searchImagesCmd(term));
216-
// }
217-
218203
public RemoveImageCmd removeImageCmd(String imageId) {
219204
return new RemoveImageCmd(imageId).withBaseResource(baseResource);
220205
}
221206

222-
// /**
223-
// * Remove an image, deleting any tags it might have.
224-
// */
225-
// public void removeImage(String imageId) {
226-
// execute(removeImageCmd(imageId));
227-
// }
228-
//
229-
// public void removeImages(List<String> images) {
230-
// Preconditions.checkNotNull(images, "List of images can't be null");
231-
//
232-
// for (String imageId : images) {
233-
// removeImage(imageId);
234-
// }
235-
// }
236-
237207
public ListImagesCmd listImagesCmd() {
238208
return new ListImagesCmd().withBaseResource(baseResource);
239209
}
240210

241-
// public List<Image> listImages() {
242-
// return execute(listImagesCmd());
243-
// }
244-
245211
public InspectImageCmd inspectImageCmd(String imageId) {
246212
return new InspectImageCmd(imageId).withBaseResource(baseResource);
247213
}
248214

249-
// public ImageInspectResponse inspectImage(String imageId) {
250-
// return execute(inspectImageCmd(imageId));
251-
// }
252-
253215
/**
254216
* * CONTAINER API *
255217
*/
@@ -258,10 +220,6 @@ public ListContainersCmd listContainersCmd() {
258220
return new ListContainersCmd().withBaseResource(baseResource);
259221
}
260222

261-
// public List<Container> listContainers() {
262-
// return execute(listContainersCmd());
263-
// }
264-
265223
public CreateContainerCmd createContainerCmd(String image) {
266224
return new CreateContainerCmd(new CreateContainerConfig()).withImage(
267225
image).withBaseResource(baseResource);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.github.dockerjava.client;
2+
3+
import java.util.Set;
4+
5+
import javax.ws.rs.core.HttpHeaders;
6+
import javax.ws.rs.core.MediaType;
7+
8+
import com.google.common.collect.ImmutableSet;
9+
import com.sun.jersey.api.client.ClientHandlerException;
10+
import com.sun.jersey.api.client.ClientRequest;
11+
import com.sun.jersey.api.client.ClientResponse;
12+
import com.sun.jersey.api.client.filter.LoggingFilter;
13+
14+
/**
15+
* A version of the logging filter that will avoid trying to log entities which can cause
16+
* issues with the console.
17+
*
18+
* @author sfitts
19+
*
20+
*/
21+
public class SelectiveLoggingFilter extends LoggingFilter {
22+
23+
private static final Set<String> SKIPPED_CONTENT = ImmutableSet.<String>builder()
24+
.add(MediaType.APPLICATION_OCTET_STREAM)
25+
.add("application/tar")
26+
.build();
27+
28+
@Override
29+
public ClientResponse handle(ClientRequest request) throws ClientHandlerException {
30+
// Unless the content type is in the list of those we want to ellide, then just have
31+
// our super-class handle things.
32+
Object contentType = request.getHeaders().getFirst(HttpHeaders.CONTENT_TYPE);
33+
if (contentType != null && SKIPPED_CONTENT.contains(contentType.toString())) {
34+
// Skip logging this.
35+
//
36+
// N.B. -- I'd actually love to reproduce (or better yet just use) the logging code from
37+
// our super-class. However, everything is private (so we can't use it) and the code
38+
// is under a modified GPL which means we can't pull it into an ASL project. Right now
39+
// I don't have the energy to do a clean implementation.
40+
return getNext().handle(request);
41+
}
42+
43+
// Do what we normally would
44+
return super.handle(request);
45+
}
46+
47+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package com.github.dockerjava.client.command;
22

3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
36
import com.google.common.base.Preconditions;
47
import com.sun.jersey.api.client.WebResource;
58

69
public abstract class AbstrDockerCmd<T extends AbstrDockerCmd<T, RES_T>, RES_T> implements DockerCmd<RES_T> {
10+
11+
private final static Logger LOGGER = LoggerFactory.getLogger(AbstrDockerCmd.class);
712

813
protected WebResource baseResource;
914

@@ -18,6 +23,7 @@ public T withBaseResource(WebResource baseResource) {
1823
@Override
1924
public RES_T exec() {
2025
Preconditions.checkNotNull(baseResource, "baseResource was not specified");
26+
LOGGER.debug("Cmd: {}", this);
2127
return impl();
2228
}
2329
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@ protected Void impl() throws DockerException {
3434
throw new DockerException(e);
3535
}
3636
}
37+
38+
@Override
39+
public String toString() {
40+
return "authenticate using " + this.authConfig;
41+
}
3742
}

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import javax.ws.rs.core.MultivaluedMap;
1616

1717
import org.apache.commons.io.FileUtils;
18-
import org.apache.commons.lang.StringUtils;
1918
import org.slf4j.Logger;
2019
import org.slf4j.LoggerFactory;
2120

@@ -65,6 +64,15 @@ public BuildImgCmd withNoCache(boolean noCache) {
6564
return this;
6665
}
6766

67+
@Override
68+
public String toString() {
69+
return new StringBuilder("build ")
70+
.append(tag != null ? "-t " + tag + " " : "")
71+
.append(noCache ? "--nocache=true " : "")
72+
.append(dockerFolder != null ? dockerFolder.getPath() : "-")
73+
.toString();
74+
}
75+
6876
protected ClientResponse impl() {
6977
if (tarInputStream == null) {
7078
File dockerFolderTar = buildDockerFolderTar();
@@ -132,7 +140,7 @@ protected File buildDockerFolderTar() {
132140
throw new DockerException(String.format("Wrong format on line [%s]", cmd));
133141
}
134142

135-
String resource = matcher.group(1);
143+
String resource = matcher.group(1).trim();
136144

137145
if(isFileResource(resource)) {
138146
File src = new File(resource);

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,17 @@ public CommitCmd withRun(String run) {
6767
return this;
6868
}
6969

70-
70+
@Override
71+
public String toString() {
72+
return new StringBuilder("commit ")
73+
.append(commitConfig.getAuthor() != null ? "--author " + commitConfig.getAuthor() + " " : "")
74+
.append(commitConfig.getMessage() != null ? "--message " + commitConfig.getMessage() + " " : "")
75+
.append(commitConfig.getContainerId())
76+
.append(commitConfig.getRepo() != null ? " " + commitConfig.getRepo() + ":" : " ")
77+
.append(commitConfig.getTag() != null ? commitConfig.getTag() : "")
78+
.toString();
79+
}
80+
7181
private void checkCommitConfig(CommitConfig commitConfig) {
7282
Preconditions.checkNotNull(commitConfig, "CommitConfig was not specified");
7383
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ public ContainerDiffCmd withContainerId(String containerId) {
3737
return this;
3838
}
3939

40-
protected List<ChangeLog> impl() throws DockerException {
40+
@Override
41+
public String toString() {
42+
return new StringBuilder("diff ")
43+
.append(containerId)
44+
.toString();
45+
}
46+
47+
protected List<ChangeLog> impl() throws DockerException {
4148
WebResource webResource = baseResource.path(String.format("/containers/%s/changes", containerId));
4249

4350
try {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ public CopyFileFromContainerCmd withResource(String resource) {
4040
return this;
4141
}
4242

43+
@Override
44+
public String toString() {
45+
return new StringBuilder("cp ")
46+
.append(containerId)
47+
.append(":")
48+
.append(resource)
49+
.toString();
50+
}
51+
4352
protected ClientResponse impl() throws DockerException {
4453
CopyConfig copyConfig = new CopyConfig();
4554
copyConfig.setResource(resource);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ public CreateContainerCmd withExposedPorts(ExposedPort... exposedPorts) {
7676
return this;
7777
}
7878

79+
@Override
80+
public String toString() {
81+
return new StringBuilder("create container ")
82+
.append(name != null ? "name=" + name + " " : "")
83+
.append(containerCreateConfig)
84+
.toString();
85+
}
86+
7987
protected ContainerCreateResponse impl() {
8088
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
8189
if (name != null) {

0 commit comments

Comments
 (0)