Repository: ambari
Updated Branches:
  refs/heads/branch-2.4 bace3bf89 -> d8c6e67a9


AMBARI-17188. Ambari upgrade from 2.2.2 to 2.4.0 fails if cluster name was 
changed. (Gaurav Nagar via dipayanb)


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

Branch: refs/heads/branch-2.4
Commit: d8c6e67a92bbcb3b535a8454a8b4c717f2c3347d
Parents: bace3bf
Author: Dipayan Bhowmick <[email protected]>
Authored: Tue Jun 14 15:54:12 2016 +0530
Committer: Dipayan Bhowmick <[email protected]>
Committed: Tue Jun 14 15:54:12 2016 +0530

----------------------------------------------------------------------
 .../server/upgrade/UpgradeCatalog240.java       | 25 ++++++++++++++------
 1 file changed, 18 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d8c6e67a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
index 7451bbe..bdcb8bf 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
@@ -2388,13 +2388,14 @@ public class UpgradeCatalog240 extends 
AbstractUpgradeCatalog {
           CLUSTER_TABLE);
 
         resultSet = statement.executeQuery(selectSQL);
-        while (null != resultSet && resultSet.next()) {
+
+        //Getting 1st cluster and updating view instance table with cluster_id
+        if (null != resultSet && resultSet.next()) {
           final Long clusterId = resultSet.getLong("cluster_id");
-          final String clusterName = resultSet.getString("cluster_name");
 
           String updateSQL = String.format(
-            "UPDATE %s SET %s = %d WHERE cluster_handle = '%s'",
-            VIEWINSTANCE_TABLE, cluster_handle_dummy, clusterId, clusterName);
+            "UPDATE %s SET %s = %d WHERE cluster_handle IS NOT NULL",
+            VIEWINSTANCE_TABLE, cluster_handle_dummy, clusterId);
 
           dbAccessor.executeQuery(updateSQL);
         }
@@ -2428,10 +2429,20 @@ public class UpgradeCatalog240 extends 
AbstractUpgradeCatalog {
         RemoteAmbariClusterEntity clusterEntity = new 
RemoteAmbariClusterEntity();
         clusterEntity.setName(instance.getName() + "-cluster");
         Map<String, String> propertyMap = instance.getPropertyMap();
-        clusterEntity.setUrl(propertyMap.get("ambari.server.url"));
-        clusterEntity.setUsername(propertyMap.get("ambari.server.username"));
+
+        String url = propertyMap.get("ambari.server.url");
+        String password = propertyMap.get("ambari.server.password");
+        String username = propertyMap.get("ambari.server.username");
+
+        if (StringUtils.isEmpty(url) || StringUtils.isEmpty(username) || 
StringUtils.isEmpty(password)) {
+          LOG.info("One of url, username, password is empty. Skipping upgrade 
for View Instance {}.", instance.getName());
+          continue;
+        }
+
+        clusterEntity.setUrl(url);
+        clusterEntity.setUsername(username);
         try {
-          clusterEntity.setPassword(new 
DefaultMasker().unmask(propertyMap.get("ambari.server.password")));
+          clusterEntity.setPassword(new DefaultMasker().unmask(password));
         } catch (MaskException e) {
           // ignore
         }

Reply via email to