com.github.dockerjava.api.command.InspectImageCmd Java Examples

The following examples show how to use com.github.dockerjava.api.command.InspectImageCmd. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DockerImplTest.java    From vespa with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings({"unchecked", "rawtypes"})
public void pullImageAsyncIfNeededWithError() {
    final DockerImage image = DockerImage.fromString("test:1.2.3");

    InspectImageCmd imageInspectCmd = mock(InspectImageCmd.class);
    when(imageInspectCmd.exec()).thenThrow(new NotFoundException("Image not found"));

    // Array to make it final
    ArgumentCaptor<ResultCallback> resultCallback = ArgumentCaptor.forClass(ResultCallback.class);
    PullImageCmd pullImageCmd = mock(PullImageCmd.class);
    when(pullImageCmd.exec(resultCallback.capture())).thenReturn(null);

    when(dockerClient.inspectImageCmd(image.asString())).thenReturn(imageInspectCmd);
    when(dockerClient.pullImageCmd(eq(image.asString()))).thenReturn(pullImageCmd);

    assertTrue("Should return true, we just scheduled the pull", docker.pullImageAsyncIfNeeded(image));
    assertTrue("Should return true, the pull i still ongoing", docker.pullImageAsyncIfNeeded(image));

    try {
        resultCallback.getValue().onComplete();
    } catch (Exception ignored) { }

    assertFalse(docker.imageIsDownloaded(image));
    assertTrue("Should return true, new pull scheduled", docker.pullImageAsyncIfNeeded(image));
}
 
Example #2
Source File: DockerImplTest.java    From vespa with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings({"unchecked", "rawtypes"})
public void pullImageAsyncIfNeededSuccessfully() {
    final DockerImage image = DockerImage.fromString("test:1.2.3");

    InspectImageResponse inspectImageResponse = mock(InspectImageResponse.class);
    when(inspectImageResponse.getId()).thenReturn(image.asString());

    InspectImageCmd imageInspectCmd = mock(InspectImageCmd.class);
    when(imageInspectCmd.exec())
            .thenThrow(new NotFoundException("Image not found"))
            .thenReturn(inspectImageResponse);

    // Array to make it final
    ArgumentCaptor<ResultCallback> resultCallback = ArgumentCaptor.forClass(ResultCallback.class);
    PullImageCmd pullImageCmd = mock(PullImageCmd.class);
    when(pullImageCmd.exec(resultCallback.capture())).thenReturn(null);

    when(dockerClient.inspectImageCmd(image.asString())).thenReturn(imageInspectCmd);
    when(dockerClient.pullImageCmd(eq(image.asString()))).thenReturn(pullImageCmd);

    assertTrue("Should return true, we just scheduled the pull", docker.pullImageAsyncIfNeeded(image));
    assertTrue("Should return true, the pull i still ongoing", docker.pullImageAsyncIfNeeded(image));

    assertTrue(docker.imageIsDownloaded(image));
    resultCallback.getValue().onComplete();
    assertFalse(docker.pullImageAsyncIfNeeded(image));
}
 
Example #3
Source File: InspectImageCmdExec.java    From docker-java with Apache License 2.0 5 votes vote down vote up
@Override
protected InspectImageResponse execute(InspectImageCmd command) {
    WebTarget webResource = getBaseResource().path("/images/{id}/json").resolveTemplate("id", command.getImageId());

    LOGGER.trace("GET: {}", webResource);

    return webResource.request().accept(MediaType.APPLICATION_JSON).get(new TypeReference<InspectImageResponse>() {
    });
}
 
Example #4
Source File: DockerImagePullStrategyTest.java    From docker-plugin with MIT License 5 votes vote down vote up
private DockerClient mockDockerClient() {
    InspectImageCmd cmd = mock(InspectImageCmd.class);
    if (existedImage)
        when(cmd.exec()).thenReturn(mock(InspectImageResponse.class));
    else
        when(cmd.exec()).thenThrow(new NotFoundException("not found"));
    DockerClient dockerClient = mock(DockerClient.class);
    when(dockerClient.inspectImageCmd(imageName)).thenReturn(cmd);

    return dockerClient;
}
 
Example #5
Source File: DockerClientImpl.java    From docker-java with Apache License 2.0 4 votes vote down vote up
@Override
public InspectImageCmd inspectImageCmd(String imageId) {
    return new InspectImageCmdImpl(getDockerCmdExecFactory().createInspectImageCmdExec(), imageId);
}
 
Example #6
Source File: AbstractDockerCmdExecFactory.java    From docker-java with Apache License 2.0 4 votes vote down vote up
@Override
public InspectImageCmd.Exec createInspectImageCmdExec() {
    return new InspectImageCmdExec(getBaseResource(), getDockerClientConfig());
}
 
Example #7
Source File: InspectImageCmdImpl.java    From docker-java with Apache License 2.0 4 votes vote down vote up
public InspectImageCmdImpl(InspectImageCmd.Exec exec, String imageId) {
    super(exec);
    withImageId(imageId);
}
 
Example #8
Source File: InspectImageCmdImpl.java    From docker-java with Apache License 2.0 4 votes vote down vote up
@Override
public InspectImageCmd withImageId(String imageId) {
    checkNotNull(imageId, "imageId was not specified");
    this.imageId = imageId;
    return this;
}
 
Example #9
Source File: DelegatingDockerClient.java    From docker-plugin with MIT License 4 votes vote down vote up
@Override
public InspectImageCmd inspectImageCmd(String arg0) {
    return getDelegate().inspectImageCmd(arg0);
}
 
Example #10
Source File: DockerClient.java    From docker-java with Apache License 2.0 votes vote down vote up
InspectImageCmd inspectImageCmd(@Nonnull String imageId);