forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPruneCmdImpl.java
More file actions
102 lines (87 loc) · 2.88 KB
/
Copy pathPruneCmdImpl.java
File metadata and controls
102 lines (87 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package com.github.dockerjava.core.command;
import com.github.dockerjava.api.command.PruneCmd;
import com.github.dockerjava.api.model.PruneResponse;
import com.github.dockerjava.api.model.PruneType;
import com.github.dockerjava.core.util.FiltersBuilder;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import java.util.List;
import java.util.Map;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Delete unused content (containers, images, volumes, networks, build relicts)
*/
public class PruneCmdImpl extends AbstrDockerCmd<PruneCmd, PruneResponse> implements PruneCmd {
private static final String BUILD_API_PATH = "/build/prune";
private static final String CONTAINERS_API_PATH = "/containers/prune";
private static final String IMAGES_API_PATH = "/images/prune";
private static final String VOLUMES_API_PATH = "/volumes/prune";
private static final String NETWORKS_API_PATH = "/networks/prune";
private FiltersBuilder filters = new FiltersBuilder();
private PruneType pruneType;
public PruneCmdImpl(Exec exec, PruneType pruneType) {
super(exec);
this.pruneType = pruneType;
}
@Nonnull
@Override
public PruneType getPruneType() {
return pruneType;
}
@Nonnull
@Override
public String getApiPath() {
String apiPath;
switch (getPruneType()) {
case BUILD:
apiPath = BUILD_API_PATH;
break;
case IMAGES:
apiPath = IMAGES_API_PATH;
break;
case NETWORKS:
apiPath = NETWORKS_API_PATH;
break;
case VOLUMES:
apiPath = VOLUMES_API_PATH;
break;
default:
apiPath = CONTAINERS_API_PATH;
break;
}
return apiPath;
}
@CheckForNull
@Override
public Map<String, List<String>> getFilters() {
return filters.build();
}
@Override
public PruneCmd withPruneType(final PruneType pruneType) {
checkNotNull(pruneType, "pruneType has not been specified");
this.pruneType = pruneType;
return this;
}
@Override
public PruneCmd withDangling(Boolean dangling) {
checkNotNull(dangling, "dangling has not been specified");
filters.withFilter("dangling", dangling ? "1" : "0");
return this;
}
@Override
public PruneCmd withUntilFilter(final String until) {
checkNotNull(until, "until has not been specified");
filters.withUntil(until);
return this;
}
@Override
public PruneCmd withLabelFilter(final String... labels) {
checkNotNull(labels, "labels have not been specified");
filters.withLabels(labels);
return this;
}
@Override
public PruneResponse exec() {
return super.exec();
}
}