cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sate...@apache.org
Subject [49/50] [abbrv] git commit: updated refs/heads/vmware-datamodel to f1a5d70
Date Thu, 23 May 2013 07:25:54 GMT
CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter

Upgrade handling.
Detect legacy zones during db upgrade and perform data migration.
If legacy zone is detected the table 'cloud'.'legacy_zones' is populated.
If an existing zone which has resources that belong to single VMware datacenter then such
zone would not be marked as legacy zone. Such zone would be automatically associated with
the specific Vmware datacenter of the clusters inside the zone.

Signed-off-by: Sateesh Chodapuneedi <sateesh@apache.org>


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

Branch: refs/heads/vmware-datamodel
Commit: d4d8380ab2179a6905bea59cd74f7fc259ba6b96
Parents: 3e3e164
Author: Sateesh Chodapuneedi <sateesh@apache.org>
Authored: Thu May 23 12:44:54 2013 +0530
Committer: Sateesh Chodapuneedi <sateesh@apache.org>
Committed: Thu May 23 12:53:22 2013 +0530

----------------------------------------------------------------------
 .../src/com/cloud/upgrade/dao/Upgrade410to420.java |  178 +++++++++++++++
 1 files changed, 178 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d4d8380a/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 c03d377..352e54a 100644
--- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
@@ -18,6 +18,7 @@
 package com.cloud.upgrade.dao;
 
 import com.cloud.deploy.DeploymentPlanner;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.script.Script;
 import org.apache.log4j.Logger;
@@ -28,6 +29,8 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Types;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.UUID;
 import com.cloud.network.vpc.NetworkACL;
 
