@RequiresSession
  public UpgradeEntity findLastUpgradeForCluster(long clusterId, Direction direction) {
    TypedQuery<UpgradeEntity> query = entityManagerProvider.get().createNamedQuery(
        "UpgradeEntity.findLatestForClusterInDirection", UpgradeEntity.class);
    query.setMaxResults(1);
    query.setParameter("clusterId", clusterId);
    query.setParameter("direction", direction);

    return daoUtils.selectSingle(query);
  }
@param clusterId
         the cluster id
@param direction
         the direction (not {@code null}).
@return the upgrade entity, or {@code null} if not found
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UpgradeDAO.java