ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amag...@apache.org
Subject [29/45] ambari git commit: AMBARI-21559. Alert definition paths should be updated on upgrade
Date Fri, 05 Jan 2018 07:56:25 GMT
AMBARI-21559. Alert definition paths should be updated on upgrade


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

Branch: refs/heads/branch-feature-AMBARI-22008-isilon
Commit: 217620b0a2d13e1ac8432d6dcb38ae27316d1aab
Parents: e2be62d
Author: Attila Doroszlai <adoroszlai@hortonworks.com>
Authored: Mon Jul 24 13:06:29 2017 +0200
Committer: Doroszlai, Attila <adoroszlai@hortonworks.com>
Committed: Thu Jan 4 15:59:59 2018 +0100

----------------------------------------------------------------------
 .../server/api/services/AmbariMetaInfo.java     | 34 ++++++++++--
 .../ambari/server/controller/AmbariServer.java  |  2 +-
 .../state/alert/AlertDefinitionFactory.java     | 31 ++++++++---
 .../ambari/server/state/alert/ScriptSource.java |  4 ++
 .../upgrade/AbstractFinalUpgradeCatalog.java    | 58 ++++++++++++++++++++
 .../server/upgrade/FinalUpgradeCatalog.java     | 28 +---------
 .../server/upgrade/SchemaUpgradeHelper.java     |  1 +
 .../server/upgrade/UpdateAlertScriptPaths.java  | 48 ++++++++++++++++
 .../server/api/services/AmbariMetaInfoTest.java |  6 +-
 9 files changed, 168 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/217620b0/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 9fee0ae..5f63c76 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
@@ -34,6 +34,7 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Scanner;
 import java.util.Set;
 
@@ -70,6 +71,9 @@ 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.AlertDefinitionFactory;
+import org.apache.ambari.server.state.alert.ScriptSource;
+import org.apache.ambari.server.state.alert.Source;
+import org.apache.ambari.server.state.alert.SourceType;
 import org.apache.ambari.server.state.kerberos.KerberosDescriptor;
 import org.apache.ambari.server.state.kerberos.KerberosDescriptorFactory;
 import org.apache.ambari.server.state.kerberos.KerberosServiceDescriptor;
