use of org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException in project jkube by eclipse.
the class DockerAccessWithHcClient method buildImage.
@Override
public void buildImage(String image, File dockerArchive, BuildOptions options) throws DockerAccessException {
try {
String url = urlBuilder.buildImage(image, options);
delegate.post(url, dockerArchive, createBuildResponseHandler(), HTTP_OK);
} catch (IOException e) {
throw new DockerAccessException(e, "Unable to build image [%s]", image);
}
}
use of org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException in project jkube by eclipse.
the class DockerAccessWithHcClient method listNetworks.
@Override
public List<Network> listNetworks() throws DockerAccessException {
String url = urlBuilder.listNetworks();
try {
String response = delegate.get(url, HTTP_OK);
JsonArray array = JsonFactory.newJsonArray(response);
List<Network> networks = new ArrayList<>(array.size());
for (int i = 0; i < array.size(); i++) {
networks.add(new NetworksListElement(array.get(i).getAsJsonObject()));
}
return networks;
} catch (IOException e) {
throw new DockerAccessException(e.getMessage());
}
}
use of org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException in project jkube by eclipse.
the class DockerAccessWithHcClient method createContainer.
@Override
public String createContainer(ContainerCreateConfig containerConfig, String containerName) throws DockerAccessException {
String createJson = containerConfig.toJson();
log.debug("Container create config: %s", createJson);
try {
String url = urlBuilder.createContainer(containerName);
String response = delegate.post(url, createJson, new ApacheHttpClientDelegate.BodyResponseHandler(), HTTP_CREATED);
JsonObject json = JsonFactory.newJsonObject(response);
logWarnings(json);
// only need first 12 to id a container
return json.get("Id").getAsString().substring(0, 12);
} catch (IOException e) {
throw new DockerAccessException(e, "Unable to create container for [%s]", containerConfig.getImageName());
}
}
use of org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException in project jkube by eclipse.
the class DockerAccessWithHcClient method startExecContainer.
@Override
public void startExecContainer(String containerId, LogOutputSpec outputSpec) throws DockerAccessException {
try {
String url = urlBuilder.startExecContainer(containerId);
JsonObject request = new JsonObject();
request.addProperty("Detach", false);
request.addProperty("Tty", true);
delegate.post(url, request.toString(), createExecResponseHandler(outputSpec), HTTP_OK);
} catch (Exception e) {
throw new DockerAccessException(e, "Unable to start container id [%s]", containerId);
}
}
use of org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException in project jkube by eclipse.
the class DockerAccessWithHcClient method createExecContainer.
@Override
public String createExecContainer(String containerId, Arguments arguments) throws DockerAccessException {
String url = urlBuilder.createExecContainer(containerId);
JsonObject request = new JsonObject();
request.addProperty("Tty", true);
request.addProperty("AttachStdin", false);
request.addProperty("AttachStdout", true);
request.addProperty("AttachStderr", true);
request.add("Cmd", JsonFactory.newJsonArray(arguments.getExec()));
String execJsonRequest = request.toString();
try {
String response = delegate.post(url, execJsonRequest, new ApacheHttpClientDelegate.BodyResponseHandler(), HTTP_CREATED);
JsonObject json = JsonFactory.newJsonObject(response);
if (json.has("Warnings")) {
logWarnings(json);
}
return json.get("Id").getAsString();
} catch (IOException e) {
throw new DockerAccessException(e, "Unable to exec [%s] on container [%s]", request.toString(), containerId);
}
}
Aggregations