Skip to content

Commit b8e96d0

Browse files
committed
Resize container and exec
1 parent 6d9dec3 commit b8e96d0

15 files changed

+420
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
import com.github.dockerjava.api.command.RemoveServiceCmd;
4848
import com.github.dockerjava.api.command.RemoveVolumeCmd;
4949
import com.github.dockerjava.api.command.RenameContainerCmd;
50+
import com.github.dockerjava.api.command.ResizeContainerCmd;
51+
import com.github.dockerjava.api.command.ResizeExecCmd;
5052
import com.github.dockerjava.api.command.RestartContainerCmd;
5153
import com.github.dockerjava.api.command.SaveImageCmd;
5254
import com.github.dockerjava.api.command.SearchImagesCmd;
@@ -147,6 +149,8 @@ public interface DockerClient extends Closeable {
147149
*/
148150
StartContainerCmd startContainerCmd(@Nonnull String containerId);
149151

152+
ResizeContainerCmd resizeContainerCmd(@Nonnull String containerId);
153+
150154
ExecCreateCmd execCreateCmd(@Nonnull String containerId);
151155

152156
InspectContainerCmd inspectContainerCmd(@Nonnull String containerId);
@@ -159,6 +163,8 @@ public interface DockerClient extends Closeable {
159163

160164
ExecStartCmd execStartCmd(@Nonnull String execId);
161165

166+
ResizeExecCmd resizeExecCmd(@Nonnull String execId);
167+
162168
InspectExecCmd inspectExecCmd(@Nonnull String execId);
163169

164170
LogContainerCmd logContainerCmd(@Nonnull String containerId);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ public interface DockerCmdExecFactory extends Closeable {
5252

5353
AttachContainerCmd.Exec createAttachContainerCmdExec();
5454

55+
ResizeContainerCmd.Exec createResizeContainerCmdExec();
56+
5557
ExecStartCmd.Exec createExecStartCmdExec();
5658

59+
ResizeExecCmd.Exec createResizeExecCmdExec();
60+
5761
InspectExecCmd.Exec createInspectExecCmdExec();
5862

5963
LogContainerCmd.Exec createLogContainerCmdExec();
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import javax.annotation.CheckForNull;
4+
import javax.annotation.Nonnull;
5+
6+
import com.github.dockerjava.api.exception.NotFoundException;
7+
8+
public interface ResizeContainerCmd extends SyncDockerCmd<Void> {
9+
10+
@CheckForNull
11+
String getContainerId();
12+
13+
Integer getHeight();
14+
15+
Integer getWidth();
16+
17+
ResizeContainerCmd withContainerId(@Nonnull String execId);
18+
19+
ResizeContainerCmd withSize(int height, int width);
20+
21+
/**
22+
*
23+
* @throws NotFoundException
24+
* No such container instance
25+
*/
26+
@Override
27+
Void exec() throws NotFoundException;
28+
29+
interface Exec extends DockerCmdSyncExec<ResizeContainerCmd, Void> {
30+
}
31+
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import javax.annotation.CheckForNull;
4+
import javax.annotation.Nonnull;
5+
6+
import com.github.dockerjava.api.exception.NotFoundException;
7+
8+
public interface ResizeExecCmd extends SyncDockerCmd<Void> {
9+
10+
@CheckForNull
11+
String getExecId();
12+
13+
Integer getHeight();
14+
15+
Integer getWidth();
16+
17+
ResizeExecCmd withExecId(@Nonnull String execId);
18+
19+
ResizeExecCmd withSize(int height, int width);
20+
21+
/**
22+
*
23+
* @throws NotFoundException
24+
* No such exec instance
25+
*/
26+
@Override
27+
Void exec() throws NotFoundException;
28+
29+
interface Exec extends DockerCmdSyncExec<ResizeExecCmd, Void> {
30+
}
31+
32+
}

src/main/java/com/github/dockerjava/core/DockerClientImpl.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
import com.github.dockerjava.api.command.RemoveServiceCmd;
5050
import com.github.dockerjava.api.command.RemoveVolumeCmd;
5151
import com.github.dockerjava.api.command.RenameContainerCmd;
52+
import com.github.dockerjava.api.command.ResizeContainerCmd;
53+
import com.github.dockerjava.api.command.ResizeExecCmd;
5254
import com.github.dockerjava.api.command.RestartContainerCmd;
5355
import com.github.dockerjava.api.command.SaveImageCmd;
5456
import com.github.dockerjava.api.command.SearchImagesCmd;
@@ -114,6 +116,8 @@
114116
import com.github.dockerjava.core.command.RemoveServiceCmdImpl;
115117
import com.github.dockerjava.core.command.RemoveVolumeCmdImpl;
116118
import com.github.dockerjava.core.command.RenameContainerCmdImpl;
119+
import com.github.dockerjava.core.command.ResizeContainerCmdImpl;
120+
import com.github.dockerjava.core.command.ResizeExecCmdImpl;
117121
import com.github.dockerjava.core.command.RestartContainerCmdImpl;
118122
import com.github.dockerjava.core.command.SaveImageCmdImpl;
119123
import com.github.dockerjava.core.command.SearchImagesCmdImpl;
@@ -341,11 +345,21 @@ public AttachContainerCmd attachContainerCmd(String containerId) {
341345
return new AttachContainerCmdImpl(getDockerCmdExecFactory().createAttachContainerCmdExec(), containerId);
342346
}
343347

348+
@Override
349+
public ResizeContainerCmd resizeContainerCmd(String containerId) {
350+
return new ResizeContainerCmdImpl(getDockerCmdExecFactory().createResizeContainerCmdExec(), containerId);
351+
}
352+
344353
@Override
345354
public ExecStartCmd execStartCmd(String execId) {
346355
return new ExecStartCmdImpl(getDockerCmdExecFactory().createExecStartCmdExec(), execId);
347356
}
348357

358+
@Override
359+
public ResizeExecCmd resizeExecCmd(String execId) {
360+
return new ResizeExecCmdImpl(getDockerCmdExecFactory().createResizeExecCmdExec(), execId);
361+
}
362+
349363
@Override
350364
public InspectExecCmd inspectExecCmd(String execId) {
351365
return new InspectExecCmdImpl(getDockerCmdExecFactory().createInspectExecCmdExec(), execId);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.github.dockerjava.core.command;
2+
3+
import static com.google.common.base.Preconditions.checkNotNull;
4+
5+
import com.fasterxml.jackson.annotation.JsonInclude;
6+
import com.fasterxml.jackson.annotation.JsonInclude.Include;
7+
import com.github.dockerjava.api.command.ResizeContainerCmd;
8+
import com.github.dockerjava.api.exception.NotFoundException;
9+
10+
@JsonInclude(Include.NON_NULL)
11+
public class ResizeContainerCmdImpl extends AbstrDockerCmd<ResizeContainerCmd, Void> implements ResizeContainerCmd {
12+
13+
private String containerId;
14+
15+
private Integer height;
16+
17+
private Integer width;
18+
19+
public ResizeContainerCmdImpl(ResizeContainerCmd.Exec exec, String execId) {
20+
super(exec);
21+
withContainerId(execId);
22+
}
23+
24+
@Override
25+
public String getContainerId() {
26+
return containerId;
27+
}
28+
29+
@Override
30+
public Integer getHeight() {
31+
return height;
32+
}
33+
34+
@Override
35+
public Integer getWidth() {
36+
return width;
37+
}
38+
39+
@Override
40+
public ResizeContainerCmd withContainerId(String containerId) {
41+
checkNotNull(containerId, "containerId was not specified");
42+
this.containerId = containerId;
43+
return this;
44+
}
45+
46+
@Override
47+
public ResizeContainerCmd withSize(int height, int width) {
48+
this.height = height;
49+
this.width = width;
50+
return this;
51+
}
52+
53+
/**
54+
* @throws NotFoundException
55+
* No such exec instance
56+
*/
57+
@Override
58+
public Void exec() throws NotFoundException {
59+
return super.exec();
60+
}
61+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.github.dockerjava.core.command;
2+
3+
import static com.google.common.base.Preconditions.checkNotNull;
4+
5+
import com.fasterxml.jackson.annotation.JsonInclude;
6+
import com.fasterxml.jackson.annotation.JsonInclude.Include;
7+
import com.github.dockerjava.api.command.ResizeExecCmd;
8+
import com.github.dockerjava.api.exception.NotFoundException;
9+
10+
@JsonInclude(Include.NON_NULL)
11+
public class ResizeExecCmdImpl extends AbstrDockerCmd<ResizeExecCmd, Void> implements ResizeExecCmd {
12+
13+
private String execId;
14+
15+
private Integer height;
16+
17+
private Integer width;
18+
19+
public ResizeExecCmdImpl(ResizeExecCmd.Exec exec, String execId) {
20+
super(exec);
21+
withExecId(execId);
22+
}
23+
24+
@Override
25+
public String getExecId() {
26+
return execId;
27+
}
28+
29+
@Override
30+
public Integer getHeight() {
31+
return height;
32+
}
33+
34+
@Override
35+
public Integer getWidth() {
36+
return width;
37+
}
38+
39+
@Override
40+
public ResizeExecCmd withExecId(String execId) {
41+
checkNotNull(execId, "execId was not specified");
42+
this.execId = execId;
43+
return this;
44+
}
45+
46+
@Override
47+
public ResizeExecCmd withSize(int height, int width) {
48+
this.height = height;
49+
this.width = width;
50+
return this;
51+
}
52+
53+
/**
54+
* @throws NotFoundException
55+
* No such exec instance
56+
*/
57+
@Override
58+
public Void exec() throws NotFoundException {
59+
return super.exec();
60+
}
61+
}

src/main/java/com/github/dockerjava/jaxrs/JerseyDockerCmdExecFactory.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
import com.github.dockerjava.api.command.RemoveSwarmNodeCmd;
5555
import com.github.dockerjava.api.command.RemoveVolumeCmd;
5656
import com.github.dockerjava.api.command.RenameContainerCmd;
57+
import com.github.dockerjava.api.command.ResizeContainerCmd.Exec;
58+
import com.github.dockerjava.api.command.ResizeExecCmd;
5759
import com.github.dockerjava.api.command.RestartContainerCmd;
5860
import com.github.dockerjava.api.command.SaveImageCmd;
5961
import com.github.dockerjava.api.command.SearchImagesCmd;
@@ -413,11 +415,21 @@ public AttachContainerCmd.Exec createAttachContainerCmdExec() {
413415
return new AttachContainerCmdExec(getBaseResource(), getDockerClientConfig());
414416
}
415417

418+
@Override
419+
public Exec createResizeContainerCmdExec() {
420+
return new ResizeContainerCmdExec(getBaseResource(), getDockerClientConfig());
421+
}
422+
416423
@Override
417424
public ExecStartCmd.Exec createExecStartCmdExec() {
418425
return new ExecStartCmdExec(getBaseResource(), getDockerClientConfig());
419426
}
420427

428+
@Override
429+
public ResizeExecCmd.Exec createResizeExecCmdExec() {
430+
return new ResizeExecCmdExec(getBaseResource(), getDockerClientConfig());
431+
}
432+
421433
@Override
422434
public InspectExecCmd.Exec createInspectExecCmdExec() {
423435
return new InspectExecCmdExec(getBaseResource(), getDockerClientConfig());
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.github.dockerjava.jaxrs;
2+
3+
import javax.ws.rs.client.WebTarget;
4+
import javax.ws.rs.core.MediaType;
5+
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
9+
import com.github.dockerjava.api.command.ResizeContainerCmd;
10+
import com.github.dockerjava.core.DockerClientConfig;
11+
12+
public class ResizeContainerCmdExec extends AbstrSyncDockerCmdExec<ResizeContainerCmd, Void> implements ResizeContainerCmd.Exec {
13+
14+
private static final Logger LOGGER = LoggerFactory.getLogger(ResizeContainerCmdExec.class);
15+
16+
public ResizeContainerCmdExec(WebTarget baseResource, DockerClientConfig dockerClientConfig) {
17+
super(baseResource, dockerClientConfig);
18+
}
19+
20+
@Override
21+
protected Void execute(ResizeContainerCmd command) {
22+
WebTarget webResource = getBaseResource().path("/containers/{id}/resize").resolveTemplate("id", command.getContainerId())
23+
.queryParam("h", command.getHeight()).queryParam("w", command.getWidth());
24+
25+
LOGGER.trace("POST: {}", webResource);
26+
webResource.request().accept(MediaType.APPLICATION_JSON).post(null).close();
27+
28+
return null;
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.github.dockerjava.jaxrs;
2+
3+
import javax.ws.rs.client.WebTarget;
4+
import javax.ws.rs.core.MediaType;
5+
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
9+
import com.github.dockerjava.api.command.ResizeExecCmd;
10+
import com.github.dockerjava.core.DockerClientConfig;
11+
12+
public class ResizeExecCmdExec extends AbstrSyncDockerCmdExec<ResizeExecCmd, Void> implements ResizeExecCmd.Exec {
13+
14+
private static final Logger LOGGER = LoggerFactory.getLogger(ResizeExecCmdExec.class);
15+
16+
public ResizeExecCmdExec(WebTarget baseResource, DockerClientConfig dockerClientConfig) {
17+
super(baseResource, dockerClientConfig);
18+
}
19+
20+
@Override
21+
protected Void execute(ResizeExecCmd command) {
22+
WebTarget webResource = getBaseResource().path("/exec/{id}/resize").resolveTemplate("id", command.getExecId())
23+
.queryParam("h", command.getHeight()).queryParam("w", command.getWidth());
24+
25+
LOGGER.trace("POST: {}", webResource);
26+
webResource.request().accept(MediaType.APPLICATION_JSON).post(null).close();
27+
28+
return null;
29+
}
30+
}

0 commit comments

Comments
 (0)