You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by dm...@apache.org on 2015/09/23 17:29:14 UTC
[1/3] ambari git commit: AMBARI-13209. API returns incorrect info
about alerts (dlysnichenko)
Repository: ambari
Updated Branches:
refs/heads/branch-2.1 0894b5b8a -> f430fd3ca
refs/heads/branch-2.1.2 4fa100b6c -> 15c2ec39e
refs/heads/trunk 44573693b -> d05dd6654
AMBARI-13209. API returns incorrect info about alerts (dlysnichenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/15c2ec39
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/15c2ec39
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/15c2ec39
Branch: refs/heads/branch-2.1.2
Commit: 15c2ec39ea2a0933d0020c799b17e2deb723b064
Parents: 4fa100b
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Wed Sep 23 18:28:46 2015 +0300
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Wed Sep 23 18:29:20 2015 +0300
----------------------------------------------------------------------
.../apache/ambari/server/orm/dao/AlertsDAO.java | 56 +++++++-------------
1 file changed, 20 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/15c2ec39/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 39b12c4..0429534 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
@@ -71,14 +71,6 @@ public class AlertsDAO {
/**
* A template of JPQL for getting the number of hosts in various states.
*/
- private static final String HOST_COUNT_SQL_TEMPLATE = "SELECT MAX("
- + "CASE "
- + " WHEN history.alertState = :criticalState AND alert.maintenanceState = :maintenanceStateOff THEN 3 "
- + " WHEN history.alertState = :warningState AND alert.maintenanceState = :maintenanceStateOff THEN 2 "
- + " WHEN history.alertState = :unknownState AND alert.maintenanceState = :maintenanceStateOff THEN 1 ELSE 0 END) "
- + "FROM AlertCurrentEntity alert JOIN alert.alertHistory history "
- + "WHERE history.clusterId = :clusterId AND history.hostName IS NOT NULL GROUP BY history.hostName";
-
private static final String ALERT_COUNT_SQL_TEMPLATE = "SELECT NEW %s("
+ "SUM(CASE WHEN history.alertState = :okState AND alert.maintenanceState = :maintenanceStateOff THEN 1 ELSE 0 END), "
+ "SUM(CASE WHEN history.alertState = :warningState AND alert.maintenanceState = :maintenanceStateOff THEN 1 ELSE 0 END), "
@@ -497,12 +489,14 @@ public class AlertsDAO {
*/
@RequiresSession
public AlertHostSummaryDTO findCurrentHostCounts(long clusterId) {
- // use Number here since some databases like MySQL return Long and some
- // return Integer and we don't want a class cast exception
- TypedQuery<Object> query = m_entityManagerProvider.get().createQuery(
- HOST_COUNT_SQL_TEMPLATE, Object.class);
+ String sql = String.format(ALERT_COUNT_PER_HOST_SQL_TEMPLATE, HostAlertSummaryDTO.class.getName());
+
+ StringBuilder sb = new StringBuilder(sql);
+
+ TypedQuery<HostAlertSummaryDTO> query = m_entityManagerProvider.get().createQuery(sb.toString(), HostAlertSummaryDTO.class);
query.setParameter("clusterId", Long.valueOf(clusterId));
+ query.setParameter("okState", AlertState.OK);
query.setParameter("criticalState", AlertState.CRITICAL);
query.setParameter("warningState", AlertState.WARNING);
query.setParameter("unknownState", AlertState.UNKNOWN);
@@ -513,37 +507,27 @@ public class AlertsDAO {
int criticalCount = 0;
int unknownCount = 0;
- List<Object> hostStateValues = m_daoUtils.selectList(query);
- for (Object hostStateValue : hostStateValues) {
- if (null == hostStateValue) {
+ List<HostAlertSummaryDTO> resultList = m_daoUtils.selectList(query);
+ for (HostAlertSummaryDTO result : resultList) {
+ if (result.getHostName() == null) {
continue;
}
-
- int integerValue;
- if (hostStateValue instanceof Boolean) {
- integerValue = ((Boolean)hostStateValue).booleanValue() ? 1 : 0;
- } else {
- integerValue = ((Number)hostStateValue).intValue();
+ if (result.getCriticalCount() > 0) {
+ criticalCount++;
}
-
- switch (integerValue) {
- case 0:
- okCount++;
- break;
- case 1:
- unknownCount++;
- break;
- case 2:
- warningCount++;
- break;
- case 3:
- criticalCount++;
- break;
+ else if (result.getWarningCount() > 0) {
+ warningCount++;
+ }
+ else if (result.getUnknownCount() > 0) {
+ unknownCount++;
+ }
+ else {
+ okCount++;
}
}
AlertHostSummaryDTO hostSummary = new AlertHostSummaryDTO(okCount,
- unknownCount, warningCount, criticalCount);
+ unknownCount, warningCount, criticalCount);
return hostSummary;
}
[2/3] ambari git commit: AMBARI-13209. API returns incorrect info
about alerts (dlysnichenko)
Posted by dm...@apache.org.
AMBARI-13209. API returns incorrect info about alerts (dlysnichenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/f430fd3c
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/f430fd3c
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/f430fd3c
Branch: refs/heads/branch-2.1
Commit: f430fd3caf27b5a3aba5a9088e1c49b2d63e6666
Parents: 0894b5b
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Wed Sep 23 18:28:46 2015 +0300
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Wed Sep 23 18:29:53 2015 +0300
----------------------------------------------------------------------
.../apache/ambari/server/orm/dao/AlertsDAO.java | 56 +++++++-------------
1 file changed, 20 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/f430fd3c/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 39b12c4..0429534 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
@@ -71,14 +71,6 @@ public class AlertsDAO {
/**
* A template of JPQL for getting the number of hosts in various states.
*/
- private static final String HOST_COUNT_SQL_TEMPLATE = "SELECT MAX("
- + "CASE "
- + " WHEN history.alertState = :criticalState AND alert.maintenanceState = :maintenanceStateOff THEN 3 "
- + " WHEN history.alertState = :warningState AND alert.maintenanceState = :maintenanceStateOff THEN 2 "
- + " WHEN history.alertState = :unknownState AND alert.maintenanceState = :maintenanceStateOff THEN 1 ELSE 0 END) "
- + "FROM AlertCurrentEntity alert JOIN alert.alertHistory history "
- + "WHERE history.clusterId = :clusterId AND history.hostName IS NOT NULL GROUP BY history.hostName";
-
private static final String ALERT_COUNT_SQL_TEMPLATE = "SELECT NEW %s("
+ "SUM(CASE WHEN history.alertState = :okState AND alert.maintenanceState = :maintenanceStateOff THEN 1 ELSE 0 END), "
+ "SUM(CASE WHEN history.alertState = :warningState AND alert.maintenanceState = :maintenanceStateOff THEN 1 ELSE 0 END), "
@@ -497,12 +489,14 @@ public class AlertsDAO {
*/
@RequiresSession
public AlertHostSummaryDTO findCurrentHostCounts(long clusterId) {
- // use Number here since some databases like MySQL return Long and some
- // return Integer and we don't want a class cast exception
- TypedQuery<Object> query = m_entityManagerProvider.get().createQuery(
- HOST_COUNT_SQL_TEMPLATE, Object.class);
+ String sql = String.format(ALERT_COUNT_PER_HOST_SQL_TEMPLATE, HostAlertSummaryDTO.class.getName());
+
+ StringBuilder sb = new StringBuilder(sql);
+
+ TypedQuery<HostAlertSummaryDTO> query = m_entityManagerProvider.get().createQuery(sb.toString(), HostAlertSummaryDTO.class);
query.setParameter("clusterId", Long.valueOf(clusterId));
+ query.setParameter("okState", AlertState.OK);
query.setParameter("criticalState", AlertState.CRITICAL);
query.setParameter("warningState", AlertState.WARNING);
query.setParameter("unknownState", AlertState.UNKNOWN);
@@ -513,37 +507,27 @@ public class AlertsDAO {
int criticalCount = 0;
int unknownCount = 0;
- List<Object> hostStateValues = m_daoUtils.selectList(query);
- for (Object hostStateValue : hostStateValues) {
- if (null == hostStateValue) {
+ List<HostAlertSummaryDTO> resultList = m_daoUtils.selectList(query);
+ for (HostAlertSummaryDTO result : resultList) {
+ if (result.getHostName() == null) {
continue;
}
-
- int integerValue;
- if (hostStateValue instanceof Boolean) {
- integerValue = ((Boolean)hostStateValue).booleanValue() ? 1 : 0;
- } else {
- integerValue = ((Number)hostStateValue).intValue();
+ if (result.getCriticalCount() > 0) {
+ criticalCount++;
}
-
- switch (integerValue) {
- case 0:
- okCount++;
- break;
- case 1:
- unknownCount++;
- break;
- case 2:
- warningCount++;
- break;
- case 3:
- criticalCount++;
- break;
+ else if (result.getWarningCount() > 0) {
+ warningCount++;
+ }
+ else if (result.getUnknownCount() > 0) {
+ unknownCount++;
+ }
+ else {
+ okCount++;
}
}
AlertHostSummaryDTO hostSummary = new AlertHostSummaryDTO(okCount,
- unknownCount, warningCount, criticalCount);
+ unknownCount, warningCount, criticalCount);
return hostSummary;
}
[3/3] ambari git commit: AMBARI-13209. API returns incorrect info
about alerts (dlysnichenko)
Posted by dm...@apache.org.
AMBARI-13209. API returns incorrect info about alerts (dlysnichenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/d05dd665
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/d05dd665
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/d05dd665
Branch: refs/heads/trunk
Commit: d05dd665487aabad6f3b75297c396615f4eff94c
Parents: 4457369
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Wed Sep 23 18:28:46 2015 +0300
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Wed Sep 23 18:30:11 2015 +0300
----------------------------------------------------------------------
.../apache/ambari/server/orm/dao/AlertsDAO.java | 56 +++++++-------------
1 file changed, 20 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/d05dd665/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 39b12c4..0429534 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
@@ -71,14 +71,6 @@ public class AlertsDAO {
/**
* A template of JPQL for getting the number of hosts in various states.
*/
- private static final String HOST_COUNT_SQL_TEMPLATE = "SELECT MAX("
- + "CASE "
- + " WHEN history.alertState = :criticalState AND alert.maintenanceState = :maintenanceStateOff THEN 3 "
- + " WHEN history.alertState = :warningState AND alert.maintenanceState = :maintenanceStateOff THEN 2 "
- + " WHEN history.alertState = :unknownState AND alert.maintenanceState = :maintenanceStateOff THEN 1 ELSE 0 END) "
- + "FROM AlertCurrentEntity alert JOIN alert.alertHistory history "
- + "WHERE history.clusterId = :clusterId AND history.hostName IS NOT NULL GROUP BY history.hostName";
-
private static final String ALERT_COUNT_SQL_TEMPLATE = "SELECT NEW %s("
+ "SUM(CASE WHEN history.alertState = :okState AND alert.maintenanceState = :maintenanceStateOff THEN 1 ELSE 0 END), "
+ "SUM(CASE WHEN history.alertState = :warningState AND alert.maintenanceState = :maintenanceStateOff THEN 1 ELSE 0 END), "
@@ -497,12 +489,14 @@ public class AlertsDAO {
*/
@RequiresSession
public AlertHostSummaryDTO findCurrentHostCounts(long clusterId) {
- // use Number here since some databases like MySQL return Long and some
- // return Integer and we don't want a class cast exception
- TypedQuery<Object> query = m_entityManagerProvider.get().createQuery(
- HOST_COUNT_SQL_TEMPLATE, Object.class);
+ String sql = String.format(ALERT_COUNT_PER_HOST_SQL_TEMPLATE, HostAlertSummaryDTO.class.getName());
+
+ StringBuilder sb = new StringBuilder(sql);
+
+ TypedQuery<HostAlertSummaryDTO> query = m_entityManagerProvider.get().createQuery(sb.toString(), HostAlertSummaryDTO.class);
query.setParameter("clusterId", Long.valueOf(clusterId));
+ query.setParameter("okState", AlertState.OK);
query.setParameter("criticalState", AlertState.CRITICAL);
query.setParameter("warningState", AlertState.WARNING);
query.setParameter("unknownState", AlertState.UNKNOWN);
@@ -513,37 +507,27 @@ public class AlertsDAO {
int criticalCount = 0;
int unknownCount = 0;
- List<Object> hostStateValues = m_daoUtils.selectList(query);
- for (Object hostStateValue : hostStateValues) {
- if (null == hostStateValue) {
+ List<HostAlertSummaryDTO> resultList = m_daoUtils.selectList(query);
+ for (HostAlertSummaryDTO result : resultList) {
+ if (result.getHostName() == null) {
continue;
}
-
- int integerValue;
- if (hostStateValue instanceof Boolean) {
- integerValue = ((Boolean)hostStateValue).booleanValue() ? 1 : 0;
- } else {
- integerValue = ((Number)hostStateValue).intValue();
+ if (result.getCriticalCount() > 0) {
+ criticalCount++;
}
-
- switch (integerValue) {
- case 0:
- okCount++;
- break;
- case 1:
- unknownCount++;
- break;
- case 2:
- warningCount++;
- break;
- case 3:
- criticalCount++;
- break;
+ else if (result.getWarningCount() > 0) {
+ warningCount++;
+ }
+ else if (result.getUnknownCount() > 0) {
+ unknownCount++;
+ }
+ else {
+ okCount++;
}
}
AlertHostSummaryDTO hostSummary = new AlertHostSummaryDTO(okCount,
- unknownCount, warningCount, criticalCount);
+ unknownCount, warningCount, criticalCount);
return hostSummary;
}