@Override protected Void execute(PingCmd command) { WebTarget webResource = getBaseResource().path("/_ping"); // TODO contribute to docker-java, make it close the stream IOUtils.closeQuietly(webResource.request().get()); return null; } };
@Override protected CreateNetworkResponse execute(CreateNetworkCmd command) { WebTarget webResource = getBaseResource().path("/networks/create"); LOGGER.trace("POST: {}", webResource); return webResource.request().accept(MediaType.APPLICATION_JSON) .post(command, new TypeReference<CreateNetworkResponse>() { }); } }
@Override protected Void execute(LoadImageCmd command) { WebTarget webResource = getBaseResource().path("/images/load"); LOGGER.trace("POST: {}", webResource); webResource.request().postStream(command.getImageStream()); return null; } }
@Override protected InputStream execute(CopyFileFromContainerCmd command) { WebTarget webResource = getBaseResource().path("/containers/{id}/copy").resolveTemplate("id", command.getContainerId()); LOGGER.trace("POST: " + webResource.toString()); return webResource.request().accept(MediaType.APPLICATION_OCTET_STREAM) .post(command); }
@Override protected Void execute(RemoveServiceCmd command) { WebTarget webTarget = getBaseResource().path("/services/" + command.getServiceId()); LOGGER.trace("DELETE: {}", webTarget); webTarget.request().accept(MediaType.APPLICATION_JSON).delete(); return null; }
@Override protected SwarmNode execute(InspectSwarmNodeCmd command) { WebTarget webResource = getBaseResource().path("/nodes/{id}").resolveTemplate("id", command.getSwarmNodeId()); LOGGER.debug("GET: {}", webResource); return webResource.request().accept(MediaType.APPLICATION_JSON) .get(new TypeReference<SwarmNode>() { }); } }
@Override protected UpdateContainerResponse execute(UpdateContainerCmd command) { WebTarget webResource = getBaseResource().path("/containers/{id}/update") .resolveTemplate("id", command.getContainerId()); LOGGER.trace("POST: {}", webResource); return webResource.request().accept(MediaType.APPLICATION_JSON) .post(command, new TypeReference<UpdateContainerResponse>() { }); } }
@Override protected List<SearchItem> execute(SearchImagesCmd command) { WebTarget webResource = getBaseResource().path("/images/search").queryParam("term", command.getTerm()); LOGGER.trace("GET: {}", webResource); return webResource.request().accept(MediaType.APPLICATION_JSON).get(new TypeReference<List<SearchItem>>() { }); }
@Override protected InspectExecResponse execute(InspectExecCmd command) { WebTarget webResource = getBaseResource().path("/exec/{id}/json").resolveTemplate("id", command.getExecId()); LOGGER.debug("GET: {}", webResource); return webResource.request().accept(MediaType.APPLICATION_JSON).get(new TypeReference<InspectExecResponse>() { }); } }
@Override protected InspectImageResponse execute(InspectImageCmd command) { WebTarget webResource = getBaseResource().path("/images/{id}/json").resolveTemplate("id", command.getImageId()); LOGGER.trace("GET: {}", webResource); return webResource.request().accept(MediaType.APPLICATION_JSON).get(new TypeReference<InspectImageResponse>() { }); }
@Override protected InputStream execute(CopyArchiveFromContainerCmd command) { WebTarget webResource = getBaseResource().path("/containers/{id}/archive").resolveTemplate("id", command.getContainerId()); LOGGER.trace("Get: " + webResource.toString()); return webResource.queryParam("path", command.getResource()).request().accept(MediaType.APPLICATION_X_TAR) .get(); } }
@Override protected ListVolumesResponse execute(ListVolumesCmd command) { WebTarget webTarget = getBaseResource().path("/volumes"); if (command.getFilters() != null && !command.getFilters().isEmpty()) { webTarget = webTarget.queryParam("filters", FiltersEncoder.jsonEncode(command.getFilters())); } LOGGER.trace("GET: {}", webTarget); return webTarget.request().accept(MediaType.APPLICATION_JSON).get(new TypeReference<ListVolumesResponse>() { }); } }
@Override protected TopContainerResponse execute(TopContainerCmd command) { WebTarget webResource = getBaseResource().path("/containers/{id}/top").resolveTemplate("id", command.getContainerId()); if (!StringUtils.isEmpty(command.getPsArgs())) { webResource = webResource.queryParam("ps_args", command.getPsArgs()); } LOGGER.trace("GET: {}", webResource); return webResource.request().accept(MediaType.APPLICATION_JSON).get(new TypeReference<TopContainerResponse>() { }); }
@Override protected Void execute(RemoveSwarmNodeCmd command) { WebTarget webTarget = getBaseResource().path("/nodes/" + command.getSwarmNodeId()); webTarget = booleanQueryParam(webTarget, "force", command.hasForceEnabled()); LOGGER.trace("DELETE: {}", webTarget); webTarget.request().accept(MediaType.APPLICATION_JSON).delete(); return null; } }
@Override protected Void execute(CopyArchiveToContainerCmd command) { WebTarget webResource = getBaseResource().path("/containers/{id}/archive").resolveTemplate("id", command.getContainerId()); LOGGER.trace("PUT: " + webResource.toString()); InputStream streamToUpload = command.getTarInputStream(); webResource.queryParam("path", command.getRemotePath()) .queryParam("noOverwriteDirNonDir", command.isNoOverwriteDirNonDir()).request() .put(streamToUpload, MediaType.APPLICATION_X_TAR); return null; } }
@Override protected Void execute(RemoveImageCmd command) { WebTarget webTarget = getBaseResource().path("/images/" + command.getImageId()); webTarget = booleanQueryParam(webTarget, "force", command.hasForceEnabled()); webTarget = booleanQueryParam(webTarget, "noprune", command.hasNoPruneEnabled()); LOGGER.trace("DELETE: {}", webTarget); webTarget.request().delete(); return null; }
@Override protected InspectContainerResponse execute(InspectContainerCmd command) { WebTarget webResource = getBaseResource().path("/containers/{id}/json").resolveTemplate("id", command.getContainerId()); webResource = booleanQueryParam(webResource, "size", command.getSize()); LOGGER.debug("GET: {}", webResource); return webResource.request().accept(MediaType.APPLICATION_JSON) .get(new TypeReference<InspectContainerResponse>() { }); }
@Override protected Void execute(KillContainerCmd command) { WebTarget webResource = getBaseResource().path("/containers/{id}/kill").resolveTemplate("id", command.getContainerId()); if (command.getSignal() != null) { webResource = webResource.queryParam("signal", command.getSignal()); } LOGGER.trace("POST: {}", webResource); webResource.request().accept(MediaType.APPLICATION_JSON).post(null); return null; }
@Override protected CreateContainerResponse execute(CreateContainerCmd command) { WebTarget webResource = getBaseResource().path("/containers/create"); if (command.getName() != null) { webResource = webResource.queryParam("name", command.getName()); } LOGGER.trace("POST: {} ", webResource); return resourceWithOptionalAuthConfig(command.getAuthConfig(), webResource.request()) .accept(MediaType.APPLICATION_JSON) .post(command, new TypeReference<CreateContainerResponse>() { }); } }
@Override protected Void execute(TagImageCmd command) { WebTarget webTarget = getBaseResource().path("/images/" + command.getImageId() + "/tag") .queryParam("repo", command.getRepository()).queryParam("tag", command.getTag()); webTarget = booleanQueryParam(webTarget, "force", command.hasForceEnabled()); LOGGER.trace("POST: {}", webTarget); webTarget.request().post(null); return null; }