com.github.dockerjava.api.exception.ConflictException Java Examples
The following examples show how to use
com.github.dockerjava.api.exception.ConflictException.
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: ContainerUtil.java From presto with Apache License 2.0 | 6 votes |
public static void killContainers(DockerClient dockerClient, Function<ListContainersCmd, ListContainersCmd> filter) { while (true) { ListContainersCmd listContainersCmd = filter.apply(dockerClient.listContainersCmd() .withShowAll(true)); List<Container> containers = listContainersCmd.exec(); if (containers.isEmpty()) { break; } for (Container container : containers) { try { dockerClient.removeContainerCmd(container.getId()) .withForce(true) .exec(); } catch (ConflictException | NotFoundException ignored) { } } } }
Example #2
Source File: ResponseStatusExceptionFilter.java From docker-java with Apache License 2.0 | 6 votes |
@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); } }
Example #3
Source File: CreateServiceCmdExecIT.java From docker-java with Apache License 2.0 | 6 votes |
@Test @Ignore // TODO rework test (does not throw as expected atm) public void testCreateServiceWithInvalidAuth() throws DockerException { AuthConfig invalidAuthConfig = new AuthConfig() .withUsername("testuser") .withPassword("testwrongpassword") .withEmail("[email protected]") .withRegistryAddress(authConfig.getRegistryAddress()); exception.expect(ConflictException.class); dockerClient.createServiceCmd(new ServiceSpec() .withName(SERVICE_NAME) .withTaskTemplate(new TaskSpec() .withContainerSpec(new ContainerSpec() .withImage(DEFAULT_IMAGE)))) .withAuthConfig(invalidAuthConfig) .exec(); }
Example #4
Source File: CreateContainerCmdIT.java From docker-java with Apache License 2.0 | 6 votes |
@Test(expected = ConflictException.class) public void createContainerWithName() throws DockerException { String containerName = "container_" + dockerRule.getKind(); CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE) .withName(containerName) .withCmd("env").exec(); LOG.info("Created container {}", container.toString()); assertThat(container.getId(), not(is(emptyString()))); InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec(); assertThat(inspectContainerResponse.getName(), equalTo("/" + containerName)); dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE) .withName(containerName) .withCmd("env") .exec(); }
Example #5
Source File: DockerBasedPublishingIntegrationTest.java From confluence-publisher with Apache License 2.0 | 5 votes |
private static void publishAndVerify(String pathToContent, Map<String, String> env, Runnable runnable) { try (GenericContainer<?> publisher = new GenericContainer<>("confluencepublisher/confluence-publisher:0.0.0-SNAPSHOT") .withEnv(env) .withNetwork(SHARED) .withClasspathResourceMapping("/" + pathToContent, "/var/asciidoc-root-folder", READ_ONLY) .withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger(DockerBasedPublishingIntegrationTest.class))) .waitingFor(forLogMessage(".*Documentation successfully published to Confluence.*", 1))) { publisher.start(); runnable.run(); } catch (ConflictException ignored) { // avoid test failures due to issues with already terminated confluence publisher container } }
Example #6
Source File: DefaultInvocationBuilder.java From docker-java with Apache License 2.0 | 5 votes |
protected DockerHttpClient.Response execute(DockerHttpClient.Request request) { try { DockerHttpClient.Response response = dockerHttpClient.execute(request); int statusCode = response.getStatusCode(); if (statusCode < 200 || statusCode > 299) { try { String body = IOUtils.toString(response.getBody(), StandardCharsets.UTF_8); switch (statusCode) { case 304: throw new NotModifiedException(body); case 400: throw new BadRequestException(body); case 401: throw new UnauthorizedException(body); case 404: throw new NotFoundException(body); case 406: throw new NotAcceptableException(body); case 409: throw new ConflictException(body); case 500: throw new InternalServerErrorException(body); default: throw new DockerException(body, statusCode); } } finally { response.close(); } } else { return response; } } catch (IOException e) { throw new RuntimeException(e); } }
Example #7
Source File: HttpResponseHandler.java From docker-java with Apache License 2.0 | 4 votes |
@Override protected void channelRead0(final ChannelHandlerContext ctx, HttpObject msg) throws Exception { if (msg instanceof HttpResponse) { response = (HttpResponse) msg; resultCallback.onStart(() -> ctx.channel().close()); } else if (msg instanceof HttpContent) { HttpContent content = (HttpContent) msg; ByteBuf byteBuf = content.content(); switch (response.status().code()) { case 200: case 201: case 204: ctx.fireChannelRead(byteBuf); break; default: errorBody.writeBytes(byteBuf); } if (content instanceof LastHttpContent) { try { switch (response.status().code()) { case 101: case 200: case 201: case 204: break; case 301: case 302: if (response.headers().contains(HttpHeaderNames.LOCATION)) { String location = response.headers().get(HttpHeaderNames.LOCATION); HttpRequest redirected = requestProvider.getHttpRequest(location); ctx.channel().writeAndFlush(redirected); } break; case 304: throw new NotModifiedException(getBodyAsMessage(errorBody)); case 400: throw new BadRequestException(getBodyAsMessage(errorBody)); case 401: throw new UnauthorizedException(getBodyAsMessage(errorBody)); case 404: throw new NotFoundException(getBodyAsMessage(errorBody)); case 406: throw new NotAcceptableException(getBodyAsMessage(errorBody)); case 409: throw new ConflictException(getBodyAsMessage(errorBody)); case 500: throw new InternalServerErrorException(getBodyAsMessage(errorBody)); default: throw new DockerException(getBodyAsMessage(errorBody), response.status().code()); } } catch (Throwable e) { resultCallback.onError(e); } finally { resultCallback.onComplete(); } } } }
Example #8
Source File: CreateContainerCmdIT.java From docker-java with Apache License 2.0 | 3 votes |
@Test(expected = ConflictException.class) public void createContainerWithExistingName() throws DockerException { String containerName = "generated_" + new SecureRandom().nextInt(); CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("env") .withName(containerName).exec(); LOG.info("Created container {}", container.toString()); assertThat(container.getId(), not(is(emptyString()))); dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("env").withName(containerName).exec(); }
Example #9
Source File: CreateServiceCmd.java From docker-java with Apache License 2.0 | 2 votes |
/** * @throws ConflictException * Named service already exists */ @Override CreateServiceResponse exec() throws ConflictException;
Example #10
Source File: CreateSecretCmd.java From docker-java with Apache License 2.0 | 2 votes |
/** * @throws ConflictException Named secret already exists */ @Override CreateSecretResponse exec() throws ConflictException;
Example #11
Source File: CreateContainerCmd.java From docker-java with Apache License 2.0 | 2 votes |
/** * @throws NotFoundException No such container * @throws ConflictException Named container already exists */ @Override CreateContainerResponse exec() throws NotFoundException, ConflictException;