@@ -1041,9 +1045,10 @@ public class AmbariMetaInfo {
    * service.
    *
    * @param clusters all clusters
-   * @throws AmbariException
+   * @param updateScriptPaths whether existing script-based alerts should be updated
+   *        with possibly new paths from the stack definition
    */
-  public void reconcileAlertDefinitions(Clusters clusters)
+  public void reconcileAlertDefinitions(Clusters clusters, boolean updateScriptPaths)
       throws AmbariException {
 
     Map<String, Cluster> clusterMap = clusters.getClusters();
@@ -1120,6 +1125,26 @@ public class AmbariMetaInfo {
           LOG.debug(
               "The alert named {} has been modified from the stack definition and will not
be merged",
               stackDefinition.getName());
+
+          if (updateScriptPaths) {
+            Source databaseSource = databaseDefinition.getSource();
+            Source stackSource = stackDefinition.getSource();
+            if (databaseSource.getType() == SourceType.SCRIPT && stackSource.getType()
== SourceType.SCRIPT) {
+              ScriptSource databaseScript = (ScriptSource) databaseSource;
+              ScriptSource stackScript = (ScriptSource) stackSource;
+              String oldPath = databaseScript.getPath();
+              String newPath = stackScript.getPath();
+              if (!Objects.equals(oldPath, newPath)) {
+                databaseScript.setPath(newPath);
+                entity = alertDefinitionFactory.mergeSource(databaseScript, entity);
+                persist.add(entity);
+
+                LOG.info("Updating script path for the alert named {} from '{}' to '{}'",
+                  stackDefinition.getName(), oldPath, newPath
+                );
+              }
+            }
+          }
         }
       }
 
@@ -1149,10 +1174,7 @@ public class AmbariMetaInfo {
 
       // persist any new or updated definition
       for (AlertDefinitionEntity entity : persist) {
-        if (LOG.isDebugEnabled()) {
-          LOG.info("Merging Alert Definition {} into the database",
-              entity.getDefinitionName());
-        }
+        LOG.debug("Merging Alert Definition {} into the database", entity.getDefinitionName());
         alertDefinitionDao.createOrUpdate(entity);
       }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/217620b0/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
index 64a4338..cb93e47 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
@@ -533,7 +533,7 @@ public class AmbariServer {
       LOG.info(clusterDump.toString());
 
       LOG.info("********* Reconciling Alert Definitions **********");
-      ambariMetaInfo.reconcileAlertDefinitions(clusters);
+      ambariMetaInfo.reconcileAlertDefinitions(clusters, false);
 
       LOG.info("********* Initializing ActionManager **********");
       ActionManager manager = injector.getInstance(ActionManager.class);

http://git-wip-us.apache.org/repos/asf/ambari/blob/217620b0/ambari-server/src/main/java/org/apache/ambari/server/state/alert/AlertDefinitionFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/alert/AlertDefinitionFactory.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/alert/AlertDefinitionFactory.java
index 2e309e5..ecf025f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/alert/AlertDefinitionFactory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/alert/AlertDefinitionFactory.java
@@ -249,7 +249,6 @@ public class AlertDefinitionFactory {
     entity.setDefinitionName(definition.getName());
     entity.setEnabled(definition.isEnabled());
     entity.setHostIgnored(definition.isHostIgnored());
-    entity.setHash(UUID.randomUUID().toString());
     entity.setLabel(definition.getLabel());
     entity.setDescription(definition.getDescription());
     entity.setScheduleInterval(definition.getInterval());
@@ -263,24 +262,42 @@ public class AlertDefinitionFactory {
 
     entity.setScope(scope);
 
-    Source source = definition.getSource();
+    return mergeSource(definition.getSource(), entity);
+  }
+
+  /**
+   * Updates source and source type of <code>entity</code> from <code>source</code>.
+   * Also updates UUID, which must be done for any change in to the entity for it
+   * to take effect on the agents.
+   *
+   * @return the updated entity to be persisted, or null if alert source cannot be serialized
to JSON
+   */
+  public AlertDefinitionEntity mergeSource(Source source, AlertDefinitionEntity entity) {
     entity.setSourceType(source.getType());
 
     try {
       String sourceJson = m_gson.toJson(source);
       entity.setSource(sourceJson);
-    } catch (Exception exception) {
-      LOG.error(
-          "Unable to serialize the alert definition source during coercion",
-          exception);
-
+    } catch (Exception e) {
+      LOG.error("Unable to serialize the alert definition source during merge", e);
       return null;
     }
 
+    assignNewUUID(entity);
+
     return entity;
   }
 
   /**
+   * Updates <code>entity</code> with a new UUID.
+   */
+  private static void assignNewUUID(AlertDefinitionEntity entity) {
+    if (entity != null) {
+      entity.setHash(UUID.randomUUID().toString());
+    }
+  }
+
+  /**
    * Gets an instance of {@link Gson} that can correctly serialize and
    * deserialize an {@link AlertDefinition}.
    *

http://git-wip-us.apache.org/repos/asf/ambari/blob/217620b0/ambari-server/src/main/java/org/apache/ambari/server/state/alert/ScriptSource.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/alert/ScriptSource.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/alert/ScriptSource.java
index a5ed440..a4f9b27 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/alert/ScriptSource.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/alert/ScriptSource.java
@@ -37,6 +37,10 @@ public class ScriptSource extends ParameterizedSource {
     return m_path;
   }
 
+  public void setPath(String path) {
+    m_path = path;
+  }
+
   /**
    * {@inheritDoc}
    */

http://git-wip-us.apache.org/repos/asf/ambari/blob/217620b0/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractFinalUpgradeCatalog.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractFinalUpgradeCatalog.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractFinalUpgradeCatalog.java
new file mode 100644
index 0000000..9abf548
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractFinalUpgradeCatalog.java
@@ -0,0 +1,58 @@
+/*
+ * 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
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.server.upgrade;
+
+import java.sql.SQLException;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.utils.VersionUtils;
+
+import com.google.inject.Injector;
+
+/**
+ * Upgrade catalog which is executed after all version-dependent catalogs.
+ */
+public abstract class AbstractFinalUpgradeCatalog extends AbstractUpgradeCatalog {
+  AbstractFinalUpgradeCatalog(Injector injector) {
+    super(injector);
+  }
+
+  @Override
+  protected void executeDDLUpdates() throws AmbariException, SQLException {
+    //no-op
+  }
+
+  @Override
+  protected void executePreDMLUpdates() throws AmbariException, SQLException {
+    //no-op
+  }
+
+  @Override
+  public String getTargetVersion() {
+    return getFinalVersion();
+  }
+
+  @Override
+  public boolean isFinal() {
+    return true;
+  }
+
+  private String getFinalVersion() {
+    return VersionUtils.getVersionSubstring(configuration.getServerVersion());
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/217620b0/ambari-server/src/main/java/org/apache/ambari/server/upgrade/FinalUpgradeCatalog.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/FinalUpgradeCatalog.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/FinalUpgradeCatalog.java
index 052edba..591ec38 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/FinalUpgradeCatalog.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/FinalUpgradeCatalog.java
@@ -35,7 +35,6 @@ import org.apache.ambari.server.state.PropertyInfo;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.StackInfo;
-import org.apache.ambari.server.utils.VersionUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -45,7 +44,7 @@ import com.google.inject.Injector;
 /**
  * Final upgrade catalog which simply updates database version (in case if no db changes
between releases)
  */
-public class FinalUpgradeCatalog extends AbstractUpgradeCatalog {
+public class FinalUpgradeCatalog extends AbstractFinalUpgradeCatalog {
 
   /**
    * Logger.
@@ -58,16 +57,6 @@ public class FinalUpgradeCatalog extends AbstractUpgradeCatalog {
   }
 
   @Override
-  protected void executeDDLUpdates() throws AmbariException, SQLException {
-    //noop
-  }
-
-  @Override
-  protected void executePreDMLUpdates() throws AmbariException, SQLException {
-    //noop
-  }
-
-  @Override
   protected void executeDMLUpdates() throws AmbariException, SQLException {
     updateClusterEnv();
   }
@@ -82,8 +71,6 @@ public class FinalUpgradeCatalog extends AbstractUpgradeCatalog {
    *
    * Note: Config properties stack_features and stack_tools should always be updated to latest
values as defined
    * in the stack on an Ambari upgrade.
-   *
-   * @throws Exception
    */
   protected void updateClusterEnv() throws AmbariException {
 
@@ -117,17 +104,4 @@ public class FinalUpgradeCatalog extends AbstractUpgradeCatalog {
     }
   }
 
-  @Override
-  public String getTargetVersion() {
-    return getFinalVersion();
-  }
-
-  @Override
-  public boolean isFinal() {
-    return true;
-  }
-
-  private String getFinalVersion() {
-    return VersionUtils.getVersionSubstring(configuration.getServerVersion());
-  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/217620b0/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
index 039e041..89fd1fb 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
@@ -187,6 +187,7 @@ public class SchemaUpgradeHelper {
       catalogBinder.addBinding().to(UpgradeCatalog260.class);
       catalogBinder.addBinding().to(UpgradeCatalog261.class);
       catalogBinder.addBinding().to(UpgradeCatalog300.class);
+      catalogBinder.addBinding().to(UpdateAlertScriptPaths.class);
       catalogBinder.addBinding().to(FinalUpgradeCatalog.class);
 
       EventBusSynchronizer.synchronizeAmbariEventPublisher(binder());

http://git-wip-us.apache.org/repos/asf/ambari/blob/217620b0/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpdateAlertScriptPaths.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpdateAlertScriptPaths.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpdateAlertScriptPaths.java
new file mode 100644
index 0000000..087a5af
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpdateAlertScriptPaths.java
@@ -0,0 +1,48 @@
+/*
+ * 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
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.server.upgrade;
+
+import java.sql.SQLException;
+
+import javax.inject.Inject;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.state.Clusters;
+
+import com.google.inject.Injector;
+
+/**
+ * Updates script-based alert definitions with paths from the stack.
+ */
+public class UpdateAlertScriptPaths extends AbstractFinalUpgradeCatalog {
+
+  @Inject
+  public UpdateAlertScriptPaths(Injector injector) {
+    super(injector);
+  }
+
+  @Override
+  protected void executeDMLUpdates() throws AmbariException, SQLException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    AmbariMetaInfo ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class);
+    Clusters clusters = ambariManagementController.getClusters();
+    ambariMetaInfo.reconcileAlertDefinitions(clusters, true);
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/217620b0/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 f98cffd..83b8f87 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
@@ -1718,7 +1718,7 @@ public class AmbariMetaInfoTest {
 
     cluster.addService("HDFS", repositoryVersion);
 
-    metaInfo.reconcileAlertDefinitions(clusters);
+    metaInfo.reconcileAlertDefinitions(clusters, false);
 
     AlertDefinitionDAO dao = injector.getInstance(AlertDefinitionDAO.class);
     List<AlertDefinitionEntity> definitions = dao.findAll(clusterId);
@@ -1742,7 +1742,7 @@ public class AmbariMetaInfoTest {
       dao.merge(definition);
     }
 
-    metaInfo.reconcileAlertDefinitions(clusters);
+    metaInfo.reconcileAlertDefinitions(clusters, false);
 
     definitions = dao.findAll();
     assertEquals(13, definitions.size());
@@ -1776,7 +1776,7 @@ public class AmbariMetaInfoTest {
     assertEquals(13, definitions.size());
 
     // reconcile, which should disable our bad definition
-    metaInfo.reconcileAlertDefinitions(clusters);
+    metaInfo.reconcileAlertDefinitions(clusters, false);
 
     // find all enabled for the cluster should find 6
     definitions = dao.findAllEnabled(cluster.getClusterId());


Mime
View raw message