use of com.spotify.docker.client.exceptions.DockerRequestException in project docker-client by spotify.
the class DefaultDockerClient method propagate.
private RuntimeException propagate(final String method, final WebTarget resource, final Exception ex) throws DockerException, InterruptedException {
Throwable cause = ex.getCause();
// So we unpack it here.
if (ex instanceof MultiException) {
cause = cause.getCause();
}
Response response = null;
if (cause instanceof ResponseProcessingException) {
response = ((ResponseProcessingException) cause).getResponse();
} else if (cause instanceof WebApplicationException) {
response = ((WebApplicationException) cause).getResponse();
} else if ((cause instanceof ProcessingException) && (cause.getCause() != null)) {
// For a ProcessingException, The exception message or nested Throwable cause SHOULD contain
// additional information about the reason of the processing failure.
cause = cause.getCause();
}
if (response != null) {
throw new DockerRequestException(method, resource.getUri(), response.getStatus(), message(response), cause);
} else if ((cause instanceof SocketTimeoutException) || (cause instanceof ConnectTimeoutException)) {
throw new DockerTimeoutException(method, resource.getUri(), ex);
} else if ((cause instanceof InterruptedIOException) || (cause instanceof InterruptedException)) {
throw new InterruptedException("Interrupted: " + method + " " + resource);
} else {
throw new DockerException(ex);
}
}
use of com.spotify.docker.client.exceptions.DockerRequestException in project docker-client by spotify.
the class DefaultDockerClient method push.
@Override
public void push(final String image, final ProgressHandler handler, final RegistryAuth registryAuth) throws DockerException, InterruptedException {
final ImageRef imageRef = new ImageRef(image);
WebTarget resource = resource().path("images").path(imageRef.getImage()).path("push");
if (imageRef.getTag() != null) {
resource = resource.queryParam("tag", imageRef.getTag());
}
try (ProgressStream push = request(POST, ProgressStream.class, resource, resource.request(APPLICATION_JSON_TYPE).header("X-Registry-Auth", authHeader(registryAuth)))) {
push.tail(handler, POST, resource.getUri());
} catch (IOException e) {
throw new DockerException(e);
} catch (DockerRequestException e) {
switch(e.status()) {
case 404:
throw new ImageNotFoundException(image, e);
default:
throw e;
}
}
}
use of com.spotify.docker.client.exceptions.DockerRequestException in project docker-client by spotify.
the class DefaultDockerClient method execStart.
@Override
public LogStream execStart(final String execId, final ExecStartParameter... params) throws DockerException, InterruptedException {
final WebTarget resource = noTimeoutResource().path("exec").path(execId).path("start");
final StringWriter writer = new StringWriter();
try {
final JsonGenerator generator = objectMapper().getFactory().createGenerator(writer);
generator.writeStartObject();
for (final ExecStartParameter param : params) {
generator.writeBooleanField(param.getName(), true);
}
generator.writeEndObject();
generator.close();
} catch (IOException e) {
throw new DockerException(e);
}
try {
return request(POST, LogStream.class, resource, resource.request("application/vnd.docker.raw-stream"), Entity.json(writer.toString()));
} catch (DockerRequestException e) {
switch(e.status()) {
case 404:
throw new ExecNotFoundException(execId, e);
case 409:
throw new ExecStartConflictException(execId, e);
default:
throw e;
}
}
}
use of com.spotify.docker.client.exceptions.DockerRequestException in project docker-client by spotify.
the class DefaultDockerClient method commitContainer.
@Override
public ContainerCreation commitContainer(final String containerId, final String repo, final String tag, final ContainerConfig config, final String comment, final String author) throws DockerException, InterruptedException {
checkNotNull(containerId, "containerId");
checkNotNull(repo, "repo");
checkNotNull(config, "containerConfig");
WebTarget resource = resource().path("commit").queryParam("container", containerId).queryParam("repo", repo);
if (!isNullOrEmpty(author)) {
resource = resource.queryParam("author", author);
}
if (!isNullOrEmpty(comment)) {
resource = resource.queryParam("comment", comment);
}
if (!isNullOrEmpty(tag)) {
resource = resource.queryParam("tag", tag);
}
log.debug("Committing container id: {} to repository: {} with ContainerConfig: {}", containerId, repo, config);
try {
return request(POST, ContainerCreation.class, resource, resource.request(APPLICATION_JSON_TYPE), Entity.json(config));
} catch (DockerRequestException e) {
switch(e.status()) {
case 404:
throw new ContainerNotFoundException(containerId, e);
default:
throw e;
}
}
}
use of com.spotify.docker.client.exceptions.DockerRequestException in project docker-client by spotify.
the class DefaultDockerClient method removeService.
@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;
}
}
}
Aggregations