@Test public void testFindCurrentByDefinitionId() throws Exception { AlertDefinitionEntity definition = new AlertDefinitionEntity(); definition.setDefinitionName("Foo Definition"); definition.setServiceName("YARN"); definition.setComponentName("NODEMANAGER"); definition.setClusterId(m_cluster.getClusterId()); definition.setHash(UUID.randomUUID().toString()); definition.setScheduleInterval(Integer.valueOf(60)); definition.setScope(Scope.HOST); definition.setSource("{\"type\" : \"SCRIPT\"}"); definition.setSourceType(SourceType.SCRIPT); m_definitionDao.create(definition); AlertHistoryEntity history = new AlertHistoryEntity(); history.setServiceName(definition.getServiceName()); history.setClusterId(m_cluster.getClusterId()); history.setAlertDefinition(definition); history.setAlertLabel(definition.getDefinitionName()); history.setAlertText(definition.getDefinitionName()); history.setAlertTimestamp(Long.valueOf(1L)); history.setHostName("h1"); history.setAlertState(AlertState.OK); m_dao.create(history); AlertCurrentEntity current = new AlertCurrentEntity(); current.setOriginalTimestamp(1L); current.setLatestTimestamp(2L); current.setAlertHistory(history); m_dao.create(current); List<AlertCurrentEntity> currentAlerts = m_dao.findCurrentByDefinitionId(definition.getDefinitionId()); assertEquals(1, currentAlerts.size()); AlertHistoryEntity history2 = new AlertHistoryEntity(); history2.setServiceName(definition.getServiceName()); history2.setClusterId(m_cluster.getClusterId()); history2.setAlertDefinition(definition); history2.setAlertLabel(definition.getDefinitionName()); history2.setAlertText(definition.getDefinitionName()); history2.setAlertTimestamp(Long.valueOf(1L)); history2.setHostName("h2"); history2.setAlertState(AlertState.OK); m_dao.create(history); AlertCurrentEntity current2 = new AlertCurrentEntity(); current2.setOriginalTimestamp(1L); current2.setLatestTimestamp(2L); current2.setAlertHistory(history2); m_dao.create(current2); currentAlerts = m_dao.findCurrentByDefinitionId(definition.getDefinitionId()); assertEquals(2, currentAlerts.size()); }
@RequiresSession public List<AlertCurrentEntity> findCurrentByDefinitionId(long definitionId) { TypedQuery<AlertCurrentEntity> query = m_entityManagerProvider.get().createNamedQuery( "AlertCurrentEntity.findByDefinitionId", AlertCurrentEntity.class); query.setParameter("definitionId", Long.valueOf(definitionId)); List<AlertCurrentEntity> alerts = m_daoUtils.selectList(query); if (m_configuration.isAlertCacheEnabled()) { alerts = supplementWithCachedAlerts(alerts); } return alerts; }
AlertsDAO implements Cleanable { @RequiresSession public List<AlertCurrentEntity> findCurrentByDefinitionId(long definitionId) { TypedQuery<AlertCurrentEntity> query = m_entityManagerProvider.get().createNamedQuery( "AlertCurrentEntity.findByDefinitionId", AlertCurrentEntity.class); query.setParameter("definitionId", Long.valueOf(definitionId)); List<AlertCurrentEntity> alerts = m_daoUtils.selectList(query); if (m_configuration.isAlertCacheEnabled()) { alerts = supplementWithCachedAlerts(alerts); } return alerts; } }
AlertsDAO implements Cleanable { @RequiresSession public List<AlertCurrentEntity> findCurrentByDefinitionId(long definitionId) { TypedQuery<AlertCurrentEntity> query = m_entityManagerProvider.get().createNamedQuery( "AlertCurrentEntity.findByDefinitionId", AlertCurrentEntity.class); query.setParameter("definitionId", Long.valueOf(definitionId)); List<AlertCurrentEntity> alerts = m_daoUtils.selectList(query); if (m_configuration.isAlertCacheEnabled()) { alerts = supplementWithCachedAlerts(alerts); } return alerts; } @Inject  AlertsDAO(Configuration configuration); }
AlertsDAO implements Cleanable { @RequiresSession public List<AlertCurrentEntity> findCurrentByDefinitionId(long definitionId) { TypedQuery<AlertCurrentEntity> query = m_entityManagerProvider.get().createNamedQuery( "AlertCurrentEntity.findByDefinitionId", AlertCurrentEntity.class); query.setParameter("definitionId", Long.valueOf(definitionId)); List<AlertCurrentEntity> alerts = m_daoUtils.selectList(query); if (m_configuration.isAlertCacheEnabled()) { alerts = supplementWithCachedAlerts(alerts); } return alerts; } @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<AlertCurrentEntity> findCurrentByDefinitionId(long definitionId) { TypedQuery<AlertCurrentEntity> query = m_entityManagerProvider.get().createNamedQuery( "AlertCurrentEntity.findByDefinitionId", AlertCurrentEntity.class); query.setParameter("definitionId", Long.valueOf(definitionId)); List<AlertCurrentEntity> alerts = m_daoUtils.selectList(query); if (m_configuration.isAlertCacheEnabled()) { alerts = supplementWithCachedAlerts(alerts); } return alerts; } @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);  }