Search in sources :

Example 1 with InspectImageResponse

use of com.github.dockerjava.api.command.InspectImageResponse in project vespa by vespa-engine.

the class DockerImplTest method pullImageAsyncIfNeededSuccessfully.

@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void pullImageAsyncIfNeededSuccessfully() {
    final DockerImage image = new DockerImage("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);
    final DockerClient dockerClient = mock(DockerClient.class);
    when(dockerClient.inspectImageCmd(image.asString())).thenReturn(imageInspectCmd);
    when(dockerClient.pullImageCmd(eq(image.asString()))).thenReturn(pullImageCmd);
    final DockerImpl docker = new DockerImpl(dockerClient);
    docker.setMetrics(new MetricReceiverWrapper(MetricReceiver.nullImplementation));
    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));
}
Also used : InspectImageCmd(com.github.dockerjava.api.command.InspectImageCmd) MetricReceiverWrapper(com.yahoo.vespa.hosted.dockerapi.metrics.MetricReceiverWrapper) ExecStartResultCallback(com.github.dockerjava.core.command.ExecStartResultCallback) ResultCallback(com.github.dockerjava.api.async.ResultCallback) DockerClient(com.github.dockerjava.api.DockerClient) PullImageCmd(com.github.dockerjava.api.command.PullImageCmd) InspectImageResponse(com.github.dockerjava.api.command.InspectImageResponse) NotFoundException(com.github.dockerjava.api.exception.NotFoundException) Test(org.junit.Test)

Example 2 with InspectImageResponse

use of com.github.dockerjava.api.command.InspectImageResponse in project elastest-torm by elastest.

the class EtmContextService method loadHelpInfoFromImages.

private void loadHelpInfoFromImages() {
    List<String> imagesNames = Arrays.asList(etImages.split(","));
    helpInfo = new HelpInfo();
    imagesNames.forEach((imageName) -> {
        try {
            InspectImageResponse imageInfo = dockerService.getImageInfoByName(imageName);
            VersionInfo imageVersionInfo = new VersionInfo(imageInfo.getConfig().getLabels().get("git_commit"), imageInfo.getConfig().getLabels().get("commit_date"), imageInfo.getConfig().getLabels().get("version"));
            helpInfo.getVersionsInfo().put(imageName, imageVersionInfo);
        } catch (Exception e) {
            logger.error("Unable to retrieve ElasTest Help Information.");
        }
    });
}
Also used : VersionInfo(io.elastest.etm.model.VersionInfo) InspectImageResponse(com.github.dockerjava.api.command.InspectImageResponse) HelpInfo(io.elastest.etm.model.HelpInfo)

Example 3 with InspectImageResponse

use of com.github.dockerjava.api.command.InspectImageResponse in project elastest-torm by elastest.

the class DockerService2 method getImageInfoByName.

public InspectImageResponse getImageInfoByName(String imageName) {
    InspectImageResponse response = null;
    DockerClient dockerClient = getDockerClient();
    if (imageExistsLocally(imageName, dockerClient)) {
        try {
            response = dockerClient.inspectImageCmd(imageName).exec();
        } catch (Exception e) {
            logger.error("Error loading image \"{}\" information.", imageName);
            throw e;
        }
    }
    return response;
}
Also used : DockerClient(com.github.dockerjava.api.DockerClient) InspectImageResponse(com.github.dockerjava.api.command.InspectImageResponse) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NotModifiedException(com.github.dockerjava.api.exception.NotModifiedException) DockerClientException(com.github.dockerjava.api.exception.DockerClientException) InternalServerErrorException(com.github.dockerjava.api.exception.InternalServerErrorException) NotFoundException(com.github.dockerjava.api.exception.NotFoundException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 4 with InspectImageResponse

use of com.github.dockerjava.api.command.InspectImageResponse in project tutorials by eugenp.

the class ImageLiveTest method givenListOfImages_whenInspectImage_thenMustReturnObject.

@Test
public void givenListOfImages_whenInspectImage_thenMustReturnObject() {
    // given
    List<Image> images = dockerClient.listImagesCmd().exec();
    Image image = images.get(0);
    // when
    InspectImageResponse imageResponse = dockerClient.inspectImageCmd(image.getId()).exec();
    // then
    assertThat(imageResponse.getId(), is(image.getId()));
}
Also used : InspectImageResponse(com.github.dockerjava.api.command.InspectImageResponse) Image(com.github.dockerjava.api.model.Image) Test(org.junit.Test)

Example 5 with InspectImageResponse

use of com.github.dockerjava.api.command.InspectImageResponse in project hub-docker-inspector by blackducksoftware.

the class DockerClientManager method getTarFileFromDockerImageById.

public File getTarFileFromDockerImageById(final String imageId) throws HubIntegrationException, IOException {
    final File imageTarDirectory = new File(new File(programPaths.getHubDockerWorkingDirPath()), "tarDirectory");
    final DockerClient dockerClient = hubDockerClient.getDockerClient();
    final InspectImageCmd inspectImageCmd = dockerClient.inspectImageCmd(imageId);
    final InspectImageResponse imageDetails = inspectImageCmd.exec();
    final List<String> repoTags = imageDetails.getRepoTags();
    if (repoTags.size() == 0) {
        throw new HubIntegrationException(String.format("Unable to get image name:tag for image ID %s", imageId));
    }
    final ImageNameResolver resolver = new ImageNameResolver(repoTags.get(0));
    final String imageName = resolver.getNewImageRepo().get();
    final String tagName = resolver.getNewImageTag().get();
    logger.info(String.format("Converted image ID %s to image name:tag %s:%s", imageId, imageName, tagName));
    final File imageTarFile = saveImageToDir(imageTarDirectory, Names.getImageTarFilename(imageName, tagName), imageName, tagName);
    return imageTarFile;
}
Also used : InspectImageCmd(com.github.dockerjava.api.command.InspectImageCmd) DockerClient(com.github.dockerjava.api.DockerClient) ImageNameResolver(com.blackducksoftware.integration.hub.imageinspector.name.ImageNameResolver) InspectImageResponse(com.github.dockerjava.api.command.InspectImageResponse) File(java.io.File) HubIntegrationException(com.blackducksoftware.integration.hub.exception.HubIntegrationException)

Aggregations

InspectImageResponse (com.github.dockerjava.api.command.InspectImageResponse)5 DockerClient (com.github.dockerjava.api.DockerClient)3 InspectImageCmd (com.github.dockerjava.api.command.InspectImageCmd)2 NotFoundException (com.github.dockerjava.api.exception.NotFoundException)2 Test (org.junit.Test)2 HubIntegrationException (com.blackducksoftware.integration.hub.exception.HubIntegrationException)1 ImageNameResolver (com.blackducksoftware.integration.hub.imageinspector.name.ImageNameResolver)1 ResultCallback (com.github.dockerjava.api.async.ResultCallback)1 PullImageCmd (com.github.dockerjava.api.command.PullImageCmd)1 DockerClientException (com.github.dockerjava.api.exception.DockerClientException)1 InternalServerErrorException (com.github.dockerjava.api.exception.InternalServerErrorException)1 NotModifiedException (com.github.dockerjava.api.exception.NotModifiedException)1 Image (com.github.dockerjava.api.model.Image)1 ExecStartResultCallback (com.github.dockerjava.core.command.ExecStartResultCallback)1 MetricReceiverWrapper (com.yahoo.vespa.hosted.dockerapi.metrics.MetricReceiverWrapper)1 HelpInfo (io.elastest.etm.model.HelpInfo)1 VersionInfo (io.elastest.etm.model.VersionInfo)1 File (java.io.File)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1