cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahu...@apache.org
Subject [16/50] [abbrv] CLOUDSTACK-2056: DeploymentPlanner choice via ServiceOffering
Date Mon, 20 May 2013 18:47:31 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a2eb7bab/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java
----------------------------------------------------------------------
diff --git a/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java
b/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java
index 6f52397..7ffbe32 100644
--- a/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java
+++ b/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java
@@ -82,6 +82,7 @@ import com.cloud.offerings.dao.NetworkOfferingDao;
 import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
 import com.cloud.offerings.dao.NetworkOfferingServiceMapDaoImpl;
 import com.cloud.projects.ProjectManager;
+import com.cloud.server.ManagementService;
 import com.cloud.service.dao.ServiceOfferingDaoImpl;
 import com.cloud.storage.dao.DiskOfferingDaoImpl;
 import com.cloud.storage.dao.S3DaoImpl;
@@ -155,162 +156,167 @@ useDefaultFilters=false
 )
 
 public class ChildTestConfiguration {
-    
+
+    @Bean
+    public ManagementService managementService() {
+        return Mockito.mock(ManagementService.class);
+    }
+
     @Bean
     public AccountManager acctMgr() {
         return Mockito.mock(AccountManager.class);
     }
-    
+
     @Bean
     public NetworkService ntwkSvc() {
         return Mockito.mock(NetworkService.class);
     }
-    
+
     @Bean
     public NetworkModel ntwkMdl() {
         return Mockito.mock(NetworkModel.class);
     }
-    
+
     @Bean
     public AlertManager alertMgr() {
         return Mockito.mock(AlertManager.class);
     }
-    
+
     @Bean
     public SecurityChecker securityChkr() {
         return Mockito.mock(SecurityChecker.class);
     }
-    
+
     @Bean
     public ResourceLimitService resourceSvc() {
         return Mockito.mock(ResourceLimitService.class);
     }
-    
+
     @Bean
     public ProjectManager projectMgr() {
         return Mockito.mock(ProjectManager.class);
     }
-    
+
     @Bean
     public SecondaryStorageVmManager ssvmMgr() {
         return Mockito.mock(SecondaryStorageVmManager.class);
     }
-    
+
     @Bean
     public SwiftManager swiftMgr() {
         return Mockito.mock(SwiftManager.class);
     }
-    
+
     @Bean
     public S3Manager s3Mgr() {
         return Mockito.mock(S3Manager.class);
     }
-    
+
     @Bean
     public VpcManager vpcMgr() {
         return Mockito.mock(VpcManager.class);
     }
-    
+
     @Bean
     public UserVmDao userVMDao() {
         return Mockito.mock(UserVmDao.class);
     }
-    
+
     @Bean
     public RulesManager rulesMgr() {
         return Mockito.mock(RulesManager.class);
     }
-    
+
     @Bean
     public LoadBalancingRulesManager lbRulesMgr() {
         return Mockito.mock(LoadBalancingRulesManager.class);
     }
-    
+
     @Bean
     public RemoteAccessVpnService vpnMgr() {
         return Mockito.mock(RemoteAccessVpnService.class);
     }
-    
+
     @Bean
     public NetworkGuru ntwkGuru() {
         return Mockito.mock(NetworkGuru.class);
     }
-    
+
     @Bean
     public NetworkElement ntwkElement() {
         return Mockito.mock(NetworkElement.class);
     }
-    
+
     @Bean
     public IpDeployer ipDeployer() {
         return Mockito.mock(IpDeployer.class);
     }
-    
+
     @Bean
     public DhcpServiceProvider dhcpProvider() {
         return Mockito.mock(DhcpServiceProvider.class);
     }
-    
+
     @Bean
     public FirewallManager firewallMgr() {
         return Mockito.mock(FirewallManager.class);
     }
-    
+
     @Bean
     public AgentManager agentMgr() {
         return Mockito.mock(AgentManager.class);
     }
-    
+
     @Bean
     public StorageNetworkManager storageNtwkMgr() {
         return Mockito.mock(StorageNetworkManager.class);
     }
-    
+
     @Bean
     public NetworkACLManager ntwkAclMgr() {
         return Mockito.mock(NetworkACLManager.class);
     }
-    
+
     @Bean
     public Ipv6AddressManager ipv6Mgr() {
         return Mockito.mock(Ipv6AddressManager.class);
     }
-    
+
     @Bean
     public ConfigurationDao configDao() {
         return Mockito.mock(ConfigurationDao.class);
     }
-    
+
     @Bean
     public UserContext userContext() {
         return Mockito.mock(UserContext.class);
     }
-    
+
     @Bean
     public UserContextInitializer userContextInitializer() {
         return Mockito.mock(UserContextInitializer.class);
     }
-    
+
     @Bean
     public NetworkManager networkManager() {
         return Mockito.mock(NetworkManager.class);
     }
-    
+
     @Bean
     public NetworkOfferingDao networkOfferingDao() {
         return Mockito.mock(NetworkOfferingDao.class);
     }
-    
+
     @Bean
     public NetworkDao networkDao() {
         return Mockito.mock(NetworkDao.class);
     }
-    
+
     @Bean
     public NetworkOfferingServiceMapDao networkOfferingServiceMapDao() {
         return Mockito.mock(NetworkOfferingServiceMapDao.class);
     }
-    
+
     @Bean
     public DataCenterLinkLocalIpAddressDao datacenterLinkLocalIpAddressDao() {
     	return Mockito.mock(DataCenterLinkLocalIpAddressDao.class);
@@ -342,5 +348,5 @@ public class ChildTestConfiguration {
         }
 
     }
-    
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a2eb7bab/server/test/resources/affinityContext.xml
----------------------------------------------------------------------
diff --git a/server/test/resources/affinityContext.xml b/server/test/resources/affinityContext.xml
new file mode 100644
index 0000000..ed880dd
--- /dev/null
+++ b/server/test/resources/affinityContext.xml
@@ -0,0 +1,42 @@
+<!-- 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. -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
+  xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
+  xsi:schemaLocation="http://www.springframework.org/schema/beans
+                      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+                      http://www.springframework.org/schema/tx 
+                      http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
+                      http://www.springframework.org/schema/aop
+                      http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
+                      http://www.springframework.org/schema/context
+                      http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+
+     <context:annotation-config />
+
+    <!-- @DB support -->
+	<bean id="componentContext" class="com.cloud.utils.component.ComponentContext" />
+	
+	  <bean id="transactionContextBuilder" class="com.cloud.utils.db.TransactionContextBuilder"
/>
+	  <bean id="actionEventInterceptor" class="com.cloud.event.ActionEventInterceptor" />
+	  <bean id="instantiatePostProcessor" class="com.cloud.utils.component.ComponentInstantiationPostProcessor">
+	    <property name="Interceptors">
+	        <list>
+	            <ref bean="transactionContextBuilder" />
+	            <ref bean="actionEventInterceptor" />
+	        </list>
+	    </property>
+	  </bean>
+  
+    <bean class="org.apache.cloudstack.affinity.AffinityApiTestConfiguration" />
+    
+
+</beans>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a2eb7bab/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql
index 334aae7..442a544 100644
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@ -973,9 +973,61 @@ CREATE TABLE `cloud`.`network_asa1000v_map` (
 
 ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `eip_associate_public_ip` int(1) unsigned
NOT NULL DEFAULT 0 COMMENT 'true if public IP is associated with user VM creation by default
when EIP service is enabled.' AFTER `elastic_ip_service`;
 
--- Re-enable foreign key checking, at the end of the upgrade path
-SET foreign_key_checks = 1;     
 
+CREATE TABLE `cloud`.`op_host_planner_reservation` (
+  `id` bigint unsigned NOT NULL auto_increment,
+  `data_center_id` bigint unsigned NOT NULL,
+  `pod_id` bigint unsigned,
+  `cluster_id` bigint unsigned,
+  `host_id` bigint unsigned,
+  `resource_usage` varchar(255) COMMENT 'Shared(between planners) Vs Dedicated (exclusive
usage to a planner)',
+  PRIMARY KEY  (`id`),
+  INDEX `i_op_host_planner_reservation__host_resource_usage`(`host_id`, `resource_usage`),
+  CONSTRAINT `fk_planner_reservation__host_id` FOREIGN KEY (`host_id`) REFERENCES `host`(`id`)
ON DELETE CASCADE,
+  CONSTRAINT `fk_planner_reservation__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES
`cloud`.`data_center`(`id`) ON DELETE CASCADE,
+  CONSTRAINT `fk_planner_reservation__pod_id` FOREIGN KEY (`pod_id`) REFERENCES `cloud`.`host_pod_ref`(`id`)
ON DELETE CASCADE,
+  CONSTRAINT `fk_planner_reservation__cluster_id` FOREIGN KEY (`cluster_id`) REFERENCES `cloud`.`cluster`(`id`)
ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+ALTER TABLE `cloud`.`service_offering` ADD COLUMN `deployment_planner` varchar(255) COMMENT
'Planner heuristics used to deploy a VM of this offering; if null global config vm.deployment.planner
is used';
+
+INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server',
'vm.deployment.planner', 'FirstFitPlanner', '[''FirstFitPlanner'', ''UserDispersingPlanner'',
''UserConcentratedPodPlanner'']: DeploymentPlanner heuristic that will be used for VM deployment.');
+INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server',
'host.reservation.release.period', '300000', 'The interval in milliseconds between host reservation
release checks');
+
+DROP VIEW IF EXISTS `cloud`.`service_offering_view`;
+CREATE VIEW `cloud`.`service_offering_view` AS
+    select 
+        service_offering.id,
+        disk_offering.uuid,
+        disk_offering.name,
+        disk_offering.display_text,
+        disk_offering.created,
+        disk_offering.tags,
+        disk_offering.removed,
+        disk_offering.use_local_storage,
+        disk_offering.system_use,
+        service_offering.cpu,
+        service_offering.speed,
+        service_offering.ram_size,
+        service_offering.nw_rate,
+        service_offering.mc_rate,
+        service_offering.ha_enabled,
+        service_offering.limit_cpu_use,
+        service_offering.host_tag,
+        service_offering.default_use,
+        service_offering.vm_type,
+        service_offering.sort_key,
+        service_offering.deployment_planner,
+        domain.id domain_id,
+        domain.uuid domain_uuid,
+        domain.name domain_name,
+        domain.path domain_path
+    from
+        `cloud`.`service_offering`
+            inner join
+        `cloud`.`disk_offering` ON service_offering.id = disk_offering.id
+            left join
+        `cloud`.`domain` ON disk_offering.domain_id = domain.id;
 
 -- Add "default" field to account/user tables
 ALTER TABLE `cloud`.`account` ADD COLUMN `default` int(1) unsigned NOT NULL DEFAULT '0' COMMENT
'1 if account is default';
@@ -1605,3 +1657,8 @@ CREATE  TABLE `cloud`.`nic_ip_alias` (
 
 alter table `cloud`.`vpc_gateways` add column network_acl_id bigint unsigned default 1 NOT
NULL;
 update `cloud`.`vpc_gateways` set network_acl_id = 2;
+
+-- Re-enable foreign key checking, at the end of the upgrade path
+SET foreign_key_checks = 1;			
+
+

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a2eb7bab/test/integration/smoke/test_deploy_vms_with_varied_deploymentplanners.py
----------------------------------------------------------------------
diff --git a/test/integration/smoke/test_deploy_vms_with_varied_deploymentplanners.py b/test/integration/smoke/test_deploy_vms_with_varied_deploymentplanners.py
new file mode 100644
index 0000000..d904a4c
--- /dev/null
+++ b/test/integration/smoke/test_deploy_vms_with_varied_deploymentplanners.py
@@ -0,0 +1,164 @@
+# 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.
+
+#!/usr/bin/env python
+
+import marvin
+from marvin import cloudstackTestCase
+from marvin.cloudstackTestCase import *
+
+import unittest
+import hashlib
+import random
+
+class TestDeployVmWithVariedPlanners(cloudstackTestCase):
+    """
+    This test tests that we can create serviceOfferings with different deployment Planners
and deploy virtual machines into a user account
+    using these service offerings and builtin template
+    """
+    def setUp(self):
+        """
+        CloudStack internally saves its passwords in md5 form and that is how we
+        specify it in the API. Python's hashlib library helps us to quickly hash
+        strings as follows
+        """
+        mdf = hashlib.md5()
+        mdf.update('password')
+        mdf_pass = mdf.hexdigest()
+		
+        self.apiClient = self.testClient.getApiClient() #Get ourselves an API client
+
+        self.acct = createAccount.createAccountCmd() #The createAccount command
+        self.acct.accounttype = 0                    #We need a regular user. admins have
accounttype=1
+        self.acct.firstname = 'test'
+        self.acct.lastname = 'user'                 #What's up doc?
+        self.acct.username = 'testuser'
+        self.acct.password = mdf_pass				#The md5 hashed password string
+        self.acct.email = 'test@domain.com'
+        self.acct.account = 'testacct'
+        self.acct.domainid = 1                       #The default ROOT domain
+        self.acctResponse = self.apiClient.createAccount(self.acct)
+        # And upon successful creation we'll log a helpful message in our logs
+        # using the default debug logger of the test framework
+        self.debug("successfully created account: %s, id: \
+                   %s"%(self.acctResponse.name, \
+                        self.acctResponse.id))
+        
+        #Create service offerings with varied planners
+        self.svcOfferingFirstFit = createServiceOffering.createServiceOfferingCmd()
+        self.svcOfferingFirstFit.name = 'Tiny Instance FirstFit'
+        self.svcOfferingFirstFit.displaytext = 'Tiny Instance with FirstFitPlanner'
+        self.svcOfferingFirstFit.cpuspeed = 100
+        self.svcOfferingFirstFit.cpunumber = 1
+        self.svcOfferingFirstFit.memory = 256
+        self.svcOfferingFirstFit.deploymentplanner = 'FirstFitPlanner'
+        self.svcOfferingFirstFitResponse = self.apiClient.createServiceOffering(self.svcOfferingFirstFit)
+        
+        self.debug("successfully created serviceofferring name: %s, id: \
+				   %s, deploymentPlanner: %s"%(self.svcOfferingFirstFitResponse.name, \
+						self.svcOfferingFirstFitResponse.id,self.svcOfferingFirstFitResponse.deploymentplanner))
+        
+		#Create service offerings with varied planners
+        self.svcOfferingUserDispersing = createServiceOffering.createServiceOfferingCmd()
+        self.svcOfferingUserDispersing.name = 'Tiny Instance UserDispersing'
+        self.svcOfferingUserDispersing.displaytext = 'Tiny Instance with UserDispersingPlanner'
+        self.svcOfferingUserDispersing.cpuspeed = 100
+        self.svcOfferingUserDispersing.cpunumber = 1
+        self.svcOfferingUserDispersing.memory = 256
+        self.svcOfferingUserDispersing.deploymentplanner = 'FirstFitPlanner'
+        self.svcOfferingUserDispersingResponse = self.apiClient.createServiceOffering(self.svcOfferingUserDispersing)
+        
+        self.debug("successfully created serviceofferring name: %s, id: \
+                   %s, deploymentPlanner: %s"%(self.svcOfferingUserDispersingResponse.name,
\
+                        self.svcOfferingUserDispersingResponse.id,self.svcOfferingUserDispersingResponse.deploymentplanner))
+
+    def test_DeployVm(self):
+        """
+        Let's start by defining the attributes of our VM that we will be
+        deploying on CloudStack. We will be assuming a single zone is available
+        and is configured and all templates are Ready
+
+        The hardcoded values are used only for brevity.
+        """
+        deployVmCmd = deployVirtualMachine.deployVirtualMachineCmd()
+        deployVmCmd.zoneid = 1
+        deployVmCmd.account = self.acct.account
+        deployVmCmd.domainid = self.acct.domainid
+        deployVmCmd.templateid = 5                   #For default template- CentOS 5.6(64
bit)
+        deployVmCmd.serviceofferingid = self.svcOfferingFirstFitResponse.id
+
+        deployVmResponse = self.apiClient.deployVirtualMachine(deployVmCmd)
+        self.debug("VM %s was deployed in the job %s"%(deployVmResponse.id, deployVmResponse.jobid))
+
+        # At this point our VM is expected to be Running. Let's find out what
+        # listVirtualMachines tells us about VMs in this account
+
+        listVmCmd = listVirtualMachines.listVirtualMachinesCmd()
+        listVmCmd.id = deployVmResponse.id
+        listVmResponse = self.apiClient.listVirtualMachines(listVmCmd)
+
+        self.assertNotEqual(len(listVmResponse), 0, "Check if the list API \
+                            returns a non-empty response")
+
+        vm1 = listVmResponse[0]
+
+        self.assertEqual(vm1.id, deployVmResponse.id, "Check if the VM returned \
+                         is the same as the one we deployed")
+        self.assertEqual(vm1.state, "Running", "Check if VM has reached \
+                         a state of running")
+        
+
+        deployVm2Cmd = deployVirtualMachine.deployVirtualMachineCmd()
+        deployVm2Cmd.zoneid = 1
+        deployVm2Cmd.account = self.acct.account
+        deployVm2Cmd.domainid = self.acct.domainid
+        deployVm2Cmd.templateid = 5                   #For default template- CentOS 5.6(64
bit)
+        deployVm2Cmd.serviceofferingid = self.svcOfferingFirstFitResponse.id
+
+        deployVm2Response = self.apiClient.deployVirtualMachine(deployVm2Cmd)
+        self.debug("VM %s was deployed in the job %s"%(deployVm2Response.id, deployVm2Response.jobid))
+
+        # At this point our VM is expected to be Running. Let's find out what
+        # listVirtualMachines tells us about VMs in this account
+
+        listVm2Cmd = listVirtualMachines.listVirtualMachinesCmd()
+        listVm2Cmd.id = deployVm2Response.id
+        listVm2Response = self.apiClient.listVirtualMachines(listVm2Cmd)
+        self.assertNotEqual(len(listVm2Response), 0, "Check if the list API \
+                            returns a non-empty response")
+        vm2 = listVm2Response[0]
+        self.assertEqual(vm2.id, deployVm2Response.id, "Check if the VM returned \
+                         is the same as the one we deployed")
+        self.assertEqual(vm2.state, "Running", "Check if VM has reached \
+                         a state of running")
+
+
+    def tearDown(self):                               # Teardown will delete the Account
as well as the VM once the VM reaches "Running" state
+        """
+        And finally let us cleanup the resources we created by deleting the
+        account. All good unittests are atomic and rerunnable this way
+        """
+        deleteAcct = deleteAccount.deleteAccountCmd()
+        deleteAcct.id = self.acctResponse.id
+        self.apiClient.deleteAccount(deleteAcct)
+        deleteSvcOfferingFirstFit = deleteServiceOffering.deleteServiceOfferingCmd()
+        deleteSvcOfferingFirstFit.id = self.svcOfferingFirstFitResponse.id
+        self.apiClient.deleteServiceOffering(deleteSvcOfferingFirstFit);
+        deleteSvcOfferingUserDispersing = deleteServiceOffering.deleteServiceOfferingCmd()
+        deleteSvcOfferingUserDispersing.id = self.svcOfferingUserDispersingResponse.id
+        self.apiClient.deleteServiceOffering(deleteSvcOfferingUserDispersing);
+        
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a2eb7bab/tools/apidoc/gen_toc.py
----------------------------------------------------------------------
diff --git a/tools/apidoc/gen_toc.py b/tools/apidoc/gen_toc.py
index 8b6460e..3758503 100644
--- a/tools/apidoc/gen_toc.py
+++ b/tools/apidoc/gen_toc.py
@@ -142,6 +142,7 @@ known_categories = {
     'listNics':'Nic',
 	'AffinityGroup': 'Affinity Group',
     'InternalLoadBalancer': 'Internal LB',
+	'DeploymentPlanners': 'Configuration',
     }
 
 


Mime
View raw message