use of com.spotify.docker.client.exceptions.ExecCreateConflictException 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;
}
}
}
Aggregations