Skip to content

Commit db38412

Browse files
committed
Merge branch '4.9'
2 parents d3e4551 + b7f1ba9 commit db38412

1 file changed

Lines changed: 42 additions & 41 deletions

File tree

engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -706,11 +706,11 @@ private void persistLegacyZones(Connection conn) {
706706
String vc = "";
707707
String dcName = "";
708708

709-
try(PreparedStatement pstmt = conn.prepareStatement("select id from `cloud`.`data_center` where removed is NULL");) {
709+
try (PreparedStatement pstmt = conn.prepareStatement("select id from `cloud`.`data_center` where removed is NULL");) {
710710
try (ResultSet rs = pstmt.executeQuery();) {
711711
while (rs.next()) {
712712
zoneId = rs.getLong("id");
713-
try(PreparedStatement clustersQuery = conn.prepareStatement("select id, hypervisor_type from `cloud`.`cluster` where removed is NULL AND data_center_id=?");) {
713+
try (PreparedStatement clustersQuery = conn.prepareStatement("select id, hypervisor_type from `cloud`.`cluster` where removed is NULL AND data_center_id=?");) {
714714
clustersQuery.setLong(1, zoneId);
715715
legacyZone = false;
716716
ignoreZone = true;
@@ -719,53 +719,54 @@ private void persistLegacyZones(Connection conn) {
719719
// Legacy zone term is meant only for VMware
720720
// Legacy zone is a zone with atleast 2 clusters & with multiple DCs or VCs
721721
clusters = clustersQuery.executeQuery();
722-
}catch (SQLException e) {
723-
throw new CloudRuntimeException("persistLegacyZones:Exception:"+e.getMessage(), e);
724-
}
725-
if (!clusters.next()) {
726-
continue; // Ignore the zone without any clusters
727-
} else {
728-
dcOfPreviousCluster = null;
729-
dcOfCurrentCluster = null;
730-
do {
731-
clusterHypervisorType = clusters.getString("hypervisor_type");
732-
clusterId = clusters.getLong("id");
733-
if (clusterHypervisorType.equalsIgnoreCase("VMware")) {
734-
ignoreZone = false;
735-
try (PreparedStatement clusterDetailsQuery = conn.prepareStatement("select value from `cloud`.`cluster_details` where name='url' and cluster_id=?");) {
736-
clusterDetailsQuery.setLong(1, clusterId);
737-
try (ResultSet clusterDetails = clusterDetailsQuery.executeQuery();) {
738-
clusterDetails.next();
739-
url = clusterDetails.getString("value");
740-
tokens = url.split("/"); // url format - http://vcenter/dc/cluster
741-
vc = tokens[2];
742-
dcName = tokens[3];
743-
dcOfPreviousCluster = dcOfCurrentCluster;
744-
dcOfCurrentCluster = dcName + "@" + vc;
745-
if (!dcList.contains(dcOfCurrentCluster)) {
746-
dcList.add(dcOfCurrentCluster);
747-
}
748-
if (count > 0) {
749-
if (!dcOfPreviousCluster.equalsIgnoreCase(dcOfCurrentCluster)) {
750-
legacyZone = true;
751-
s_logger.debug("Marking the zone " + zoneId + " as legacy zone.");
722+
if (!clusters.next()) {
723+
continue; // Ignore the zone without any clusters
724+
} else {
725+
dcOfPreviousCluster = null;
726+
dcOfCurrentCluster = null;
727+
do {
728+
clusterHypervisorType = clusters.getString("hypervisor_type");
729+
clusterId = clusters.getLong("id");
730+
if (clusterHypervisorType.equalsIgnoreCase("VMware")) {
731+
ignoreZone = false;
732+
try (PreparedStatement clusterDetailsQuery = conn
733+
.prepareStatement("select value from `cloud`.`cluster_details` where name='url' and cluster_id=?");) {
734+
clusterDetailsQuery.setLong(1, clusterId);
735+
try (ResultSet clusterDetails = clusterDetailsQuery.executeQuery();) {
736+
clusterDetails.next();
737+
url = clusterDetails.getString("value");
738+
tokens = url.split("/"); // url format - http://vcenter/dc/cluster
739+
vc = tokens[2];
740+
dcName = tokens[3];
741+
dcOfPreviousCluster = dcOfCurrentCluster;
742+
dcOfCurrentCluster = dcName + "@" + vc;
743+
if (!dcList.contains(dcOfCurrentCluster)) {
744+
dcList.add(dcOfCurrentCluster);
745+
}
746+
if (count > 0) {
747+
if (!dcOfPreviousCluster.equalsIgnoreCase(dcOfCurrentCluster)) {
748+
legacyZone = true;
749+
s_logger.debug("Marking the zone " + zoneId + " as legacy zone.");
750+
}
752751
}
752+
} catch (SQLException e) {
753+
throw new CloudRuntimeException("Unable add zones to cloud.legacyzones table.", e);
753754
}
754755
} catch (SQLException e) {
755756
throw new CloudRuntimeException("Unable add zones to cloud.legacyzones table.", e);
756757
}
757-
} catch (SQLException e) {
758-
throw new CloudRuntimeException("Unable add zones to cloud.legacyzones table.", e);
758+
} else {
759+
s_logger.debug("Ignoring zone " + zoneId + " with hypervisor type " + clusterHypervisorType);
760+
break;
759761
}
760-
} else {
761-
s_logger.debug("Ignoring zone " + zoneId + " with hypervisor type " + clusterHypervisorType);
762-
break;
762+
count++;
763+
} while (clusters.next());
764+
if (ignoreZone) {
765+
continue; // Ignore the zone with hypervisors other than VMware
763766
}
764-
count++;
765-
} while (clusters.next());
766-
if (ignoreZone) {
767-
continue; // Ignore the zone with hypervisors other than VMware
768767
}
768+
} catch (SQLException e) {
769+
throw new CloudRuntimeException("persistLegacyZones:Exception:" + e.getMessage(), e);
769770
}
770771
if (legacyZone) {
771772
listOfLegacyZones.add(zoneId);

0 commit comments

Comments
 (0)