本文整理汇总了Java中com.github.dockerjava.api.exception.NotFoundException类的典型用法代码示例。如果您正苦于以下问题:Java NotFoundException类的具体用法?Java NotFoundException怎么用?Java NotFoundException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NotFoundException类属于com.github.dockerjava.api.exception包,在下文中一共展示了NotFoundException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: destroyInstance
import com.github.dockerjava.api.exception.NotFoundException; //导入依赖的package包/类
private ServiceInstance destroyInstance(ServiceInstance i, DockerClient client) {
if(i.getContainerId() != null) {
RemoveContainerCmd cmd = client.removeContainerCmd(i.getContainerId()).withForce(true);
try {
cmd.exec();
return i.withStatus(Status.TERMINATED);
} catch (NotFoundException e) {
logger.warning("No container with id " + i.getContainerId() + " found");
return i.withStatus(Status.TERMINATION_FAILED)
.withStatusDetails(e.getMessage());
}
} else {
return i.withStatus(Status.TERMINATION_FAILED)
.withStatusDetails("No container id found.");
}
}
示例2: deleteContainer
import com.github.dockerjava.api.exception.NotFoundException; //导入依赖的package包/类
@Override
public void deleteContainer(ContainerName containerName) {
try {
dockerImageGC.ifPresent(imageGC -> {
Optional<InspectContainerResponse> inspectResponse = inspectContainerCmd(containerName.asString());
inspectResponse.ifPresent(response -> imageGC.updateLastUsedTimeFor(response.getImageId()));
});
dockerClient.removeContainerCmd(containerName.asString()).exec();
} catch (NotFoundException ignored) {
// If container doesn't exist ignore
} catch (RuntimeException e) {
numberOfDockerDaemonFails.add();
throw new DockerException("Failed to delete container '" + containerName.asString() + "'", e);
}
}
示例3: pullImageAsyncIfNeededSuccessfully
import com.github.dockerjava.api.exception.NotFoundException; //导入依赖的package包/类
@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));
}
示例4: pullImageAsyncIfNeededWithError
import com.github.dockerjava.api.exception.NotFoundException; //导入依赖的package包/类
@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));
}
示例5: runInsideDocker
import com.github.dockerjava.api.exception.NotFoundException; //导入依赖的package包/类
private <T> T runInsideDocker(DockerClient client, Consumer<CreateContainerCmd> createContainerCmdConsumer, BiFunction<DockerClient, String, T> block) {
checkAndPullImage(client, TINY_IMAGE);
CreateContainerCmd createContainerCmd = client.createContainerCmd(TINY_IMAGE);
createContainerCmdConsumer.accept(createContainerCmd);
String id = createContainerCmd.exec().getId();
try {
client.startContainerCmd(id).exec();
return block.apply(client, id);
} finally {
try {
client.removeContainerCmd(id).withRemoveVolumes(true).withForce(true).exec();
} catch (NotFoundException | InternalServerErrorException ignored) {
log.debug("", ignored);
}
}
}
示例6: filter
import com.github.dockerjava.api.exception.NotFoundException; //导入依赖的package包/类
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
int status = responseContext.getStatus();
switch (status) {
case 200:
case 201:
case 204:
return;
case 304:
throw new NotModifiedException(getBodyAsMessage(responseContext));
case 400:
throw new BadRequestException(getBodyAsMessage(responseContext));
case 401:
throw new UnauthorizedException(getBodyAsMessage(responseContext));
case 404:
throw new NotFoundException(getBodyAsMessage(responseContext));
case 406:
throw new NotAcceptableException(getBodyAsMessage(responseContext));
case 409:
throw new ConflictException(getBodyAsMessage(responseContext));
case 500:
throw new InternalServerErrorException(getBodyAsMessage(responseContext));
default:
throw new DockerException(getBodyAsMessage(responseContext), status);
}
}
示例7: before
import com.github.dockerjava.api.exception.NotFoundException; //导入依赖的package包/类
@Override
protected void before() throws Throwable {
// LOG.info("======================= BEFORETEST =======================");
LOG.debug("Connecting to Docker server");
try {
getClient().inspectImageCmd(DEFAULT_IMAGE).exec();
} catch (NotFoundException e) {
LOG.info("Pulling image 'busybox'");
// need to block until image is pulled completely
getClient().pullImageCmd("busybox")
.withTag("latest")
.exec(new PullImageResultCallback())
.awaitSuccess();
}
// assertThat(getClient(), notNullValue());
// LOG.info("======================= END OF BEFORETEST =======================\n\n");
}
示例8: removeVolume
import com.github.dockerjava.api.exception.NotFoundException; //导入依赖的package包/类
@Test(expected = NotFoundException.class)
public void removeVolume() throws DockerException {
String volumeName = "volume1" + dockerRule.getKind();
CreateVolumeResponse createVolumeResponse = dockerRule.getClient().createVolumeCmd()
.withName(volumeName)
.withDriver("local").exec();
assertThat(createVolumeResponse.getName(), equalTo(volumeName));
assertThat(createVolumeResponse.getDriver(), equalTo("local"));
assertThat(createVolumeResponse.getMountpoint(), containsString(volumeName));
dockerRule.getClient().removeVolumeCmd(volumeName).exec();
dockerRule.getClient().inspectVolumeCmd(volumeName).exec();
}
示例9: execStartWithNonExistentUser
import com.github.dockerjava.api.exception.NotFoundException; //导入依赖的package包/类
@Test(expected = NotFoundException.class)
public void execStartWithNonExistentUser() throws Exception {
String containerName = "generated_" + new SecureRandom().nextInt();
CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("sleep", "9999")
.withName(containerName).exec();
LOG.info("Created container {}", container.toString());
assertThat(container.getId(), not(isEmptyString()));
dockerRule.getClient().startContainerCmd(container.getId()).exec();
ExecCreateCmdResponse execCreateCmdResponse = dockerRule.getClient().execCreateCmd(container.getId())
.withAttachStdout(true).withCmd("touch", "/execStartTest.log").withUser("NonExistentUser").exec();
dockerRule.getClient().execStartCmd(execCreateCmdResponse.getId()).withDetach(false).withTty(true)
.exec(new ExecStartResultCallback(System.out, System.err)).awaitCompletion();
dockerRule.getClient().copyArchiveFromContainerCmd(container.getId(), "/execStartTest.log").exec();
}
示例10: close
import com.github.dockerjava.api.exception.NotFoundException; //导入依赖的package包/类
@Override
public void close() throws Exception {
if (containerId != null) {
LOGGER.info("removing container {}", containerId);
try {
client.removeContainerCmd(containerId).withForce(true) // stop too
.exec();
} catch (NotFoundException | InternalServerErrorException ignored) {
LOGGER.info("ignoring {}", ignored.getMessage());
}
containerId = null;
}
if (repository != null) {
LOGGER.info("removing repository {}", repository);
try {
client.removeImageCmd(repository).withForce(true).exec();
} catch (NotFoundException | InternalServerErrorException e) {
LOGGER.info("ignoring {}", e.getMessage());
}
repository = null;
}
}
示例11: pullImage
import com.github.dockerjava.api.exception.NotFoundException; //导入依赖的package包/类
void pullImage(DockerAPI api, TaskListener listener) throws IOException, InterruptedException {
String image = getFullImageId();
final DockerClient client = api.getClient();
if (pullStrategy.shouldPullImage(client, image)) {
// TODO create a FlyWeightTask so end-user get visibility on pull operation progress
LOGGER.info("Pulling image '{}'. This may take awhile...", image);
long startTime = System.currentTimeMillis();
PullImageCmd cmd = client.pullImageCmd(image);
final DockerRegistryEndpoint registry = getRegistry();
DockerCloud.setRegistryAuthentication(cmd, registry, Jenkins.getInstance());
cmd.exec(new PullImageResultCallback() {
@Override
public void onNext(PullResponseItem item) {
listener.getLogger().println(item.getStatus());
}
}).awaitCompletion();
try {
client.inspectImageCmd(image).exec();
} catch (NotFoundException e) {
throw new DockerClientException("Could not pull image: " + image, e);
}
long pullTime = System.currentTimeMillis() - startTime;
LOGGER.info("Finished pulling image '{}', took {} ms", image, pullTime);
}
}
示例12: isRunning
import com.github.dockerjava.api.exception.NotFoundException; //导入依赖的package包/类
public static boolean isRunning(DockerClient docker, Instance instance) {
Value id = instance.findMetaDataByID(ModelHelper.DOCKER_ID);
if (id != null) {
try {
InspectContainerResponse containerRes = docker.inspectContainerCmd(id.getValue()).exec();
return containerRes.getState().getRunning();
} catch (NotFoundException ignore) {
return false;
}
} else {
return docker.listContainersCmd().exec()
.stream()
.filter(container -> container.getNames()[0].equals("/"+instance.getName()))
.findFirst()
.map(container -> container.getStatus().toLowerCase().startsWith("up"))
.orElse(false);
}
}
示例13: existsImage
import com.github.dockerjava.api.exception.NotFoundException; //导入依赖的package包/类
public boolean existsImage(String imageId) {
boolean exists = true;
try {
dockerClient.inspectImageCmd(imageId).exec();
log.trace("Docker image {} already exists", imageId);
} catch (NotFoundException e) {
log.trace("Image {} does not exist", imageId);
exists = false;
}
return exists;
}
示例14: existsContainer
import com.github.dockerjava.api.exception.NotFoundException; //导入依赖的package包/类
public boolean existsContainer(String containerName) {
boolean exists = true;
try {
dockerClient.inspectContainerCmd(containerName).exec();
log.trace("Container {} already exist", containerName);
} catch (NotFoundException e) {
log.trace("Container {} does not exist", containerName);
exists = false;
}
return exists;
}
示例15: pullImageIfRequired
import com.github.dockerjava.api.exception.NotFoundException; //导入依赖的package包/类
private void pullImageIfRequired(final DockerComponent dockerC) {
val image = dockerC.image();
val tag = dockerC.tag();
if (dockerC.isForcePull() || dockerCommands.isImageAvailable(image, tag)) {
log.info("Pulling image {}:{}", image, tag);
try {
dockerCommands.pullImage(image, tag);
} catch (final NotFoundException e) {
log.warn("Cannot pull image: {}", e.getMessage());
}
}
}