You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jo...@apache.org on 2014/09/29 18:18:41 UTC

git commit: AMBARI-7540 - Alerts: Stack Alerts Should Not Be Merged Into the DB (jonathanhurley)

Repository: ambari
Updated Branches:
  refs/heads/branch-alerts-dev f923fd880 -> a42b72726


AMBARI-7540 - Alerts: Stack Alerts Should Not Be Merged Into the DB (jonathanhurley)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/a42b7272
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a42b7272
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a42b7272

Branch: refs/heads/branch-alerts-dev
Commit: a42b727260fde066429347f640c4cb1958f712e3
Parents: f923fd8
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Mon Sep 29 11:06:22 2014 -0400
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Mon Sep 29 12:17:53 2014 -0400

----------------------------------------------------------------------
 .../ambari_agent/dummy_files/definitions.json   |  2 +-
 .../server/api/services/AmbariMetaInfo.java     | 17 ++++++--
 .../stacks/HDP/2.0.6/services/HDFS/alerts.json  |  6 +++
 .../server/api/services/AmbariMetaInfoTest.java | 42 ++++++++++++++++++++
 4 files changed, 62 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/a42b7272/ambari-agent/src/test/python/ambari_agent/dummy_files/definitions.json
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/dummy_files/definitions.json b/ambari-agent/src/test/python/ambari_agent/dummy_files/definitions.json
index 8e01833..6e80dea 100644
--- a/ambari-agent/src/test/python/ambari_agent/dummy_files/definitions.json
+++ b/ambari-agent/src/test/python/ambari_agent/dummy_files/definitions.json
@@ -15,7 +15,7 @@
         "component": "NAMENODE",
         "label": "NameNode process",
         "interval": 6,
