cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anim...@apache.org
Subject [10/50] git commit: updated refs/heads/4.2 to 86c9363
Date Thu, 03 Oct 2013 06:06:08 GMT
CLOUDSTACK-4704: 41-42 db upgrade - populate vpc_service_map table with the services/providers
supported by VPC


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

Branch: refs/heads/4.2
Commit: 798f34a49cbfbb3a475f3dadf62d1ac1b8dfa510
Parents: cea14ce
Author: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Authored: Thu Sep 19 13:08:38 2013 -0700
Committer: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Committed: Thu Sep 19 13:15:05 2013 -0700

----------------------------------------------------------------------
 .../src/com/cloud/network/vpc/dao/VpcDao.java   |  4 +-
 .../com/cloud/network/vpc/dao/VpcDaoImpl.java   | 10 ++--
 .../com/cloud/upgrade/dao/Upgrade410to420.java  | 56 ++++++++++++++++++++
 .../com/cloud/network/vpc/VpcManagerImpl.java   | 25 ++++-----
 .../test/com/cloud/vpc/dao/MockVpcDaoImpl.java  |  4 +-
 setup/db/db/schema-410to420.sql                 |  2 +-
 6 files changed, 77 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/798f34a4/engine/schema/src/com/cloud/network/vpc/dao/VpcDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/dao/VpcDao.java b/engine/schema/src/com/cloud/network/vpc/dao/VpcDao.java
