Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Auto detect text files and perform LF normalization
* text=auto

# Unix shell files use Unix line endings
*.sh text eol=lf

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
5 changes: 2 additions & 3 deletions src/main/java/com/github/dockerjava/client/DockerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.client.filter.LoggingFilter;
import com.sun.jersey.client.apache4.ApacheHttpClient4;
import com.sun.jersey.client.apache4.ApacheHttpClient4Handler;

Expand All @@ -63,7 +62,7 @@
*/
public class DockerClient {

private Client client;
private Client client;
private WebResource baseResource;
private AuthConfig authConfig;

Expand Down Expand Up @@ -110,7 +109,7 @@ private DockerClient(Config config) {
// client = new UnixSocketClient(clientConfig);

client.addFilter(new JsonClientFilter());
client.addFilter(new LoggingFilter());
client.addFilter(new SelectiveLoggingFilter());

baseResource = client.resource(config.url + "/v" + config.version);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.github.dockerjava.client;

import java.util.Set;

import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;

import com.google.common.collect.ImmutableSet;
import com.sun.jersey.api.client.ClientHandlerException;
import com.sun.jersey.api.client.ClientRequest;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.filter.LoggingFilter;

/**
* A version of the logging filter that will avoid trying to log entities which can cause
* issues with the console.
*
* @author sfitts
*
*/
public class SelectiveLoggingFilter extends LoggingFilter {

private static final Set<String> SKIPPED_CONTENT = ImmutableSet.<String>builder()
.add(MediaType.APPLICATION_OCTET_STREAM)
.add("application/tar")
.build();

@Override
public ClientResponse handle(ClientRequest request) throws ClientHandlerException {
// Unless the content type is in the list of those we want to ellide, then just have
// our super-class handle things.
Object contentType = request.getHeaders().getFirst(HttpHeaders.CONTENT_TYPE);
if (contentType != null && SKIPPED_CONTENT.contains(contentType.toString())) {
// Skip logging this.
//
// N.B. -- I'd actually love to reproduce (or better yet just use) the logging code from
// our super-class. However, everything is private (so we can't use it) and the code
// is under a modified GPL which means we can't pull it into an ASL project. Right now
// I don't have the energy to do a clean implementation.
return getNext().handle(request);
}

// Do what we normally would
return super.handle(request);
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.github.dockerjava.client.command;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Preconditions;
import com.sun.jersey.api.client.WebResource;

public abstract class AbstrDockerCmd<T extends AbstrDockerCmd<T, RES_T>, RES_T> implements DockerCmd<RES_T> {

private final static Logger LOGGER = LoggerFactory.getLogger(AbstrDockerCmd.class);

protected WebResource baseResource;

Expand All @@ -18,6 +23,7 @@ public T withBaseResource(WebResource baseResource) {
@Override
public RES_T exec() {
Preconditions.checkNotNull(baseResource, "baseResource was not specified");
LOGGER.debug("Cmd: {}", this);
return impl();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ protected Void impl() throws DockerException {
throw new DockerException(e);
}
}

@Override
public String toString() {
return "authenticate using " + this.authConfig;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ public BuildImgCmd withNoCache(boolean noCache) {
return this;
}

@Override
public String toString() {
return new StringBuilder("build ")
.append(tag != null ? "-t " + tag + " " : "")
.append(noCache ? "--nocache=true " : "")
.append(dockerFolder != null ? dockerFolder.getPath() : "-")
.toString();
}

protected ClientResponse impl() {
if (tarInputStream == null) {
File dockerFolderTar = buildDockerFolderTar();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,17 @@ public CommitCmd withRun(String run) {
return this;
}


@Override
public String toString() {
return new StringBuilder("commit ")
.append(commitConfig.getAuthor() != null ? "--author " + commitConfig.getAuthor() + " " : "")
.append(commitConfig.getMessage() != null ? "--message " + commitConfig.getMessage() + " " : "")
.append(commitConfig.getContainerId())
.append(commitConfig.getRepo() != null ? " " + commitConfig.getRepo() + ":" : " ")
.append(commitConfig.getTag() != null ? commitConfig.getTag() : "")
.toString();
}

private void checkCommitConfig(CommitConfig commitConfig) {
Preconditions.checkNotNull(commitConfig, "CommitConfig was not specified");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ public ContainerDiffCmd withContainerId(String containerId) {
return this;
}

protected List<ChangeLog> impl() throws DockerException {
@Override
public String toString() {
return new StringBuilder("diff ")
.append(containerId)
.toString();
}

protected List<ChangeLog> impl() throws DockerException {
WebResource webResource = baseResource.path(String.format("/containers/%s/changes", containerId));

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ public CopyFileFromContainerCmd withResource(String resource) {
return this;
}

@Override
public String toString() {
return new StringBuilder("cp ")
.append(containerId)
.append(":")
.append(resource)
.toString();
}

protected ClientResponse impl() throws DockerException {
CopyConfig copyConfig = new CopyConfig();
copyConfig.setResource(resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ public CreateContainerCmd withExposedPorts(ExposedPort... exposedPorts) {
return this;
}

@Override
public String toString() {
return new StringBuilder("create container ")
.append(name != null ? "name=" + name + " " : "")
.append(containerCreateConfig)
.toString();
}

protected ContainerCreateResponse impl() {
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
if (name != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ public ImportImageCmd withTag(String tag) {
return this;
}

@Override
public String toString() {
return new StringBuilder("import - ")
.append(repository != null ? repository + ":" : "")
.append(tag != null ? tag : "")
.toString();
}

protected ImageCreateResponse impl() {
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
params.add("repo", repository);
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/github/dockerjava/client/command/InfoCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@


/**
*
*
*
* Return Docker server info
*/
public class InfoCmd extends AbstrDockerCmd<InfoCmd, Info> {

private static final Logger LOGGER = LoggerFactory.getLogger(InfoCmd.class);


@Override
public String toString() {
return "info";
}

protected Info impl() throws DockerException {
WebResource webResource = baseResource.path("/info");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import com.sun.jersey.api.client.WebResource;

/**
*
*
*
* Inspect the details of a container.
*/
public class InspectContainerCmd extends AbstrDockerCmd<InspectContainerCmd, ContainerInspectResponse> {

Expand All @@ -33,6 +31,11 @@ public InspectContainerCmd withContainerId(String containerId) {
return this;
}

@Override
public String toString() {
return "inspect " + containerId;
}

protected ContainerInspectResponse impl() throws DockerException {
WebResource webResource = baseResource.path(String.format("/containers/%s/json", containerId));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@


/**
*
*
*
* Inspect the details of an image.
*/
public class InspectImageCmd extends AbstrDockerCmd<InspectImageCmd, ImageInspectResponse> {

Expand All @@ -34,6 +32,11 @@ public InspectImageCmd withImageId(String imageId) {
return this;
}

@Override
public String toString() {
return "inspect " + imageId;
}

protected ImageInspectResponse impl() {
WebResource webResource = baseResource.path(String.format("/images/%s/json", imageId));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
import com.sun.jersey.api.client.WebResource;

/**
*
*
*
* Kill a running container.
*/
public class KillContainerCmd extends AbstrDockerCmd<KillContainerCmd, Void> {

Expand All @@ -31,6 +29,11 @@ public KillContainerCmd withContainerId(String containerId) {
return this;
}

@Override
public String toString() {
return "kill " + containerId;
}

protected Void impl() throws DockerException {
WebResource webResource = baseResource.path(String.format("/containers/%s/kill", containerId));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ public ListContainersCmd withBefore(String before) {
return this;
}

@Override
public String toString() {
return new StringBuilder("ps ")
.append(showAll ? "--all=true" : "")
.append(showSize ? "--size=true" : "")
.append(sinceId != null ? "--since " + sinceId : "")
.append(beforeId != null ? "--before " + beforeId : "")
.append(limit != -1 ? "-n " + limit : "")
.toString();
}

protected List<Container> impl() {
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
if(limit >= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ public ListImagesCmd withFilter(String filter) {
return this;
}

@Override
public String toString() {
return new StringBuilder("images ")
.append(showAll ? "--all=true" : "")
.append(filter != null ? "--filter " + filter : "")
.toString();
}

protected List<Image> impl() {
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
params.add("filter", filter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,14 @@ public LogContainerCmd withStdErr(boolean stderr) {
return this;
}


@Override
public String toString() {
return new StringBuilder("logs ")
.append(followStream ? "--follow=true" : "")
.append(timestamps ? "--timestamps=true" : "")
.append(containerId)
.toString();
}

protected ClientResponse impl() throws DockerException {
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ public PullImageCmd withRegistry(String registry) {
return this;
}

@Override
public String toString() {
return new StringBuilder("pull ")
.append(repository)
.append(tag != null ? ":" + tag : "")
.toString();
}

protected ClientResponse impl() {
Preconditions.checkNotNull(repository, "Repository was not specified");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ public PushImageCmd withName(String name) {
return this;
}

@Override
public String toString() {
return new StringBuilder("push ")
.append(name)
.toString();
}

protected ClientResponse impl() {
WebResource webResource = baseResource.path("/images/" + name(name) + "/push");
try {
Expand Down
Loading