Search in sources :

Example 1 with HttpBodyAndStatus

use of io.fabric8.maven.docker.access.hc.ApacheHttpClientDelegate.HttpBodyAndStatus in project docker-maven-plugin by fabric8io.

the class DockerAccessWithHcClient method getImageId.

@Override
public String getImageId(String name) throws DockerAccessException {
    HttpBodyAndStatus response = inspectImage(name);
    if (response.getStatusCode() == HTTP_NOT_FOUND) {
        return null;
    }
    JSONObject imageDetails = new JSONObject(response.getBody());
    return imageDetails.getString("Id").substring(0, 12);
}
Also used : JSONObject(org.json.JSONObject) HttpBodyAndStatus(io.fabric8.maven.docker.access.hc.ApacheHttpClientDelegate.HttpBodyAndStatus)

Example 2 with HttpBodyAndStatus

use of io.fabric8.maven.docker.access.hc.ApacheHttpClientDelegate.HttpBodyAndStatus in project docker-maven-plugin by fabric8io.

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);
        HttpBodyAndStatus response = delegate.delete(url, new BodyAndStatusResponseHandler(), HTTP_OK, HTTP_NOT_FOUND);
        if (log.isDebugEnabled()) {
            logRemoveResponse(new JSONArray(response.getBody()));
        }
        return response.getStatusCode() == HTTP_OK;
    } catch (IOException e) {
        throw new DockerAccessException(e, "Unable to remove image [%s]", image);
    }
}
Also used : BodyAndStatusResponseHandler(io.fabric8.maven.docker.access.hc.ApacheHttpClientDelegate.BodyAndStatusResponseHandler) JSONArray(org.json.JSONArray) HttpBodyAndStatus(io.fabric8.maven.docker.access.hc.ApacheHttpClientDelegate.HttpBodyAndStatus)

Aggregations

HttpBodyAndStatus (io.fabric8.maven.docker.access.hc.ApacheHttpClientDelegate.HttpBodyAndStatus)2 BodyAndStatusResponseHandler (io.fabric8.maven.docker.access.hc.ApacheHttpClientDelegate.BodyAndStatusResponseHandler)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1