private void handleDockerSwarmResponse(final PullResponseItem item) { if (results == null) { results = new HashMap<>(); } // Swarm terminates a pull sometimes with an empty line. // Therefore keep first success message PullResponseItem currentItem = results.get(item.getId()); if (currentItem == null || !currentItem.isPullSuccessIndicated()) { results.put(item.getId(), item); } }
@Override public void onNext(PullResponseItem item) { // only do it once if (results == null && latestItem == null) { checkForDockerSwarmResponse(item); } if (isSwarm) { handleDockerSwarmResponse(item); } else { handleDockerClientResponse(item); } LOGGER.debug(item.toString()); }
/** * Returns whether the status indicates a successful pull operation * * @returns true: status indicates that pull was successful, false: status doesn't indicate a successful pull */ @JsonIgnore public boolean isPullSuccessIndicated() { if (isErrorIndicated() || getStatus() == null) { return false; } return (getStatus().contains(DOWNLOAD_COMPLETE) || getStatus().contains(IMAGE_UP_TO_DATE) || getStatus().contains(DOWNLOADED_NEWER_IMAGE) || getStatus().contains(LEGACY_REGISTRY) || getStatus().contains(DOWNLOADED_SWARM) ); } }
private ItemStatus createStatusItem(PullResponseItem item, ItemStatus previousStatus) { ProgressDetail progressDetail = item.getProgressDetail(); if (progressDetail != null && progressDetail.getTotal() != null && progressDetail.getTotal() > 0) { int currentPct = computePercentage(previousStatus, progressDetail); return ItemStatus.builder() .id(item.getId()) .percentage(currentPct) .pullStatus(statusNotNull(item.getStatus())? item.getStatus() : "") .build(); } return ItemStatus.builder() .id(item.getId()) .percentage(0) .pullStatus(statusNotNull(item.getStatus())? item.getStatus() : "") .build(); }
private void checkForDockerSwarmResponse(PullResponseItem item) { if (item.getStatus().matches("Pulling\\s.+\\.{3}$")) { isSwarm = true; LOGGER.debug("Communicating with Docker Swarm."); } }
private void checkDockerClientPullSuccessful() { if (latestItem == null) { throw new DockerClientException("Could not pull image"); } else if (!latestItem.isPullSuccessIndicated()) { throw new DockerClientException("Could not pull image: " + messageFromPullResult(latestItem)); } }
/** * Returns whether the status indicates a successful pull operation * * @returns true: status indicates that pull was successful, false: status doesn't indicate a successful pull */ @JsonIgnore public boolean isPullSuccessIndicated() { if (isErrorIndicated() || getStatus() == null) { return false; } return (getStatus().contains(DOWNLOAD_COMPLETE) || getStatus().contains(IMAGE_UP_TO_DATE) || getStatus().contains(DOWNLOADED_NEWER_IMAGE) || getStatus().contains(LEGACY_REGISTRY) || getStatus().contains(DOWNLOADED_SWARM) ); } }
private void checkForDockerSwarmResponse(PullResponseItem item) { if (item.getStatus().matches("Pulling\\s.+\\.{3}$")) { isSwarm = true; LOGGER.debug("Communicating with Docker Swarm."); } }
private void checkDockerClientPullSuccessful() { if (latestItem == null) { throw new DockerClientException("Could not pull image"); } else if (!latestItem.isPullSuccessIndicated()) { throw new DockerClientException("Could not pull image: " + messageFromPullResult(latestItem)); } }
private void checkDockerSwarmPullSuccessful() { if (results.isEmpty()) { throw new DockerClientException("Could not pull image through Docker Swarm"); } else { boolean pullFailed = false; StringBuilder sb = new StringBuilder(); for (PullResponseItem pullResponseItem : results.values()) { if (!pullResponseItem.isPullSuccessIndicated()) { pullFailed = true; sb.append("[" + pullResponseItem.getId() + ":" + messageFromPullResult(pullResponseItem) + "]"); } } if (pullFailed) { throw new DockerClientException("Could not pull image: " + sb.toString()); } } }
@Override public void onNext(PullResponseItem item) { listener.getLogger().println(item.getStatus()); } }).awaitCompletion();
@Override public void onNext(PullResponseItem item) { console.logInfo(item.toString()); super.onNext(item); }
private void handleDockerSwarmResponse(final PullResponseItem item) { if (results == null) { results = new HashMap<>(); } // Swarm terminates a pull sometimes with an empty line. // Therefore keep first success message PullResponseItem currentItem = results.get(item.getId()); if (currentItem == null || !currentItem.isPullSuccessIndicated()) { results.put(item.getId(), item); } }
@Override public void onNext(PullResponseItem item) { // only do it once if (results == null && latestItem == null) { checkForDockerSwarmResponse(item); } if (isSwarm) { handleDockerSwarmResponse(item); } else { handleDockerClientResponse(item); } LOGGER.debug(item.toString()); }
private void checkDockerSwarmPullSuccessful() { if (results.isEmpty()) { throw new DockerClientException("Could not pull image through Docker Swarm"); } else { boolean pullFailed = false; StringBuilder sb = new StringBuilder(); for (PullResponseItem pullResponseItem : results.values()) { if (!pullResponseItem.isPullSuccessIndicated()) { pullFailed = true; sb.append("[" + pullResponseItem.getId() + ":" + messageFromPullResult(pullResponseItem) + "]"); } } if (pullFailed) { throw new DockerClientException("Could not pull image: " + sb.toString()); } } }