UpgradeCatalog250 extends AbstractUpgradeCatalog { protected void updateStormAlerts() { 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(); LOG.info("Updating storm alert definitions on cluster : " + cluster.getClusterName()); final AlertDefinitionEntity stormServerProcessDefinitionEntity = alertDefinitionDAO.findByName( clusterID, "storm_server_process"); final AlertDefinitionEntity stormWebAlert = alertDefinitionDAO.findByName( clusterID, "storm_webui"); if (stormServerProcessDefinitionEntity != null) { LOG.info("Removing alert definition : " + stormServerProcessDefinitionEntity.toString()); alertDefinitionDAO.remove(stormServerProcessDefinitionEntity); } if (stormWebAlert != null) { LOG.info("Updating alert definition : " + stormWebAlert.getDefinitionName()); String source = stormWebAlert.getSource(); JsonObject sourceJson = new JsonParser().parse(source).getAsJsonObject(); LOG.debug("Source before update : " + sourceJson); JsonObject uriJson = sourceJson.get("uri").getAsJsonObject(); uriJson.remove("https"); uriJson.remove("https_property"); uriJson.remove("https_property_value"); uriJson.addProperty("https", "{{storm-site/ui.https.port}}"); uriJson.addProperty("https_property", "{{storm-site/ui.https.keystore.type}}"); uriJson.addProperty("https_property_value", "jks"); LOG.debug("Source after update : " + sourceJson); stormWebAlert.setSource(sourceJson.toString()); alertDefinitionDAO.merge(stormWebAlert); } } } @Inject  UpgradeCatalog250(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion(); static final String COMPONENT_TABLE; static final String COMPONENT_VERSION_TABLE; static final String COMPONENT_VERSION_PK; static final String COMPONENT_VERSION_FK_COMPONENT; static final String COMPONENT_VERSION_FK_REPO_VERSION; }
@Test public void testUpdateAlerts_StormUIWebAlert() { EasyMockSupport easyMockSupport = new EasyMockSupport(); final AmbariManagementController mockAmbariManagementController = easyMockSupport.createNiceMock(AmbariManagementController.class); final Clusters mockClusters = easyMockSupport.createStrictMock(Clusters.class); final Cluster mockClusterExpected = easyMockSupport.createNiceMock(Cluster.class); final AlertDefinitionDAO mockAlertDefinitionDAO = easyMockSupport.createNiceMock(AlertDefinitionDAO.class); final AlertDefinitionEntity stormWebUIAlertMock = easyMockSupport.createNiceMock(AlertDefinitionEntity.class); final Injector mockInjector = createInjector(mockAmbariManagementController, mockClusters, mockAlertDefinitionDAO); long clusterId = 1; 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("storm_webui"))) .andReturn(stormWebUIAlertMock).atLeastOnce(); expect(stormWebUIAlertMock.getSource()).andReturn("{\"uri\": {\n" + " \"http\": \"{{storm-site/ui.port}}\",\n" + " \"kerberos_keytab\": \"{{storm-env/storm_ui_keytab}}\",\n" + " \"kerberos_principal\": \"{{storm-env/storm_ui_principal_name}}\",\n" + " \"connection_timeout\": 5.0\n" + " } }"); stormWebUIAlertMock.setSource("{\"uri\":{\"http\":\"{{storm-site/ui.port}}\",\"kerberos_keytab\":\"{{storm-env/storm_ui_keytab}}\",\"kerberos_principal\":\"{{storm-env/storm_ui_principal_name}}\",\"connection_timeout\":5.0,\"https\":\"{{storm-site/ui.https.port}}\",\"https_property\":\"{{storm-site/ui.https.keystore.type}}\",\"https_property_value\":\"jks\"}}"); expectLastCall().once(); easyMockSupport.replayAll(); mockInjector.getInstance(UpgradeCatalog250.class).updateStormAlerts(); easyMockSupport.verifyAll(); }
@Test public void testUpdateAlerts_StormUIPortAlert() { EasyMockSupport easyMockSupport = new EasyMockSupport(); final AmbariManagementController mockAmbariManagementController = easyMockSupport.createNiceMock(AmbariManagementController.class); final Clusters mockClusters = easyMockSupport.createStrictMock(Clusters.class); final Cluster mockClusterExpected = easyMockSupport.createNiceMock(Cluster.class); final AlertDefinitionDAO mockAlertDefinitionDAO = easyMockSupport.createNiceMock(AlertDefinitionDAO.class); final AlertDefinitionEntity stormUIPortAlertMock = easyMockSupport.createNiceMock(AlertDefinitionEntity.class); final Injector mockInjector = createInjector(mockAmbariManagementController, mockClusters, mockAlertDefinitionDAO); long clusterId = 1; 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("storm_server_process"))) .andReturn(stormUIPortAlertMock).atLeastOnce(); mockAlertDefinitionDAO.remove(stormUIPortAlertMock); expectLastCall().once(); easyMockSupport.replayAll(); mockInjector.getInstance(UpgradeCatalog250.class).updateStormAlerts(); easyMockSupport.verifyAll(); }