public UpgradePack suggestUpgradePack(String clusterName,
      StackId sourceStackId, StackId targetStackId, Direction direction, UpgradeType upgradeType,
      String preferredUpgradePackName) throws AmbariException {

    // Find upgrade packs based on current stack. This is where to upgrade from
    Cluster cluster = m_clusters.get().getCluster(clusterName);

    StackId currentStack = cluster.getCurrentStackVersion();

    /*
     * To find upgrades packs when moving STACK-1.0 to STACK-2.0:
     * - Search STACK-2.0 upgrade packs that define source as STACK-1.0
     * - Search STACK-1.0 upgrade packs that define target as STACK-2.0 (legacy)
     */

    UpgradePack pack = findPreferred(preferredUpgradePackName, currentStack, targetStackId);
    if (null != pack) {
      return pack;
    }

    // !!! try to find a stack that defines the source
    pack = findUpgradePack(targetStackId, currentStack, upgradeType, true);
    if (null != pack) {
      return pack;
    }

    // !!! try to find a stack that defines the target (legacy)
    pack = findUpgradePack(currentStack, targetStackId, upgradeType, false);

    if (null == pack) {
      throw new AmbariException(
          String.format("Unable to perform %s. Could not locate %s upgrade pack for stack %s",
              direction.getText(false), upgradeType.toString(), targetStackId));
    }

   return pack;
  }
Get right Upgrade Pack, depends on stack, direction and upgrade type
information

@param clusterName
         The name of the cluster
@param sourceStackId
         the "from" stack for this upgrade/downgrade
@param targetStackId
         the "to" stack for this upgrade/downgrade
@param direction
         {@code Direction} of the upgrade
@param upgradeType
         The {@code UpgradeType}
@param preferredUpgradePackName
         For unit test, need to prefer an upgrade pack since multiple
         matches can be found.
@return {@code UpgradeType} object
@throws AmbariException
ambari-server/src/main/java/org/apache/ambari/server/stack/upgrade/orchestrate/UpgradeHelper.java