Skip to content

Commit 76be397

Browse files
xuchenCNKostyaSha
authored andcommitted
Resize container and exec
1 parent fd1dbfe commit 76be397

15 files changed

+410
-1
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
@@ -54,6 +54,8 @@
5454
import com.github.dockerjava.api.command.RemoveServiceCmd;
5555
import com.github.dockerjava.api.command.RemoveVolumeCmd;
5656
import com.github.dockerjava.api.command.RenameContainerCmd;
57+
import com.github.dockerjava.api.command.ResizeContainerCmd;
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;
@@ -157,6 +159,8 @@ public interface DockerClient extends Closeable {
157159
*/
158160
StartContainerCmd startContainerCmd(@Nonnull String containerId);
159161

162+
ResizeContainerCmd resizeContainerCmd(@Nonnull String containerId);
163+
160164
ExecCreateCmd execCreateCmd(@Nonnull String containerId);
161165

162166
InspectContainerCmd inspectContainerCmd(@Nonnull String containerId);
@@ -169,6 +173,8 @@ public interface DockerClient extends Closeable {
169173

170174
ExecStartCmd execStartCmd(@Nonnull String execId);
171175

176+
ResizeExecCmd resizeExecCmd(@Nonnull String execId);
177+
172178
InspectExecCmd inspectExecCmd(@Nonnull String execId);
173179

174180
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
@@ -56,6 +56,8 @@
5656
import com.github.dockerjava.api.command.RemoveServiceCmd;
5757
import com.github.dockerjava.api.command.RemoveVolumeCmd;
5858
import com.github.dockerjava.api.command.RenameContainerCmd;
59+
import com.github.dockerjava.api.command.ResizeContainerCmd;
60+
import com.github.dockerjava.api.command.ResizeExecCmd;
5961
import com.github.dockerjava.api.command.RestartContainerCmd;
6062
import com.github.dockerjava.api.command.SaveImageCmd;
6163
import com.github.dockerjava.api.command.SearchImagesCmd;
@@ -131,6 +133,8 @@
131133
import com.github.dockerjava.core.command.RemoveServiceCmdImpl;
132134
import com.github.dockerjava.core.command.RemoveVolumeCmdImpl;
133135
import com.github.dockerjava.core.command.RenameContainerCmdImpl;
136+
import com.github.dockerjava.core.command.ResizeContainerCmdImpl;
137+
import com.github.dockerjava.core.command.ResizeExecCmdImpl;
134138
import com.github.dockerjava.core.command.RestartContainerCmdImpl;
135139
import com.github.dockerjava.core.command.SaveImageCmdImpl;
136140
import com.github.dockerjava.core.command.SearchImagesCmdImpl;
@@ -356,11 +360,21 @@ public AttachContainerCmd attachContainerCmd(String containerId) {
356360
return new AttachContainerCmdImpl(getDockerCmdExecFactory().createAttachContainerCmdExec(), containerId);
357361
}
358362

363+
@Override
364+
public ResizeContainerCmd resizeContainerCmd(String containerId) {
365+
return new ResizeContainerCmdImpl(getDockerCmdExecFactory().createResizeContainerCmdExec(), containerId);
366+
}
367+
359368
@Override
360369
public ExecStartCmd execStartCmd(String execId) {
361370
return new ExecStartCmdImpl(getDockerCmdExecFactory().createExecStartCmdExec(), execId);
362371
}
363372

373+
@Override
374+
public ResizeExecCmd resizeExecCmd(String execId) {
375+
return new ResizeExecCmdImpl(getDockerCmdExecFactory().createResizeExecCmdExec(), execId);
376+
}
377+
364378
@Override
365379
public InspectExecCmd inspectExecCmd(String execId) {
366380
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
@@ -60,6 +60,8 @@
6060
import com.github.dockerjava.api.command.RemoveSwarmNodeCmd;
6161
import com.github.dockerjava.api.command.RemoveVolumeCmd;
6262
import com.github.dockerjava.api.command.RenameContainerCmd;
63+
import com.github.dockerjava.api.command.ResizeContainerCmd.Exec;
64+
import com.github.dockerjava.api.command.ResizeExecCmd;
6365
import com.github.dockerjava.api.command.RestartContainerCmd;
6466
import com.github.dockerjava.api.command.SaveImageCmd;
6567
import com.github.dockerjava.api.command.SearchImagesCmd;
@@ -424,11 +426,21 @@ public AttachContainerCmd.Exec createAttachContainerCmdExec() {
424426
return new AttachContainerCmdExec(getBaseResource(), getDockerClientConfig());
425427
}
426428

429+
@Override
430+
public Exec createResizeContainerCmdExec() {
431+
return new ResizeContainerCmdExec(getBaseResource(), getDockerClientConfig());
432+
}
433+
427434
@Override
428435
public ExecStartCmd.Exec createExecStartCmdExec() {
429436
return new ExecStartCmdExec(getBaseResource(), getDockerClientConfig());
430437
}
431438

439+
@Override
440+
public ResizeExecCmd.Exec createResizeExecCmdExec() {
441+
return new ResizeExecCmdExec(getBaseResource(), getDockerClientConfig());
442+
}
443+
432444
@Override
433445
public InspectExecCmd.Exec createInspectExecCmdExec() {
434446
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)