Skip to content

Commit f9d2db6

Browse files
jrietdijkbsideup
andauthored
Support Swarm config operations (docker-java#1482)
Co-authored-by: Sergei Egorov <segorov@vmware.com>
1 parent 9ba70a9 commit f9d2db6

23 files changed

+836
-0
lines changed

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.github.dockerjava.api.command.CopyArchiveFromContainerCmd;
1010
import com.github.dockerjava.api.command.CopyArchiveToContainerCmd;
1111
import com.github.dockerjava.api.command.CopyFileFromContainerCmd;
12+
import com.github.dockerjava.api.command.CreateConfigCmd;
1213
import com.github.dockerjava.api.command.CreateContainerCmd;
1314
import com.github.dockerjava.api.command.CreateImageCmd;
1415
import com.github.dockerjava.api.command.CreateNetworkCmd;
@@ -21,6 +22,7 @@
2122
import com.github.dockerjava.api.command.ExecStartCmd;
2223
import com.github.dockerjava.api.command.InfoCmd;
2324
import com.github.dockerjava.api.command.InitializeSwarmCmd;
25+
import com.github.dockerjava.api.command.InspectConfigCmd;
2426
import com.github.dockerjava.api.command.InspectContainerCmd;
2527
import com.github.dockerjava.api.command.InspectExecCmd;
2628
import com.github.dockerjava.api.command.InspectImageCmd;
@@ -31,6 +33,7 @@
3133
import com.github.dockerjava.api.command.JoinSwarmCmd;
3234
import com.github.dockerjava.api.command.KillContainerCmd;
3335
import com.github.dockerjava.api.command.LeaveSwarmCmd;
36+
import com.github.dockerjava.api.command.ListConfigsCmd;
3437
import com.github.dockerjava.api.command.ListContainersCmd;
3538
import com.github.dockerjava.api.command.ListImagesCmd;
3639
import com.github.dockerjava.api.command.ListNetworksCmd;
@@ -47,6 +50,7 @@
4750
import com.github.dockerjava.api.command.PruneCmd;
4851
import com.github.dockerjava.api.command.PullImageCmd;
4952
import com.github.dockerjava.api.command.PushImageCmd;
53+
import com.github.dockerjava.api.command.RemoveConfigCmd;
5054
import com.github.dockerjava.api.command.RemoveContainerCmd;
5155
import com.github.dockerjava.api.command.RemoveImageCmd;
5256
import com.github.dockerjava.api.command.RemoveNetworkCmd;
@@ -435,12 +439,47 @@ public interface DockerClient extends Closeable {
435439

436440
/**
437441
* Command to remove a secret
442+
*
443+
* @since {@link RemoteApiVersion#VERSION_1_25}
438444
* @param secretId secret id or secret name
439445
* @return command
440446
*/
441447
RemoveSecretCmd removeSecretCmd(String secretId);
442448

443449

450+
/**
451+
* Command to list all configs. Only applicable if docker runs in swarm mode.
452+
*
453+
* @since {@link RemoteApiVersion#VERSION_1_30}
454+
* @return command
455+
*/
456+
ListConfigsCmd listConfigsCmd();
457+
458+
/**
459+
* Command to create a config in a docker swarm. Only applicable if docker runs in swarm mode.
460+
*
461+
* @since {@link RemoteApiVersion#VERSION_1_30}
462+
* @return command
463+
*/
464+
CreateConfigCmd createConfigCmd();
465+
466+
/**
467+
* Command to inspect a service
468+
*
469+
* @since {@link RemoteApiVersion#VERSION_1_30}
470+
* @param configId config id or config name
471+
* @return command
472+
*/
473+
InspectConfigCmd inspectConfigCmd(String configId);
474+
475+
/**
476+
* Command to remove a config
477+
* @since {@link RemoteApiVersion#VERSION_1_30}
478+
* @param configId config id or config name
479+
* @return command
480+
*/
481+
RemoveConfigCmd removeConfigCmd(String configId);
482+
444483

445484
@Override
446485
void close() throws IOException;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import com.github.dockerjava.api.exception.ConflictException;
4+
5+
import javax.annotation.CheckForNull;
6+
import java.util.Map;
7+
8+
/**
9+
* Command to create a new config
10+
*
11+
* @since {@link RemoteApiVersion#VERSION_1_30}
12+
*/
13+
public interface CreateConfigCmd extends SyncDockerCmd<CreateConfigResponse> {
14+
15+
@CheckForNull
16+
String getName();
17+
18+
@CheckForNull
19+
String getData();
20+
21+
@CheckForNull
22+
Map<String, String> getLabels();
23+
24+
/**
25+
* @param name
26+
* - The new config name.
27+
*/
28+
CreateConfigCmd withName(String name);
29+
30+
/**
31+
* @param data
32+
* - The new config data.
33+
*/
34+
CreateConfigCmd withData(byte[] data);
35+
36+
/**
37+
* @param labels
38+
* - A mapping of labels keys and values. Labels are a mechanism for applying metadata to Docker objects.
39+
*/
40+
CreateConfigCmd withLabels(Map<String, String> labels);
41+
42+
/**
43+
* @throws ConflictException Named config already exists
44+
*/
45+
@Override
46+
CreateConfigResponse exec() throws ConflictException;
47+
48+
interface Exec extends DockerCmdSyncExec<CreateConfigCmd, CreateConfigResponse> {
49+
}
50+
51+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.EqualsAndHashCode;
5+
import lombok.ToString;
6+
7+
/**
8+
* The response of a {@link CreateConfigCmd}
9+
*/
10+
@EqualsAndHashCode
11+
@ToString
12+
public class CreateConfigResponse {
13+
@JsonProperty("ID")
14+
private String id;
15+
16+
public String getId() {
17+
return id;
18+
}
19+
}

docker-java-api/src/main/java/com/github/dockerjava/api/command/DelegatingDockerCmdExecFactory.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,26 @@ public RemoveSecretCmd.Exec createRemoveSecretCmdExec() {
380380
return getDockerCmdExecFactory().createRemoveSecretCmdExec();
381381
}
382382

383+
@Override
384+
public ListConfigsCmd.Exec createListConfigsCmdExec() {
385+
return getDockerCmdExecFactory().createListConfigsCmdExec();
386+
}
387+
388+
@Override
389+
public CreateConfigCmd.Exec createCreateConfigCmdExec() {
390+
return getDockerCmdExecFactory().createCreateConfigCmdExec();
391+
}
392+
393+
@Override
394+
public InspectConfigCmd.Exec createInspectConfigCmdExec() {
395+
return getDockerCmdExecFactory().createInspectConfigCmdExec();
396+
}
397+
398+
@Override
399+
public RemoveConfigCmd.Exec createRemoveConfigCmdExec() {
400+
return getDockerCmdExecFactory().createRemoveConfigCmdExec();
401+
}
402+
383403
@Override
384404
public void close() throws IOException {
385405
getDockerCmdExecFactory().close();

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,35 @@ public interface DockerCmdExecFactory extends Closeable {
236236
*/
237237
RemoveSecretCmd.Exec createRemoveSecretCmdExec();
238238

239+
/**
240+
* Command to list all configs.
241+
*
242+
* @since {@link RemoteApiVersion#VERSION_1_30}
243+
*/
244+
ListConfigsCmd.Exec createListConfigsCmdExec();
245+
246+
/**
247+
* Command to inspect a config in a docker swarm. Only applicable if docker runs in swarm mode.
248+
*
249+
* @since {@link RemoteApiVersion#VERSION_1_30}
250+
*/
251+
InspectConfigCmd.Exec createInspectConfigCmdExec();
252+
253+
/**
254+
* Command to create a new config in a docker swarm. Only applicable if docker runs in swarm mode.
255+
*
256+
* @since {@link RemoteApiVersion#VERSION_1_30}
257+
*/
258+
CreateConfigCmd.Exec createCreateConfigCmdExec();
259+
260+
/**
261+
* Command to remove a config in a docker swarm. Only applicable if docker runs in swarm mode.
262+
*
263+
* @since {@link RemoteApiVersion#VERSION_1_30}
264+
*/
265+
RemoveConfigCmd.Exec createRemoveConfigCmdExec();
266+
267+
239268
@Override
240269
void close() throws IOException;
241270

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import com.github.dockerjava.api.exception.NotFoundException;
4+
import com.github.dockerjava.api.model.Config;
5+
6+
import javax.annotation.CheckForNull;
7+
import javax.annotation.Nonnull;
8+
9+
public interface InspectConfigCmd extends SyncDockerCmd<Config> {
10+
11+
@CheckForNull
12+
String getConfigId();
13+
14+
InspectConfigCmd withConfigId(@Nonnull String configId);
15+
16+
/**
17+
* @throws NotFoundException
18+
* No such config
19+
*/
20+
@Override
21+
Config exec() throws NotFoundException;
22+
23+
interface Exec extends DockerCmdSyncExec<InspectConfigCmd, Config> {
24+
}
25+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import com.github.dockerjava.api.model.Config;
4+
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
/**
9+
* Command to list all configs in a docker swarm. Only applicable if docker runs in swarm mode.
10+
*
11+
* @since {@link RemoteApiVersion#VERSION_1_30}
12+
*/
13+
public interface ListConfigsCmd extends SyncDockerCmd<List<Config>> {
14+
15+
Map<String, List<String>> getFilters();
16+
17+
ListConfigsCmd withFilters(Map<String, List<String>> filters);
18+
19+
interface Exec extends DockerCmdSyncExec<ListConfigsCmd, List<Config>> {
20+
}
21+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import com.github.dockerjava.api.exception.NotFoundException;
4+
5+
import javax.annotation.CheckForNull;
6+
import javax.annotation.Nonnull;
7+
8+
/**
9+
* Remove a config.
10+
*/
11+
public interface RemoveConfigCmd extends SyncDockerCmd<Void> {
12+
13+
@CheckForNull
14+
String getConfigId();
15+
16+
RemoveConfigCmd withConfigId(@Nonnull String secretId);
17+
18+
/**
19+
* @throws NotFoundException
20+
* No such config
21+
*/
22+
@Override
23+
Void exec() throws NotFoundException;
24+
25+
interface Exec extends DockerCmdSyncExec<RemoveConfigCmd, Void> {
26+
}
27+
28+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package com.github.dockerjava.api.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.EqualsAndHashCode;
5+
import lombok.ToString;
6+
7+
import java.io.Serializable;
8+
import java.util.Date;
9+
10+
/**
11+
* Used for Listing config.
12+
*
13+
* @since {@link RemoteApiVersion#VERSION_1_30}
14+
*/
15+
@ToString
16+
@EqualsAndHashCode
17+
public class Config implements Serializable {
18+
19+
private static final long serialVersionUID = 1L;
20+
21+
/**
22+
* @since 1.30
23+
*/
24+
@JsonProperty("ID")
25+
private String id;
26+
27+
/**
28+
* @since 1.30
29+
*/
30+
@JsonProperty("CreatedAt")
31+
private Date createdAt;
32+
33+
/**
34+
* @since 1.30
35+
*/
36+
@JsonProperty("UpdatedAt")
37+
private Date updatedAt;
38+
39+
/**
40+
* @since 1.30
41+
*/
42+
@JsonProperty("Spec")
43+
private ConfigSpec spec;
44+
45+
/**
46+
* @since 1.30
47+
*/
48+
@JsonProperty("Version")
49+
private ResourceVersion version;
50+
51+
public String getId() {
52+
return id;
53+
}
54+
55+
public void setId(String id) {
56+
this.id = id;
57+
}
58+
59+
public Date getCreatedAt() {
60+
return createdAt;
61+
}
62+
63+
public void setCreatedAt(Date createdAt) {
64+
this.createdAt = createdAt;
65+
}
66+
67+
public Date getUpdatedAt() {
68+
return updatedAt;
69+
}
70+
71+
public void setUpdatedAt(Date updatedAt) {
72+
this.updatedAt = updatedAt;
73+
}
74+
75+
public ConfigSpec getSpec() {
76+
return spec;
77+
}
78+
79+
public void setSpec(ConfigSpec spec) {
80+
this.spec = spec;
81+
}
82+
83+
public ResourceVersion getVersion() {
84+
return version;
85+
}
86+
87+
public void setVersion(ResourceVersion version) {
88+
this.version = version;
89+
}
90+
}

0 commit comments

Comments
 (0)