X Tutup
Skip to content

Commit 779204b

Browse files
committed
Add ping method
1 parent cb9b3f2 commit 779204b

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.github.dockerjava.client.command.ListContainersCmd;
3535
import com.github.dockerjava.client.command.ListImagesCmd;
3636
import com.github.dockerjava.client.command.LogContainerCmd;
37+
import com.github.dockerjava.client.command.PingCmd;
3738
import com.github.dockerjava.client.command.PullImageCmd;
3839
import com.github.dockerjava.client.command.PushImageCmd;
3940
import com.github.dockerjava.client.command.RemoveContainerCmd;
@@ -174,6 +175,10 @@ public AuthCmd authCmd() {
174175
public InfoCmd infoCmd() throws DockerException {
175176
return new InfoCmd().withBaseResource(baseResource);
176177
}
178+
179+
public PingCmd pingCmd() {
180+
return new PingCmd().withBaseResource(baseResource);
181+
}
177182

178183
public VersionCmd versionCmd() throws DockerException {
179184
return new VersionCmd().withBaseResource(baseResource);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.github.dockerjava.client.command;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
import com.sun.jersey.api.client.ClientResponse;
7+
import com.sun.jersey.api.client.UniformInterfaceException;
8+
import com.sun.jersey.api.client.WebResource;
9+
10+
/**
11+
* Ping the Docker server
12+
*
13+
*/
14+
public class PingCmd extends AbstrDockerCmd<PingCmd, Integer> {
15+
16+
private static final Logger LOGGER = LoggerFactory.getLogger(PingCmd.class);
17+
18+
protected Integer impl() {
19+
WebResource webResource = baseResource.path("/_ping");
20+
21+
try {
22+
LOGGER.trace("GET: {}", webResource);
23+
ClientResponse resp = webResource.get(ClientResponse.class);
24+
return resp.getStatus();
25+
} catch (UniformInterfaceException exception) {
26+
return exception.getResponse().getStatus();
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)
X Tutup