UpgradeCatalog250 extends AbstractUpgradeCatalog { protected void updateLogSearchAlert() { 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 Log Search web ui alert definitions on cluster : " + cluster.getClusterName()); final AlertDefinitionEntity logSearchWebAlert = alertDefinitionDAO.findByName( clusterID, "logsearch_ui"); if (logSearchWebAlert != null) { LOG.info("Updating alert definition : " + logSearchWebAlert.getDefinitionName()); String source = logSearchWebAlert.getSource(); JsonObject sourceJson = new JsonParser().parse(source).getAsJsonObject(); LOG.debug("Source before update : " + sourceJson); JsonObject uriJson = sourceJson.get("uri").getAsJsonObject(); uriJson.remove("https_property"); uriJson.remove("https_property_value"); uriJson.addProperty("https_property", "{{logsearch-env/logsearch_ui_protocol}}"); uriJson.addProperty("https_property_value", "https"); LOG.debug("Source after update : " + sourceJson); logSearchWebAlert.setSource(sourceJson.toString()); alertDefinitionDAO.merge(logSearchWebAlert); } } } @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_LogSearchUIWebAlert() { 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 logSearchWebUIAlertMock = 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("logsearch_ui"))) .andReturn(logSearchWebUIAlertMock).atLeastOnce(); expect(logSearchWebUIAlertMock.getSource()).andReturn("{\"uri\": {\n" + " \"http\": \"{{logsearch-env/logsearch_ui_port}}\",\n" + " \"https\": \"{{logsearch-env/logsearch_ui_port}}\"\n" + " } }"); logSearchWebUIAlertMock.setSource("{\"uri\":{\"http\":\"{{logsearch-env/logsearch_ui_port}}\",\"https\":\"{{logsearch-env/logsearch_ui_port}}\",\"https_property\":\"{{logsearch-env/logsearch_ui_protocol}}\",\"https_property_value\":\"https\"}}"); expectLastCall().once(); easyMockSupport.replayAll(); mockInjector.getInstance(UpgradeCatalog250.class).updateLogSearchAlert(); easyMockSupport.verifyAll(); }