Merge pull request #1 from zajezdy/prune_operations · docker-java/docker-java@b876d3b · GitHub
Skip to content

Commit b876d3b

Browse files
authored
Merge pull request #1 from zajezdy/prune_operations
add Prune operations
2 parents 7b249ad + 527e55b commit b876d3b

13 files changed

Lines changed: 380 additions & 478 deletions

File tree

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

Lines changed: 9 additions & 69 deletions

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ public interface DockerCmdExecFactory extends Closeable {
207207
*/
208208
ListTasksCmd.Exec listTasksCmdExec();
209209

210+
/**
211+
* Delete unused content (containers, images, volumes, networks, build relicts)
212+
*
213+
* @since {@link RemoteApiVersion#VERSION_1_25}
214+
*/
215+
PruneCmd.Exec pruneCmdExec();
216+
210217
@Override
211218
void close() throws IOException;
212219

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import com.github.dockerjava.api.model.PruneResponse;
4+
import com.github.dockerjava.api.model.PruneType;
5+
import com.github.dockerjava.core.RemoteApiVersion;
6+
7+
import javax.annotation.CheckForNull;
8+
import javax.annotation.Nonnull;
9+
import java.util.List;
10+
import java.util.Map;
11+
12+
/**
13+
* Delete unused content (containers, images, volumes, networks, build relicts)
14+
*
15+
* @since {@link RemoteApiVersion#VERSION_1_25}
16+
*/
17+
public interface PruneCmd extends SyncDockerCmd<PruneResponse> {
18+
19+
@Nonnull
20+
PruneType getPruneType();
21+
22+
@Nonnull
23+
String getApiPath();
24+
25+
@CheckForNull
26+
Map<String, List<String>> getFilters();
27+
28+
PruneCmd withPruneType(final PruneType pruneType);
29+
/**
30+
* Prune containers created before this timestamp
31+
* Meaningful only for CONTAINERS and IMAGES prune type
32+
* @param until Can be Unix timestamps, date formatted timestamps, or Go duration strings (e.g. 10m, 1h30m) computed relative to the daemon machine’s time.
33+
*/
34+
PruneCmd withUntilFilter(String until);
35+
36+
/**
37+
* When set to true, prune only unused and untagged images. When set to false, all unused images are pruned.
38+
* Meaningful only for IMAGES prune type
39+
*/
40+
PruneCmd withDangling(Boolean dangling);
41+
42+
/**
43+
* Prune containers with the specified labels
44+
*/
45+
PruneCmd withLabelFilter(String... label);
46+
47+
@Override
48+
PruneResponse exec();
49+
50+
interface Exec extends DockerCmdSyncExec<PruneCmd, PruneResponse> {
51+
}
52+
53+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.github.dockerjava.api.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import org.apache.commons.lang.builder.EqualsBuilder;
6+
import org.apache.commons.lang.builder.HashCodeBuilder;
7+
8+
import java.io.Serializable;
9+
10+
/**
11+
* Delete unused content (containers, images, volumes, networks, build relicts)
12+
*/
13+
@JsonIgnoreProperties(ignoreUnknown = true)
14+
public class PruneResponse implements Serializable {
15+
private static final long serialVersionUID = 1L;
16+
17+
@JsonProperty("SpaceReclaimed")
18+
private Long spaceReclaimed;
19+
20+
/**
21+
* Default constructor for the deserialization.
22+
*/
23+
public PruneResponse() {
24+
}
25+
26+
/**
27+
* Constructor.
28+
*
29+
* @param spaceReclaimed Space reclaimed after purification
30+
*/
31+
public PruneResponse(Long spaceReclaimed) {
32+
this.spaceReclaimed = spaceReclaimed;
33+
}
34+
35+
/**
36+
* Disk space reclaimed in bytes
37+
*/
38+
public Long getSpaceReclaimed() {
39+
return spaceReclaimed;
40+
}
41+
42+
@Override
43+
public String toString() {
44+
StringBuilder sb = new StringBuilder();
45+
sb.append("PruneResponse {");
46+
sb.append(" spaceReclaimed: ").append(getSpaceReclaimed());
47+
sb.append("}");
48+
return sb.toString();
49+
}
50+
51+
@Override
52+
public boolean equals(Object o) {
53+
if (o instanceof Ulimit) {
54+
Ulimit other = (Ulimit) o;
55+
return new EqualsBuilder().append(spaceReclaimed, other.getName()).isEquals();
56+
} else
57+
return super.equals(o);
58+
}
59+
60+
@Override
61+
public int hashCode() {
62+
return new HashCodeBuilder().append(spaceReclaimed).toHashCode();
63+
}
64+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.github.dockerjava.api.model;
2+
3+
public enum PruneType {
4+
BUILD,
5+
CONTAINERS,
6+
IMAGES,
7+
NETWORKS,
8+
VOLUMES
9+
}

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

Lines changed: 7 additions & 135 deletions

0 commit comments

Comments
 (0)