@@ -62,6 +65,7 @@ public class Upgrade410to420 implements DbUpgrade {
 	@Override
 	public void performDataMigration(Connection conn) {
         upgradeVmwareLabels(conn);
+        persistLegacyZones(conn);
         createPlaceHolderNics(conn);
         updateRemoteAccessVpn(conn);
         updateSystemVmTemplates(conn);
@@ -245,6 +249,180 @@ public class Upgrade410to420 implements DbUpgrade {
         }
     }
 
+    private void persistLegacyZones(Connection conn) {
+        List<Long> listOfLegacyZones = new ArrayList<Long>();
+        PreparedStatement pstmt = null;
+        PreparedStatement clustersQuery = null;
+        PreparedStatement clusterDetailsQuery = null;
+        ResultSet rs = null;
+        ResultSet clusters = null;
+        ResultSet clusterDetails = null;
+        ResultSet dcInfo = null;
+        Long vmwareDcId = 1L;
+        Long zoneId;
+        Long clusterId;
+        String clusterHypervisorType;
+        boolean legacyZone;
+        boolean ignoreZone;
+        Long count;
+        String dcOfPreviousCluster = null;
+        String dcOfCurrentCluster = null;
+        String[] tokens;
+        String url;
+        String user = "";
+        String password = "";
+        String vc = "";
+        String dcName = "";
+        String guid;
+        String key;
+        String value;
+
+        try {
+            clustersQuery = conn.prepareStatement("select id, hypervisor_type from `cloud`.`cluster`
where removed is NULL");
+            pstmt = conn.prepareStatement("select id from `cloud`.`data_center` where removed
is NULL");
+            rs = pstmt.executeQuery();
+
+            while (rs.next()) {
+                zoneId = rs.getLong("id");
+                legacyZone = false;
+                ignoreZone = true;
+                count = 0L;
+                // 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();
+                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;
+                            clusterDetailsQuery = conn.prepareStatement("select value from
`cloud`.`cluster_details` where name='url' and cluster_id=?");
+                            clusterDetailsQuery.setLong(1, clusterId);
+                            clusterDetails = clusterDetailsQuery.executeQuery();
+                            clusterDetails.next();
+                            url = clusterDetails.getString("value");
+                            tokens = url.split("/"); // url format - http://vcenter/dc/cluster
+                            vc = tokens[2];
+                            dcName = tokens[3];
+                            if (count > 0) {
+                                dcOfPreviousCluster = dcOfCurrentCluster;
+                                dcOfCurrentCluster = dcName + "@" + vc;
+                                if (!dcOfPreviousCluster.equals(dcOfCurrentCluster)) {
+                                    legacyZone = true;
+                                    s_logger.debug("Marking the zone " + zoneId + " as legacy
zone.");
+                                }
+                            }
+                        } 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
+                    }
+                }
+                if (legacyZone) {
+                    listOfLegacyZones.add(zoneId);
+                } else {
+                    assert(clusterDetails != null) : "Couldn't retrieve details of cluster!";
+                    s_logger.debug("Discovered non-legacy zone " + zoneId + ". Processing
the zone to associate with VMware datacenter.");
+
+                    clusterDetailsQuery = conn.prepareStatement("select name, value from
`cloud`.`cluster_details` where cluster_id=?");
+                    clusterDetailsQuery.setLong(1, clusterId);
+                    clusterDetails = clusterDetailsQuery.executeQuery();
+                    while (clusterDetails.next()) {
+                        key = clusterDetails.getString(1);
+                        value = clusterDetails.getString(2);
+                        if (key.equalsIgnoreCase("username")) {
+                            user = value;
+                        } else if (key.equalsIgnoreCase("password")) {
+                            password = value;
+                        }
+                    }
+                    guid = dcName + "@" + vc;
+
+                    pstmt = conn.prepareStatement("INSERT INTO `cloud`.`vmware_data_center`
(uuid, name, guid, vcenter_host, username, password) values(?, ?, ?, ?, ?, ?)");
+                    pstmt.setString(1, UUID.randomUUID().toString());
+                    pstmt.setString(2, dcName);
+                    pstmt.setString(3, guid);
+                    pstmt.setString(4, vc);
+                    pstmt.setString(5, user);
+                    pstmt.setString(6, password);
+                    pstmt.executeUpdate();
+
+                    pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`vmware_data_center`
where guid=?");
+                    pstmt.setString(1, guid);
+                    dcInfo = pstmt.executeQuery();
+                    if(dcInfo.next()) {
+                        vmwareDcId = dcInfo.getLong("id");
+                    }
+
+                    pstmt = conn.prepareStatement("INSERT INTO `cloud`.`vmware_data_center_zone_map`
(zone_id, vmware_data_center_id) values(?, ?)");
+                    pstmt.setLong(1, zoneId);
+                    pstmt.setLong(2, vmwareDcId);
+                    pstmt.executeUpdate();
+                }
+            }
+            updateLegacyZones(conn, listOfLegacyZones);
+        } catch (SQLException e) {
+            String msg = "Unable to discover legacy zones." + e.getMessage();
+            s_logger.error(msg);
+            throw new CloudRuntimeException(msg, e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+                if (dcInfo != null) {
+                    dcInfo.close();
+                }
+                if (clusters != null) {
+                    clusters.close();
+                }
+                if (clusterDetails != null) {
+                    clusterDetails.close();
+                }
+                if (clustersQuery != null) {
+                    clustersQuery.close();
+                }
+                if (clusterDetailsQuery != null) {
+                    clusterDetailsQuery.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
+
+    private void updateLegacyZones(Connection conn, List<Long> zones) {
+        PreparedStatement legacyZonesQuery = null;
+        //Insert legacy zones into table for legacy zones.
+        try {
+            legacyZonesQuery = conn.prepareStatement("INSERT INTO `cloud`.`legacy_zones`
(zone_id) VALUES (?)");
+            for(Long zoneId : zones) {
+                legacyZonesQuery.setLong(1, zoneId);
+                legacyZonesQuery.executeUpdate();
+                s_logger.debug("Inserted zone " + zoneId + " into cloud.legacyzones table");
+            }
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable add zones to cloud.legacyzones table.",
e);
+        } finally {
+            try {
+                if (legacyZonesQuery != null) {
+                    legacyZonesQuery.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
+
     private void createPlaceHolderNics(Connection conn) {
         PreparedStatement pstmt = null;
         ResultSet rs = null;


Mime
View raw message