ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject ambari git commit: AMBARI-15253 - Ambari upgrade fails if there is incorrect version in upgrade table (jonathanhurley)
Date Wed, 02 Mar 2016 14:52:41 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.2 bf0014c50 -> 2d65e6aae


AMBARI-15253 - Ambari upgrade fails if there is incorrect version in upgrade table (jonathanhurley)


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

Branch: refs/heads/branch-2.2
Commit: 2d65e6aaebcec9227bd15f853de22445b09d6632
Parents: bf0014c
Author: Jonathan Hurley <jhurley@hortonworks.com>
Authored: Tue Mar 1 16:35:19 2016 -0500
Committer: Jonathan Hurley <jhurley@hortonworks.com>
Committed: Wed Mar 2 09:52:18 2016 -0500

----------------------------------------------------------------------
 .../server/upgrade/AbstractUpgradeCatalog.java  |  42 +++----
 .../server/upgrade/UpgradeCatalog220.java       | 114 ++++++++++++-------
 2 files changed, 96 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/2d65e6aa/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java
index 7cbdd33..7be2dfe 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java
@@ -17,11 +17,23 @@
  */
 package org.apache.ambari.server.upgrade;
 
-import com.google.common.collect.Maps;
-import com.google.inject.Inject;
-import com.google.inject.Injector;
-import com.google.inject.Provider;
-import com.google.inject.persist.Transactional;
+import java.io.StringReader;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.configuration.Configuration.DatabaseType;
@@ -48,21 +60,11 @@ import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.xml.sax.InputSource;
 
-import javax.persistence.EntityManager;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import java.io.StringReader;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
+import com.google.common.collect.Maps;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import com.google.inject.Provider;
+import com.google.inject.persist.Transactional;
 
 public abstract class AbstractUpgradeCatalog implements UpgradeCatalog {
   @Inject

http://git-wip-us.apache.org/repos/asf/ambari/blob/2d65e6aa/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog220.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog220.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog220.java
index 2330a21..ac6b3c5 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog220.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog220.java
@@ -18,15 +18,31 @@
 
 package org.apache.ambari.server.upgrade;
 
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import com.google.inject.Inject;
-import com.google.inject.Injector;
-import com.google.inject.persist.Transactional;
+import java.io.StringWriter;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.regex.Matcher;
+
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
 import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.controller.AmbariManagementController;
-import org.apache.ambari.server.state.Cluster;
-import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.AmbariManagementController;
@@ -47,23 +63,23 @@ import org.apache.ambari.server.orm.entities.ClusterEntity;
 import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
 import org.apache.ambari.server.orm.entities.HostEntity;
 import org.apache.ambari.server.orm.entities.HostVersionEntity;
-import org.apache.ambari.server.orm.entities.StackEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
+import org.apache.ambari.server.orm.entities.StackEntity;
 import org.apache.ambari.server.orm.entities.UpgradeEntity;
-
-
+import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.RepositoryVersionState;
 import org.apache.ambari.server.state.SecurityType;
 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.state.alert.SourceType;
+import org.apache.ambari.server.state.kerberos.KerberosComponentDescriptor;
 import org.apache.ambari.server.state.kerberos.KerberosDescriptor;
-import org.apache.ambari.server.state.kerberos.KerberosServiceDescriptor;
 import org.apache.ambari.server.state.kerberos.KerberosDescriptorFactory;
-import org.apache.ambari.server.state.kerberos.KerberosComponentDescriptor;
 import org.apache.ambari.server.state.kerberos.KerberosIdentityDescriptor;
+import org.apache.ambari.server.state.kerberos.KerberosServiceDescriptor;
 import org.apache.ambari.server.state.stack.upgrade.Direction;
 import org.apache.ambari.server.state.stack.upgrade.RepositoryVersionHelper;
 import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
@@ -76,28 +92,11 @@ import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-import java.io.StringWriter;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-import java.util.regex.Matcher;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import com.google.inject.persist.Transactional;
 
 /**
  * Upgrade catalog for version 2.2.0.
@@ -598,11 +597,32 @@ public class UpgradeCatalog220 extends AbstractUpgradeCatalog {
   }
 
   /**
-   * Find the single Repo Version for the given stack and version, and return its upgrade_package
column.
-   * Because the upgrade_package column is going to be removed from this entity, must use
raw SQL
-   * instead of the entity class.
-   * @param stack Stack
-   * @param version Stack version
+   * Find the single Repo Version for the given stack and version, and return
+   * its upgrade_package column. Because the upgrade_package column is going to
+   * be removed from this entity, must use raw SQL instead of the entity class.
+   * <p/>
+   * It's possible that there is an invalid version listed in the upgrade table.
+   * For example:
+   *
+   * <pre>
+   * upgrade
+   * 1 2 1295  2.2.0.0-2041  2.2.4.2-2     UPGRADE
+   * 2 2 1296  2.2.0.0-2041  2.2.0.0-2041  DOWNGRADE
+   * 3 2 1299  2.2.0.0-2041  2.2.4.2       UPGRADE
+   *
+   * repo_version
+   * 1  2.2.0.0-2041  HDP-2.2.0.0-2041  upgrade-2.2
+   * 2  2.2.4.2-2     HDP-2.2.4.2-2     upgrade-2.2
+   * </pre>
+   *
+   * Notice that it's possible for the {@code upgrade} table to include entries
+   * for a repo version which does not exist; {@code 2.2.4.2}. In these cases,
+   * this method will attempt a "best match".
+   *
+   * @param stack
+   *          Stack
+   * @param version
+   *          Stack version
    * @return The value of the upgrade_package column, or null if not found.
    */
 
@@ -612,6 +632,20 @@ public class UpgradeCatalog220 extends AbstractUpgradeCatalog {
     if (null != version && null != stack) {
       RepositoryVersionEntity repoVersion = repositoryVersionDAO.findByStackNameAndVersion(stack.getStackName(),
version);
 
+      // a null repoVersion means there's mismatch between the upgrade and repo_version table;
+      // use a best-guess approach based on the Stack
+      if( null == repoVersion ){
+        List<RepositoryVersionEntity> bestMatches = repositoryVersionDAO.findByStack(new
StackId(stack));
+        if (!bestMatches.isEmpty()) {
+          repoVersion = bestMatches.get(0);
+        }
+      }
+
+      // our efforts have failed; we have no idea what to use; return null as per the contract
of the method
+      if( null == repoVersion ) {
+        return null;
+      }
+
       Statement statement = null;
       ResultSet rs = null;
       try {


Mime
View raw message