Search in sources :

Example 16 with DockerAccessException

use of org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException in project jkube by eclipse.

the class DockerAccessWithHcClient method startContainer.

@Override
public void startContainer(String containerId) throws DockerAccessException {
    try {
        String url = urlBuilder.startContainer(containerId);
        delegate.post(url, HTTP_NO_CONTENT, HTTP_OK);
    } catch (IOException e) {
        throw new DockerAccessException(e, "Unable to start container id [%s]", containerId);
    }
}
Also used : DockerAccessException(org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException) IOException(java.io.IOException)

Example 17 with DockerAccessException

use of org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException in project jkube by eclipse.

the class DockerAccessWithHcClient method removeContainer.

@Override
public void removeContainer(String containerId, boolean removeVolumes) throws DockerAccessException {
    try {
        String url = urlBuilder.removeContainer(containerId, removeVolumes);
        delegate.delete(url, HTTP_NO_CONTENT);
    } catch (IOException e) {
        throw new DockerAccessException(e, "Unable to remove container [%s]", containerId);
    }
}
Also used : DockerAccessException(org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException) IOException(java.io.IOException)

Example 18 with DockerAccessException

use of org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException in project jkube by eclipse.

the class DockerAccessWithHcClient method pushImage.

@Override
public void pushImage(String image, AuthConfig authConfig, String registry, int retries) throws DockerAccessException {
    ImageName name = new ImageName(image);
    String pushUrl = urlBuilder.pushImage(name, registry);
    TemporaryImageHandler temporaryImageHandler = tagTemporaryImage(name, registry);
    DockerAccessException dae = null;
    try {
        doPushImage(pushUrl, createAuthHeader(authConfig), createPullOrPushResponseHandler(), HTTP_OK, retries);
    } catch (IOException e) {
        dae = new DockerAccessException(e, "Unable to push '%s'%s", image, (registry != null) ? " to registry '" + registry + "'" : "");
        throw dae;
    } finally {
        temporaryImageHandler.handle(dae);
    }
}
Also used : ImageName(org.eclipse.jkube.kit.config.image.ImageName) DockerAccessException(org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException) IOException(java.io.IOException)

Example 19 with DockerAccessException

use of org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException in project jkube by eclipse.

the class DockerAccessWithHcClient method createNetwork.

@Override
public String createNetwork(NetworkCreateConfig networkConfig) throws DockerAccessException {
    String createJson = networkConfig.toJson();
    log.debug("Network create config: " + createJson);
    try {
        String url = urlBuilder.createNetwork();
        String response = delegate.post(url, createJson, new ApacheHttpClientDelegate.BodyResponseHandler(), HTTP_CREATED);
        log.debug(response);
        JsonObject json = JsonFactory.newJsonObject(response);
        if (json.has("Warnings")) {
            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 network for [%s]", networkConfig.getName());
    }
}
Also used : DockerAccessException(org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException)

Example 20 with DockerAccessException

use of org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException in project jkube by eclipse.

the class DockerAccessWithHcClient method removeImage.

@Override
public boolean removeImage(String image, boolean... forceOpt) throws DockerAccessException {
    boolean force = forceOpt != null && forceOpt.length > 0 && forceOpt[0];
    try {
        String url = urlBuilder.deleteImage(image, force);
        ApacheHttpClientDelegate.HttpBodyAndStatus response = delegate.delete(url, new ApacheHttpClientDelegate.BodyAndStatusResponseHandler(), HTTP_OK, HTTP_NOT_FOUND);
        if (log.isDebugEnabled()) {
            logRemoveResponse(JsonFactory.newJsonArray(response.getBody()));
        }
        return response.getStatusCode() == HTTP_OK;
    } catch (IOException e) {
        throw new DockerAccessException(e, "Unable to remove image [%s]", image);
    }
}
Also used : DockerAccessException(org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException) 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