@Test public void testUpdateAlertDefinitions() { EasyMockSupport easyMockSupport = new EasyMockSupport(); long clusterId = 1; final AmbariManagementController mockAmbariManagementController = easyMockSupport.createNiceMock(AmbariManagementController.class); final AlertDefinitionDAO mockAlertDefinitionDAO = easyMockSupport.createNiceMock(AlertDefinitionDAO.class); final Clusters mockClusters = easyMockSupport.createStrictMock(Clusters.class); final Cluster mockClusterExpected = easyMockSupport.createNiceMock(Cluster.class); final AlertDefinitionEntity mockAmsZookeeperProcessAlertDefinitionEntity = easyMockSupport.createNiceMock(AlertDefinitionEntity.class); final Injector mockInjector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(AmbariManagementController.class).toInstance(mockAmbariManagementController); bind(Clusters.class).toInstance(mockClusters); bind(EntityManager.class).toInstance(entityManager); bind(AlertDefinitionDAO.class).toInstance(mockAlertDefinitionDAO); bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class)); bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class)); } }); expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).once(); expect(mockClusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{ put("normal", mockClusterExpected); }}).atLeastOnce(); expect(mockClusterExpected.getClusterId()).andReturn(clusterId).anyTimes(); expect(mockAlertDefinitionDAO.findByName(eq(clusterId), eq("ams_metrics_collector_zookeeper_server_process"))) .andReturn(mockAmsZookeeperProcessAlertDefinitionEntity).atLeastOnce(); mockAlertDefinitionDAO.remove(mockAmsZookeeperProcessAlertDefinitionEntity); expectLastCall().once(); easyMockSupport.replayAll(); mockInjector.getInstance(UpgradeCatalog221.class).updateAlerts(); easyMockSupport.verifyAll(); }
protected void updateAlerts() { LOG.info("Updating alert definitions."); AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); AlertDefinitionDAO alertDefinitionDAO = injector.getInstance(AlertDefinitionDAO.class); Clusters clusters = ambariManagementController.getClusters(); Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters); for (final Cluster cluster : clusterMap.values()) { long clusterID = cluster.getClusterId(); final AlertDefinitionEntity hiveMetastoreProcessAlertDefinitionEntity = alertDefinitionDAO.findByName( clusterID, "hive_metastore_process"); final AlertDefinitionEntity hiveServerProcessAlertDefinitionEntity = alertDefinitionDAO.findByName( clusterID, "hive_server_process"); List<AlertDefinitionEntity> hiveAlertDefinitions = new ArrayList<>(); if(hiveMetastoreProcessAlertDefinitionEntity != null) { hiveAlertDefinitions.add(hiveMetastoreProcessAlertDefinitionEntity); } if(hiveServerProcessAlertDefinitionEntity != null) { hiveAlertDefinitions.add(hiveServerProcessAlertDefinitionEntity); } for(AlertDefinitionEntity alertDefinition : hiveAlertDefinitions){ String source = alertDefinition.getSource(); alertDefinition.setScheduleInterval(3); alertDefinition.setSource(addCheckCommandTimeoutParam(source)); alertDefinition.setHash(UUID.randomUUID().toString()); alertDefinitionDAO.merge(alertDefinition); } final AlertDefinitionEntity amsZookeeperProcessAlertDefinitionEntity = alertDefinitionDAO.findByName( clusterID, "ams_metrics_collector_zookeeper_server_process"); if (amsZookeeperProcessAlertDefinitionEntity != null) { LOG.info("Removing alert : ams_metrics_collector_zookeeper_server_process"); alertDefinitionDAO.remove(amsZookeeperProcessAlertDefinitionEntity); } } }
UpgradeCatalog221 extends AbstractUpgradeCatalog { protected void updateAlerts() { LOG.info("Updating alert definitions."); AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); AlertDefinitionDAO alertDefinitionDAO = injector.getInstance(AlertDefinitionDAO.class); Clusters clusters = ambariManagementController.getClusters(); Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters); for (final Cluster cluster : clusterMap.values()) { long clusterID = cluster.getClusterId(); final AlertDefinitionEntity hiveMetastoreProcessAlertDefinitionEntity = alertDefinitionDAO.findByName( clusterID, "hive_metastore_process"); final AlertDefinitionEntity hiveServerProcessAlertDefinitionEntity = alertDefinitionDAO.findByName( clusterID, "hive_server_process"); List<AlertDefinitionEntity> hiveAlertDefinitions = new ArrayList<>(); if(hiveMetastoreProcessAlertDefinitionEntity != null) { hiveAlertDefinitions.add(hiveMetastoreProcessAlertDefinitionEntity); } if(hiveServerProcessAlertDefinitionEntity != null) { hiveAlertDefinitions.add(hiveServerProcessAlertDefinitionEntity); } for(AlertDefinitionEntity alertDefinition : hiveAlertDefinitions){ String source = alertDefinition.getSource(); alertDefinition.setScheduleInterval(3); alertDefinition.setSource(addCheckCommandTimeoutParam(source)); alertDefinition.setHash(UUID.randomUUID().toString()); alertDefinitionDAO.merge(alertDefinition); } final AlertDefinitionEntity amsZookeeperProcessAlertDefinitionEntity = alertDefinitionDAO.findByName( clusterID, "ams_metrics_collector_zookeeper_server_process"); if (amsZookeeperProcessAlertDefinitionEntity != null) { LOG.info("Removing alert : ams_metrics_collector_zookeeper_server_process"); alertDefinitionDAO.remove(amsZookeeperProcessAlertDefinitionEntity); } } } }
UpgradeCatalog221 extends AbstractUpgradeCatalog { protected void updateAlerts() { LOG.info("Updating alert definitions."); AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); AlertDefinitionDAO alertDefinitionDAO = injector.getInstance(AlertDefinitionDAO.class); Clusters clusters = ambariManagementController.getClusters(); Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters); for (final Cluster cluster : clusterMap.values()) { long clusterID = cluster.getClusterId(); final AlertDefinitionEntity hiveMetastoreProcessAlertDefinitionEntity = alertDefinitionDAO.findByName( clusterID, "hive_metastore_process"); final AlertDefinitionEntity hiveServerProcessAlertDefinitionEntity = alertDefinitionDAO.findByName( clusterID, "hive_server_process"); List<AlertDefinitionEntity> hiveAlertDefinitions = new ArrayList<>(); if(hiveMetastoreProcessAlertDefinitionEntity != null) { hiveAlertDefinitions.add(hiveMetastoreProcessAlertDefinitionEntity); } if(hiveServerProcessAlertDefinitionEntity != null) { hiveAlertDefinitions.add(hiveServerProcessAlertDefinitionEntity); } for(AlertDefinitionEntity alertDefinition : hiveAlertDefinitions){ String source = alertDefinition.getSource(); alertDefinition.setScheduleInterval(3); alertDefinition.setSource(addCheckCommandTimeoutParam(source)); alertDefinition.setHash(UUID.randomUUID().toString()); alertDefinitionDAO.merge(alertDefinition); } final AlertDefinitionEntity amsZookeeperProcessAlertDefinitionEntity = alertDefinitionDAO.findByName( clusterID, "ams_metrics_collector_zookeeper_server_process"); if (amsZookeeperProcessAlertDefinitionEntity != null) { LOG.info("Removing alert : ams_metrics_collector_zookeeper_server_process"); alertDefinitionDAO.remove(amsZookeeperProcessAlertDefinitionEntity); } } } @Inject  UpgradeCatalog221(Injector injector); }
UpgradeCatalog221 extends AbstractUpgradeCatalog { protected void updateAlerts() { LOG.info("Updating alert definitions."); AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); AlertDefinitionDAO alertDefinitionDAO = injector.getInstance(AlertDefinitionDAO.class); Clusters clusters = ambariManagementController.getClusters(); Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters); for (final Cluster cluster : clusterMap.values()) { long clusterID = cluster.getClusterId(); final AlertDefinitionEntity hiveMetastoreProcessAlertDefinitionEntity = alertDefinitionDAO.findByName( clusterID, "hive_metastore_process"); final AlertDefinitionEntity hiveServerProcessAlertDefinitionEntity = alertDefinitionDAO.findByName( clusterID, "hive_server_process"); List<AlertDefinitionEntity> hiveAlertDefinitions = new ArrayList<>(); if(hiveMetastoreProcessAlertDefinitionEntity != null) { hiveAlertDefinitions.add(hiveMetastoreProcessAlertDefinitionEntity); } if(hiveServerProcessAlertDefinitionEntity != null) { hiveAlertDefinitions.add(hiveServerProcessAlertDefinitionEntity); } for(AlertDefinitionEntity alertDefinition : hiveAlertDefinitions){ String source = alertDefinition.getSource(); alertDefinition.setScheduleInterval(3); alertDefinition.setSource(addCheckCommandTimeoutParam(source)); alertDefinition.setHash(UUID.randomUUID().toString()); alertDefinitionDAO.merge(alertDefinition); } final AlertDefinitionEntity amsZookeeperProcessAlertDefinitionEntity = alertDefinitionDAO.findByName( clusterID, "ams_metrics_collector_zookeeper_server_process"); if (amsZookeeperProcessAlertDefinitionEntity != null) { LOG.info("Removing alert : ams_metrics_collector_zookeeper_server_process"); alertDefinitionDAO.remove(amsZookeeperProcessAlertDefinitionEntity); } } } @Inject  UpgradeCatalog221(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion(); }
UpgradeCatalog221 extends AbstractUpgradeCatalog { protected void updateAlerts() { LOG.info("Updating alert definitions."); AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); AlertDefinitionDAO alertDefinitionDAO = injector.getInstance(AlertDefinitionDAO.class); Clusters clusters = ambariManagementController.getClusters(); Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters); for (final Cluster cluster : clusterMap.values()) { long clusterID = cluster.getClusterId(); final AlertDefinitionEntity hiveMetastoreProcessAlertDefinitionEntity = alertDefinitionDAO.findByName( clusterID, "hive_metastore_process"); final AlertDefinitionEntity hiveServerProcessAlertDefinitionEntity = alertDefinitionDAO.findByName( clusterID, "hive_server_process"); List<AlertDefinitionEntity> hiveAlertDefinitions = new ArrayList<>(); if(hiveMetastoreProcessAlertDefinitionEntity != null) { hiveAlertDefinitions.add(hiveMetastoreProcessAlertDefinitionEntity); } if(hiveServerProcessAlertDefinitionEntity != null) { hiveAlertDefinitions.add(hiveServerProcessAlertDefinitionEntity); } for(AlertDefinitionEntity alertDefinition : hiveAlertDefinitions){ String source = alertDefinition.getSource(); alertDefinition.setScheduleInterval(3); alertDefinition.setSource(addCheckCommandTimeoutParam(source)); alertDefinition.setHash(UUID.randomUUID().toString()); alertDefinitionDAO.merge(alertDefinition); } final AlertDefinitionEntity amsZookeeperProcessAlertDefinitionEntity = alertDefinitionDAO.findByName( clusterID, "ams_metrics_collector_zookeeper_server_process"); if (amsZookeeperProcessAlertDefinitionEntity != null) { LOG.info("Removing alert : ams_metrics_collector_zookeeper_server_process"); alertDefinitionDAO.remove(amsZookeeperProcessAlertDefinitionEntity); } } } @Inject  UpgradeCatalog221(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion();  }