Repository: ambari Updated Branches: refs/heads/trunk 48205daaa -> f65fb23b6
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/f65fb23b Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/f65fb23b Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/f65fb23b Branch: refs/heads/trunk Commit: f65fb23b69e8670017a6635c8a54f98cc587f169 Parents: 48205da 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:55 2016 +0530 ---------------------------------------------------------------------- .../server/upgrade/UpgradeCatalog240.java | 25 ++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/f65fb23b/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 5016325..794ad83 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 @@ -2395,13 +2395,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); } @@ -2435,10 +2436,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 }
