UpgradeHelper { public UpgradePack suggestUpgradePack(String clusterName, String upgradeFromVersion, String upgradeToVersion, Direction direction, UpgradeType upgradeType, String preferredUpgradePackName) throws AmbariException { Cluster cluster = clusters.get().getCluster(clusterName); StackId stack = cluster.getCurrentStackVersion(); String repoVersion = upgradeToVersion; if (direction.isDowngrade() && null != upgradeFromVersion) { repoVersion = upgradeFromVersion; } RepositoryVersionEntity versionEntity = s_repoVersionDAO.get().findByStackNameAndVersion(stack.getStackName(), repoVersion); if (versionEntity == null) { throw new AmbariException(String.format("Repository version %s was not found", repoVersion)); } Map<String, UpgradePack> packs = m_ambariMetaInfo.get().getUpgradePacks(stack.getStackName(), stack.getStackVersion()); UpgradePack pack = null; if (StringUtils.isNotEmpty(preferredUpgradePackName) && packs.containsKey(preferredUpgradePackName)) { pack = packs.get(preferredUpgradePackName); } else { String repoStackId = versionEntity.getStackId().getStackId(); for (UpgradePack upgradePack : packs.values()) { if (null != upgradePack.getTargetStack() && upgradePack.getTargetStack().equals(repoStackId) && upgradeType == upgradePack.getType()) { if (null == pack) { pack = upgradePack; } else { throw new AmbariException( String.format("Unable to perform %s. Found multiple upgrade packs for type %s and target version %s", direction.getText(false), upgradeType.toString(), repoVersion)); } } } } if (null == pack) { throw new AmbariException(String.format("Unable to perform %s. Could not locate %s upgrade pack for version %s", direction.getText(false), upgradeType.toString(), repoVersion)); } return pack; }  UpgradePack suggestUpgradePack(String clusterName, String upgradeFromVersion, String upgradeToVersion,
    Direction direction, UpgradeType upgradeType, String preferredUpgradePackName); List<UpgradeGroupHolder> createSequence(UpgradePack upgradePack,
      UpgradeContext context); Set<Resource> getStageResources(String clusterName, Long requestId, List<Long> stageIds); Resource getTaskResource(String clusterName, Long requestId, Long stageId, Long taskId); @Transactional void putComponentsToUpgradingState(String version,
      Map<Service, Set<ServiceComponent>> targetServices, StackId targetStack);  }
@Test public void testSuggestUpgradePack() throws Exception{ final String clusterName = "c1"; final String upgradeFromVersion = "2.1.1"; final String upgradeToVersion = "2.2.0"; final Direction upgradeDirection = Direction.UPGRADE; final UpgradeType upgradeType = UpgradeType.ROLLING; makeCluster(); try { String preferredUpgradePackName = "upgrade_test"; UpgradePack up = m_upgradeHelper.suggestUpgradePack(clusterName, upgradeFromVersion, upgradeToVersion, upgradeDirection, upgradeType, preferredUpgradePackName); assertEquals(upgradeType, up.getType()); } catch (AmbariException e){ assertTrue(false); } }