From f4e4be01ff1f7cd2d1aafb2bb3dc2b4cd94cec58 Mon Sep 17 00:00:00 2001 From: Prachi Damle Date: Fri, 13 Sep 2013 13:46:29 -0700 Subject: [PATCH] CLOUDSTACK-4668: Upgrade to 4.2 fails with NullPointerException when hypervisor_type is null for a cluster entry Changes: - Care for null value during comparing the hypervisor_type - Do not consider removed clusters - Method rename according to coding conventions --- .../schema/src/com/cloud/upgrade/dao/Upgrade410to420.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java index 3c753e90156..43f03c057f9 100755 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java @@ -83,7 +83,7 @@ public class Upgrade410to420 implements DbUpgrade { createPlaceHolderNics(conn); updateRemoteAccessVpn(conn); updateSystemVmTemplates(conn); - updateCluster_details(conn); + updateOverCommitRatioClusterDetails(conn); updatePrimaryStore(conn); addEgressFwRulesForSRXGuestNw(conn); upgradeEIPNetworkOfferings(conn); @@ -898,7 +898,7 @@ public class Upgrade410to420 implements DbUpgrade { } //update the cluster_details table with default overcommit ratios. - private void updateCluster_details(Connection conn) { + private void updateOverCommitRatioClusterDetails(Connection conn) { PreparedStatement pstmt = null; PreparedStatement pstmt1 = null; PreparedStatement pstmt2 =null; @@ -907,7 +907,7 @@ public class Upgrade410to420 implements DbUpgrade { ResultSet rscpu_global = null; ResultSet rsmem_global = null; try { - pstmt = conn.prepareStatement("select id, hypervisor_type from `cloud`.`cluster`"); + pstmt = conn.prepareStatement("select id, hypervisor_type from `cloud`.`cluster` WHERE removed IS NULL"); pstmt1=conn.prepareStatement("INSERT INTO `cloud`.`cluster_details` (cluster_id, name, value) VALUES(?, 'cpuOvercommitRatio', ?)"); pstmt2=conn.prepareStatement("INSERT INTO `cloud`.`cluster_details` (cluster_id, name, value) VALUES(?, 'memoryOvercommitRatio', ?)"); pstmt3=conn.prepareStatement("select value from `cloud`.`configuration` where name=?"); @@ -926,7 +926,7 @@ public class Upgrade410to420 implements DbUpgrade { while (rs1.next()) { long id = rs1.getLong(1); String hypervisor_type = rs1.getString(2); - if (hypervisor_type.equalsIgnoreCase(HypervisorType.VMware.toString())) { + if (HypervisorType.VMware.toString().equalsIgnoreCase(hypervisor_type)) { pstmt1.setLong(1,id); pstmt1.setString(2,global_cpu_overprovisioning_factor); pstmt1.execute();