private UpgradePack findUpgradePack(StackId sourceStack, StackId stackToFind,
      UpgradeType upgradeType, boolean compareToSource) throws AmbariException {

    Map<String, UpgradePack> packs = m_ambariMetaInfoProvider.get().getUpgradePacks(
        sourceStack.getStackName(), sourceStack.getStackVersion());

    UpgradePack result = null;

    for (UpgradePack upgradePack : packs.values()) {
      StackId upgradeStack = compareToSource ?
          new StackId(upgradePack.getSourceStack()) : new StackId(upgradePack.getTargetStack());

      if (upgradeStack.equals(stackToFind) && upgradePack.getType() == upgradeType) {
        if (null == result) {
          result = upgradePack;
        } else {
          throw new AmbariException(
              String.format(
                  "Unable to resolve upgrade pack. Found multiple upgrade packs for type %s and stack %s",
                  upgradeType.toString(), stackToFind));
        }
      }
    }

    return result;
  }
Finds a suitable upgrade pack given the source and target stacks.

@param sourceStack
         the source stack
@param stackToFind
         the stack to search in upgrade packs
@param compareToSource
         when comparing, use the {@code source} or {@code target} in the upgrade pack
@return
         the upgrade pack, if found
@throws AmbariException
ambari-server/src/main/java/org/apache/ambari/server/stack/upgrade/orchestrate/UpgradeHelper.java