@Test public void testAlertHistoryPredicate() throws Exception { m_helper.installHdfsService(m_cluster, m_serviceFactory, m_componentFactory, m_schFactory, HOSTNAME); m_alertHelper.populateData(m_cluster); Predicate clusterPredicate = null; Predicate hdfsPredicate = null; Predicate yarnPredicate = null; Predicate clusterAndHdfsPredicate = null; Predicate clusterAndHdfsAndCriticalPredicate = null; Predicate hdfsAndCriticalOrWarningPredicate = null; Predicate alertNamePredicate = null; Predicate historyIdPredicate = null; clusterPredicate = new PredicateBuilder().property( AlertHistoryResourceProvider.ALERT_HISTORY_CLUSTER_NAME).equals("c1").toPredicate(); AlertHistoryRequest request = new AlertHistoryRequest(); request.Predicate = clusterPredicate; List<AlertHistoryEntity> histories = m_dao.findAll(request); assertEquals(3, histories.size()); hdfsPredicate = new PredicateBuilder().property( AlertHistoryResourceProvider.ALERT_HISTORY_SERVICE_NAME).equals("HDFS").toPredicate(); yarnPredicate = new PredicateBuilder().property( AlertHistoryResourceProvider.ALERT_HISTORY_SERVICE_NAME).equals("YARN").toPredicate(); clusterAndHdfsPredicate = new PredicateBuilder().property( AlertHistoryResourceProvider.ALERT_HISTORY_CLUSTER_NAME).equals("c1").and().property( AlertHistoryResourceProvider.ALERT_HISTORY_SERVICE_NAME).equals("HDFS").toPredicate(); clusterAndHdfsPredicate = new PredicateBuilder().property( AlertHistoryResourceProvider.ALERT_HISTORY_CLUSTER_NAME).equals("c1").and().property( AlertHistoryResourceProvider.ALERT_HISTORY_SERVICE_NAME).equals("HDFS").toPredicate(); clusterAndHdfsAndCriticalPredicate = new PredicateBuilder().property( AlertHistoryResourceProvider.ALERT_HISTORY_CLUSTER_NAME).equals("c1").and().property( AlertHistoryResourceProvider.ALERT_HISTORY_SERVICE_NAME).equals("HDFS").and().property( AlertHistoryResourceProvider.ALERT_HISTORY_STATE).equals( AlertState.CRITICAL.name()).toPredicate(); hdfsAndCriticalOrWarningPredicate = new PredicateBuilder().begin().property( AlertHistoryResourceProvider.ALERT_HISTORY_SERVICE_NAME).equals("HDFS").and().property( AlertHistoryResourceProvider.ALERT_HISTORY_STATE).equals( AlertState.CRITICAL.name()).end().or().property( AlertHistoryResourceProvider.ALERT_HISTORY_STATE).equals( AlertState.WARNING.name()).toPredicate(); alertNamePredicate = new PredicateBuilder().property( AlertHistoryResourceProvider.ALERT_HISTORY_DEFINITION_NAME).equals( "NAMENODE").toPredicate(); request.Predicate = hdfsPredicate; histories = m_dao.findAll(request); assertEquals(2, histories.size()); request.Predicate = yarnPredicate; histories = m_dao.findAll(request); assertEquals(1, histories.size()); request.Predicate = clusterAndHdfsPredicate; histories = m_dao.findAll(request); assertEquals(2, histories.size()); request.Predicate = clusterAndHdfsAndCriticalPredicate; histories = m_dao.findAll(request); assertEquals(0, histories.size()); request.Predicate = hdfsAndCriticalOrWarningPredicate; histories = m_dao.findAll(request); assertEquals(1, histories.size()); request.Predicate = alertNamePredicate; histories = m_dao.findAll(request); assertEquals(1, histories.size()); historyIdPredicate = new PredicateBuilder().property( AlertHistoryResourceProvider.ALERT_HISTORY_ID).equals( histories.get(0).getAlertId()).toPredicate(); request.Predicate = historyIdPredicate; histories = m_dao.findAll(request); assertEquals(1, histories.size()); }
@RequiresSession public List<AlertHistoryEntity> findAll() { TypedQuery<AlertHistoryEntity> query = m_entityManagerProvider.get().createNamedQuery( "AlertHistoryEntity.findAll", AlertHistoryEntity.class); return m_daoUtils.selectList(query); }
AlertsDAO implements Cleanable { @RequiresSession public List<AlertHistoryEntity> findAll() { TypedQuery<AlertHistoryEntity> query = m_entityManagerProvider.get().createNamedQuery( "AlertHistoryEntity.findAll", AlertHistoryEntity.class); return m_daoUtils.selectList(query); } }
AlertsDAO implements Cleanable { @RequiresSession public List<AlertHistoryEntity> findAll() { TypedQuery<AlertHistoryEntity> query = m_entityManagerProvider.get().createNamedQuery( "AlertHistoryEntity.findAll", AlertHistoryEntity.class); return m_daoUtils.selectList(query); } @Inject  AlertsDAO(Configuration configuration); }
AlertsDAO implements Cleanable { @RequiresSession public List<AlertHistoryEntity> findAll() { TypedQuery<AlertHistoryEntity> query = m_entityManagerProvider.get().createNamedQuery( "AlertHistoryEntity.findAll", AlertHistoryEntity.class); return m_daoUtils.selectList(query); } @Inject  AlertsDAO(Configuration configuration); @RequiresSession AlertHistoryEntity findById(long alertId); @RequiresSession List<AlertHistoryEntity> findAll(); @RequiresSession List<AlertHistoryEntity> findAll(long clusterId); @RequiresSession List<AlertHistoryEntity> findAll(long clusterId,
      List<AlertState> alertStates); @RequiresSession List<AlertHistoryEntity> findAll(long clusterId, Date startDate,
      Date endDate); @RequiresSession List<AlertHistoryEntity> findAll(AlertHistoryRequest request); @Transactional List<AlertCurrentEntity> findAll(AlertCurrentRequest request); int getCount(Predicate predicate); @RequiresSession List<AlertCurrentEntity> findCurrent(); @RequiresSession AlertCurrentEntity findCurrentById(long alertId); @RequiresSession List<AlertCurrentEntity> findCurrentByDefinitionId(long definitionId); @RequiresSession List<AlertCurrentEntity> findCurrentByCluster(long clusterId); @RequiresSession AlertSummaryDTO findCurrentCounts(long clusterId, String serviceName, String hostName); @RequiresSession Map<String, AlertSummaryDTO> findCurrentPerHostCounts(long clusterId); @RequiresSession AlertHostSummaryDTO findCurrentHostCounts(long clusterId); @RequiresSession List<AlertCurrentEntity> findCurrentByService(long clusterId,
      String serviceName); AlertCurrentEntity findCurrentByHostAndName(long clusterId, String hostName,
      String alertName); @Transactional void removeByDefinitionId(long definitionId); @Transactional int removeCurrentByHistoryId(long historyId); @Transactional int removeCurrentDisabledAlerts(); @Transactional int removeCurrentByService(long clusterId, String serviceName); @Transactional int removeCurrentByHost(String hostName); @Transactional int removeCurrentByServiceComponentHost(long clusterId, String serviceName,
      String componentName, String hostName); @Transactional void create(AlertHistoryEntity alert); @Transactional void refresh(AlertHistoryEntity alert); @Transactional AlertHistoryEntity merge(AlertHistoryEntity alert); @Transactional void remove(AlertHistoryEntity alert); @Transactional void create(AlertCurrentEntity alert); @Transactional void refresh(AlertCurrentEntity alert); @Transactional AlertCurrentEntity merge(AlertCurrentEntity alert); AlertCurrentEntity merge(AlertCurrentEntity alert, boolean updateCacheOnly); @Transactional void remove(AlertCurrentEntity alert); @RequiresSession AlertSummaryDTO findAggregateCounts(long clusterId, String alertName); AlertCurrentEntity findCurrentByNameNoHost(long clusterId, String alertName); @Transactional void flushCachedEntitiesToJPA(); @Transactional @Override long cleanup(TimeBasedCleanupPolicy policy); }
