Repository: ambari Updated Branches: refs/heads/trunk f8c34a088 -> bda839e1f
AMBARI-20010 Critical alert: 'Percent JournalNodes Available' appears after upgrade from ambari 2.2.2.0 to 2.5.0.0 (dsen) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/bda839e1 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/bda839e1 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/bda839e1 Branch: refs/heads/trunk Commit: bda839e1f1452dc711f7e33888ffa90b79e7be27 Parents: f8c34a0 Author: Dmytro Sen <[email protected]> Authored: Tue Feb 14 18:09:42 2017 +0200 Committer: Dmytro Sen <[email protected]> Committed: Tue Feb 14 18:10:00 2017 +0200 ---------------------------------------------------------------------- .../server/upgrade/UpgradeCatalog250.java | 37 ++++++++++++++++++++ .../server/upgrade/UpgradeCatalog250Test.java | 5 +++ 2 files changed, 42 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/bda839e1/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java index 1f93f1f..5e929e3 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java @@ -38,8 +38,11 @@ import org.apache.ambari.server.controller.AmbariManagementController; import org.apache.ambari.server.orm.DBAccessor; import org.apache.ambari.server.orm.DBAccessor.DBColumnInfo; import org.apache.ambari.server.orm.dao.AlertDefinitionDAO; +import org.apache.ambari.server.orm.dao.AlertsDAO; import org.apache.ambari.server.orm.dao.DaoUtils; +import org.apache.ambari.server.orm.entities.AlertCurrentEntity; import org.apache.ambari.server.orm.entities.AlertDefinitionEntity; +import org.apache.ambari.server.orm.entities.AlertHistoryEntity; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; import org.apache.ambari.server.state.Config; @@ -162,6 +165,7 @@ public class UpgradeCatalog250 extends AbstractUpgradeCatalog { addNewConfigurationsFromXml(); updateAMSConfigs(); updateStormAlerts(); + removeAlertDuplicates(); updateHadoopEnvConfigs(); updateKafkaConfigs(); updateHIVEInteractiveConfigs(); @@ -176,6 +180,39 @@ public class UpgradeCatalog250 extends AbstractUpgradeCatalog { addManageServiceAutoStartPermissions(); } + /** + * Removes all {@link AlertCurrentEntity} duplicates from database. + * Alerts are considered as duplicates if their definition, host and alert instance are the same. + * Duplicates could be created in earlier versions of Ambari up till 2.4.1. + */ + protected void removeAlertDuplicates() { + AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); + AlertsDAO alertsDao = injector.getInstance(AlertsDAO.class); + Clusters clusters = ambariManagementController.getClusters(); + + Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters); + for (final Cluster cluster : clusterMap.values()) { + long clusterID = cluster.getClusterId(); + LOG.info("Removing alert duplicates on cluster {}", cluster.getClusterName()); + List<AlertCurrentEntity> alertCurrentEntities = alertsDao.findCurrentByCluster(clusterID); + Set<AlertHistoryEntity> uniqueAlerts = new HashSet<>(); + for (AlertCurrentEntity alertCurrentEntity : alertCurrentEntities) { + + AlertHistoryEntity currentAlert = new AlertHistoryEntity(); + currentAlert.setAlertDefinition(alertCurrentEntity.getAlertHistory().getAlertDefinition()); + currentAlert.setHostName(alertCurrentEntity.getAlertHistory().getHostName()); + currentAlert.setAlertInstance(alertCurrentEntity.getAlertHistory().getAlertInstance()); + + if (uniqueAlerts.contains(currentAlert)) { + LOG.info("Alert entity duplicate {} will be removed",alertCurrentEntity.getAlertHistory()); + alertsDao.remove(alertCurrentEntity); + } else { + uniqueAlerts.add(currentAlert); + } + } + } + } + protected void updateStormAlerts() { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); AlertDefinitionDAO alertDefinitionDAO = injector.getInstance(AlertDefinitionDAO.class); http://git-wip-us.apache.org/repos/asf/ambari/blob/bda839e1/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java index cee490b..2836858 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java @@ -367,6 +367,7 @@ public class UpgradeCatalog250Test { Method updateRangerUrlConfigs = UpgradeCatalog250.class.getDeclaredMethod("updateRangerUrlConfigs"); Method updateYarnSite = UpgradeCatalog250.class.getDeclaredMethod("updateYarnSite"); Method updateAlerts = UpgradeCatalog250.class.getDeclaredMethod("updateStormAlerts"); + Method removeAlertDuplicates = UpgradeCatalog250.class.getDeclaredMethod("removeAlertDuplicates"); UpgradeCatalog250 upgradeCatalog250 = createMockBuilder(UpgradeCatalog250.class) .addMockedMethod(updateAmsConfigs) @@ -384,6 +385,7 @@ public class UpgradeCatalog250Test { .addMockedMethod(updateRangerUrlConfigs) .addMockedMethod(updateYarnSite) .addMockedMethod(updateAlerts) + .addMockedMethod(removeAlertDuplicates) .createMock(); upgradeCatalog250.updateAMSConfigs(); @@ -431,6 +433,9 @@ public class UpgradeCatalog250Test { upgradeCatalog250.updateStormAlerts(); expectLastCall().once(); + upgradeCatalog250.removeAlertDuplicates(); + expectLastCall().once(); + replay(upgradeCatalog250); upgradeCatalog250.executeDMLUpdates();
