cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sate...@apache.org
Subject git commit: updated refs/heads/vmware-datamodel to 91e3825
Date Mon, 06 May 2013 10:32:11 GMT
Updated Branches:
  refs/heads/vmware-datamodel 776b043ea -> 91e382592


CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter
Upgrade changes with legacy zone support


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

Branch: refs/heads/vmware-datamodel
Commit: 91e382592dded50e8e371d4a6c7469bc81f49f6a
Parents: 776b043
Author: Sateesh Chodapuneedi <sateesh@apache.org>
Authored: Mon May 6 15:59:24 2013 +0530
Committer: Sateesh Chodapuneedi <sateesh@apache.org>
Committed: Mon May 6 15:59:24 2013 +0530

----------------------------------------------------------------------
 .../cloud/hypervisor/vmware/VmwareDatacenter.java  |    4 -
 .../hypervisor/vmware/VmwareDatacenterVO.java      |   12 -
 .../vmware/manager/VmwareManagerImpl.java          |    5 +-
 .../src/com/cloud/upgrade/dao/Upgrade410to420.java |  162 ++++++++++++++-
 4 files changed, 164 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/91e38259/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java
b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java
index 246b477..b978cd9 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java
@@ -3,14 +3,10 @@ package com.cloud.hypervisor.vmware;
 import org.apache.cloudstack.api.Identity;
 import org.apache.cloudstack.api.InternalIdentity;
 
-import com.vmware.vim25.ManagedObjectReference;
-
 public interface VmwareDatacenter extends Identity, InternalIdentity {
 
     String getVmwareDatacenterName();
 
-    ManagedObjectReference getVmwareDatacenterMor();
-
     String getGuid();
 
     String getVcenterHost();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/91e38259/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java
b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java
index aaeccc2..61a531a 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java
@@ -11,7 +11,6 @@ import javax.persistence.Table;
 
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.db.Encrypt;
-import com.vmware.vim25.ManagedObjectReference;
 
 /**
  * VmwareDatacenterVO contains information of Vmware Datacenter associated with a CloudStack
zone.
@@ -76,17 +75,6 @@ public class VmwareDatacenterVO implements VmwareDatacenter {
     }
 
     @Override
-    public ManagedObjectReference getVmwareDatacenterMor() {
-        String morString = guid.split("@")[0];
-        ManagedObjectReference mor = new ManagedObjectReference();
-
-        mor.setType(morString.split(":")[0]);
-        mor.setValue(morString.split(":")[1]);
-
-        return mor;
-    }
-
-    @Override
     public String getVcenterHost() {
         return vCenterHost;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/91e38259/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
index 3b94537..3e90312 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
@@ -985,8 +985,9 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager,
Vmw
 
             // Check if DC is already associated with another cloudstack deployment
             // Get custom field property cloud.zone over this DC
-            dcMor = dcMo.getMor();
-            guid = dcMor.getType() + ":" + dcMor.getValue() + "@" + vCenterHost;
+            // dcMor = dcMo.getMor();
+            // guid = dcMor.getType() + ":" + dcMor.getValue() + "@" + vCenterHost;
+            guid = vmwareDcName + "@" + vCenterHost;
 
             dcCustomFieldValue = dcMo.getCustomFieldValue(CustomFieldConstants.CLOUD_ZONE);
             if (dcCustomFieldValue == null) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/91e38259/server/src/com/cloud/upgrade/dao/Upgrade410to420.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/upgrade/dao/Upgrade410to420.java b/server/src/com/cloud/upgrade/dao/Upgrade410to420.java
index 05e2b49..c3e37de 100644
--- a/server/src/com/cloud/upgrade/dao/Upgrade410to420.java
+++ b/server/src/com/cloud/upgrade/dao/Upgrade410to420.java
@@ -17,6 +17,7 @@
 
 package com.cloud.upgrade.dao;
 
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.script.Script;
 import org.apache.log4j.Logger;
@@ -26,6 +27,8 @@ import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.UUID;
 
 public class Upgrade410to420 implements DbUpgrade {
@@ -59,6 +62,7 @@ public class Upgrade410to420 implements DbUpgrade {
 	@Override
 	public void performDataMigration(Connection conn) {
         upgradeVmwareLabels(conn);
+        persistLegacyZones(conn);
         createPlaceHolderNics(conn);
         updateRemoteAccessVpn(conn);
         updateSystemVmTemplates(conn);
@@ -235,7 +239,163 @@ 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;
+
+        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;
+                            if (count > 0) {
+                                dcOfPreviousCluster = dcOfCurrentCluster;
+                                clusterDetailsQuery = conn.prepareStatement("select value,username,password
from `cloud`.`cluster_details` where name='url' and cluster_id=?");
+                                clusterDetailsQuery.setLong(1, clusterId);
+                                clusterDetails = clusterDetailsQuery.executeQuery();
+                                url = clusterDetails.getString("value");
+                                tokens = url.split("/"); // url format - http://vcenter/dc/cluster
+                                vc = tokens[2];
+                                dcName = tokens[3];
+                                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 {
+                    user = clusterDetails.getString("username");
+                    password = clusterDetails.getString("password");
+                    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) {
+            throw new CloudRuntimeException("Unable to load legacy zones into cloud.legacy_zones
table.", 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