File tree Expand file tree Collapse file tree 12 files changed +220
-0
lines changed
docker-java-api/src/main/java/com/github/dockerjava/api
docker-java-core/src/main/java/com/github/dockerjava/core
docker-java/src/test/java/com/github/dockerjava/cmd Expand file tree Collapse file tree 12 files changed +220
-0
lines changed Original file line number Diff line number Diff line change 4242import com .github .dockerjava .api .command .ListSwarmNodesCmd ;
4343import com .github .dockerjava .api .command .ListTasksCmd ;
4444import com .github .dockerjava .api .command .ListVolumesCmd ;
45+ import com .github .dockerjava .api .command .LoadImageAsyncCmd ;
4546import com .github .dockerjava .api .command .LoadImageCmd ;
4647import com .github .dockerjava .api .command .LogContainerCmd ;
4748import com .github .dockerjava .api .command .LogSwarmObjectCmd ;
@@ -131,6 +132,8 @@ public interface DockerClient extends Closeable {
131132 */
132133 LoadImageCmd loadImageCmd (@ Nonnull InputStream imageStream );
133134
135+ LoadImageAsyncCmd loadImageAsyncCmd (@ Nonnull InputStream imageStream );
136+
134137 SearchImagesCmd searchImagesCmd (@ Nonnull String term );
135138
136139 RemoveImageCmd removeImageCmd (@ Nonnull String imageId );
Original file line number Diff line number Diff line change 4242import com .github .dockerjava .api .command .ListSwarmNodesCmd ;
4343import com .github .dockerjava .api .command .ListTasksCmd ;
4444import com .github .dockerjava .api .command .ListVolumesCmd ;
45+ import com .github .dockerjava .api .command .LoadImageAsyncCmd ;
4546import com .github .dockerjava .api .command .LoadImageCmd ;
4647import com .github .dockerjava .api .command .LogContainerCmd ;
4748import com .github .dockerjava .api .command .LogSwarmObjectCmd ;
@@ -153,6 +154,11 @@ public LoadImageCmd loadImageCmd(@Nonnull InputStream imageStream) {
153154 return getDockerClient ().loadImageCmd (imageStream );
154155 }
155156
157+ @ Override
158+ public LoadImageAsyncCmd loadImageAsyncCmd (@ Nonnull InputStream imageStream ) {
159+ return getDockerClient ().loadImageAsyncCmd (imageStream );
160+ }
161+
156162 @ Override
157163 public SearchImagesCmd searchImagesCmd (@ Nonnull String term ) {
158164 return getDockerClient ().searchImagesCmd (term );
Original file line number Diff line number Diff line change @@ -75,6 +75,11 @@ public LoadImageCmd.Exec createLoadImageCmdExec() {
7575 return getDockerCmdExecFactory ().createLoadImageCmdExec ();
7676 }
7777
78+ @ Override
79+ public LoadImageAsyncCmd .Exec createLoadImageAsyncCmdExec () {
80+ return getDockerCmdExecFactory ().createLoadImageAsyncCmdExec ();
81+ }
82+
7883 @ Override
7984 public SearchImagesCmd .Exec createSearchImagesCmdExec () {
8085 return getDockerCmdExecFactory ().createSearchImagesCmdExec ();
Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ public interface DockerCmdExecFactory extends Closeable {
2727
2828 LoadImageCmd .Exec createLoadImageCmdExec ();
2929
30+ LoadImageAsyncCmd .Exec createLoadImageAsyncCmdExec ();
31+
3032 SearchImagesCmd .Exec createSearchImagesCmdExec ();
3133
3234 RemoveImageCmd .Exec createRemoveImageCmdExec ();
Original file line number Diff line number Diff line change 1+ package com .github .dockerjava .api .command ;
2+
3+ import com .github .dockerjava .api .model .LoadResponseItem ;
4+
5+ import java .io .InputStream ;
6+
7+ public interface LoadImageAsyncCmd extends AsyncDockerCmd <LoadImageAsyncCmd , LoadResponseItem > {
8+ InputStream getImageStream ();
9+
10+ /**
11+ * @param imageStream the InputStream of the tar file
12+ */
13+ LoadImageAsyncCmd withImageStream (InputStream imageStream );
14+
15+ @ Override
16+ default LoadImageCallback start () {
17+ return exec (new LoadImageCallback ());
18+ }
19+
20+ interface Exec extends DockerCmdAsyncExec <LoadImageAsyncCmd , LoadResponseItem > {
21+ }
22+ }
Original file line number Diff line number Diff line change 1+ package com .github .dockerjava .api .command ;
2+
3+ import com .github .dockerjava .api .async .ResultCallbackTemplate ;
4+ import com .github .dockerjava .api .exception .DockerClientException ;
5+ import com .github .dockerjava .api .model .LoadResponseItem ;
6+ import org .slf4j .Logger ;
7+ import org .slf4j .LoggerFactory ;
8+
9+ public class LoadImageCallback extends ResultCallbackTemplate <LoadImageCallback , LoadResponseItem > {
10+
11+ private static final Logger LOGGER = LoggerFactory .getLogger (LoadImageCallback .class );
12+
13+ private String message ;
14+
15+ private String error ;
16+
17+ @ Override
18+ public void onNext (LoadResponseItem item ) {
19+ if (item .isBuildSuccessIndicated ()) {
20+ this .message = item .getMessage ();
21+ } else if (item .isErrorIndicated ()) {
22+ this .error = item .getError ();
23+ }
24+
25+ LOGGER .debug (item .toString ());
26+ }
27+
28+ public String awaitMessage () {
29+ try {
30+ awaitCompletion ();
31+ } catch (InterruptedException e ) {
32+ throw new DockerClientException ("" , e );
33+ }
34+
35+ return getMessage ();
36+ }
37+
38+ private String getMessage () {
39+ if (this .message != null ) {
40+ return this .message ;
41+ }
42+
43+ if (this .error == null ) {
44+ throw new DockerClientException ("Could not build image" );
45+ }
46+
47+ throw new DockerClientException ("Could not build image: " + this .error );
48+ }
49+ }
Original file line number Diff line number Diff line change 1+ package com .github .dockerjava .api .model ;
2+
3+ import com .fasterxml .jackson .annotation .JsonIgnore ;
4+
5+ public class LoadResponseItem extends ResponseItem {
6+
7+ private static final long serialVersionUID = 1L ;
8+
9+ private static final String IMPORT_SUCCESS = "Loaded image:" ;
10+
11+ /**
12+ * Returns whether the stream field indicates a successful build operation
13+ */
14+ @ JsonIgnore
15+ public boolean isBuildSuccessIndicated () {
16+ if (isErrorIndicated () || getStream () == null ) {
17+ return false ;
18+ }
19+
20+ return getStream ().contains (IMPORT_SUCCESS );
21+ }
22+
23+ @ JsonIgnore
24+ public String getMessage () {
25+ if (!isBuildSuccessIndicated ()) {
26+ return null ;
27+ } else if (getStream ().contains (IMPORT_SUCCESS )) {
28+ return getStream ();
29+ }
30+
31+ return null ;
32+ }
33+ }
Original file line number Diff line number Diff line change 4444import com .github .dockerjava .api .command .ListSwarmNodesCmd ;
4545import com .github .dockerjava .api .command .ListTasksCmd ;
4646import com .github .dockerjava .api .command .ListVolumesCmd ;
47+ import com .github .dockerjava .api .command .LoadImageAsyncCmd ;
4748import com .github .dockerjava .api .command .LoadImageCmd ;
4849import com .github .dockerjava .api .command .LogContainerCmd ;
4950import com .github .dockerjava .api .command .LogSwarmObjectCmd ;
101102import com .github .dockerjava .core .exec .ExecStartCmdExec ;
102103import com .github .dockerjava .core .exec .InspectConfigCmdExec ;
103104import com .github .dockerjava .core .exec .ListConfigsCmdExec ;
105+ import com .github .dockerjava .core .exec .LoadImageAsyncCmdExec ;
104106import com .github .dockerjava .core .exec .RemoveConfigCmdExec ;
105107import com .github .dockerjava .core .exec .ResizeContainerCmdExec ;
106108import com .github .dockerjava .core .exec .ResizeExecCmdExec ;
@@ -255,6 +257,11 @@ public LoadImageCmd.Exec createLoadImageCmdExec() {
255257 return new LoadImageCmdExec (getBaseResource (), getDockerClientConfig ());
256258 }
257259
260+ @ Override
261+ public LoadImageAsyncCmd .Exec createLoadImageAsyncCmdExec () {
262+ return new LoadImageAsyncCmdExec (getBaseResource (), getDockerClientConfig ());
263+ }
264+
258265 @ Override
259266 public SearchImagesCmd .Exec createSearchImagesCmdExec () {
260267 return new SearchImagesCmdExec (getBaseResource (), getDockerClientConfig ());
Original file line number Diff line number Diff line change 4444import com .github .dockerjava .api .command .ListSwarmNodesCmd ;
4545import com .github .dockerjava .api .command .ListTasksCmd ;
4646import com .github .dockerjava .api .command .ListVolumesCmd ;
47+ import com .github .dockerjava .api .command .LoadImageAsyncCmd ;
4748import com .github .dockerjava .api .command .LoadImageCmd ;
4849import com .github .dockerjava .api .command .LogContainerCmd ;
4950import com .github .dockerjava .api .command .LogSwarmObjectCmd ;
127128import com .github .dockerjava .core .command .ListSwarmNodesCmdImpl ;
128129import com .github .dockerjava .core .command .ListTasksCmdImpl ;
129130import com .github .dockerjava .core .command .ListVolumesCmdImpl ;
131+ import com .github .dockerjava .core .command .LoadImageAsyncCmdImpl ;
130132import com .github .dockerjava .core .command .LoadImageCmdImpl ;
131133import com .github .dockerjava .core .command .LogContainerCmdImpl ;
132134import com .github .dockerjava .core .command .LogSwarmObjectImpl ;
@@ -350,6 +352,11 @@ public LoadImageCmd loadImageCmd(@Nonnull InputStream imageStream) {
350352 return new LoadImageCmdImpl (getDockerCmdExecFactory ().createLoadImageCmdExec (), imageStream );
351353 }
352354
355+ @ Override
356+ public LoadImageAsyncCmd loadImageAsyncCmd (@ Nonnull InputStream imageStream ) {
357+ return new LoadImageAsyncCmdImpl (getDockerCmdExecFactory ().createLoadImageAsyncCmdExec (), imageStream );
358+ }
359+
353360 @ Override
354361 public SearchImagesCmd searchImagesCmd (String term ) {
355362 return new SearchImagesCmdImpl (getDockerCmdExecFactory ().createSearchImagesCmdExec (), term );
Original file line number Diff line number Diff line change 1+ package com .github .dockerjava .core .command ;
2+
3+ import com .github .dockerjava .api .command .LoadImageAsyncCmd ;
4+ import com .github .dockerjava .api .model .LoadResponseItem ;
5+
6+ import java .io .IOException ;
7+ import java .io .InputStream ;
8+
9+ import static com .google .common .base .Preconditions .checkNotNull ;
10+
11+ public class LoadImageAsyncCmdImpl extends AbstrAsyncDockerCmd <LoadImageAsyncCmd , LoadResponseItem > implements LoadImageAsyncCmd {
12+
13+ private InputStream inputStream ;
14+
15+ public LoadImageAsyncCmdImpl (LoadImageAsyncCmd .Exec exec , InputStream inputStream ) {
16+ super (exec );
17+ this .inputStream = inputStream ;
18+ }
19+
20+ @ Override
21+ public InputStream getImageStream () {
22+ return this .inputStream ;
23+ }
24+
25+ @ Override
26+ public LoadImageAsyncCmd withImageStream (InputStream imageStream ) {
27+ checkNotNull (imageStream , "imageStream was not specified" );
28+ this .inputStream = imageStream ;
29+ return this ;
30+ }
31+
32+ @ Override
33+ public void close () {
34+ super .close ();
35+
36+ try {
37+ this .inputStream .close ();
38+ } catch (IOException e ) {
39+ throw new RuntimeException (e );
40+ }
41+ }
42+ }
You can’t perform that action at this time.
0 commit comments