-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Implementation of POST /images/load endpoint #627
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
Changes from all commits
Commits
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
21 changes: 21 additions & 0 deletions
21
src/main/java/com/github/dockerjava/api/command/LoadImageCmd.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,21 @@ | ||
| package com.github.dockerjava.api.command; | ||
|
|
||
| import java.io.InputStream; | ||
|
|
||
| import javax.annotation.CheckForNull; | ||
| import javax.annotation.Nonnull; | ||
|
|
||
| public interface LoadImageCmd extends SyncDockerCmd<Void> { | ||
|
|
||
| @CheckForNull | ||
| InputStream getImageStream(); | ||
|
|
||
| /** | ||
| * @param imageStream | ||
| * the InputStream of the tar file | ||
| */ | ||
| LoadImageCmd withImageStream(@Nonnull InputStream imageStream); | ||
|
|
||
| interface Exec extends DockerCmdSyncExec<LoadImageCmd, Void> { | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,11 @@ public class RemoteApiVersion implements Serializable { | |
|
|
||
| private static final Pattern VERSION_REGEX = Pattern.compile("v?(\\d+)\\.(\\d+)"); | ||
|
|
||
| /** | ||
| * Online documentation is not available anymore. | ||
| */ | ||
| public static final RemoteApiVersion VERSION_1_7 = RemoteApiVersion.create(1, 7); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sinde docker 1.7 or 1.7 API?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. found |
||
|
|
||
| /** | ||
| * @see <a href="http://docs.docker.com/engine/reference/api/docker_remote_api_v1.16/">Docker API 1.16</a> | ||
| */ | ||
|
|
||
39 changes: 39 additions & 0 deletions
39
src/main/java/com/github/dockerjava/core/command/LoadImageCmdImpl.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,39 @@ | ||
| package com.github.dockerjava.core.command; | ||
|
|
||
| import static com.google.common.base.Preconditions.checkNotNull; | ||
|
|
||
| import java.io.InputStream; | ||
|
|
||
| import com.github.dockerjava.api.command.LoadImageCmd; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
|
|
||
| public class LoadImageCmdImpl extends AbstrDockerCmd<LoadImageCmd, Void> implements LoadImageCmd { | ||
|
|
||
| private InputStream imageStream; | ||
|
|
||
| /** | ||
| * @param imageStream | ||
| * the InputStream of the tar file | ||
| */ | ||
| public LoadImageCmdImpl(LoadImageCmd.Exec exec, InputStream imageStream) { | ||
| super(exec); | ||
| withImageStream(imageStream); | ||
| } | ||
|
|
||
| @Override | ||
| public InputStream getImageStream() { | ||
| return imageStream; | ||
| } | ||
|
|
||
| /** | ||
| * @param imageStream | ||
| * the InputStream of the tar file | ||
| */ | ||
| @Override | ||
| public LoadImageCmdImpl withImageStream(@Nonnull InputStream imageStream) { | ||
| checkNotNull(imageStream, "imageStream was not specified"); | ||
| this.imageStream = imageStream; | ||
| return this; | ||
| } | ||
| } |
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
31 changes: 31 additions & 0 deletions
31
src/main/java/com/github/dockerjava/jaxrs/LoadImageCmdExec.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,31 @@ | ||
| package com.github.dockerjava.jaxrs; | ||
|
|
||
| import static javax.ws.rs.client.Entity.entity; | ||
|
|
||
| import javax.ws.rs.client.WebTarget; | ||
| import javax.ws.rs.core.MediaType; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import com.github.dockerjava.api.command.LoadImageCmd; | ||
| import com.github.dockerjava.core.DockerClientConfig; | ||
|
|
||
| public class LoadImageCmdExec extends AbstrSyncDockerCmdExec<LoadImageCmd, Void> implements LoadImageCmd.Exec { | ||
|
|
||
| private static final Logger LOGGER = LoggerFactory.getLogger(LoadImageCmdExec.class); | ||
|
|
||
| public LoadImageCmdExec(WebTarget baseResource, DockerClientConfig dockerClientConfig) { | ||
| super(baseResource, dockerClientConfig); | ||
| } | ||
|
|
||
| @Override | ||
| protected Void execute(LoadImageCmd command) { | ||
| WebTarget webTarget = getBaseResource().path("/images/load"); | ||
|
|
||
| LOGGER.trace("POST: {}", webTarget); | ||
| webTarget.request().post(entity(command.getImageStream(), MediaType.APPLICATION_OCTET_STREAM)); | ||
|
|
||
| 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
29 changes: 29 additions & 0 deletions
29
src/main/java/com/github/dockerjava/netty/exec/LoadImageCmdExec.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,29 @@ | ||
| package com.github.dockerjava.netty.exec; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import com.fasterxml.jackson.core.type.TypeReference; | ||
| import com.github.dockerjava.api.command.LoadImageCmd; | ||
| import com.github.dockerjava.core.DockerClientConfig; | ||
| import com.github.dockerjava.netty.WebTarget; | ||
|
|
||
| public class LoadImageCmdExec extends AbstrSyncDockerCmdExec<LoadImageCmd, Void> implements | ||
| LoadImageCmd.Exec { | ||
|
|
||
| private static final Logger LOGGER = LoggerFactory.getLogger(LoadImageCmdExec.class); | ||
|
|
||
| public LoadImageCmdExec(WebTarget baseResource, DockerClientConfig dockerClientConfig) { | ||
| super(baseResource, dockerClientConfig); | ||
| } | ||
|
|
||
| @Override | ||
| protected Void execute(LoadImageCmd command) { | ||
| WebTarget webResource = getBaseResource().path("/images/load"); | ||
|
|
||
| LOGGER.trace("POST: {}", webResource); | ||
| return webResource.request() | ||
| .post(new TypeReference<Void>() { | ||
| }, command.getImageStream()); | ||
| } | ||
| } |
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
76 changes: 76 additions & 0 deletions
76
src/test/java/com/github/dockerjava/core/command/LoadImageCmdImplTest.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,76 @@ | ||
| package com.github.dockerjava.core.command; | ||
|
|
||
| import com.github.dockerjava.api.model.Image; | ||
| import com.github.dockerjava.client.AbstractDockerClientTest; | ||
|
|
||
| import com.github.dockerjava.utils.TestResources; | ||
| import org.testng.ITestResult; | ||
| import org.testng.annotations.AfterMethod; | ||
| import org.testng.annotations.AfterTest; | ||
| import org.testng.annotations.BeforeMethod; | ||
| import org.testng.annotations.BeforeTest; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import java.io.InputStream; | ||
| import java.lang.reflect.Method; | ||
| import java.nio.file.Files; | ||
| import java.util.List; | ||
|
|
||
| import static java.util.Arrays.asList; | ||
| import static java.util.Collections.singletonList; | ||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.core.IsNull.notNullValue; | ||
| import static org.hamcrest.core.IsEqual.equalTo; | ||
|
|
||
| @Test(groups = "integration") | ||
| public class LoadImageCmdImplTest extends AbstractDockerClientTest { | ||
|
|
||
| private String expectedImageId; | ||
|
|
||
| @BeforeTest | ||
| public void beforeTest() throws Exception { | ||
| super.beforeTest(); | ||
| } | ||
|
|
||
| @AfterTest | ||
| public void afterTest() { | ||
| super.afterTest(); | ||
| } | ||
|
|
||
| @BeforeMethod | ||
| public void beforeMethod(Method method) { | ||
| super.beforeMethod(method); | ||
| expectedImageId = "sha256:56031f66eb0cef2e2e5cb2d1dabafaa0ebcd0a18a507d313b5bdb8c0472c5eba"; | ||
| if (findImageWithId(expectedImageId, dockerClient.listImagesCmd().exec()) != null) { | ||
| dockerClient.removeImageCmd(expectedImageId).exec(); | ||
| } | ||
| } | ||
|
|
||
| @AfterMethod | ||
| public void afterMethod(ITestResult result) { | ||
| dockerClient.removeImageCmd(expectedImageId).exec(); | ||
| super.afterMethod(result); | ||
| } | ||
|
|
||
| @Test | ||
| public void loadImageFromTar() throws Exception { | ||
| try (InputStream uploadStream = Files.newInputStream(TestResources.getApiImagesLoadTestTarball())) { | ||
| dockerClient.loadImageCmd(uploadStream).exec(); | ||
| } | ||
|
|
||
| final Image image = findImageWithId(expectedImageId, dockerClient.listImagesCmd().exec()); | ||
|
|
||
| assertThat("Can't find expected image after loading from a tar archive!", image, notNullValue()); | ||
| assertThat("Image after loading from a tar archive has wrong tags!", | ||
| asList(image.getRepoTags()), equalTo(singletonList("docker-java/load:1.0"))); | ||
| } | ||
|
|
||
| private Image findImageWithId(final String id, final List<Image> images) { | ||
| for (Image image : images) { | ||
| if (id.equals(image.getId())) { | ||
| return image; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this feature appeared in docker API? Could you place javadoc with
since(example could be found through search) ?