AlertsDAO implements Cleanable { @RequiresSession public List<AlertHistoryEntity> findAll() { TypedQuery<AlertHistoryEntity> query = m_entityManagerProvider.get().createNamedQuery( "AlertHistoryEntity.findAll", AlertHistoryEntity.class); return m_daoUtils.selectList(query); } @Inject  AlertsDAO(Configuration configuration); @RequiresSession AlertHistoryEntity findById(long alertId); @RequiresSession List<AlertHistoryEntity> findAll(); @RequiresSession List<AlertHistoryEntity> findAll(long clusterId); @RequiresSession List<AlertHistoryEntity> findAll(long clusterId,
      List<AlertState> alertStates); @RequiresSession List<AlertHistoryEntity> findAll(long clusterId, Date startDate,
      Date endDate); @RequiresSession List<AlertHistoryEntity> findAll(AlertHistoryRequest request); @Transactional List<AlertCurrentEntity> findAll(AlertCurrentRequest request); int getCount(Predicate predicate); @RequiresSession List<AlertCurrentEntity> findCurrent(); @RequiresSession AlertCurrentEntity findCurrentById(long alertId); @RequiresSession List<AlertCurrentEntity> findCurrentByDefinitionId(long definitionId); @RequiresSession List<AlertCurrentEntity> findCurrentByCluster(long clusterId); @RequiresSession AlertSummaryDTO findCurrentCounts(long clusterId, String serviceName, String hostName); @RequiresSession Map<String, AlertSummaryDTO> findCurrentPerHostCounts(long clusterId); @RequiresSession AlertHostSummaryDTO findCurrentHostCounts(long clusterId); @RequiresSession List<AlertCurrentEntity> findCurrentByService(long clusterId,
      String serviceName); AlertCurrentEntity findCurrentByHostAndName(long clusterId, String hostName,
      String alertName); @Transactional void removeByDefinitionId(long definitionId); @Transactional int removeCurrentByHistoryId(long historyId); @Transactional int removeCurrentDisabledAlerts(); @Transactional int removeCurrentByService(long clusterId, String serviceName); @Transactional int removeCurrentByHost(String hostName); @Transactional int removeCurrentByServiceComponentHost(long clusterId, String serviceName,
      String componentName, String hostName); @Transactional void create(AlertHistoryEntity alert); @Transactional void refresh(AlertHistoryEntity alert); @Transactional AlertHistoryEntity merge(AlertHistoryEntity alert); @Transactional void remove(AlertHistoryEntity alert); @Transactional void create(AlertCurrentEntity alert); @Transactional void refresh(AlertCurrentEntity alert); @Transactional AlertCurrentEntity merge(AlertCurrentEntity alert); AlertCurrentEntity merge(AlertCurrentEntity alert, boolean updateCacheOnly); @Transactional void remove(AlertCurrentEntity alert); @RequiresSession AlertSummaryDTO findAggregateCounts(long clusterId, String alertName); AlertCurrentEntity findCurrentByNameNoHost(long clusterId, String alertName); @Transactional void flushCachedEntitiesToJPA(); @Transactional @Override long cleanup(TimeBasedCleanupPolicy policy);  }