Search in sources :

Example 6 with DockerAccessException

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);
    }
}
Also used : DockerAccessException(org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException) IOException(java.io.IOException)

Example 7 with DockerAccessException

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());
    }
}
Also used : JsonArray(com.google.gson.JsonArray) NetworksListElement(org.eclipse.jkube.kit.build.api.model.NetworksListElement) Network(org.eclipse.jkube.kit.build.api.model.Network) DockerAccessException(org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 8 with DockerAccessException

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());
    }
}
Also used : DockerAccessException(org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException)

Example 9 with DockerAccessException

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);
    }
}
Also used : DockerAccessException(org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException) JsonObject(com.google.gson.JsonObject) DockerAccessException(org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException)

Example 10 with DockerAccessException

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);
    }
}
Also used : DockerAccessException(org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException)

Aggregations

DockerAccessException (org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException)28 IOException (java.io.IOException)21 JsonObject (com.google.gson.JsonObject)8 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)3 ImageName (org.eclipse.jkube.kit.config.image.ImageName)3 JsonArray (com.google.gson.JsonArray)2 File (java.io.File)2 HttpResponseException (org.apache.http.client.HttpResponseException)2 Container (org.eclipse.jkube.kit.build.api.model.Container)2 Map (java.util.Map)1 ContainerDetails (org.eclipse.jkube.kit.build.api.model.ContainerDetails)1 ContainersListElement (org.eclipse.jkube.kit.build.api.model.ContainersListElement)1 Network (org.eclipse.jkube.kit.build.api.model.Network)1 NetworksListElement (org.eclipse.jkube.kit.build.api.model.NetworksListElement)1 BuildOptions (org.eclipse.jkube.kit.build.service.docker.access.BuildOptions)1 CreateImageOptions (org.eclipse.jkube.kit.build.service.docker.access.CreateImageOptions)1 ExitCodeChecker (org.eclipse.jkube.kit.build.service.docker.wait.ExitCodeChecker)1 HealthCheckChecker (org.eclipse.jkube.kit.build.service.docker.wait.HealthCheckChecker)1 LogWaitChecker (org.eclipse.jkube.kit.build.service.docker.wait.LogWaitChecker)1