-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add load async operation #1982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add load async operation #1982
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
docker-java-api/src/main/java/com/github/dockerjava/api/command/LoadImageAsyncCmd.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package com.github.dockerjava.api.command; | ||
|
|
||
| import com.github.dockerjava.api.model.LoadResponseItem; | ||
|
|
||
| import java.io.InputStream; | ||
|
|
||
| public interface LoadImageAsyncCmd extends AsyncDockerCmd<LoadImageAsyncCmd, LoadResponseItem> { | ||
| InputStream getImageStream(); | ||
|
|
||
| /** | ||
| * @param imageStream the InputStream of the tar file | ||
| */ | ||
| LoadImageAsyncCmd withImageStream(InputStream imageStream); | ||
|
|
||
| @Override | ||
| default LoadImageCallback start() { | ||
| return exec(new LoadImageCallback()); | ||
| } | ||
|
|
||
| interface Exec extends DockerCmdAsyncExec<LoadImageAsyncCmd, LoadResponseItem> { | ||
| } | ||
| } |
49 changes: 49 additions & 0 deletions
49
docker-java-api/src/main/java/com/github/dockerjava/api/command/LoadImageCallback.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package com.github.dockerjava.api.command; | ||
|
|
||
| import com.github.dockerjava.api.async.ResultCallbackTemplate; | ||
| import com.github.dockerjava.api.exception.DockerClientException; | ||
| import com.github.dockerjava.api.model.LoadResponseItem; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class LoadImageCallback extends ResultCallbackTemplate<LoadImageCallback, LoadResponseItem> { | ||
|
|
||
| private static final Logger LOGGER = LoggerFactory.getLogger(LoadImageCallback.class); | ||
|
|
||
| private String message; | ||
|
|
||
| private String error; | ||
|
|
||
| @Override | ||
| public void onNext(LoadResponseItem item) { | ||
| if (item.isBuildSuccessIndicated()) { | ||
| this.message = item.getMessage(); | ||
| } else if (item.isErrorIndicated()) { | ||
| this.error = item.getError(); | ||
| } | ||
|
|
||
| LOGGER.debug(item.toString()); | ||
| } | ||
|
|
||
| public String awaitMessage() { | ||
| try { | ||
| awaitCompletion(); | ||
| } catch (InterruptedException e) { | ||
| throw new DockerClientException("", e); | ||
| } | ||
|
|
||
| return getMessage(); | ||
| } | ||
|
|
||
| private String getMessage() { | ||
| if (this.message != null) { | ||
| return this.message; | ||
| } | ||
|
|
||
| if (this.error == null) { | ||
| throw new DockerClientException("Could not build image"); | ||
| } | ||
|
|
||
| throw new DockerClientException("Could not build image: " + this.error); | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
docker-java-api/src/main/java/com/github/dockerjava/api/model/LoadResponseItem.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package com.github.dockerjava.api.model; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonIgnore; | ||
|
|
||
| public class LoadResponseItem extends ResponseItem { | ||
|
|
||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| private static final String IMPORT_SUCCESS = "Loaded image:"; | ||
|
|
||
| /** | ||
| * Returns whether the stream field indicates a successful build operation | ||
| */ | ||
| @JsonIgnore | ||
| public boolean isBuildSuccessIndicated() { | ||
| if (isErrorIndicated() || getStream() == null) { | ||
| return false; | ||
| } | ||
|
|
||
| return getStream().contains(IMPORT_SUCCESS); | ||
| } | ||
|
|
||
| @JsonIgnore | ||
| public String getMessage() { | ||
| if (!isBuildSuccessIndicated()) { | ||
| return null; | ||
| } else if (getStream().contains(IMPORT_SUCCESS)) { | ||
| return getStream(); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
docker-java-core/src/main/java/com/github/dockerjava/core/command/LoadImageAsyncCmdImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package com.github.dockerjava.core.command; | ||
|
|
||
| import com.github.dockerjava.api.command.LoadImageAsyncCmd; | ||
| import com.github.dockerjava.api.model.LoadResponseItem; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
|
|
||
| import static com.google.common.base.Preconditions.checkNotNull; | ||
|
|
||
| public class LoadImageAsyncCmdImpl extends AbstrAsyncDockerCmd<LoadImageAsyncCmd, LoadResponseItem> implements LoadImageAsyncCmd { | ||
|
|
||
| private InputStream inputStream; | ||
|
|
||
| public LoadImageAsyncCmdImpl(LoadImageAsyncCmd.Exec exec, InputStream inputStream) { | ||
| super(exec); | ||
| this.inputStream = inputStream; | ||
| } | ||
|
|
||
| @Override | ||
| public InputStream getImageStream() { | ||
| return this.inputStream; | ||
| } | ||
|
|
||
| @Override | ||
| public LoadImageAsyncCmd withImageStream(InputStream imageStream) { | ||
| checkNotNull(imageStream, "imageStream was not specified"); | ||
| this.inputStream = imageStream; | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| super.close(); | ||
|
|
||
| try { | ||
| this.inputStream.close(); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
docker-java-core/src/main/java/com/github/dockerjava/core/exec/LoadImageAsyncCmdExec.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package com.github.dockerjava.core.exec; | ||
|
|
||
| import com.fasterxml.jackson.core.type.TypeReference; | ||
| import com.github.dockerjava.api.async.ResultCallback; | ||
| import com.github.dockerjava.api.command.LoadImageAsyncCmd; | ||
| import com.github.dockerjava.api.model.LoadResponseItem; | ||
| import com.github.dockerjava.core.DockerClientConfig; | ||
| import com.github.dockerjava.core.WebTarget; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class LoadImageAsyncCmdExec extends AbstrAsyncDockerCmdExec<LoadImageAsyncCmd, LoadResponseItem> implements LoadImageAsyncCmd.Exec { | ||
|
|
||
| private static final Logger LOGGER = LoggerFactory.getLogger(LoadImageAsyncCmdExec.class); | ||
|
|
||
| public LoadImageAsyncCmdExec(WebTarget baseResource, DockerClientConfig dockerClientConfig) { | ||
| super(baseResource, dockerClientConfig); | ||
| } | ||
|
|
||
| @Override | ||
| protected Void execute0(LoadImageAsyncCmd command, ResultCallback<LoadResponseItem> resultCallback) { | ||
| WebTarget webTarget = getBaseResource().path("/images/load"); | ||
|
|
||
| LOGGER.trace("POST: {}", webTarget); | ||
|
|
||
| webTarget.request().post(new TypeReference<LoadResponseItem>() { }, resultCallback, command.getImageStream()); | ||
|
|
||
| return null; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.