|
@@ -262,85 +262,19 @@ public class AlertDefinitionHash {
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * Gets the alert definition entities for the specified host. This will include the
|
|
|
- * following types of alert definitions:
|
|
|
- * <ul>
|
|
|
- * <li>Service/Component alerts</li>
|
|
|
- * <li>Service alerts where the host is a MASTER</li>
|
|
|
- * <li>Host alerts that are not bound to a service</li>
|
|
|
- * </ul>
|
|
|
+ * Invalidate the hashes of any host that would be affected by the specified
|
|
|
+ * definition.
|
|
|
*
|
|
|
- * @param clusterName
|
|
|
- * the cluster name (not {@code null}).
|
|
|
- * @param hostName
|
|
|
- * the host name (not {@code null}).
|
|
|
- * @return the alert definitions for the host, or an empty set (never
|
|
|
+ * @param definition
|
|
|
+ * the definition to use to find the hosts to invlidate (not
|
|
|
+ * {@code null}).
|
|
|
+ * @return the hosts that were invalidated, or an empty set (never
|
|
|
* {@code null}).
|
|
|
*/
|
|
|
- private Set<AlertDefinitionEntity> getAlertDefinitionEntities(
|
|
|
- String clusterName,
|
|
|
- String hostName) {
|
|
|
- Set<AlertDefinitionEntity> definitions = new HashSet<AlertDefinitionEntity>();
|
|
|
-
|
|
|
- try {
|
|
|
- Cluster cluster = m_clusters.getCluster(clusterName);
|
|
|
- if (null == cluster) {
|
|
|
- LOG.warn("Unable to get alert definitions for the missing cluster {}",
|
|
|
- clusterName);
|
|
|
-
|
|
|
- return Collections.emptySet();
|
|
|
- }
|
|
|
-
|
|
|
- long clusterId = cluster.getClusterId();
|
|
|
- List<ServiceComponentHost> serviceComponents = cluster.getServiceComponentHosts(hostName);
|
|
|
- if (null == serviceComponents || serviceComponents.size() == 0) {
|
|
|
- LOG.warn(
|
|
|
- "Unable to get alert definitions for {} since there are no service components defined",
|
|
|
- hostName);
|
|
|
-
|
|
|
- return Collections.emptySet();
|
|
|
- }
|
|
|
-
|
|
|
- for (ServiceComponentHost serviceComponent : serviceComponents) {
|
|
|
- String serviceName = serviceComponent.getServiceName();
|
|
|
- String componentName = serviceComponent.getServiceComponentName();
|
|
|
-
|
|
|
- // add all alerts for this service/component pair
|
|
|
- definitions.addAll(m_definitionDao.findByServiceComponent(
|
|
|
- clusterId, serviceName, componentName));
|
|
|
- }
|
|
|
-
|
|
|
- // for every service, get the master components and see if the host
|
|
|
- // is a master
|
|
|
- Set<String> services = new HashSet<String>();
|
|
|
- for (Entry<String, Service> entry : cluster.getServices().entrySet()) {
|
|
|
- Service service = entry.getValue();
|
|
|
- Map<String, ServiceComponent> components = service.getServiceComponents();
|
|
|
- for (Entry<String, ServiceComponent> component : components.entrySet()) {
|
|
|
- if (component.getValue().isMasterComponent()) {
|
|
|
- Map<String, ServiceComponentHost> hosts = component.getValue().getServiceComponentHosts();
|
|
|
-
|
|
|
- if( hosts.containsKey( hostName ) ){
|
|
|
- services.add(service.getName());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // add all service scoped alerts
|
|
|
- if( services.size() > 0 ){
|
|
|
- definitions.addAll(m_definitionDao.findByServiceMaster(clusterId,
|
|
|
- services));
|
|
|
- }
|
|
|
-
|
|
|
- // add any alerts not bound to a service (host level alerts)
|
|
|
- definitions.addAll(m_definitionDao.findAgentScoped(clusterId));
|
|
|
- } catch (AmbariException ambariException) {
|
|
|
- LOG.error("Unable to get alert definitions", ambariException);
|
|
|
- return Collections.emptySet();
|
|
|
- }
|
|
|
-
|
|
|
- return definitions;
|
|
|
+ public Set<String> invalidateHosts(AlertDefinitionEntity definition) {
|
|
|
+ return invalidateHosts(definition.getClusterId(),
|
|
|
+ definition.getDefinitionName(), definition.getServiceName(),
|
|
|
+ definition.getComponentName());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -353,8 +287,28 @@ public class AlertDefinitionHash {
|
|
|
* @return the hosts that were invalidated, or an empty set (never
|
|
|
* {@code null}).
|
|
|
*/
|
|
|
- public Set<String> invalidateHosts(AlertDefinitionEntity definition) {
|
|
|
- long clusterId = definition.getClusterId();
|
|
|
+ public Set<String> invalidateHosts(AlertDefinition definition) {
|
|
|
+ return invalidateHosts(definition.getClusterId(), definition.getName(),
|
|
|
+ definition.getServiceName(), definition.getComponentName());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Invalidate the hashes of any host that would be affected by the specified
|
|
|
+ * definition.
|
|
|
+ *
|
|
|
+ * @param clusterId
|
|
|
+ * the cluster ID
|
|
|
+ * @param definitionName
|
|
|
+ * the definition unique name.
|
|
|
+ * @param definitionServiceName
|
|
|
+ * the definition's service name.
|
|
|
+ * @param definitionComponentName
|
|
|
+ * the definition's component name.
|
|
|
+ * @return the hosts that were invalidated, or an empty set (never
|
|
|
+ * {@code null}).
|
|
|
+ */
|
|
|
+ public Set<String> invalidateHosts(long clusterId, String definitionName,
|
|
|
+ String definitionServiceName, String definitionComponentName) {
|
|
|
Set<String> invalidatedHosts = new HashSet<String>();
|
|
|
|
|
|
Cluster cluster = null;
|
|
@@ -379,8 +333,6 @@ public class AlertDefinitionHash {
|
|
|
}
|
|
|
|
|
|
// intercept host agent alerts; they affect all hosts
|
|
|
- String definitionServiceName = definition.getServiceName();
|
|
|
- String definitionComponentName = definition.getComponentName();
|
|
|
if (Services.AMBARI.equals(definitionServiceName)
|
|
|
&& Components.AMBARI_AGENT.equals(definitionComponentName)) {
|
|
|
|
|
@@ -413,7 +365,7 @@ public class AlertDefinitionHash {
|
|
|
Service service = services.get(definitionServiceName);
|
|
|
if (null == service) {
|
|
|
LOG.warn("The alert definition {} has an unknown service of {}",
|
|
|
- definition.getDefinitionName(), definitionServiceName);
|
|
|
+ definitionName, definitionServiceName);
|
|
|
|
|
|
return invalidatedHosts;
|
|
|
}
|
|
@@ -438,6 +390,82 @@ public class AlertDefinitionHash {
|
|
|
return invalidatedHosts;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Enqueue {@link AlertDefinitionCommand}s for every host specified so that
|
|
|
+ * they will receive a payload of alert definitions that they should be
|
|
|
+ * running.
|
|
|
+ * <p/>
|
|
|
+ * This method is typically called after
|
|
|
+ * {@link #invalidateHosts(AlertDefinitionEntity)} has caused a cache
|
|
|
+ * invalidation of the alert definition hash.
|
|
|
+ *
|
|
|
+ * @param clusterName
|
|
|
+ * the name of the cluster (not {@code null}).
|
|
|
+ * @param hosts
|
|
|
+ * the hosts to push {@link AlertDefinitionCommand}s for.
|
|
|
+ */
|
|
|
+ public void enqueueAgentCommands(long clusterId, Set<String> hosts) {
|
|
|
+ String clusterName = null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ Cluster cluster = m_clusters.getClusterById(clusterId);
|
|
|
+ clusterName = cluster.getClusterName();
|
|
|
+ } catch (AmbariException ae) {
|
|
|
+ LOG.error("Unable to lookup cluster for alert definition commands", ae);
|
|
|
+ }
|
|
|
+
|
|
|
+ enqueueAgentCommands(clusterName, hosts);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Enqueue {@link AlertDefinitionCommand}s for every host specified so that
|
|
|
+ * they will receive a payload of alert definitions that they should be
|
|
|
+ * running.
|
|
|
+ * <p/>
|
|
|
+ * This method is typically called after
|
|
|
+ * {@link #invalidateHosts(AlertDefinitionEntity)} has caused a cache
|
|
|
+ * invalidation of the alert definition hash.
|
|
|
+ *
|
|
|
+ * @param clusterName
|
|
|
+ * the name of the cluster (not {@code null}).
|
|
|
+ * @param hosts
|
|
|
+ * the hosts to push {@link AlertDefinitionCommand}s for.
|
|
|
+ */
|
|
|
+ public void enqueueAgentCommands(String clusterName, Set<String> hosts) {
|
|
|
+ if (null == clusterName) {
|
|
|
+ LOG.warn("Unable to create alert definition agent commands because of a null cluster name");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null == hosts || hosts.size() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (String hostName : hosts) {
|
|
|
+ List<AlertDefinition> definitions = getAlertDefinitions(clusterName,
|
|
|
+ hostName);
|
|
|
+
|
|
|
+ String hash = getHash(clusterName, hostName);
|
|
|
+
|
|
|
+ AlertDefinitionCommand command = new AlertDefinitionCommand(clusterName,
|
|
|
+ hostName, hash, definitions);
|
|
|
+
|
|
|
+ try {
|
|
|
+ Cluster cluster = m_clusters.getCluster(clusterName);
|
|
|
+ command.addConfigs(m_configHelper.get(), cluster);
|
|
|
+ } catch (AmbariException ae) {
|
|
|
+ LOG.warn("Unable to add configurations to alert definition command", ae);
|
|
|
+ }
|
|
|
+
|
|
|
+ // unlike other commands, the alert definitions commands are really
|
|
|
+ // designed to be 1:1 per change; if multiple invalidations happened
|
|
|
+ // before the next heartbeat, there would be several commands that would
|
|
|
+ // force the agents to reschedule their alerts more than once
|
|
|
+ m_actionQueue.dequeue(hostName, AgentCommandType.ALERT_DEFINITION_COMMAND);
|
|
|
+ m_actionQueue.enqueue(hostName, command);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Calculates a unique hash value representing all of the alert definitions
|
|
|
* that should be scheduled to run on a given host. Alerts of type
|
|
@@ -492,51 +520,84 @@ public class AlertDefinitionHash {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Enqueue {@link AlertDefinitionCommand}s for every host specified so that
|
|
|
- * they will receive a payload of alert definitions that they should be
|
|
|
- * running.
|
|
|
- * <p/>
|
|
|
- * This method is typically called after
|
|
|
- * {@link #invalidateHosts(AlertDefinitionEntity)} has caused a cache
|
|
|
- * invalidation of the alert definition hash.
|
|
|
+ * Gets the alert definition entities for the specified host. This will include the
|
|
|
+ * following types of alert definitions:
|
|
|
+ * <ul>
|
|
|
+ * <li>Service/Component alerts</li>
|
|
|
+ * <li>Service alerts where the host is a MASTER</li>
|
|
|
+ * <li>Host alerts that are not bound to a service</li>
|
|
|
+ * </ul>
|
|
|
*
|
|
|
* @param clusterName
|
|
|
- * the name of the cluster (not {@code null}).
|
|
|
- * @param hosts
|
|
|
- * the hosts to push {@link AlertDefinitionCommand}s for.
|
|
|
+ * the cluster name (not {@code null}).
|
|
|
+ * @param hostName
|
|
|
+ * the host name (not {@code null}).
|
|
|
+ * @return the alert definitions for the host, or an empty set (never
|
|
|
+ * {@code null}).
|
|
|
*/
|
|
|
- public void enqueueAgentCommands(String clusterName, Set<String> hosts) {
|
|
|
- if (null == clusterName) {
|
|
|
- LOG.warn("Unable to create alert definition agent commands because of a null cluster name");
|
|
|
- return;
|
|
|
- }
|
|
|
+ private Set<AlertDefinitionEntity> getAlertDefinitionEntities(
|
|
|
+ String clusterName,
|
|
|
+ String hostName) {
|
|
|
+ Set<AlertDefinitionEntity> definitions = new HashSet<AlertDefinitionEntity>();
|
|
|
|
|
|
- if (null == hosts || hosts.size() == 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ try {
|
|
|
+ Cluster cluster = m_clusters.getCluster(clusterName);
|
|
|
+ if (null == cluster) {
|
|
|
+ LOG.warn("Unable to get alert definitions for the missing cluster {}",
|
|
|
+ clusterName);
|
|
|
|
|
|
- for (String hostName : hosts) {
|
|
|
- List<AlertDefinition> definitions = getAlertDefinitions(clusterName,
|
|
|
- hostName);
|
|
|
+ return Collections.emptySet();
|
|
|
+ }
|
|
|
|
|
|
- String hash = getHash(clusterName, hostName);
|
|
|
+ long clusterId = cluster.getClusterId();
|
|
|
+ List<ServiceComponentHost> serviceComponents = cluster.getServiceComponentHosts(hostName);
|
|
|
+ if (null == serviceComponents || serviceComponents.size() == 0) {
|
|
|
+ LOG.warn(
|
|
|
+ "Unable to get alert definitions for {} since there are no service components defined",
|
|
|
+ hostName);
|
|
|
|
|
|
- AlertDefinitionCommand command = new AlertDefinitionCommand(clusterName,
|
|
|
- hostName, hash, definitions);
|
|
|
+ return Collections.emptySet();
|
|
|
+ }
|
|
|
|
|
|
- try {
|
|
|
- Cluster cluster = m_clusters.getCluster(clusterName);
|
|
|
- command.addConfigs(m_configHelper.get(), cluster);
|
|
|
- } catch (AmbariException ae) {
|
|
|
- LOG.warn("Unable to add configurations to alert definition command", ae);
|
|
|
+ for (ServiceComponentHost serviceComponent : serviceComponents) {
|
|
|
+ String serviceName = serviceComponent.getServiceName();
|
|
|
+ String componentName = serviceComponent.getServiceComponentName();
|
|
|
+
|
|
|
+ // add all alerts for this service/component pair
|
|
|
+ definitions.addAll(m_definitionDao.findByServiceComponent(
|
|
|
+ clusterId, serviceName, componentName));
|
|
|
}
|
|
|
|
|
|
- // unlike other commands, the alert definitions commands are really
|
|
|
- // designed to be 1:1 per change; if multiple invalidations happened
|
|
|
- // before the next heartbeat, there would be several commands that would
|
|
|
- // force the agents to reschedule their alerts more than once
|
|
|
- m_actionQueue.dequeue(hostName, AgentCommandType.ALERT_DEFINITION_COMMAND);
|
|
|
- m_actionQueue.enqueue(hostName, command);
|
|
|
+ // for every service, get the master components and see if the host
|
|
|
+ // is a master
|
|
|
+ Set<String> services = new HashSet<String>();
|
|
|
+ for (Entry<String, Service> entry : cluster.getServices().entrySet()) {
|
|
|
+ Service service = entry.getValue();
|
|
|
+ Map<String, ServiceComponent> components = service.getServiceComponents();
|
|
|
+ for (Entry<String, ServiceComponent> component : components.entrySet()) {
|
|
|
+ if (component.getValue().isMasterComponent()) {
|
|
|
+ Map<String, ServiceComponentHost> hosts = component.getValue().getServiceComponentHosts();
|
|
|
+
|
|
|
+ if( hosts.containsKey( hostName ) ){
|
|
|
+ services.add(service.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // add all service scoped alerts
|
|
|
+ if( services.size() > 0 ){
|
|
|
+ definitions.addAll(m_definitionDao.findByServiceMaster(clusterId,
|
|
|
+ services));
|
|
|
+ }
|
|
|
+
|
|
|
+ // add any alerts not bound to a service (host level alerts)
|
|
|
+ definitions.addAll(m_definitionDao.findAgentScoped(clusterId));
|
|
|
+ } catch (AmbariException ambariException) {
|
|
|
+ LOG.error("Unable to get alert definitions", ambariException);
|
|
|
+ return Collections.emptySet();
|
|
|
}
|
|
|
+
|
|
|
+ return definitions;
|
|
|
}
|
|
|
}
|