Skip to content

Commit f65b03f

Browse files
author
Marcus Linke
committed
Refactored build, push & pull commands APIs (async / callback driven)
1 parent c9cdda6 commit f65b03f

72 files changed

Lines changed: 800 additions & 771 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@
4444
import com.github.dockerjava.api.command.WaitContainerCmd;
4545
import com.github.dockerjava.api.model.AuthConfig;
4646
import com.github.dockerjava.api.model.Event;
47+
import com.github.dockerjava.api.model.BuildResponseItem;
4748
import com.github.dockerjava.api.model.Frame;
4849
import com.github.dockerjava.api.model.Identifier;
50+
import com.github.dockerjava.api.model.PullResponseItem;
51+
import com.github.dockerjava.api.model.PushResponseItem;
4952
import com.github.dockerjava.api.model.Statistics;
5053

5154
// https://godoc.org/github.com/fsouza/go-dockerclient
@@ -68,11 +71,11 @@ public interface DockerClient extends Closeable {
6871
* * IMAGE API *
6972
*/
7073

71-
public PullImageCmd pullImageCmd(String repository);
74+
public PullImageCmd pullImageCmd(String repository, ResultCallback<PullResponseItem> resultCallback);
7275

73-
public PushImageCmd pushImageCmd(String name);
76+
public PushImageCmd pushImageCmd(String name, ResultCallback<PushResponseItem> resultCallback);
7477

75-
public PushImageCmd pushImageCmd(Identifier identifier);
78+
public PushImageCmd pushImageCmd(Identifier identifier, ResultCallback<PushResponseItem> resultCallback);
7679

7780
public CreateImageCmd createImageCmd(String repository, InputStream imageStream);
7881

@@ -134,11 +137,11 @@ public interface DockerClient extends Closeable {
134137

135138
public CommitCmd commitCmd(String containerId);
136139

137-
public BuildImageCmd buildImageCmd();
140+
public BuildImageCmd buildImageCmd(ResultCallback<BuildResponseItem> resultCallback);
138141

139-
public BuildImageCmd buildImageCmd(File dockerFileOrFolder);
142+
public BuildImageCmd buildImageCmd(File dockerFileOrFolder, ResultCallback<BuildResponseItem> resultCallback);
140143

141-
public BuildImageCmd buildImageCmd(InputStream tarInputStream);
144+
public BuildImageCmd buildImageCmd(InputStream tarInputStream, ResultCallback<BuildResponseItem> resultCallback);
142145

143146
public TopContainerCmd topContainerCmd(String containerId);
144147

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* @author marcus
1212
*
1313
*/
14-
public interface AsyncDockerCmd<CMD_T extends DockerCmd<RES_T>, A_RES_T, RES_T> extends DockerCmd<RES_T> {
14+
public interface AsyncDockerCmd<CMD_T extends AsyncDockerCmd<CMD_T, A_RES_T, RES_T>, A_RES_T, RES_T> extends DockerCmd<RES_T> {
1515

1616
public ResultCallback<A_RES_T> getResultCallback();
1717

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,11 @@ public interface AttachContainerCmd extends AsyncDockerCmd<AttachContainerCmd, F
6464
public AttachContainerCmd withLogs();
6565

6666
/**
67-
* Its the responsibility of the caller to consume and/or close the {@link InputStream} to prevent connection leaks.
68-
*
6967
* @throws NotFoundException
7068
* No such container
7169
*/
7270
@Override
73-
public Void exec() throws NotFoundException;
71+
public Void exec();
7472

7573
public static interface Exec extends DockerCmdExec<AttachContainerCmd, Void> {
7674
}

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package com.github.dockerjava.api.command;
22

3-
import com.github.dockerjava.api.model.AuthConfigurations;
4-
import com.github.dockerjava.api.model.EventStreamItem;
5-
63
import java.io.File;
7-
import java.io.IOException;
84
import java.io.InputStream;
95

6+
import com.github.dockerjava.api.model.AuthConfigurations;
7+
import com.github.dockerjava.api.model.BuildResponseItem;
8+
109
/**
11-
*
10+
*
1211
* Build an image from Dockerfile.
13-
*
12+
*
1413
* TODO: http://docs.docker.com/reference/builder/#dockerignore
15-
*
14+
*
1615
*/
17-
public interface BuildImageCmd extends DockerCmd<BuildImageCmd.Response> {
16+
public interface BuildImageCmd extends AsyncDockerCmd<BuildImageCmd, BuildResponseItem, Void> {
1817

1918
public BuildImageCmd withTag(String tag);
2019

@@ -58,14 +57,9 @@ public interface BuildImageCmd extends DockerCmd<BuildImageCmd.Response> {
5857

5958
public BuildImageCmd withBuildAuthConfigs(AuthConfigurations authConfig);
6059

61-
public static interface Exec extends DockerCmdExec<BuildImageCmd, BuildImageCmd.Response> {
60+
public static interface Exec extends DockerCmdExec<BuildImageCmd, Void> {
6261
}
6362

64-
/**
65-
* @see {@link com.github.dockerjava.core.command.EventStreamReader}
66-
*/
67-
public static abstract class Response extends InputStream {
68-
public abstract Iterable<EventStreamItem> getItems() throws IOException;
69-
}
63+
7064

7165
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,12 @@ public interface LogContainerCmd extends AsyncDockerCmd<LogContainerCmd, Frame,
6565
public LogContainerCmd withTail(int tail);
6666

6767
/**
68-
* Its the responsibility of the caller to consume and/or close the {@link InputStream} to prevent connection leaks.
6968
*
7069
* @throws NotFoundException
7170
* No such container
7271
*/
7372
@Override
74-
public Void exec() throws NotFoundException;
73+
public Void exec();
7574

7675
public static interface Exec extends DockerCmdExec<LogContainerCmd, Void> {
7776
}

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.dockerjava.api.command;
22

33
import com.github.dockerjava.api.model.AuthConfig;
4+
import com.github.dockerjava.api.model.PullResponseItem;
45
import com.github.dockerjava.core.command.EventStreamReader;
56

67
import java.io.InputStream;
@@ -10,7 +11,7 @@
1011
* Pull image from repository.
1112
*
1213
*/
13-
public interface PullImageCmd extends DockerCmd<InputStream> {
14+
public interface PullImageCmd extends AsyncDockerCmd<PullImageCmd, PullResponseItem, Void> {
1415

1516
public String getRepository();
1617

@@ -28,15 +29,10 @@ public interface PullImageCmd extends DockerCmd<InputStream> {
2829

2930
public PullImageCmd withAuthConfig(AuthConfig authConfig);
3031

31-
public static interface Exec extends DockerCmdExec<PullImageCmd, InputStream> {
32+
public static interface Exec extends DockerCmdExec<PullImageCmd, Void> {
3233
}
3334

34-
/**
35-
* Its the responsibility of the caller to consume and/or close the {@link InputStream} to prevent connection leaks.
36-
*
37-
* @see {@link EventStreamReader}
38-
*/
3935
@Override
40-
public InputStream exec();
36+
public Void exec();
4137

4238
}

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,15 @@
22

33
import com.github.dockerjava.api.NotFoundException;
44
import com.github.dockerjava.api.model.AuthConfig;
5-
import com.github.dockerjava.api.model.PushEventStreamItem;
6-
import com.github.dockerjava.core.command.EventStreamReader;
7-
8-
import java.io.IOException;
9-
import java.io.InputStream;
5+
import com.github.dockerjava.api.model.PushResponseItem;
106

117
/**
128
* Push the latest image to the repository.
139
*
1410
* @param name
1511
* The name, e.g. "alexec/busybox" or just "busybox" if you want to default. Not null.
1612
*/
17-
public interface PushImageCmd extends DockerCmd<PushImageCmd.Response> {
13+
public interface PushImageCmd extends AsyncDockerCmd<PushImageCmd, PushResponseItem, Void> {
1814

1915
public String getName();
2016

@@ -40,16 +36,8 @@ public interface PushImageCmd extends DockerCmd<PushImageCmd.Response> {
4036
* @throws NotFoundException
4137
* No such image
4238
*/
43-
public Response exec() throws NotFoundException;
44-
45-
public static interface Exec extends DockerCmdExec<PushImageCmd, Response> {
46-
}
39+
public Void exec() throws NotFoundException;
4740

48-
/**
49-
* @see {@link EventStreamReader}
50-
*/
51-
public static abstract class Response extends InputStream {
52-
public abstract Iterable<PushEventStreamItem> getItems() throws IOException;
41+
public static interface Exec extends DockerCmdExec<PushImageCmd, Void> {
5342
}
54-
5543
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.github.dockerjava.api.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
/**
7+
* Represents a build response stream item
8+
*/
9+
@JsonIgnoreProperties(ignoreUnknown = false)
10+
public class BuildResponseItem extends ResponseItem {
11+
12+
private static final long serialVersionUID = -1252904184236343612L;
13+
14+
@JsonProperty("stream")
15+
private String stream;
16+
17+
public String getStream() {
18+
return stream;
19+
}
20+
}

src/main/java/com/github/dockerjava/api/model/EventStreamItem.java

Lines changed: 0 additions & 59 deletions
This file was deleted.

src/main/java/com/github/dockerjava/api/model/PullEventStreamItem.java

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)