You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by sa...@apache.org on 2013/05/23 03:50:44 UTC
[03/10] git commit: updated refs/heads/vmware-datamodel to 599b826
CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter
Upgrade changes with legacy zone support
CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter
Plugin, API & DB changes
CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter
Upgrade changes with legacy zone support
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.
CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter
Plugin, API & DB changes
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/579a8121
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/579a8121
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/579a8121
Branch: refs/heads/vmware-datamodel
Commit: 579a8121128ad6eab784d7faf680c17fbf0fc792
Parents: 3db1cdf
Author: Sateesh Chodapuneedi <sa...@apache.org>
Authored: Mon May 6 15:59:24 2013 +0530
Committer: Sateesh Chodapuneedi <sa...@apache.org>
Committed: Thu May 23 06:36:29 2013 +0530
----------------------------------------------------------------------
.../src/com/cloud/upgrade/dao/Upgrade410to420.java | 179 +++++
.../cloud/hypervisor/vmware/VmwareDatacenter.java | 2 -
.../hypervisor/vmware/VmwareDatacenterVO.java | 18 +-
.../vmware/manager/VmwareManagerImpl.java | 35 +-
.../src/com/cloud/upgrade/dao/Upgrade410to420.java | 562 +++++++++++++++
setup/db/db/schema-410to420.sql | 1 -
6 files changed, 754 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/579a8121/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..0d630a0 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,181 @@ 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) {
+ }
+ }
+ }
+
+>>>>>>> CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter
private void createPlaceHolderNics(Connection conn) {
PreparedStatement pstmt = null;
ResultSet rs = null;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/579a8121/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..c5d35b1 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java
@@ -9,8 +9,6 @@ public interface VmwareDatacenter extends Identity, InternalIdentity {
String getVmwareDatacenterName();
- ManagedObjectReference getVmwareDatacenterMor();
-
String getGuid();
String getVcenterHost();
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/579a8121/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..4b08d9e 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;
}
@@ -152,4 +140,8 @@ public class VmwareDatacenterVO implements VmwareDatacenter {
this.uuid = UUID.randomUUID().toString();
}
-}
\ No newline at end of file
+<<<<<<< HEAD
+}
+=======
+}
+>>>>>>> CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/579a8121/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..c90a8ff 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);
@@ -985,8 +962,7 @@ 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;
+ guid = vmwareDcName + "@" + vCenterHost;
dcCustomFieldValue = dcMo.getCustomFieldValue(CustomFieldConstants.CLOUD_ZONE);
if (dcCustomFieldValue == null) {
@@ -1130,9 +1106,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/579a8121/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
new file mode 100644
index 0000000..c3e37de
--- /dev/null
+++ b/server/src/com/cloud/upgrade/dao/Upgrade410to420.java
@@ -0,0 +1,562 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+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;
+
+import java.io.File;
+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 {
+ final static Logger s_logger = Logger.getLogger(Upgrade410to420.class);
+
+ @Override
+ public String[] getUpgradableVersionRange() {
+ return new String[] { "4.1.0", "4.2.0" };
+ }
+
+ @Override
+ public String getUpgradedVersion() {
+ return "4.2.0";
+ }
+
+ @Override
+ public boolean supportsRollingUpgrade() {
+ return false;
+ }
+
+ @Override
+ public File[] getPrepareScripts() {
+ String script = Script.findScript("", "db/schema-410to420.sql");
+ if (script == null) {
+ throw new CloudRuntimeException("Unable to find db/schema-410to420.sql");
+ }
+
+ return new File[] { new File(script) };
+ }
+
+ @Override
+ public void performDataMigration(Connection conn) {
+ upgradeVmwareLabels(conn);
+ persistLegacyZones(conn);
+ createPlaceHolderNics(conn);
+ updateRemoteAccessVpn(conn);
+ updateSystemVmTemplates(conn);
+ updateCluster_details(conn);
+ updatePrimaryStore(conn);
+ addEgressFwRulesForSRXGuestNw(conn);
+ upgradeEIPNetworkOfferings(conn);
+ }
+
+ private void updateSystemVmTemplates(Connection conn) {
+ PreparedStatement sql = null;
+ try {
+ sql = conn.prepareStatement("update vm_template set image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
+ sql.executeUpdate();
+ } catch (SQLException e) {
+ throw new CloudRuntimeException("Failed to upgrade vm template data store uuid: " + e.toString());
+ } finally {
+ if (sql != null) {
+ try {
+ sql.close();
+ } catch (SQLException e) {
+ }
+ }
+ }
+ }
+
+ private void updatePrimaryStore(Connection conn) {
+ PreparedStatement sql = null;
+ PreparedStatement sql2 = null;
+ try {
+ sql = conn.prepareStatement("update storage_pool set storage_provider_name = ? , scope = ? where pool_type = 'Filesystem' or pool_type = 'LVM'");
+ sql.setString(1, "ancient primary data store provider");
+ sql.setString(2, "HOST");
+ sql.executeUpdate();
+
+ sql2 = conn.prepareStatement("update storage_pool set storage_provider_name = ? , scope = ? where pool_type != 'Filesystem' and pool_type != 'LVM'");
+ sql2.setString(1, "ancient primary data store provider");
+ sql2.setString(2, "CLUSTER");
+ sql2.executeUpdate();
+ } catch (SQLException e) {
+ throw new CloudRuntimeException("Failed to upgrade vm template data store uuid: " + e.toString());
+ } finally {
+ if (sql != null) {
+ try {
+ sql.close();
+ } catch (SQLException e) {
+ }
+ }
+
+ if (sql2 != null) {
+ try {
+ sql2.close();
+ } catch (SQLException e) {
+ }
+ }
+ }
+ }
+
+ //update the cluster_details table with default overcommit ratios.
+ private void updateCluster_details(Connection conn) {
+ PreparedStatement pstmt = null;
+ PreparedStatement pstmt1 = null;
+ PreparedStatement pstmt2 =null;
+ ResultSet rs = null;
+
+ try {
+ pstmt = conn.prepareStatement("select id from `cloud`.`cluster`");
+ pstmt1=conn.prepareStatement("INSERT INTO `cloud`.`cluster_details` (cluster_id, name, value) VALUES(?, 'cpuOvercommitRatio', '1')");
+ pstmt2=conn.prepareStatement("INSERT INTO `cloud`.`cluster_details` (cluster_id, name, value) VALUES(?, 'memoryOvercommitRatio', '1')");
+ rs = pstmt.executeQuery();
+ while (rs.next()) {
+ long id = rs.getLong(1);
+ //update cluster_details table with the default overcommit ratios.
+ pstmt1.setLong(1,id);
+ pstmt1.execute();
+ pstmt2.setLong(1,id);
+ pstmt2.execute();
+ }
+ } catch (SQLException e) {
+ throw new CloudRuntimeException("Unable to update cluster_details with default overcommit ratios.", e);
+ } finally {
+ try {
+ if (rs != null) {
+ rs.close();
+ }
+ if (pstmt != null) {
+ pstmt.close();
+ }
+ } catch (SQLException e) {
+ }
+ }
+ }
+
+
+ @Override
+ public File[] getCleanupScripts() {
+ String script = Script.findScript("", "db/schema-410to420-cleanup.sql");
+ if (script == null) {
+ throw new CloudRuntimeException("Unable to find db/schema-410to420-cleanup.sql");
+ }
+
+ return new File[] { new File(script) };
+ }
+
+ private String getNewLabel(ResultSet rs, String oldParamValue) {
+ int separatorIndex;
+ String oldGuestLabel;
+ String newGuestLabel = oldParamValue;
+ try {
+ // No need to iterate because the global param setting applies to all physical networks irrespective of traffic type
+ if (rs.next()) {
+ oldGuestLabel = rs.getString("vmware_network_label");
+ // guestLabel is in format [[<VSWITCHNAME>],VLANID]
+ separatorIndex = oldGuestLabel.indexOf(",");
+ if(separatorIndex > -1) {
+ newGuestLabel += oldGuestLabel.substring(separatorIndex);
+ }
+ }
+ } catch (SQLException e) {
+ s_logger.error(new CloudRuntimeException("Failed to read vmware_network_label : " + e));
+ } finally {
+ try {
+ if (rs != null) {
+ rs.close();
+ }
+ } catch (SQLException e) {
+ }
+ }
+ return newGuestLabel;
+ }
+
+ private void upgradeVmwareLabels(Connection conn) {
+ PreparedStatement pstmt = null;
+ ResultSet rsParams = null;
+ ResultSet rsLabel = null;
+ String newLabel;
+ String trafficType = null;
+ String trafficTypeVswitchParam;
+ String trafficTypeVswitchParamValue;
+
+ try {
+ // update the existing vmware traffic labels
+ pstmt = conn.prepareStatement("select name,value from `cloud`.`configuration` where category='Hidden' and value is not NULL and name REGEXP 'vmware\\.*\\.vswitch';");
+ rsParams = pstmt.executeQuery();
+ while (rsParams.next()) {
+ trafficTypeVswitchParam = rsParams.getString("name");
+ trafficTypeVswitchParamValue = rsParams.getString("value");
+ // When upgraded from 4.0 to 4.1 update physical network traffic label with trafficTypeVswitchParam
+ if (trafficTypeVswitchParam.equals("vmware.private.vswitch")) {
+ trafficType = "Management"; //TODO(sateesh): Ignore storage traffic, as required physical network already implemented, anything else tobe done?
+ } else if (trafficTypeVswitchParam.equals("vmware.public.vswitch")) {
+ trafficType = "Public";
+ } else if (trafficTypeVswitchParam.equals("vmware.guest.vswitch")) {
+ trafficType = "Guest";
+ }
+ s_logger.debug("Updating vmware label for " + trafficType + " traffic. Update SQL statement is " + pstmt);
+ pstmt = conn.prepareStatement("select physical_network_id, traffic_type, vmware_network_label from physical_network_traffic_types where vmware_network_label is not NULL and traffic_type='" + trafficType + "';");
+ rsLabel = pstmt.executeQuery();
+ newLabel = getNewLabel(rsLabel, trafficTypeVswitchParamValue);
+ pstmt = conn.prepareStatement("update physical_network_traffic_types set vmware_network_label = " + newLabel + " where traffic_type = '" + trafficType + "' and vmware_network_label is not NULL;");
+ pstmt.executeUpdate();
+ }
+ } catch (SQLException e) {
+ throw new CloudRuntimeException("Unable to set vmware traffic labels ", e);
+ } finally {
+ try {
+ if (rsParams != null) {
+ rsParams.close();
+ }
+ if (pstmt != null) {
+ pstmt.close();
+ }
+ } catch (SQLException e) {
+ }
+ }
+ }
+
+ 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;
+
+ try {
+ pstmt = conn.prepareStatement("SELECT network_id, gateway, ip4_address FROM `cloud`.`nics` WHERE reserver_name IN ('DirectNetworkGuru','DirectPodBasedNetworkGuru') and vm_type='DomainRouter' AND removed IS null");
+ rs = pstmt.executeQuery();
+ while (rs.next()) {
+ Long networkId = rs.getLong(1);
+ String gateway = rs.getString(2);
+ String ip = rs.getString(3);
+ String uuid = UUID.randomUUID().toString();
+ //Insert placeholder nic for each Domain router nic in Shared network
+ pstmt = conn.prepareStatement("INSERT INTO `cloud`.`nics` (uuid, ip4_address, gateway, network_id, state, strategy, vm_type) VALUES (?, ?, ?, ?, 'Reserved', 'PlaceHolder', 'DomainRouter')");
+ pstmt.setString(1, uuid);
+ pstmt.setString(2, ip);
+ pstmt.setString(3, gateway);
+ pstmt.setLong(4, networkId);
+ pstmt.executeUpdate();
+ s_logger.debug("Created placeholder nic for the ipAddress " + ip);
+
+ }
+ } catch (SQLException e) {
+ throw new CloudRuntimeException("Unable to create placeholder nics", e);
+ } finally {
+ try {
+ if (rs != null) {
+ rs.close();
+ }
+ if (pstmt != null) {
+ pstmt.close();
+ }
+ } catch (SQLException e) {
+ }
+ }
+ }
+
+
+ private void updateRemoteAccessVpn(Connection conn) {
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
+
+ try {
+ pstmt = conn.prepareStatement("SELECT vpn_server_addr_id FROM `cloud`.`remote_access_vpn`");
+ rs = pstmt.executeQuery();
+ long id=1;
+ while (rs.next()) {
+ String uuid = UUID.randomUUID().toString();
+ Long ipId = rs.getLong(1);
+ pstmt = conn.prepareStatement("UPDATE `cloud`.`remote_access_vpn` set uuid=?, id=? where vpn_server_addr_id=?");
+ pstmt.setString(1, uuid);
+ pstmt.setLong(2, id);
+ pstmt.setLong(3, ipId);
+ pstmt.executeUpdate();
+ id++;
+ }
+ } catch (SQLException e) {
+ throw new CloudRuntimeException("Unable to update id/uuid of remote_access_vpn table", e);
+ } finally {
+ try {
+ if (rs != null) {
+ rs.close();
+ }
+ if (pstmt != null) {
+ pstmt.close();
+ }
+ } catch (SQLException e) {
+ }
+ }
+ }
+ private void addEgressFwRulesForSRXGuestNw(Connection conn) {
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
+ ResultSet rsId = null;
+ ResultSet rsNw = null;
+ try {
+ pstmt = conn.prepareStatement("select network_id FROM `cloud`.`ntwk_service_map` where service='Firewall' and provider='JuniperSRX' ");
+ rs = pstmt.executeQuery();
+ while (rs.next()) {
+ long netId = rs.getLong(1);
+ //checking for Isolated OR Virtual
+ pstmt = conn.prepareStatement("select account_id, domain_id FROM `cloud`.`networks` where (guest_type='Isolated' OR guest_type='Virtual') and traffic_type='Guest' and vpc_id is NULL and (state='implemented' OR state='Shutdown') and id=? ");
+ pstmt.setLong(1, netId);
+ s_logger.debug("Getting account_id, domain_id from networks table: " + pstmt);
+ rsNw = pstmt.executeQuery();
+
+ if(rsNw.next()) {
+ long accountId = rsNw.getLong(1);
+ long domainId = rsNw.getLong(2);
+
+ //Add new rule for the existing networks
+ s_logger.debug("Adding default egress firewall rule for network " + netId);
+ pstmt = conn.prepareStatement("INSERT INTO firewall_rules (uuid, state, protocol, purpose, account_id, domain_id, network_id, xid, created, traffic_type) VALUES (?, 'Active', 'all', 'Firewall', ?, ?, ?, ?, now(), 'Egress')");
+ pstmt.setString(1, UUID.randomUUID().toString());
+ pstmt.setLong(2, accountId);
+ pstmt.setLong(3, domainId);
+ pstmt.setLong(4, netId);
+ pstmt.setString(5, UUID.randomUUID().toString());
+ s_logger.debug("Inserting default egress firewall rule " + pstmt);
+ pstmt.executeUpdate();
+
+ pstmt = conn.prepareStatement("select id from firewall_rules where protocol='all' and network_id=?");
+ pstmt.setLong(1, netId);
+ rsId = pstmt.executeQuery();
+
+ long firewallRuleId;
+ if(rsId.next()) {
+ firewallRuleId = rsId.getLong(1);
+ pstmt = conn.prepareStatement("insert into firewall_rules_cidrs (firewall_rule_id,source_cidr) values (?, '0.0.0.0/0')");
+ pstmt.setLong(1, firewallRuleId);
+ s_logger.debug("Inserting rule for cidr 0.0.0.0/0 for the new Firewall rule id=" + firewallRuleId + " with statement " + pstmt);
+ pstmt.executeUpdate();
+ }
+ }
+ }
+ } catch (SQLException e) {
+ throw new CloudRuntimeException("Unable to set egress firewall rules ", e);
+ } finally {
+ try {
+ if (rs != null) {
+ rs.close();
+ }
+ if (pstmt != null) {
+ pstmt.close();
+ }
+ } catch (SQLException e) {
+ }
+ }
+ }
+
+ private void upgradeEIPNetworkOfferings(Connection conn) {
+
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
+
+ try {
+ pstmt = conn.prepareStatement("select id, elastic_ip_service from `cloud`.`network_offerings` where traffic_type='Guest'");
+ rs = pstmt.executeQuery();
+ while (rs.next()) {
+ long id = rs.getLong(1);
+ // check if elastic IP service is enabled for network offering
+ if (rs.getLong(2) != 0) {
+ //update network offering with eip_associate_public_ip set to true
+ pstmt = conn.prepareStatement("UPDATE `cloud`.`network_offerings` set eip_associate_public_ip=? where id=?");
+ pstmt.setBoolean(1, true);
+ pstmt.setLong(2, id);
+ pstmt.executeUpdate();
+ }
+ }
+ } catch (SQLException e) {
+ throw new CloudRuntimeException("Unable to set elastic_ip_service for network offerings with EIP service enabled.", e);
+ } finally {
+ try {
+ if (rs != null) {
+ rs.close();
+ }
+ if (pstmt != null) {
+ pstmt.close();
+ }
+ } catch (SQLException e) {
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/579a8121/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql
index 7199fd3..e4baacd 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,