cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [03/13] git commit: updated refs/heads/4.9-systemdubuntupkging to 917e288
Date Wed, 24 Aug 2016 06:57:27 GMT
CLOUDSTACK-9459: the try's catch block was shortening the preparedstatement life
resulting in bad resultset when used outside of try catch.


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

Branch: refs/heads/4.9-systemdubuntupkging
Commit: a2fcc65d9050b9cd6915e36e5274379aa3298957
Parents: 227ff38
Author: Abhinandan Prateek <abhinandan.prateek@shapeblue.com>
Authored: Tue Aug 16 14:04:43 2016 +0530
Committer: Abhinandan Prateek <abhinandan.prateek@shapeblue.com>
Committed: Tue Aug 16 14:19:07 2016 +0530

----------------------------------------------------------------------
 .../com/cloud/upgrade/dao/Upgrade410to420.java  | 83 ++++++++++----------
 1 file changed, 42 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a2fcc65d/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
index 7d67d2e..6e88110 100644
--- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
@@ -706,11 +706,11 @@ public class Upgrade410to420 implements DbUpgrade {
         String vc = "";
         String dcName = "";
 
-        try(PreparedStatement pstmt = conn.prepareStatement("select id from `cloud`.`data_center`
where removed is NULL");) {
+        try (PreparedStatement pstmt = conn.prepareStatement("select id from `cloud`.`data_center`
where removed is NULL");) {
             try (ResultSet rs = pstmt.executeQuery();) {
                 while (rs.next()) {
                     zoneId = rs.getLong("id");
-                    try(PreparedStatement clustersQuery = conn.prepareStatement("select id,
hypervisor_type from `cloud`.`cluster` where removed is NULL AND data_center_id=?");) {
+                    try (PreparedStatement clustersQuery = conn.prepareStatement("select
id, hypervisor_type from `cloud`.`cluster` where removed is NULL AND data_center_id=?");)
{
                         clustersQuery.setLong(1, zoneId);
                         legacyZone = false;
                         ignoreZone = true;
@@ -719,53 +719,54 @@ public class Upgrade410to420 implements DbUpgrade {
                         // Legacy zone term is meant only for VMware
                         // Legacy zone is a zone with atleast 2 clusters & with multiple
DCs or VCs
                         clusters = clustersQuery.executeQuery();
-                    }catch (SQLException e) {
-                        throw new CloudRuntimeException("persistLegacyZones:Exception:"+e.getMessage(),
e);
-                    }
-                    if (!clusters.next()) {
-                        continue; // Ignore the zone without any clusters
-                    } else {
-                        dcOfPreviousCluster = null;
-                        dcOfCurrentCluster = null;
-                        do {
-                            clusterHypervisorType = clusters.getString("hypervisor_type");
-                            clusterId = clusters.getLong("id");
-                            if (clusterHypervisorType.equalsIgnoreCase("VMware")) {
-                                ignoreZone = false;
-                                try (PreparedStatement clusterDetailsQuery = conn.prepareStatement("select
value from `cloud`.`cluster_details` where name='url' and cluster_id=?");) {
-                                    clusterDetailsQuery.setLong(1, clusterId);
-                                    try (ResultSet clusterDetails = clusterDetailsQuery.executeQuery();)
{
-                                        clusterDetails.next();
-                                        url = clusterDetails.getString("value");
-                                        tokens = url.split("/"); // url format - http://vcenter/dc/cluster
-                                        vc = tokens[2];
-                                        dcName = tokens[3];
-                                        dcOfPreviousCluster = dcOfCurrentCluster;
-                                        dcOfCurrentCluster = dcName + "@" + vc;
-                                        if (!dcList.contains(dcOfCurrentCluster)) {
-                                            dcList.add(dcOfCurrentCluster);
-                                        }
-                                        if (count > 0) {
-                                            if (!dcOfPreviousCluster.equalsIgnoreCase(dcOfCurrentCluster))
{
-                                                legacyZone = true;
-                                                s_logger.debug("Marking the zone " + zoneId
+ " as legacy zone.");
+                        if (!clusters.next()) {
+                            continue; // Ignore the zone without any clusters
+                        } else {
+                            dcOfPreviousCluster = null;
+                            dcOfCurrentCluster = null;
+                            do {
+                                clusterHypervisorType = clusters.getString("hypervisor_type");
+                                clusterId = clusters.getLong("id");
+                                if (clusterHypervisorType.equalsIgnoreCase("VMware")) {
+                                    ignoreZone = false;
+                                    try (PreparedStatement clusterDetailsQuery = conn
+                                            .prepareStatement("select value from `cloud`.`cluster_details`
where name='url' and cluster_id=?");) {
+                                        clusterDetailsQuery.setLong(1, clusterId);
+                                        try (ResultSet clusterDetails = clusterDetailsQuery.executeQuery();)
{
+                                            clusterDetails.next();
+                                            url = clusterDetails.getString("value");
+                                            tokens = url.split("/"); // url format - http://vcenter/dc/cluster
+                                            vc = tokens[2];
+                                            dcName = tokens[3];
+                                            dcOfPreviousCluster = dcOfCurrentCluster;
+                                            dcOfCurrentCluster = dcName + "@" + vc;
+                                            if (!dcList.contains(dcOfCurrentCluster)) {
+                                                dcList.add(dcOfCurrentCluster);
+                                            }
+                                            if (count > 0) {
+                                                if (!dcOfPreviousCluster.equalsIgnoreCase(dcOfCurrentCluster))
{
+                                                    legacyZone = true;
+                                                    s_logger.debug("Marking the zone " +
zoneId + " as legacy zone.");
+                                                }
                                             }
+                                        } catch (SQLException e) {
+                                            throw new CloudRuntimeException("Unable add zones
to cloud.legacyzones table.", e);
                                         }
                                     } catch (SQLException e) {
                                         throw new CloudRuntimeException("Unable add zones
to cloud.legacyzones table.", e);
                                     }
-                                } catch (SQLException e) {
-                                    throw new CloudRuntimeException("Unable add zones to
cloud.legacyzones table.", e);
+                                } else {
+                                    s_logger.debug("Ignoring zone " + zoneId + " with hypervisor
type " + clusterHypervisorType);
+                                    break;
                                 }
-                            } else {
-                                s_logger.debug("Ignoring zone " + zoneId + " with hypervisor
type " + clusterHypervisorType);
-                                break;
+                                count++;
+                            } while (clusters.next());
+                            if (ignoreZone) {
+                                continue; // Ignore the zone with hypervisors other than
VMware
                             }
-                            count++;
-                        } while (clusters.next());
-                        if (ignoreZone) {
-                            continue; // Ignore the zone with hypervisors other than VMware
                         }
+                    } catch (SQLException e) {
+                        throw new CloudRuntimeException("persistLegacyZones:Exception:" +
e.getMessage(), e);
                     }
                     if (legacyZone) {
                         listOfLegacyZones.add(zoneId);


Mime
View raw message