/**
   * Gets image entity and sends patch to update total datastore and total image datastore field.
   *
   * @param current
   */
  protected void updateTotalImageDatastore(final State current) {
    try {
      // build the image entity update patch
      ImageService.State imageServiceState = new ImageService.State();
      imageServiceState.totalImageDatastore = getZookeeperHostMonitor().getImageDatastores().size();
      imageServiceState.totalDatastore = getZookeeperHostMonitor().getAllDatastores().size();
      Operation imagePatch =
          getCloudStoreHelper()
              .createPatch(ImageServiceFactory.SELF_LINK + "/" + current.image)
              .setBody(imageServiceState);

      // create operation sequence
      OperationSequence sequence =
          OperationSequence.create(imagePatch)
              .setCompletion(
                  (Map<Long, Operation> ops, Map<Long, Throwable> failures) -> {
                    if (failures != null && failures.size() > 0) {
                      failTask(failures.values().iterator().next());
                      return;
                    }
                  });

      if (!current.isSelfProgressionDisabled) {
        // move to next stage
        Operation progress =
            this.buildSelfPatchOperation(
                this.buildPatch(
                    TaskState.TaskStage.STARTED, TaskState.SubStage.TRIGGER_COPIES, null));

        sequence.next(progress);
      }

      sequence.sendWith(this);
    } catch (Exception e) {
      failTask(e);
    }
  }