private StackId getTargetStackId(Cluster cluster) throws AmbariException {
    UpgradeContext upgradeContext = getUpgradeContext(cluster);

    // !!! FIXME in a per-service view, what does this become?
    Set<StackId> stackIds = new HashSet<>();

    for (Service service : cluster.getServices().values()) {
      RepositoryVersionEntity targetRepoVersion = upgradeContext.getTargetRepositoryVersion(service.getName());
      StackId targetStackId = targetRepoVersion.getStackId();
      stackIds.add(targetStackId);
    }

    if (1 != stackIds.size()) {
      throw new AmbariException("Services are deployed from multiple stacks and cannot determine a unique one.");
    }

    return stackIds.iterator().next();
  }
Retrieves the target stack ID for the stack upgrade or downgrade operation.

@param cluster the cluster
@return the target {@link StackId}
@throws AmbariException if multiple stack id's are detected
ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/PreconfigureKerberosAction.java