public ProgressMessage nextMessage(final String method, final URI uri) throws DockerException { try { return iterator.nextValue(); } catch (SocketTimeoutException e) { throw new DockerTimeoutException(method, uri, e); } catch (IOException e) { throw new DockerException(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; } } }
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 Config inspectConfig(final String configId) throws DockerException, InterruptedException { assertApiVersionIsAbove("1.30"); final WebTarget resource = resource().path("configs").path(configId); try { return request(GET, Config.class, resource, resource.request(APPLICATION_JSON_TYPE)); } catch (final DockerRequestException ex) { switch (ex.status()) { case 404: throw new NotFoundException("Config " + configId + " not found.", ex); case 503: throw new NonSwarmNodeException("Config not part of swarm.", ex); default: throw ex; } } }
@Override public void removeVolume(final String volumeName) throws DockerException, InterruptedException { final WebTarget resource = resource().path("volumes").path(volumeName); try { request(DELETE, resource, resource.request(APPLICATION_JSON_TYPE)); } catch (DockerRequestException e) { switch (e.status()) { case 404: throw new VolumeNotFoundException(volumeName, e); case 409: throw new ConflictException("Volume is in use and cannot be removed", e); default: throw e; } } }
@Override public NodeInfo inspectNode(final String nodeId) throws DockerException, InterruptedException { assertApiVersionIsAbove("1.24"); WebTarget resource = resource().path("nodes") .path(nodeId); try { return request(GET, NodeInfo.class, resource, resource.request(APPLICATION_JSON_TYPE)); } catch (DockerRequestException e) { switch (e.status()) { case 404: throw new NodeNotFoundException(nodeId); case 503: throw new NonSwarmNodeException("Node " + nodeId + " is not in a swarm", e); default: throw e; } } }
@Override public Network inspectNetwork(String networkId) throws DockerException, InterruptedException { final WebTarget resource = resource().path("networks").path(networkId); try { return request(GET, Network.class, resource, resource.request(APPLICATION_JSON_TYPE)); } catch (DockerRequestException e) { switch (e.status()) { case 404: throw new NetworkNotFoundException(networkId, e); default: throw e; } } }
@Override public ContainerInfo inspectContainer(final String containerId) throws DockerException, InterruptedException { try { final WebTarget resource = resource().path("containers").path(containerId).path("json"); return request(GET, ContainerInfo.class, resource, resource.request(APPLICATION_JSON_TYPE)); } catch (DockerRequestException e) { switch (e.status()) { case 404: throw new ContainerNotFoundException(containerId, e); default: throw e; } } }
@Override public ImageInfo inspectImage(final String image) throws DockerException, InterruptedException { try { final WebTarget resource = resource().path("images").path(image).path("json"); return request(GET, ImageInfo.class, resource, resource.request(APPLICATION_JSON_TYPE)); } catch (DockerRequestException e) { switch (e.status()) { case 404: throw new ImageNotFoundException(image, e); default: throw e; } } }
@Override public ExecState execInspect(final String execId) throws DockerException, InterruptedException { final WebTarget resource = resource().path("exec").path(execId).path("json"); try { return request(GET, ExecState.class, resource, resource.request(APPLICATION_JSON_TYPE)); } catch (DockerRequestException e) { switch (e.status()) { case 404: throw new ExecNotFoundException(execId, e); default: throw e; } } }
@Override public Volume inspectVolume(final String volumeName) throws DockerException, InterruptedException { final WebTarget resource = resource().path("volumes").path(volumeName); try { return request(GET, Volume.class, resource, resource.request(APPLICATION_JSON_TYPE)); } catch (DockerRequestException e) { switch (e.status()) { case 404: throw new VolumeNotFoundException(volumeName, e); default: throw e; } } }
@Override public void removeService(final String serviceId) throws DockerException, InterruptedException { assertApiVersionIsAbove("1.24"); try { final WebTarget resource = resource().path("services").path(serviceId); request(DELETE, resource, resource.request(APPLICATION_JSON_TYPE)); } catch (DockerRequestException e) { switch (e.status()) { case 404: throw new ServiceNotFoundException(serviceId); default: throw e; } } }
@Override public void deleteSecret(final String secretId) throws DockerException, InterruptedException { assertApiVersionIsAbove("1.25"); final WebTarget resource = resource().path("secrets").path(secretId); try { request(DELETE, resource, resource.request(APPLICATION_JSON_TYPE)); } catch (final DockerRequestException ex) { switch (ex.status()) { case 404: throw new NotFoundException("Secret " + secretId + " not found.", ex); default: throw ex; } } }
@Override public Task inspectTask(final String taskId) throws DockerException, InterruptedException { assertApiVersionIsAbove("1.24"); try { final WebTarget resource = resource().path("tasks").path(taskId); return request(GET, Task.class, resource, resource.request(APPLICATION_JSON_TYPE)); } catch (DockerRequestException e) { switch (e.status()) { case 404: throw new TaskNotFoundException(taskId); default: throw e; } } }
@Override public List<Config> listConfigs() throws DockerException, InterruptedException { assertApiVersionIsAbove("1.30"); final WebTarget resource = resource().path("configs"); try { return request(GET, CONFIG_LIST, resource, resource.request(APPLICATION_JSON_TYPE)); } catch (DockerRequestException e) { switch (e.status()) { case 503: throw new NonSwarmNodeException("node is not part of a swarm", e); default: throw e; } } }
@Override public void deleteConfig(final String configId) throws DockerException, InterruptedException { assertApiVersionIsAbove("1.30"); final WebTarget resource = resource().path("configs").path(configId); try { request(DELETE, resource, resource.request(APPLICATION_JSON_TYPE)); } catch (final DockerRequestException ex) { switch (ex.status()) { case 404: throw new NotFoundException("Config " + configId + " not found.", ex); case 503: throw new NonSwarmNodeException("Config not part of a swarm.", ex); default: throw ex; } } }
public boolean hasNextMessage(final String method, final URI uri) throws DockerException { try { return iterator.hasNextValue(); } catch (SocketTimeoutException e) { throw new DockerTimeoutException(method, uri, e); } catch (IOException e) { throw new DockerException(e); } }
@Override public void removeNetwork(String networkId) throws DockerException, InterruptedException { try { final WebTarget resource = resource().path("networks").path(networkId); request(DELETE, resource, resource.request(APPLICATION_JSON_TYPE)); } catch (DockerRequestException e) { switch (e.status()) { case 404: throw new NetworkNotFoundException(networkId, e); default: throw e; } } }
@Override public ContainerStats stats(final String containerId) throws DockerException, InterruptedException { final WebTarget resource = resource().path("containers").path(containerId).path("stats") .queryParam("stream", "0"); try { return request(GET, ContainerStats.class, resource, resource.request(APPLICATION_JSON_TYPE)); } catch (DockerRequestException e) { switch (e.status()) { case 404: throw new ContainerNotFoundException(containerId, e); default: throw e; } } }
@Override public Secret inspectSecret(final String secretId) throws DockerException, InterruptedException { assertApiVersionIsAbove("1.25"); final WebTarget resource = resource().path("secrets").path(secretId); try { return request(GET, Secret.class, resource, resource.request(APPLICATION_JSON_TYPE)); } catch (final DockerRequestException ex) { switch (ex.status()) { case 404: throw new NotFoundException("Secret " + secretId + " not found.", ex); case 406: throw new NonSwarmNodeException("Server not part of swarm.", ex); default: throw ex; } } }