use of com.github.dockerjava.api.command.InspectImageCmd in project camel by apache.
the class DockerProducer method executeInspectImageRequest.
/**
* Produces a inspect image request
*
* @param client
* @param message
* @return
*/
private InspectImageCmd executeInspectImageRequest(DockerClient client, Message message) {
LOGGER.debug("Executing Docker Inspect Image Request");
String imageId = DockerHelper.getProperty(DockerConstants.DOCKER_IMAGE_ID, configuration, message, String.class);
ObjectHelper.notNull(imageId, "Image ID must be specified");
InspectImageCmd inspectImageCmd = client.inspectImageCmd(imageId);
return inspectImageCmd;
}
use of com.github.dockerjava.api.command.InspectImageCmd 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));
}
use of com.github.dockerjava.api.command.InspectImageCmd in project vespa by vespa-engine.
the class DockerImplTest method pullImageAsyncIfNeededWithError.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void pullImageAsyncIfNeededWithError() {
final DockerImage image = new DockerImage("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);
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));
try {
resultCallback.getValue().onComplete();
} catch (Exception ignored) {
}
assertFalse(docker.imageIsDownloaded(image));
assertTrue("Should return true, new pull scheduled", docker.pullImageAsyncIfNeeded(image));
}
use of com.github.dockerjava.api.command.InspectImageCmd 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;
}
Aggregations