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

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