index 5a33217..57a2621 100644
--- a/engine/schema/src/com/cloud/network/vpc/dao/VpcDao.java
+++ b/engine/schema/src/com/cloud/network/vpc/dao/VpcDao.java
@@ -40,8 +40,8 @@ public interface VpcDao extends GenericDao<VpcVO, Long>{
     
     long countByAccountId(long accountId);
 
-    VpcVO persist(VpcVO vpc, Map<String, String> serviceProviderMap);
+    VpcVO persist(VpcVO vpc, Map<String, List<String>> serviceProviderMap);
 
     void persistVpcServiceProviders(long vpcId,
-                                    Map<String, String> serviceProviderMap);
+                                    Map<String, List<String>> serviceProviderMap);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/798f34a4/engine/schema/src/com/cloud/network/vpc/dao/VpcDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/dao/VpcDaoImpl.java b/engine/schema/src/com/cloud/network/vpc/dao/VpcDaoImpl.java
index 6560b90..12868fe 100644
--- a/engine/schema/src/com/cloud/network/vpc/dao/VpcDaoImpl.java
+++ b/engine/schema/src/com/cloud/network/vpc/dao/VpcDaoImpl.java
@@ -128,7 +128,7 @@ public class VpcDaoImpl extends GenericDaoBase<VpcVO, Long> implements
VpcDao{
 
     @Override
     @DB
-    public VpcVO persist(VpcVO vpc, Map<String, String> serviceProviderMap) {
+    public VpcVO persist(VpcVO vpc, Map<String, List<String>> serviceProviderMap)
{
         Transaction txn = Transaction.currentTxn();
         txn.start();
         VpcVO newVpc = super.persist(vpc);
@@ -139,12 +139,14 @@ public class VpcDaoImpl extends GenericDaoBase<VpcVO, Long> implements
VpcDao{
 
     @Override
     @DB
-    public void persistVpcServiceProviders(long vpcId, Map<String, String> serviceProviderMap)
{
+    public void persistVpcServiceProviders(long vpcId, Map<String, List<String>>
serviceProviderMap) {
         Transaction txn = Transaction.currentTxn();
         txn.start();
         for (String service : serviceProviderMap.keySet()) {
-            VpcServiceMapVO serviceMap = new VpcServiceMapVO(vpcId, Network.Service.getService(service),
Network.Provider.getProvider(serviceProviderMap.get(service)));
-            _vpcSvcMap.persist(serviceMap);
+            for (String provider : serviceProviderMap.get(service)) {
+                VpcServiceMapVO serviceMap = new VpcServiceMapVO(vpcId, Network.Service.getService(service),
Network.Provider.getProvider(provider));
+                _vpcSvcMap.persist(serviceMap);
+            }
         }
         txn.commit();
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/798f34a4/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 43f03c0..646b406 100755
--- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
@@ -114,6 +114,7 @@ public class Upgrade410to420 implements DbUpgrade {
         setRAWformatForRBDVolumes(conn);
         migrateVolumeOnSecondaryStorage(conn);
         createFullCloneFlag(conn);
+        upgradeVpcServiceMap(conn);
     }
 
     private void createFullCloneFlag(Connection conn) {
@@ -2956,4 +2957,59 @@ public class Upgrade410to420 implements DbUpgrade {
             throw new CloudRuntimeException("Failed to update volume format to RAW for volumes
on RBD pools due to exception ", e);
         }
     }
+    
+    
+    private void upgradeVpcServiceMap(Connection conn){
+        s_logger.debug("Upgrading VPC service Map");
+        PreparedStatement listVpc = null;
+        PreparedStatement listServiceProviders = null;
+        PreparedStatement insertProviders = null;
+        ResultSet rs = null;
+        ResultSet rs1 = null;
+        try {
+            //Get all vpc Ids along with vpc offering Id
+            listVpc = conn.prepareStatement("SELECT id, vpc_offering_id FROM `cloud`.`vpc`
where removed is NULL");
+            rs = listVpc.executeQuery();
+            while (rs.next()) {
+                long vpc_id = rs.getLong(1);
+                long offering_id = rs.getLong(2);
+                //list all services and providers in offering
+                listServiceProviders = conn.prepareStatement("SELECT service, provider FROM
`cloud`.`vpc_offering_service_map` where vpc_offering_id = ?");
+                listServiceProviders.setLong(1, offering_id);
+                rs1 = listServiceProviders.executeQuery();
+                //Insert entries in vpc_service_map
+                while (rs1.next()) {
+                    String service = rs1.getString(1);
+                    String provider = rs1.getString(2);
+                    insertProviders = conn.prepareStatement("INSERT INTO `cloud`.`vpc_service_map`
(`vpc_id`, `service`, `provider`, `created`) VALUES (?, ?, ?, now());");
+                    insertProviders.setLong(1, vpc_id);
+                    insertProviders.setString(2, service);
+                    insertProviders.setString(3, provider);
+                    insertProviders.executeUpdate();
+                }
+                s_logger.debug("Upgraded service map for VPC: "+vpc_id);
+            }
+        }catch (SQLException e) {
+            throw new CloudRuntimeException("Error during VPC service map upgrade", e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+                if (rs1 != null) {
+                    rs1.close();
+                }
+                if (listVpc != null) {
+                    listVpc.close();
+                }
+                if (listServiceProviders != null) {
+                    listServiceProviders.close();
+                }
+                if (insertProviders != null) {
+                    insertProviders.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/798f34a4/server/src/com/cloud/network/vpc/VpcManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java
index f81dee9..8ee249f 100644
--- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java
+++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java
@@ -656,18 +656,11 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager,
VpcProvis
         return vpc; 
     }
 
-    private Map<String, String> finalizeServicesAndProvidersForVpc(long zoneId, long
offeringId) {
-        Map<String, String> svcProviders = new HashMap<String, String>();
-        Map<String, List<String>> providerSvcs = new HashMap<String, List<String>>();
+    private Map<String, List<String>> finalizeServicesAndProvidersForVpc(long
zoneId, long offeringId) {
+        Map<String, List<String>> svcProviders = new HashMap<String, List<String>>();
         List<VpcOfferingServiceMapVO> servicesMap = _vpcOffSvcMapDao.listByVpcOffId(offeringId);
 
         for (VpcOfferingServiceMapVO serviceMap : servicesMap) {
-            if (svcProviders.containsKey(serviceMap.getService())) {
-                // FIXME - right now we pick up the first provider from the list, need to
add more logic based on
-                // provider load, etc
-                continue;
-            }
-
             String service = serviceMap.getService();
             String provider = serviceMap.getProvider();
 
@@ -681,13 +674,15 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager,
VpcProvis
                 throw new InvalidParameterValueException("Provider " + provider +
                         " should be enabled in at least one physical network of the zone
specified");
             }
-
-            svcProviders.put(service, provider);
-            List<String> l = providerSvcs.get(provider);
-            if (l == null) {
-                providerSvcs.put(provider, l = new ArrayList<String>());
+            
+            List<String> providers = null;
+            if (svcProviders.get(service) == null) {
+                providers = new ArrayList<String>();
+            } else {
+                providers = svcProviders.get(service);
             }
-            l.add(service);
+            providers.add(provider);
+            svcProviders.put(service, providers);
         }
 
         return svcProviders;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/798f34a4/server/test/com/cloud/vpc/dao/MockVpcDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/dao/MockVpcDaoImpl.java b/server/test/com/cloud/vpc/dao/MockVpcDaoImpl.java
index 562d67d..5e1c2ec 100644
--- a/server/test/com/cloud/vpc/dao/MockVpcDaoImpl.java
+++ b/server/test/com/cloud/vpc/dao/MockVpcDaoImpl.java
@@ -86,12 +86,12 @@ public class MockVpcDaoImpl extends GenericDaoBase<VpcVO, Long>
implements VpcDa
     }
 
     @Override
-    public VpcVO persist(VpcVO vpc, Map<String, String> serviceProviderMap) {
+    public VpcVO persist(VpcVO vpc, Map<String, List<String>> serviceProviderMap)
{
         return null;
     }
 
     @Override
-    public void persistVpcServiceProviders(long vpcId, Map<String, String> serviceProviderMap)
{
+    public void persistVpcServiceProviders(long vpcId, Map<String, List<String>>
serviceProviderMap) {
         return;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/798f34a4/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql
index f7f10b9..197f375 100644
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@ -270,7 +270,7 @@ CREATE TABLE  `vpc_service_map` (
   `created` datetime COMMENT 'date created',
   PRIMARY KEY (`id`),
   CONSTRAINT `fk_vpc_service_map__vpc_id` FOREIGN KEY(`vpc_id`) REFERENCES `vpc`(`id`) ON
DELETE CASCADE,
-  UNIQUE (`vpc_id`, `service`)
+  UNIQUE (`vpc_id`, `service`, `provider`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 CREATE TABLE `cloud`.`load_balancer_healthcheck_policies` (


Mime
View raw message