CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter Upgrade changes with legacy zone support
DC-Zone mapping constraints should allow multiple hypervisors per zone. Such zones would just be ignored. Looking for only VMware clusters in the zone while associating a VMware DC with a zone. Fixed upgrade path for zones with 1 cluster from 1 DC/vCenter. Auto-associating in this case. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/43850575 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/43850575 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/43850575 Branch: refs/heads/vmware-datamodel Commit: 438505756d00258f211a1c3d986fe37d57290554 Parents: f78c2a3 Author: Sateesh Chodapuneedi <[email protected]> Authored: Thu May 9 23:13:28 2013 +0530 Committer: Sateesh Chodapuneedi <[email protected]> Committed: Sun May 19 08:52:03 2013 +0530 ---------------------------------------------------------------------- .../src/com/cloud/upgrade/dao/Upgrade410to420.java | 42 ++++++++++---- .../vmware/manager/VmwareManagerImpl.java | 32 +++--------- setup/db/db/schema-410to420.sql | 1 - 3 files changed, 37 insertions(+), 38 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/43850575/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 7baa1ab..352e54a 100644 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java @@ -269,11 +269,13 @@ public class Upgrade410to420 implements DbUpgrade { String dcOfCurrentCluster = null; String[] tokens; String url; - String user; - String password; + 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"); @@ -298,15 +300,16 @@ public class Upgrade410to420 implements DbUpgrade { 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; - 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; @@ -326,8 +329,21 @@ public class Upgrade410to420 implements DbUpgrade { if (legacyZone) { listOfLegacyZones.add(zoneId); } else { - user = clusterDetails.getString("username"); - password = clusterDetails.getString("password"); + 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(?, ?, ?, ?, ?, ?)"); @@ -354,7 +370,9 @@ public class Upgrade410to420 implements DbUpgrade { } updateLegacyZones(conn, listOfLegacyZones); } catch (SQLException e) { - throw new CloudRuntimeException("Unable to load legacy zones into cloud.legacy_zones table.", e); + String msg = "Unable to discover legacy zones." + e.getMessage(); + s_logger.error(msg); + throw new CloudRuntimeException(msg, e); } finally { try { if (rs != null) { http://git-wip-us.apache.org/repos/asf/cloudstack/blob/43850575/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 3e90312..21c6cda 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 @@ -910,35 +910,12 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw // Zone validation validateZone(zoneId, "add VMware datacenter to zone"); - // Check if the zone exists in the system - // If no, throw invalid param value exception - DataCenterVO zone = _dcDao.findById(zoneId); - if (zone == null) { - InvalidParameterValueException ex = new InvalidParameterValueException( - "Can't find zone by the id specified"); - ex.addProxyObject(zone, zoneId, "dcId"); - throw ex; - } - VmwareDatacenterZoneMapVO vmwareDcZoneMap = _vmwareDcZoneMapDao.findByZoneId(zoneId); // Check if zone is associated with VMware DC if (vmwareDcZoneMap != null) { throw new CloudRuntimeException("Zone " + zoneId + " is already associated with a VMware datacenter."); } - // Check if zone has resources? - For now look for clusters - // If yes, throw resource in use execption - List<ClusterVO> clusters = _clusterDao.listByZoneId(zoneId); - if (clusters != null) { - try { - if (clusters.size() > 0) { - throw new ResourceInUseException("Zone has one or more clusters." - + " Can't add VMware datacenter to zone which already has clusters."); - }}catch(Throwable t) { - s_logger.error(t); - } - } - // Validate url and get uri URI uri = getUri(url); @@ -1131,9 +1108,14 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw // Check if zone has resources? - For now look for clusters List<ClusterVO> clusters = _clusterDao.listByZoneId(zoneId); - if(clusters != null && clusters.size() != 0) { - throw new ResourceInUseException("Zone has one or more clusters." + if (clusters != null && clusters.size() > 0) { + // Look for VMware hypervisor. + for (ClusterVO cluster : clusters) { + if (cluster.getHypervisorType().equals(HypervisorType.VMware)) { + throw new ResourceInUseException("Zone has one or more clusters." + " Can't " + errStr + " which already has clusters."); + } + } } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/43850575/setup/db/db/schema-410to420.sql ---------------------------------------------------------------------- diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql index 12d50af..a401e75 100644 --- a/setup/db/db/schema-410to420.sql +++ b/setup/db/db/schema-410to420.sql @@ -1117,7 +1117,6 @@ CREATE VIEW `cloud`.`account_view` AS select account.id, account.uuid, - account.uuid, account.account_name, account.type, account.state,
