use of com.github.dockerjava.api.exception.NotFoundException in project hub-docker-inspector by blackducksoftware.
the class DockerClientManager method pullImage.
public String pullImage(final String imageName, final String tagName) throws HubIntegrationException {
logger.info(String.format("Pulling image %s:%s", imageName, tagName));
final DockerClient dockerClient = hubDockerClient.getDockerClient();
final Image alreadyPulledImage = getLocalImage(dockerClient, imageName, tagName);
if (alreadyPulledImage == null) {
// Only pull if we dont already have it
final PullImageCmd pull = dockerClient.pullImageCmd(imageName).withTag(tagName);
try {
pull.exec(new PullImageResultCallback()).awaitSuccess();
} catch (final NotFoundException e) {
final String msg = String.format("Pull failed: Image %s:%s not found. Please check the image name/tag", imageName, tagName);
logger.error(msg);
throw new HubIntegrationException(msg, e);
}
final Image justPulledImage = getLocalImage(dockerClient, imageName, tagName);
if (justPulledImage == null) {
final String msg = String.format("Pulled image %s:%s not found in image list.", imageName, tagName);
logger.error(msg);
throw new HubIntegrationException(msg);
}
return justPulledImage.getId();
} else {
logger.info("Image already pulled");
return alreadyPulledImage.getId();
}
}
use of com.github.dockerjava.api.exception.NotFoundException in project elastest-torm by elastest.
the class DockerService2 method pullETExecImage.
public void pullETExecImage(String image, String name) throws TJobStoppedException {
DockerClient dockerClient = this.getDockerClient();
try {
logger.debug("Try to Pulling {} Image ({})", name, image);
dockerClient.pullImageCmd(image).exec(new PullImageResultCallback()).awaitCompletion();
logger.debug("{} image pulled succesfully!", name);
} catch (InternalServerErrorException | NotFoundException | InterruptedException e) {
if (imageExistsLocally(image, dockerClient)) {
logger.info("Docker image exits locally.");
} else {
logger.error("Error pulling the {} image: {}", name, image, e.getMessage());
}
} catch (DockerClientException e) {
logger.info("Error on Pulling {} image ({}). Probably because the user has stopped the execution", name, image);
throw new TJobStoppedException();
}
}
use of com.github.dockerjava.api.exception.NotFoundException in project elastest-torm by elastest.
the class DockerService2 method existsContainer.
public boolean existsContainer(String containerName) {
DockerClient dockerClient = this.getDockerClient();
boolean exists = true;
try {
dockerClient.inspectContainerCmd(containerName).exec();
} catch (NotFoundException e) {
exists = false;
}
return exists;
}
use of com.github.dockerjava.api.exception.NotFoundException in project testcontainers-java by testcontainers.
the class DockerClientFactoryTest method runCommandInsideDockerShouldNotFailIfImageDoesNotExistsLocally.
@Test
public void runCommandInsideDockerShouldNotFailIfImageDoesNotExistsLocally() {
final DockerClientFactory dockFactory = DockerClientFactory.instance();
try {
// remove tiny image, so it will be pulled during next command run
dockFactory.client().removeImageCmd(TestcontainersConfiguration.getInstance().getTinyImage()).withForce(true).exec();
} catch (NotFoundException ignored) {
// Do not fail if it's not pulled yet
}
dockFactory.runInsideDocker(cmd -> cmd.withCmd("sh", "-c", "echo 'SUCCESS'"), (client, id) -> client.logContainerCmd(id).withStdOut(true).exec(new LogToStringContainerCallback()).toString());
}
use of com.github.dockerjava.api.exception.NotFoundException 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));
}
Aggregations