You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ad...@apache.org on 2017/09/08 18:14:26 UTC
ambari git commit: AMBARI-21878. Implement STOMP endpoint to handle
alerts from agent
Repository: ambari
Updated Branches:
refs/heads/branch-3.0-perf a5d85a899 -> ad1264127
AMBARI-21878. Implement STOMP endpoint to handle alerts from agent
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/ad126412
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/ad126412
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/ad126412
Branch: refs/heads/branch-3.0-perf
Commit: ad1264127c78c44eb05de15ffdbf6875e934f9bc
Parents: a5d85a8
Author: Attila Doroszlai <ad...@hortonworks.com>
Authored: Mon Sep 4 17:01:24 2017 +0200
Committer: Attila Doroszlai <ad...@hortonworks.com>
Committed: Fri Sep 8 20:10:02 2017 +0200
----------------------------------------------------------------------
.../python/ambari_agent/alerts/base_alert.py | 2 +-
.../ambari/server/agent/HeartbeatProcessor.java | 14 +-
.../agent/stomp/AgentReportsController.java | 25 ++--
.../alerts/AgentHeartbeatAlertRunnable.java | 2 +-
.../alerts/AmbariPerformanceRunnable.java | 2 +-
.../server/alerts/StaleAlertRunnable.java | 2 +-
.../server/events/AlertReceivedEvent.java | 8 +-
.../alerts/AlertAggregateListener.java | 7 +-
.../listeners/alerts/AlertReceivedListener.java | 89 +++++-------
.../org/apache/ambari/server/state/Alert.java | 134 +++++--------------
.../apache/ambari/server/state/Clusters.java | 5 +-
.../server/state/cluster/ClustersImpl.java | 4 +-
.../server/agent/HeartbeatProcessorTest.java | 2 +-
.../state/alerts/AlertReceivedListenerTest.java | 36 ++---
.../state/alerts/InitialAlertEventTest.java | 18 +--
.../state/cluster/AlertDataManagerTest.java | 8 +-
16 files changed, 130 insertions(+), 228 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/ad126412/ambari-agent/src/main/python/ambari_agent/alerts/base_alert.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/alerts/base_alert.py b/ambari-agent/src/main/python/ambari_agent/alerts/base_alert.py
index 76d8390..e364447 100644
--- a/ambari-agent/src/main/python/ambari_agent/alerts/base_alert.py
+++ b/ambari-agent/src/main/python/ambari_agent/alerts/base_alert.py
@@ -146,7 +146,7 @@ class BaseAlert(object):
data['name'] = self._get_alert_meta_value_safely('name')
data['label'] = self._get_alert_meta_value_safely('label')
data['uuid'] = self._get_alert_meta_value_safely('uuid')
- data['cluster'] = self.cluster_name
+ data['clusterId'] = self.cluster_id
data['service'] = self._get_alert_meta_value_safely('serviceName')
data['component'] = self._get_alert_meta_value_safely('componentName')
data['timestamp'] = long(time.time() * 1000)
http://git-wip-us.apache.org/repos/asf/ambari/blob/ad126412/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatProcessor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatProcessor.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatProcessor.java
index fce6be6..43470cf 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatProcessor.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatProcessor.java
@@ -227,19 +227,19 @@ public class HeartbeatProcessor extends AbstractService{
* the heartbeat to process.
*/
protected void processAlerts(HeartBeat heartbeat) {
- if (heartbeat == null) {
- return;
+ if (heartbeat != null) {
+ processAlerts(heartbeat.getHostname(), heartbeat.getAlerts());
}
+ }
- String hostname = heartbeat.getHostname();
-
- if (null != heartbeat.getAlerts()) {
- AlertEvent event = new AlertReceivedEvent(heartbeat.getAlerts());
- for (Alert alert : event.getAlerts()) {
+ public void processAlerts(String hostname, List<Alert> alerts) {
+ if (alerts != null && !alerts.isEmpty()) {
+ for (Alert alert : alerts) {
if (alert.getHostName() == null) {
alert.setHostName(hostname);
}
}
+ AlertEvent event = new AlertReceivedEvent(alerts);
alertEventPublisher.publish(event);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ad126412/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/AgentReportsController.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/AgentReportsController.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/AgentReportsController.java
index 0152d89..4d2b9d6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/AgentReportsController.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/AgentReportsController.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -18,6 +18,7 @@
package org.apache.ambari.server.agent.stomp;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -32,10 +33,10 @@ import org.apache.ambari.server.agent.stomp.dto.CommandStatusReports;
import org.apache.ambari.server.agent.stomp.dto.ComponentStatusReport;
import org.apache.ambari.server.agent.stomp.dto.ComponentStatusReports;
import org.apache.ambari.server.agent.stomp.dto.HostStatusReport;
-import org.apache.ambari.server.state.cluster.ClustersImpl;
+import org.apache.ambari.server.state.Alert;
import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.simp.annotation.SendToUser;
@@ -48,14 +49,12 @@ import com.google.inject.Injector;
@SendToUser("/")
@MessageMapping("/reports")
public class AgentReportsController {
- private static Log LOG = LogFactory.getLog(AgentReportsController.class);
+ private static final Logger LOG = LoggerFactory.getLogger(AgentReportsController.class);
private final HeartBeatHandler hh;
- private final ClustersImpl clusters;
private final AgentSessionManager agentSessionManager;
public AgentReportsController(Injector injector) {
hh = injector.getInstance(HeartBeatHandler.class);
- clusters = injector.getInstance(ClustersImpl.class);
agentSessionManager = injector.getInstance(AgentSessionManager.class);
}
@@ -70,9 +69,9 @@ public class AgentReportsController {
componentStatus.setComponentName(report.getComponentName());
componentStatus.setServiceName(report.getServiceName());
if (report.getCommand().equals(ComponentStatusReport.CommandStatusCommand.STATUS)) {
- componentStatus.setStatus(report.getStatus().toString());
+ componentStatus.setStatus(report.getStatus());
} else {
- componentStatus.setSecurityState(report.getStatus().toString());
+ componentStatus.setSecurityState(report.getStatus());
}
statuses.add(componentStatus);
}
@@ -99,4 +98,12 @@ public class AgentReportsController {
hh.handleHostReportStatus(message, agentSessionManager.getHost(simpSessionId).getHostName());
}
+ @SubscribeMapping("/alerts_status")
+ public void handleAlertsStatus(@Header String simpSessionId, Alert[] message) throws AmbariException {
+ String hostName = agentSessionManager.getHost(simpSessionId).getHostName();
+ List<Alert> alerts = Arrays.asList(message);
+ LOG.info("Handling {} alerts status for host {}", alerts.size(), hostName);
+ hh.getHeartbeatProcessor().processAlerts(hostName, alerts);
+ }
+
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ad126412/ambari-server/src/main/java/org/apache/ambari/server/alerts/AgentHeartbeatAlertRunnable.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/alerts/AgentHeartbeatAlertRunnable.java b/ambari-server/src/main/java/org/apache/ambari/server/alerts/AgentHeartbeatAlertRunnable.java
index 41be01e..c64c89f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/alerts/AgentHeartbeatAlertRunnable.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/alerts/AgentHeartbeatAlertRunnable.java
@@ -124,7 +124,7 @@ public class AgentHeartbeatAlertRunnable extends AlertRunnable {
alert.setLabel(definition.getLabel());
alert.setText(alertText);
alert.setTimestamp(alertTimestamp);
- alert.setCluster(cluster.getClusterName());
+ alert.setClusterId(cluster.getClusterId());
alerts.add(alert);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ad126412/ambari-server/src/main/java/org/apache/ambari/server/alerts/AmbariPerformanceRunnable.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/alerts/AmbariPerformanceRunnable.java b/ambari-server/src/main/java/org/apache/ambari/server/alerts/AmbariPerformanceRunnable.java
index a35e6fd..b4614e5 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/alerts/AmbariPerformanceRunnable.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/alerts/AmbariPerformanceRunnable.java
@@ -343,7 +343,7 @@ public class AmbariPerformanceRunnable extends AlertRunnable {
alert.setLabel(entity.getLabel());
alert.setText(overview);
alert.setTimestamp(System.currentTimeMillis());
- alert.setCluster(cluster.getClusterName());
+ alert.setClusterId(cluster.getClusterId());
return Collections.singletonList(alert);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ad126412/ambari-server/src/main/java/org/apache/ambari/server/alerts/StaleAlertRunnable.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/alerts/StaleAlertRunnable.java b/ambari-server/src/main/java/org/apache/ambari/server/alerts/StaleAlertRunnable.java
index 503ad92..bea0185 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/alerts/StaleAlertRunnable.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/alerts/StaleAlertRunnable.java
@@ -239,7 +239,7 @@ public class StaleAlertRunnable extends AlertRunnable {
alert.setLabel(myDefinition.getLabel());
alert.setText(alertText);
alert.setTimestamp(now);
- alert.setCluster(cluster.getClusterName());
+ alert.setClusterId(cluster.getClusterId());
return Collections.singletonList(alert);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ad126412/ambari-server/src/main/java/org/apache/ambari/server/events/AlertReceivedEvent.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/AlertReceivedEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/events/AlertReceivedEvent.java
index b17071c..a1225ce 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/events/AlertReceivedEvent.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/AlertReceivedEvent.java
@@ -27,12 +27,6 @@ import org.apache.ambari.server.state.Alert;
*/
public final class AlertReceivedEvent extends AlertEvent {
- /**
- * Constructor.
- *
- * @param clusterId
- * @param alert
- */
public AlertReceivedEvent(long clusterId, Alert alert) {
super(clusterId, alert);
}
@@ -47,7 +41,7 @@ public final class AlertReceivedEvent extends AlertEvent {
@Override
public String toString() {
StringBuilder buffer = new StringBuilder("AlertReceivedEvent{");
- buffer.append("cluserId=").append(m_clusterId);
+ buffer.append("clusterId=").append(m_clusterId);
buffer.append(", alerts=").append(getAlerts());
buffer.append("}");
return buffer.toString();
http://git-wip-us.apache.org/repos/asf/ambari/blob/ad126412/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertAggregateListener.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertAggregateListener.java b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertAggregateListener.java
index 1ed19a4..cb8071a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertAggregateListener.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertAggregateListener.java
@@ -22,7 +22,6 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.EagerSingleton;
import org.apache.ambari.server.events.AggregateAlertRecalculateEvent;
import org.apache.ambari.server.events.AlertReceivedEvent;
@@ -188,11 +187,7 @@ public class AlertAggregateListener {
aggregateAlert.setLabel(aggregateDefinition.getLabel());
aggregateAlert.setTimestamp(System.currentTimeMillis());
- try {
- aggregateAlert.setCluster(m_clusters.get().getClusterById(clusterId).getClusterName());
- } catch (AmbariException exception) {
- LOG.error("Unable to lookup cluster with ID {}", clusterId, exception);
- }
+ aggregateAlert.setClusterId(clusterId);
if (0 == totalCount) {
aggregateAlert.setText("There are no instances of the aggregated alert.");
http://git-wip-us.apache.org/repos/asf/ambari/blob/ad126412/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertReceivedListener.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertReceivedListener.java b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertReceivedListener.java
index 23a547f..3607df4 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertReceivedListener.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertReceivedListener.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -91,7 +91,7 @@ public class AlertReceivedListener {
* Used for looking up whether an alert has a valid service/component/host
*/
@Inject
- Provider<Clusters> m_clusters;
+ private Provider<Clusters> m_clusters;
@Inject
private StateUpdateEventPublisher stateUpdateEventPublisher;
@@ -119,8 +119,6 @@ public class AlertReceivedListener {
/**
* Constructor.
- *
- * @param publisher
*/
@Inject
public AlertReceivedListener(AlertEventPublisher publisher) {
@@ -160,8 +158,7 @@ public class AlertReceivedListener {
continue;
}
- String clusterName = alert.getCluster();
- Long clusterId = getClusterIdByName(clusterName);
+ Long clusterId = alert.getClusterId();
if (clusterId == null) {
// check event
clusterId = event.getClusterId();
@@ -172,8 +169,8 @@ public class AlertReceivedListener {
if (null == definition) {
LOG.warn(
- "Received an alert for {} which is a definition that does not exist anymore",
- alert.getName());
+ "Received an alert for {} which is a definition that does not exist in cluster id={}",
+ alert.getName(), clusterId);
continue;
}
@@ -261,7 +258,7 @@ public class AlertReceivedListener {
// still SOFT, then we transition it to HARD - we also need to fire an
// event
AlertFirmness firmness = current.getFirmness();
- int repeatTolerance = getRepeatTolerance(definition, clusterName);
+ int repeatTolerance = getRepeatTolerance(definition, clusterId);
if (firmness == AlertFirmness.SOFT && occurrences >= repeatTolerance) {
current.setFirmness(AlertFirmness.HARD);
@@ -332,7 +329,7 @@ public class AlertReceivedListener {
// set the firmness of the new alert state based on the state, type,
// occurrences, and repeat tolerance
- AlertFirmness firmness = calculateFirmnessForStateChange(clusterName, definition,
+ AlertFirmness firmness = calculateFirmnessForStateChange(clusterId, definition,
alertState, current.getOccurrences());
current.setFirmness(firmness);
@@ -381,21 +378,6 @@ public class AlertReceivedListener {
}
/**
- * Gets the cluster ID given a name.
- *
- * @param clusterName
- * @return
- */
- private Long getClusterIdByName(String clusterName) {
- try {
- return m_clusters.get().getCluster(clusterName).getClusterId();
- } catch (AmbariException e) {
- LOG.warn("Cluster lookup failed for cluster named {}", clusterName);
- return null;
- }
- }
-
- /**
* Gets the {@link AlertCurrentEntity} which cooresponds to the new alert being received, if any.
*
* @param clusterId the ID of the cluster.
@@ -456,7 +438,7 @@ public class AlertReceivedListener {
* cluster/service/component/host.
*/
private boolean isValid(Alert alert) {
- String clusterName = alert.getCluster();
+ Long clusterId = alert.getClusterId();
String serviceName = alert.getService();
String componentName = alert.getComponent();
String hostName = alert.getHostName();
@@ -471,14 +453,15 @@ public class AlertReceivedListener {
// if the alert is not bound to a cluster, then it's most likely a
// host alert and is always valid as long as the host exists
- if (StringUtils.isBlank(clusterName)) {
+ Clusters clusters = m_clusters.get();
+ if (clusterId == null) {
// no cluster, no host; return true out of respect for the unknown alert
if (StringUtils.isBlank(hostName)) {
return true;
}
// if a host is reported, it must be registered to some cluster somewhere
- if (!m_clusters.get().hostExists(hostName)) {
+ if (!clusters.hostExists(hostName)) {
LOG.error("Unable to process alert {} for an invalid host named {}",
alert.getName(), hostName);
return false;
@@ -493,22 +476,14 @@ public class AlertReceivedListener {
// - this is not for AMBARI_SERVER component
final Cluster cluster;
try {
- cluster = m_clusters.get().getCluster(clusterName);
+ cluster = clusters.getCluster(clusterId);
if (null == cluster) {
- LOG.error("Unable to process alert {} for an invalid cluster named {}",
- alert.getName(), clusterName);
-
+ LOG.error("Unable to process alert {} for cluster id={}", alert.getName(), clusterId);
return false;
}
} catch (AmbariException ambariException) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Unable to process alert {} for an invalid cluster named {}",
- alert.getName(), clusterName, ambariException);
- } else {
- LOG.error("Unable to process alert {} for an invalid cluster named {}",
- alert.getName(), clusterName);
- }
-
+ String msg = String.format("Unable to process alert %s for cluster id=%s", alert.getName(), clusterId);
+ LOG.error(msg, ambariException);
return false;
}
@@ -520,11 +495,11 @@ public class AlertReceivedListener {
// the agent's host is still a part of the reported cluster
if (ambariServiceName.equals(serviceName) && ambariAgentComponentName.equals(componentName)) {
// agents MUST report a hostname
- if (StringUtils.isBlank(hostName) || !m_clusters.get().hostExists(hostName)
- || !m_clusters.get().isHostMappedToCluster(clusterName, hostName)) {
+ if (StringUtils.isBlank(hostName) || !clusters.hostExists(hostName)
+ || !clusters.isHostMappedToCluster(clusterId, hostName)) {
LOG.warn(
"Unable to process alert {} for cluster {} and host {} because the host is not a part of the cluster.",
- alert.getName(), clusterName, hostName);
+ alert.getName(), hostName);
return false;
}
@@ -538,7 +513,7 @@ public class AlertReceivedListener {
// - not for the AMBARI service
if (StringUtils.isNotBlank(hostName)) {
// if valid hostname
- if (!m_clusters.get().hostExists(hostName)) {
+ if (!clusters.hostExists(hostName)) {
LOG.warn("Unable to process alert {} for an invalid host named {}",
alert.getName(), hostName);
return false;
@@ -585,8 +560,8 @@ public class AlertReceivedListener {
history.setAlertInstance(alert.getInstance());
history.setAlertState(alert.getState());
history.setAlertText(alert.getText());
- history.setAlertTimestamp(Long.valueOf(alert.getTimestamp()));
- history.setClusterId(Long.valueOf(clusterId));
+ history.setAlertTimestamp(alert.getTimestamp());
+ history.setClusterId(clusterId);
history.setComponentName(alert.getComponent());
history.setServiceName(alert.getService());
@@ -616,12 +591,12 @@ public class AlertReceivedListener {
* the definition to read any repeat tolerance overrides from.
* @param state
* the state of the {@link AlertCurrentEntity}.
- * @param the
+ * @param occurrences the
* occurrences of the alert in the current state (used for
* calculation firmness when moving between non-OK states)
* @return
*/
- private AlertFirmness calculateFirmnessForStateChange(String clusterName, AlertDefinitionEntity definition,
+ private AlertFirmness calculateFirmnessForStateChange(Long clusterId, AlertDefinitionEntity definition,
AlertState state, long occurrences) {
// OK is always HARD since the alert has fulfilled the conditions
if (state == AlertState.OK) {
@@ -633,7 +608,7 @@ public class AlertReceivedListener {
return AlertFirmness.HARD;
}
- int tolerance = getRepeatTolerance(definition, clusterName);
+ int tolerance = getRepeatTolerance(definition, clusterId);
if (tolerance <= 1) {
return AlertFirmness.HARD;
}
@@ -652,13 +627,11 @@ public class AlertReceivedListener {
* Otherwise, it uses {@link ConfigHelper#CLUSTER_ENV_ALERT_REPEAT_TOLERANCE},
* defaulting to {@code 1} if not found.
*
- * @param definition
- * the definition (not {@code null}).
- * @param clusterName
- * the name of the cluster (not {@code null}).
+ * @param definition the definition (not {@code null}).
+ * @param clusterId the ID of the cluster (not {@code null}).
* @return the repeat tolerance for the alert
*/
- private int getRepeatTolerance(AlertDefinitionEntity definition, String clusterName) {
+ private int getRepeatTolerance(AlertDefinitionEntity definition, Long clusterId) {
// if the definition overrides the global value, then use that
if (definition.isRepeatToleranceEnabled()) {
@@ -667,12 +640,14 @@ public class AlertReceivedListener {
int repeatTolerance = 1;
try {
- Cluster cluster = m_clusters.get().getCluster(clusterName);
+ Cluster cluster = m_clusters.get().getCluster(clusterId);
String value = cluster.getClusterProperty(ConfigHelper.CLUSTER_ENV_ALERT_REPEAT_TOLERANCE, "1");
repeatTolerance = NumberUtils.toInt(value, 1);
} catch (AmbariException ambariException) {
- LOG.warn("Unable to read {}/{} from cluster {}, defaulting to 1", ConfigHelper.CLUSTER_ENV,
- ConfigHelper.CLUSTER_ENV_ALERT_REPEAT_TOLERANCE, clusterName, ambariException);
+ String msg = String.format("Unable to read %s/%s from cluster %s, defaulting to 1",
+ ConfigHelper.CLUSTER_ENV, ConfigHelper.CLUSTER_ENV_ALERT_REPEAT_TOLERANCE, clusterId
+ );
+ LOG.warn(msg, ambariException);
}
return repeatTolerance;
http://git-wip-us.apache.org/repos/asf/ambari/blob/ad126412/ambari-server/src/main/java/org/apache/ambari/server/state/Alert.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Alert.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Alert.java
index 1caa0e3..6764d33 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/Alert.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Alert.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -17,22 +17,25 @@
*/
package org.apache.ambari.server.state;
+import java.util.Objects;
+
import org.apache.commons.lang.StringUtils;
import org.codehaus.jackson.annotate.JsonProperty;
/**
* An alert represents a problem or notice for a cluster.
*/
public class Alert {
- private String cluster = null;
- private String name = null;
- private String instance = null;
- private String service = null;
- private String component = null;
- private String hostName = null;
+ private String name;
+ private String instance;
+ private String service;
+ private String component;
+ private String hostName;
private AlertState state = AlertState.UNKNOWN;
- private String label = null;
- private String text = null;
- private long timestamp = 0L;
+ private String label;
+ private String text;
+ private long timestamp;
+ private Long clusterId;
+ private String uuid;
// Maximum string size for MySql TEXT (utf8) column data type
protected final static int MAX_ALERT_TEXT_SIZE = 32617;
@@ -198,118 +201,55 @@ public class Alert {
return timestamp;
}
- /**
- * @return
- */
- @JsonProperty("cluster")
- @com.fasterxml.jackson.annotation.JsonProperty("cluster")
- public String getCluster() {
- return cluster;
+ @com.fasterxml.jackson.annotation.JsonProperty("clusterId")
+ public Long getClusterId() {
+ return clusterId;
}
- @JsonProperty("cluster")
- @com.fasterxml.jackson.annotation.JsonProperty("cluster")
- public void setCluster(String cluster){
- this.cluster = cluster;
+ public void setClusterId(Long clusterId) {
+ this.clusterId = clusterId;
+ }
+
+ @com.fasterxml.jackson.annotation.JsonProperty("uuid")
+ public String getUUID() {
+ return uuid;
+ }
+
+ public void setUUID(String uuid) {
+ this.uuid = uuid;
}
- /**
- * {@inheritDoc}
- */
@Override
public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((state == null) ? 0 : state.hashCode());
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result + ((service == null) ? 0 : service.hashCode());
- result = prime * result + ((component == null) ? 0 : component.hashCode());
- result = prime * result + ((hostName == null) ? 0 : hostName.hashCode());
- result = prime * result + ((cluster == null) ? 0 : cluster.hashCode());
- result = prime * result + ((instance == null) ? 0 : instance.hashCode());
- return result;
+ return Objects.hash(state, name, service, component, hostName, instance, clusterId);
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
- if (obj == null) {
- return false;
- }
-
- if (getClass() != obj.getClass()) {
+ if (obj == null || getClass() != obj.getClass()) {
return false;
}
Alert other = (Alert) obj;
- if (state != other.state) {
- return false;
- }
-
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
- return false;
- }
-
- if (service == null) {
- if (other.service != null) {
- return false;
- }
- } else if (!service.equals(other.service)) {
- return false;
- }
-
- if (component == null) {
- if (other.component != null) {
- return false;
- }
- } else if (!component.equals(other.component)) {
- return false;
- }
-
- if (hostName == null) {
- if (other.hostName != null) {
- return false;
- }
- } else if (!hostName.equals(other.hostName)) {
- return false;
- }
-
- if (cluster == null) {
- if (other.cluster != null) {
- return false;
- }
- } else if (!cluster.equals(other.cluster)) {
- return false;
- }
-
- if (instance == null) {
- if (other.instance != null) {
- return false;
- }
- } else if (!instance.equals(other.instance)) {
- return false;
- }
-
-
- return true;
+ return Objects.equals(state, other.state) &&
+ Objects.equals(name, other.name) &&
+ Objects.equals(service, other.service) &&
+ Objects.equals(component, other.component) &&
+ Objects.equals(hostName, other.hostName) &&
+ Objects.equals(instance, other.instance) &&
+ Objects.equals(clusterId, other.clusterId);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append('{');
- sb.append("cluster=").append(cluster).append(", ");
+ sb.append("clusterId=").append(clusterId).append(", ");
sb.append("state=").append(state).append(", ");
sb.append("name=").append(name).append(", ");
sb.append("service=").append(service).append(", ");
http://git-wip-us.apache.org/repos/asf/ambari/blob/ad126412/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java
index aa53564..594707c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java
@@ -109,14 +109,13 @@ public interface Clusters {
/**
* Gets whether the specified cluster has a mapping for the specified host.
*
- * @param clusterName
- * the cluster (not {@code null}).
+ * @param clusterId the cluster ID
* @param hostName
* the host (not {@code null}).
* @return {@code true} if the host belongs to the cluster, {@code false}
* otherwise.
*/
- boolean isHostMappedToCluster(String clusterName, String hostName);
+ boolean isHostMappedToCluster(long clusterId, String hostName);
/**
* Get a Host object managed by this server
http://git-wip-us.apache.org/repos/asf/ambari/blob/ad126412/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
index aecfabe..702d776 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
@@ -386,10 +386,10 @@ public class ClustersImpl implements Clusters {
* {@inheritDoc}
*/
@Override
- public boolean isHostMappedToCluster(String clusterName, String hostName) {
+ public boolean isHostMappedToCluster(long clusterId, String hostName) {
Set<Cluster> clusters = hostClusterMap.get(hostName);
for (Cluster cluster : clusters) {
- if (clusterName.equals(cluster.getClusterName())) {
+ if (clusterId == cluster.getClusterId()) {
return true;
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ad126412/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java
index 9a6391c..b2546e0 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java
@@ -1193,7 +1193,7 @@ public class HeartbeatProcessorTest {
Alert alert = new Alert("foo", "bar", "baz", "foobar", "foobarbaz",
AlertState.OK);
- alert.setCluster("BADCLUSTER");
+ alert.setClusterId(-1L);
List<Alert> alerts = Collections.singletonList(alert);
hb.setAlerts(alerts);
http://git-wip-us.apache.org/repos/asf/ambari/blob/ad126412/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertReceivedListenerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertReceivedListenerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertReceivedListenerTest.java
index 68395b5..bde938f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertReceivedListenerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertReceivedListenerTest.java
@@ -152,7 +152,7 @@ public class AlertReceivedListenerTest {
Alert alert1 = new Alert(definitionName, null, "HDFS", componentName,
HOST1, AlertState.OK);
- alert1.setCluster(m_cluster.getClusterName());
+ alert1.setClusterId(m_cluster.getClusterId());
alert1.setLabel(ALERT_LABEL);
alert1.setText("HDFS " + componentName + " is OK");
alert1.setTimestamp(1L);
@@ -194,7 +194,7 @@ public class AlertReceivedListenerTest {
Alert alert = new Alert(definitionName, null, "HDFS", componentName,
HOST1, AlertState.OK);
- alert.setCluster(m_cluster.getClusterName());
+ alert.setClusterId(m_cluster.getClusterId());
alert.setLabel(ALERT_LABEL);
alert.setText("HDFS " + componentName + " is OK");
alert.setTimestamp(1L);
@@ -256,7 +256,7 @@ public class AlertReceivedListenerTest {
Alert alert = new Alert(definitionName, null, "HDFS", componentName,
HOST1, AlertState.OK);
- alert.setCluster(m_cluster.getClusterName());
+ alert.setClusterId(m_cluster.getClusterId());
alert.setLabel(ALERT_LABEL);
alert.setText("HDFS " + componentName + " is OK");
alert.setTimestamp(1L);
@@ -295,7 +295,7 @@ public class AlertReceivedListenerTest {
Alert alert1 = new Alert(definitionName, null, "HDFS", componentName, HOST1,
AlertState.CRITICAL);
- alert1.setCluster(m_cluster.getClusterName());
+ alert1.setClusterId(m_cluster.getClusterId());
alert1.setLabel(ALERT_LABEL);
alert1.setText("HDFS " + componentName + " is OK");
alert1.setTimestamp(1L);
@@ -342,7 +342,7 @@ public class AlertReceivedListenerTest {
Alert alert = new Alert(definitionName, null, serviceName, componentName, HOST1,
AlertState.OK);
- alert.setCluster(m_cluster.getClusterName());
+ alert.setClusterId(m_cluster.getClusterId());
alert.setLabel(ALERT_LABEL);
alert.setText(serviceName + " " + componentName + " is OK");
alert.setTimestamp(1L);
@@ -381,7 +381,7 @@ public class AlertReceivedListenerTest {
Alert alert = new Alert(definitionName, null, serviceName, componentName, HOST1,
AlertState.OK);
- alert.setCluster(m_cluster.getClusterName());
+ alert.setClusterId(m_cluster.getClusterId());
alert.setLabel(ALERT_LABEL);
alert.setText(serviceName + " " + componentName + " is OK");
alert.setTimestamp(1L);
@@ -396,7 +396,7 @@ public class AlertReceivedListenerTest {
// invalid host, invalid cluster
alert.setHostName("INVALID");
- alert.setCluster("INVALID");
+ alert.setClusterId(null);
// remove all
m_dao.removeCurrentByHost(HOST1);
@@ -422,7 +422,7 @@ public class AlertReceivedListenerTest {
Alert alert1 = new Alert(definitionName, null, serviceName, componentName, HOST1,
AlertState.OK);
- alert1.setCluster(m_cluster.getClusterName());
+ alert1.setClusterId(m_cluster.getClusterId());
alert1.setLabel(ALERT_LABEL);
alert1.setText(serviceName + " " + componentName + " is OK");
alert1.setTimestamp(1L);
@@ -436,7 +436,7 @@ public class AlertReceivedListenerTest {
assertEquals(1, allCurrent.size());
// missing cluster, invalid host
- alert1.setCluster(null);
+ alert1.setClusterId(null);
alert1.setHostName("INVALID");
// remove all
@@ -462,7 +462,7 @@ public class AlertReceivedListenerTest {
Alert alert = new Alert(definitionName, null, serviceName, componentName, HOST1, AlertState.SKIPPED);
- alert.setCluster(m_cluster.getClusterName());
+ alert.setClusterId(m_cluster.getClusterId());
alert.setLabel(ALERT_LABEL);
alert.setText(serviceName + " " + componentName + " is OK");
alert.setTimestamp(1L);
@@ -489,7 +489,7 @@ public class AlertReceivedListenerTest {
Alert alert = new Alert(definitionName, null, serviceName, componentName, HOST1, AlertState.OK);
- alert.setCluster(m_cluster.getClusterName());
+ alert.setClusterId(m_cluster.getClusterId());
alert.setLabel(ALERT_LABEL);
alert.setText(text);
alert.setTimestamp(1L);
@@ -546,7 +546,7 @@ public class AlertReceivedListenerTest {
Alert alert = new Alert(definitionName, null, serviceName, componentName, HOST1, AlertState.OK);
- alert.setCluster(m_cluster.getClusterName());
+ alert.setClusterId(m_cluster.getClusterId());
alert.setLabel(ALERT_LABEL);
alert.setText(text);
alert.setTimestamp(1L);
@@ -603,7 +603,7 @@ public class AlertReceivedListenerTest {
Alert alert = new Alert(definitionName, null, serviceName, componentName, HOST1,
AlertState.CRITICAL);
- alert.setCluster(m_cluster.getClusterName());
+ alert.setClusterId(m_cluster.getClusterId());
alert.setLabel(ALERT_LABEL);
alert.setText(text);
alert.setTimestamp(1L);
@@ -667,7 +667,7 @@ public class AlertReceivedListenerTest {
String text = serviceName + " " + componentName + " is OK";
Alert alert = new Alert(definitionName, null, serviceName, componentName, HOST1, AlertState.OK);
- alert.setCluster(m_cluster.getClusterName());
+ alert.setClusterId(m_cluster.getClusterId());
alert.setLabel(ALERT_LABEL);
alert.setText(text);
alert.setTimestamp(1L);
@@ -751,7 +751,7 @@ public class AlertReceivedListenerTest {
Alert alert = new Alert(definition.getDefinitionName(), null, definition.getServiceName(),
definition.getComponentName(), HOST1, AlertState.OK);
- alert.setCluster(m_cluster.getClusterName());
+ alert.setClusterId(m_cluster.getClusterId());
alert.setLabel(ALERT_LABEL);
alert.setText("Aggregate alerts are always HARD");
alert.setTimestamp(1L);
@@ -798,7 +798,7 @@ public class AlertReceivedListenerTest {
String text = serviceName + " " + componentName + " is OK";
Alert alert = new Alert(definitionName, null, serviceName, componentName, HOST1, AlertState.OK);
- alert.setCluster(m_cluster.getClusterName());
+ alert.setClusterId(m_cluster.getClusterId());
alert.setLabel(ALERT_LABEL);
alert.setText(text);
alert.setTimestamp(1L);
@@ -854,7 +854,7 @@ public class AlertReceivedListenerTest {
String text = serviceName + " " + componentName + " is OK";
Alert alert = new Alert(definitionName, null, serviceName, componentName, HOST1, AlertState.OK);
- alert.setCluster(m_cluster.getClusterName());
+ alert.setClusterId(m_cluster.getClusterId());
alert.setLabel(ALERT_LABEL);
alert.setText(text);
alert.setTimestamp(1L);
@@ -913,7 +913,7 @@ public class AlertReceivedListenerTest {
@Override
public void run() {
Alert alert = new Alert(definitionName, null, "HDFS", null, HOST1, AlertState.OK);
- alert.setCluster(m_cluster.getClusterName());
+ alert.setClusterId(m_cluster.getClusterId());
alert.setLabel(ALERT_LABEL);
alert.setText("HDFS is OK ");
alert.setTimestamp(System.currentTimeMillis());
http://git-wip-us.apache.org/repos/asf/ambari/blob/ad126412/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/InitialAlertEventTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/InitialAlertEventTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/InitialAlertEventTest.java
index 890464d..c3f8e00 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/InitialAlertEventTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/InitialAlertEventTest.java
@@ -67,14 +67,9 @@ public class InitialAlertEventTest {
private MockEventListener m_listener;
private AlertDefinitionDAO m_definitionDao;
- private Clusters m_clusters;
private Cluster m_cluster;
- private String m_clusterName;
private ServiceFactory m_serviceFactory;
- /**
- *
- */
@Before
public void setup() throws Exception {
m_injector = Guice.createInjector(Modules.override(
@@ -93,14 +88,14 @@ public class InitialAlertEventTest {
synchronizedBus.register(m_listener);
m_definitionDao = m_injector.getInstance(AlertDefinitionDAO.class);
- m_clusters = m_injector.getInstance(Clusters.class);
+ Clusters clusters = m_injector.getInstance(Clusters.class);
m_serviceFactory = m_injector.getInstance(ServiceFactory.class);
m_alertsDao = m_injector.getInstance(AlertsDAO.class);
- m_clusterName = "c1";
- m_clusters.addCluster(m_clusterName, new StackId("HDP", "2.0.6"));
- m_cluster = m_clusters.getCluster(m_clusterName);
+ String clusterName = "c1";
+ clusters.addCluster(clusterName, new StackId("HDP", "2.0.6"));
+ m_cluster = clusters.getCluster(clusterName);
Assert.assertNotNull(m_cluster);
// install HDFS to get 6 definitions
@@ -109,9 +104,6 @@ public class InitialAlertEventTest {
Assert.assertEquals(6, m_definitionDao.findAll().size());
}
- /**
- * @throws Exception
- */
@After
public void teardown() throws Exception {
H2DatabaseCleaner.clearDatabase(m_injector.getProvider(EntityManager.class).get());
@@ -140,7 +132,7 @@ public class InitialAlertEventTest {
definition.getServiceName(), definition.getComponentName(), null,
AlertState.CRITICAL);
- alert.setCluster(m_clusterName);
+ alert.setClusterId(m_cluster.getClusterId());
AlertReceivedEvent event = new AlertReceivedEvent(m_cluster.getClusterId(), alert);
http://git-wip-us.apache.org/repos/asf/ambari/blob/ad126412/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/AlertDataManagerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/AlertDataManagerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/AlertDataManagerTest.java
index 8d7d8ad..2942b32 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/AlertDataManagerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/AlertDataManagerTest.java
@@ -165,13 +165,13 @@ public class AlertDataManagerTest {
alert1.setLabel(ALERT_LABEL);
alert1.setText("Component component1 is OK");
alert1.setTimestamp(1L);
- alert1.setCluster(m_cluster.getClusterName());
+ alert1.setClusterId(m_cluster.getClusterId());
Alert alert2 = new Alert(ALERT_DEFINITION, null, SERVICE, COMPONENT, HOST2,
AlertState.CRITICAL);
alert2.setLabel(ALERT_LABEL);
alert2.setText("Component component2 is not OK");
- alert2.setCluster(m_cluster.getClusterName());
+ alert2.setClusterId(m_cluster.getClusterId());
AlertReceivedListener listener = m_injector.getInstance(AlertReceivedListener.class);
@@ -214,7 +214,7 @@ public class AlertDataManagerTest {
alert3.setLabel(ALERT_LABEL);
alert3.setText("Component component1 is OK");
alert3.setTimestamp(2L);
- alert3.setCluster(m_cluster.getClusterName());
+ alert3.setClusterId(m_cluster.getClusterId());
AlertReceivedEvent event3 = new AlertReceivedEvent(
m_cluster.getClusterId(),
@@ -247,7 +247,7 @@ public class AlertDataManagerTest {
alert4.setLabel(ALERT_LABEL);
alert4.setText("Component component1 is about to go down");
alert4.setTimestamp(3L);
- alert4.setCluster(m_cluster.getClusterName());
+ alert4.setClusterId(m_cluster.getClusterId());
AlertReceivedEvent event4 = new AlertReceivedEvent(