private void checkTtyParams(final Integer height, final Integer width) throws BadParamException { if ((height == null && width == null) || (height != null && height == 0) || (width != null && width == 0)) { final Map<String, String> paramMap = Maps.newHashMap(); paramMap.put("h", height == null ? null : height.toString()); paramMap.put("w", width == null ? null : width.toString()); throw new BadParamException(paramMap, "Either width or height must be non-null and > 0"); } }
@Override public void copyToContainer(InputStream tarStream, String containerId, String path) throws DockerException, InterruptedException { final WebTarget resource = resource() .path("containers") .path(containerId) .path("archive") .queryParam("noOverwriteDirNonDir", true) .queryParam("path", path); try { request(PUT, String.class, resource, resource.request(APPLICATION_OCTET_STREAM_TYPE), Entity.entity(tarStream, "application/tar")); } catch (DockerRequestException e) { switch (e.status()) { case 400: throw new BadParamException(getQueryParamMap(resource), e); case 403: throw new PermissionException("Volume or container rootfs is marked as read-only.", e); case 404: throw new NotFoundException( String.format("Either container %s or path %s not found.", containerId, path), e); default: throw e; } } }
@Override public List<Container> listContainers(final ListContainersParam... params) throws DockerException, InterruptedException { WebTarget resource = resource() .path("containers").path("json"); resource = addParameters(resource, params); try { return request(GET, CONTAINER_LIST, resource, resource.request(APPLICATION_JSON_TYPE)); } catch (DockerRequestException e) { switch (e.status()) { case 400: throw new BadParamException(getQueryParamMap(resource), e); default: throw e; } } }
private LogStream getLogStream(final String method, final WebTarget resource, final String containerId) throws DockerException, InterruptedException { try { final Invocation.Builder request = resource.request("application/vnd.docker.raw-stream"); return request(method, LogStream.class, resource, request); } catch (DockerRequestException e) { switch (e.status()) { case 400: throw new BadParamException(getQueryParamMap(resource), e); case 404: throw new ContainerNotFoundException(containerId); default: throw e; } } }
private LogStream getServiceLogStream(final String method, final WebTarget resource, final String serviceId) throws DockerException, InterruptedException { try { final Invocation.Builder request = resource.request("application/vnd.docker.raw-stream"); return request(method, LogStream.class, resource, request); } catch (DockerRequestException e) { switch (e.status()) { case 400: throw new BadParamException(getQueryParamMap(resource), e); case 404: throw new ServiceNotFoundException(serviceId); default: throw e; } } }
@Override public void removeContainer(final String containerId, final RemoveContainerParam... params) throws DockerException, InterruptedException { try { WebTarget resource = resource().path("containers").path(containerId); for (final RemoveContainerParam param : params) { resource = resource.queryParam(param.name(), param.value()); } request(DELETE, resource, resource.request(APPLICATION_JSON_TYPE)); } catch (DockerRequestException e) { switch (e.status()) { case 400: throw new BadParamException(getQueryParamMap(resource()), e); case 404: throw new ContainerNotFoundException(containerId, e); default: throw e; } } }
@Override public void tag(final String image, final String name, final boolean force) throws DockerException, InterruptedException { final ImageRef imageRef = new ImageRef(name); WebTarget resource = resource().path("images").path(image).path("tag"); resource = resource.queryParam("repo", imageRef.getImage()); if (imageRef.getTag() != null) { resource = resource.queryParam("tag", imageRef.getTag()); } if (force) { resource = resource.queryParam("force", true); } try { request(POST, resource, resource.request()); } catch (DockerRequestException e) { switch (e.status()) { case 400: throw new BadParamException(getQueryParamMap(resource), e); case 404: throw new ImageNotFoundException(image, e); case 409: throw new ConflictException(e); default: throw e; } } }
private void checkTtyParams(final Integer height, final Integer width) throws BadParamException { if ((height == null && width == null) || (height != null && height == 0) || (width != null && width == 0)) { final Map<String, String> paramMap = Maps.newHashMap(); paramMap.put("h", height == null ? null : height.toString()); paramMap.put("w", width == null ? null : width.toString()); throw new BadParamException(paramMap, "Either width or height must be non-null and > 0"); } }
private LogStream getServiceLogStream(final String method, final WebTarget resource, final String serviceId) throws DockerException, InterruptedException { try { final Invocation.Builder request = resource.request("application/vnd.docker.raw-stream"); return request(method, LogStream.class, resource, request); } catch (DockerRequestException e) { switch (e.status()) { case 400: throw new BadParamException(getQueryParamMap(resource), e); case 404: throw new ServiceNotFoundException(serviceId); default: throw e; } } }
private LogStream getLogStream(final String method, final WebTarget resource, final String containerId) throws DockerException, InterruptedException { try { final Invocation.Builder request = resource.request("application/vnd.docker.raw-stream"); return request(method, LogStream.class, resource, request); } catch (DockerRequestException e) { switch (e.status()) { case 400: throw new BadParamException(getQueryParamMap(resource), e); case 404: throw new ContainerNotFoundException(containerId); default: throw e; } } }
@Override public List<Container> listContainers(final ListContainersParam... params) throws DockerException, InterruptedException { WebTarget resource = resource() .path("containers").path("json"); resource = addParameters(resource, params); try { return request(GET, CONTAINER_LIST, resource, resource.request(APPLICATION_JSON_TYPE)); } catch (DockerRequestException e) { switch (e.status()) { case 400: throw new BadParamException(getQueryParamMap(resource), e); default: throw e; } } }
@Override public void copyToContainer(InputStream tarStream, String containerId, String path) throws DockerException, InterruptedException { final WebTarget resource = resource() .path("containers") .path(containerId) .path("archive") .queryParam("noOverwriteDirNonDir", true) .queryParam("path", path); try { request(PUT, String.class, resource, resource.request(APPLICATION_OCTET_STREAM_TYPE), Entity.entity(tarStream, "application/tar")); } catch (DockerRequestException e) { switch (e.status()) { case 400: throw new BadParamException(getQueryParamMap(resource), e); case 403: throw new PermissionException("Volume or container rootfs is marked as read-only.", e); case 404: throw new NotFoundException( String.format("Either container %s or path %s not found.", containerId, path), e); default: throw e; } } }
@Override public void removeContainer(final String containerId, final RemoveContainerParam... params) throws DockerException, InterruptedException { try { WebTarget resource = resource().path("containers").path(containerId); for (final RemoveContainerParam param : params) { resource = resource.queryParam(param.name(), param.value()); } request(DELETE, resource, resource.request(APPLICATION_JSON_TYPE)); } catch (DockerRequestException e) { switch (e.status()) { case 400: throw new BadParamException(getQueryParamMap(resource()), e); case 404: throw new ContainerNotFoundException(containerId, e); default: throw e; } } }
@Override public void tag(final String image, final String name, final boolean force) throws DockerException, InterruptedException { final ImageRef imageRef = new ImageRef(name); WebTarget resource = resource().path("images").path(image).path("tag"); resource = resource.queryParam("repo", imageRef.getImage()); if (imageRef.getTag() != null) { resource = resource.queryParam("tag", imageRef.getTag()); } if (force) { resource = resource.queryParam("force", true); } try { request(POST, resource, resource.request()); } catch (DockerRequestException e) { switch (e.status()) { case 400: throw new BadParamException(getQueryParamMap(resource), e); case 404: throw new ImageNotFoundException(image, e); case 409: throw new ConflictException(e); default: throw e; } } }