private Set<String> getServicesForUpgrade(Cluster cluster,
      RepositoryVersionEntity repositoryVersion) throws AmbariException {

    // keep track of the services which will be in this upgrade
    Set<String> servicesForUpgrade;

    // standard repo types use all services of the cluster
    if (repositoryVersion.getType() == RepositoryType.STANDARD) {
      servicesForUpgrade = cluster.getServices().keySet();
    } else {
      try {
        // use the VDF and cluster to determine what services should be in this
        // upgrade - this will take into account the type (such as patch/maint)
        // and the version of services installed in the cluster
        VersionDefinitionXml vdf = repositoryVersion.getRepositoryXml();
        ClusterVersionSummary clusterVersionSummary = vdf.getClusterSummary(
            cluster, m_metaInfo);
        servicesForUpgrade = clusterVersionSummary.getAvailableServiceNames();

        // if this is every true, then just stop the upgrade attempt and
        // throw an exception
        if (servicesForUpgrade.isEmpty()) {
          String message = String.format(
              "When using a VDF of type %s, the available services must be defined in the VDF",
              repositoryVersion.getType());

          throw new AmbariException(message);
        }
      } catch (Exception e) {
        String msg = String.format(
            "Could not parse version definition for %s.  Upgrade will not proceed.",
            repositoryVersion.getVersion());

        throw new AmbariException(msg);
      }
    }

    // now that we have a list of the services defined by the VDF, only include
    // services which are actually installed
    Iterator<String> iterator = servicesForUpgrade.iterator();
    while (iterator.hasNext()) {
      String serviceName = null;
      try {
        serviceName = iterator.next();
        Service service = cluster.getService(serviceName);

        m_sourceRepositoryMap.put(serviceName, service.getDesiredRepositoryVersion());
        m_targetRepositoryMap.put(serviceName, repositoryVersion);
      } catch (ServiceNotFoundException e) {
        // remove the service which is not part of the cluster - this should
        // never happen since the summary from the VDF does this already, but
        // can't hurt to be safe
        iterator.remove();

        LOG.warn(
            "Skipping orchestration for service {}, as it was defined to upgrade, but is not installed in cluster {}",
            serviceName, cluster.getClusterName());
      }
    }

    return servicesForUpgrade;
  }
Gets the set of services which will participate in the upgrade. The
services available in the repository are compared against those installed
in the cluster to arrive at the final subset.
<p/>
In some cases, such as with a {@link RepositoryType#MAINT} repository, the
subset can be further trimmed by determing that an installed service is
already at a high enough version and doesn't need to be upgraded.
<p/>
This method will also populate the source ({@link #m_sourceRepositoryMap})
and target ({@link #m_targetRepositoryMap}) repository maps.

@param cluster
         the cluster (not {@code null}).
@param repositoryVersion
         the repository to use for the upgrade (not {@code null}).
@return the set of services which will participate in the upgrade.
@throws AmbariException
ambari-server/src/main/java/org/apache/ambari/server/stack/upgrade/orchestrate/UpgradeContext.java