-        "scope": "host",
+        "scope": "HOST",
         "uuid": "3f82ae27-fa6a-465b-b77d-67963ac55d2f",
         "enabled": true,
         "source": {

http://git-wip-us.apache.org/repos/asf/ambari/blob/a42b7272/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
index c15f73b..28dd397 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
@@ -197,6 +197,7 @@ public class AmbariMetaInfo {
 
     alertDefinitionFactory = injector.getInstance(AlertDefinitionFactory.class);
     alertDefinitionDao = injector.getInstance(AlertDefinitionDAO.class);
+    eventPublisher = injector.getInstance(AmbariEventPublisher.class);
   }
 
   /**
@@ -1275,12 +1276,20 @@ public class AmbariMetaInfo {
           continue;
         }
 
-        // if the definition exists in the stack and the database and they are
-        // not deeply equal, then merge the stack definition into the database
+        // definitions from the stack that are altered will not be overwritten;
+        // use the REST APIs to modify them instead
         AlertDefinition databaseDefinition = alertDefinitionFactory.coerce(entity);
         if (!stackDefinition.deeplyEquals(databaseDefinition)) {
-          entity = alertDefinitionFactory.merge(stackDefinition, entity);
-          persist.add(entity);
+          // this is the code that would normally merge the stack definition
+          // into the database; this is not the behavior we want today
+
+          // entity = alertDefinitionFactory.merge(stackDefinition, entity);
+          // persist.add(entity);
+
+          LOG.debug(
+              "The alert named {} has been modified from the stack definition and will not be merged",
+              stackDefinition.getName());
+
           continue;
         }
       }

http://git-wip-us.apache.org/repos/asf/ambari/blob/a42b7272/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/HDFS/alerts.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/HDFS/alerts.json b/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/HDFS/alerts.json
index 620c89f..d81170a 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/HDFS/alerts.json
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/HDFS/alerts.json
@@ -5,6 +5,7 @@
       "label": "Percent DataNodes Live",
       "interval": 1,
       "scope": "SERVICE",
+      "enabled": true,
       "source": {
         "type": "AGGREGATE",
         "alert_name": "datanode_process",
@@ -30,6 +31,7 @@
       "label": "NameNode Process",
       "interval": 1,
       "scope": "ANY",
+      "enabled": true,
       "source": {
         "type": "PORT",
         "uri": "{{hdfs-site/dfs.namenode.http-address}}",
@@ -49,6 +51,7 @@
       "label": "NameNode host CPU utilization",
       "interval": 2,
       "scope": "ANY",
+      "enabled": true,
       "source": {
         "type": "METRIC",
         "uri": "{{hdfs-site/dfs.namenode.http-address}}",
@@ -81,6 +84,7 @@
       "label": "Secondary NameNode Process",
       "interval": 1,
       "scope": "any",
+      "enabled": true,
       "source": {
         "type": "PORT",        
         "uri": "{{hdfs-site/dfs.namenode.secondary.http-address}}",
@@ -102,6 +106,7 @@
       "label": "JournalNode Process",
       "interval": 1,
       "scope": "host",
+      "enabled": true,
       "source": {
         "type": "PORT",        
         "uri": "{{hdfs-site/dfs.journalnode.http-address}}",
@@ -123,6 +128,7 @@
       "label": "DateNode Process",
       "interval": 1,
       "scope": "host",
+      "enabled": true,
       "source": {
         "type": "PORT",        
         "uri": "{{hdfs-site/dfs.datanode.http.address}}",

http://git-wip-us.apache.org/repos/asf/ambari/blob/a42b7272/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
index 4c59a36..613b950 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
@@ -47,7 +47,12 @@ import org.apache.ambari.server.api.util.StackExtensionHelper;
 import org.apache.ambari.server.metadata.ActionMetadata;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.OrmTestHelper;
+import org.apache.ambari.server.orm.dao.AlertDefinitionDAO;
+import org.apache.ambari.server.orm.entities.AlertDefinitionEntity;
 import org.apache.ambari.server.state.AutoDeployInfo;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.ComponentInfo;
 import org.apache.ambari.server.state.CustomCommandDefinition;
 import org.apache.ambari.server.state.DependencyInfo;
@@ -56,6 +61,7 @@ import org.apache.ambari.server.state.PropertyInfo;
 import org.apache.ambari.server.state.RepositoryInfo;
 import org.apache.ambari.server.state.ServiceInfo;
 import org.apache.ambari.server.state.Stack;
+import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.StackInfo;
 import org.apache.ambari.server.state.alert.AlertDefinition;
 import org.apache.ambari.server.state.alert.PortSource;
@@ -1617,6 +1623,42 @@ public class AmbariMetaInfoTest {
     assertNotNull(reporting.getWarning().getValue());
   }
 
+  /**
+   * Tests merging stack-based with existing definitions works
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testAlertDefinitionMerging() throws Exception {
+    injector.getInstance(OrmTestHelper.class).createCluster();
+    Clusters clusters = injector.getInstance(Clusters.class);
+    Cluster cluster = clusters.getClusterById(1);
+    cluster.setDesiredStackVersion(
+        new StackId(STACK_NAME_HDP, "2.0.6"));
+
+    cluster.addService("HDFS");
+
+    metaInfo.reconcileAlertDefinitions(clusters);
+
+    AlertDefinitionDAO dao = injector.getInstance(AlertDefinitionDAO.class);
+    List<AlertDefinitionEntity> definitions = dao.findAll();
+    assertEquals(4, definitions.size());
+
+    for (AlertDefinitionEntity definition : definitions) {
+      definition.setScheduleInterval(28);
+      dao.merge(definition);
+    }
+
+    metaInfo.reconcileAlertDefinitions(clusters);
+
+    definitions = dao.findAll();
+    assertEquals(4, definitions.size());
+
+    for (AlertDefinitionEntity definition : definitions) {
+      assertEquals(28, definition.getScheduleInterval().intValue());
+    }
+  }
+
   private AmbariMetaInfo setupTempAmbariMetaInfo(String buildDir)
       throws Exception {
     File stackRootTmp = new File(buildDir + "/ambari-metaInfo");