public List<Grouping> getGroups(Direction direction) {
    List<Grouping> list;
    if (direction.isUpgrade()) {
      list = groups;
    } else {
      switch (type) {
        case NON_ROLLING:
          list = getDowngradeGroupsForNonrolling();
          break;
        case HOST_ORDERED:
        case ROLLING:
        default:
          list = getDowngradeGroupsForRolling();
          break;
      }
    }

    List<Grouping> checked = new ArrayList<>();
    for (Grouping group : list) {
      if (null == group.intendedDirection || direction == group.intendedDirection) {
        checked.add(group);
      }

    }

    return checked;
  }
Gets the groups defined for the upgrade pack. If a direction is defined for
a group, it must match the supplied direction to be returned

@param direction
         the direction to return the ordered groups
@return the list of groups
ambari-server/src/main/java/org/apache/ambari/server/stack/upgrade/UpgradePack.java