| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| 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> { | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -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); | ||
|
Comment thread
Copy link
Copy Markdown
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Qualitysinde docker 1.7 or 1.7 API?
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Qualityfound
Sorry, something went wrong.
All reactions
|
||
|
|
||
| /** | ||
| * @see <a href="http://docs.docker.com/engine/reference/api/docker_remote_api_v1.16/">Docker API 1.16</a> | ||
| */ | ||
| Expand Down | ||
| 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; | ||
| } | ||
| } |
| 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; | ||
| } | ||
| } |
| 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()); | ||
| } | ||
| } |
| 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; | ||
| } | ||
| } |
| Back | FazBrowse Home | New Git URL |
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityWhen this feature appeared in docker API? Could you place javadoc with since (example could be found through search) ?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.