Repository: ambari Updated Branches: refs/heads/trunk f9014f604 -> 4bab98c9e
AMBARI-8865 - Alerts On MySQL Don't Have The Correct Host Counts (jonathanhurley) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/4bab98c9 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/4bab98c9 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/4bab98c9 Branch: refs/heads/trunk Commit: 4bab98c9e84ee3af6e7b7d6115d50dfaba276820 Parents: f9014f6 Author: Jonathan Hurley <[email protected]> Authored: Mon Dec 22 13:07:40 2014 -0500 Committer: Jonathan Hurley <[email protected]> Committed: Mon Dec 22 15:43:50 2014 -0500 ---------------------------------------------------------------------- .../org/apache/ambari/server/orm/dao/AlertsDAO.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/4bab98c9/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertsDAO.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertsDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertsDAO.java index 6fac728..016dfe5 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertsDAO.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertsDAO.java @@ -356,8 +356,10 @@ public class AlertsDAO { sb.append("FROM AlertCurrentEntity alert JOIN alert.alertHistory history "); sb.append("WHERE history.clusterId = :clusterId AND history.hostName IS NOT NULL GROUP BY history.hostName"); - TypedQuery<Integer> query = entityManagerProvider.get().createQuery( - sb.toString(), Integer.class); + // use Number here since some databases like MySQL return Long and some + // return Integer and we don't want a class cast exception + TypedQuery<Number> query = entityManagerProvider.get().createQuery( + sb.toString(), Number.class); query.setParameter("clusterId", Long.valueOf(clusterId)); query.setParameter("criticalState", AlertState.CRITICAL); @@ -369,13 +371,15 @@ public class AlertsDAO { int criticalCount = 0; int unknownCount = 0; - List<Integer> hostStateValues = daoUtils.selectList(query); - for (Integer hostStateValue : hostStateValues) { + List<Number> hostStateValues = daoUtils.selectList(query); + for (Number hostStateValue : hostStateValues) { if (null == hostStateValue) { continue; } - switch (hostStateValue) { + int integerValue = hostStateValue.intValue(); + + switch (integerValue) { case 0: okCount++; break;
