use of com.spotify.docker.client.exceptions.DockerRequestException in project docker-client by spotify.
the class DefaultDockerClient method deleteNode.
@Override
public void deleteNode(final String nodeId, final boolean force) throws DockerException, InterruptedException {
assertApiVersionIsAbove("1.24");
final WebTarget resource = resource().path("nodes").path(nodeId).queryParam("force", String.valueOf(force));
try {
request(DELETE, 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 a swarm node", e);
default:
throw e;
}
}
}
use of com.spotify.docker.client.exceptions.DockerRequestException in project docker-client by spotify.
the class DefaultDockerClient method execCreate.
@Override
public ExecCreation execCreate(final String containerId, final String[] cmd, final ExecCreateParam... params) throws DockerException, InterruptedException {
final ContainerInfo containerInfo = inspectContainer(containerId);
if (!containerInfo.state().running()) {
throw new IllegalStateException("Container " + containerId + " is not running.");
}
final WebTarget resource = resource().path("containers").path(containerId).path("exec");
final StringWriter writer = new StringWriter();
try {
final JsonGenerator generator = objectMapper().getFactory().createGenerator(writer);
generator.writeStartObject();
for (final ExecCreateParam param : params) {
if (param.value().equals("true") || param.value().equals("false")) {
generator.writeBooleanField(param.name(), Boolean.valueOf(param.value()));
} else {
generator.writeStringField(param.name(), param.value());
}
}
generator.writeArrayFieldStart("Cmd");
for (final String s : cmd) {
generator.writeString(s);
}
generator.writeEndArray();
generator.writeEndObject();
generator.close();
} catch (IOException e) {
throw new DockerException(e);
}
try {
return request(POST, ExecCreation.class, resource, resource.request(APPLICATION_JSON_TYPE), Entity.json(writer.toString()));
} catch (DockerRequestException e) {
switch(e.status()) {
case 404:
throw new ContainerNotFoundException(containerId, e);
case 409:
throw new ExecCreateConflictException(containerId, e);
default:
throw e;
}
}
}
use of com.spotify.docker.client.exceptions.DockerRequestException in project docker-client by spotify.
the class DefaultDockerClient method createContainer.
@Override
public ContainerCreation createContainer(final ContainerConfig config, final String name) throws DockerException, InterruptedException {
WebTarget resource = resource().path("containers").path("create");
if (name != null) {
checkArgument(CONTAINER_NAME_PATTERN.matcher(name).matches(), "Invalid container name: \"%s\"", name);
resource = resource.queryParam("name", name);
}
log.debug("Creating container with ContainerConfig: {}", 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 ImageNotFoundException(config.image(), e);
case 406:
throw new DockerException("Impossible to attach. Container not running.", e);
default:
throw e;
}
}
}
use of com.spotify.docker.client.exceptions.DockerRequestException in project docker-client by spotify.
the class DefaultDockerClient method updateSwarm.
@Override
public void updateSwarm(final Long version, final boolean rotateWorkerToken, final boolean rotateManagerToken, final boolean rotateManagerUnlockKey, final SwarmSpec spec) throws DockerException, InterruptedException {
assertApiVersionIsAbove("1.24");
try {
final WebTarget resource = resource().path("swarm").path("update").queryParam("version", version).queryParam("rotateWorkerToken", rotateWorkerToken).queryParam("rotateManagerToken", rotateManagerToken).queryParam("rotateManagerUnlockKey", rotateManagerUnlockKey);
request(POST, String.class, resource, resource.request(APPLICATION_JSON_TYPE), Entity.json(spec));
} catch (DockerRequestException e) {
switch(e.status()) {
case 400:
throw new DockerException("bad parameter", e);
default:
throw e;
}
}
}
use of com.spotify.docker.client.exceptions.DockerRequestException in project docker-client by spotify.
the class DefaultDockerClient method execResizeTty.
@Override
public void execResizeTty(final String execId, final Integer height, final Integer width) throws DockerException, InterruptedException {
checkTtyParams(height, width);
WebTarget resource = resource().path("exec").path(execId).path("resize");
if (height != null && height > 0) {
resource = resource.queryParam("h", height);
}
if (width != null && width > 0) {
resource = resource.queryParam("w", width);
}
try {
request(POST, resource, resource.request(TEXT_PLAIN_TYPE));
} catch (DockerRequestException e) {
switch(e.status()) {
case 404:
throw new ExecNotFoundException(execId, e);
default:
throw e;
}
}
}
Aggregations