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

    return daoUtils.selectSingle(query);
  }
Gets the only revertable upgrade if one exists. By definition, only the
most recent {@code RepositoryType#PATCH} or {@code RepositoryType#MAINT}
upgrade which doesn't have a downgrade already is revertable.

@param clusterId
         the cluster id
@return the upgrade which can be reverted, or {@code null} if not found
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UpgradeDAO.java