private void failTaskAndPatchDocument(
      final KubernetesClusterCreateTask currentState,
      final NodeType nodeType,
      final Throwable throwable) {
    ServiceUtils.logSevere(this, throwable);
    KubernetesClusterCreateTask patchState =
        buildPatch(
            TaskState.TaskStage.FAILED,
            null,
            new IllegalStateException(
                String.format(
                    "Failed to rollout %s. Error: %s", nodeType.toString(), throwable.toString())));

    ClusterService.State document = new ClusterService.State();
    document.clusterState = ClusterState.ERROR;
    updateStates(currentState, patchState, document);
  }
  /**
   * This method creates a Kubernetes Cluster Service instance. On successful creation, the method
   * moves the sub-stage to SETUP_MASTER.
   *
   * @param currentState
   * @param imageId
   */
  private void createClusterService(
      final KubernetesClusterCreateTask currentState, final String imageId) {

    ClusterService.State cluster = new ClusterService.State();
    cluster.clusterState = ClusterState.CREATING;
    cluster.clusterName = currentState.clusterName;
    cluster.clusterType = ClusterType.KUBERNETES;
    cluster.imageId = imageId;
    cluster.projectId = currentState.projectId;
    cluster.diskFlavorName = currentState.diskFlavorName;
    cluster.masterVmFlavorName = currentState.masterVmFlavorName;
    cluster.otherVmFlavorName = currentState.otherVmFlavorName;
    cluster.vmNetworkId = currentState.vmNetworkId;
    cluster.slaveCount = currentState.slaveCount;
    cluster.extendedProperties = new HashMap<>();
    cluster.extendedProperties.put(ClusterManagerConstants.EXTENDED_PROPERTY_DNS, currentState.dns);
    cluster.extendedProperties.put(
        ClusterManagerConstants.EXTENDED_PROPERTY_GATEWAY, currentState.gateway);
    cluster.extendedProperties.put(
        ClusterManagerConstants.EXTENDED_PROPERTY_NETMASK, currentState.netmask);
    cluster.extendedProperties.put(
        ClusterManagerConstants.EXTENDED_PROPERTY_CONTAINER_NETWORK, currentState.containerNetwork);
    cluster.extendedProperties.put(
        ClusterManagerConstants.EXTENDED_PROPERTY_ETCD_IPS,
        NodeTemplateUtils.serializeAddressList(currentState.etcdIps));
    cluster.extendedProperties.put(
        ClusterManagerConstants.EXTENDED_PROPERTY_MASTER_IP, currentState.masterIp);
    cluster.documentSelfLink = currentState.clusterId;

    sendRequest(
        HostUtils.getCloudStoreHelper(this)
            .createPost(ClusterServiceFactory.SELF_LINK)
            .setBody(cluster)
            .setCompletion(
                (operation, throwable) -> {
                  if (null != throwable) {
                    failTask(throwable);
                    return;
                  }

                  KubernetesClusterCreateTask patchState =
                      buildPatch(TaskState.TaskStage.STARTED, TaskState.SubStage.SETUP_ETCD);
                  patchState.imageId = imageId;
                  TaskUtils.sendSelfPatch(this, patchState);
                }));
  }