You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by pr...@apache.org on 2013/04/11 22:24:40 UTC

[01/34] git commit: updated refs/heads/master to 6137d32

Updated Branches:
  refs/heads/master a4e61b71c -> 6137d327a


API changes for createAffinityGroup


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

Branch: refs/heads/master
Commit: 119c5ceada2ed40d65c723176a4d5f3af43a9026
Parents: a4e61b7
Author: Prachi Damle <pr...@cloud.com>
Authored: Mon Feb 25 10:23:15 2013 -0800
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:22:26 2013 -0700

----------------------------------------------------------------------
 api/src/org/apache/cloudstack/api/BaseCmd.java |    9 +++++----
 client/tomcatconf/commands.properties.in       |    3 +++
 2 files changed, 8 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/119c5cea/api/src/org/apache/cloudstack/api/BaseCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/BaseCmd.java b/api/src/org/apache/cloudstack/api/BaseCmd.java
index 8fef422..c94f3fb 100644
--- a/api/src/org/apache/cloudstack/api/BaseCmd.java
+++ b/api/src/org/apache/cloudstack/api/BaseCmd.java
@@ -27,6 +27,7 @@ import java.util.regex.Pattern;
 
 import javax.inject.Inject;
 
+import org.apache.cloudstack.affinity.AffinityGroupService;
 import org.apache.cloudstack.query.QueryService;
 import org.apache.cloudstack.usage.UsageService;
 import org.apache.log4j.Logger;
@@ -60,7 +61,6 @@ import com.cloud.projects.ProjectService;
 import com.cloud.resource.ResourceService;
 import com.cloud.server.ManagementService;
 import com.cloud.server.TaggedResourceService;
-import com.cloud.storage.DataStoreProviderApiService;
 import com.cloud.storage.StorageService;
 import com.cloud.storage.VolumeApiService;
 import com.cloud.storage.snapshot.SnapshotService;
@@ -132,6 +132,7 @@ public abstract class BaseCmd {
     @Inject public VMSnapshotService _vmSnapshotService;
     @Inject public DataStoreProviderApiService dataStoreProviderApiService;
     @Inject public VpcProvisioningService _vpcProvSvc;
+    @Inject public AffinityGroupService _affinityGroupService;
 
     public abstract void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException;
 
@@ -154,7 +155,7 @@ public abstract class BaseCmd {
     /**
      * For commands the API framework needs to know the owner of the object being acted upon. This method is
      * used to determine that information.
-     * 
+     *
      * @return the id of the account that owns the object being acted upon
      */
     public abstract long getEntityOwnerId();
@@ -467,7 +468,7 @@ public abstract class BaseCmd {
                 if (!enabledOnly || account.getState() == Account.State.enabled) {
                     return account.getId();
                 } else {
-                    throw new PermissionDeniedException("Can't add resources to the account id=" + account.getId() + " in state=" + account.getState() + " as it's no longer active");                    
+                    throw new PermissionDeniedException("Can't add resources to the account id=" + account.getId() + " in state=" + account.getState() + " as it's no longer active");
                 }
             } else {
                 // idList is not used anywhere, so removed it now
@@ -484,7 +485,7 @@ public abstract class BaseCmd {
                     return project.getProjectAccountId();
                 } else {
                     PermissionDeniedException ex = new PermissionDeniedException("Can't add resources to the project with specified projectId in state=" + project.getState() + " as it's no longer active");
-                    ex.addProxyObject(project, projectId, "projectId");                    
+                    ex.addProxyObject(project, projectId, "projectId");
                     throw ex;
                 }
             } else {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/119c5cea/client/tomcatconf/commands.properties.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in
index 163c2ce..e4823d9 100644
--- a/client/tomcatconf/commands.properties.in
+++ b/client/tomcatconf/commands.properties.in
@@ -568,3 +568,6 @@ revertToSnapshot=15
 
 #### Baremetal commands
 addBaremetalHost=1
+
+#### Affinity group commands
+createAffinityGroup=15


[20/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
Correcting the rebase merge issues.


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

Branch: refs/heads/master
Commit: ec3f844ef1004ae6ecaf8b7150842fcb50759b84
Parents: fd23b36
Author: Prachi Damle <pr...@cloud.com>
Authored: Wed Apr 3 16:23:57 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:23:15 2013 -0700

----------------------------------------------------------------------
 .../api/command/user/vm/DeployVMCmd.java           |    8 +-
 setup/db/db/schema-410to420.sql                    |   71 +--------------
 2 files changed, 5 insertions(+), 74 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ec3f844e/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
index 22fe1ba..77ba9fe 100755
--- a/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
@@ -174,15 +174,13 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
     private Boolean startVm;
 
     @ACL
-    @Parameter(name = ApiConstants.AFFINITY_GROUP_IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = AffinityGroupResponse.class, description = "comma separated list of affinity groups id that are going to be applied to the virtual machine. "
-            + "Should be passed only when vm is created from a zone with Basic Network support."
-            + " Mutually exclusive with securitygroupnames parameter")
+    @Parameter(name = ApiConstants.AFFINITY_GROUP_IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = AffinityGroupResponse.class, description = "comma separated list of affinity groups id that are going to be applied to the virtual machine."
+            + " Mutually exclusive with affinitygroupnames parameter")
     private List<Long> affinityGroupIdList;
 
     @ACL
     @Parameter(name = ApiConstants.AFFINITY_GROUP_NAMES, type = CommandType.LIST, collectionType = CommandType.STRING, entityType = AffinityGroupResponse.class, description = "comma separated list of affinity groups names that are going to be applied to the virtual machine."
-            + " Should be passed only when vm is created from a zone with Basic Network support. "
-            + "Mutually exclusive with securitygroupids parameter")
+            + "Mutually exclusive with affinitygroupids parameter")
     private List<String> affinityGroupNameList;
 
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ec3f844e/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql
index 0f6b41e..b4c693a 100644
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@ -166,77 +166,8 @@ CREATE TABLE `cloud`.`affinity_group_vm_map` (
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 
-CREATE TABLE nic_secondary_ips (
-  `id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT,
-  `uuid` varchar(40),
-  `vmId` bigint unsigned COMMENT 'vm instance id',
-  `nicId` bigint unsigned NOT NULL,
-  `ip4_address` char(40) COMMENT 'ip4 address',
-  `ip6_address` char(40) COMMENT 'ip6 address',
-  `network_id` bigint unsigned NOT NULL COMMENT 'network configuration id',
-  `created` datetime NOT NULL COMMENT 'date created',
-  `account_id` bigint unsigned NOT NULL COMMENT 'owner.  foreign key to   account table',
-  `domain_id` bigint unsigned NOT NULL COMMENT 'the domain that the owner belongs to',
-   PRIMARY KEY (`id`),
-   CONSTRAINT `fk_nic_secondary_ip__vmId` FOREIGN KEY `fk_nic_secondary_ip__vmId`(`vmId`) REFERENCES `vm_instance`(`id`) ON DELETE CASCADE,
-   CONSTRAINT `fk_nic_secondary_ip__networks_id` FOREIGN KEY `fk_nic_secondary_ip__networks_id`(`network_id`) REFERENCES `networks`(`id`),
-   CONSTRAINT `uc_nic_secondary_ip__uuid` UNIQUE (`uuid`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
-ALTER TABLE `cloud`.`nics` ADD COLUMN secondary_ip SMALLINT DEFAULT '0' COMMENT 'secondary ips configured for the nic';
-ALTER TABLE `cloud`.`user_ip_address` ADD COLUMN dnat_vmip VARCHAR(40);
-
-ALTER TABLE `cloud`.`alert` ADD COLUMN `archived` tinyint(1) unsigned NOT NULL DEFAULT 0;
-ALTER TABLE `cloud`.`event` ADD COLUMN `archived` tinyint(1) unsigned NOT NULL DEFAULT 0;
-INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'alert.purge.interval', '86400', 'The interval (in seconds) to wait before running the alert purge thread');
-INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'alert.purge.delay', '0', 'Alerts older than specified number days will be purged. Set this value to 0 to never delete alerts');
-
-DROP VIEW IF EXISTS `cloud`.`event_view`;
-CREATE VIEW `cloud`.`event_view` AS
-    select
-        event.id,
-        event.uuid,
-        event.type,
-        event.state,
-        event.description,
-        event.created,
-        event.level,
-        event.parameters,
-        event.start_id,
-        eve.uuid start_uuid,
-        event.user_id,
-        event.archived,
-        user.username user_name,
-        account.id account_id,
-        account.uuid account_uuid,
-        account.account_name account_name,
-        account.type account_type,
-        domain.id domain_id,
-        domain.uuid domain_uuid,
-        domain.name domain_name,
-        domain.path domain_path,
-        projects.id project_id,
-        projects.uuid project_uuid,
-        projects.name project_name
-    from
-        `cloud`.`event`
-            inner join
-        `cloud`.`account` ON event.account_id = account.id
-            inner join
-        `cloud`.`domain` ON event.domain_id = domain.id
-            inner join
-        `cloud`.`user` ON event.user_id = user.id
-            left join
-        `cloud`.`projects` ON projects.project_account_id = event.account_id
-            left join
-        `cloud`.`event` eve ON event.start_id = eve.id;
-
 ALTER TABLE `cloud`.`service_offering` ADD COLUMN `deployment_planner` varchar(255) NOT NULL DEFAULT 'FirstFitPlanner'  COMMENT 'Planner heuristics used to deploy a VM of this offering';
 
--- Re-enable foreign key checking, at the end of the upgrade path
-SET foreign_key_checks = 1;
-
-
 CREATE TABLE nic_secondary_ips (
   `id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT,
   `uuid` varchar(40),
@@ -539,3 +470,5 @@ CREATE TABLE `cloud`.`vm_snapshots` (
 ALTER TABLE `cloud`.`hypervisor_capabilities` ADD COLUMN `vm_snapshot_enabled` tinyint(1) DEFAULT 0 NOT NULL COMMENT 'Whether VM snapshot is supported by hypervisor';
 UPDATE `cloud`.`hypervisor_capabilities` SET `vm_snapshot_enabled`=1 WHERE `hypervisor_type` in ('VMware', 'XenServer');
 
+-- Re-enable foreign key checking, at the end of the upgrade path
+SET foreign_key_checks = 1;			


[05/34] Changes to add AffinityGroupprocessor, deployVM changes

Posted by pr...@apache.org.
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe2a8687/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java b/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java
index e9286db..0fb4e79 100644
--- a/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java
+++ b/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java
@@ -19,17 +19,22 @@ package org.apache.cloudstack.affinity.dao;
 import java.util.List;
 
 import javax.ejb.Local;
+import javax.inject.Inject;
 
 import org.apache.cloudstack.affinity.AffinityGroupVMMapVO;
+import org.apache.cloudstack.affinity.AffinityGroupVO;
 import org.springframework.stereotype.Component;
 
+import com.cloud.host.HostTagVO;
 import com.cloud.utils.Pair;
 import com.cloud.utils.db.Filter;
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.JoinBuilder.JoinType;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.SearchCriteria.Func;
+import com.cloud.utils.db.Transaction;
 
 @Component
 @Local(value = { AffinityGroupVMMapDao.class })
@@ -40,6 +45,10 @@ public class AffinityGroupVMMapDaoImpl extends GenericDaoBase<AffinityGroupVMMap
     protected GenericSearchBuilder<AffinityGroupVMMapVO, Long> CountSGForVm;
     private GenericSearchBuilder<AffinityGroupVMMapVO, Long> ListVmIdByAffinityGroup;
     private SearchBuilder<AffinityGroupVMMapVO> ListByAffinityGroup;
+    private SearchBuilder<AffinityGroupVMMapVO> ListByVmIdType;
+
+    @Inject
+    protected AffinityGroupDao _affinityGroupDao;
 
     protected AffinityGroupVMMapDaoImpl() {
         ListVmIdByAffinityGroup = createSearchBuilder(Long.class);
@@ -62,6 +71,14 @@ public class AffinityGroupVMMapDaoImpl extends GenericDaoBase<AffinityGroupVMMap
         ListByVmIdGroupId.and("affinityGroupId", ListByVmIdGroupId.entity().getAffinityGroupId(), SearchCriteria.Op.EQ);
         ListByVmIdGroupId.done();
 
+        ListByVmIdType = createSearchBuilder();
+        ListByVmIdType.and("instanceId", ListByVmIdType.entity().getInstanceId(), SearchCriteria.Op.EQ);
+        SearchBuilder<AffinityGroupVO> groupSearch = _affinityGroupDao.createSearchBuilder();
+        groupSearch.and("type", groupSearch.entity().getType(), SearchCriteria.Op.EQ);
+        ListByVmIdType.join("groupSearch", groupSearch, ListByVmIdType.entity().getAffinityGroupId(), groupSearch
+                .entity().getId(), JoinType.INNER);
+        ListByVmIdType.done();
+
         CountSGForVm = createSearchBuilder(Long.class);
         CountSGForVm.select(null, Func.COUNT, null);
         CountSGForVm.and("vmId", CountSGForVm.entity().getInstanceId(), SearchCriteria.Op.EQ);
@@ -117,4 +134,30 @@ public class AffinityGroupVMMapDaoImpl extends GenericDaoBase<AffinityGroupVMMap
     	sc.setParameters("vmId", instanceId);
         return customSearch(sc, null).get(0);
 	}
+
+    @Override
+    public AffinityGroupVMMapVO findByVmIdType(long instanceId, String type) {
+        SearchCriteria<AffinityGroupVMMapVO> sc = ListByVmIdType.create();
+        sc.setParameters("instanceId", instanceId);
+        sc.setJoinParameters("groupSearch", "type", type);
+        return customSearch(sc, null).get(0);
+    }
+
+    @Override
+    public void updateMap(Long vmId, List<Long> affinityGroupIds) {
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+
+        SearchCriteria<AffinityGroupVMMapVO> sc = createSearchCriteria();
+        sc.addAnd("instanceId", SearchCriteria.Op.EQ, vmId);
+        expunge(sc);
+
+        for (Long groupId : affinityGroupIds) {
+            AffinityGroupVMMapVO vo = new AffinityGroupVMMapVO(groupId, vmId);
+            persist(vo);
+        }
+
+        txn.commit();
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe2a8687/server/test/com/cloud/vm/MockUserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vm/MockUserVmManagerImpl.java b/server/test/com/cloud/vm/MockUserVmManagerImpl.java
index dd8dd83..fd826d9 100644
--- a/server/test/com/cloud/vm/MockUserVmManagerImpl.java
+++ b/server/test/com/cloud/vm/MockUserVmManagerImpl.java
@@ -253,13 +253,13 @@ public class MockUserVmManagerImpl extends ManagerBase implements UserVmManager,
         // TODO Auto-generated method stub
         return null;
     }
-    
+
     @Override
     public UserVm removeNicFromVirtualMachine(RemoveNicFromVMCmd cmd) throws InvalidParameterValueException, PermissionDeniedException, CloudRuntimeException {
         // TODO Auto-generated method stub
         return null;
     }
-    
+
     @Override
     public UserVm updateDefaultNicForVirtualMachine(UpdateDefaultNicForVMCmd cmd) throws InvalidParameterValueException, CloudRuntimeException {
         // TODO Auto-generated method stub
@@ -330,7 +330,9 @@ public class MockUserVmManagerImpl extends ManagerBase implements UserVmManager,
     @Override
     public UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> securityGroupIdList, Account owner,
             String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, String userData, String sshKeyPair, Map<Long, IpAddresses> requestedIps,
-            IpAddresses defaultIp, String keyboard) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException,
+ IpAddresses defaultIp,
+            String keyboard, List<Long> affinityGroupIdList) throws InsufficientCapacityException,
+            ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException,
             ResourceAllocationException {
         // TODO Auto-generated method stub
         return null;
@@ -339,7 +341,9 @@ public class MockUserVmManagerImpl extends ManagerBase implements UserVmManager,
     @Override
     public UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList,
             List<Long> securityGroupIdList, Account owner, String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, String userData,
-            String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps, String keyboard) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException,
+ String sshKeyPair, Map<Long, IpAddresses> requestedIps,
+            IpAddresses defaultIps, String keyboard, List<Long> affinityGroupIdList)
+            throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException,
             StorageUnavailableException, ResourceAllocationException {
         // TODO Auto-generated method stub
         return null;
@@ -348,7 +352,9 @@ public class MockUserVmManagerImpl extends ManagerBase implements UserVmManager,
     @Override
     public UserVm createAdvancedVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList, Account owner, String hostName,
             String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, String userData, String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps,
-            String keyboard) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException {
+            String keyboard, List<Long> affinityGroupIdList) throws InsufficientCapacityException,
+            ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException,
+            ResourceAllocationException {
         // TODO Auto-generated method stub
         return null;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe2a8687/utils/src/com/cloud/utils/SerialVersionUID.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/SerialVersionUID.java b/utils/src/com/cloud/utils/SerialVersionUID.java
index 35e9446..856d563 100755
--- a/utils/src/com/cloud/utils/SerialVersionUID.java
+++ b/utils/src/com/cloud/utils/SerialVersionUID.java
@@ -61,4 +61,5 @@ public interface SerialVersionUID {
     public static final long CloudExecutionException = Base | 0x27;
     public static final long CallFailedException = Base | 0x28;
     public static final long UnableDeleteHostException = Base | 0x29;
+    public static final long AffinityConflictException = Base | 0x2a;
 }


[27/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
bvt: marvin test for the affinity groups feature

The test deploys two VMs in the simulator context and verifies that the
default host -antiaffinity processor placed the VMs on two distinct
hosts.

Signed-off-by: Prasanna Santhanam <ts...@apache.org>


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

Branch: refs/heads/master
Commit: 79812c253f26841523c9fe3c04ce7c6c47d98314
Parents: e52bf52
Author: Prasanna Santhanam <ts...@apache.org>
Authored: Mon Apr 8 23:18:00 2013 +0530
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:23:32 2013 -0700

----------------------------------------------------------------------
 client/tomcatconf/simulatorComponentContext.xml.in |   23 +-
 test/integration/smoke/test_affinity_groups.py     |  297 ++++++++-------
 tools/marvin/marvin/integration/lib/base.py        |   29 ++-
 3 files changed, 212 insertions(+), 137 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/79812c25/client/tomcatconf/simulatorComponentContext.xml.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/simulatorComponentContext.xml.in b/client/tomcatconf/simulatorComponentContext.xml.in
index fc5cf54..435b9e2 100644
--- a/client/tomcatconf/simulatorComponentContext.xml.in
+++ b/client/tomcatconf/simulatorComponentContext.xml.in
@@ -1,4 +1,3 @@
-
 <!--
   ~ Licensed to the Apache Software Foundation (ASF) under one
   ~ or more contributor license agreements.  See the NOTICE file
@@ -34,8 +33,8 @@
   <!--
     OSS deployment component configuration
   -->
-  <bean id="databaseUpgradeChecker" class="com.cloud.upgrade.DatabaseUpgradeChecker" />
-  <bean id="configurationDaoImpl" class="com.cloud.configuration.dao.ConfigurationDaoImpl" />
+  <bean id="databaseUpgradeChecker" class="com.cloud.upgrade.DatabaseUpgradeChecker"/>
+  <bean id="configurationDaoImpl" class="com.cloud.configuration.dao.ConfigurationDaoImpl"/>
 
   <!-- simulator components -->
   <bean id="SimulatorSecondaryDiscoverer" class="com.cloud.resource.SimulatorSecondaryDiscoverer">
@@ -122,9 +121,9 @@
   <bean id="deploymentPlanners" class="com.cloud.utils.component.AdapterList">
     <property name="Adapters">
       <list>
-        <ref bean="FirstFitPlanner" />
-        <ref bean="UserDispersingPlanner" />
-        <ref bean="UserConcentratedPodPlanner" />
+        <ref bean="FirstFitPlanner"/>
+        <ref bean="UserDispersingPlanner"/>
+        <ref bean="UserConcentratedPodPlanner"/>
 
         <!--
                   <ref bean="BareMetalPlanner" />
@@ -215,6 +214,16 @@
     </property>
   </bean>
 
-  <bean id="GlobalLoadBalancingRulesServiceImpl" class ="org.apache.cloudstack.region.gslb.GlobalLoadBalancingRulesServiceImpl" />
+  <bean id="GlobalLoadBalancingRulesServiceImpl"
+        class="org.apache.cloudstack.region.gslb.GlobalLoadBalancingRulesServiceImpl"/>
+
+  <!--
+  AffinityGroup Processors
+  -->
+  <bean id="HostAntiAffinityProcessor" class="org.apache.cloudstack.affinity.HostAntiAffinityProcessor">
+    <property name="name" value="HostAntiAffinityProcessor"/>
+    <property name="type" value="host anti-affinity"/>
+  </bean>
+
 
 </beans>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/79812c25/test/integration/smoke/test_affinity_groups.py
----------------------------------------------------------------------
diff --git a/test/integration/smoke/test_affinity_groups.py b/test/integration/smoke/test_affinity_groups.py
index 432751c..83fccf5 100644
--- a/test/integration/smoke/test_affinity_groups.py
+++ b/test/integration/smoke/test_affinity_groups.py
@@ -16,142 +16,181 @@
 # specific language governing permissions and limitations
 # under the License.
 
+from marvin.cloudstackTestCase import *
+from marvin.cloudstackAPI import *
+from marvin.integration.lib.utils import *
+from marvin.integration.lib.base import *
+from marvin.integration.lib.common import *
+from marvin import remoteSSHClient
+from nose.plugins.attrib import attr
+
+class Services:
+    """Test Account Services
+    """
 
+    def __init__(self):
+        self.services = {
+            "domain": {
+                "name": "Domain",
+            },
+            "account": {
+                "email": "test@test.com",
+                "firstname": "Test",
+                "lastname": "User",
+                "username": "test",
+                # Random characters are appended for unique
+                # username
+                "password": "password",
+            },
+            "service_offering": {
+                "name": "Tiny Instance",
+                "displaytext": "Tiny Instance",
+                "cpunumber": 1,
+                "cpuspeed": 100,
+                # in MHz
+                "memory": 64,
+                # In MBs
+            },
+            "ostype": 'CentOS 5.3 (64-bit)',
+            "mode": 'advanced',
+            "affinity": {
+                "name": "webvms",
+                "type": "host anti-affinity",
+            }
+        }
 
-import marvin
-from marvin.cloudstackTestCase import *
-from marvin.remoteSSHClient import remoteSSHClient
-import hashlib
-import random
 
 class TestDeployVmWithAffinityGroup(cloudstackTestCase):
     """
     This test deploys a virtual machine into a user account
     using the small service offering 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.password = mdf_pass				#The md5 hashed password string
-		self.acct.username = 'testuser'
-		self.acct.email = 'testuser@xyz.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, user: %s, id: \
-				   %s"%(self.acctResponse.account.account, \
-						self.acctResponse.account.username, \
-						self.acctResponse.account.id))
-
-
-		self.zone = listZones.listZonesCmd()
-		self.zone.uuid = self.apiClient.listZones(self.zone)[0].id
-
-		self.service_offering = listServiceOfferings.listServiceOfferingsCmd()
-		self.service_offering.uuid = self.apiClient.listServiceOfferings(self.service_offering)[0].id
-
-		self.template = listTemplates.listTemplatesCmd()
-		self.template.templatefilter = 'featured'
-		self.template.name = 'CentOS'
-		self.template.uuid = self.apiClient.listTemplates(self.template)[0].id
-
-    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.
 
-		First create the host anti-affinity group for this account
+    @classmethod
+    def setUpClass(cls):
+        cls.api_client = super(TestDeployVmWithAffinityGroup, cls).getClsTestClient().getApiClient()
+        cls.services = Services().services
+        # Get Zone, Domain and templates
+        cls.domain = get_domain(cls.api_client, cls.services)
+        cls.zone = get_zone(cls.api_client, cls.services)
+        cls.disk_offering = DiskOffering.create(
+            cls.api_client,
+            cls.services["disk_offering"]
+        )
+        cls.template = get_template(
+            cls.api_client,
+            cls.zone.id,
+            cls.services["ostype"]
+        )
+        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
+        cls.services["volume"]["zoneid"] = cls.zone.id
+
+        cls.services["template"] = cls.template.id
+        cls.services["zoneid"] = cls.zone.id
+
+        cls.account = Account.create(
+            cls.api_client,
+            cls.services["account"],
+            domainid=cls.domain.id
+        )
+
+        cls.services["account"] = cls.account.account.name
+
+        cls.service_offering = ServiceOffering.create(
+            cls.api_client,
+            cls.services["service_offering"]
+        )
+
+        cls.ag = AffinityGroup.create(cls.api_client, cls.services["affinity"], domainid=cls.domain.id)
+
+        cls._cleanup = [
+            cls.service_offering,
+            cls.disk_offering,
+            cls.account,
+        ]
+        return
+
+    @attr(tags=["simulator", "basic", "advanced"])
+    def test_DeployVmAntiAffinityGroup(self):
+        """
+        Deploys a couple of VMs in the same affinity group and verifies they are not on the same host
         """
-	createAGCmd = createAffinityGroup.createAffinityGroupCmd()
-	createAGCmd.name = 'webvms1'
-	createAGCmd.type = 'host anti-affinity'
-	createAGCmd.account = self.acct.account
-	createAGCmd.domainid = self.acct.domainid
-
-	createAGResponse = self.apiClient.createAffinityGroup(createAGCmd)
-	self.debug("AffinityGroup %s was created in the job %s"%(createAGResponse.id, createAGResponse.jobid))
-
-
-	deployVmCmd = deployVirtualMachine.deployVirtualMachineCmd()
-	deployVmCmd.zoneid = self.zone.uuid
-	deployVmCmd.templateid = self.template.uuid #CentOS 5.6 builtin
-	deployVmCmd.serviceofferingid = self.service_offering.uuid
-	deployVmCmd.account = self.acct.account
-	deployVmCmd.domainid = self.acct.domainid
-	deployVmCmd.affinitygroupnames=[]
-	deployVmCmd.affinitygroupnames.append(str(createAGResponse.name))
-	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")
-
-	vm = listVmResponse[0]
-	self.assertEqual(vm.state, "Running", "Check if VM has reached Running state in CS")
-
-	VM1hostid = vm.hostid
-
-	#Deploy another VM in same affinity group
-	deployVm2Cmd = deployVirtualMachine.deployVirtualMachineCmd()
-	deployVm2Cmd.zoneid = self.zone.uuid
-	deployVm2Cmd.templateid = self.template.uuid #CentOS 5.6 builtin
-	deployVm2Cmd.serviceofferingid = self.service_offering.uuid
-	deployVm2Cmd.account = self.acct.account
-	deployVm2Cmd.domainid = self.acct.domainid
-	deployVm2Cmd.affinitygroupnames=[]
-	deployVm2Cmd.affinitygroupnames.append(str(createAGResponse.name))
-
-	deployVm2Response = self.apiClient.deployVirtualMachine(deployVm2Cmd)
-	self.debug("VM2 %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.state, "Running", "Check if VM has reached Running state in CS")
-
-	VM2hostid = vm2.hostid
-
-	self.assertNotEqual(VM1hostid, VM2hostid, "The hosts of the 2 VM's in the host anti-affinity group are not different, test failed")
-
-    def tearDown(self):
-	"""
-		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.account.id
-        self.apiClient.deleteAccount(deleteAcct)
-        self.testClient.close()
+        #deploy VM1 in affinity group created in setUp
+        vm1 = VirtualMachine.create(
+            self.api_client,
+            self.services["virtual_machine"],
+            templateid=self.template.id,
+            accountid=self.account.account.name,
+            domainid=self.account.account.domainid,
+            serviceofferingid=self.service_offering.id,
+            affinitygroupnames=self.ag.name,
+            mode=self.services["mode"]
+        )
+
+        list_vm1 = list_virtual_machines(
+            self.api_client,
+            id=vm1.id
+        )
+        self.assertEqual(
+            isinstance(list_vm1, list),
+            True,
+            "Check list response returns a valid list"
+        )
+        self.assertNotEqual(
+            len(list_vm1),
+            0,
+            "Check VM available in List Virtual Machines"
+        )
+        vm1_response = list_vm1[0]
+        self.assertEqual(
+            vm1_response.state,
+            'Running',
+            msg="VM is not in Running state"
+        )
+        host_of_vm1 = vm1_response.hostid
+
+        #deploy VM2 in affinity group created in setUp
+        vm2 = VirtualMachine.create(
+            self.api_client,
+            self.services["virtual_machine"],
+            templateid=self.template.id,
+            accountid=self.account.account.name,
+            domainid=self.account.account.domainid,
+            serviceofferingid=self.service_offering.id,
+            affinitygroupnames=self.ag.name,
+            mode=self.services["mode"]
+        )
+        list_vm2 = list_virtual_machines(
+            self.api_client,
+            id=self.vm1.id
+        )
+        self.assertEqual(
+            isinstance(list_vm2, list),
+            True,
+            "Check list response returns a valid list"
+        )
+        self.assertNotEqual(
+            len(list_vm2),
+            0,
+            "Check VM available in List Virtual Machines"
+        )
+        vm2_response = list_vm2[0]
+        self.assertEqual(
+            vm2_response.state,
+            'Running',
+            msg="VM is not in Running state"
+        )
+        host_of_vm2 = vm2_response.hostid
+
+        self.assertNotEqual(host_of_vm1, host_of_vm2,
+            msg="Both VMs of affinity group %s are on the same host" % self.ag.name)
+
+
+        @classmethod
+        def tearDown(cls):
+            try:
+                cls.api_client = super(TestDeployVmWithAffinityGroup, cls).getClsTestClient().getApiClient()
+                #Clean up, terminate the created templates
+                cleanup_resources(cls.api_client, cls.cleanup)
+            except Exception as e:
+                raise Exception("Warning: Exception during cleanup : %s" % e)

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/79812c25/tools/marvin/marvin/integration/lib/base.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/integration/lib/base.py b/tools/marvin/marvin/integration/lib/base.py
index f3370eb..8c7470e 100644
--- a/tools/marvin/marvin/integration/lib/base.py
+++ b/tools/marvin/marvin/integration/lib/base.py
@@ -223,7 +223,7 @@ class VirtualMachine:
     def create(cls, apiclient, services, templateid=None, accountid=None,
                     domainid=None, zoneid=None, networkids=None, serviceofferingid=None,
                     securitygroupids=None, projectid=None, startvm=None,
-                    diskofferingid=None, hostid=None, mode='basic'):
+                    diskofferingid=None, affinitygroupname=None, hostid=None, mode='basic'):
         """Create the instance"""
 
         cmd = deployVirtualMachine.deployVirtualMachineCmd()
@@ -268,6 +268,9 @@ class VirtualMachine:
         if "userdata" in services:
             cmd.userdata = base64.b64encode(services["userdata"])
 
+        if "affinitygroupnames" in services:
+            cmd.affinitygroupnames  = services["affinitygroupnames"]
+
         if projectid:
             cmd.projectid = projectid
 
@@ -2424,3 +2427,27 @@ class VPC:
         cmd = listVPCs.listVPCsCmd()
         [setattr(cmd, k, v) for k, v in kwargs.items()]
         return(apiclient.listVPCs(cmd))
+
+
+class AffinityGroup:
+    def __init__(self, items):
+        self.__dict__.update(items)
+
+    @classmethod
+    def create(cls, apiclient, services, account=None, domainid=None):
+        agCmd = createAffinityGroup.createAffinityGroupCmd()
+        agCmd.name = services['name']
+        agCmd.displayText = services['displaytext'] if 'displaytext' in services else services['name']
+        agCmd.type = services['type']
+        agCmd.account = services['account'] if 'account' in services else account
+        agCmd.domainid = services['domainid'] if 'domainid' in services else domainid
+
+    def update(self):
+        pass
+
+    def delete(self):
+        pass
+
+    @classmethod
+    def list(cls):
+        pass
\ No newline at end of file


[09/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
Schema changes to create affinity group tables


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

Branch: refs/heads/master
Commit: 1ba6740fc1aa30a9111c8375e45646947962b384
Parents: d108fb4
Author: Prachi Damle <pr...@cloud.com>
Authored: Thu Mar 14 17:32:33 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:22:49 2013 -0700

----------------------------------------------------------------------
 setup/db/db/schema-410to420.sql |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1ba6740f/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql
index c7c8b5b..77bb8d6 100644
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@ -142,6 +142,29 @@ CREATE TABLE `cloud`.`user_vm_clone_setting` (
 
 INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'UserVmManager', 'vmware.create.full.clone' , 'false', 'If set to true, creates VMs as full clones on ESX hypervisor');
 
+CREATE TABLE `cloud`.`affinity_group` (
+  `id` bigint unsigned NOT NULL auto_increment,
+  `name` varchar(255) NOT NULL,
+  `type` varchar(255) NOT NULL,
+  `uuid` varchar(40),
+  `description` varchar(4096) NULL,
+  `domain_id` bigint unsigned NOT NULL,
+  `account_id` bigint unsigned NOT NULL,
+  UNIQUE (`name`, `account_id`),
+  PRIMARY KEY  (`id`),
+  CONSTRAINT `fk_affinity_group__account_id` FOREIGN KEY(`account_id`) REFERENCES `account`(`id`),
+  CONSTRAINT `fk_affinity_group__domain_id` FOREIGN KEY(`domain_id`) REFERENCES `domain`(`id`),
+  CONSTRAINT `uc_affinity_group__uuid` UNIQUE (`uuid`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+CREATE TABLE `cloud`.`affinity_group_vm_map` (
+  `id` bigint unsigned NOT NULL auto_increment,
+  `affinity_group_id` bigint unsigned NOT NULL,
+  `instance_id` bigint unsigned NOT NULL,
+  PRIMARY KEY  (`id`),
+  CONSTRAINT `fk_agvm__group_id` FOREIGN KEY(`affinity_group_id`) REFERENCES `affinity_group`(`id`)  
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
 -- Re-enable foreign key checking, at the end of the upgrade path
 SET foreign_key_checks = 1;
 


[03/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
DeleteAffinityGroup API changes


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

Branch: refs/heads/master
Commit: 50f53c86f59dd696f5f5315ba9a4c11b3f84c302
Parents: 1e205a3
Author: Prachi Damle <pr...@cloud.com>
Authored: Thu Feb 28 13:42:33 2013 -0800
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:22:34 2013 -0700

----------------------------------------------------------------------
 api/src/com/cloud/event/EventTypes.java            |    7 +-
 .../cloudstack/affinity/AffinityGroupService.java  |    9 +-
 .../apache/cloudstack/api/ResponseGenerator.java   |    2 +
 .../user/affinitygroup/DeleteAffinityGroupCmd.java |  137 +++++++++++++++
 server/src/com/cloud/api/ApiDBUtils.java           |   14 ++-
 server/src/com/cloud/api/ApiResponseHelper.java    |   10 +
 .../affinity/AffinityGroupServiceImpl.java         |   70 +++++++-
 7 files changed, 239 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/50f53c86/api/src/com/cloud/event/EventTypes.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/event/EventTypes.java b/api/src/com/cloud/event/EventTypes.java
index 5671f99..bd5f220 100755
--- a/api/src/com/cloud/event/EventTypes.java
+++ b/api/src/com/cloud/event/EventTypes.java
@@ -348,7 +348,7 @@ public class EventTypes {
     // tag related events
     public static final String EVENT_TAGS_CREATE = "CREATE_TAGS";
     public static final String EVENT_TAGS_DELETE = "DELETE_TAGS";
-    
+
 	// vm snapshot events
     public static final String EVENT_VM_SNAPSHOT_CREATE = "VMSNAPSHOT.CREATE";
     public static final String EVENT_VM_SNAPSHOT_DELETE = "VMSNAPSHOT.DELETE";
@@ -382,6 +382,11 @@ public class EventTypes {
     public static final String EVENT_BAREMETAL_PXE_SERVER_ADD = "PHYSICAL.PXE.ADD";
     public static final String EVENT_BAREMETAL_PXE_SERVER_DELETE = "PHYSICAL.PXE.DELETE";
 
+    public static final String EVENT_AFFINITY_GROUP_CREATE = "AG.CREATE";
+    public static final String EVENT_AFFINITY_GROUP_DELETE = "AG.DELETE";
+    public static final String EVENT_AFFINITY_GROUP_ASSIGN = "AG.ASSIGN";
+    public static final String EVENT_AFFINITY_GROUP_REMOVE = "AG.REMOVE";
+
     static {
 
         // TODO: need a way to force author adding event types to declare the entity details as well, with out braking

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/50f53c86/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java b/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java
index 8323176..501280d 100644
--- a/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java
+++ b/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java
@@ -2,6 +2,8 @@ package org.apache.cloudstack.affinity;
 
 import java.util.List;
 
+import com.cloud.exception.ResourceInUseException;
+
 public interface AffinityGroupService {
 
     /**
@@ -20,14 +22,15 @@ public interface AffinityGroupService {
 
     /**
      * Creates an affinity/anti-affinity group.
-     *
+     * 
      * @param affinityGroupId
      * @param account
      * @param domainId
      * @param affinityGroupName
-     * @param vmId
+     * @throws ResourceInUseException
      */
-    void deleteAffinityGroup(Long affinityGroupId, String account, Long domainId, String affinityGroupName, Long vmId);
+    boolean deleteAffinityGroup(Long affinityGroupId, String account, Long domainId, String affinityGroupName)
+            throws ResourceInUseException;
 
     /**
      * Lists Affinity Groups

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/50f53c86/api/src/org/apache/cloudstack/api/ResponseGenerator.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ResponseGenerator.java b/api/src/org/apache/cloudstack/api/ResponseGenerator.java
index f09f8ae..9777130 100644
--- a/api/src/org/apache/cloudstack/api/ResponseGenerator.java
+++ b/api/src/org/apache/cloudstack/api/ResponseGenerator.java
@@ -386,4 +386,6 @@ public interface ResponseGenerator {
     public NicResponse createNicResponse(Nic result);
 
     AffinityGroupResponse createAffinityGroupResponse(AffinityGroup group);
+
+    Long getAffinityGroupId(String name, long entityOwnerId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/50f53c86/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java
new file mode 100644
index 0000000..8ace2e5
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java
@@ -0,0 +1,137 @@
+// 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 org.apache.cloudstack.api.command.user.affinitygroup;
+
+import org.apache.cloudstack.affinity.AffinityGroupResponse;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.log4j.Logger;
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.ResourceInUseException;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+
+@APICommand(name = "deleteAffinityGroup", description = "Deletes affinity group", responseObject = SuccessResponse.class)
+public class DeleteAffinityGroupCmd extends BaseCmd {
+    public static final Logger s_logger = Logger.getLogger(DeleteAffinityGroupCmd.class.getName());
+    private static final String s_name = "deleteaffinitygroupresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "the account of the affinity group. Must be specified with domain ID")
+    private String accountName;
+
+    @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, description = "the domain ID of account owning the affinity group", entityType = DomainResponse.class)
+    private Long domainId;
+
+    @Parameter(name = ApiConstants.ID, type = CommandType.UUID, description = "The ID of the affinity group. Mutually exclusive with name parameter", entityType = AffinityGroupResponse.class)
+    private Long id;
+
+    @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "The ID of the affinity group. Mutually exclusive with id parameter")
+    private String name;
+
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public String getAccountName() {
+        return accountName;
+    }
+
+    public Long getDomainId() {
+        return domainId;
+    }
+
+
+    public Long getId() {
+        if (id != null && name != null) {
+            throw new InvalidParameterValueException("name and id parameters are mutually exclusive");
+        }
+
+        if (name != null) {
+            id = _responseGenerator.getAffinityGroupId(name, getEntityOwnerId());
+            if (id == null) {
+                throw new InvalidParameterValueException("Unable to find affinity group by name " + name
+                        + " for the account id=" + getEntityOwnerId());
+            }
+        }
+
+        if (id == null) {
+            throw new InvalidParameterValueException(
+                    "Either id or name parameter is requred by deleteAffinityGroup command");
+        }
+
+        return id;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        Account account = UserContext.current().getCaller();
+        if ((account == null) || isAdmin(account.getType())) {
+            if ((domainId != null) && (accountName != null)) {
+                Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId);
+                if (userAccount != null) {
+                    return userAccount.getId();
+                }
+            }
+        }
+
+        if (account != null) {
+            return account.getId();
+        }
+
+        return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this
+                                          // command to SYSTEM so ERROR events
+                                          // are tracked
+
+    }
+
+    @Override
+    public void execute(){
+        try{
+            boolean result = _affinityGroupService.deleteAffinityGroup(id, accountName, domainId, name);
+            if (result) {
+                SuccessResponse response = new SuccessResponse(getCommandName());
+                this.setResponseObject(response);
+            } else {
+                throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete affinity group");
+            }
+        } catch (ResourceInUseException ex) {
+            s_logger.warn("Exception: ", ex);
+            throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, ex.getMessage());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/50f53c86/server/src/com/cloud/api/ApiDBUtils.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java
index 7b44190..d21e2c4 100755
--- a/server/src/com/cloud/api/ApiDBUtils.java
+++ b/server/src/com/cloud/api/ApiDBUtils.java
@@ -25,6 +25,8 @@ import java.util.Set;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 
+import org.apache.cloudstack.affinity.AffinityGroup;
+import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
 import org.apache.cloudstack.api.ApiConstants.HostDetails;
 import org.apache.cloudstack.api.ApiConstants.VMDetails;
 import org.apache.cloudstack.api.response.AccountResponse;
@@ -284,7 +286,7 @@ public class ApiDBUtils {
     static NetworkModel _networkModel;
     static NetworkManager _networkMgr;
     static TemplateManager _templateMgr;
-    
+
     static StatsCollector _statsCollector;
 
     static AccountDao _accountDao;
@@ -379,6 +381,7 @@ public class ApiDBUtils {
     static ClusterDetailsDao _clusterDetailsDao;
     static NicSecondaryIpDao _nicSecondaryIpDao;
     static VpcProvisioningService _vpcProvSvc;
+    static AffinityGroupDao _affinityGroupDao;
 
     @Inject private ManagementServer ms;
     @Inject public AsyncJobManager asyncMgr;
@@ -483,6 +486,8 @@ public class ApiDBUtils {
     @Inject private VMSnapshotDao vmSnapshotDao;
     @Inject private NicSecondaryIpDao nicSecondaryIpDao;
     @Inject private VpcProvisioningService vpcProvSvc;
+    @Inject private AffinityGroupDao affinityGroupDao;
+
     @PostConstruct
     void init() {
         _ms = ms;
@@ -585,6 +590,7 @@ public class ApiDBUtils {
         _vmSnapshotDao = vmSnapshotDao;
         _nicSecondaryIpDao = nicSecondaryIpDao;
         _vpcProvSvc = vpcProvSvc;
+        _affinityGroupDao = affinityGroupDao;
         // Note: stats collector should already have been initialized by this time, otherwise a null instance is returned
         _statsCollector = StatsCollector.getInstance();
     }
@@ -1579,7 +1585,7 @@ public class ApiDBUtils {
    public static DataCenterJoinVO newDataCenterView(DataCenter dc){
        return _dcJoinDao.newDataCenterView(dc);
    }
-   
+
    public static Map<String, String> findHostDetailsById(long hostId){
 	   return _hostDetailsDao.findDetails(hostId);
    }
@@ -1587,4 +1593,8 @@ public class ApiDBUtils {
    public static List<NicSecondaryIpVO> findNicSecondaryIps(long nicId) {
        return _nicSecondaryIpDao.listByNicId(nicId);
    }
+
+    public static AffinityGroup getAffinityGroup(String groupName, long accountId) {
+        return _affinityGroupDao.findByAccountAndName(accountId, groupName);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/50f53c86/server/src/com/cloud/api/ApiResponseHelper.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java
index 7b23b3b..d651f1f 100755
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -3668,4 +3668,14 @@ public class ApiResponseHelper implements ResponseGenerator {
 
         return response;
     }
+
+    @Override
+    public Long getAffinityGroupId(String groupName, long accountId) {
+        AffinityGroup ag = ApiDBUtils.getAffinityGroup(groupName, accountId);
+        if (ag == null) {
+            return null;
+        } else {
+            return ag.getId();
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/50f53c86/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
index eee3e6f..f3b166f 100644
--- a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
+++ b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
@@ -8,15 +8,25 @@ import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
 import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
+import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
 import org.apache.log4j.Logger;
 
 
+import com.cloud.event.ActionEvent;
+import com.cloud.event.EventTypes;
 import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.ResourceInUseException;
+import com.cloud.network.security.SecurityGroupManager;
+import com.cloud.network.security.SecurityGroupRuleVO;
+import com.cloud.network.security.SecurityGroupVMMapVO;
+import com.cloud.network.security.SecurityGroupVO;
 import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
 import com.cloud.user.UserContext;
 import com.cloud.utils.component.Manager;
 import com.cloud.utils.component.ManagerBase;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.Transaction;
 
 @Local(value = { AffinityGroupService.class })
 public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGroupService, Manager {
@@ -30,6 +40,9 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
     @Inject
     AffinityGroupDao _affinityGroupDao;
 
+    @Inject
+    AffinityGroupVMMapDao _affinityGroupVMMapDao;
+
     @Override
     public AffinityGroup createAffinityGroup(String account, Long domainId, String affinityGroupName,
             String affinityGroupType, String description) {
@@ -37,7 +50,7 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
         Account caller = UserContext.current().getCaller();
         Account owner = _accountMgr.finalizeOwner(caller, account, domainId, null);
 
-        if (_affinityGroupDao.isNameInUse(owner.getId(), owner.getDomainId(), affinityGroupName)) {
+        if (_affinityGroupDao.isNameInUse(owner.getAccountId(), owner.getDomainId(), affinityGroupName)) {
             throw new InvalidParameterValueException("Unable to create affinity group, a group with name "
                     + affinityGroupName
                     + " already exisits.");
@@ -47,14 +60,63 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
                 owner.getId());
         _affinityGroupDao.persist(group);
 
+        if (s_logger.isDebugEnabled()) {
+            s_logger.debug("Created affinity group =" + affinityGroupName);
+        }
+
         return group;
     }
 
+    @DB
     @Override
-    public void deleteAffinityGroup(Long affinityGroupId, String account, Long domainId, String affinityGroupName,
-            Long vmId) {
-        // TODO Auto-generated method stub
+    @ActionEvent(eventType = EventTypes.EVENT_SECURITY_GROUP_DELETE, eventDescription = "deleting affinity group")
+    public boolean deleteAffinityGroup(Long affinityGroupId, String account, Long domainId, String affinityGroupName)
+            throws ResourceInUseException {
+
+        Account caller = UserContext.current().getCaller();
+        Account owner = _accountMgr.finalizeOwner(caller, account, domainId, null);
+
+        AffinityGroupVO group = null;
+        if (affinityGroupId != null) {
+            group = _affinityGroupDao.findById(affinityGroupId);
+            if (group == null) {
+                throw new InvalidParameterValueException("Unable to find affinity group: " + affinityGroupId
+                        + "; failed to delete group.");
+            }
+        } else if (affinityGroupName != null) {
+            group = _affinityGroupDao.findByAccountAndName(owner.getAccountId(), affinityGroupName);
+            if (group == null) {
+                throw new InvalidParameterValueException("Unable to find affinity group: " + affinityGroupName
+                        + "; failed to delete group.");
+            }
+        } else {
+            throw new InvalidParameterValueException(
+                    "Either the affinity group Id or group name must be specified to delete the group");
+        }
 
+        // check permissions
+        _accountMgr.checkAccess(caller, null, true, group);
+
+        final Transaction txn = Transaction.currentTxn();
+        txn.start();
+
+        group = _affinityGroupDao.lockRow(affinityGroupId, true);
+        if (group == null) {
+            throw new InvalidParameterValueException("Unable to find affinity group by id " + affinityGroupId);
+        }
+
+        List<AffinityGroupVMMapVO> affinityGroupVmMap = _affinityGroupVMMapDao.listByAffinityGroup(affinityGroupId);
+        if (!affinityGroupVmMap.isEmpty()) {
+            throw new ResourceInUseException("Cannot delete affinity group when it's in use by virtual machines");
+        }
+
+        _affinityGroupDao.expunge(affinityGroupId);
+        txn.commit();
+
+        if (s_logger.isDebugEnabled()) {
+            s_logger.debug("Deleted affinity group id=" + affinityGroupId);
+        }
+        return true;
     }
 
     @Override


[24/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
Fixes to de-couple the AffinityGroupResponse from UserVmResponse, since ApiDiscoveryService breaks, if we nest two response objects into each other.


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

Branch: refs/heads/master
Commit: 0f565f2167981071962b629cb550f9a1973c8fa4
Parents: 3403b54
Author: Prachi Damle <pr...@cloud.com>
Authored: Fri Apr 5 17:01:06 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:23:25 2013 -0700

----------------------------------------------------------------------
 .../cloudstack/affinity/AffinityGroupResponse.java |   18 +++++++-----
 .../api/query/dao/AffinityGroupJoinDaoImpl.java    |   21 +++------------
 setup/db/db/schema-410to420.sql                    |    3 +-
 3 files changed, 16 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0f565f21/api/src/org/apache/cloudstack/affinity/AffinityGroupResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/affinity/AffinityGroupResponse.java b/api/src/org/apache/cloudstack/affinity/AffinityGroupResponse.java
index 1ae7c59..afd33da 100644
--- a/api/src/org/apache/cloudstack/affinity/AffinityGroupResponse.java
+++ b/api/src/org/apache/cloudstack/affinity/AffinityGroupResponse.java
@@ -16,8 +16,10 @@
 // under the License.
 package org.apache.cloudstack.affinity;
 
+import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.LinkedHashSet;
+import java.util.List;
 import java.util.Set;
 
 import org.apache.cloudstack.api.ApiConstants;
@@ -57,12 +59,12 @@ public class AffinityGroupResponse extends BaseResponse implements ControlledVie
     @Param(description = "the type of the affinity group")
     private String type;
 
-    @SerializedName("virtualmachine")
-    @Param(description = "virtual machines associated with this affinity group ", responseObject = UserVmResponse.class)
-    private Set<UserVmResponse> vmList;
+    @SerializedName("virtualmachineIds")
+    @Param(description = "virtual machine Ids associated with this affinity group ")
+    private List<String> vmIdList;
 
     public AffinityGroupResponse() {
-        this.vmList = new LinkedHashSet<UserVmResponse>();
+        this.vmIdList = new ArrayList<String>();
     }
 
     @Override
@@ -142,12 +144,12 @@ public class AffinityGroupResponse extends BaseResponse implements ControlledVie
 
     }
 
-    public void setVMList(Set<UserVmResponse> vmList) {
-        this.vmList = vmList;
+    public void setVMIdList(List<String> vmIdList) {
+        this.vmIdList = vmIdList;
     }
 
-    public void addVM(UserVmResponse vm) {
-        this.vmList.add(vm);
+    public void addVMId(String vmId) {
+        this.vmIdList.add(vmId);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0f565f21/server/src/com/cloud/api/query/dao/AffinityGroupJoinDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/dao/AffinityGroupJoinDaoImpl.java b/server/src/com/cloud/api/query/dao/AffinityGroupJoinDaoImpl.java
index 98c6440..a176793 100644
--- a/server/src/com/cloud/api/query/dao/AffinityGroupJoinDaoImpl.java
+++ b/server/src/com/cloud/api/query/dao/AffinityGroupJoinDaoImpl.java
@@ -25,13 +25,10 @@ import javax.inject.Inject;
 
 import org.apache.cloudstack.affinity.AffinityGroup;
 import org.apache.cloudstack.affinity.AffinityGroupResponse;
-import org.apache.cloudstack.api.response.UserVmResponse;
 import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
 import com.cloud.api.ApiResponseHelper;
 import com.cloud.api.query.vo.AffinityGroupJoinVO;
 import com.cloud.configuration.dao.ConfigurationDao;
-import com.cloud.user.Account;
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
@@ -72,13 +69,9 @@ public class AffinityGroupJoinDaoImpl extends GenericDaoBase<AffinityGroupJoinVO
         // update vm information
         long instanceId = vag.getVmId();
         if (instanceId > 0) {
-            UserVmResponse resp = new UserVmResponse();
-            resp.setObjectName("virtualmachine");
-            resp.setId(vag.getVmUuid());
-            resp.setName(vag.getVmName());
-            resp.setDisplayName(vag.getVmDisplayName());
-            resp.setState(vag.getVmState().toString());
-            agResponse.addVM(resp);
+            List<String> vmIdList = new ArrayList<String>();
+            vmIdList.add(vag.getVmUuid());
+            agResponse.setVMIdList(vmIdList);
         }
 
         agResponse.setObjectName("affinitygroup");
@@ -90,13 +83,7 @@ public class AffinityGroupJoinDaoImpl extends GenericDaoBase<AffinityGroupJoinVO
         // update vm information
         long instanceId = vag.getVmId();
         if (instanceId > 0) {
-            UserVmResponse resp = new UserVmResponse();
-            resp.setObjectName("virtualmachine");
-            resp.setId(vag.getVmUuid());
-            resp.setName(vag.getVmName());
-            resp.setDisplayName(vag.getVmDisplayName());
-            resp.setState(vag.getVmState().toString());
-            vagData.addVM(resp);
+            vagData.addVMId(vag.getVmUuid());
         }
         return vagData;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0f565f21/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql
index ae08ebe..92b2d9c 100644
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@ -162,7 +162,8 @@ CREATE TABLE `cloud`.`affinity_group_vm_map` (
   `affinity_group_id` bigint unsigned NOT NULL,
   `instance_id` bigint unsigned NOT NULL,
   PRIMARY KEY  (`id`),
-  CONSTRAINT `fk_agvm__group_id` FOREIGN KEY(`affinity_group_id`) REFERENCES `affinity_group`(`id`)  
+  CONSTRAINT `fk_agvm__group_id` FOREIGN KEY(`affinity_group_id`) REFERENCES `affinity_group`(`id`) ON DELETE CASCADE,
+  CONSTRAINT `fk_affinity_group_vm_map___instance_id` FOREIGN KEY(`instance_id`) REFERENCES `user_vm` (`id`) ON DELETE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 


[07/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
Separated out host anti-affinity as a plugin.


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

Branch: refs/heads/master
Commit: bf9221a370da0c0720f1411f50738ab7d6d98ab5
Parents: fe2a868
Author: Prachi Damle <pr...@cloud.com>
Authored: Thu Mar 14 17:20:42 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:22:45 2013 -0700

----------------------------------------------------------------------
 .../host-anti-affinity/pom.xml                     |   33 +++++++
 .../affinity/HostAntiAffinityProcessor.java        |   66 +++++++++++++++
 plugins/pom.xml                                    |    1 +
 .../affinity/HostAntiAffinityProcessor.java        |   66 ---------------
 4 files changed, 100 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bf9221a3/plugins/affinity-group-processors/host-anti-affinity/pom.xml
----------------------------------------------------------------------
diff --git a/plugins/affinity-group-processors/host-anti-affinity/pom.xml b/plugins/affinity-group-processors/host-anti-affinity/pom.xml
new file mode 100644
index 0000000..669febd
--- /dev/null
+++ b/plugins/affinity-group-processors/host-anti-affinity/pom.xml
@@ -0,0 +1,33 @@
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>cloud-plugin-host-anti-affinity</artifactId>
+  <name>Apache CloudStack Plugin - Host Anti-Affinity Processor</name>
+  <parent>
+    <groupId>org.apache.cloudstack</groupId>
+    <artifactId>cloudstack-plugins</artifactId>
+    <version>4.2.0-SNAPSHOT</version>
+    <relativePath>../../pom.xml</relativePath>
+  </parent>
+  <build>
+    <defaultGoal>install</defaultGoal>
+    <sourceDirectory>src</sourceDirectory>    
+  </build>  
+</project>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bf9221a3/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
----------------------------------------------------------------------
diff --git a/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java b/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
new file mode 100644
index 0000000..93bd358
--- /dev/null
+++ b/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
@@ -0,0 +1,66 @@
+package org.apache.cloudstack.affinity;
+
+import java.util.List;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
+import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
+import org.apache.log4j.Logger;
+
+import com.cloud.deploy.DeploymentPlan;
+import com.cloud.deploy.DeploymentPlanner.ExcludeList;
+import com.cloud.exception.AffinityConflictException;
+import com.cloud.utils.component.AdapterBase;
+import com.cloud.vm.VMInstanceVO;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.VirtualMachineProfile;
+import com.cloud.vm.dao.UserVmDao;
+import com.cloud.vm.dao.VMInstanceDao;
+
+@Local(value = AffinityGroupProcessor.class)
+public class HostAntiAffinityProcessor extends AdapterBase implements AffinityGroupProcessor {
+
+    private static final Logger s_logger = Logger.getLogger(HostAntiAffinityProcessor.class);
+    @Inject
+    protected UserVmDao _vmDao;
+    @Inject
+    protected VMInstanceDao _vmInstanceDao;
+    @Inject
+    protected AffinityGroupDao _affinityGroupDao;
+    @Inject
+    protected AffinityGroupVMMapDao _affinityGroupVMMapDao;
+
+    @Override
+    public void process(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan,
+            ExcludeList avoid)
+            throws AffinityConflictException {
+        VirtualMachine vm = vmProfile.getVirtualMachine();
+        AffinityGroupVMMapVO vmGroupMapping = _affinityGroupVMMapDao.findByVmIdType(vm.getId(), getType());
+
+        if (vmGroupMapping != null) {
+            AffinityGroupVO group = _affinityGroupDao.findById(vmGroupMapping.getAffinityGroupId());
+
+            if (s_logger.isDebugEnabled()) {
+                s_logger.debug("Processing affinity group " + group.getName() + " for VM Id: " + vm.getId());
+            }
+
+            List<Long> groupVMIds = _affinityGroupVMMapDao.listVmIdsByAffinityGroup(group.getId());
+
+            for (Long groupVMId : groupVMIds) {
+                VMInstanceVO groupVM = _vmInstanceDao.findById(groupVMId);
+                if (groupVM != null && !groupVM.isRemoved() && groupVM.getHostId() != null) {
+                    avoid.addHost(groupVM.getHostId());
+                }
+            }
+        }
+
+    }
+
+    @Override
+    public String getType() {
+        return "HostAntiAffinity";
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bf9221a3/plugins/pom.xml
----------------------------------------------------------------------
diff --git a/plugins/pom.xml b/plugins/pom.xml
index 607c50c..12c85ff 100755
--- a/plugins/pom.xml
+++ b/plugins/pom.xml
@@ -36,6 +36,7 @@
     <module>api/rate-limit</module>
     <module>api/discovery</module>
     <module>acl/static-role-based</module>
+	<module>affinity-group-processors/host-anti-affinity</module>
     <module>deployment-planners/user-concentrated-pod</module>
     <module>deployment-planners/user-dispersing</module>
     <module>host-allocators/random</module>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bf9221a3/server/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java b/server/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
deleted file mode 100644
index 93bd358..0000000
--- a/server/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package org.apache.cloudstack.affinity;
-
-import java.util.List;
-
-import javax.ejb.Local;
-import javax.inject.Inject;
-
-import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
-import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
-import org.apache.log4j.Logger;
-
-import com.cloud.deploy.DeploymentPlan;
-import com.cloud.deploy.DeploymentPlanner.ExcludeList;
-import com.cloud.exception.AffinityConflictException;
-import com.cloud.utils.component.AdapterBase;
-import com.cloud.vm.VMInstanceVO;
-import com.cloud.vm.VirtualMachine;
-import com.cloud.vm.VirtualMachineProfile;
-import com.cloud.vm.dao.UserVmDao;
-import com.cloud.vm.dao.VMInstanceDao;
-
-@Local(value = AffinityGroupProcessor.class)
-public class HostAntiAffinityProcessor extends AdapterBase implements AffinityGroupProcessor {
-
-    private static final Logger s_logger = Logger.getLogger(HostAntiAffinityProcessor.class);
-    @Inject
-    protected UserVmDao _vmDao;
-    @Inject
-    protected VMInstanceDao _vmInstanceDao;
-    @Inject
-    protected AffinityGroupDao _affinityGroupDao;
-    @Inject
-    protected AffinityGroupVMMapDao _affinityGroupVMMapDao;
-
-    @Override
-    public void process(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan,
-            ExcludeList avoid)
-            throws AffinityConflictException {
-        VirtualMachine vm = vmProfile.getVirtualMachine();
-        AffinityGroupVMMapVO vmGroupMapping = _affinityGroupVMMapDao.findByVmIdType(vm.getId(), getType());
-
-        if (vmGroupMapping != null) {
-            AffinityGroupVO group = _affinityGroupDao.findById(vmGroupMapping.getAffinityGroupId());
-
-            if (s_logger.isDebugEnabled()) {
-                s_logger.debug("Processing affinity group " + group.getName() + " for VM Id: " + vm.getId());
-            }
-
-            List<Long> groupVMIds = _affinityGroupVMMapDao.listVmIdsByAffinityGroup(group.getId());
-
-            for (Long groupVMId : groupVMIds) {
-                VMInstanceVO groupVM = _vmInstanceDao.findById(groupVMId);
-                if (groupVM != null && !groupVM.isRemoved() && groupVM.getHostId() != null) {
-                    avoid.addHost(groupVM.getHostId());
-                }
-            }
-        }
-
-    }
-
-    @Override
-    public String getType() {
-        return "HostAntiAffinity";
-    }
-
-}


[04/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
ListAffinityGroups API changes


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

Branch: refs/heads/master
Commit: 1aed5bf9c2c75843c1d89973f467ec7c9128242d
Parents: 50f53c8
Author: Prachi Damle <pr...@cloud.com>
Authored: Thu Feb 28 17:16:54 2013 -0800
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:22:38 2013 -0700

----------------------------------------------------------------------
 api/src/com/cloud/async/AsyncJob.java              |    3 +-
 .../cloudstack/affinity/AffinityGroupService.java  |   15 ++-
 .../user/affinitygroup/CreateAffinityGroupCmd.java |   49 ++++++-
 .../user/affinitygroup/DeleteAffinityGroupCmd.java |   21 +++-
 .../user/affinitygroup/ListAffinityGroupsCmd.java  |  107 +++++++++++++++
 .../affinity/AffinityGroupServiceImpl.java         |   76 ++++++++++-
 6 files changed, 254 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1aed5bf9/api/src/com/cloud/async/AsyncJob.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/async/AsyncJob.java b/api/src/com/cloud/async/AsyncJob.java
index 8e4aec0..866429b 100644
--- a/api/src/com/cloud/async/AsyncJob.java
+++ b/api/src/com/cloud/async/AsyncJob.java
@@ -49,7 +49,8 @@ public interface AsyncJob extends Identity, InternalIdentity {
         AutoScalePolicy,
         AutoScaleVmProfile,
         AutoScaleVmGroup,
-        GlobalLoadBalancerRule
+        GlobalLoadBalancerRule,
+        AffinityGroup
     }
 
     long getUserId();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1aed5bf9/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java b/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java
index 501280d..368abe2 100644
--- a/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java
+++ b/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java
@@ -3,6 +3,7 @@ package org.apache.cloudstack.affinity;
 import java.util.List;
 
 import com.cloud.exception.ResourceInUseException;
+import com.cloud.utils.Pair;
 
 public interface AffinityGroupService {
 
@@ -22,7 +23,7 @@ public interface AffinityGroupService {
 
     /**
      * Creates an affinity/anti-affinity group.
-     * 
+     *
      * @param affinityGroupId
      * @param account
      * @param domainId
@@ -32,19 +33,19 @@ public interface AffinityGroupService {
     boolean deleteAffinityGroup(Long affinityGroupId, String account, Long domainId, String affinityGroupName)
             throws ResourceInUseException;
 
-    /**
-     * Lists Affinity Groups
-     *
+    /** Lists Affinity Groups in your account
      * @param account
      * @param domainId
      * @param affinityGroupId
      * @param affinityGroupName
      * @param affinityGroupType
      * @param vmId
+     * @param startIndex
+     * @param pageSize
      * @return
      */
-    List<AffinityGroup> listAffinityGroups(String account, Long domainId, Long affinityGroupId,
-            String affinityGroupName, String affinityGroupType, Long vmId);
+    Pair<List<? extends AffinityGroup>, Integer> listAffinityGroups(Long affinityGroupId, String affinityGroupName,
+            String affinityGroupType, Long vmId, Long startIndex, Long pageSize);
 
 
     /**
@@ -54,4 +55,6 @@ public interface AffinityGroupService {
      */
     List<String> listAffinityGroupTypes();
 
+    AffinityGroup getAffinityGroup(Long groupId);
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1aed5bf9/api/src/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java
index c38bcff..b465214 100644
--- a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java
@@ -21,17 +21,20 @@ import org.apache.cloudstack.affinity.AffinityGroupResponse;
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.ApiErrorCode;
-import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.BaseAsyncCreateCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.DomainResponse;
 import org.apache.log4j.Logger;
 
+import com.cloud.async.AsyncJob;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ResourceAllocationException;
 import com.cloud.user.Account;
 import com.cloud.user.UserContext;
 
 @APICommand(name = "createAffinityGroup", responseObject = AffinityGroupResponse.class, description = "Creates an affinity/anti-affinity group")
-public class CreateAffinityGroupCmd extends BaseCmd {
+public class CreateAffinityGroupCmd extends BaseAsyncCreateCmd {
     public static final Logger s_logger = Logger.getLogger(CreateAffinityGroupCmd.class.getName());
 
     private static final String s_name = "createaffinitygroupresponse";
@@ -112,8 +115,7 @@ public class CreateAffinityGroupCmd extends BaseCmd {
 
     @Override
     public void execute() {
-        AffinityGroup group = _affinityGroupService.createAffinityGroup(accountName, domainId, affinityGroupName,
-                affinityGroupType, description);
+        AffinityGroup group = _affinityGroupService.getAffinityGroup(getEntityId());
         if (group != null) {
             AffinityGroupResponse response = _responseGenerator.createAffinityGroupResponse(group);
             response.setResponseName(getCommandName());
@@ -123,4 +125,43 @@ public class CreateAffinityGroupCmd extends BaseCmd {
                     + affinityGroupName);
         }
     }
+
+    @Override
+    public void create() throws ResourceAllocationException {
+        AffinityGroup result = _affinityGroupService.createAffinityGroup(accountName, domainId, affinityGroupName,
+                affinityGroupType, description);
+        if (result != null) {
+            setEntityId(result.getId());
+            setEntityUuid(result.getUuid());
+        } else {
+            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create affinity group entity" + affinityGroupName);
+        }
+
+    }
+
+    @Override
+    public String getEventType() {
+        return EventTypes.EVENT_AFFINITY_GROUP_CREATE;
+    }
+
+    @Override
+    public String getEventDescription() {
+        return "creating Affinity Group";
+    }
+
+    @Override
+    public String getCreateEventType() {
+        return EventTypes.EVENT_AFFINITY_GROUP_CREATE;
+    }
+
+    @Override
+    public String getCreateEventDescription() {
+        return "creating Affinity Group";
+    }
+
+    @Override
+    public AsyncJob.Type getInstanceType() {
+        return AsyncJob.Type.AffinityGroup;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1aed5bf9/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java
index 8ace2e5..4ceba29 100644
--- a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java
@@ -20,20 +20,22 @@ import org.apache.cloudstack.affinity.AffinityGroupResponse;
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.ApiErrorCode;
-import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.DomainResponse;
 import org.apache.cloudstack.api.response.SuccessResponse;
 import org.apache.log4j.Logger;
 
+import com.cloud.async.AsyncJob;
+import com.cloud.event.EventTypes;
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.ResourceInUseException;
 import com.cloud.user.Account;
 import com.cloud.user.UserContext;
 
 @APICommand(name = "deleteAffinityGroup", description = "Deletes affinity group", responseObject = SuccessResponse.class)
-public class DeleteAffinityGroupCmd extends BaseCmd {
+public class DeleteAffinityGroupCmd extends BaseAsyncCmd {
     public static final Logger s_logger = Logger.getLogger(DeleteAffinityGroupCmd.class.getName());
     private static final String s_name = "deleteaffinitygroupresponse";
 
@@ -134,4 +136,19 @@ public class DeleteAffinityGroupCmd extends BaseCmd {
             throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, ex.getMessage());
         }
     }
+
+    @Override
+    public String getEventType() {
+        return EventTypes.EVENT_AFFINITY_GROUP_DELETE;
+    }
+
+    @Override
+    public String getEventDescription() {
+        return "Deleting Affinity Group";
+    }
+
+    @Override
+    public AsyncJob.Type getInstanceType() {
+        return AsyncJob.Type.AffinityGroup;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1aed5bf9/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java
new file mode 100644
index 0000000..09d1f8f
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java
@@ -0,0 +1,107 @@
+// 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 org.apache.cloudstack.api.command.user.affinitygroup;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.cloudstack.affinity.AffinityGroup;
+import org.apache.cloudstack.affinity.AffinityGroupResponse;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseListCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.UserVmResponse;
+import org.apache.log4j.Logger;
+
+import com.cloud.async.AsyncJob;
+import com.cloud.utils.Pair;
+
+@APICommand(name = "listAffinityGroups", description = "Lists affinity groups", responseObject = AffinityGroupResponse.class)
+public class ListAffinityGroupsCmd extends BaseListCmd {
+    public static final Logger s_logger = Logger.getLogger(ListAffinityGroupsCmd.class.getName());
+
+    private static final String s_name = "listaffinitygroupsresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "lists affinity groups by name")
+    private String affinityGroupName;
+
+    @Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, type = CommandType.UUID, description = "lists affinity groups by virtual machine id", entityType = UserVmResponse.class)
+    private Long virtualMachineId;
+
+    @Parameter(name = ApiConstants.ID, type = CommandType.UUID, description = "list the affinity group by the id provided", entityType = AffinityGroupResponse.class)
+    private Long id;
+
+    @Parameter(name = ApiConstants.TYPE, type = CommandType.STRING, description = "lists affinity groups by type")
+    private String affinityGroupType;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+    public String getAffinityGroupName() {
+        return affinityGroupName;
+    }
+
+    public Long getVirtualMachineId() {
+        return virtualMachineId;
+    }
+
+    public Long getId(){
+        return id;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public void execute(){
+
+        Pair<List<AffinityGroup>, Integer> result = _affinityGroupService.listAffinityGroups(id, affinityGroupName,
+                affinityGroupType, virtualMachineId, this.getStartIndex(), this.getPageSizeVal());
+        if (result != null) {
+            ListResponse<AffinityGroupResponse> response = new ListResponse<AffinityGroupResponse>();
+            List<AffinityGroupResponse> groupResponses = new ArrayList<AffinityGroupResponse>();
+            for (AffinityGroup group : result.first()) {
+                AffinityGroupResponse groupResponse = _responseGenerator.createAffinityGroupResponse(group);
+                groupResponses.add(groupResponse);
+            }
+            response.setResponses(groupResponses, result.second());
+            response.setResponseName(getCommandName());
+            this.setResponseObject(response);
+        } else {
+            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to search for affinity groups");
+        }
+    }
+
+    @Override
+    public AsyncJob.Type getInstanceType() {
+        return AsyncJob.Type.AffinityGroup;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1aed5bf9/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
index f3b166f..994f225 100644
--- a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
+++ b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
@@ -1,5 +1,6 @@
 package org.apache.cloudstack.affinity;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -12,10 +13,13 @@ import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
 import org.apache.log4j.Logger;
 
 
+import com.cloud.api.query.vo.SecurityGroupJoinVO;
 import com.cloud.event.ActionEvent;
 import com.cloud.event.EventTypes;
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.ResourceInUseException;
+import com.cloud.network.PhysicalNetwork;
+import com.cloud.network.dao.PhysicalNetworkVO;
 import com.cloud.network.security.SecurityGroupManager;
 import com.cloud.network.security.SecurityGroupRuleVO;
 import com.cloud.network.security.SecurityGroupVMMapVO;
@@ -23,10 +27,19 @@ import com.cloud.network.security.SecurityGroupVO;
 import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
 import com.cloud.user.UserContext;
+import com.cloud.utils.Pair;
 import com.cloud.utils.component.Manager;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.db.DB;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.JoinBuilder.JoinType;
+import com.cloud.utils.db.JoinBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.Transaction;
+import com.cloud.vm.UserVmVO;
+import com.cloud.vm.VMInstanceVO;
+import com.cloud.vm.dao.UserVmDao;
 
 @Local(value = { AffinityGroupService.class })
 public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGroupService, Manager {
@@ -43,6 +56,9 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
     @Inject
     AffinityGroupVMMapDao _affinityGroupVMMapDao;
 
+    @Inject
+    private UserVmDao _userVmDao;
+
     @Override
     public AffinityGroup createAffinityGroup(String account, Long domainId, String affinityGroupName,
             String affinityGroupType, String description) {
@@ -120,12 +136,59 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
     }
 
     @Override
-    public List<AffinityGroup> listAffinityGroups(String account, Long domainId, Long affinityGroupId,
-            String affinityGroupName, String affinityGroupType, Long vmId) {
-        // TODO Auto-generated method stub
-        return null;
+    public Pair<List<? extends AffinityGroup>, Integer> listAffinityGroups(Long affinityGroupId, String affinityGroupName, String affinityGroupType, Long vmId, Long startIndex, Long pageSize) {
+        Filter searchFilter = new Filter(AffinityGroupVO.class, "id", Boolean.TRUE, startIndex, pageSize);
+
+        Account caller = UserContext.current().getCaller();
+
+        Long accountId = caller.getAccountId();
+        Long domainId = caller.getDomainId();
+
+        SearchBuilder<AffinityGroupVMMapVO> vmInstanceSearch = _affinityGroupVMMapDao.createSearchBuilder();
+        vmInstanceSearch.and("instanceId", vmInstanceSearch.entity().getInstanceId(), SearchCriteria.Op.EQ);
+
+        SearchBuilder<AffinityGroupVO> groupSearch = _affinityGroupDao.createSearchBuilder();
+        groupSearch.join("vmInstanceSearch", vmInstanceSearch, groupSearch.entity().getId(), vmInstanceSearch.entity()
+                .getAffinityGroupId(), JoinBuilder.JoinType.INNER);
+
+        SearchCriteria<AffinityGroupVO> sc = groupSearch.create();
+
+        if (accountId != null) {
+            sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+        }
+
+        if (domainId != null) {
+            sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+        }
+
+        if (affinityGroupId != null) {
+            sc.addAnd("id", SearchCriteria.Op.EQ, affinityGroupId);
+        }
+
+        if (affinityGroupName != null) {
+            sc.addAnd("name", SearchCriteria.Op.EQ, affinityGroupName);
+        }
+
+        if (affinityGroupType != null) {
+            sc.addAnd("type", SearchCriteria.Op.EQ, affinityGroupType);
+        }
+
+        if (vmId != null) {
+            UserVmVO userVM = _userVmDao.findById(vmId);
+            if (userVM == null) {
+                throw new InvalidParameterValueException("Unable to list affinity groups for virtual machine instance "
+                        + vmId + "; instance not found.");
+            }
+            _accountMgr.checkAccess(caller, null, true, userVM);
+            // add join to affinity_groups_vm_map
+            sc.setJoinParameters("vmInstanceSearch", "instanceId", vmId);
+        }
+
+        Pair<List<AffinityGroupVO>, Integer> result =  _affinityGroupDao.searchAndCount(sc, searchFilter);
+        return new Pair<List<? extends AffinityGroup>, Integer>(result.first(), result.second());
     }
 
+
     @Override
     public List<String> listAffinityGroupTypes() {
         // TODO Auto-generated method stub
@@ -153,4 +216,9 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
         return _name;
     }
 
+    @Override
+    public AffinityGroup getAffinityGroup(Long groupId) {
+        return _affinityGroupDao.findById(groupId);
+    }
+
 }


[10/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
DAO constructor should be lightweight to make Spring DI faster.


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

Branch: refs/heads/master
Commit: e9300d2676b72875e4de1bdb6c48ae853df99263
Parents: 1ba6740
Author: Prachi Damle <pr...@cloud.com>
Authored: Fri Mar 15 15:06:17 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:22:51 2013 -0700

----------------------------------------------------------------------
 .../affinity/dao/AffinityGroupDaoImpl.java         |    8 +++++++-
 .../affinity/dao/AffinityGroupVMMapDaoImpl.java    |    7 ++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e9300d26/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupDaoImpl.java b/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupDaoImpl.java
index bfa06c7..f7db418 100644
--- a/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupDaoImpl.java
+++ b/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupDaoImpl.java
@@ -18,6 +18,7 @@ package org.apache.cloudstack.affinity.dao;
 
 import java.util.List;
 
+import javax.annotation.PostConstruct;
 import javax.ejb.Local;
 import org.apache.cloudstack.affinity.AffinityGroupVO;
 import org.springframework.stereotype.Component;
@@ -33,7 +34,12 @@ public class AffinityGroupDaoImpl extends GenericDaoBase<AffinityGroupVO, Long>
     private SearchBuilder<AffinityGroupVO> AccountIdNamesSearch;
 
 
-    protected AffinityGroupDaoImpl() {
+    public AffinityGroupDaoImpl() {
+
+    }
+
+    @PostConstruct
+    protected void init() {
         AccountIdSearch = createSearchBuilder();
         AccountIdSearch.and("accountId", AccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
         AccountIdSearch.done();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e9300d26/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java b/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java
index 0fb4e79..ea315ac 100644
--- a/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java
+++ b/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java
@@ -18,6 +18,7 @@ package org.apache.cloudstack.affinity.dao;
 
 import java.util.List;
 
+import javax.annotation.PostConstruct;
 import javax.ejb.Local;
 import javax.inject.Inject;
 
@@ -50,7 +51,11 @@ public class AffinityGroupVMMapDaoImpl extends GenericDaoBase<AffinityGroupVMMap
     @Inject
     protected AffinityGroupDao _affinityGroupDao;
 
-    protected AffinityGroupVMMapDaoImpl() {
+    public AffinityGroupVMMapDaoImpl() {
+    }
+
+    @PostConstruct
+    protected void init() {
         ListVmIdByAffinityGroup = createSearchBuilder(Long.class);
         ListVmIdByAffinityGroup.and("affinityGroupId", ListVmIdByAffinityGroup.entity().getAffinityGroupId(),
                 SearchCriteria.Op.EQ);


[15/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
Fixes after functional tests

Conflicts:

	client/tomcatconf/commands.properties.in


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

Branch: refs/heads/master
Commit: c7c899f62d9eb9d314718ae1e4d4822c3998864b
Parents: bb9bdf0
Author: Prachi Damle <pr...@cloud.com>
Authored: Fri Mar 29 00:17:44 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:23:04 2013 -0700

----------------------------------------------------------------------
 .../cloud/exception/AffinityConflictException.java |    4 +-
 .../affinity/AffinityGroupProcessor.java           |   23 +++-
 .../cloudstack/affinity/AffinityProcessorBase.java |   28 ++++
 .../deploy/UserPreferrenceProcessor.java           |   27 ----
 client/tomcatconf/commands.properties.in           |    1 +
 .../cloud/entity/api/VMEntityManagerImpl.java      |   82 +++++++-----
 .../affinity/HostAntiAffinityProcessor.java        |    8 +-
 server/src/com/cloud/deploy/FirstFitPlanner.java   |   56 +++++----
 .../src/com/cloud/server/ManagementServerImpl.java |  104 ++++-----------
 server/src/com/cloud/vm/UserVmManagerImpl.java     |   14 ++-
 .../com/cloud/vm/VirtualMachineManagerImpl.java    |   39 +++---
 .../affinity/AffinityGroupServiceImpl.java         |   33 ++---
 .../cloudstack/affinity/AffinityGroupVMMapVO.java  |    8 -
 .../affinity/dao/AffinityGroupVMMapDaoImpl.java    |   10 +-
 14 files changed, 201 insertions(+), 236 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c7c899f6/api/src/com/cloud/exception/AffinityConflictException.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/exception/AffinityConflictException.java b/api/src/com/cloud/exception/AffinityConflictException.java
index 75df784..da7148f 100644
--- a/api/src/com/cloud/exception/AffinityConflictException.java
+++ b/api/src/com/cloud/exception/AffinityConflictException.java
@@ -1,9 +1,9 @@
 package com.cloud.exception;
 
-import com.cloud.exception.CloudException;
 import com.cloud.utils.SerialVersionUID;
+import com.cloud.utils.exception.CloudRuntimeException;
 
-public class AffinityConflictException extends CloudException {
+public class AffinityConflictException extends CloudRuntimeException {
 
     private static final long serialVersionUID = SerialVersionUID.AffinityConflictException;
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c7c899f6/api/src/org/apache/cloudstack/affinity/AffinityGroupProcessor.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/affinity/AffinityGroupProcessor.java b/api/src/org/apache/cloudstack/affinity/AffinityGroupProcessor.java
index e6c64b3..9bdd051 100644
--- a/api/src/org/apache/cloudstack/affinity/AffinityGroupProcessor.java
+++ b/api/src/org/apache/cloudstack/affinity/AffinityGroupProcessor.java
@@ -1,8 +1,27 @@
 package org.apache.cloudstack.affinity;
 
-import org.apache.cloudstack.deploy.UserPreferrenceProcessor;
+import com.cloud.deploy.DeploymentPlan;
+import com.cloud.deploy.DeploymentPlanner.ExcludeList;
+import com.cloud.exception.AffinityConflictException;
+import com.cloud.utils.component.Adapter;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.VirtualMachineProfile;
 
-public interface AffinityGroupProcessor extends UserPreferrenceProcessor {
+public interface AffinityGroupProcessor extends Adapter {
+
+    /**
+     * process() is called to apply any user preferences to the deployment plan
+     * and avoid set for the given VM placement.
+     *
+     * @param vm
+     *            virtual machine.
+     * @param plan
+     *            deployment plan that tells you where it's being deployed to.
+     * @param avoid
+     *            avoid these data centers, pods, clusters, or hosts.
+     */
+    void process(VirtualMachineProfile<? extends VirtualMachine> vm, DeploymentPlan plan, ExcludeList avoid)
+            throws AffinityConflictException;
 
     /**
      * getType() should return the affinity/anti-affinity group being

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c7c899f6/api/src/org/apache/cloudstack/affinity/AffinityProcessorBase.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/affinity/AffinityProcessorBase.java b/api/src/org/apache/cloudstack/affinity/AffinityProcessorBase.java
new file mode 100644
index 0000000..74fdde1
--- /dev/null
+++ b/api/src/org/apache/cloudstack/affinity/AffinityProcessorBase.java
@@ -0,0 +1,28 @@
+package org.apache.cloudstack.affinity;
+
+import com.cloud.deploy.DeploymentPlan;
+import com.cloud.deploy.DeploymentPlanner.ExcludeList;
+import com.cloud.exception.AffinityConflictException;
+import com.cloud.utils.component.AdapterBase;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.VirtualMachineProfile;
+
+public class AffinityProcessorBase extends AdapterBase implements AffinityGroupProcessor {
+
+    protected String _type;
+
+    @Override
+    public void process(VirtualMachineProfile<? extends VirtualMachine> vm, DeploymentPlan plan, ExcludeList avoid)
+            throws AffinityConflictException {
+
+    }
+
+    @Override
+    public String getType() {
+        return _type;
+    }
+
+    public void setType(String type) {
+        _type = type;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c7c899f6/api/src/org/apache/cloudstack/deploy/UserPreferrenceProcessor.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/deploy/UserPreferrenceProcessor.java b/api/src/org/apache/cloudstack/deploy/UserPreferrenceProcessor.java
deleted file mode 100644
index ad26f0e..0000000
--- a/api/src/org/apache/cloudstack/deploy/UserPreferrenceProcessor.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package org.apache.cloudstack.deploy;
-
-
-import com.cloud.deploy.DeploymentPlan;
-import com.cloud.deploy.DeploymentPlanner.ExcludeList;
-import com.cloud.exception.AffinityConflictException;
-import com.cloud.utils.component.Adapter;
-import com.cloud.vm.VirtualMachine;
-import com.cloud.vm.VirtualMachineProfile;
-
-public interface UserPreferrenceProcessor extends Adapter {
-
-    /**
-     * process() is called to apply any user preferences to the deployment plan
-     * and avoid set for the given VM placement.
-     *
-     * @param vm
-     *            virtual machine.
-     * @param plan
-     *            deployment plan that tells you where it's being deployed to.
-     * @param avoid
-     *            avoid these data centers, pods, clusters, or hosts.
-     */
-    void process(VirtualMachineProfile<? extends VirtualMachine> vm, DeploymentPlan plan, ExcludeList avoid)
-            throws AffinityConflictException;
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c7c899f6/client/tomcatconf/commands.properties.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in
index 55fa599..4ce9fd3 100644
--- a/client/tomcatconf/commands.properties.in
+++ b/client/tomcatconf/commands.properties.in
@@ -574,3 +574,4 @@ createAffinityGroup=15
 deleteAffinityGroup=15
 listAffinityGroups=15
 updateVMAffinityGroup=15
+listAffinityGroupTypes=15

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c7c899f6/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java
index 0359db9..ec813b2 100755
--- a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java
@@ -36,7 +36,9 @@ import com.cloud.deploy.DataCenterDeployment;
 import com.cloud.deploy.DeployDestination;
 import com.cloud.deploy.DeploymentPlan;
 import com.cloud.deploy.DeploymentPlanner;
+import com.cloud.deploy.DeploymentPlanningManager;
 import com.cloud.deploy.DeploymentPlanner.ExcludeList;
+import com.cloud.exception.AffinityConflictException;
 import com.cloud.exception.AgentUnavailableException;
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.InsufficientCapacityException;
@@ -55,7 +57,7 @@ import com.cloud.storage.dao.VMTemplateDao;
 import com.cloud.storage.dao.VolumeDao;
 import com.cloud.user.dao.AccountDao;
 import com.cloud.user.dao.UserDao;
-import com.cloud.utils.component.ComponentContext;
+import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.vm.VMInstanceVO;
 import com.cloud.vm.VirtualMachineManager;
 import com.cloud.vm.VirtualMachineProfile;
@@ -69,42 +71,45 @@ public class VMEntityManagerImpl implements VMEntityManager {
     protected VMInstanceDao _vmDao;
     @Inject
     protected VMTemplateDao _templateDao = null;
-    
+
     @Inject
     protected ServiceOfferingDao _serviceOfferingDao;
-    
+
     @Inject
     protected DiskOfferingDao _diskOfferingDao = null;
-    
+
     @Inject
     protected NetworkDao _networkDao;
-    
+
     @Inject
     protected AccountDao _accountDao = null;
 
     @Inject
     protected UserDao _userDao = null;
 
-    @Inject 
+    @Inject
     protected VMEntityDao _vmEntityDao;
-    
-    @Inject 
+
+    @Inject
     protected VMReservationDao _reservationDao;
-    
+
     @Inject
     protected VirtualMachineManager _itMgr;
-    
+
     @Inject
     protected List<DeploymentPlanner> _planners;
-    
+
     @Inject
     protected VolumeDao _volsDao;
-    
+
     @Inject
     protected PrimaryDataStoreDao _storagePoolDao;
     @Inject
     DataStoreManager dataStoreMgr;
-    
+
+    @Inject
+    DeploymentPlanningManager _dpMgr;
+
 	@Override
 	public VMEntityVO loadVirtualMachine(String vmId) {
 		// TODO Auto-generated method stub
@@ -114,11 +119,11 @@ public class VMEntityManagerImpl implements VMEntityManager {
 	@Override
 	public void saveVirtualMachine(VMEntityVO entity) {
 	    _vmEntityDao.persist(entity);
-		
+
 	}
 
     @Override
-    public String reserveVirtualMachine(VMEntityVO vmEntityVO, String plannerToUse, DeploymentPlan planToDeploy, ExcludeList exclude) 
+    public String reserveVirtualMachine(VMEntityVO vmEntityVO, String plannerToUse, DeploymentPlan planToDeploy, ExcludeList exclude)
             throws InsufficientCapacityException, ResourceUnavailableException {
 
         //call planner and get the deployDestination.
@@ -130,12 +135,12 @@ public class VMEntityManagerImpl implements VMEntityManager {
         if(planToDeploy != null && planToDeploy.getDataCenterId() != 0){
             plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), planToDeploy.getPoolId(), planToDeploy.getPhysicalNetworkId());
         }
-        
+
         List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
         if(!vols.isEmpty()){
             VolumeVO vol = vols.get(0);
             StoragePool pool = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(vol.getPoolId());
-            
+
             if (!pool.isInMaintenance()) {
                 long rootVolDcId = pool.getDataCenterId();
                 Long rootVolPodId = pool.getPodId();
@@ -156,21 +161,21 @@ public class VMEntityManagerImpl implements VMEntityManager {
 
                 }
             }
-        
+
+        }
+
+        DeployDestination dest;
+        try {
+            dest = _dpMgr.planDeployment(vmProfile, plan, exclude);
+        } catch (AffinityConflictException e) {
+            throw new CloudRuntimeException("Unable to create deployment, affinity rules associted to the VM conflict");
         }
-        
-        DeploymentPlanner planner = ComponentContext.getComponent(plannerToUse);
-        DeployDestination dest = null;
-        
-        if (planner.canHandle(vmProfile, plan, exclude)) {
-            dest = planner.plan(vmProfile, plan, exclude);
-        } 
 
         if (dest != null) {
            //save destination with VMEntityVO
             VMReservationVO vmReservation = new VMReservationVO(vm.getId(), dest.getDataCenter().getId(), dest.getPod().getId(), dest.getCluster().getId(), dest.getHost().getId());
             Map<Long,Long> volumeReservationMap = new HashMap<Long,Long>();
-            
+
             if (vm.getHypervisorType() != HypervisorType.BareMetal) {
                 for(Volume vo : dest.getStorageForDisks().keySet()){
                     volumeReservationMap.put(vo.getId(), dest.getStorageForDisks().get(vo).getId());
@@ -180,21 +185,21 @@ public class VMEntityManagerImpl implements VMEntityManager {
 
             vmEntityVO.setVmReservation(vmReservation);
             _vmEntityDao.persist(vmEntityVO);
-            
+
             return vmReservation.getUuid();
         }else{
             throw new InsufficientServerCapacityException("Unable to create a deployment for " + vmProfile, DataCenter.class, plan.getDataCenterId());
         }
-        
+
     }
 
     @Override
     public void deployVirtualMachine(String reservationId, String caller, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ResourceUnavailableException{
         //grab the VM Id and destination using the reservationId.
-        
+
         VMReservationVO vmReservation = _reservationDao.findByReservationId(reservationId);
         long vmId = vmReservation.getVmId();
-        
+
         VMInstanceVO vm = _vmDao.findById(vmId);
         //Pass it down
         Long poolId = null;
@@ -205,12 +210,17 @@ public class VMEntityManagerImpl implements VMEntityManager {
                 poolId = storage.get(volIdList.get(0));
             }
         }
-        
-        DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), vmReservation.getPodId(), vmReservation.getClusterId(),
+
+        DataCenterDeployment reservedPlan = new DataCenterDeployment(vm.getDataCenterId(), vmReservation.getPodId(), vmReservation.getClusterId(),
                 vmReservation.getHostId(), null , null);
-        
-        VMInstanceVO vmDeployed = _itMgr.start(vm, params, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()), plan);
-        
+        try{
+            VMInstanceVO vmDeployed = _itMgr.start(vm, params, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()), reservedPlan);
+        }catch(Exception ex){
+            //Retry the deployment without using the reservation plan
+            DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), null, null,null, null , null);
+            _itMgr.start(vm, params, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()), plan);
+        }
+
     }
 
     @Override
@@ -227,7 +237,7 @@ public class VMEntityManagerImpl implements VMEntityManager {
          VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
          return _itMgr.destroy(vm, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()));
 
-            
+
     }
 
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c7c899f6/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
----------------------------------------------------------------------
diff --git a/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java b/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
index 11b391b..88030f2 100644
--- a/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
+++ b/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
@@ -28,7 +28,6 @@ import org.apache.log4j.Logger;
 import com.cloud.deploy.DeploymentPlan;
 import com.cloud.deploy.DeploymentPlanner.ExcludeList;
 import com.cloud.exception.AffinityConflictException;
-import com.cloud.utils.component.AdapterBase;
 import com.cloud.vm.VMInstanceVO;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachineProfile;
@@ -36,7 +35,7 @@ import com.cloud.vm.dao.UserVmDao;
 import com.cloud.vm.dao.VMInstanceDao;
 
 @Local(value = AffinityGroupProcessor.class)
-public class HostAntiAffinityProcessor extends AdapterBase implements AffinityGroupProcessor {
+public class HostAntiAffinityProcessor extends AffinityProcessorBase implements AffinityGroupProcessor {
 
     private static final Logger s_logger = Logger.getLogger(HostAntiAffinityProcessor.class);
     @Inject
@@ -74,9 +73,4 @@ public class HostAntiAffinityProcessor extends AdapterBase implements AffinityGr
 
     }
 
-    @Override
-    public String getType() {
-        return "HostAntiAffinity";
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c7c899f6/server/src/com/cloud/deploy/FirstFitPlanner.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/deploy/FirstFitPlanner.java b/server/src/com/cloud/deploy/FirstFitPlanner.java
index 2dffe70..1647cf7 100755
--- a/server/src/com/cloud/deploy/FirstFitPlanner.java
+++ b/server/src/com/cloud/deploy/FirstFitPlanner.java
@@ -161,38 +161,44 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
                         + hostIdSpecified);
             }
             HostVO host = _hostDao.findById(hostIdSpecified);
-            if (s_logger.isDebugEnabled()) {
-                if(host == null){
-                    s_logger.debug("The specified host cannot be found");
-                }else{
+            if (host == null) {
+                s_logger.debug("The specified host cannot be found");
+            } else if (avoid.shouldAvoid(host)) {
+                s_logger.debug("The specified host is in avoid set");
+            } else {
+                if (s_logger.isDebugEnabled()) {
                     s_logger.debug("Looking for suitable pools for this host under zone: "+host.getDataCenterId() +", pod: "+ host.getPodId()+", cluster: "+ host.getClusterId());
                 }
-            }
 
-            //search for storage under the zone, pod, cluster of the host.
-            DataCenterDeployment lastPlan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), hostIdSpecified, plan.getPoolId(), null, plan.getReservationContext());
+                // search for storage under the zone, pod, cluster of the host.
+                DataCenterDeployment lastPlan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(),
+                        host.getClusterId(), hostIdSpecified, plan.getPoolId(), null, plan.getReservationContext());
 
-            Pair<Map<Volume, List<StoragePool>>, List<Volume>> result = findSuitablePoolsForVolumes(vmProfile, lastPlan, avoid, HostAllocator.RETURN_UPTO_ALL);
-            Map<Volume, List<StoragePool>> suitableVolumeStoragePools = result.first();
-            List<Volume> readyAndReusedVolumes = result.second();
+                Pair<Map<Volume, List<StoragePool>>, List<Volume>> result = findSuitablePoolsForVolumes(vmProfile,
+                        lastPlan, avoid, HostAllocator.RETURN_UPTO_ALL);
+                Map<Volume, List<StoragePool>> suitableVolumeStoragePools = result.first();
+                List<Volume> readyAndReusedVolumes = result.second();
 
-            //choose the potential pool for this VM for this host
-            if(!suitableVolumeStoragePools.isEmpty()){
-                List<Host> suitableHosts = new ArrayList<Host>();
-                suitableHosts.add(host);
+                // choose the potential pool for this VM for this host
+                if (!suitableVolumeStoragePools.isEmpty()) {
+                    List<Host> suitableHosts = new ArrayList<Host>();
+                    suitableHosts.add(host);
 
-                Pair<Host, Map<Volume, StoragePool>> potentialResources = findPotentialDeploymentResources(suitableHosts, suitableVolumeStoragePools);
-                if(potentialResources != null){
-                    Pod pod = _podDao.findById(host.getPodId());
-                    Cluster cluster = _clusterDao.findById(host.getClusterId());
-                    Map<Volume, StoragePool> storageVolMap = potentialResources.second();
-                    // remove the reused vol<->pool from destination, since we don't have to prepare this volume.
-                    for(Volume vol : readyAndReusedVolumes){
-                        storageVolMap.remove(vol);
+                    Pair<Host, Map<Volume, StoragePool>> potentialResources = findPotentialDeploymentResources(
+                            suitableHosts, suitableVolumeStoragePools);
+                    if (potentialResources != null) {
+                        Pod pod = _podDao.findById(host.getPodId());
+                        Cluster cluster = _clusterDao.findById(host.getClusterId());
+                        Map<Volume, StoragePool> storageVolMap = potentialResources.second();
+                        // remove the reused vol<->pool from destination, since
+                        // we don't have to prepare this volume.
+                        for (Volume vol : readyAndReusedVolumes) {
+                            storageVolMap.remove(vol);
+                        }
+                        DeployDestination dest = new DeployDestination(dc, pod, cluster, host, storageVolMap);
+                        s_logger.debug("Returning Deployment Destination: " + dest);
+                        return dest;
                     }
-                    DeployDestination dest =  new DeployDestination(dc, pod, cluster, host, storageVolMap);
-                    s_logger.debug("Returning Deployment Destination: "+ dest);
-                    return dest;
                 }
             }
             s_logger.debug("Cannnot deploy to specified host, returning.");

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c7c899f6/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java
index 01798cc..b869d1e 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -37,14 +37,9 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 
-import javax.annotation.PostConstruct;
 import javax.crypto.Mac;
 import javax.crypto.spec.SecretKeySpec;
 import javax.inject.Inject;
-import javax.management.InstanceAlreadyExistsException;
-import javax.management.MBeanRegistrationException;
-import javax.management.MalformedObjectNameException;
-import javax.management.NotCompliantMBeanException;
 import javax.naming.ConfigurationException;
 
 import com.cloud.storage.dao.*;
@@ -54,59 +49,43 @@ import org.apache.cloudstack.api.ApiConstants;
 import com.cloud.event.ActionEventUtils;
 import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoCmd;
 import org.apache.cloudstack.api.command.admin.account.*;
-import org.apache.cloudstack.api.command.admin.autoscale.*;
-import org.apache.cloudstack.api.command.admin.cluster.*;
-import org.apache.cloudstack.api.command.admin.config.*;
 import org.apache.cloudstack.api.command.admin.domain.*;
 import org.apache.cloudstack.api.command.admin.host.*;
-import org.apache.cloudstack.api.command.admin.ldap.*;
 import org.apache.cloudstack.api.command.admin.network.*;
 import org.apache.cloudstack.api.command.admin.offering.*;
-import org.apache.cloudstack.api.command.admin.pod.*;
-import org.apache.cloudstack.api.command.admin.region.*;
 import org.apache.cloudstack.api.command.admin.resource.*;
 import org.apache.cloudstack.api.command.admin.router.*;
 import org.apache.cloudstack.api.command.admin.storage.*;
-import org.apache.cloudstack.api.command.admin.swift.*;
 import org.apache.cloudstack.api.command.admin.systemvm.*;
-import org.apache.cloudstack.api.command.admin.template.*;
 import org.apache.cloudstack.api.command.admin.usage.*;
 import org.apache.cloudstack.api.command.admin.user.*;
-import org.apache.cloudstack.api.command.admin.vlan.*;
-import org.apache.cloudstack.api.command.admin.vm.*;
 import org.apache.cloudstack.api.command.admin.vpc.*;
-import org.apache.cloudstack.api.command.admin.zone.*;
-import org.apache.cloudstack.api.command.user.account.*;
-import org.apache.cloudstack.api.command.user.address.*;
 import org.apache.cloudstack.api.command.user.autoscale.*;
-import org.apache.cloudstack.api.command.user.config.*;
-import org.apache.cloudstack.api.command.user.event.*;
 import org.apache.cloudstack.api.command.user.firewall.*;
-import org.apache.cloudstack.api.command.user.guest.*;
 import org.apache.cloudstack.api.command.user.iso.*;
-import org.apache.cloudstack.api.command.user.job.*;
 import org.apache.cloudstack.api.command.user.loadbalancer.*;
 import org.apache.cloudstack.api.command.user.nat.*;
 import org.apache.cloudstack.api.command.user.network.*;
-import org.apache.cloudstack.api.command.user.offering.*;
 import org.apache.cloudstack.api.command.user.project.*;
-import org.apache.cloudstack.api.command.user.region.*;
 import org.apache.cloudstack.api.command.user.resource.*;
 import org.apache.cloudstack.api.command.user.securitygroup.*;
 import org.apache.cloudstack.api.command.user.snapshot.*;
-import org.apache.cloudstack.api.command.user.ssh.*;
-import org.apache.cloudstack.api.command.user.tag.*;
 import org.apache.cloudstack.api.command.user.template.*;
 import org.apache.cloudstack.api.command.user.vm.*;
-import org.apache.cloudstack.api.command.user.vmgroup.*;
 import org.apache.cloudstack.api.command.user.volume.*;
 import org.apache.cloudstack.api.command.user.vpc.*;
 import org.apache.cloudstack.api.command.user.vpn.*;
-import org.apache.cloudstack.api.command.user.zone.*;
 import org.apache.cloudstack.api.response.ExtractResponse;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
+import org.apache.cloudstack.affinity.AffinityGroupProcessor;
+import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
+
+import org.apache.cloudstack.api.command.user.affinitygroup.CreateAffinityGroupCmd;
+import org.apache.cloudstack.api.command.user.affinitygroup.DeleteAffinityGroupCmd;
+import org.apache.cloudstack.api.command.user.affinitygroup.ListAffinityGroupTypesCmd;
+import org.apache.cloudstack.api.command.user.affinitygroup.ListAffinityGroupsCmd;
+import org.apache.cloudstack.api.command.user.affinitygroup.UpdateVMAffinityGroupCmd;
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.api.GetVncPortAnswer;
 import com.cloud.agent.api.GetVncPortCommand;
@@ -140,7 +119,6 @@ import com.cloud.deploy.DeploymentPlanner.ExcludeList;
 import com.cloud.domain.DomainVO;
 import com.cloud.domain.dao.DomainDao;
 import com.cloud.event.ActionEvent;
-import com.cloud.event.ActionEventUtils;
 import com.cloud.event.EventTypes;
 import com.cloud.event.EventVO;
 import com.cloud.event.dao.EventDao;
@@ -175,7 +153,6 @@ import com.cloud.service.dao.ServiceOfferingDao;
 import com.cloud.storage.*;
 import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.storage.Upload.Mode;
-import com.cloud.storage.dao.*;
 import com.cloud.storage.s3.S3Manager;
 import com.cloud.storage.secondary.SecondaryStorageVmManager;
 import com.cloud.storage.snapshot.SnapshotManager;
@@ -193,11 +170,7 @@ import com.cloud.utils.EnumUtils;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.Pair;
 import com.cloud.utils.PasswordGenerator;
-import com.cloud.utils.ReflectUtil;
 import com.cloud.utils.Ternary;
-import com.cloud.utils.component.Adapter;
-import com.cloud.utils.component.AdapterBase;
-import com.cloud.utils.component.ComponentContext;
 import com.cloud.utils.component.ComponentLifecycle;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.concurrency.NamedThreadFactory;
@@ -214,10 +187,6 @@ import com.cloud.vm.dao.*;
 import edu.emory.mathcs.backport.java.util.Arrays;
 import edu.emory.mathcs.backport.java.util.Collections;
 import org.apache.cloudstack.acl.ControlledEntity;
-import org.apache.cloudstack.acl.SecurityChecker.AccessType;
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoCmd;
-import org.apache.cloudstack.api.command.admin.account.*;
 import org.apache.cloudstack.api.command.admin.autoscale.CreateCounterCmd;
 import org.apache.cloudstack.api.command.admin.autoscale.DeleteCounterCmd;
 import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd;
@@ -228,12 +197,8 @@ import org.apache.cloudstack.api.command.admin.config.ListCfgsByCmd;
 import org.apache.cloudstack.api.command.admin.config.ListHypervisorCapabilitiesCmd;
 import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd;
 import org.apache.cloudstack.api.command.admin.config.UpdateHypervisorCapabilitiesCmd;
-import org.apache.cloudstack.api.command.admin.domain.*;
-import org.apache.cloudstack.api.command.admin.host.*;
 import org.apache.cloudstack.api.command.admin.ldap.LDAPConfigCmd;
 import org.apache.cloudstack.api.command.admin.ldap.LDAPRemoveCmd;
-import org.apache.cloudstack.api.command.admin.network.*;
-import org.apache.cloudstack.api.command.admin.offering.*;
 import org.apache.cloudstack.api.command.admin.pod.CreatePodCmd;
 import org.apache.cloudstack.api.command.admin.pod.DeletePodCmd;
 import org.apache.cloudstack.api.command.admin.pod.ListPodsByCmd;
@@ -241,22 +206,15 @@ import org.apache.cloudstack.api.command.admin.pod.UpdatePodCmd;
 import org.apache.cloudstack.api.command.admin.region.AddRegionCmd;
 import org.apache.cloudstack.api.command.admin.region.RemoveRegionCmd;
 import org.apache.cloudstack.api.command.admin.region.UpdateRegionCmd;
-import org.apache.cloudstack.api.command.admin.resource.*;
-import org.apache.cloudstack.api.command.admin.router.*;
-import org.apache.cloudstack.api.command.admin.storage.*;
 import org.apache.cloudstack.api.command.admin.swift.AddSwiftCmd;
 import org.apache.cloudstack.api.command.admin.swift.ListSwiftsCmd;
-import org.apache.cloudstack.api.command.admin.systemvm.*;
 import org.apache.cloudstack.api.command.admin.template.PrepareTemplateCmd;
-import org.apache.cloudstack.api.command.admin.usage.*;
-import org.apache.cloudstack.api.command.admin.user.*;
 import org.apache.cloudstack.api.command.admin.vlan.CreateVlanIpRangeCmd;
 import org.apache.cloudstack.api.command.admin.vlan.DeleteVlanIpRangeCmd;
 import org.apache.cloudstack.api.command.admin.vlan.ListVlanIpRangesCmd;
 import org.apache.cloudstack.api.command.admin.vm.AssignVMCmd;
 import org.apache.cloudstack.api.command.admin.vm.MigrateVMCmd;
 import org.apache.cloudstack.api.command.admin.vm.RecoverVMCmd;
-import org.apache.cloudstack.api.command.admin.vpc.*;
 import org.apache.cloudstack.api.command.admin.zone.CreateZoneCmd;
 import org.apache.cloudstack.api.command.admin.zone.DeleteZoneCmd;
 import org.apache.cloudstack.api.command.admin.zone.MarkDefaultZoneForAccountCmd;
@@ -268,29 +226,19 @@ import org.apache.cloudstack.api.command.user.account.ListProjectAccountsCmd;
 import org.apache.cloudstack.api.command.user.address.AssociateIPAddrCmd;
 import org.apache.cloudstack.api.command.user.address.DisassociateIPAddrCmd;
 import org.apache.cloudstack.api.command.user.address.ListPublicIpAddressesCmd;
-import org.apache.cloudstack.api.command.user.autoscale.*;
 import org.apache.cloudstack.api.command.user.config.ListCapabilitiesCmd;
 import org.apache.cloudstack.api.command.user.event.ArchiveEventsCmd;
 import org.apache.cloudstack.api.command.user.event.DeleteEventsCmd;
 import org.apache.cloudstack.api.command.user.event.ListEventTypesCmd;
 import org.apache.cloudstack.api.command.user.event.ListEventsCmd;
-import org.apache.cloudstack.api.command.user.firewall.*;
 import org.apache.cloudstack.api.command.user.guest.ListGuestOsCategoriesCmd;
 import org.apache.cloudstack.api.command.user.guest.ListGuestOsCmd;
-import org.apache.cloudstack.api.command.user.iso.*;
 import org.apache.cloudstack.api.command.user.job.ListAsyncJobsCmd;
 import org.apache.cloudstack.api.command.user.job.QueryAsyncJobResultCmd;
-import org.apache.cloudstack.api.command.user.loadbalancer.*;
-import org.apache.cloudstack.api.command.user.nat.*;
-import org.apache.cloudstack.api.command.user.network.*;
 import org.apache.cloudstack.api.command.user.offering.ListDiskOfferingsCmd;
 import org.apache.cloudstack.api.command.user.offering.ListServiceOfferingsCmd;
-import org.apache.cloudstack.api.command.user.project.*;
 import org.apache.cloudstack.api.command.user.region.ListRegionsCmd;
 import org.apache.cloudstack.api.command.user.region.ha.gslb.*;
-import org.apache.cloudstack.api.command.user.resource.*;
-import org.apache.cloudstack.api.command.user.securitygroup.*;
-import org.apache.cloudstack.api.command.user.snapshot.*;
 import org.apache.cloudstack.api.command.user.ssh.CreateSSHKeyPairCmd;
 import org.apache.cloudstack.api.command.user.ssh.DeleteSSHKeyPairCmd;
 import org.apache.cloudstack.api.command.user.ssh.ListSSHKeyPairsCmd;
@@ -298,8 +246,6 @@ import org.apache.cloudstack.api.command.user.ssh.RegisterSSHKeyPairCmd;
 import org.apache.cloudstack.api.command.user.tag.CreateTagsCmd;
 import org.apache.cloudstack.api.command.user.tag.DeleteTagsCmd;
 import org.apache.cloudstack.api.command.user.tag.ListTagsCmd;
-import org.apache.cloudstack.api.command.user.template.*;
-import org.apache.cloudstack.api.command.user.vm.*;
 import org.apache.cloudstack.api.command.user.vmgroup.CreateVMGroupCmd;
 import org.apache.cloudstack.api.command.user.vmgroup.DeleteVMGroupCmd;
 import org.apache.cloudstack.api.command.user.vmgroup.ListVMGroupsCmd;
@@ -308,27 +254,10 @@ import org.apache.cloudstack.api.command.user.vmsnapshot.CreateVMSnapshotCmd;
 import org.apache.cloudstack.api.command.user.vmsnapshot.DeleteVMSnapshotCmd;
 import org.apache.cloudstack.api.command.user.vmsnapshot.ListVMSnapshotCmd;
 import org.apache.cloudstack.api.command.user.vmsnapshot.RevertToSnapshotCmd;
-import org.apache.cloudstack.api.command.user.volume.*;
-import org.apache.cloudstack.api.command.user.vpc.*;
-import org.apache.cloudstack.api.command.user.vpn.*;
 import org.apache.cloudstack.api.command.user.zone.ListZonesByCmd;
-import org.apache.cloudstack.api.response.ExtractResponse;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.log4j.Logger;
-
-import javax.crypto.Mac;
-import javax.crypto.spec.SecretKeySpec;
-import javax.inject.Inject;
-import javax.naming.ConfigurationException;
-import java.lang.reflect.Field;
-import java.net.*;
-import java.util.*;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
 
 public class ManagementServerImpl extends ManagerBase implements ManagementServer {
     public static final Logger s_logger = Logger.getLogger(ManagementServerImpl.class.getName());
@@ -466,6 +395,12 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
     @Inject ClusterManager _clusterMgr;
     private String _hashKey = null;
 
+    @Inject
+    protected AffinityGroupVMMapDao _affinityGroupVMMapDao;
+
+    @Inject
+    protected List<AffinityGroupProcessor> _affinityProcessors;
+
     public ManagementServerImpl() {
     	setRunLevel(ComponentLifecycle.RUN_LEVEL_APPLICATION_MAINLOOP);
     }
@@ -824,6 +759,15 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
         ExcludeList excludes = new ExcludeList();
         excludes.addHost(srcHostId);
 
+        // call affinitygroup chain
+        long vmGroupCount = _affinityGroupVMMapDao.countAffinityGroupsForVm(vm.getId());
+
+        if (vmGroupCount > 0) {
+            for (AffinityGroupProcessor processor : _affinityProcessors) {
+                processor.process(vmProfile, plan, excludes);
+            }
+        }
+
         for (HostAllocator allocator : _hostAllocators) {
             suitableHosts = allocator.allocateTo(vmProfile, plan, Host.Type.Routing, excludes, HostAllocator.RETURN_UPTO_ALL, false);
             if (suitableHosts != null && !suitableHosts.isEmpty()) {
@@ -2308,6 +2252,8 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
         cmdList.add(DeleteAffinityGroupCmd.class);
         cmdList.add(ListAffinityGroupsCmd.class);
         cmdList.add(UpdateVMAffinityGroupCmd.class);
+        cmdList.add(ListAffinityGroupTypesCmd.class);
+
         return cmdList;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c7c899f6/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java
index ca158f1..8b6ad3b 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -2284,10 +2284,12 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
         }
 
         // check that the affinity groups exist
-        for (Long affinityGroupId : affinityGroupIdList) {
-            AffinityGroupVO ag = _affinityGroupDao.findById(affinityGroupId);
-            if (ag == null) {
-                throw new InvalidParameterValueException("Unable to find affinity group by id " + affinityGroupId);
+        if (affinityGroupIdList != null) {
+            for (Long affinityGroupId : affinityGroupIdList) {
+                AffinityGroupVO ag = _affinityGroupDao.findById(affinityGroupId);
+                if (ag == null) {
+                    throw new InvalidParameterValueException("Unable to find affinity group by id " + affinityGroupId);
+                }
             }
         }
 
@@ -2582,7 +2584,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
 
         _securityGroupMgr.addInstanceToGroups(vm.getId(), securityGroupIdList);
 
-        _affinityGroupVMMapDao.updateMap(vm.getId(), affinityGroupIdList);
+        if (affinityGroupIdList != null && !affinityGroupIdList.isEmpty()) {
+            _affinityGroupVMMapDao.updateMap(vm.getId(), affinityGroupIdList);
+        }
 
         return vm;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c7c899f6/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
index 08c6e7c..4072531 100755
--- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -703,8 +703,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
                 try {
                     dest = _dpMgr.planDeployment(vmProfile, plan, avoids);
                 } catch (AffinityConflictException e2) {
-                    // TODO Auto-generated catch block
-                    e2.printStackTrace();
+                    s_logger.warn("Unable to create deployment, affinity rules associted to the VM conflict", e2);
+                    throw new CloudRuntimeException(
+                            "Unable to create deployment, affinity rules associted to the VM conflict");
+
                 }
 
                 if (dest == null) {
@@ -718,6 +720,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
                     throw new InsufficientServerCapacityException("Unable to create a deployment for " + vmProfile, DataCenter.class, plan.getDataCenterId());
                 }
 
+                if (dest != null) {
+                    avoids.addHost(dest.getHost().getId());
+                    journal.record("Deployment found ", vmProfile, dest);
+                }
+
                 long destHostId = dest.getHost().getId();
                 vm.setPodId(dest.getPod().getId());
                 Long cluster_id = dest.getCluster().getId();
@@ -1486,25 +1493,23 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 
         DeployDestination dest = null;
         while (true) {
-            for (DeploymentPlanner planner : _planners) {
-                if (planner.canHandle(profile, plan, excludes)) {
-                    dest = planner.plan(profile, plan, excludes);
-                } else {
-                    continue;
-                }
 
-                if (dest != null) {
-                    if (s_logger.isDebugEnabled()) {
-                        s_logger.debug("Planner " + planner + " found " + dest + " for migrating to.");
-                    }
-                    break;
+            try {
+                dest = _dpMgr.planDeployment(profile, plan, excludes);
+            } catch (AffinityConflictException e2) {
+                s_logger.warn("Unable to create deployment, affinity rules associted to the VM conflict", e2);
+                throw new CloudRuntimeException(
+                        "Unable to create deployment, affinity rules associted to the VM conflict");
+            }
+
+            if (dest != null) {
+                if (s_logger.isDebugEnabled()) {
+                    s_logger.debug("Found destination " + dest + " for migrating to.");
                 }
+            } else {
                 if (s_logger.isDebugEnabled()) {
-                    s_logger.debug("Planner " + planner + " was unable to find anything.");
+                    s_logger.debug("Unable to find destination for migrating the vm " + profile);
                 }
-            }
-
-            if (dest == null) {
                 throw new InsufficientServerCapacityException("Unable to find a server to migrate to.", host.getClusterId());
             }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c7c899f6/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
index 8536022..b22ed83 100644
--- a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
+++ b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
@@ -16,6 +16,7 @@ import org.apache.log4j.Logger;
 import org.springframework.context.annotation.Primary;
 
 
+import com.cloud.deploy.DeploymentPlanner;
 import com.cloud.event.ActionEvent;
 import com.cloud.event.EventTypes;
 import com.cloud.exception.InvalidParameterValueException;
@@ -77,28 +78,22 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
 
 
         //validate the affinityGroupType
-        String internalAffinityType = null;
         Map<String, AffinityGroupProcessor> typeProcessorMap = getAffinityTypeToProcessorMap();
         if (typeProcessorMap != null && !typeProcessorMap.isEmpty()) {
             if (!typeProcessorMap.containsKey(affinityGroupType)) {
                 throw new InvalidParameterValueException("Unable to create affinity group, invalid affinity group type"
                         + affinityGroupType);
-            } else {
-                AffinityGroupProcessor processor = typeProcessorMap.get(affinityGroupType);
-                internalAffinityType = processor.getType();
             }
         } else {
             throw new InvalidParameterValueException(
                     "Unable to create affinity group, no Affinity Group Types configured");
         }
 
-        if (internalAffinityType == null) {
-            throw new InvalidParameterValueException(
-                    "Unable to create affinity group, Affinity Group Processor for type " + affinityGroupType
-                            + "is wrongly configured");
+        if (domainId == null) {
+            domainId = owner.getDomainId();
         }
 
-        AffinityGroupVO group = new AffinityGroupVO(affinityGroupName, internalAffinityType, description, domainId,
+        AffinityGroupVO group = new AffinityGroupVO(affinityGroupName, affinityGroupType, description, domainId,
                 owner.getId());
         _affinityGroupDao.persist(group);
 
@@ -174,8 +169,6 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
         vmInstanceSearch.and("instanceId", vmInstanceSearch.entity().getInstanceId(), SearchCriteria.Op.EQ);
 
         SearchBuilder<AffinityGroupVO> groupSearch = _affinityGroupDao.createSearchBuilder();
-        groupSearch.join("vmInstanceSearch", vmInstanceSearch, groupSearch.entity().getId(), vmInstanceSearch.entity()
-                .getAffinityGroupId(), JoinBuilder.JoinType.INNER);
 
         SearchCriteria<AffinityGroupVO> sc = groupSearch.create();
 
@@ -207,6 +200,8 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
             }
             _accountMgr.checkAccess(caller, null, true, userVM);
             // add join to affinity_groups_vm_map
+            groupSearch.join("vmInstanceSearch", vmInstanceSearch, groupSearch.entity().getId(), vmInstanceSearch
+                    .entity().getAffinityGroupId(), JoinBuilder.JoinType.INNER);
             sc.setJoinParameters("vmInstanceSearch", "instanceId", vmId);
         }
 
@@ -222,11 +217,7 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
 
         if (componentMap.size() > 0) {
             for (Entry<String, AffinityGroupProcessor> entry : componentMap.entrySet()) {
-                Map<String, Object> params = entry.getValue().getConfigParams();
-                if (params.containsKey("type")) {
-                    types.add((String) params.get("type"));
-                }
-
+                types.add(entry.getValue().getType());
             }
 
         }
@@ -235,17 +226,13 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
 
     protected Map<String, AffinityGroupProcessor> getAffinityTypeToProcessorMap() {
         Map<String, AffinityGroupProcessor> typeProcessorMap = new HashMap<String, AffinityGroupProcessor>();
-        Map<String, AffinityGroupProcessor> componentMap = ComponentContext.getComponentsOfType(AffinityGroupProcessor.class);
+        Map<String, AffinityGroupProcessor> componentMap = ComponentContext
+                .getComponentsOfType(AffinityGroupProcessor.class);
 
         if (componentMap.size() > 0) {
             for (Entry<String, AffinityGroupProcessor> entry : componentMap.entrySet()) {
-                Map<String, Object> params = entry.getValue().getConfigParams();
-                if (params.containsKey("type")) {
-                    typeProcessorMap.put((String) params.get("type"), entry.getValue());
-                }
-
+                typeProcessorMap.put(entry.getValue().getType(), entry.getValue());
             }
-
         }
         return typeProcessorMap;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c7c899f6/server/src/org/apache/cloudstack/affinity/AffinityGroupVMMapVO.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/AffinityGroupVMMapVO.java b/server/src/org/apache/cloudstack/affinity/AffinityGroupVMMapVO.java
index 5401b4a..f84e4c3 100644
--- a/server/src/org/apache/cloudstack/affinity/AffinityGroupVMMapVO.java
+++ b/server/src/org/apache/cloudstack/affinity/AffinityGroupVMMapVO.java
@@ -30,7 +30,6 @@ import org.apache.cloudstack.api.InternalIdentity;
 
 @Entity
 @Table(name = ("affinity_group_vm_map"))
-@SecondaryTables({ @SecondaryTable(name = "affinity_group", pkJoinColumns = { @PrimaryKeyJoinColumn(name = "affinity_group_id", referencedColumnName = "id") }) })
 public class AffinityGroupVMMapVO implements InternalIdentity {
     @Id
     @GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -43,9 +42,6 @@ public class AffinityGroupVMMapVO implements InternalIdentity {
     @Column(name = "instance_id")
     private long instanceId;
 
-    @Column(name = "name", table = "affinity_group", insertable = false, updatable = false)
-    private String groupName;
-
     public AffinityGroupVMMapVO() {
     }
 
@@ -67,8 +63,4 @@ public class AffinityGroupVMMapVO implements InternalIdentity {
         return instanceId;
     }
 
-
-    public String getGroupName() {
-        return groupName;
-    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c7c899f6/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java b/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java
index ea315ac..b17d0b3 100644
--- a/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java
+++ b/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java
@@ -76,12 +76,12 @@ public class AffinityGroupVMMapDaoImpl extends GenericDaoBase<AffinityGroupVMMap
         ListByVmIdGroupId.and("affinityGroupId", ListByVmIdGroupId.entity().getAffinityGroupId(), SearchCriteria.Op.EQ);
         ListByVmIdGroupId.done();
 
-        ListByVmIdType = createSearchBuilder();
-        ListByVmIdType.and("instanceId", ListByVmIdType.entity().getInstanceId(), SearchCriteria.Op.EQ);
         SearchBuilder<AffinityGroupVO> groupSearch = _affinityGroupDao.createSearchBuilder();
         groupSearch.and("type", groupSearch.entity().getType(), SearchCriteria.Op.EQ);
-        ListByVmIdType.join("groupSearch", groupSearch, ListByVmIdType.entity().getAffinityGroupId(), groupSearch
-                .entity().getId(), JoinType.INNER);
+
+        ListByVmIdType = createSearchBuilder();
+        ListByVmIdType.and("instanceId", ListByVmIdType.entity().getInstanceId(), SearchCriteria.Op.EQ);
+        ListByVmIdType.join("groupSearch", groupSearch, ListByVmIdType.entity().getAffinityGroupId(), groupSearch.entity().getId(), JoinType.INNER);
         ListByVmIdType.done();
 
         CountSGForVm = createSearchBuilder(Long.class);
@@ -145,7 +145,7 @@ public class AffinityGroupVMMapDaoImpl extends GenericDaoBase<AffinityGroupVMMap
         SearchCriteria<AffinityGroupVMMapVO> sc = ListByVmIdType.create();
         sc.setParameters("instanceId", instanceId);
         sc.setJoinParameters("groupSearch", "type", type);
-        return customSearch(sc, null).get(0);
+        return findOneBy(sc);
     }
 
     @Override


[26/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
affinity group tests moved into the test folder

Signed-off-by: Prasanna Santhanam <ts...@apache.org>


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

Branch: refs/heads/master
Commit: e52bf5223848ec4f470499ae2aaef8258e724c3f
Parents: d38bf8a
Author: Prasanna Santhanam <ts...@apache.org>
Authored: Fri Apr 5 15:17:20 2013 +0530
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:23:30 2013 -0700

----------------------------------------------------------------------
 test/integration/smoke/test_affinity_groups.py     |  157 +++++++++++++++
 .../demo/live/testDeployVMWithAffinityGroup.py     |  157 ---------------
 .../marvin/sandbox/demo/live/testaffinitygroup.cfg |   45 ----
 3 files changed, 157 insertions(+), 202 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e52bf522/test/integration/smoke/test_affinity_groups.py
----------------------------------------------------------------------
diff --git a/test/integration/smoke/test_affinity_groups.py b/test/integration/smoke/test_affinity_groups.py
new file mode 100644
index 0000000..432751c
--- /dev/null
+++ b/test/integration/smoke/test_affinity_groups.py
@@ -0,0 +1,157 @@
+#!/usr/bin/env python
+# 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.
+
+
+
+import marvin
+from marvin.cloudstackTestCase import *
+from marvin.remoteSSHClient import remoteSSHClient
+import hashlib
+import random
+
+class TestDeployVmWithAffinityGroup(cloudstackTestCase):
+    """
+    This test deploys a virtual machine into a user account
+    using the small service offering 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.password = mdf_pass				#The md5 hashed password string
+		self.acct.username = 'testuser'
+		self.acct.email = 'testuser@xyz.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, user: %s, id: \
+				   %s"%(self.acctResponse.account.account, \
+						self.acctResponse.account.username, \
+						self.acctResponse.account.id))
+
+
+		self.zone = listZones.listZonesCmd()
+		self.zone.uuid = self.apiClient.listZones(self.zone)[0].id
+
+		self.service_offering = listServiceOfferings.listServiceOfferingsCmd()
+		self.service_offering.uuid = self.apiClient.listServiceOfferings(self.service_offering)[0].id
+
+		self.template = listTemplates.listTemplatesCmd()
+		self.template.templatefilter = 'featured'
+		self.template.name = 'CentOS'
+		self.template.uuid = self.apiClient.listTemplates(self.template)[0].id
+
+    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.
+
+		First create the host anti-affinity group for this account
+        """
+	createAGCmd = createAffinityGroup.createAffinityGroupCmd()
+	createAGCmd.name = 'webvms1'
+	createAGCmd.type = 'host anti-affinity'
+	createAGCmd.account = self.acct.account
+	createAGCmd.domainid = self.acct.domainid
+
+	createAGResponse = self.apiClient.createAffinityGroup(createAGCmd)
+	self.debug("AffinityGroup %s was created in the job %s"%(createAGResponse.id, createAGResponse.jobid))
+
+
+	deployVmCmd = deployVirtualMachine.deployVirtualMachineCmd()
+	deployVmCmd.zoneid = self.zone.uuid
+	deployVmCmd.templateid = self.template.uuid #CentOS 5.6 builtin
+	deployVmCmd.serviceofferingid = self.service_offering.uuid
+	deployVmCmd.account = self.acct.account
+	deployVmCmd.domainid = self.acct.domainid
+	deployVmCmd.affinitygroupnames=[]
+	deployVmCmd.affinitygroupnames.append(str(createAGResponse.name))
+	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")
+
+	vm = listVmResponse[0]
+	self.assertEqual(vm.state, "Running", "Check if VM has reached Running state in CS")
+
+	VM1hostid = vm.hostid
+
+	#Deploy another VM in same affinity group
+	deployVm2Cmd = deployVirtualMachine.deployVirtualMachineCmd()
+	deployVm2Cmd.zoneid = self.zone.uuid
+	deployVm2Cmd.templateid = self.template.uuid #CentOS 5.6 builtin
+	deployVm2Cmd.serviceofferingid = self.service_offering.uuid
+	deployVm2Cmd.account = self.acct.account
+	deployVm2Cmd.domainid = self.acct.domainid
+	deployVm2Cmd.affinitygroupnames=[]
+	deployVm2Cmd.affinitygroupnames.append(str(createAGResponse.name))
+
+	deployVm2Response = self.apiClient.deployVirtualMachine(deployVm2Cmd)
+	self.debug("VM2 %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.state, "Running", "Check if VM has reached Running state in CS")
+
+	VM2hostid = vm2.hostid
+
+	self.assertNotEqual(VM1hostid, VM2hostid, "The hosts of the 2 VM's in the host anti-affinity group are not different, test failed")
+
+    def tearDown(self):
+	"""
+		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.account.id
+        self.apiClient.deleteAccount(deleteAcct)
+        self.testClient.close()

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e52bf522/tools/marvin/marvin/sandbox/demo/live/testDeployVMWithAffinityGroup.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/sandbox/demo/live/testDeployVMWithAffinityGroup.py b/tools/marvin/marvin/sandbox/demo/live/testDeployVMWithAffinityGroup.py
deleted file mode 100644
index 93c6571..0000000
--- a/tools/marvin/marvin/sandbox/demo/live/testDeployVMWithAffinityGroup.py
+++ /dev/null
@@ -1,157 +0,0 @@
-#!/usr/bin/env python
-# 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.
-
-
-
-import marvin
-from marvin.cloudstackTestCase import *
-from marvin.remoteSSHClient import remoteSSHClient 
-import hashlib
-import random
-
-class TestDeployVmWithAffinityGroup(cloudstackTestCase):
-    """
-    This test deploys a virtual machine into a user account 
-    using the small service offering 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.password = mdf_pass				#The md5 hashed password string
-		self.acct.username = 'testuser'
-		self.acct.email = 'testuser@xyz.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, user: %s, id: \
-				   %s"%(self.acctResponse.account.account, \
-						self.acctResponse.account.username, \
-						self.acctResponse.account.id))
-		
-
-		self.zone = listZones.listZonesCmd()
-		self.zone.uuid = self.apiClient.listZones(self.zone)[0].id
-
-		self.service_offering = listServiceOfferings.listServiceOfferingsCmd()
-		self.service_offering.uuid = self.apiClient.listServiceOfferings(self.service_offering)[0].id
-
-		self.template = listTemplates.listTemplatesCmd()
-		self.template.templatefilter = 'featured'
-		self.template.name = 'CentOS'
-		self.template.uuid = self.apiClient.listTemplates(self.template)[0].id        
-
-    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. 
-		
-		First create the host anti-affinity group for this account
-        """
-	createAGCmd = createAffinityGroup.createAffinityGroupCmd()
-	createAGCmd.name = 'webvms1'
-	createAGCmd.type = 'host anti-affinity'
-	createAGCmd.account = self.acct.account
-	createAGCmd.domainid = self.acct.domainid
-		
-	createAGResponse = self.apiClient.createAffinityGroup(createAGCmd)
-	self.debug("AffinityGroup %s was created in the job %s"%(createAGResponse.id, createAGResponse.jobid))
-    
-	
-	deployVmCmd = deployVirtualMachine.deployVirtualMachineCmd()
-	deployVmCmd.zoneid = self.zone.uuid
-	deployVmCmd.templateid = self.template.uuid #CentOS 5.6 builtin
-	deployVmCmd.serviceofferingid = self.service_offering.uuid
-	deployVmCmd.account = self.acct.account
-	deployVmCmd.domainid = self.acct.domainid
-	deployVmCmd.affinitygroupnames=[]
-	deployVmCmd.affinitygroupnames.append(str(createAGResponse.name))
-	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")
-
-	vm = listVmResponse[0]
-	self.assertEqual(vm.state, "Running", "Check if VM has reached Running state in CS")
-
-	VM1hostid = vm.hostid
-
-	#Deploy another VM in same affinity group
-	deployVm2Cmd = deployVirtualMachine.deployVirtualMachineCmd()
-	deployVm2Cmd.zoneid = self.zone.uuid
-	deployVm2Cmd.templateid = self.template.uuid #CentOS 5.6 builtin
-	deployVm2Cmd.serviceofferingid = self.service_offering.uuid
-	deployVm2Cmd.account = self.acct.account
-	deployVm2Cmd.domainid = self.acct.domainid
-	deployVm2Cmd.affinitygroupnames=[]
-	deployVm2Cmd.affinitygroupnames.append(str(createAGResponse.name))
-
-	deployVm2Response = self.apiClient.deployVirtualMachine(deployVm2Cmd)
-	self.debug("VM2 %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.state, "Running", "Check if VM has reached Running state in CS")
-
-	VM2hostid = vm2.hostid
-	
-	self.assertNotEqual(VM1hostid, VM2hostid, "The hosts of the 2 VM's in the host anti-affinity group are not different, test failed")                         
-	
-    def tearDown(self):
-    	"""
-		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.account.id
-        self.apiClient.deleteAccount(deleteAcct)
-        self.testClient.close()

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e52bf522/tools/marvin/marvin/sandbox/demo/live/testaffinitygroup.cfg
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/sandbox/demo/live/testaffinitygroup.cfg b/tools/marvin/marvin/sandbox/demo/live/testaffinitygroup.cfg
deleted file mode 100644
index a814016..0000000
--- a/tools/marvin/marvin/sandbox/demo/live/testaffinitygroup.cfg
+++ /dev/null
@@ -1,45 +0,0 @@
-#  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.
-#
-# This config is designed to run as an advanced network, with management server in devcloud
-# It also requires an 'apt-get install dnsmasq' to run a resolver in devcloud for internal dns
-
-{
-    "dbSvr": {
-        "dbSvr": "127.0.0.1", 
-        "passwd": "cloud", 
-        "db": "cloud", 
-        "port": 3306, 
-        "user": "cloud"
-    }, 
-    "logger": [
-        {
-            "name": "TestClient", 
-            "file": "C:\\var\\log\\testclient.log"
-        }, 
-        {
-            "name": "TestCase", 
-            "file": "C:\\var\\log\\testcase.log"
-        }
-    ], 
-    "mgtSvr": [
-        {
-            "mgtSvrIp": "127.0.0.1", 
-            "port": 8096
-        }
-    ]
-}


[14/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
Changes to make affinity group types configurable.


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

Branch: refs/heads/master
Commit: bb9bdf0173f7a225402a6640a0d8752155c9ee3c
Parents: 708157d
Author: Prachi Damle <pr...@cloud.com>
Authored: Mon Mar 25 14:53:19 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:23:01 2013 -0700

----------------------------------------------------------------------
 .../affinity/AffinityGroupTypeResponse.java        |   48 ++++++++++
 .../affinitygroup/ListAffinityGroupTypesCmd.java   |   67 +++++++++++++++
 client/tomcatconf/componentContext.xml.in          |    9 ++
 .../affinity/AffinityGroupServiceImpl.java         |   64 +++++++++++++-
 4 files changed, 185 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bb9bdf01/api/src/org/apache/cloudstack/affinity/AffinityGroupTypeResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/affinity/AffinityGroupTypeResponse.java b/api/src/org/apache/cloudstack/affinity/AffinityGroupTypeResponse.java
new file mode 100644
index 0000000..2d1cd25
--- /dev/null
+++ b/api/src/org/apache/cloudstack/affinity/AffinityGroupTypeResponse.java
@@ -0,0 +1,48 @@
+// 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 org.apache.cloudstack.affinity;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseResponse;
+import org.apache.cloudstack.api.EntityReference;
+import org.apache.cloudstack.api.response.ControlledEntityResponse;
+import org.apache.cloudstack.api.response.ControlledViewEntityResponse;
+
+import com.cloud.network.security.SecurityGroup;
+import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
+
+@SuppressWarnings("unused")
+@EntityReference(value = AffinityGroup.class)
+public class AffinityGroupTypeResponse extends BaseResponse {
+
+    @SerializedName(ApiConstants.TYPE)
+    @Param(description = "the type of the affinity group")
+    private String type;
+
+
+    public AffinityGroupTypeResponse() {
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bb9bdf01/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupTypesCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupTypesCmd.java b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupTypesCmd.java
new file mode 100644
index 0000000..ce6e89a
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupTypesCmd.java
@@ -0,0 +1,67 @@
+// 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 org.apache.cloudstack.api.command.user.affinitygroup;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.cloudstack.affinity.AffinityGroupTypeResponse;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.BaseListCmd;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.log4j.Logger;
+
+import com.cloud.user.Account;
+
+@APICommand(name = "listAffinityGroupTypes", description = "Lists affinity group types available", responseObject = AffinityGroupTypeResponse.class)
+public class ListAffinityGroupTypesCmd extends BaseListCmd {
+    public static final Logger s_logger = Logger.getLogger(ListAffinityGroupTypesCmd.class.getName());
+
+    private static final String s_name = "listaffinitygrouptypesresponse";
+
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    public long getEntityOwnerId() {
+        return Account.ACCOUNT_ID_SYSTEM;
+    }
+
+    @Override
+    public void execute() {
+        List<String> result = _affinityGroupService.listAffinityGroupTypes();
+        ListResponse<AffinityGroupTypeResponse> response = new ListResponse<AffinityGroupTypeResponse>();
+        ArrayList<AffinityGroupTypeResponse> responses = new ArrayList<AffinityGroupTypeResponse>();
+        if (result != null) {
+            for (String type : result) {
+                AffinityGroupTypeResponse affinityTypeResponse = new AffinityGroupTypeResponse();
+                affinityTypeResponse.setType(type);
+                affinityTypeResponse.setObjectName("affinityGroupType");
+                responses.add(affinityTypeResponse);
+            }
+        }
+        response.setResponses(responses);
+        response.setResponseName(getCommandName());
+        this.setResponseObject(response);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bb9bdf01/client/tomcatconf/componentContext.xml.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/componentContext.xml.in b/client/tomcatconf/componentContext.xml.in
index 1582e8b..7f3e02d 100644
--- a/client/tomcatconf/componentContext.xml.in
+++ b/client/tomcatconf/componentContext.xml.in
@@ -247,4 +247,13 @@
       </list>
     </property>
   </bean>
+
+  <!--
+   AffinityGroup Processors
+  -->
+    <bean id="HostAntiAffinityProcessor" class="org.apache.cloudstack.affinity.HostAntiAffinityProcessor">
+    	<property name="name" value="HostAntiAffinityProcessor"/>
+    	<property name="type" value="host anti-affinity"/>
+ 	</bean>
+  
 </beans>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bb9bdf01/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
index 21052d0..8536022 100644
--- a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
+++ b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
@@ -1,7 +1,10 @@
 package org.apache.cloudstack.affinity;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import javax.ejb.Local;
 import javax.inject.Inject;
@@ -10,6 +13,7 @@ import javax.naming.ConfigurationException;
 import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
 import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
 import org.apache.log4j.Logger;
+import org.springframework.context.annotation.Primary;
 
 
 import com.cloud.event.ActionEvent;
@@ -22,6 +26,7 @@ import com.cloud.user.AccountManager;
 import com.cloud.user.UserContext;
 import com.cloud.uservm.UserVm;
 import com.cloud.utils.Pair;
+import com.cloud.utils.component.ComponentContext;
 import com.cloud.utils.component.Manager;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.db.DB;
@@ -30,6 +35,7 @@ import com.cloud.utils.db.JoinBuilder;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.Transaction;
+import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.fsm.StateListener;
 import com.cloud.vm.UserVmVO;
 import com.cloud.vm.VirtualMachine;
@@ -69,7 +75,30 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
                     + " already exisits.");
         }
 
-        AffinityGroupVO group = new AffinityGroupVO(affinityGroupName, affinityGroupType, description, domainId,
+
+        //validate the affinityGroupType
+        String internalAffinityType = null;
+        Map<String, AffinityGroupProcessor> typeProcessorMap = getAffinityTypeToProcessorMap();
+        if (typeProcessorMap != null && !typeProcessorMap.isEmpty()) {
+            if (!typeProcessorMap.containsKey(affinityGroupType)) {
+                throw new InvalidParameterValueException("Unable to create affinity group, invalid affinity group type"
+                        + affinityGroupType);
+            } else {
+                AffinityGroupProcessor processor = typeProcessorMap.get(affinityGroupType);
+                internalAffinityType = processor.getType();
+            }
+        } else {
+            throw new InvalidParameterValueException(
+                    "Unable to create affinity group, no Affinity Group Types configured");
+        }
+
+        if (internalAffinityType == null) {
+            throw new InvalidParameterValueException(
+                    "Unable to create affinity group, Affinity Group Processor for type " + affinityGroupType
+                            + "is wrongly configured");
+        }
+
+        AffinityGroupVO group = new AffinityGroupVO(affinityGroupName, internalAffinityType, description, domainId,
                 owner.getId());
         _affinityGroupDao.persist(group);
 
@@ -188,8 +217,37 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
 
     @Override
     public List<String> listAffinityGroupTypes() {
-        // TODO Auto-generated method stub
-        return null;
+        List<String> types = new ArrayList<String>();
+        Map<String, AffinityGroupProcessor> componentMap = ComponentContext.getComponentsOfType(AffinityGroupProcessor.class);
+
+        if (componentMap.size() > 0) {
+            for (Entry<String, AffinityGroupProcessor> entry : componentMap.entrySet()) {
+                Map<String, Object> params = entry.getValue().getConfigParams();
+                if (params.containsKey("type")) {
+                    types.add((String) params.get("type"));
+                }
+
+            }
+
+        }
+        return types;
+    }
+
+    protected Map<String, AffinityGroupProcessor> getAffinityTypeToProcessorMap() {
+        Map<String, AffinityGroupProcessor> typeProcessorMap = new HashMap<String, AffinityGroupProcessor>();
+        Map<String, AffinityGroupProcessor> componentMap = ComponentContext.getComponentsOfType(AffinityGroupProcessor.class);
+
+        if (componentMap.size() > 0) {
+            for (Entry<String, AffinityGroupProcessor> entry : componentMap.entrySet()) {
+                Map<String, Object> params = entry.getValue().getConfigParams();
+                if (params.containsKey("type")) {
+                    typeProcessorMap.put((String) params.get("type"), entry.getValue());
+                }
+
+            }
+
+        }
+        return typeProcessorMap;
     }
 
     @Override


[28/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
marvin bvt: getting rid of unused keys in the test

Signed-off-by: Prasanna Santhanam <ts...@apache.org>


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

Branch: refs/heads/master
Commit: 943aef76f1c7339cd31613b7780fb0e93c6a7a90
Parents: 79812c2
Author: Prasanna Santhanam <ts...@apache.org>
Authored: Mon Apr 8 23:25:06 2013 +0530
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:23:34 2013 -0700

----------------------------------------------------------------------
 test/integration/smoke/test_affinity_groups.py |   15 ++++++---------
 1 files changed, 6 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/943aef76/test/integration/smoke/test_affinity_groups.py
----------------------------------------------------------------------
diff --git a/test/integration/smoke/test_affinity_groups.py b/test/integration/smoke/test_affinity_groups.py
index 83fccf5..0d06e64 100644
--- a/test/integration/smoke/test_affinity_groups.py
+++ b/test/integration/smoke/test_affinity_groups.py
@@ -53,9 +53,11 @@ class Services:
             },
             "ostype": 'CentOS 5.3 (64-bit)',
             "mode": 'advanced',
-            "affinity": {
-                "name": "webvms",
-                "type": "host anti-affinity",
+            "virtual_machine" : {
+                "affinity": {
+                    "name": "webvms",
+                    "type": "host anti-affinity",
+                }
             }
         }
 
@@ -73,17 +75,12 @@ class TestDeployVmWithAffinityGroup(cloudstackTestCase):
         # Get Zone, Domain and templates
         cls.domain = get_domain(cls.api_client, cls.services)
         cls.zone = get_zone(cls.api_client, cls.services)
-        cls.disk_offering = DiskOffering.create(
-            cls.api_client,
-            cls.services["disk_offering"]
-        )
         cls.template = get_template(
             cls.api_client,
             cls.zone.id,
             cls.services["ostype"]
         )
         cls.services["virtual_machine"]["zoneid"] = cls.zone.id
-        cls.services["volume"]["zoneid"] = cls.zone.id
 
         cls.services["template"] = cls.template.id
         cls.services["zoneid"] = cls.zone.id
@@ -101,7 +98,7 @@ class TestDeployVmWithAffinityGroup(cloudstackTestCase):
             cls.services["service_offering"]
         )
 
-        cls.ag = AffinityGroup.create(cls.api_client, cls.services["affinity"], domainid=cls.domain.id)
+        cls.ag = AffinityGroup.create(cls.api_client, cls.services["virtual_machine"]["affinity"], domainid=cls.domain.id)
 
         cls._cleanup = [
             cls.service_offering,


[25/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
More log statements to debug


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

Branch: refs/heads/master
Commit: d38bf8a10cd9f5287dbc1f89d3b404a8620ae5c8
Parents: 0f565f2
Author: Prachi Damle <pr...@cloud.com>
Authored: Fri Apr 5 17:59:50 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:23:27 2013 -0700

----------------------------------------------------------------------
 .../affinity/HostAntiAffinityProcessor.java        |    9 +++++++++
 .../affinity/AffinityGroupServiceImpl.java         |    3 +++
 2 files changed, 12 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d38bf8a1/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
----------------------------------------------------------------------
diff --git a/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java b/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
index 4049571..4011c02 100644
--- a/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
+++ b/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
@@ -68,9 +68,18 @@ public class HostAntiAffinityProcessor extends AffinityProcessorBase implements
                 if (groupVM != null && !groupVM.isRemoved()) {
                     if (groupVM.getHostId() != null) {
                         avoid.addHost(groupVM.getHostId());
+                        if (s_logger.isDebugEnabled()) {
+                            s_logger.debug("Added host " + groupVM.getHostId() + " to avoid set, since VM "
+                                    + groupVM.getId() + " is present on the host");
+                        }
                     } else if (VirtualMachine.State.Stopped.equals(groupVM.getState())
                             && groupVM.getLastHostId() != null) {
                         avoid.addHost(groupVM.getLastHostId());
+                        if (s_logger.isDebugEnabled()) {
+                            s_logger.debug("Added host " + groupVM.getLastHostId() + " to avoid set, since VM "
+                                    + groupVM.getId() + " is present on the host, in Stopped state");
+                        }
+
                     }
                 }
             }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d38bf8a1/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
index 17f7401..5c7edc5 100644
--- a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
+++ b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
@@ -310,6 +310,9 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
             }
         }
         _affinityGroupVMMapDao.updateMap(vmId, affinityGroupIds);
+        if (s_logger.isDebugEnabled()) {
+            s_logger.debug("Updated VM :" + vmId + " affinity groups to =" + affinityGroupIds);
+        }
         // APIResponseHelper will pull out the updated affinitygroups.
         return vmInstance;
 


[22/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
Changes to return affinity groups information during listVMsCmd


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

Branch: refs/heads/master
Commit: 09a6eb735d2d14c27be4f1911798e581ff60b678
Parents: 0b3850c
Author: Prachi Damle <pr...@cloud.com>
Authored: Thu Apr 4 14:40:05 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:23:20 2013 -0700

----------------------------------------------------------------------
 .../org/apache/cloudstack/api/ApiConstants.java    |    2 +-
 .../cloudstack/api/response/UserVmResponse.java    |   14 ++
 .../com/cloud/api/query/ViewResponseHelper.java    |    2 +-
 .../com/cloud/api/query/dao/UserVmJoinDaoImpl.java |   27 +++
 .../src/com/cloud/api/query/vo/UserVmJoinVO.java   |   37 +++
 setup/db/db/schema-410to420.sql                    |  179 +++++++++++++++
 6 files changed, 259 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/09a6eb73/api/src/org/apache/cloudstack/api/ApiConstants.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java
index dd8bfcd..b08e992 100755
--- a/api/src/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/org/apache/cloudstack/api/ApiConstants.java
@@ -482,7 +482,7 @@ public class ApiConstants {
     }
 
     public enum VMDetails {
-        all, group, nics, stats, secgrp, tmpl, servoff, iso, volume, min;
+        all, group, nics, stats, secgrp, tmpl, servoff, iso, volume, min, affgrp;
     }
 
     public enum LDAPParams {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/09a6eb73/api/src/org/apache/cloudstack/api/response/UserVmResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/response/UserVmResponse.java b/api/src/org/apache/cloudstack/api/response/UserVmResponse.java
index 71d1b82..212601c 100644
--- a/api/src/org/apache/cloudstack/api/response/UserVmResponse.java
+++ b/api/src/org/apache/cloudstack/api/response/UserVmResponse.java
@@ -21,6 +21,7 @@ import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.Set;
 
+import org.apache.cloudstack.affinity.AffinityGroupResponse;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseResponse;
 import org.apache.cloudstack.api.EntityReference;
@@ -169,10 +170,15 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp
     @SerializedName(ApiConstants.SSH_KEYPAIR) @Param(description="ssh key-pair")
     private String keyPairName;
 
+    @SerializedName("affinitygroup")
+    @Param(description = "list of affinity groups associated with the virtual machine", responseObject = AffinityGroupResponse.class)
+    private Set<AffinityGroupResponse> affinityGroupList;
+
     public UserVmResponse(){
         securityGroupList = new LinkedHashSet<SecurityGroupResponse>();
         nics = new LinkedHashSet<NicResponse>();
         tags = new LinkedHashSet<ResourceTagResponse>();
+        affinityGroupList = new LinkedHashSet<AffinityGroupResponse>();
     }
 
     public void setHypervisor(String hypervisor) {
@@ -381,4 +387,12 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp
         this.keyPairName = keyPairName;
     }
 
+    public void setAffinityGroupList(Set<AffinityGroupResponse> affinityGroups) {
+        this.affinityGroupList = affinityGroups;
+    }
+
+    public void addAffinityGroup(AffinityGroupResponse affinityGroup) {
+        this.affinityGroupList.add(affinityGroup);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/09a6eb73/server/src/com/cloud/api/query/ViewResponseHelper.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/ViewResponseHelper.java b/server/src/com/cloud/api/query/ViewResponseHelper.java
index 9e612b0..931327a 100644
--- a/server/src/com/cloud/api/query/ViewResponseHelper.java
+++ b/server/src/com/cloud/api/query/ViewResponseHelper.java
@@ -123,7 +123,7 @@ public class ViewResponseHelper {
                 // first time encountering this vm
                 userVmData = ApiDBUtils.newUserVmResponse(objectName, userVm, details, caller);
             } else{
-                // update nics, securitygroups, tags for 1 to many mapping fields
+                // update nics, securitygroups, tags, affinitygroups for 1 to many mapping fields
                 userVmData = ApiDBUtils.fillVmDetails(userVmData, userVm);
             }
             vmDataList.put(userVm.getId(), userVmData);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/09a6eb73/server/src/com/cloud/api/query/dao/UserVmJoinDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/dao/UserVmJoinDaoImpl.java b/server/src/com/cloud/api/query/dao/UserVmJoinDaoImpl.java
index 8b6abf8..4ed6226 100644
--- a/server/src/com/cloud/api/query/dao/UserVmJoinDaoImpl.java
+++ b/server/src/com/cloud/api/query/dao/UserVmJoinDaoImpl.java
@@ -26,6 +26,7 @@ import java.util.Set;
 import javax.ejb.Local;
 import javax.inject.Inject;
 
+import org.apache.cloudstack.affinity.AffinityGroupResponse;
 import org.apache.cloudstack.api.ApiConstants.VMDetails;
 import org.apache.cloudstack.api.response.NicResponse;
 import org.apache.cloudstack.api.response.SecurityGroupResponse;
@@ -216,6 +217,20 @@ public class UserVmJoinDaoImpl extends GenericDaoBase<UserVmJoinVO, Long> implem
                 userVmResponse.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
             }
         }
+
+        if (details.contains(VMDetails.all) || details.contains(VMDetails.affgrp)) {
+            Long affinityGroupId = userVm.getAffinityGroupId();
+            if (affinityGroupId != null && affinityGroupId.longValue() != 0) {
+                AffinityGroupResponse resp = new AffinityGroupResponse();
+                resp.setId(userVm.getAffinityGroupUuid());
+                resp.setName(userVm.getAffinityGroupName());
+                resp.setDescription(userVm.getAffinityGroupDescription());
+                resp.setObjectName("affinitygroup");
+                resp.setAccountName(userVm.getAccountName());
+                userVmResponse.addAffinityGroup(resp);
+            }
+        }
+
         userVmResponse.setObjectName(objectName);
 
         return userVmResponse;
@@ -276,6 +291,18 @@ public class UserVmJoinDaoImpl extends GenericDaoBase<UserVmJoinVO, Long> implem
                 userVmData.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
             }
         }
+
+        Long affinityGroupId = uvo.getAffinityGroupId();
+        if (affinityGroupId != null && affinityGroupId.longValue() != 0) {
+            AffinityGroupResponse resp = new AffinityGroupResponse();
+            resp.setId(uvo.getAffinityGroupUuid());
+            resp.setName(uvo.getAffinityGroupName());
+            resp.setDescription(uvo.getAffinityGroupDescription());
+            resp.setObjectName("affinitygroup");
+            resp.setAccountName(uvo.getAccountName());
+            userVmData.addAffinityGroup(resp);
+        }
+
         return userVmData;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/09a6eb73/server/src/com/cloud/api/query/vo/UserVmJoinVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/vo/UserVmJoinVO.java b/server/src/com/cloud/api/query/vo/UserVmJoinVO.java
index 33c49cd..8d1314e 100644
--- a/server/src/com/cloud/api/query/vo/UserVmJoinVO.java
+++ b/server/src/com/cloud/api/query/vo/UserVmJoinVO.java
@@ -368,6 +368,18 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity {
     @Column(name="tag_customer")
     private String tagCustomer;
 
+    @Column(name = "affinity_group_id")
+    private long affinityGroupId;
+
+    @Column(name = "affinity_group_uuid")
+    private String affinityGroupUuid;
+
+    @Column(name = "affinity_group_name")
+    private String affinityGroupName;
+
+    @Column(name = "affinity_group_description")
+    private String affinityGroupDescription;
+
     transient String password;
 
     @Transient
@@ -1671,4 +1683,29 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity {
 	public void setIp6Cidr(String ip6Cidr) {
 		this.ip6Cidr = ip6Cidr;
 	}
+
+
+    public long getAffinityGroupId() {
+        return affinityGroupId;
+    }
+
+
+
+    public String getAffinityGroupUuid() {
+        return affinityGroupUuid;
+    }
+
+
+
+    public String getAffinityGroupName() {
+        return affinityGroupName;
+    }
+
+
+
+    public String getAffinityGroupDescription() {
+        return affinityGroupDescription;
+    }
+
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/09a6eb73/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql
index b4c693a..6464c08 100644
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@ -470,5 +470,184 @@ CREATE TABLE `cloud`.`vm_snapshots` (
 ALTER TABLE `cloud`.`hypervisor_capabilities` ADD COLUMN `vm_snapshot_enabled` tinyint(1) DEFAULT 0 NOT NULL COMMENT 'Whether VM snapshot is supported by hypervisor';
 UPDATE `cloud`.`hypervisor_capabilities` SET `vm_snapshot_enabled`=1 WHERE `hypervisor_type` in ('VMware', 'XenServer');
 
+			
+DROP VIEW IF EXISTS `cloud`.`user_vm_view`;
+CREATE VIEW `cloud`.`user_vm_view` AS
+    select 
+        vm_instance.id id,
+        vm_instance.name name,
+        user_vm.display_name display_name,
+        user_vm.user_data user_data,
+        account.id account_id,
+        account.uuid account_uuid,
+        account.account_name account_name,
+        account.type account_type,
+        domain.id domain_id,
+        domain.uuid domain_uuid,
+        domain.name domain_name,
+        domain.path domain_path,
+        projects.id project_id,
+        projects.uuid project_uuid,
+        projects.name project_name,
+        instance_group.id instance_group_id,
+        instance_group.uuid instance_group_uuid,
+        instance_group.name instance_group_name,
+        vm_instance.uuid uuid,
+        vm_instance.last_host_id last_host_id,
+        vm_instance.vm_type type,
+        vm_instance.vnc_password vnc_password,
+        vm_instance.limit_cpu_use limit_cpu_use,
+        vm_instance.created created,
+        vm_instance.state state,
+        vm_instance.removed removed,
+        vm_instance.ha_enabled ha_enabled,
+        vm_instance.hypervisor_type hypervisor_type,
+        vm_instance.instance_name instance_name,
+        vm_instance.guest_os_id guest_os_id,
+        guest_os.uuid guest_os_uuid,
+        vm_instance.pod_id pod_id,
+        host_pod_ref.uuid pod_uuid,
+        vm_instance.private_ip_address private_ip_address,
+        vm_instance.private_mac_address private_mac_address,
+        vm_instance.vm_type vm_type,
+        data_center.id data_center_id,
+        data_center.uuid data_center_uuid,
+        data_center.name data_center_name,
+        data_center.is_security_group_enabled security_group_enabled,
+        host.id host_id,
+        host.uuid host_uuid,
+        host.name host_name,
+        vm_template.id template_id,
+        vm_template.uuid template_uuid,
+        vm_template.name template_name,
+        vm_template.display_text template_display_text,
+        vm_template.enable_password password_enabled,
+        iso.id iso_id,
+        iso.uuid iso_uuid,
+        iso.name iso_name,
+        iso.display_text iso_display_text,
+        service_offering.id service_offering_id,
+        disk_offering.uuid service_offering_uuid,
+        service_offering.cpu cpu,
+        service_offering.speed speed,
+        service_offering.ram_size ram_size,
+        disk_offering.name service_offering_name,
+        storage_pool.id pool_id,
+        storage_pool.uuid pool_uuid,
+        storage_pool.pool_type pool_type,
+        volumes.id volume_id,
+        volumes.uuid volume_uuid,
+        volumes.device_id volume_device_id,
+        volumes.volume_type volume_type,
+        security_group.id security_group_id,
+        security_group.uuid security_group_uuid,
+        security_group.name security_group_name,
+        security_group.description security_group_description,
+        nics.id nic_id,
+        nics.uuid nic_uuid,
+        nics.network_id network_id,
+        nics.ip4_address ip_address,
+        nics.ip6_address ip6_address,
+        nics.ip6_gateway ip6_gateway,
+        nics.ip6_cidr ip6_cidr,
+        nics.default_nic is_default_nic,
+        nics.gateway gateway,
+        nics.netmask netmask,
+        nics.mac_address mac_address,
+        nics.broadcast_uri broadcast_uri,
+        nics.isolation_uri isolation_uri,
+        vpc.id vpc_id,
+        vpc.uuid vpc_uuid,
+        networks.uuid network_uuid,
+        networks.name network_name,
+        networks.traffic_type traffic_type,
+        networks.guest_type guest_type,
+        user_ip_address.id public_ip_id,
+        user_ip_address.uuid public_ip_uuid,
+        user_ip_address.public_ip_address public_ip_address,
+        ssh_keypairs.keypair_name keypair_name,
+        resource_tags.id tag_id,
+        resource_tags.uuid tag_uuid,
+        resource_tags.key tag_key,
+        resource_tags.value tag_value,
+        resource_tags.domain_id tag_domain_id,
+        resource_tags.account_id tag_account_id,
+        resource_tags.resource_id tag_resource_id,
+        resource_tags.resource_uuid tag_resource_uuid,
+        resource_tags.resource_type tag_resource_type,
+        resource_tags.customer tag_customer,
+        async_job.id job_id,
+        async_job.uuid job_uuid,
+        async_job.job_status job_status,
+        async_job.account_id job_account_id,
+		affinity_group.id affinity_group_id,
+        affinity_group.uuid affinity_group_uuid,
+        affinity_group.name affinity_group_name,
+        affinity_group.description affinity_group_description
+    from
+        `cloud`.`user_vm`
+            inner join
+        `cloud`.`vm_instance` ON vm_instance.id = user_vm.id
+            and vm_instance.removed is NULL
+            inner join
+        `cloud`.`account` ON vm_instance.account_id = account.id
+            inner join
+        `cloud`.`domain` ON vm_instance.domain_id = domain.id
+            left join
+        `cloud`.`guest_os` ON vm_instance.guest_os_id = guest_os.id
+            left join
+        `cloud`.`host_pod_ref` ON vm_instance.pod_id = host_pod_ref.id
+            left join
+        `cloud`.`projects` ON projects.project_account_id = account.id
+            left join
+        `cloud`.`instance_group_vm_map` ON vm_instance.id = instance_group_vm_map.instance_id
+            left join
+        `cloud`.`instance_group` ON instance_group_vm_map.group_id = instance_group.id
+            left join
+        `cloud`.`data_center` ON vm_instance.data_center_id = data_center.id
+            left join
+        `cloud`.`host` ON vm_instance.host_id = host.id
+            left join
+        `cloud`.`vm_template` ON vm_instance.vm_template_id = vm_template.id
+            left join
+        `cloud`.`vm_template` iso ON iso.id = user_vm.iso_id
+            left join
+        `cloud`.`service_offering` ON vm_instance.service_offering_id = service_offering.id
+            left join
+        `cloud`.`disk_offering` ON vm_instance.service_offering_id = disk_offering.id
+            left join
+        `cloud`.`volumes` ON vm_instance.id = volumes.instance_id
+            left join
+        `cloud`.`storage_pool` ON volumes.pool_id = storage_pool.id
+            left join
+        `cloud`.`security_group_vm_map` ON vm_instance.id = security_group_vm_map.instance_id
+            left join
+        `cloud`.`security_group` ON security_group_vm_map.security_group_id = security_group.id
+            left join
+        `cloud`.`nics` ON vm_instance.id = nics.instance_id
+            left join
+        `cloud`.`networks` ON nics.network_id = networks.id
+            left join
+        `cloud`.`vpc` ON networks.vpc_id = vpc.id
+            left join
+        `cloud`.`user_ip_address` ON user_ip_address.vm_id = vm_instance.id
+            left join
+        `cloud`.`user_vm_details` ON user_vm_details.vm_id = vm_instance.id
+            and user_vm_details.name = 'SSH.PublicKey'
+            left join
+        `cloud`.`ssh_keypairs` ON ssh_keypairs.public_key = user_vm_details.value
+            left join
+        `cloud`.`resource_tags` ON resource_tags.resource_id = vm_instance.id
+            and resource_tags.resource_type = 'UserVm'
+            left join
+        `cloud`.`async_job` ON async_job.instance_id = vm_instance.id
+            and async_job.instance_type = 'VirtualMachine'
+            and async_job.job_status = 0
+            left join
+        `cloud`.`affinity_group_vm_map` ON vm_instance.id = affinity_group_vm_map.instance_id
+			left join
+        `cloud`.`affinity_group` ON affinity_group_vm_map.affinity_group_id = affinity_group.id;
+
+			
 -- Re-enable foreign key checking, at the end of the upgrade path
 SET foreign_key_checks = 1;			


[08/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
Added apache license header


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

Branch: refs/heads/master
Commit: d108fb46004aca4d134e67629044dbe91ed94c49
Parents: bf9221a
Author: Prachi Damle <pr...@cloud.com>
Authored: Thu Mar 14 17:22:06 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:22:47 2013 -0700

----------------------------------------------------------------------
 .../affinity/HostAntiAffinityProcessor.java        |   16 +++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d108fb46/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
----------------------------------------------------------------------
diff --git a/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java b/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
index 93bd358..11b391b 100644
--- a/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
+++ b/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
@@ -1,3 +1,19 @@
+// 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 org.apache.cloudstack.affinity;
 
 import java.util.List;


[13/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
API changes to expose the commands


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

Branch: refs/heads/master
Commit: 708157d33fd32b186f59687d176b9251bdb7d23c
Parents: c8ae2a9
Author: Prachi Damle <pr...@cloud.com>
Authored: Fri Mar 22 14:57:27 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:22:59 2013 -0700

----------------------------------------------------------------------
 .../user/affinitygroup/CreateAffinityGroupCmd.java |    4 +-
 .../api/response/DeploymentPlannersResponse.java   |   37 +++++++++++++++
 client/pom.xml                                     |    5 ++
 client/tomcatconf/commands.properties.in           |    3 +
 .../affinity/AffinityGroupServiceImpl.java         |    2 +-
 5 files changed, 48 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/708157d3/api/src/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java
index b465214..96de4aa 100644
--- a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java
@@ -43,10 +43,10 @@ public class CreateAffinityGroupCmd extends BaseAsyncCreateCmd {
     // ////////////// API parameters /////////////////////
     // ///////////////////////////////////////////////////
 
-    @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, required = true, description = "an account for the affinity group. Must be used with domainId.")
+    @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "an account for the affinity group. Must be used with domainId.")
     private String accountName;
 
-    @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, required = true, description = "domainId of the account owning the affinity group", entityType = DomainResponse.class)
+    @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, description = "domainId of the account owning the affinity group", entityType = DomainResponse.class)
     private Long domainId;
 
     @Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "optional description of the affinity group")

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/708157d3/api/src/org/apache/cloudstack/api/response/DeploymentPlannersResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/response/DeploymentPlannersResponse.java b/api/src/org/apache/cloudstack/api/response/DeploymentPlannersResponse.java
new file mode 100644
index 0000000..a37800f
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/response/DeploymentPlannersResponse.java
@@ -0,0 +1,37 @@
+// 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 org.apache.cloudstack.api.response;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseResponse;
+
+import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
+
+public class DeploymentPlannersResponse extends BaseResponse {
+    @SerializedName(ApiConstants.NAME)
+    @Param(description = "Deployment Planner name")
+    private String name;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/708157d3/client/pom.xml
----------------------------------------------------------------------
diff --git a/client/pom.xml b/client/pom.xml
index cd61dfc..08946b6 100644
--- a/client/pom.xml
+++ b/client/pom.xml
@@ -234,6 +234,11 @@
       <artifactId>cloud-plugin-snmp-alerts</artifactId>
       <version>${project.version}</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.cloudstack</groupId>
+      <artifactId>cloud-plugin-host-anti-affinity</artifactId>
+      <version>${project.version}</version>
+    </dependency>
   </dependencies>
   <build>
     <defaultGoal>install</defaultGoal>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/708157d3/client/tomcatconf/commands.properties.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in
index e4823d9..55fa599 100644
--- a/client/tomcatconf/commands.properties.in
+++ b/client/tomcatconf/commands.properties.in
@@ -571,3 +571,6 @@ addBaremetalHost=1
 
 #### Affinity group commands
 createAffinityGroup=15
+deleteAffinityGroup=15
+listAffinityGroups=15
+updateVMAffinityGroup=15

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/708157d3/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
index f6c87cb..21052d0 100644
--- a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
+++ b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
@@ -231,7 +231,7 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
             return false;
         }
         if ((newState == State.Expunging)) {
-            // cleanup all affinity groups associated to the Expunged VM
+            // cleanup all affinity groups associations of the Expunged VM
             SearchCriteria<AffinityGroupVMMapVO> sc = _affinityGroupVMMapDao.createSearchCriteria();
             sc.addAnd("instanceId", SearchCriteria.Op.EQ, vo.getId());
             _affinityGroupVMMapDao.expunge(sc);


[29/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
CLOUDSTACK-1968: affinity_groups: Column 'deployment planner' cannot be null when creating a service offering

Added default value to all constructors..


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

Branch: refs/heads/master
Commit: 7201eb9ee492e3faad5c70db81906fa32e1861bb
Parents: 943aef7
Author: Prachi Damle <pr...@cloud.com>
Authored: Mon Apr 8 11:04:01 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:23:37 2013 -0700

----------------------------------------------------------------------
 .../src/com/cloud/service/ServiceOfferingVO.java   |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7201eb9e/server/src/com/cloud/service/ServiceOfferingVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/service/ServiceOfferingVO.java b/server/src/com/cloud/service/ServiceOfferingVO.java
index 40f817d..a3da904 100755
--- a/server/src/com/cloud/service/ServiceOfferingVO.java
+++ b/server/src/com/cloud/service/ServiceOfferingVO.java
@@ -87,6 +87,7 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
         this.volatileVm = false;
         this.default_use = defaultUse;
         this.vm_type = vm_type == null ? null : vm_type.toString().toLowerCase();
+        this.deploymentPlanner = "FirstFitPlanner";
     }
 
     public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA, boolean limitCpuUse, boolean volatileVm, String displayText, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse, VirtualMachine.Type vm_type, Long domainId) {
@@ -100,11 +101,13 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
         this.limitCpuUse = limitCpuUse;
         this.volatileVm = volatileVm;
         this.vm_type = vm_type == null ? null : vm_type.toString().toLowerCase();
+        this.deploymentPlanner = "FirstFitPlanner";
     }
 
     public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA, boolean limitResourceUse, boolean volatileVm, String displayText, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse, VirtualMachine.Type vm_type, Long domainId, String hostTag) {
         this(name, cpu, ramSize, speed, rateMbps, multicastRateMbps, offerHA, limitResourceUse, volatileVm, displayText, useLocalStorage, recreatable, tags, systemUse, vm_type, domainId);
         this.hostTag = hostTag;
+        this.deploymentPlanner = "FirstFitPlanner";
     }
 
     public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, Integer rateMbps, Integer multicastRateMbps,
@@ -113,7 +116,11 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
             String hostTag, String deploymentPlanner) {
         this(name, cpu, ramSize, speed, rateMbps, multicastRateMbps, offerHA, limitResourceUse, volatileVm,
                 displayText, useLocalStorage, recreatable, tags, systemUse, vm_type, domainId, hostTag);
-        this.deploymentPlanner = deploymentPlanner;
+        if (deploymentPlanner != null) {
+            this.deploymentPlanner = deploymentPlanner;
+        } else {
+            this.deploymentPlanner = "FirstFitPlanner";
+        }
     }
 
     @Override


[06/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
Changes to add AffinityGroupprocessor, deployVM changes


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

Branch: refs/heads/master
Commit: fe2a86871fde27832b8ed99f5fe965b905b874c0
Parents: 1aed5bf
Author: Prachi Damle <pr...@cloud.com>
Authored: Wed Mar 13 13:57:47 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:22:42 2013 -0700

----------------------------------------------------------------------
 api/src/com/cloud/event/EventTypes.java            |    1 +
 .../cloud/exception/AffinityConflictException.java |   18 ++
 api/src/com/cloud/vm/UserVmService.java            |  183 ++++++++-------
 .../affinity/AffinityGroupProcessor.java           |   14 ++
 .../cloudstack/affinity/AffinityGroupService.java  |    3 +
 .../org/apache/cloudstack/api/ApiConstants.java    |    2 +
 .../user/affinitygroup/ListAffinityGroupsCmd.java  |    3 +-
 .../affinitygroup/UpdateVMAffinityGroupCmd.java    |  158 +++++++++++++
 .../api/command/user/vm/DeployVMCmd.java           |   43 ++++-
 .../deploy/UserPreferrenceProcessor.java           |   27 +++
 .../cloud/deploy/DeploymentPlanningManager.java    |   29 +++
 .../deploy/DeploymentPlanningManagerImpl.java      |   80 +++++++
 server/src/com/cloud/vm/UserVmManagerImpl.java     |   62 ++++--
 .../com/cloud/vm/VirtualMachineManagerImpl.java    |   97 ++++----
 .../affinity/AffinityGroupServiceImpl.java         |   71 +++++-
 .../affinity/HostAntiAffinityProcessor.java        |   66 ++++++
 .../affinity/dao/AffinityGroupVMMapDao.java        |    4 +
 .../affinity/dao/AffinityGroupVMMapDaoImpl.java    |   43 ++++
 .../test/com/cloud/vm/MockUserVmManagerImpl.java   |   16 +-
 utils/src/com/cloud/utils/SerialVersionUID.java    |    1 +
 20 files changed, 755 insertions(+), 166 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe2a8687/api/src/com/cloud/event/EventTypes.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/event/EventTypes.java b/api/src/com/cloud/event/EventTypes.java
index bd5f220..6a26212 100755
--- a/api/src/com/cloud/event/EventTypes.java
+++ b/api/src/com/cloud/event/EventTypes.java
@@ -386,6 +386,7 @@ public class EventTypes {
     public static final String EVENT_AFFINITY_GROUP_DELETE = "AG.DELETE";
     public static final String EVENT_AFFINITY_GROUP_ASSIGN = "AG.ASSIGN";
     public static final String EVENT_AFFINITY_GROUP_REMOVE = "AG.REMOVE";
+    public static final String EVENT_VM_AFFINITY_GROUP_UPDATE = "VM.AG.UPDATE";
 
     static {
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe2a8687/api/src/com/cloud/exception/AffinityConflictException.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/exception/AffinityConflictException.java b/api/src/com/cloud/exception/AffinityConflictException.java
new file mode 100644
index 0000000..75df784
--- /dev/null
+++ b/api/src/com/cloud/exception/AffinityConflictException.java
@@ -0,0 +1,18 @@
+package com.cloud.exception;
+
+import com.cloud.exception.CloudException;
+import com.cloud.utils.SerialVersionUID;
+
+public class AffinityConflictException extends CloudException {
+
+    private static final long serialVersionUID = SerialVersionUID.AffinityConflictException;
+
+    public AffinityConflictException(String message) {
+        super(message);
+    }
+
+    public AffinityConflictException(String message, Throwable th) {
+        super(message, th);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe2a8687/api/src/com/cloud/vm/UserVmService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/vm/UserVmService.java b/api/src/com/cloud/vm/UserVmService.java
index 2c33d41..d963b74 100755
--- a/api/src/com/cloud/vm/UserVmService.java
+++ b/api/src/com/cloud/vm/UserVmService.java
@@ -26,9 +26,6 @@ import org.apache.cloudstack.api.command.admin.vm.RecoverVMCmd;
 import org.apache.cloudstack.api.command.user.vm.*;
 import org.apache.cloudstack.api.command.user.vmgroup.CreateVMGroupCmd;
 import org.apache.cloudstack.api.command.user.vmgroup.DeleteVMGroupCmd;
-import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd;
-import org.apache.cloudstack.api.command.user.volume.DetachVolumeCmd;
-
 import com.cloud.dc.DataCenter;
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.InsufficientCapacityException;
@@ -42,7 +39,6 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.network.Network.IpAddresses;
 import com.cloud.offering.ServiceOffering;
 import com.cloud.storage.StoragePool;
-import com.cloud.storage.Volume;
 import com.cloud.template.VirtualMachineTemplate;
 import com.cloud.user.Account;
 import com.cloud.uservm.UserVm;
@@ -104,14 +100,14 @@ public interface UserVmService {
      * @return the vm object if successful, null otherwise
      */
     UserVm addNicToVirtualMachine(AddNicToVMCmd cmd);
-    
+
     /**
      * Removes a NIC on the given network from the virtual machine
      * @param cmd the command object that defines the vm and the given network
      * @return the vm object if successful, null otherwise
      */
     UserVm removeNicFromVirtualMachine(RemoveNicFromVMCmd cmd);
-    
+
     /**
      * Updates default Nic to the given network for given virtual machine
      * @param cmd the command object that defines the vm and the given network
@@ -123,7 +119,8 @@ public interface UserVmService {
 
 
     /**
-     * Creates a Basic Zone User VM in the database and returns the VM to the caller.
+     * Creates a Basic Zone User VM in the database and returns the VM to the
+     * caller.
      *
      * @param zone
      *            - availability zone for the virtual machine
@@ -132,61 +129,69 @@ public interface UserVmService {
      * @param template
      *            - the template for the virtual machine
      * @param securityGroupIdList
-     *            - comma separated list of security groups id that going to be applied to the virtual machine
+     *            - comma separated list of security groups id that going to be
+     *            applied to the virtual machine
      * @param hostName
      *            - host name for the virtual machine
      * @param displayName
      *            - an optional user generated name for the virtual machine
      * @param diskOfferingId
-     *            - the ID of the disk offering for the virtual machine. If the template is of ISO format, the
-     *            diskOfferingId is
-     *            for the root disk volume. Otherwise this parameter is used to indicate the offering for the data disk
-     *            volume.
-     *            If the templateId parameter passed is from a Template object, the diskOfferingId refers to a DATA Disk
-     *            Volume
-     *            created. If the templateId parameter passed is from an ISO object, the diskOfferingId refers to a ROOT
-     *            Disk
-     *            Volume created
+     *            - the ID of the disk offering for the virtual machine. If the
+     *            template is of ISO format, the diskOfferingId is for the root
+     *            disk volume. Otherwise this parameter is used to indicate the
+     *            offering for the data disk volume. If the templateId parameter
+     *            passed is from a Template object, the diskOfferingId refers to
+     *            a DATA Disk Volume created. If the templateId parameter passed
+     *            is from an ISO object, the diskOfferingId refers to a ROOT
+     *            Disk Volume created
      * @param diskSize
-     *            - the arbitrary size for the DATADISK volume. Mutually exclusive with diskOfferingId
+     *            - the arbitrary size for the DATADISK volume. Mutually
+     *            exclusive with diskOfferingId
      * @param group
      *            - an optional group for the virtual machine
      * @param hypervisor
      *            - the hypervisor on which to deploy the virtual machine
      * @param userData
-     *            - an optional binary data that can be sent to the virtual machine upon a successful deployment. This
-     *            binary
-     *            data must be base64 encoded before adding it to the request. Currently only HTTP GET is supported.
-     *            Using HTTP
-     *            GET (via querystring), you can send up to 2KB of data after base64 encoding
+     *            - an optional binary data that can be sent to the virtual
+     *            machine upon a successful deployment. This binary data must be
+     *            base64 encoded before adding it to the request. Currently only
+     *            HTTP GET is supported. Using HTTP GET (via querystring), you
+     *            can send up to 2KB of data after base64 encoding
      * @param sshKeyPair
-     *            - name of the ssh key pair used to login to the virtual machine
+     *            - name of the ssh key pair used to login to the virtual
+     *            machine
      * @param requestedIps
      *            TODO
      * @param defaultIp
      *            TODO
+     * @param affinityGroupIdList
      * @param accountName
-     *            - an optional account for the virtual machine. Must be used with domainId
+     *            - an optional account for the virtual machine. Must be used
+     *            with domainId
      * @param domainId
-     *            - an optional domainId for the virtual machine. If the account parameter is used, domainId must also
-     *            be used
+     *            - an optional domainId for the virtual machine. If the account
+     *            parameter is used, domainId must also be used
      * @return UserVm object if successful.
      *
      * @throws InsufficientCapacityException
      *             if there is insufficient capacity to deploy the VM.
      * @throws ConcurrentOperationException
-     *             if there are multiple users working on the same VM or in the same environment.
+     *             if there are multiple users working on the same VM or in the
+     *             same environment.
      * @throws ResourceUnavailableException
-     *             if the resources required to deploy the VM is not currently available.
+     *             if the resources required to deploy the VM is not currently
+     *             available.
      * @throws InsufficientResourcesException
      */
     UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> securityGroupIdList, Account owner, String hostName,
-            String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, String userData, String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIp, String keyboard)
+            String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor,
+            String userData, String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIp,
+            String keyboard, List<Long> affinityGroupIdList)
             throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException;
 
     /**
-     * Creates a User VM in Advanced Zone (Security Group feature is enabled) in the database and returns the VM to the
-     * caller.
+     * Creates a User VM in Advanced Zone (Security Group feature is enabled) in
+     * the database and returns the VM to the caller.
      *
      * @param zone
      *            - availability zone for the virtual machine
@@ -197,63 +202,69 @@ public interface UserVmService {
      * @param networkIdList
      *            - list of network ids used by virtual machine
      * @param securityGroupIdList
-     *            - comma separated list of security groups id that going to be applied to the virtual machine
+     *            - comma separated list of security groups id that going to be
+     *            applied to the virtual machine
      * @param hostName
      *            - host name for the virtual machine
      * @param displayName
      *            - an optional user generated name for the virtual machine
      * @param diskOfferingId
-     *            - the ID of the disk offering for the virtual machine. If the template is of ISO format, the
-     *            diskOfferingId is
-     *            for the root disk volume. Otherwise this parameter is used to indicate the offering for the data disk
-     *            volume.
-     *            If the templateId parameter passed is from a Template object, the diskOfferingId refers to a DATA Disk
-     *            Volume
-     *            created. If the templateId parameter passed is from an ISO object, the diskOfferingId refers to a ROOT
-     *            Disk
-     *            Volume created
+     *            - the ID of the disk offering for the virtual machine. If the
+     *            template is of ISO format, the diskOfferingId is for the root
+     *            disk volume. Otherwise this parameter is used to indicate the
+     *            offering for the data disk volume. If the templateId parameter
+     *            passed is from a Template object, the diskOfferingId refers to
+     *            a DATA Disk Volume created. If the templateId parameter passed
+     *            is from an ISO object, the diskOfferingId refers to a ROOT
+     *            Disk Volume created
      * @param diskSize
-     *            - the arbitrary size for the DATADISK volume. Mutually exclusive with diskOfferingId
+     *            - the arbitrary size for the DATADISK volume. Mutually
+     *            exclusive with diskOfferingId
      * @param group
      *            - an optional group for the virtual machine
      * @param hypervisor
      *            - the hypervisor on which to deploy the virtual machine
      * @param userData
-     *            - an optional binary data that can be sent to the virtual machine upon a successful deployment. This
-     *            binary
-     *            data must be base64 encoded before adding it to the request. Currently only HTTP GET is supported.
-     *            Using HTTP
-     *            GET (via querystring), you can send up to 2KB of data after base64 encoding
+     *            - an optional binary data that can be sent to the virtual
+     *            machine upon a successful deployment. This binary data must be
+     *            base64 encoded before adding it to the request. Currently only
+     *            HTTP GET is supported. Using HTTP GET (via querystring), you
+     *            can send up to 2KB of data after base64 encoding
      * @param sshKeyPair
-     *            - name of the ssh key pair used to login to the virtual machine
+     *            - name of the ssh key pair used to login to the virtual
+     *            machine
      * @param requestedIps
      *            TODO
      * @param defaultIps
      *            TODO
+     * @param affinityGroupIdList
      * @param accountName
-     *            - an optional account for the virtual machine. Must be used with domainId
+     *            - an optional account for the virtual machine. Must be used
+     *            with domainId
      * @param domainId
-     *            - an optional domainId for the virtual machine. If the account parameter is used, domainId must also
-     *            be used
+     *            - an optional domainId for the virtual machine. If the account
+     *            parameter is used, domainId must also be used
      * @return UserVm object if successful.
      *
      * @throws InsufficientCapacityException
      *             if there is insufficient capacity to deploy the VM.
      * @throws ConcurrentOperationException
-     *             if there are multiple users working on the same VM or in the same environment.
+     *             if there are multiple users working on the same VM or in the
+     *             same environment.
      * @throws ResourceUnavailableException
-     *             if the resources required to deploy the VM is not currently available.
+     *             if the resources required to deploy the VM is not currently
+     *             available.
      * @throws InsufficientResourcesException
      */
     UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList, List<Long> securityGroupIdList,
             Account owner, String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, String userData, String sshKeyPair, Map<Long, IpAddresses> requestedIps,
-            IpAddresses defaultIps, String keyboard)
+            IpAddresses defaultIps, String keyboard, List<Long> affinityGroupIdList)
             throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException;
 
     /**
-     * Creates a User VM in Advanced Zone (Security Group feature is disabled) in the database and returns the VM to the
-     * caller.
-     *
+     * Creates a User VM in Advanced Zone (Security Group feature is disabled)
+     * in the database and returns the VM to the caller.
+     * 
      * @param zone
      *            - availability zone for the virtual machine
      * @param serviceOffering
@@ -267,49 +278,57 @@ public interface UserVmService {
      * @param displayName
      *            - an optional user generated name for the virtual machine
      * @param diskOfferingId
-     *            - the ID of the disk offering for the virtual machine. If the template is of ISO format, the
-     *            diskOfferingId is
-     *            for the root disk volume. Otherwise this parameter is used to indicate the offering for the data disk
-     *            volume.
-     *            If the templateId parameter passed is from a Template object, the diskOfferingId refers to a DATA Disk
-     *            Volume
-     *            created. If the templateId parameter passed is from an ISO object, the diskOfferingId refers to a ROOT
-     *            Disk
-     *            Volume created
+     *            - the ID of the disk offering for the virtual machine. If the
+     *            template is of ISO format, the diskOfferingId is for the root
+     *            disk volume. Otherwise this parameter is used to indicate the
+     *            offering for the data disk volume. If the templateId parameter
+     *            passed is from a Template object, the diskOfferingId refers to
+     *            a DATA Disk Volume created. If the templateId parameter passed
+     *            is from an ISO object, the diskOfferingId refers to a ROOT
+     *            Disk Volume created
      * @param diskSize
-     *            - the arbitrary size for the DATADISK volume. Mutually exclusive with diskOfferingId
+     *            - the arbitrary size for the DATADISK volume. Mutually
+     *            exclusive with diskOfferingId
      * @param group
      *            - an optional group for the virtual machine
      * @param hypervisor
      *            - the hypervisor on which to deploy the virtual machine
      * @param userData
-     *            - an optional binary data that can be sent to the virtual machine upon a successful deployment. This
-     *            binary
-     *            data must be base64 encoded before adding it to the request. Currently only HTTP GET is supported.
-     *            Using HTTP
-     *            GET (via querystring), you can send up to 2KB of data after base64 encoding
+     *            - an optional binary data that can be sent to the virtual
+     *            machine upon a successful deployment. This binary data must be
+     *            base64 encoded before adding it to the request. Currently only
+     *            HTTP GET is supported. Using HTTP GET (via querystring), you
+     *            can send up to 2KB of data after base64 encoding
      * @param sshKeyPair
-     *            - name of the ssh key pair used to login to the virtual machine
+     *            - name of the ssh key pair used to login to the virtual
+     *            machine
      * @param requestedIps
      *            TODO
-     * @param defaultIps TODO
+     * @param defaultIps
+     *            TODO
+     * @param affinityGroupIdList
      * @param accountName
-     *            - an optional account for the virtual machine. Must be used with domainId
+     *            - an optional account for the virtual machine. Must be used
+     *            with domainId
      * @param domainId
-     *            - an optional domainId for the virtual machine. If the account parameter is used, domainId must also
-     *            be used
+     *            - an optional domainId for the virtual machine. If the account
+     *            parameter is used, domainId must also be used
      * @return UserVm object if successful.
-     *
+     * 
      * @throws InsufficientCapacityException
      *             if there is insufficient capacity to deploy the VM.
      * @throws ConcurrentOperationException
-     *             if there are multiple users working on the same VM or in the same environment.
+     *             if there are multiple users working on the same VM or in the
+     *             same environment.
      * @throws ResourceUnavailableException
-     *             if the resources required to deploy the VM is not currently available.
+     *             if the resources required to deploy the VM is not currently
+     *             available.
      * @throws InsufficientResourcesException
      */
     UserVm createAdvancedVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList, Account owner, String hostName,
-            String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, String userData, String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps, String keyboard)
+            String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor,
+            String userData, String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps,
+            String keyboard, List<Long> affinityGroupIdList)
             throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException;
 
     /**

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe2a8687/api/src/org/apache/cloudstack/affinity/AffinityGroupProcessor.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/affinity/AffinityGroupProcessor.java b/api/src/org/apache/cloudstack/affinity/AffinityGroupProcessor.java
new file mode 100644
index 0000000..e6c64b3
--- /dev/null
+++ b/api/src/org/apache/cloudstack/affinity/AffinityGroupProcessor.java
@@ -0,0 +1,14 @@
+package org.apache.cloudstack.affinity;
+
+import org.apache.cloudstack.deploy.UserPreferrenceProcessor;
+
+public interface AffinityGroupProcessor extends UserPreferrenceProcessor {
+
+    /**
+     * getType() should return the affinity/anti-affinity group being
+     * implemented
+     *
+     * @return String Affinity/Anti-affinity type
+     */
+    String getType();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe2a8687/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java b/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java
index 368abe2..b6bf2ab 100644
--- a/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java
+++ b/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java
@@ -3,6 +3,7 @@ package org.apache.cloudstack.affinity;
 import java.util.List;
 
 import com.cloud.exception.ResourceInUseException;
+import com.cloud.uservm.UserVm;
 import com.cloud.utils.Pair;
 
 public interface AffinityGroupService {
@@ -57,4 +58,6 @@ public interface AffinityGroupService {
 
     AffinityGroup getAffinityGroup(Long groupId);
 
+    UserVm updateVMAffinityGroups(Long vmId, List<Long> affinityGroupIds);
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe2a8687/api/src/org/apache/cloudstack/api/ApiConstants.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java
index c518830..cfabc61 100755
--- a/api/src/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/org/apache/cloudstack/api/ApiConstants.java
@@ -473,6 +473,8 @@ public class ApiConstants {
     public static final String HEALTHCHECK_HEALTHY_THRESHOLD = "healthythreshold";
     public static final String HEALTHCHECK_UNHEALTHY_THRESHOLD = "unhealthythreshold";
     public static final String HEALTHCHECK_PINGPATH = "pingpath";
+    public static final String AFFINITY_GROUP_IDS = "affinitygroupids";
+    public static final String AFFINITY_GROUP_NAMES = "affinitygroupnames";
 
     public enum HostDetails {
         all, capacity, events, stats, min;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe2a8687/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java
index 09d1f8f..effbd86 100644
--- a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java
@@ -83,7 +83,8 @@ public class ListAffinityGroupsCmd extends BaseListCmd {
     @Override
     public void execute(){
 
-        Pair<List<AffinityGroup>, Integer> result = _affinityGroupService.listAffinityGroups(id, affinityGroupName,
+        Pair<List<? extends AffinityGroup>, Integer> result = _affinityGroupService.listAffinityGroups(id,
+                affinityGroupName,
                 affinityGroupType, virtualMachineId, this.getStartIndex(), this.getPageSizeVal());
         if (result != null) {
             ListResponse<AffinityGroupResponse> response = new ListResponse<AffinityGroupResponse>();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe2a8687/api/src/org/apache/cloudstack/api/command/user/affinitygroup/UpdateVMAffinityGroupCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/UpdateVMAffinityGroupCmd.java b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/UpdateVMAffinityGroupCmd.java
new file mode 100644
index 0000000..94f8446
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/UpdateVMAffinityGroupCmd.java
@@ -0,0 +1,158 @@
+// 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 org.apache.cloudstack.api.command.user.affinitygroup;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.cloudstack.affinity.AffinityGroupResponse;
+import org.apache.cloudstack.api.ACL;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.UserVmResponse;
+import org.apache.log4j.Logger;
+
+import com.cloud.async.AsyncJob;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+import com.cloud.uservm.UserVm;
+
+
+@APICommand(name = "updateVMAffinityGroup", description = "Updates the affinity/anti-affinity group associations of a virtual machine. The VM has to be stopped and restarted for the "
+        + "new properties to take effect.", responseObject = UserVmResponse.class)
+public class UpdateVMAffinityGroupCmd extends BaseAsyncCmd {
+    public static final Logger s_logger = Logger.getLogger(UpdateVMAffinityGroupCmd.class.getName());
+    private static final String s_name = "updatevirtualmachineresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+
+    @ACL
+    @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=UserVmResponse.class,
+            required=true, description="The ID of the virtual machine")
+    private Long id;
+
+    @ACL
+    @Parameter(name = ApiConstants.AFFINITY_GROUP_IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = AffinityGroupResponse.class, description = "comma separated list of affinity groups id that are going to be applied to the virtual machine. "
+            + "Should be passed only when vm is created from a zone with Basic Network support."
+            + " Mutually exclusive with securitygroupnames parameter")
+    private List<Long> affinityGroupIdList;
+
+    @ACL
+    @Parameter(name = ApiConstants.AFFINITY_GROUP_NAMES, type = CommandType.LIST, collectionType = CommandType.STRING, entityType = AffinityGroupResponse.class, description = "comma separated list of affinity groups names that are going to be applied to the virtual machine."
+            + " Should be passed only when vm is created from a zone with Basic Network support. "
+            + "Mutually exclusive with securitygroupids parameter")
+    private List<String> affinityGroupNameList;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+
+    public Long getId() {
+        return id;
+    }
+
+
+    public List<Long> getAffinityGroupIdList() {
+        if (affinityGroupNameList != null && affinityGroupIdList != null) {
+            throw new InvalidParameterValueException(
+                    "affinitygroupids parameter is mutually exclusive with affinitygroupnames parameter");
+        }
+
+        // transform group names to ids here
+        if (affinityGroupNameList != null) {
+            List<Long> affinityGroupIds = new ArrayList<Long>();
+            for (String groupName : affinityGroupNameList) {
+                Long groupId = _responseGenerator.getAffinityGroupId(groupName, getEntityOwnerId());
+                if (groupId == null) {
+                    throw new InvalidParameterValueException("Unable to find group by name " + groupName
+                            + " for account " + getEntityOwnerId());
+                } else {
+                    affinityGroupIds.add(groupId);
+                }
+            }
+            return affinityGroupIds;
+        } else {
+            return affinityGroupIdList;
+        }
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    public static String getResultObjectName() {
+        return "virtualmachine";
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        UserVm userVm = _entityMgr.findById(UserVm.class, getId());
+        if (userVm != null) {
+            return userVm.getAccountId();
+        }
+
+        return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+    }
+
+    @Override
+    public void execute() throws ResourceUnavailableException,
+            InsufficientCapacityException, ServerApiException {
+        UserContext.current().setEventDetails("Vm Id: "+getId());
+        UserVm result = _affinityGroupService.updateVMAffinityGroups(getId(), getAffinityGroupIdList());
+        if (result != null){
+            UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
+            response.setResponseName(getCommandName());
+            this.setResponseObject(response);
+        } else {
+            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update vm's affinity groups");
+        }
+    }
+
+    @Override
+    public String getEventType() {
+        return EventTypes.EVENT_VM_AFFINITY_GROUP_UPDATE;
+    }
+
+    @Override
+    public String getEventDescription() {
+        return "updating VM Affinity Group";
+    }
+
+    @Override
+    public AsyncJob.Type getInstanceType() {
+        return AsyncJob.Type.AffinityGroup;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe2a8687/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
index 21a45f8..22fe1ba 100755
--- a/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
@@ -25,6 +25,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.cloudstack.acl.SecurityChecker.AccessType;
+import org.apache.cloudstack.affinity.AffinityGroupResponse;
 import org.apache.cloudstack.api.ACL;
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
@@ -172,6 +173,18 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
     @Parameter(name=ApiConstants.START_VM, type=CommandType.BOOLEAN, description="true if network offering supports specifying ip ranges; defaulted to true if not specified")
     private Boolean startVm;
 
+    @ACL
+    @Parameter(name = ApiConstants.AFFINITY_GROUP_IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = AffinityGroupResponse.class, description = "comma separated list of affinity groups id that are going to be applied to the virtual machine. "
+            + "Should be passed only when vm is created from a zone with Basic Network support."
+            + " Mutually exclusive with securitygroupnames parameter")
+    private List<Long> affinityGroupIdList;
+
+    @ACL
+    @Parameter(name = ApiConstants.AFFINITY_GROUP_NAMES, type = CommandType.LIST, collectionType = CommandType.STRING, entityType = AffinityGroupResponse.class, description = "comma separated list of affinity groups names that are going to be applied to the virtual machine."
+            + " Should be passed only when vm is created from a zone with Basic Network support. "
+            + "Mutually exclusive with securitygroupids parameter")
+    private List<String> affinityGroupNameList;
+
 
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
@@ -321,6 +334,30 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
 		return ip6Address.toLowerCase();
 	}
 
+    public List<Long> getAffinityGroupIdList() {
+        if (affinityGroupNameList != null && affinityGroupIdList != null) {
+            throw new InvalidParameterValueException(
+                    "affinitygroupids parameter is mutually exclusive with affinitygroupnames parameter");
+        }
+
+        // transform group names to ids here
+        if (affinityGroupNameList != null) {
+            List<Long> affinityGroupIds = new ArrayList<Long>();
+            for (String groupName : affinityGroupNameList) {
+                Long groupId = _responseGenerator.getAffinityGroupId(groupName, getEntityOwnerId());
+                if (groupId == null) {
+                    throw new InvalidParameterValueException("Unable to find group by name " + groupName
+                            + " for account " + getEntityOwnerId());
+                } else {
+                    affinityGroupIds.add(groupId);
+                }
+            }
+            return affinityGroupIds;
+        } else {
+            return affinityGroupIdList;
+        }
+    }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
@@ -447,18 +484,18 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
                     throw new InvalidParameterValueException("Can't specify network Ids in Basic zone");
                 } else {
                     vm = _userVmService.createBasicSecurityGroupVirtualMachine(zone, serviceOffering, template, getSecurityGroupIdList(), owner, name,
-                                displayName, diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap(), addrs, keyboard);
+                                displayName, diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap(), addrs, keyboard, getAffinityGroupIdList());
                 }
             } else {
                 if (zone.isSecurityGroupEnabled())  {
                     vm = _userVmService.createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, template, getNetworkIds(), getSecurityGroupIdList(),
-                                owner, name, displayName, diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap(), addrs, keyboard);
+                                owner, name, displayName, diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap(), addrs, keyboard, getAffinityGroupIdList());
                 } else {
                     if (getSecurityGroupIdList() != null && !getSecurityGroupIdList().isEmpty()) {
                         throw new InvalidParameterValueException("Can't create vm with security groups; security group feature is not enabled per zone");
                     }
                     vm = _userVmService.createAdvancedVirtualMachine(zone, serviceOffering, template, getNetworkIds(), owner, name, displayName,
-                                diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap(), addrs, keyboard);
+                                diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap(), addrs, keyboard, getAffinityGroupIdList());
                 }
             }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe2a8687/api/src/org/apache/cloudstack/deploy/UserPreferrenceProcessor.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/deploy/UserPreferrenceProcessor.java b/api/src/org/apache/cloudstack/deploy/UserPreferrenceProcessor.java
new file mode 100644
index 0000000..ad26f0e
--- /dev/null
+++ b/api/src/org/apache/cloudstack/deploy/UserPreferrenceProcessor.java
@@ -0,0 +1,27 @@
+package org.apache.cloudstack.deploy;
+
+
+import com.cloud.deploy.DeploymentPlan;
+import com.cloud.deploy.DeploymentPlanner.ExcludeList;
+import com.cloud.exception.AffinityConflictException;
+import com.cloud.utils.component.Adapter;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.VirtualMachineProfile;
+
+public interface UserPreferrenceProcessor extends Adapter {
+
+    /**
+     * process() is called to apply any user preferences to the deployment plan
+     * and avoid set for the given VM placement.
+     *
+     * @param vm
+     *            virtual machine.
+     * @param plan
+     *            deployment plan that tells you where it's being deployed to.
+     * @param avoid
+     *            avoid these data centers, pods, clusters, or hosts.
+     */
+    void process(VirtualMachineProfile<? extends VirtualMachine> vm, DeploymentPlan plan, ExcludeList avoid)
+            throws AffinityConflictException;
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe2a8687/server/src/com/cloud/deploy/DeploymentPlanningManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/deploy/DeploymentPlanningManager.java b/server/src/com/cloud/deploy/DeploymentPlanningManager.java
new file mode 100644
index 0000000..4ac71e3
--- /dev/null
+++ b/server/src/com/cloud/deploy/DeploymentPlanningManager.java
@@ -0,0 +1,29 @@
+package com.cloud.deploy;
+
+import com.cloud.deploy.DeploymentPlanner.ExcludeList;
+import com.cloud.exception.AffinityConflictException;
+import com.cloud.exception.InsufficientServerCapacityException;
+import com.cloud.utils.component.Manager;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.VirtualMachineProfile;
+
+public interface DeploymentPlanningManager extends Manager {
+
+    /**
+     * Manages vm deployment stages: First Process Affinity/Anti-affinity - Call
+     * the chain of AffinityGroupProcessor adapters to set deploymentplan scope
+     * and exclude list Secondly, Call DeploymentPlanner - to use heuristics to
+     * find the best spot to place the vm/volume. Planner will drill down to the
+     * write set of clusters to look for placement based on various heuristics.
+     * Lastly, Call Allocators - Given a cluster, allocators matches the
+     * requirements to capabilities of the physical resource (host, storage
+     * pool).
+     *
+     * @throws AffinityConflictException
+     *
+     *
+     *
+     */
+    DeployDestination planDeployment(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan,
+            ExcludeList avoids) throws InsufficientServerCapacityException, AffinityConflictException;
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe2a8687/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java b/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java
new file mode 100644
index 0000000..11e5b82
--- /dev/null
+++ b/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java
@@ -0,0 +1,80 @@
+package com.cloud.deploy;
+
+import java.util.List;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.apache.cloudstack.affinity.AffinityGroupProcessor;
+import org.apache.cloudstack.affinity.AffinityGroupVMMapVO;
+import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
+import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
+import org.apache.log4j.Logger;
+
+import com.cloud.deploy.DeploymentPlanner.ExcludeList;
+import com.cloud.exception.AffinityConflictException;
+import com.cloud.exception.InsufficientServerCapacityException;
+import com.cloud.utils.component.Manager;
+import com.cloud.utils.component.ManagerBase;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.VirtualMachineProfile;
+import com.cloud.vm.dao.UserVmDao;
+import com.cloud.vm.dao.VMInstanceDao;
+
+@Local(value = { DeploymentPlanningManager.class })
+public class DeploymentPlanningManagerImpl extends ManagerBase implements DeploymentPlanningManager, Manager {
+
+    private static final Logger s_logger = Logger.getLogger(DeploymentPlanningManagerImpl.class);
+    @Inject
+    protected UserVmDao _vmDao;
+    @Inject
+    protected VMInstanceDao _vmInstanceDao;
+    @Inject
+    protected AffinityGroupDao _affinityGroupDao;
+    @Inject
+    protected AffinityGroupVMMapDao _affinityGroupVMMapDao;
+
+    @Inject
+    protected List<DeploymentPlanner> _planners;
+
+    @Inject
+    protected List<AffinityGroupProcessor> _affinityProcessors;
+
+    @Override
+    public DeployDestination planDeployment(VirtualMachineProfile<? extends VirtualMachine> vmProfile,
+            DeploymentPlan plan, ExcludeList avoids) throws InsufficientServerCapacityException,
+            AffinityConflictException {
+
+        // call affinitygroup chain
+        VirtualMachine vm = vmProfile.getVirtualMachine();
+        long vmGroupCount = _affinityGroupVMMapDao.countAffinityGroupsForVm(vm.getId());
+
+        if (vmGroupCount > 0) {
+            for (AffinityGroupProcessor processor : _affinityProcessors) {
+                processor.process(vmProfile, plan, avoids);
+            }
+        }
+
+        if (s_logger.isDebugEnabled()) {
+            s_logger.debug("Deploy avoids pods: " + avoids.getPodsToAvoid() + ", clusters: "
+                    + avoids.getClustersToAvoid() + ", hosts: " + avoids.getHostsToAvoid());
+        }
+
+        // call planners
+        DeployDestination dest = null;
+        for (DeploymentPlanner planner : _planners) {
+            if (planner.canHandle(vmProfile, plan, avoids)) {
+                dest = planner.plan(vmProfile, plan, avoids);
+            } else {
+                continue;
+            }
+            if (dest != null) {
+                avoids.addHost(dest.getHost().getId());
+                break;
+            }
+
+        }
+        return dest;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe2a8687/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java
index 1c3764a..ca158f1 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -35,6 +35,9 @@ import javax.naming.ConfigurationException;
 import com.cloud.api.ApiDBUtils;
 import org.apache.cloudstack.acl.ControlledEntity.ACLType;
 import org.apache.cloudstack.acl.SecurityChecker.AccessType;
+import org.apache.cloudstack.affinity.AffinityGroupVO;
+import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
+import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
 import org.apache.cloudstack.api.command.admin.vm.AssignVMCmd;
 import org.apache.cloudstack.api.command.admin.vm.RecoverVMCmd;
 import org.apache.cloudstack.api.command.user.vm.*;
@@ -369,7 +372,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
     VpcManager _vpcMgr;
     @Inject
     TemplateManager templateMgr;
-    @Inject 
+    @Inject
     protected GuestOSCategoryDao _guestOSCategoryDao;
     @Inject
     UsageEventDao _usageEventDao;
@@ -379,6 +382,11 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
     protected VMSnapshotManager _vmSnapshotMgr;
 
     @Inject
+    AffinityGroupVMMapDao _affinityGroupVMMapDao;
+    @Inject
+    AffinityGroupDao _affinityGroupDao;
+
+    @Inject
     List<DeployPlannerSelector> plannerSelectors;
 
     protected ScheduledExecutorService _executor = null;
@@ -684,7 +692,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
 
         try {
             VirtualMachineEntity vmEntity = _orchSrvc.getVirtualMachine(vm.getUuid());
-            status = vmEntity.stop(new Long(userId).toString());            
+            status = vmEntity.stop(new Long(userId).toString());
         } catch (ResourceUnavailableException e) {
             s_logger.debug("Unable to stop due to ", e);
             status = false;
@@ -1916,7 +1924,10 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
 
     @Override
     public UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> securityGroupIdList, Account owner,
-            String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, String userData, String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps, String keyboard)
+ String hostName,
+            String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor,
+            String userData, String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps,
+            String keyboard, List<Long> affinityGroupIdList)
                     throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException {
 
         Account caller = UserContext.current().getCaller();
@@ -1966,13 +1977,17 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
         }
 
         return createVirtualMachine(zone, serviceOffering, template, hostName, displayName, owner, diskOfferingId,
-                diskSize, networkList, securityGroupIdList, group, userData, sshKeyPair, hypervisor, caller, requestedIps, defaultIps, keyboard);
+                diskSize, networkList, securityGroupIdList, group, userData, sshKeyPair, hypervisor, caller,
+                requestedIps, defaultIps, keyboard, affinityGroupIdList);
     }
 
     @Override
     public UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList,
             List<Long> securityGroupIdList, Account owner, String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, String userData,
-            String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps, String keyboard) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException,
+ String sshKeyPair, Map<Long, IpAddresses> requestedIps,
+            IpAddresses defaultIps, String keyboard, List<Long> affinityGroupIdList)
+            throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException,
+            StorageUnavailableException,
             ResourceAllocationException {
 
         Account caller = UserContext.current().getCaller();
@@ -2018,7 +2033,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
             isSecurityGroupEnabledNetworkUsed = true;
 
         } else {
-            // Verify that all the networks are Shared/Guest; can't create combination of SG enabled and disabled networks 
+            // Verify that all the networks are Shared/Guest; can't create combination of SG enabled and disabled networks
             for (Long networkId : networkIdList) {
                 NetworkVO network = _networkDao.findById(networkId);
 
@@ -2034,7 +2049,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
                     }
 
                     isSecurityGroupEnabledNetworkUsed = true;
-                }            
+                }
 
                 if (!(network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Shared)) {
                     throw new InvalidParameterValueException("Can specify only Shared Guest networks when" +
@@ -2079,12 +2094,15 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
         }
 
         return createVirtualMachine(zone, serviceOffering, template, hostName, displayName, owner, diskOfferingId,
-                diskSize, networkList, securityGroupIdList, group, userData, sshKeyPair, hypervisor, caller, requestedIps, defaultIps, keyboard);
+                diskSize, networkList, securityGroupIdList, group, userData, sshKeyPair, hypervisor, caller,
+                requestedIps, defaultIps, keyboard, affinityGroupIdList);
     }
 
     @Override
     public UserVm createAdvancedVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList, Account owner, String hostName,
-            String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, String userData, String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps, String keyboard)
+            String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor,
+            String userData, String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps,
+            String keyboard, List<Long> affinityGroupIdList)
                     throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException {
 
         Account caller = UserContext.current().getCaller();
@@ -2192,7 +2210,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
             }
         }
 
-        return createVirtualMachine(zone, serviceOffering, template, hostName, displayName, owner, diskOfferingId, diskSize, networkList, null, group, userData, sshKeyPair, hypervisor, caller, requestedIps, defaultIps, keyboard);
+        return createVirtualMachine(zone, serviceOffering, template, hostName, displayName, owner, diskOfferingId,
+                diskSize, networkList, null, group, userData, sshKeyPair, hypervisor, caller, requestedIps, defaultIps,
+                keyboard, affinityGroupIdList);
     }
 
 
@@ -2205,7 +2225,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
 
     @DB @ActionEvent(eventType = EventTypes.EVENT_VM_CREATE, eventDescription = "deploying Vm", create = true)
     protected UserVm createVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, String hostName, String displayName, Account owner, Long diskOfferingId,
-            Long diskSize, List<NetworkVO> networkList, List<Long> securityGroupIdList, String group, String userData, String sshKeyPair, HypervisorType hypervisor, Account caller, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps, String keyboard)
+            Long diskSize, List<NetworkVO> networkList, List<Long> securityGroupIdList, String group, String userData,
+            String sshKeyPair, HypervisorType hypervisor, Account caller, Map<Long, IpAddresses> requestedIps,
+            IpAddresses defaultIps, String keyboard, List<Long> affinityGroupIdList)
                     throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, StorageUnavailableException, ResourceAllocationException {
 
         _accountMgr.checkAccess(caller, null, true, owner);
@@ -2261,6 +2283,14 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
             }
         }
 
+        // check that the affinity groups exist
+        for (Long affinityGroupId : affinityGroupIdList) {
+            AffinityGroupVO ag = _affinityGroupDao.findById(affinityGroupId);
+            if (ag == null) {
+                throw new InvalidParameterValueException("Unable to find affinity group by id " + affinityGroupId);
+            }
+        }
+
         if (template.getHypervisorType() != null && template.getHypervisorType() != HypervisorType.BareMetal) {
             // check if we have available pools for vm deployment
             long availablePools = _storagePoolDao.countPoolsByStatus(StoragePoolStatus.Up);
@@ -2438,7 +2468,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
                     // * verify that there are no duplicates
                     if (hostNames.contains(hostName)) {
                         throw new InvalidParameterValueException("The vm with hostName " + hostName
-                                + " already exists in the network domain: " + ntwkDomain + "; network=" 
+                                + " already exists in the network domain: " + ntwkDomain + "; network="
                                 + _networkModel.getNetwork(ntwkId));
                     }
                 }
@@ -2510,7 +2540,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
         List<String> computeTags = new ArrayList<String>();
         computeTags.add(offering.getHostTag());
 
-        List<String> rootDiskTags =	new ArrayList<String>();    	
+        List<String> rootDiskTags =	new ArrayList<String>();
         rootDiskTags.add(offering.getTags());
 
         if(isIso){
@@ -2552,6 +2582,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
 
         _securityGroupMgr.addInstanceToGroups(vm.getId(), securityGroupIdList);
 
+        _affinityGroupVMMapDao.updateMap(vm.getId(), affinityGroupIdList);
+
         return vm;
     }
 
@@ -2829,7 +2861,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
 
         try {
             VirtualMachineEntity vmEntity = _orchSrvc.getVirtualMachine(vm.getUuid());
-            vmEntity.stop(new Long(userId).toString());            
+            vmEntity.stop(new Long(userId).toString());
         } catch (ResourceUnavailableException e) {
             throw new CloudRuntimeException(
                     "Unable to contact the agent to stop the virtual machine "
@@ -3044,7 +3076,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
 
         try {
             VirtualMachineEntity vmEntity = _orchSrvc.getVirtualMachine(vm.getUuid());
-            status = vmEntity.destroy(new Long(userId).toString());    
+            status = vmEntity.destroy(new Long(userId).toString());
         } catch (CloudException e) {
             CloudRuntimeException ex = new CloudRuntimeException(
                     "Unable to destroy with specified vmId", e);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe2a8687/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
index af22716..08c6e7c 100755
--- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -5,7 +5,7 @@
 // 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,
@@ -68,7 +68,9 @@ import com.cloud.deploy.DeployDestination;
 import com.cloud.deploy.DeploymentPlan;
 import com.cloud.deploy.DeploymentPlanner;
 import com.cloud.deploy.DeploymentPlanner.ExcludeList;
+import com.cloud.deploy.DeploymentPlanningManager;
 import com.cloud.domain.dao.DomainDao;
+import com.cloud.exception.AffinityConflictException;
 import com.cloud.exception.AgentUnavailableException;
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.ConnectionException;
@@ -226,8 +228,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 
 	@Inject
     protected ResourceManager _resourceMgr;
-    
-    @Inject 
+
+    @Inject
     protected VMSnapshotManager _vmSnapshotMgr = null;
     @Inject
     protected ClusterDetailsDao  _clusterDetailsDao;
@@ -239,6 +241,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
     @Inject
     VolumeManager volumeMgr;
 
+    @Inject
+    DeploymentPlanningManager _dpMgr;
+
     Map<VirtualMachine.Type, VirtualMachineGuru<? extends VMInstanceVO>> _vmGurus = new HashMap<VirtualMachine.Type, VirtualMachineGuru<? extends VMInstanceVO>>();
     protected StateMachine2<State, VirtualMachine.Event, VirtualMachine> _stateMachine;
 
@@ -586,7 +591,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
     ConcurrentOperationException, ResourceUnavailableException {
         return advanceStart(vm, params, caller, account, null);
     }
-    
+
     @Override
     public <T extends VMInstanceVO> T advanceStart(T vm, Map<VirtualMachineProfile.Param, Object> params, User caller, Account account, DeploymentPlan planToDeploy)
             throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
@@ -695,17 +700,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 
                 VirtualMachineProfileImpl<T> vmProfile = new VirtualMachineProfileImpl<T>(vm, template, offering, account, params);
                 DeployDestination dest = null;
-                for (DeploymentPlanner planner : _planners) {
-                    if (planner.canHandle(vmProfile, plan, avoids)) {
-                        dest = planner.plan(vmProfile, plan, avoids);
-                    } else {
-                        continue;
-                    }
-                    if (dest != null) {
-                        avoids.addHost(dest.getHost().getId());
-                        journal.record("Deployment found ", vmProfile, dest);
-                        break;
-                    }
+                try {
+                    dest = _dpMgr.planDeployment(vmProfile, plan, avoids);
+                } catch (AffinityConflictException e2) {
+                    // TODO Auto-generated catch block
+                    e2.printStackTrace();
                 }
 
                 if (dest == null) {
@@ -739,7 +738,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
                     if (s_logger.isDebugEnabled()) {
                         s_logger.debug("VM is being created in podId: " + vm.getPodIdToDeployIn());
                     }
-                    _networkMgr.prepare(vmProfile, dest, ctx); 
+                    _networkMgr.prepare(vmProfile, dest, ctx);
                     if (vm.getHypervisorType() != HypervisorType.BareMetal) {
                         this.volumeMgr.prepare(vmProfile, dest);
                     }
@@ -797,7 +796,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
                             StopCommand cmd = new StopCommand(vm);
                             StopAnswer answer = (StopAnswer) _agentMgr.easySend(destHostId, cmd);
                             if (answer == null || !answer.getResult()) {
-                                s_logger.warn("Unable to stop " + vm + " due to " + (answer != null ? answer.getDetails() : "no answers")); 
+                                s_logger.warn("Unable to stop " + vm + " due to " + (answer != null ? answer.getDetails() : "no answers"));
                                 _haMgr.scheduleStop(vm, destHostId, WorkType.ForceStop);
                                 throw new ExecutionException("Unable to stop " + vm + " so we are unable to retry the start operation");
                             }
@@ -1144,7 +1143,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
             s_logger.error("State transit with event: " + e + " failed due to: " + vm.getInstanceName() + " has active VM snapshots tasks");
             return false;
         }
-        
+
         State oldState = vm.getState();
         if (oldState == State.Starting) {
             if (e == Event.OperationSucceeded) {
@@ -1179,12 +1178,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
             s_logger.debug("Unable to stop " + vm);
             return false;
         }
-        
+
         if (!_vmSnapshotMgr.deleteAllVMSnapshots(vm.getId(),null)){
             s_logger.debug("Unable to delete all snapshots for " + vm);
             return false;
         }
-        
+
         try {
             if (!stateTransitTo(vm, VirtualMachine.Event.DestroyRequested, vm.getHostId())) {
                 s_logger.debug("Unable to destroy the vm because it is not in the correct state: " + vm);
@@ -1559,7 +1558,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 
     @Override
     public boolean isVirtualMachineUpgradable(VirtualMachine vm, ServiceOffering offering) {
-        boolean isMachineUpgradable = true;    	
+        boolean isMachineUpgradable = true;
         for(HostAllocator allocator : _hostAllocators) {
             isMachineUpgradable = allocator.isVirtualMachineUpgradable(vm, offering);
             if(isMachineUpgradable)
@@ -1628,7 +1627,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
         return new StopCommand(vmName);
     }
 
-    public Commands fullHostSync(final long hostId, StartupRoutingCommand startup) {  
+    public Commands fullHostSync(final long hostId, StartupRoutingCommand startup) {
         Commands commands = new Commands(OnError.Continue);
 
         Map<Long, AgentVmInfo> infos = convertToInfos(startup);
@@ -1637,7 +1636,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
         s_logger.debug("Found " + vms.size() + " VMs for host " + hostId);
         for (VMInstanceVO vm : vms) {
             AgentVmInfo info = infos.remove(vm.getId());
-            
+
             // sync VM Snapshots related transient states
             List<VMSnapshotVO> vmSnapshotsInTrasientStates = _vmSnapshotDao.listByInstanceId(vm.getId(), VMSnapshot.State.Expunging,VMSnapshot.State.Reverting, VMSnapshot.State.Creating);
             if(vmSnapshotsInTrasientStates.size() > 1){
@@ -1649,11 +1648,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
                     s_logger.info("Successfully sync VM with transient snapshot: " + vm.getInstanceName());
                 }
             }
-            
+
             VMInstanceVO castedVm = null;
             if (info == null) {
                 info = new AgentVmInfo(vm.getInstanceName(), getVmGuru(vm), vm, State.Stopped);
-            } 
+            }
             castedVm = info.guru.findById(vm.getId());
 
             HypervisorGuru hvGuru = _hvGuruMgr.getGuru(castedVm.getHypervisorType());
@@ -1767,7 +1766,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
         for (VMInstanceVO vm : set_vms) {
             AgentVmInfo info =  infos.remove(vm.getId());
             VMInstanceVO castedVm = null;
-            
+
             // sync VM Snapshots related transient states
             List<VMSnapshotVO> vmSnapshotsInExpungingStates = _vmSnapshotDao.listByInstanceId(vm.getId(), VMSnapshot.State.Expunging, VMSnapshot.State.Creating,VMSnapshot.State.Reverting);
             if(vmSnapshotsInExpungingStates.size() > 0){
@@ -1785,9 +1784,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
                     s_logger.info("Successfully sync VM with transient snapshot: " + vm.getInstanceName());
                 }
             }
-            
-            if ((info == null && (vm.getState() == State.Running || vm.getState() == State.Starting ))  
-            		||  (info != null && (info.state == State.Running && vm.getState() == State.Starting))) 
+
+            if ((info == null && (vm.getState() == State.Running || vm.getState() == State.Starting ))
+            		||  (info != null && (info.state == State.Running && vm.getState() == State.Starting)))
             {
                 s_logger.info("Found vm " + vm.getInstanceName() + " in inconsistent state. " + vm.getState() + " on CS while " +  (info == null ? "Stopped" : "Running") + " on agent");
                 info = new AgentVmInfo(vm.getInstanceName(), getVmGuru(vm), vm, State.Stopped);
@@ -1925,7 +1924,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
         return map;
     }
 
-    protected Map<Long, AgentVmInfo> convertToInfos(StartupRoutingCommand cmd) { 
+    protected Map<Long, AgentVmInfo> convertToInfos(StartupRoutingCommand cmd) {
         final Map<String, VmState> states = cmd.getVmStates();
         final HashMap<Long, AgentVmInfo> map = new HashMap<Long, AgentVmInfo>();
         if (states == null) {
@@ -1989,7 +1988,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
      * compareState does as its name suggests and compares the states between
      * management server and agent. It returns whether something should be
      * cleaned up
-     * 
+     *
      */
     protected Command compareState(long hostId, VMInstanceVO vm, final AgentVmInfo info, final boolean fullSync, boolean trackExternalChange) {
         State agentState = info.state;
@@ -2192,7 +2191,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
         List<NicVO> nics = _nicsDao.listByVmId(profile.getId());
         for (NicVO nic : nics) {
             Network network = _networkModel.getNetwork(nic.getNetworkId());
-            NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, 
+            NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null,
                     _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(profile.getHypervisorType(), network));
             profile.addNic(nicProfile);
         }
@@ -2319,7 +2318,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
                 s_logger.fatal("The Cluster VM sync process failed for cluster id " + clusterId + " with ", e);
             }
         }
-        else { // for others KVM and VMWare 
+        else { // for others KVM and VMWare
             StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
             Commands commands = fullHostSync(agentId, startup);
 
@@ -2492,7 +2491,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
     }
 
     @Override
-    public NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile requested) throws ConcurrentOperationException, 
+    public NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile requested) throws ConcurrentOperationException,
     ResourceUnavailableException, InsufficientCapacityException {
 
         s_logger.debug("Adding vm " + vm + " to network " + network + "; requested nic profile " + requested);
@@ -2502,14 +2501,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
         } else {
             vmVO = _vmDao.findById(vm.getId());
         }
-        ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM), 
+        ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM),
                 _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM));
 
-        VirtualMachineProfileImpl<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vmVO, null, 
+        VirtualMachineProfileImpl<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vmVO, null,
                 null, null, null);
 
         DataCenter dc = _configMgr.getZone(network.getDataCenterId());
-        Host host = _hostDao.findById(vm.getHostId()); 
+        Host host = _hostDao.findById(vm.getHostId());
         DeployDestination dest = new DeployDestination(dc, null, null, host);
 
         //check vm state
@@ -2557,14 +2556,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
     public boolean removeNicFromVm(VirtualMachine vm, NicVO nic) throws ConcurrentOperationException, ResourceUnavailableException {
         VMInstanceVO vmVO = _vmDao.findById(vm.getId());
         NetworkVO network = _networkDao.findById(nic.getNetworkId());
-        ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM), 
+        ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM),
                 _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM));
 
-        VirtualMachineProfileImpl<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vmVO, null, 
+        VirtualMachineProfileImpl<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vmVO, null,
                 null, null, null);
 
         DataCenter dc = _configMgr.getZone(network.getDataCenterId());
-        Host host = _hostDao.findById(vm.getHostId()); 
+        Host host = _hostDao.findById(vm.getHostId());
         DeployDestination dest = new DeployDestination(dc, null, null, host);
         VirtualMachineGuru<VMInstanceVO> vmGuru = getVmGuru(vmVO);
         HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
@@ -2576,9 +2575,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
             throw new CloudRuntimeException("Failed to remove nic from " + vm + " in " + network + ", nic is default.");
         }
 
-        NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 
-                _networkModel.getNetworkRate(network.getId(), vm.getId()), 
-                _networkModel.isSecurityGroupSupportedInNetwork(network), 
+        NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(),
+                _networkModel.getNetworkRate(network.getId(), vm.getId()),
+                _networkModel.isSecurityGroupSupportedInNetwork(network),
                 _networkModel.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network));
 
         //1) Unplug the nic
@@ -2611,14 +2610,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
     @Override
     public boolean removeVmFromNetwork(VirtualMachine vm, Network network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException {
         VMInstanceVO vmVO = _vmDao.findById(vm.getId());
-        ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM), 
+        ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM),
                 _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM));
 
-        VirtualMachineProfileImpl<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vmVO, null, 
+        VirtualMachineProfileImpl<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vmVO, null,
                 null, null, null);
 
         DataCenter dc = _configMgr.getZone(network.getDataCenterId());
-        Host host = _hostDao.findById(vm.getHostId()); 
+        Host host = _hostDao.findById(vm.getHostId());
         DeployDestination dest = new DeployDestination(dc, null, null, host);
         VirtualMachineGuru<VMInstanceVO> vmGuru = getVmGuru(vmVO);
         HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
@@ -2643,9 +2642,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
             throw new CloudRuntimeException("Failed to remove nic from " + vm + " in " + network + ", nic is default.");
         }
 
-        NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 
-                _networkModel.getNetworkRate(network.getId(), vm.getId()), 
-                _networkModel.isSecurityGroupSupportedInNetwork(network), 
+        NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(),
+                _networkModel.getNetworkRate(network.getId(), vm.getId()),
+                _networkModel.isSecurityGroupSupportedInNetwork(network),
                 _networkModel.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network));
 
         //1) Unplug the nic

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe2a8687/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
index 994f225..f6c87cb 100644
--- a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
+++ b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
@@ -1,6 +1,5 @@
 package org.apache.cloudstack.affinity;
 
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -13,36 +12,34 @@ import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
 import org.apache.log4j.Logger;
 
 
-import com.cloud.api.query.vo.SecurityGroupJoinVO;
 import com.cloud.event.ActionEvent;
 import com.cloud.event.EventTypes;
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.ResourceInUseException;
-import com.cloud.network.PhysicalNetwork;
-import com.cloud.network.dao.PhysicalNetworkVO;
-import com.cloud.network.security.SecurityGroupManager;
-import com.cloud.network.security.SecurityGroupRuleVO;
-import com.cloud.network.security.SecurityGroupVMMapVO;
-import com.cloud.network.security.SecurityGroupVO;
+import com.cloud.network.security.SecurityGroup;
 import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
 import com.cloud.user.UserContext;
+import com.cloud.uservm.UserVm;
 import com.cloud.utils.Pair;
 import com.cloud.utils.component.Manager;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.Filter;
-import com.cloud.utils.db.JoinBuilder.JoinType;
 import com.cloud.utils.db.JoinBuilder;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.Transaction;
+import com.cloud.utils.fsm.StateListener;
 import com.cloud.vm.UserVmVO;
-import com.cloud.vm.VMInstanceVO;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.VirtualMachine.Event;
+import com.cloud.vm.VirtualMachine.State;
 import com.cloud.vm.dao.UserVmDao;
 
 @Local(value = { AffinityGroupService.class })
-public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGroupService, Manager {
+public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGroupService, Manager,
+        StateListener<State, VirtualMachine.Event, VirtualMachine> {
 
     public static final Logger s_logger = Logger.getLogger(AffinityGroupServiceImpl.class);
     private String _name;
@@ -221,4 +218,56 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
         return _affinityGroupDao.findById(groupId);
     }
 
+    @Override
+    public boolean preStateTransitionEvent(State oldState, Event event, State newState, VirtualMachine vo,
+            boolean status, Object opaque) {
+        return true;
+    }
+
+    @Override
+    public boolean postStateTransitionEvent(State oldState, Event event, State newState, VirtualMachine vo,
+            boolean status, Object opaque) {
+        if (!status) {
+            return false;
+        }
+        if ((newState == State.Expunging)) {
+            // cleanup all affinity groups associated to the Expunged VM
+            SearchCriteria<AffinityGroupVMMapVO> sc = _affinityGroupVMMapDao.createSearchCriteria();
+            sc.addAnd("instanceId", SearchCriteria.Op.EQ, vo.getId());
+            _affinityGroupVMMapDao.expunge(sc);
+        }
+        return true;
+    }
+
+    @Override
+    public UserVm updateVMAffinityGroups(Long vmId, List<Long> affinityGroupIds) {
+        // Verify input parameters
+        UserVmVO vmInstance = _userVmDao.findById(vmId);
+        if (vmInstance == null) {
+            throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId);
+        }
+
+        // Check that the VM is stopped
+        if (!vmInstance.getState().equals(State.Stopped)) {
+            s_logger.warn("Unable to update affinity groups of the virtual machine " + vmInstance.toString()
+                    + " in state " + vmInstance.getState());
+            throw new InvalidParameterValueException("Unable update affinity groups of the virtual machine "
+                    + vmInstance.toString() + " " + "in state " + vmInstance.getState()
+                    + "; make sure the virtual machine is stopped and not in an error state before updating.");
+        }
+
+        // check that the affinity groups exist
+        for (Long affinityGroupId : affinityGroupIds) {
+            AffinityGroupVO ag = _affinityGroupDao.findById(affinityGroupId);
+            if (ag == null) {
+                throw new InvalidParameterValueException("Unable to find affinity group by id " + affinityGroupId);
+            }
+        }
+        _affinityGroupVMMapDao.updateMap(vmId, affinityGroupIds);
+
+        // APIResponseHelper will pull out the updated affinitygroups.
+        return vmInstance;
+
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe2a8687/server/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java b/server/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
new file mode 100644
index 0000000..93bd358
--- /dev/null
+++ b/server/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
@@ -0,0 +1,66 @@
+package org.apache.cloudstack.affinity;
+
+import java.util.List;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
+import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
+import org.apache.log4j.Logger;
+
+import com.cloud.deploy.DeploymentPlan;
+import com.cloud.deploy.DeploymentPlanner.ExcludeList;
+import com.cloud.exception.AffinityConflictException;
+import com.cloud.utils.component.AdapterBase;
+import com.cloud.vm.VMInstanceVO;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.VirtualMachineProfile;
+import com.cloud.vm.dao.UserVmDao;
+import com.cloud.vm.dao.VMInstanceDao;
+
+@Local(value = AffinityGroupProcessor.class)
+public class HostAntiAffinityProcessor extends AdapterBase implements AffinityGroupProcessor {
+
+    private static final Logger s_logger = Logger.getLogger(HostAntiAffinityProcessor.class);
+    @Inject
+    protected UserVmDao _vmDao;
+    @Inject
+    protected VMInstanceDao _vmInstanceDao;
+    @Inject
+    protected AffinityGroupDao _affinityGroupDao;
+    @Inject
+    protected AffinityGroupVMMapDao _affinityGroupVMMapDao;
+
+    @Override
+    public void process(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan,
+            ExcludeList avoid)
+            throws AffinityConflictException {
+        VirtualMachine vm = vmProfile.getVirtualMachine();
+        AffinityGroupVMMapVO vmGroupMapping = _affinityGroupVMMapDao.findByVmIdType(vm.getId(), getType());
+
+        if (vmGroupMapping != null) {
+            AffinityGroupVO group = _affinityGroupDao.findById(vmGroupMapping.getAffinityGroupId());
+
+            if (s_logger.isDebugEnabled()) {
+                s_logger.debug("Processing affinity group " + group.getName() + " for VM Id: " + vm.getId());
+            }
+
+            List<Long> groupVMIds = _affinityGroupVMMapDao.listVmIdsByAffinityGroup(group.getId());
+
+            for (Long groupVMId : groupVMIds) {
+                VMInstanceVO groupVM = _vmInstanceDao.findById(groupVMId);
+                if (groupVM != null && !groupVM.isRemoved() && groupVM.getHostId() != null) {
+                    avoid.addHost(groupVM.getHostId());
+                }
+            }
+        }
+
+    }
+
+    @Override
+    public String getType() {
+        return "HostAntiAffinity";
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe2a8687/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDao.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDao.java b/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDao.java
index 9841de4..a98ae0f 100644
--- a/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDao.java
+++ b/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDao.java
@@ -40,4 +40,8 @@ public interface AffinityGroupVMMapDao extends GenericDao<AffinityGroupVMMapVO,
     long countAffinityGroupsForVm(long instanceId);
 
     int deleteVM(long instanceId);
+
+    AffinityGroupVMMapVO findByVmIdType(long instanceId, String type);
+
+    void updateMap(Long vmId, List<Long> affinityGroupIds);
 }


[19/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
Integration testcase and the config file needed,  that runs with marvin.


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

Branch: refs/heads/master
Commit: fd23b36c119db1c77ee8b31a24f889630dd863c2
Parents: b633dde
Author: Prachi Damle <pr...@cloud.com>
Authored: Wed Apr 3 16:22:58 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:23:13 2013 -0700

----------------------------------------------------------------------
 tools/apidoc/gen_toc.py                            |    3 +-
 .../demo/live/testDeployVMWithAffinityGroup.py     |  157 +++++++++++++++
 .../marvin/sandbox/demo/live/testaffinitygroup.cfg |   45 ++++
 3 files changed, 204 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fd23b36c/tools/apidoc/gen_toc.py
----------------------------------------------------------------------
diff --git a/tools/apidoc/gen_toc.py b/tools/apidoc/gen_toc.py
index ab2456d..2d5292b 100644
--- a/tools/apidoc/gen_toc.py
+++ b/tools/apidoc/gen_toc.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/cygdrive/c/Python27
 # 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
@@ -137,6 +137,7 @@ known_categories = {
     'addIpToNic': 'Nic',
     'removeIpFromNic': 'Nic',
     'listNics':'Nic',
+	'AffinityGroup': 'Affinity Group',
     }
 
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fd23b36c/tools/marvin/marvin/sandbox/demo/live/testDeployVMWithAffinityGroup.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/sandbox/demo/live/testDeployVMWithAffinityGroup.py b/tools/marvin/marvin/sandbox/demo/live/testDeployVMWithAffinityGroup.py
new file mode 100644
index 0000000..93c6571
--- /dev/null
+++ b/tools/marvin/marvin/sandbox/demo/live/testDeployVMWithAffinityGroup.py
@@ -0,0 +1,157 @@
+#!/usr/bin/env python
+# 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.
+
+
+
+import marvin
+from marvin.cloudstackTestCase import *
+from marvin.remoteSSHClient import remoteSSHClient 
+import hashlib
+import random
+
+class TestDeployVmWithAffinityGroup(cloudstackTestCase):
+    """
+    This test deploys a virtual machine into a user account 
+    using the small service offering 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.password = mdf_pass				#The md5 hashed password string
+		self.acct.username = 'testuser'
+		self.acct.email = 'testuser@xyz.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, user: %s, id: \
+				   %s"%(self.acctResponse.account.account, \
+						self.acctResponse.account.username, \
+						self.acctResponse.account.id))
+		
+
+		self.zone = listZones.listZonesCmd()
+		self.zone.uuid = self.apiClient.listZones(self.zone)[0].id
+
+		self.service_offering = listServiceOfferings.listServiceOfferingsCmd()
+		self.service_offering.uuid = self.apiClient.listServiceOfferings(self.service_offering)[0].id
+
+		self.template = listTemplates.listTemplatesCmd()
+		self.template.templatefilter = 'featured'
+		self.template.name = 'CentOS'
+		self.template.uuid = self.apiClient.listTemplates(self.template)[0].id        
+
+    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. 
+		
+		First create the host anti-affinity group for this account
+        """
+	createAGCmd = createAffinityGroup.createAffinityGroupCmd()
+	createAGCmd.name = 'webvms1'
+	createAGCmd.type = 'host anti-affinity'
+	createAGCmd.account = self.acct.account
+	createAGCmd.domainid = self.acct.domainid
+		
+	createAGResponse = self.apiClient.createAffinityGroup(createAGCmd)
+	self.debug("AffinityGroup %s was created in the job %s"%(createAGResponse.id, createAGResponse.jobid))
+    
+	
+	deployVmCmd = deployVirtualMachine.deployVirtualMachineCmd()
+	deployVmCmd.zoneid = self.zone.uuid
+	deployVmCmd.templateid = self.template.uuid #CentOS 5.6 builtin
+	deployVmCmd.serviceofferingid = self.service_offering.uuid
+	deployVmCmd.account = self.acct.account
+	deployVmCmd.domainid = self.acct.domainid
+	deployVmCmd.affinitygroupnames=[]
+	deployVmCmd.affinitygroupnames.append(str(createAGResponse.name))
+	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")
+
+	vm = listVmResponse[0]
+	self.assertEqual(vm.state, "Running", "Check if VM has reached Running state in CS")
+
+	VM1hostid = vm.hostid
+
+	#Deploy another VM in same affinity group
+	deployVm2Cmd = deployVirtualMachine.deployVirtualMachineCmd()
+	deployVm2Cmd.zoneid = self.zone.uuid
+	deployVm2Cmd.templateid = self.template.uuid #CentOS 5.6 builtin
+	deployVm2Cmd.serviceofferingid = self.service_offering.uuid
+	deployVm2Cmd.account = self.acct.account
+	deployVm2Cmd.domainid = self.acct.domainid
+	deployVm2Cmd.affinitygroupnames=[]
+	deployVm2Cmd.affinitygroupnames.append(str(createAGResponse.name))
+
+	deployVm2Response = self.apiClient.deployVirtualMachine(deployVm2Cmd)
+	self.debug("VM2 %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.state, "Running", "Check if VM has reached Running state in CS")
+
+	VM2hostid = vm2.hostid
+	
+	self.assertNotEqual(VM1hostid, VM2hostid, "The hosts of the 2 VM's in the host anti-affinity group are not different, test failed")                         
+	
+    def tearDown(self):
+    	"""
+		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.account.id
+        self.apiClient.deleteAccount(deleteAcct)
+        self.testClient.close()

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fd23b36c/tools/marvin/marvin/sandbox/demo/live/testaffinitygroup.cfg
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/sandbox/demo/live/testaffinitygroup.cfg b/tools/marvin/marvin/sandbox/demo/live/testaffinitygroup.cfg
new file mode 100644
index 0000000..a814016
--- /dev/null
+++ b/tools/marvin/marvin/sandbox/demo/live/testaffinitygroup.cfg
@@ -0,0 +1,45 @@
+#  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.
+#
+# This config is designed to run as an advanced network, with management server in devcloud
+# It also requires an 'apt-get install dnsmasq' to run a resolver in devcloud for internal dns
+
+{
+    "dbSvr": {
+        "dbSvr": "127.0.0.1", 
+        "passwd": "cloud", 
+        "db": "cloud", 
+        "port": 3306, 
+        "user": "cloud"
+    }, 
+    "logger": [
+        {
+            "name": "TestClient", 
+            "file": "C:\\var\\log\\testclient.log"
+        }, 
+        {
+            "name": "TestCase", 
+            "file": "C:\\var\\log\\testcase.log"
+        }
+    ], 
+    "mgtSvr": [
+        {
+            "mgtSvrIp": "127.0.0.1", 
+            "port": 8096
+        }
+    ]
+}


[12/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
API to list planners and set the planner in Service offering

Conflicts:

	server/src/com/cloud/server/ManagementServerImpl.java
	setup/db/db/schema-410to420.sql


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

Branch: refs/heads/master
Commit: c8ae2a9d25128b692719d33cffaed2fe62f6a339
Parents: cf7d40c
Author: Prachi Damle <pr...@cloud.com>
Authored: Fri Mar 29 00:15:23 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:22:56 2013 -0700

----------------------------------------------------------------------
 api/src/com/cloud/server/ManagementService.java    |    4 +-
 .../org/apache/cloudstack/api/ApiConstants.java    |    1 +
 .../admin/config/ListDeploymentPlannersCmd.java    |   71 ++++++++++++++
 .../admin/offering/CreateServiceOfferingCmd.java   |    7 ++
 client/tomcatconf/componentContext.xml.in          |    3 -
 .../cloud/configuration/ConfigurationManager.java  |    3 +-
 .../configuration/ConfigurationManagerImpl.java    |    6 +-
 .../src/com/cloud/server/ManagementServerImpl.java |   19 ++++-
 .../src/com/cloud/service/ServiceOfferingVO.java   |   74 +++++++++------
 .../cloud/vpc/MockConfigurationManagerImpl.java    |    2 +-
 setup/db/db/schema-410to420.sql                    |   68 +++++++++++++
 11 files changed, 219 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c8ae2a9d/api/src/com/cloud/server/ManagementService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/server/ManagementService.java b/api/src/com/cloud/server/ManagementService.java
index 1e6ca8d..6e6dbc3 100755
--- a/api/src/com/cloud/server/ManagementService.java
+++ b/api/src/com/cloud/server/ManagementService.java
@@ -123,7 +123,7 @@ public interface ManagementService {
     /**
      * Searches for servers by the specified search criteria Can search by: "name", "type", "state", "dataCenterId",
      * "podId"
-     * 
+     *
      * @param cmd
      * @return List of Hosts
      */
@@ -407,4 +407,6 @@ public interface ManagementService {
      */
     List<? extends Capacity> listTopConsumedResources(ListCapacityCmd cmd);
 
+    List<String> listDeploymentPlanners();
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c8ae2a9d/api/src/org/apache/cloudstack/api/ApiConstants.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java
index cfabc61..dd8bfcd 100755
--- a/api/src/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/org/apache/cloudstack/api/ApiConstants.java
@@ -475,6 +475,7 @@ public class ApiConstants {
     public static final String HEALTHCHECK_PINGPATH = "pingpath";
     public static final String AFFINITY_GROUP_IDS = "affinitygroupids";
     public static final String AFFINITY_GROUP_NAMES = "affinitygroupnames";
+    public static final String DEPLOYMENT_PLANNER = "deploymentplanner";
 
     public enum HostDetails {
         all, capacity, events, stats, min;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c8ae2a9d/api/src/org/apache/cloudstack/api/command/admin/config/ListDeploymentPlannersCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/config/ListDeploymentPlannersCmd.java b/api/src/org/apache/cloudstack/api/command/admin/config/ListDeploymentPlannersCmd.java
new file mode 100644
index 0000000..69004de
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/admin/config/ListDeploymentPlannersCmd.java
@@ -0,0 +1,71 @@
+// 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 org.apache.cloudstack.api.command.admin.config;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.BaseListCmd;
+import org.apache.cloudstack.api.response.DeploymentPlannersResponse;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.log4j.Logger;
+
+@APICommand(name = "listDeploymentPlanners", description = "Lists all DeploymentPlanners available.", responseObject = DeploymentPlannersResponse.class)
+public class ListDeploymentPlannersCmd extends BaseListCmd {
+    public static final Logger s_logger = Logger.getLogger(ListDeploymentPlannersCmd.class.getName());
+
+    private static final String s_name = "listdeploymentplannersresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public void execute(){
+        List<String> planners = _mgr.listDeploymentPlanners();
+        ListResponse<DeploymentPlannersResponse> response = new ListResponse<DeploymentPlannersResponse>();
+        List<DeploymentPlannersResponse> plannerResponses = new ArrayList<DeploymentPlannersResponse>();
+
+        for (String planner : planners) {
+            DeploymentPlannersResponse plannerResponse = new DeploymentPlannersResponse();
+            plannerResponse.setName(planner);
+            plannerResponse.setObjectName("deploymentPlanner");
+            plannerResponses.add(plannerResponse);
+        }
+
+        response.setResponses(plannerResponses);
+        response.setResponseName(getCommandName());
+        this.setResponseObject(response);
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c8ae2a9d/api/src/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java b/api/src/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java
index e915c48..74392cd 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java
@@ -84,6 +84,9 @@ public class CreateServiceOfferingCmd extends BaseCmd {
     @Parameter(name=ApiConstants.NETWORKRATE, type=CommandType.INTEGER, description="data transfer rate in megabits per second allowed. Supported only for non-System offering and system offerings having \"domainrouter\" systemvmtype")
     private Integer networkRate;
 
+    @Parameter(name = ApiConstants.DEPLOYMENT_PLANNER, type = CommandType.STRING, description = "The deployment planner heuristics used to deploy a VM of this offering, default \"FirstFitPlanner\".")
+    private String deploymentPlanner;
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -148,6 +151,10 @@ public class CreateServiceOfferingCmd extends BaseCmd {
         return networkRate;
     }
 
+    public String getDeploymentPlanner() {
+        return deploymentPlanner;
+    }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c8ae2a9d/client/tomcatconf/componentContext.xml.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/componentContext.xml.in b/client/tomcatconf/componentContext.xml.in
index bea2f78..1582e8b 100644
--- a/client/tomcatconf/componentContext.xml.in
+++ b/client/tomcatconf/componentContext.xml.in
@@ -155,7 +155,6 @@
           <ref bean="FirstFitPlanner" />
           <ref bean="UserDispersingPlanner" />
           <ref bean="UserConcentratedPodPlanner" />
-
 <!--
           <ref bean="BareMetalPlanner" />
 -->
@@ -248,6 +247,4 @@
       </list>
     </property>
   </bean>
-
-
 </beans>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c8ae2a9d/server/src/com/cloud/configuration/ConfigurationManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/ConfigurationManager.java b/server/src/com/cloud/configuration/ConfigurationManager.java
index 20e9884..c5f65e9 100644
--- a/server/src/com/cloud/configuration/ConfigurationManager.java
+++ b/server/src/com/cloud/configuration/ConfigurationManager.java
@@ -78,10 +78,11 @@ public interface ConfigurationManager extends ConfigurationService, Manager {
      *            TODO
      * @param id
      * @param useVirtualNetwork
+     * @param deploymentPlanner
      * @return ID
      */
     ServiceOfferingVO createServiceOffering(long userId, boolean isSystem, VirtualMachine.Type vm_typeType, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired,
-            boolean offerHA, boolean limitResourceUse, boolean volatileVm, String tags, Long domainId, String hostTag, Integer networkRate);
+            boolean offerHA, boolean limitResourceUse, boolean volatileVm, String tags, Long domainId, String hostTag, Integer networkRate, String deploymentPlanner);
 
     /**
      * Creates a new disk offering

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c8ae2a9d/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
index 1526fb0..ceeae1e 100755
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -1821,16 +1821,16 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
         }
 
         return createServiceOffering(userId, cmd.getIsSystem(), vmType, cmd.getServiceOfferingName(), cpuNumber.intValue(), memory.intValue(), cpuSpeed.intValue(), cmd.getDisplayText(),
-                localStorageRequired, offerHA, limitCpuUse, volatileVm, cmd.getTags(), cmd.getDomainId(), cmd.getHostTag(), cmd.getNetworkRate());
+                localStorageRequired, offerHA, limitCpuUse, volatileVm, cmd.getTags(), cmd.getDomainId(), cmd.getHostTag(), cmd.getNetworkRate(), cmd.getDeploymentPlanner());
     }
 
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_SERVICE_OFFERING_CREATE, eventDescription = "creating service offering")
     public ServiceOfferingVO createServiceOffering(long userId, boolean isSystem, VirtualMachine.Type vm_type, String name, int cpu, int ramSize, int speed, String displayText,
-            boolean localStorageRequired, boolean offerHA, boolean limitResourceUse, boolean volatileVm,  String tags, Long domainId, String hostTag, Integer networkRate) {
+            boolean localStorageRequired, boolean offerHA, boolean limitResourceUse, boolean volatileVm,  String tags, Long domainId, String hostTag, Integer networkRate, String deploymentPlanner) {
         tags = cleanupTags(tags);
         ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, networkRate, null, offerHA, limitResourceUse, volatileVm, displayText, localStorageRequired, false, tags, isSystem, vm_type,
-                domainId, hostTag);
+                domainId, hostTag, deploymentPlanner);
 
         if ((offering = _serviceOfferingDao.persist(offering)) != null) {
             UserContext.current().setEventDetails("Service offering id=" + offering.getId());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c8ae2a9d/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java
index af77ba5..01798cc 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -107,7 +107,6 @@ import org.apache.cloudstack.api.response.ExtractResponse;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
-
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.api.GetVncPortAnswer;
 import com.cloud.agent.api.GetVncPortCommand;
@@ -136,6 +135,7 @@ import com.cloud.dc.*;
 import com.cloud.dc.Vlan.VlanType;
 import com.cloud.dc.dao.*;
 import com.cloud.deploy.DataCenterDeployment;
+import com.cloud.deploy.DeploymentPlanner;
 import com.cloud.deploy.DeploymentPlanner.ExcludeList;
 import com.cloud.domain.DomainVO;
 import com.cloud.domain.dao.DomainDao;
@@ -460,6 +460,9 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
     private List<UserAuthenticator> _userAuthenticators;
     private List<UserAuthenticator> _userPasswordEncoders;
 
+    @Inject
+    protected List<DeploymentPlanner> _planners;
+
     @Inject ClusterManager _clusterMgr;
     private String _hashKey = null;
 
@@ -2301,6 +2304,10 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
         cmdList.add(AssignToGlobalLoadBalancerRuleCmd.class);
         cmdList.add(RemoveFromGlobalLoadBalancerRuleCmd.class);
         cmdList.add(ListStorageProvidersCmd.class);
+        cmdList.add(CreateAffinityGroupCmd.class);
+        cmdList.add(DeleteAffinityGroupCmd.class);
+        cmdList.add(ListAffinityGroupsCmd.class);
+        cmdList.add(UpdateVMAffinityGroupCmd.class);
         return cmdList;
     }
 
@@ -3366,4 +3373,14 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
 
     }
 
+    @Override
+    public List<String> listDeploymentPlanners() {
+        List<String> plannersAvailable = new ArrayList<String>();
+        for (DeploymentPlanner planner : _planners) {
+            plannersAvailable.add(planner.getName());
+        }
+
+        return plannersAvailable;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c8ae2a9d/server/src/com/cloud/service/ServiceOfferingVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/service/ServiceOfferingVO.java b/server/src/com/cloud/service/ServiceOfferingVO.java
index 7be939c..40f817d 100755
--- a/server/src/com/cloud/service/ServiceOfferingVO.java
+++ b/server/src/com/cloud/service/ServiceOfferingVO.java
@@ -34,25 +34,25 @@ import com.cloud.vm.VirtualMachine;
 public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering {
     @Column(name="cpu")
 	private int cpu;
-    
+
     @Column(name="speed")
     private int speed;
-    
+
     @Column(name="ram_size")
 	private int ramSize;
-    
+
     @Column(name="nw_rate")
     private Integer rateMbps;
-    
+
     @Column(name="mc_rate")
     private Integer multicastRateMbps;
-    
+
     @Column(name="ha_enabled")
     private boolean offerHA;
 
     @Column(name="limit_cpu_use")
-    private boolean limitCpuUse;    
-    
+    private boolean limitCpuUse;
+
     @Column(name="is_volatile")
     private boolean volatileVm;
 
@@ -64,10 +64,13 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
 
     @Column(name="vm_type")
     private String vm_type;
-    
+
     @Column(name="sort_key")
     int sortKey;
-    
+
+    @Column(name = "deployment_planner")
+    private String deploymentPlanner = "FirstFitPlanner";
+
     protected ServiceOfferingVO() {
         super();
     }
@@ -80,7 +83,7 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
         this.rateMbps = rateMbps;
         this.multicastRateMbps = multicastRateMbps;
         this.offerHA = offerHA;
-        this.limitCpuUse = false; 
+        this.limitCpuUse = false;
         this.volatileVm = false;
         this.default_use = defaultUse;
         this.vm_type = vm_type == null ? null : vm_type.toString().toLowerCase();
@@ -94,7 +97,7 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
         this.rateMbps = rateMbps;
         this.multicastRateMbps = multicastRateMbps;
         this.offerHA = offerHA;
-        this.limitCpuUse = limitCpuUse;  
+        this.limitCpuUse = limitCpuUse;
         this.volatileVm = volatileVm;
         this.vm_type = vm_type == null ? null : vm_type.toString().toLowerCase();
     }
@@ -102,31 +105,40 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
     public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA, boolean limitResourceUse, boolean volatileVm, String displayText, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse, VirtualMachine.Type vm_type, Long domainId, String hostTag) {
         this(name, cpu, ramSize, speed, rateMbps, multicastRateMbps, offerHA, limitResourceUse, volatileVm, displayText, useLocalStorage, recreatable, tags, systemUse, vm_type, domainId);
         this.hostTag = hostTag;
-    }    
+    }
+
+    public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, Integer rateMbps, Integer multicastRateMbps,
+            boolean offerHA, boolean limitResourceUse, boolean volatileVm, String displayText, boolean useLocalStorage,
+            boolean recreatable, String tags, boolean systemUse, VirtualMachine.Type vm_type, Long domainId,
+            String hostTag, String deploymentPlanner) {
+        this(name, cpu, ramSize, speed, rateMbps, multicastRateMbps, offerHA, limitResourceUse, volatileVm,
+                displayText, useLocalStorage, recreatable, tags, systemUse, vm_type, domainId, hostTag);
+        this.deploymentPlanner = deploymentPlanner;
+    }
 
     @Override
 	public boolean getOfferHA() {
 	    return offerHA;
 	}
-	
+
 	public void setOfferHA(boolean offerHA) {
 		this.offerHA = offerHA;
 	}
 
-    @Override	
+    @Override
 	public boolean getLimitCpuUse() {
 	    return limitCpuUse;
 	}
-	
+
 	public void setLimitResourceUse(boolean limitCpuUse) {
 		this.limitCpuUse = limitCpuUse;
 	}
-	
-	@Override 
+
+	@Override
     public boolean getDefaultUse() {
         return default_use;
     }
-	
+
 	@Override
     @Transient
 	public String[] getTagsArray() {
@@ -134,15 +146,15 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
 	    if (tags == null || tags.length() == 0) {
 	        return new String[0];
 	    }
-	    
+
 	    return tags.split(",");
 	}
-	
+
 	@Override
 	public int getCpu() {
 	    return cpu;
 	}
-	
+
 	public void setCpu(int cpu) {
 		this.cpu = cpu;
 	}
@@ -154,17 +166,17 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
 	public void setRamSize(int ramSize) {
 		this.ramSize = ramSize;
 	}
-	
+
 	@Override
 	public int getSpeed() {
 	    return speed;
 	}
-	
+
 	@Override
 	public int getRamSize() {
 	    return ramSize;
 	}
-	
+
 	public void setRateMbps(Integer rateMbps) {
 		this.rateMbps = rateMbps;
 	}
@@ -177,7 +189,7 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
 	public void setMulticastRateMbps(Integer multicastRateMbps) {
 		this.multicastRateMbps = multicastRateMbps;
 	}
-	
+
 	@Override
     public Integer getMulticastRateMbps() {
 		return multicastRateMbps;
@@ -185,12 +197,12 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
 
 	public void setHostTag(String hostTag) {
 		this.hostTag = hostTag;
-	}	
-	
+	}
+
 	public String getHostTag() {
 		return hostTag;
 	}
-	
+
 	public String getSystemVmType(){
 	    return vm_type;
 	}
@@ -202,10 +214,14 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
 	public int getSortKey() {
 		return sortKey;
 	}
-	
+
     @Override
     public boolean getVolatileVm() {
         return volatileVm;
     }
 
+    public String getDeploymentPlanner() {
+        return deploymentPlanner;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c8ae2a9d/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java b/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java
index d96e831..b0063fa 100644
--- a/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java
+++ b/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java
@@ -433,7 +433,7 @@ public class MockConfigurationManagerImpl extends ManagerBase implements Configu
      */
     @Override
     public ServiceOfferingVO createServiceOffering(long userId, boolean isSystem, Type vm_typeType, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA,
-            boolean limitResourceUse, boolean volatileVm, String tags, Long domainId, String hostTag, Integer networkRate) {
+            boolean limitResourceUse, boolean volatileVm, String tags, Long domainId, String hostTag, Integer networkRate, String deploymentPlanner) {
         // TODO Auto-generated method stub
         return null;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c8ae2a9d/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql
index 77bb8d6..0f6b41e 100644
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@ -165,6 +165,74 @@ CREATE TABLE `cloud`.`affinity_group_vm_map` (
   CONSTRAINT `fk_agvm__group_id` FOREIGN KEY(`affinity_group_id`) REFERENCES `affinity_group`(`id`)  
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
+
+CREATE TABLE nic_secondary_ips (
+  `id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT,
+  `uuid` varchar(40),
+  `vmId` bigint unsigned COMMENT 'vm instance id',
+  `nicId` bigint unsigned NOT NULL,
+  `ip4_address` char(40) COMMENT 'ip4 address',
+  `ip6_address` char(40) COMMENT 'ip6 address',
+  `network_id` bigint unsigned NOT NULL COMMENT 'network configuration id',
+  `created` datetime NOT NULL COMMENT 'date created',
+  `account_id` bigint unsigned NOT NULL COMMENT 'owner.  foreign key to   account table',
+  `domain_id` bigint unsigned NOT NULL COMMENT 'the domain that the owner belongs to',
+   PRIMARY KEY (`id`),
+   CONSTRAINT `fk_nic_secondary_ip__vmId` FOREIGN KEY `fk_nic_secondary_ip__vmId`(`vmId`) REFERENCES `vm_instance`(`id`) ON DELETE CASCADE,
+   CONSTRAINT `fk_nic_secondary_ip__networks_id` FOREIGN KEY `fk_nic_secondary_ip__networks_id`(`network_id`) REFERENCES `networks`(`id`),
+   CONSTRAINT `uc_nic_secondary_ip__uuid` UNIQUE (`uuid`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+ALTER TABLE `cloud`.`nics` ADD COLUMN secondary_ip SMALLINT DEFAULT '0' COMMENT 'secondary ips configured for the nic';
+ALTER TABLE `cloud`.`user_ip_address` ADD COLUMN dnat_vmip VARCHAR(40);
+
+ALTER TABLE `cloud`.`alert` ADD COLUMN `archived` tinyint(1) unsigned NOT NULL DEFAULT 0;
+ALTER TABLE `cloud`.`event` ADD COLUMN `archived` tinyint(1) unsigned NOT NULL DEFAULT 0;
+INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'alert.purge.interval', '86400', 'The interval (in seconds) to wait before running the alert purge thread');
+INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'alert.purge.delay', '0', 'Alerts older than specified number days will be purged. Set this value to 0 to never delete alerts');
+
+DROP VIEW IF EXISTS `cloud`.`event_view`;
+CREATE VIEW `cloud`.`event_view` AS
+    select
+        event.id,
+        event.uuid,
+        event.type,
+        event.state,
+        event.description,
+        event.created,
+        event.level,
+        event.parameters,
+        event.start_id,
+        eve.uuid start_uuid,
+        event.user_id,
+        event.archived,
+        user.username user_name,
+        account.id account_id,
+        account.uuid account_uuid,
+        account.account_name account_name,
+        account.type account_type,
+        domain.id domain_id,
+        domain.uuid domain_uuid,
+        domain.name domain_name,
+        domain.path domain_path,
+        projects.id project_id,
+        projects.uuid project_uuid,
+        projects.name project_name
+    from
+        `cloud`.`event`
+            inner join
+        `cloud`.`account` ON event.account_id = account.id
+            inner join
+        `cloud`.`domain` ON event.domain_id = domain.id
+            inner join
+        `cloud`.`user` ON event.user_id = user.id
+            left join
+        `cloud`.`projects` ON projects.project_account_id = event.account_id
+            left join
+        `cloud`.`event` eve ON event.start_id = eve.id;
+
+ALTER TABLE `cloud`.`service_offering` ADD COLUMN `deployment_planner` varchar(255) NOT NULL DEFAULT 'FirstFitPlanner'  COMMENT 'Planner heuristics used to deploy a VM of this offering';
+
 -- Re-enable foreign key checking, at the end of the upgrade path
 SET foreign_key_checks = 1;
 


[23/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
Added AffinityGroup View in order to include VM details while listing AffinityGroups.


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

Branch: refs/heads/master
Commit: 3403b547735fe14e22b879f2627776548394951e
Parents: 09a6eb7
Author: Prachi Damle <pr...@cloud.com>
Authored: Thu Apr 4 22:46:11 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:23:23 2013 -0700

----------------------------------------------------------------------
 .../cloudstack/affinity/AffinityGroupResponse.java |   16 +-
 .../user/affinitygroup/ListAffinityGroupsCmd.java  |   26 +--
 .../affinitygroup/UpdateVMAffinityGroupCmd.java    |    8 +-
 .../org/apache/cloudstack/query/QueryService.java  |    4 +
 client/tomcatconf/applicationContext.xml.in        |   10 +
 client/tomcatconf/componentContext.xml.in          |    1 +
 .../affinity/HostAntiAffinityProcessor.java        |    9 +-
 server/src/com/cloud/api/ApiDBUtils.java           |   14 +
 .../src/com/cloud/api/query/QueryManagerImpl.java  |  108 +++++++
 .../com/cloud/api/query/ViewResponseHelper.java    |   18 +
 .../cloud/api/query/dao/AffinityGroupJoinDao.java  |   37 +++
 .../api/query/dao/AffinityGroupJoinDaoImpl.java    |  155 +++++++++
 .../cloud/api/query/vo/AffinityGroupJoinVO.java    |  248 +++++++++++++++
 .../affinity/dao/AffinityGroupDaoImpl.java         |    1 -
 .../affinity/dao/AffinityGroupVMMapDaoImpl.java    |    1 -
 setup/db/db/schema-410to420.sql                    |   34 ++-
 16 files changed, 661 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3403b547/api/src/org/apache/cloudstack/affinity/AffinityGroupResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/affinity/AffinityGroupResponse.java b/api/src/org/apache/cloudstack/affinity/AffinityGroupResponse.java
index 073a82c..1ae7c59 100644
--- a/api/src/org/apache/cloudstack/affinity/AffinityGroupResponse.java
+++ b/api/src/org/apache/cloudstack/affinity/AffinityGroupResponse.java
@@ -17,6 +17,7 @@
 package org.apache.cloudstack.affinity;
 
 import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.Set;
 
 import org.apache.cloudstack.api.ApiConstants;
@@ -24,6 +25,7 @@ import org.apache.cloudstack.api.BaseResponse;
 import org.apache.cloudstack.api.EntityReference;
 import org.apache.cloudstack.api.response.ControlledEntityResponse;
 import org.apache.cloudstack.api.response.ControlledViewEntityResponse;
+import org.apache.cloudstack.api.response.UserVmResponse;
 
 import com.cloud.network.security.SecurityGroup;
 import com.cloud.serializer.Param;
@@ -31,7 +33,7 @@ import com.google.gson.annotations.SerializedName;
 
 @SuppressWarnings("unused")
 @EntityReference(value = AffinityGroup.class)
-public class AffinityGroupResponse extends BaseResponse implements ControlledEntityResponse {
+public class AffinityGroupResponse extends BaseResponse implements ControlledViewEntityResponse {
 
     @SerializedName(ApiConstants.ID) @Param(description="the ID of the affinity group")
     private String id;
@@ -55,8 +57,12 @@ public class AffinityGroupResponse extends BaseResponse implements ControlledEnt
     @Param(description = "the type of the affinity group")
     private String type;
 
+    @SerializedName("virtualmachine")
+    @Param(description = "virtual machines associated with this affinity group ", responseObject = UserVmResponse.class)
+    private Set<UserVmResponse> vmList;
 
     public AffinityGroupResponse() {
+        this.vmList = new LinkedHashSet<UserVmResponse>();
     }
 
     @Override
@@ -136,4 +142,12 @@ public class AffinityGroupResponse extends BaseResponse implements ControlledEnt
 
     }
 
+    public void setVMList(Set<UserVmResponse> vmList) {
+        this.vmList = vmList;
+    }
+
+    public void addVM(UserVmResponse vm) {
+        this.vmList.add(vm);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3403b547/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java
index effbd86..9310fb9 100644
--- a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java
@@ -16,23 +16,16 @@
 // under the License.
 package org.apache.cloudstack.api.command.user.affinitygroup;
 
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.cloudstack.affinity.AffinityGroup;
 import org.apache.cloudstack.affinity.AffinityGroupResponse;
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.BaseListCmd;
 import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.cloudstack.api.response.UserVmResponse;
 import org.apache.log4j.Logger;
 
 import com.cloud.async.AsyncJob;
-import com.cloud.utils.Pair;
 
 @APICommand(name = "listAffinityGroups", description = "Lists affinity groups", responseObject = AffinityGroupResponse.class)
 public class ListAffinityGroupsCmd extends BaseListCmd {
@@ -83,22 +76,11 @@ public class ListAffinityGroupsCmd extends BaseListCmd {
     @Override
     public void execute(){
 
-        Pair<List<? extends AffinityGroup>, Integer> result = _affinityGroupService.listAffinityGroups(id,
-                affinityGroupName,
+        ListResponse<AffinityGroupResponse> response = _queryService.listAffinityGroups(id, affinityGroupName,
                 affinityGroupType, virtualMachineId, this.getStartIndex(), this.getPageSizeVal());
-        if (result != null) {
-            ListResponse<AffinityGroupResponse> response = new ListResponse<AffinityGroupResponse>();
-            List<AffinityGroupResponse> groupResponses = new ArrayList<AffinityGroupResponse>();
-            for (AffinityGroup group : result.first()) {
-                AffinityGroupResponse groupResponse = _responseGenerator.createAffinityGroupResponse(group);
-                groupResponses.add(groupResponse);
-            }
-            response.setResponses(groupResponses, result.second());
-            response.setResponseName(getCommandName());
-            this.setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to search for affinity groups");
-        }
+        response.setResponseName(getCommandName());
+        this.setResponseObject(response);
+
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3403b547/api/src/org/apache/cloudstack/api/command/user/affinitygroup/UpdateVMAffinityGroupCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/UpdateVMAffinityGroupCmd.java b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/UpdateVMAffinityGroupCmd.java
index 94f8446..44d017b 100644
--- a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/UpdateVMAffinityGroupCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/UpdateVMAffinityGroupCmd.java
@@ -17,6 +17,7 @@
 package org.apache.cloudstack.api.command.user.affinitygroup;
 
 import java.util.ArrayList;
+import java.util.EnumSet;
 import java.util.List;
 
 import org.apache.cloudstack.affinity.AffinityGroupResponse;
@@ -27,6 +28,7 @@ import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.ApiConstants.VMDetails;
 import org.apache.cloudstack.api.response.UserVmResponse;
 import org.apache.log4j.Logger;
 
@@ -131,8 +133,12 @@ public class UpdateVMAffinityGroupCmd extends BaseAsyncCmd {
             InsufficientCapacityException, ServerApiException {
         UserContext.current().setEventDetails("Vm Id: "+getId());
         UserVm result = _affinityGroupService.updateVMAffinityGroups(getId(), getAffinityGroupIdList());
+        ArrayList<VMDetails> dc = new ArrayList<VMDetails>();
+        dc.add(VMDetails.valueOf("affgrp"));
+        EnumSet<VMDetails> details = EnumSet.copyOf(dc);
+
         if (result != null){
-            UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
+            UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", details, result).get(0);
             response.setResponseName(getCommandName());
             this.setResponseObject(response);
         } else {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3403b547/api/src/org/apache/cloudstack/query/QueryService.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/query/QueryService.java b/api/src/org/apache/cloudstack/query/QueryService.java
index c3f86aa..443c5df 100644
--- a/api/src/org/apache/cloudstack/query/QueryService.java
+++ b/api/src/org/apache/cloudstack/query/QueryService.java
@@ -16,6 +16,7 @@
 // under the License.
 package org.apache.cloudstack.query;
 
+import org.apache.cloudstack.affinity.AffinityGroupResponse;
 import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
 import org.apache.cloudstack.api.command.admin.router.ListRoutersCmd;
 import org.apache.cloudstack.api.command.admin.storage.ListStoragePoolsCmd;
@@ -97,4 +98,7 @@ public interface QueryService {
     public ListResponse<ServiceOfferingResponse>  searchForServiceOfferings(ListServiceOfferingsCmd cmd);
 
     public ListResponse<ZoneResponse>  listDataCenters(ListZonesByCmd cmd);
+
+    public ListResponse<AffinityGroupResponse> listAffinityGroups(Long affinityGroupId, String affinityGroupName,
+            String affinityGroupType, Long vmId, Long startIndex, Long pageSize);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3403b547/client/tomcatconf/applicationContext.xml.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/applicationContext.xml.in b/client/tomcatconf/applicationContext.xml.in
index 67b1286..0d13877 100644
--- a/client/tomcatconf/applicationContext.xml.in
+++ b/client/tomcatconf/applicationContext.xml.in
@@ -836,5 +836,15 @@
   <bean id="baremetalDhcpDaoImpl" class="com.cloud.baremetal.database.BaremetalDhcpDaoImpl" />
   <bean id="baremetalPxeDaoImpl" class="com.cloud.baremetal.database.BaremetalPxeDaoImpl" />
 -->
+
+  <bean id="AffinityGroupServiceImpl" class="org.apache.cloudstack.affinity.AffinityGroupServiceImpl"/>
+  <bean id="DeploymentPlanningManager" class="com.cloud.deploy.DeploymentPlanningManagerImpl" />
+  
+  <bean id="AffinityGroupJoinDaoImpl" class="com.cloud.api.query.dao.AffinityGroupJoinDaoImpl">
+  </bean>
+  <bean id="AffinityGroupDaoImpl" class="org.apache.cloudstack.affinity.dao.AffinityGroupDaoImpl">
+  </bean>
+  <bean id="AffinityGroupVMMapDaoImpl" class="org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDaoImpl">
+  </bean>
   
 </beans>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3403b547/client/tomcatconf/componentContext.xml.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/componentContext.xml.in b/client/tomcatconf/componentContext.xml.in
index 7f3e02d..92838fd 100644
--- a/client/tomcatconf/componentContext.xml.in
+++ b/client/tomcatconf/componentContext.xml.in
@@ -31,6 +31,7 @@
                       http://www.springframework.org/schema/context
                       http://www.springframework.org/schema/context/spring-context-3.0.xsd">                     
 
+
 <!--
  
   OSS deployment configuration

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3403b547/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
----------------------------------------------------------------------
diff --git a/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java b/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
index 88030f2..4049571 100644
--- a/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
+++ b/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
@@ -65,8 +65,13 @@ public class HostAntiAffinityProcessor extends AffinityProcessorBase implements
 
             for (Long groupVMId : groupVMIds) {
                 VMInstanceVO groupVM = _vmInstanceDao.findById(groupVMId);
-                if (groupVM != null && !groupVM.isRemoved() && groupVM.getHostId() != null) {
-                    avoid.addHost(groupVM.getHostId());
+                if (groupVM != null && !groupVM.isRemoved()) {
+                    if (groupVM.getHostId() != null) {
+                        avoid.addHost(groupVM.getHostId());
+                    } else if (VirtualMachine.State.Stopped.equals(groupVM.getState())
+                            && groupVM.getLastHostId() != null) {
+                        avoid.addHost(groupVM.getLastHostId());
+                    }
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3403b547/server/src/com/cloud/api/ApiDBUtils.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java
index d21e2c4..303f328 100755
--- a/server/src/com/cloud/api/ApiDBUtils.java
+++ b/server/src/com/cloud/api/ApiDBUtils.java
@@ -26,6 +26,7 @@ import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 
 import org.apache.cloudstack.affinity.AffinityGroup;
+import org.apache.cloudstack.affinity.AffinityGroupResponse;
 import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
 import org.apache.cloudstack.api.ApiConstants.HostDetails;
 import org.apache.cloudstack.api.ApiConstants.VMDetails;
@@ -52,6 +53,7 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 import org.springframework.stereotype.Component;
 
 import com.cloud.api.query.dao.AccountJoinDao;
+import com.cloud.api.query.dao.AffinityGroupJoinDao;
 import com.cloud.api.query.dao.AsyncJobJoinDao;
 import com.cloud.api.query.dao.DataCenterJoinDao;
 import com.cloud.api.query.dao.DiskOfferingJoinDao;
@@ -69,6 +71,7 @@ import com.cloud.api.query.dao.UserAccountJoinDao;
 import com.cloud.api.query.dao.UserVmJoinDao;
 import com.cloud.api.query.dao.VolumeJoinDao;
 import com.cloud.api.query.vo.AccountJoinVO;
+import com.cloud.api.query.vo.AffinityGroupJoinVO;
 import com.cloud.api.query.vo.AsyncJobJoinVO;
 import com.cloud.api.query.vo.DataCenterJoinVO;
 import com.cloud.api.query.vo.DiskOfferingJoinVO;
@@ -382,6 +385,7 @@ public class ApiDBUtils {
     static NicSecondaryIpDao _nicSecondaryIpDao;
     static VpcProvisioningService _vpcProvSvc;
     static AffinityGroupDao _affinityGroupDao;
+    static AffinityGroupJoinDao _affinityGroupJoinDao;
 
     @Inject private ManagementServer ms;
     @Inject public AsyncJobManager asyncMgr;
@@ -487,6 +491,7 @@ public class ApiDBUtils {
     @Inject private NicSecondaryIpDao nicSecondaryIpDao;
     @Inject private VpcProvisioningService vpcProvSvc;
     @Inject private AffinityGroupDao affinityGroupDao;
+    @Inject private AffinityGroupJoinDao affinityGroupJoinDao;
 
     @PostConstruct
     void init() {
@@ -591,6 +596,7 @@ public class ApiDBUtils {
         _nicSecondaryIpDao = nicSecondaryIpDao;
         _vpcProvSvc = vpcProvSvc;
         _affinityGroupDao = affinityGroupDao;
+        _affinityGroupJoinDao = affinityGroupJoinDao;
         // Note: stats collector should already have been initialized by this time, otherwise a null instance is returned
         _statsCollector = StatsCollector.getInstance();
     }
@@ -1597,4 +1603,12 @@ public class ApiDBUtils {
     public static AffinityGroup getAffinityGroup(String groupName, long accountId) {
         return _affinityGroupDao.findByAccountAndName(accountId, groupName);
     }
+
+    public static AffinityGroupResponse newAffinityGroupResponse(AffinityGroupJoinVO group) {
+        return _affinityGroupJoinDao.newAffinityGroupResponse(group);
+    }
+
+    public static AffinityGroupResponse fillAffinityGroupDetails(AffinityGroupResponse resp, AffinityGroupJoinVO group) {
+        return _affinityGroupJoinDao.setAffinityGroupResponse(resp, group);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3403b547/server/src/com/cloud/api/query/QueryManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java
index 951d09e..a498c18 100644
--- a/server/src/com/cloud/api/query/QueryManagerImpl.java
+++ b/server/src/com/cloud/api/query/QueryManagerImpl.java
@@ -27,6 +27,11 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
+import org.apache.cloudstack.affinity.AffinityGroup;
+import org.apache.cloudstack.affinity.AffinityGroupResponse;
+import org.apache.cloudstack.affinity.AffinityGroupVMMapVO;
+import org.apache.cloudstack.affinity.AffinityGroupVO;
+import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
 import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
 import org.apache.cloudstack.api.command.admin.router.ListRoutersCmd;
 import org.apache.cloudstack.api.command.admin.storage.ListStoragePoolsCmd;
@@ -69,6 +74,7 @@ import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
 import com.cloud.api.query.dao.AccountJoinDao;
+import com.cloud.api.query.dao.AffinityGroupJoinDao;
 import com.cloud.api.query.dao.AsyncJobJoinDao;
 import com.cloud.api.query.dao.DataCenterJoinDao;
 import com.cloud.api.query.dao.DiskOfferingJoinDao;
@@ -86,6 +92,7 @@ import com.cloud.api.query.dao.UserAccountJoinDao;
 import com.cloud.api.query.dao.UserVmJoinDao;
 import com.cloud.api.query.dao.VolumeJoinDao;
 import com.cloud.api.query.vo.AccountJoinVO;
+import com.cloud.api.query.vo.AffinityGroupJoinVO;
 import com.cloud.api.query.vo.AsyncJobJoinVO;
 import com.cloud.api.query.vo.DataCenterJoinVO;
 import com.cloud.api.query.vo.DiskOfferingJoinVO;
@@ -138,6 +145,7 @@ import com.cloud.utils.Ternary;
 import com.cloud.utils.component.Manager;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.JoinBuilder;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.SearchCriteria.Func;
@@ -246,6 +254,12 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
     @Inject
     private HighAvailabilityManager _haMgr;
 
+    @Inject
+    AffinityGroupVMMapDao _affinityGroupVMMapDao;
+
+    @Inject
+    private AffinityGroupJoinDao _affinityGroupJoinDao;
+
     /* (non-Javadoc)
      * @see com.cloud.api.query.QueryService#searchForUsers(org.apache.cloudstack.api.command.admin.user.ListUsersCmd)
      */
@@ -2328,5 +2342,99 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
         return false;
     }
 
+    @Override
+    public ListResponse<AffinityGroupResponse> listAffinityGroups(Long affinityGroupId, String affinityGroupName,
+            String affinityGroupType, Long vmId, Long startIndex, Long pageSize) {
+        Pair<List<AffinityGroupJoinVO>, Integer> result = listAffinityGroupsInternal(affinityGroupId,
+                affinityGroupName, affinityGroupType, vmId, startIndex, pageSize);
+        ListResponse<AffinityGroupResponse> response = new ListResponse<AffinityGroupResponse>();
+        List<AffinityGroupResponse> agResponses = ViewResponseHelper.createAffinityGroupResponses(result.first());
+        response.setResponses(agResponses, result.second());
+        return response;
+    }
+
+
+    public Pair<List<AffinityGroupJoinVO>, Integer> listAffinityGroupsInternal(Long affinityGroupId,
+            String affinityGroupName, String affinityGroupType, Long vmId, Long startIndex, Long pageSize) {
+
+        Account caller = UserContext.current().getCaller();
+
+        Long accountId = caller.getAccountId();
+        Long domainId = caller.getDomainId();
+
+        if (vmId != null) {
+            UserVmVO userVM = _userVmDao.findById(vmId);
+            if (userVM == null){
+                throw new InvalidParameterValueException("Unable to list affinity groups for virtual machine instance "
+                        + vmId + "; instance not found.");
+            }
+            _accountMgr.checkAccess(caller, null, true, userVM);
+            return listAffinityGroupsByVM(vmId.longValue(), startIndex, pageSize);
+        }
+
+        Filter searchFilter = new Filter(AffinityGroupJoinVO.class, "id", true, startIndex, pageSize);
+        SearchBuilder<AffinityGroupJoinVO> groupSearch = _affinityGroupJoinDao.createSearchBuilder();
+        groupSearch.select(null, Func.DISTINCT, groupSearch.entity().getId()); // select
+                                                                               // distinct
+
+        SearchCriteria<AffinityGroupJoinVO> sc = groupSearch.create();
+
+        if (accountId != null) {
+            sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+        }
+
+        if (domainId != null) {
+            sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+        }
+
+        if (affinityGroupId != null) {
+            sc.addAnd("id", SearchCriteria.Op.EQ, affinityGroupId);
+        }
+
+        if (affinityGroupName != null) {
+            sc.addAnd("name", SearchCriteria.Op.EQ, affinityGroupName);
+        }
+
+        if (affinityGroupType != null) {
+            sc.addAnd("type", SearchCriteria.Op.EQ, affinityGroupType);
+        }
+
+
+        Pair<List<AffinityGroupJoinVO>, Integer> uniqueGroupsPair = _affinityGroupJoinDao.searchAndCount(sc,
+                searchFilter);
+        // search group details by ids
+        Integer count = uniqueGroupsPair.second();
+        if (count.intValue() == 0) {
+            // empty result
+            return uniqueGroupsPair;
+        }
+        List<AffinityGroupJoinVO> uniqueGroups = uniqueGroupsPair.first();
+        Long[] vrIds = new Long[uniqueGroups.size()];
+        int i = 0;
+        for (AffinityGroupJoinVO v : uniqueGroups) {
+            vrIds[i++] = v.getId();
+        }
+        List<AffinityGroupJoinVO> vrs = _affinityGroupJoinDao.searchByIds(vrIds);
+        return new Pair<List<AffinityGroupJoinVO>, Integer>(vrs, count);
+
+    }
+
+    private Pair<List<AffinityGroupJoinVO>, Integer> listAffinityGroupsByVM(long vmId, long pageInd, long pageSize) {
+        Filter sf = new Filter(SecurityGroupVMMapVO.class, null, true, pageInd, pageSize);
+        Pair<List<AffinityGroupVMMapVO>, Integer> agVmMappingPair = _affinityGroupVMMapDao.listByInstanceId(vmId, sf);
+        Integer count = agVmMappingPair.second();
+        if (count.intValue() == 0) {
+            // handle empty result cases
+            return new Pair<List<AffinityGroupJoinVO>, Integer>(new ArrayList<AffinityGroupJoinVO>(), count);
+        }
+        List<AffinityGroupVMMapVO> agVmMappings = agVmMappingPair.first();
+        Long[] agIds = new Long[agVmMappings.size()];
+        int i = 0;
+        for (AffinityGroupVMMapVO agVm : agVmMappings) {
+            agIds[i++] = agVm.getAffinityGroupId();
+        }
+        List<AffinityGroupJoinVO> ags = _affinityGroupJoinDao.searchByIds(agIds);
+        return new Pair<List<AffinityGroupJoinVO>, Integer>(ags, count);
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3403b547/server/src/com/cloud/api/query/ViewResponseHelper.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/ViewResponseHelper.java b/server/src/com/cloud/api/query/ViewResponseHelper.java
index 931327a..dc2727e 100644
--- a/server/src/com/cloud/api/query/ViewResponseHelper.java
+++ b/server/src/com/cloud/api/query/ViewResponseHelper.java
@@ -21,6 +21,7 @@ import java.util.EnumSet;
 import java.util.Hashtable;
 import java.util.List;
 
+import org.apache.cloudstack.affinity.AffinityGroupResponse;
 import org.apache.cloudstack.api.ApiConstants.HostDetails;
 import org.apache.cloudstack.api.ApiConstants.VMDetails;
 import org.apache.cloudstack.api.response.AccountResponse;
@@ -45,6 +46,7 @@ import org.apache.log4j.Logger;
 
 import com.cloud.api.ApiDBUtils;
 import com.cloud.api.query.vo.AccountJoinVO;
+import com.cloud.api.query.vo.AffinityGroupJoinVO;
 import com.cloud.api.query.vo.AsyncJobJoinVO;
 import com.cloud.api.query.vo.DataCenterJoinVO;
 import com.cloud.api.query.vo.DiskOfferingJoinVO;
@@ -303,4 +305,20 @@ public class ViewResponseHelper {
         }
         return respList;
     }
+
+    public static List<AffinityGroupResponse> createAffinityGroupResponses(List<AffinityGroupJoinVO> groups) {
+        Hashtable<Long, AffinityGroupResponse> vrDataList = new Hashtable<Long, AffinityGroupResponse>();
+        for (AffinityGroupJoinVO vr : groups) {
+            AffinityGroupResponse vrData = vrDataList.get(vr.getId());
+            if (vrData == null) {
+                // first time encountering this AffinityGroup
+                vrData = ApiDBUtils.newAffinityGroupResponse(vr);
+            } else {
+                // update vms
+                vrData = ApiDBUtils.fillAffinityGroupDetails(vrData, vr);
+            }
+            vrDataList.put(vr.getId(), vrData);
+        }
+        return new ArrayList<AffinityGroupResponse>(vrDataList.values());
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3403b547/server/src/com/cloud/api/query/dao/AffinityGroupJoinDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/dao/AffinityGroupJoinDao.java b/server/src/com/cloud/api/query/dao/AffinityGroupJoinDao.java
new file mode 100644
index 0000000..c029b3f
--- /dev/null
+++ b/server/src/com/cloud/api/query/dao/AffinityGroupJoinDao.java
@@ -0,0 +1,37 @@
+// 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.api.query.dao;
+
+import java.util.List;
+
+import org.apache.cloudstack.affinity.AffinityGroup;
+import org.apache.cloudstack.affinity.AffinityGroupResponse;
+import com.cloud.api.query.vo.AffinityGroupJoinVO;
+import com.cloud.user.Account;
+import com.cloud.utils.db.GenericDao;
+
+public interface AffinityGroupJoinDao extends GenericDao<AffinityGroupJoinVO, Long> {
+
+    AffinityGroupResponse newAffinityGroupResponse(AffinityGroupJoinVO vsg);
+
+    AffinityGroupResponse setAffinityGroupResponse(AffinityGroupResponse vsgData, AffinityGroupJoinVO vsg);
+
+    List<AffinityGroupJoinVO> newAffinityGroupView(AffinityGroup ag);
+
+    List<AffinityGroupJoinVO> searchByIds(Long... ids);
+}
+

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3403b547/server/src/com/cloud/api/query/dao/AffinityGroupJoinDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/dao/AffinityGroupJoinDaoImpl.java b/server/src/com/cloud/api/query/dao/AffinityGroupJoinDaoImpl.java
new file mode 100644
index 0000000..98c6440
--- /dev/null
+++ b/server/src/com/cloud/api/query/dao/AffinityGroupJoinDaoImpl.java
@@ -0,0 +1,155 @@
+// 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.api.query.dao;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+
+import org.apache.cloudstack.affinity.AffinityGroup;
+import org.apache.cloudstack.affinity.AffinityGroupResponse;
+import org.apache.cloudstack.api.response.UserVmResponse;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+import com.cloud.api.ApiResponseHelper;
+import com.cloud.api.query.vo.AffinityGroupJoinVO;
+import com.cloud.configuration.dao.ConfigurationDao;
+import com.cloud.user.Account;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+
+@Local(value = { AffinityGroupJoinDao.class })
+public class AffinityGroupJoinDaoImpl extends GenericDaoBase<AffinityGroupJoinVO, Long> implements AffinityGroupJoinDao {
+    public static final Logger s_logger = Logger.getLogger(AffinityGroupJoinDaoImpl.class);
+
+    @Inject
+    private ConfigurationDao  _configDao;
+
+    private final SearchBuilder<AffinityGroupJoinVO> agSearch;
+
+    private final SearchBuilder<AffinityGroupJoinVO> agIdSearch;
+
+    protected AffinityGroupJoinDaoImpl() {
+
+        agSearch = createSearchBuilder();
+        agSearch.and("idIN", agSearch.entity().getId(), SearchCriteria.Op.IN);
+        agSearch.done();
+
+        agIdSearch = createSearchBuilder();
+        agIdSearch.and("id", agIdSearch.entity().getId(), SearchCriteria.Op.EQ);
+        agIdSearch.done();
+
+        this._count = "select count(distinct id) from affinity_group_view WHERE ";
+    }
+
+    @Override
+    public AffinityGroupResponse newAffinityGroupResponse(AffinityGroupJoinVO vag) {
+        AffinityGroupResponse agResponse = new AffinityGroupResponse();
+        agResponse.setId(vag.getUuid());
+        agResponse.setName(vag.getName());
+        agResponse.setDescription(vag.getDescription());
+
+        ApiResponseHelper.populateOwner(agResponse, vag);
+
+        // update vm information
+        long instanceId = vag.getVmId();
+        if (instanceId > 0) {
+            UserVmResponse resp = new UserVmResponse();
+            resp.setObjectName("virtualmachine");
+            resp.setId(vag.getVmUuid());
+            resp.setName(vag.getVmName());
+            resp.setDisplayName(vag.getVmDisplayName());
+            resp.setState(vag.getVmState().toString());
+            agResponse.addVM(resp);
+        }
+
+        agResponse.setObjectName("affinitygroup");
+        return agResponse;
+    }
+
+    @Override
+    public AffinityGroupResponse setAffinityGroupResponse(AffinityGroupResponse vagData, AffinityGroupJoinVO vag) {
+        // update vm information
+        long instanceId = vag.getVmId();
+        if (instanceId > 0) {
+            UserVmResponse resp = new UserVmResponse();
+            resp.setObjectName("virtualmachine");
+            resp.setId(vag.getVmUuid());
+            resp.setName(vag.getVmName());
+            resp.setDisplayName(vag.getVmDisplayName());
+            resp.setState(vag.getVmState().toString());
+            vagData.addVM(resp);
+        }
+        return vagData;
+    }
+
+    @Override
+    public List<AffinityGroupJoinVO> newAffinityGroupView(AffinityGroup ag) {
+
+        SearchCriteria<AffinityGroupJoinVO> sc = agIdSearch.create();
+        sc.setParameters("id", ag.getId());
+        return searchIncludingRemoved(sc, null, null, false);
+    }
+
+    @Override
+    public List<AffinityGroupJoinVO> searchByIds(Long... agIds) {
+        // set detail batch query size
+        int DETAILS_BATCH_SIZE = 2000;
+        String batchCfg = _configDao.getValue("detail.batch.query.size");
+        if ( batchCfg != null ){
+            DETAILS_BATCH_SIZE = Integer.parseInt(batchCfg);
+        }
+        // query details by batches
+        List<AffinityGroupJoinVO> uvList = new ArrayList<AffinityGroupJoinVO>();
+        // query details by batches
+        int curr_index = 0;
+        if (agIds.length > DETAILS_BATCH_SIZE) {
+            while ((curr_index + DETAILS_BATCH_SIZE) <= agIds.length) {
+                Long[] ids = new Long[DETAILS_BATCH_SIZE];
+                for (int k = 0, j = curr_index; j < curr_index + DETAILS_BATCH_SIZE; j++, k++) {
+                    ids[k] = agIds[j];
+                }
+                SearchCriteria<AffinityGroupJoinVO> sc = agSearch.create();
+                sc.setParameters("idIN", ids);
+                List<AffinityGroupJoinVO> vms = searchIncludingRemoved(sc, null, null, false);
+                if (vms != null) {
+                    uvList.addAll(vms);
+                }
+                curr_index += DETAILS_BATCH_SIZE;
+            }
+        }
+        if (curr_index < agIds.length) {
+            int batch_size = (agIds.length - curr_index);
+            // set the ids value
+            Long[] ids = new Long[batch_size];
+            for (int k = 0, j = curr_index; j < curr_index + batch_size; j++, k++) {
+                ids[k] = agIds[j];
+            }
+            SearchCriteria<AffinityGroupJoinVO> sc = agSearch.create();
+            sc.setParameters("idIN", ids);
+            List<AffinityGroupJoinVO> vms = searchIncludingRemoved(sc, null, null, false);
+            if (vms != null) {
+                uvList.addAll(vms);
+            }
+        }
+        return uvList;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3403b547/server/src/com/cloud/api/query/vo/AffinityGroupJoinVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/vo/AffinityGroupJoinVO.java b/server/src/com/cloud/api/query/vo/AffinityGroupJoinVO.java
new file mode 100644
index 0000000..e68996c
--- /dev/null
+++ b/server/src/com/cloud/api/query/vo/AffinityGroupJoinVO.java
@@ -0,0 +1,248 @@
+// 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.api.query.vo;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import com.cloud.vm.VirtualMachine;
+
+@Entity
+@Table(name = "affinity_group_view")
+public class AffinityGroupJoinVO extends BaseViewVO implements ControlledViewEntity {
+
+    @Id
+    @Column(name="id", updatable=false, nullable = false)
+    private long id;
+
+    @Column(name="name")
+    private String name;
+
+    @Column(name = "description")
+    private String description;
+
+    @Column(name = "uuid")
+    private String uuid;
+
+    @Column(name="account_id")
+    private long accountId;
+
+    @Column(name="account_uuid")
+    private String accountUuid;
+
+    @Column(name="account_name")
+    private String accountName = null;
+
+    @Column(name="account_type")
+    private short accountType;
+
+    @Column(name="domain_id")
+    private long domainId;
+
+    @Column(name="domain_uuid")
+    private String domainUuid;
+
+    @Column(name="domain_name")
+    private String domainName = null;
+
+    @Column(name="domain_path")
+    private String domainPath = null;
+
+    @Column(name = "vm_id")
+    private long vmId;
+
+    @Column(name = "vm_uuid")
+    private String vmUuid;
+
+    @Column(name = "vm_name")
+    private String vmName;
+
+    @Column(name = "vm_display_name")
+    private String vmDisplayName;
+
+    @Column(name = "vm_state")
+    @Enumerated(value = EnumType.STRING)
+    protected VirtualMachine.State vmState = null;
+
+
+    public AffinityGroupJoinVO() {
+    }
+
+    @Override
+    public long getId() {
+        return id;
+    }
+
+    @Override
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    @Override
+    public String getUuid() {
+        return uuid;
+    }
+
+    public void setUuid(String uuid) {
+        this.uuid = uuid;
+    }
+
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public long getAccountId() {
+        return accountId;
+    }
+
+    public void setAccountId(long accountId) {
+        this.accountId = accountId;
+    }
+
+    @Override
+    public String getAccountUuid() {
+        return accountUuid;
+    }
+
+    public void setAccountUuid(String accountUuid) {
+        this.accountUuid = accountUuid;
+    }
+
+    @Override
+    public String getAccountName() {
+        return accountName;
+    }
+
+    public void setAccountName(String accountName) {
+        this.accountName = accountName;
+    }
+
+    @Override
+    public short getAccountType() {
+        return accountType;
+    }
+
+    public void setAccountType(short accountType) {
+        this.accountType = accountType;
+    }
+
+    @Override
+    public long getDomainId() {
+        return domainId;
+    }
+
+    public void setDomainId(long domainId) {
+        this.domainId = domainId;
+    }
+
+    @Override
+    public String getDomainUuid() {
+        return domainUuid;
+    }
+
+    public void setDomainUuid(String domainUuid) {
+        this.domainUuid = domainUuid;
+    }
+
+    @Override
+    public String getDomainName() {
+        return domainName;
+    }
+
+    public void setDomainName(String domainName) {
+        this.domainName = domainName;
+    }
+
+    @Override
+    public String getDomainPath() {
+        return domainPath;
+    }
+
+    public void setDomainPath(String domainPath) {
+        this.domainPath = domainPath;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public long getVmId() {
+        return vmId;
+    }
+
+    public void setVmId(long vmId) {
+        this.vmId = vmId;
+    }
+
+    public String getVmUuid() {
+        return vmUuid;
+    }
+
+    public void setVmUuid(String vmUuid) {
+        this.vmUuid = vmUuid;
+    }
+
+    public String getVmName() {
+        return vmName;
+    }
+
+    public void setVmName(String vmName) {
+        this.vmName = vmName;
+    }
+
+    public String getVmDisplayName() {
+        return vmDisplayName;
+    }
+
+    public void setVmDisplayName(String vmDisplayName) {
+        this.vmDisplayName = vmDisplayName;
+    }
+
+    public VirtualMachine.State getVmState() {
+        return vmState;
+    }
+
+    public void setVmState(VirtualMachine.State vmState) {
+        this.vmState = vmState;
+    }
+
+    @Override
+    public String getProjectUuid() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public String getProjectName() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3403b547/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupDaoImpl.java b/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupDaoImpl.java
index f7db418..d189d60 100644
--- a/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupDaoImpl.java
+++ b/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupDaoImpl.java
@@ -26,7 +26,6 @@ import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 
-@Component
 @Local(value = { AffinityGroupDao.class })
 public class AffinityGroupDaoImpl extends GenericDaoBase<AffinityGroupVO, Long> implements AffinityGroupDao {
     private SearchBuilder<AffinityGroupVO> AccountIdSearch;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3403b547/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java b/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java
index b17d0b3..abc2a2b 100644
--- a/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java
+++ b/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java
@@ -37,7 +37,6 @@ import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.SearchCriteria.Func;
 import com.cloud.utils.db.Transaction;
 
-@Component
 @Local(value = { AffinityGroupVMMapDao.class })
 public class AffinityGroupVMMapDaoImpl extends GenericDaoBase<AffinityGroupVMMapVO, Long> implements
         AffinityGroupVMMapDao {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3403b547/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql
index 6464c08..ae08ebe 100644
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@ -648,6 +648,38 @@ CREATE VIEW `cloud`.`user_vm_view` AS
 			left join
         `cloud`.`affinity_group` ON affinity_group_vm_map.affinity_group_id = affinity_group.id;
 
-			
+DROP VIEW IF EXISTS `cloud`.`affinity_group_view`;
+CREATE VIEW `cloud`.`affinity_group_view` AS
+    select 
+        affinity_group.id id,
+        affinity_group.name name,
+        affinity_group.description description,
+        affinity_group.uuid uuid,
+        account.id account_id,
+        account.uuid account_uuid,
+        account.account_name account_name,
+        account.type account_type,
+        domain.id domain_id,
+        domain.uuid domain_uuid,
+        domain.name domain_name,
+        domain.path domain_path,
+        vm_instance.id vm_id,
+        vm_instance.uuid vm_uuid,
+        vm_instance.name vm_name,
+        vm_instance.state vm_state,
+        user_vm.display_name vm_display_name
+    from
+        `cloud`.`affinity_group`
+            inner join
+        `cloud`.`account` ON affinity_group.account_id = account.id
+            inner join
+        `cloud`.`domain` ON affinity_group.domain_id = domain.id
+            left join
+        `cloud`.`affinity_group_vm_map` ON affinity_group.id = affinity_group_vm_map.affinity_group_id
+            left join
+        `cloud`.`vm_instance` ON vm_instance.id = affinity_group_vm_map.instance_id
+            left join
+		`cloud`.`user_vm` ON user_vm.id = vm_instance.id;
+		
 -- Re-enable foreign key checking, at the end of the upgrade path
 SET foreign_key_checks = 1;			


[11/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
Not using entity factory


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

Branch: refs/heads/master
Commit: cf7d40c6cd4c340aa71df959fad06e8b69070d06
Parents: e9300d2
Author: Prachi Damle <pr...@cloud.com>
Authored: Mon Mar 18 11:09:29 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:22:54 2013 -0700

----------------------------------------------------------------------
 .../platform/orchestration/CloudOrchestrator.java  |   63 +++++++--------
 1 files changed, 31 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cf7d40c6/engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java b/engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java
index c07931b..963e4d7 100755
--- a/engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java
+++ b/engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java
@@ -51,7 +51,6 @@ import com.cloud.user.dao.AccountDao;
 import com.cloud.utils.Pair;
 import com.cloud.utils.component.ComponentContext;
 import com.cloud.vm.NicProfile;
-import com.cloud.vm.UserVmVO;
 import com.cloud.vm.VMInstanceVO;
 import com.cloud.vm.VirtualMachineManager;
 import com.cloud.vm.dao.UserVmDao;
@@ -66,25 +65,25 @@ public class CloudOrchestrator implements OrchestrationService {
 
 	@Inject
 	private VirtualMachineManager _itMgr;
-	
+
 	@Inject
 	protected VMTemplateDao _templateDao = null;
-	
+
     @Inject
     protected VMInstanceDao _vmDao;
-    
+
     @Inject
     protected UserVmDao _userVmDao = null;
-    
+
 	@Inject
 	protected ServiceOfferingDao _serviceOfferingDao;
-	
+
 	@Inject
 	protected DiskOfferingDao _diskOfferingDao = null;
-	
+
 	@Inject
 	protected NetworkDao _networkDao;
-	
+
 	@Inject
 	protected AccountDao _accountDao = null;
 
@@ -147,17 +146,17 @@ public class CloudOrchestrator implements OrchestrationService {
 
     @Override
     public VirtualMachineEntity createVirtualMachine(
-            String id, 
-            String owner, 
-            String templateId, 
-            String hostName, 
+            String id,
+            String owner,
+            String templateId,
+            String hostName,
             String displayName,
             String hypervisor,
-            int cpu, 
-            int speed, 
+            int cpu,
+            int speed,
             long memory,
             Long diskSize,
-            List<String> computeTags, 
+            List<String> computeTags,
             List<String> rootDiskTags,
             Map<String, NicProfile> networkNicMap, DeploymentPlan plan) throws InsufficientCapacityException {
 
@@ -173,22 +172,22 @@ public class CloudOrchestrator implements OrchestrationService {
 
     	VirtualMachineEntityImpl vmEntity = ComponentContext.inject(VirtualMachineEntityImpl.class);
     	vmEntity.init(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, new ArrayList<String>(networkNicMap.keySet()));
-        
-    	
+
+
     	HypervisorType hypervisorType = HypervisorType.valueOf(hypervisor);
 
     	//load vm instance and offerings and call virtualMachineManagerImpl
     	VMInstanceVO vm = _vmDao.findByUuid(id);
-    	
+
 		// If the template represents an ISO, a disk offering must be passed in, and will be used to create the root disk
 		// Else, a disk offering is optional, and if present will be used to create the data disk
 
     	Pair<DiskOfferingVO, Long> rootDiskOffering = new Pair<DiskOfferingVO, Long>(null, null);
 		List<Pair<DiskOfferingVO, Long>> dataDiskOfferings = new ArrayList<Pair<DiskOfferingVO, Long>>();
- 
+
 		ServiceOfferingVO offering = _serviceOfferingDao.findById(vm.getServiceOfferingId());
 		rootDiskOffering.first(offering);
-		
+
 		if(vm.getDiskOfferingId() != null){
     		DiskOfferingVO diskOffering = _diskOfferingDao.findById(vm.getDiskOfferingId());
     		if (diskOffering == null) {
@@ -205,32 +204,32 @@ public class CloudOrchestrator implements OrchestrationService {
     		}
     		dataDiskOfferings.add(new Pair<DiskOfferingVO, Long>(diskOffering, size));
 		}
-		
-		
-		
+
+
+
     	if (_itMgr.allocate(_userVmDao.findById(vm.getId(), true), _templateDao.findById(new Long(templateId)), offering, rootDiskOffering, dataDiskOfferings, networkIpMap, null,	plan, hypervisorType, _accountDao.findById(new Long(owner))) == null) {
 			return null;
 		}
-    	
+
         return vmEntity;
     }
 
     @Override
     public VirtualMachineEntity createVirtualMachineFromScratch(String id, String owner, String isoId, String hostName, String displayName, String hypervisor, String os, int cpu, int speed, long memory,Long diskSize,
             List<String> computeTags, List<String> rootDiskTags, Map<String, NicProfile> networkNicMap, DeploymentPlan plan)  throws InsufficientCapacityException {
-		
+
     	// VirtualMachineEntityImpl vmEntity = new VirtualMachineEntityImpl(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, networks, vmEntityManager);
     	VirtualMachineEntityImpl vmEntity = ComponentContext.inject(VirtualMachineEntityImpl.class);
     	vmEntity.init(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, new ArrayList<String>(networkNicMap.keySet()));
 
     	//load vm instance and offerings and call virtualMachineManagerImpl
     	VMInstanceVO vm = _vmDao.findByUuid(id);
-    	
-    	
+
+
 		Pair<DiskOfferingVO, Long> rootDiskOffering = new Pair<DiskOfferingVO, Long>(null, null);
 		ServiceOfferingVO offering = _serviceOfferingDao.findById(vm.getServiceOfferingId());
 		rootDiskOffering.first(offering);
-		
+
 		List<Pair<DiskOfferingVO, Long>> dataDiskOfferings = new ArrayList<Pair<DiskOfferingVO, Long>>();
 		Long diskOfferingId = vm.getDiskOfferingId();
 		if (diskOfferingId == null) {
@@ -251,7 +250,7 @@ public class CloudOrchestrator implements OrchestrationService {
 		}
 		rootDiskOffering.first(diskOffering);
 		rootDiskOffering.second(size);
-		
+
         List<Pair<NetworkVO, NicProfile>> networkIpMap = new ArrayList<Pair<NetworkVO, NicProfile>>();
         for (String uuid : networkNicMap.keySet()) {
             NetworkVO network = _networkDao.findByUuid(uuid);
@@ -259,13 +258,13 @@ public class CloudOrchestrator implements OrchestrationService {
                 networkIpMap.add(new Pair<NetworkVO, NicProfile>(network, networkNicMap.get(uuid)));
             }
         }
-		
+
 		HypervisorType hypervisorType = HypervisorType.valueOf(hypervisor);
-		
+
     	if (_itMgr.allocate(_userVmDao.findById(vm.getId(), true), _templateDao.findById(new Long(isoId)), offering, rootDiskOffering, dataDiskOfferings, networkIpMap, null,	plan, hypervisorType, _accountDao.findById(new Long(owner))) == null) {
 			return null;
 		}
-    	
+
         return vmEntity;
     }
 


[02/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
More API changes


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

Branch: refs/heads/master
Commit: 1e205a3d0b8856ae6329930076dd77575e38fda6
Parents: 119c5ce
Author: Prachi Damle <pr...@cloud.com>
Authored: Wed Feb 27 14:27:02 2013 -0800
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:22:30 2013 -0700

----------------------------------------------------------------------
 .../apache/cloudstack/affinity/AffinityGroup.java  |   15 ++
 .../cloudstack/affinity/AffinityGroupResponse.java |  139 +++++++++++++++
 .../cloudstack/affinity/AffinityGroupService.java  |   54 ++++++
 .../apache/cloudstack/api/ResponseGenerator.java   |   18 +--
 .../user/affinitygroup/CreateAffinityGroupCmd.java |  126 +++++++++++++
 server/src/com/cloud/api/ApiResponseHelper.java    |   62 ++++++-
 .../affinity/AffinityGroupServiceImpl.java         |   94 ++++++++++
 .../cloudstack/affinity/AffinityGroupVMMapVO.java  |   74 ++++++++
 .../cloudstack/affinity/AffinityGroupVO.java       |  107 +++++++++++
 .../cloudstack/affinity/dao/AffinityGroupDao.java  |   30 +++
 .../affinity/dao/AffinityGroupDaoImpl.java         |   97 ++++++++++
 .../affinity/dao/AffinityGroupVMMapDao.java        |   43 +++++
 .../affinity/dao/AffinityGroupVMMapDaoImpl.java    |  120 +++++++++++++
 13 files changed, 960 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1e205a3d/api/src/org/apache/cloudstack/affinity/AffinityGroup.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/affinity/AffinityGroup.java b/api/src/org/apache/cloudstack/affinity/AffinityGroup.java
new file mode 100644
index 0000000..b8215a2
--- /dev/null
+++ b/api/src/org/apache/cloudstack/affinity/AffinityGroup.java
@@ -0,0 +1,15 @@
+package org.apache.cloudstack.affinity;
+
+import org.apache.cloudstack.acl.ControlledEntity;
+import org.apache.cloudstack.api.Identity;
+import org.apache.cloudstack.api.InternalIdentity;
+
+public interface AffinityGroup extends ControlledEntity, InternalIdentity, Identity {
+
+    String getName();
+
+    String getDescription();
+
+    String getType();
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1e205a3d/api/src/org/apache/cloudstack/affinity/AffinityGroupResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/affinity/AffinityGroupResponse.java b/api/src/org/apache/cloudstack/affinity/AffinityGroupResponse.java
new file mode 100644
index 0000000..073a82c
--- /dev/null
+++ b/api/src/org/apache/cloudstack/affinity/AffinityGroupResponse.java
@@ -0,0 +1,139 @@
+// 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 org.apache.cloudstack.affinity;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseResponse;
+import org.apache.cloudstack.api.EntityReference;
+import org.apache.cloudstack.api.response.ControlledEntityResponse;
+import org.apache.cloudstack.api.response.ControlledViewEntityResponse;
+
+import com.cloud.network.security.SecurityGroup;
+import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
+
+@SuppressWarnings("unused")
+@EntityReference(value = AffinityGroup.class)
+public class AffinityGroupResponse extends BaseResponse implements ControlledEntityResponse {
+
+    @SerializedName(ApiConstants.ID) @Param(description="the ID of the affinity group")
+    private String id;
+
+    @SerializedName(ApiConstants.NAME) @Param(description="the name of the affinity group")
+    private String name;
+
+    @SerializedName(ApiConstants.DESCRIPTION) @Param(description="the description of the affinity group")
+    private String description;
+
+    @SerializedName(ApiConstants.ACCOUNT) @Param(description="the account owning the affinity group")
+    private String accountName;
+
+    @SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the domain ID of the affinity group")
+    private String domainId;
+
+    @SerializedName(ApiConstants.DOMAIN) @Param(description="the domain name of the affinity group")
+    private String domainName;
+
+    @SerializedName(ApiConstants.TYPE)
+    @Param(description = "the type of the affinity group")
+    private String type;
+
+
+    public AffinityGroupResponse() {
+    }
+
+    @Override
+    public String getObjectId() {
+        return this.getId();
+    }
+
+
+    public String getId() {
+        return id;
+     }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public void setAccountName(String accountName) {
+        this.accountName = accountName;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    @Override
+    public void setDomainId(String domainId) {
+        this.domainId = domainId;
+    }
+
+    public void setDomainName(String domainName) {
+        this.domainName = domainName;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((id == null) ? 0 : id.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        AffinityGroupResponse other = (AffinityGroupResponse) obj;
+        if (id == null) {
+            if (other.id != null)
+                return false;
+        } else if (!id.equals(other.id))
+            return false;
+        return true;
+    }
+
+    @Override
+    public void setProjectId(String projectId) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void setProjectName(String projectName) {
+        // TODO Auto-generated method stub
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1e205a3d/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java b/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java
new file mode 100644
index 0000000..8323176
--- /dev/null
+++ b/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java
@@ -0,0 +1,54 @@
+package org.apache.cloudstack.affinity;
+
+import java.util.List;
+
+public interface AffinityGroupService {
+
+    /**
+     * Creates an affinity/anti-affinity group for the given account/domain.
+     *
+     * @param account
+     * @param domainId
+     * @param name
+     * @param type
+     * @param description
+     * @return AffinityGroup
+     */
+
+    AffinityGroup createAffinityGroup(String account, Long domainId, String affinityGroupName,
+            String affinityGroupType, String description);
+
+    /**
+     * Creates an affinity/anti-affinity group.
+     *
+     * @param affinityGroupId
+     * @param account
+     * @param domainId
+     * @param affinityGroupName
+     * @param vmId
+     */
+    void deleteAffinityGroup(Long affinityGroupId, String account, Long domainId, String affinityGroupName, Long vmId);
+
+    /**
+     * Lists Affinity Groups
+     *
+     * @param account
+     * @param domainId
+     * @param affinityGroupId
+     * @param affinityGroupName
+     * @param affinityGroupType
+     * @param vmId
+     * @return
+     */
+    List<AffinityGroup> listAffinityGroups(String account, Long domainId, Long affinityGroupId,
+            String affinityGroupName, String affinityGroupType, Long vmId);
+
+
+    /**
+     * List group types available in deployment
+     *
+     * @return
+     */
+    List<String> listAffinityGroupTypes();
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1e205a3d/api/src/org/apache/cloudstack/api/ResponseGenerator.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ResponseGenerator.java b/api/src/org/apache/cloudstack/api/ResponseGenerator.java
index d1e1302..f09f8ae 100644
--- a/api/src/org/apache/cloudstack/api/ResponseGenerator.java
+++ b/api/src/org/apache/cloudstack/api/ResponseGenerator.java
@@ -20,8 +20,8 @@ import java.text.DecimalFormat;
 import java.util.EnumSet;
 import java.util.List;
 
-import org.apache.cloudstack.api.ApiConstants.HostDetails;
-import org.apache.cloudstack.api.ApiConstants.VMDetails;
+import org.apache.cloudstack.affinity.AffinityGroup;
+import org.apache.cloudstack.affinity.AffinityGroupResponse;
 import org.apache.cloudstack.api.command.user.job.QueryAsyncJobResultCmd;
 import org.apache.cloudstack.api.response.AccountResponse;
 import org.apache.cloudstack.api.response.AsyncJobResponse;
@@ -138,7 +138,6 @@ import com.cloud.org.Cluster;
 import com.cloud.projects.Project;
 import com.cloud.projects.ProjectAccount;
 import com.cloud.projects.ProjectInvitation;
-import com.cloud.region.ha.GlobalLoadBalancerRule;
 import com.cloud.server.ResourceTag;
 import com.cloud.storage.*;
 import com.cloud.storage.snapshot.SnapshotPolicy;
@@ -153,15 +152,7 @@ import com.cloud.vm.Nic;
 import com.cloud.vm.NicSecondaryIp;
 import com.cloud.vm.snapshot.VMSnapshot;
 import com.cloud.vm.VirtualMachine;
-import org.apache.cloudstack.api.ApiConstants.HostDetails;
-import org.apache.cloudstack.api.ApiConstants.VMDetails;
-import org.apache.cloudstack.api.command.user.job.QueryAsyncJobResultCmd;
 import org.apache.cloudstack.api.response.*;
-import org.apache.cloudstack.region.Region;
-
-import java.text.DecimalFormat;
-import java.util.EnumSet;
-import java.util.List;
 
 public interface ResponseGenerator {
     UserResponse createUserResponse(UserAccount user);
@@ -384,12 +375,15 @@ public interface ResponseGenerator {
     GuestOSResponse createGuestOSResponse(GuestOS os);
 
     SnapshotScheduleResponse createSnapshotScheduleResponse(SnapshotSchedule sched);
-    
+
     UsageRecordResponse createUsageResponse(Usage usageRecord);
 
     TrafficMonitorResponse createTrafficMonitorResponse(Host trafficMonitor);
     VMSnapshotResponse createVMSnapshotResponse(VMSnapshot vmSnapshot);
+
     NicSecondaryIpResponse createSecondaryIPToNicResponse(String ip,
             Long nicId, Long networkId);
     public NicResponse createNicResponse(Nic result);
+
+    AffinityGroupResponse createAffinityGroupResponse(AffinityGroup group);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1e205a3d/api/src/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java
new file mode 100644
index 0000000..c38bcff
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java
@@ -0,0 +1,126 @@
+// 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 org.apache.cloudstack.api.command.user.affinitygroup;
+
+import org.apache.cloudstack.affinity.AffinityGroup;
+import org.apache.cloudstack.affinity.AffinityGroupResponse;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.log4j.Logger;
+
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+
+@APICommand(name = "createAffinityGroup", responseObject = AffinityGroupResponse.class, description = "Creates an affinity/anti-affinity group")
+public class CreateAffinityGroupCmd extends BaseCmd {
+    public static final Logger s_logger = Logger.getLogger(CreateAffinityGroupCmd.class.getName());
+
+    private static final String s_name = "createaffinitygroupresponse";
+
+    // ///////////////////////////////////////////////////
+    // ////////////// API parameters /////////////////////
+    // ///////////////////////////////////////////////////
+
+    @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, required = true, description = "an account for the affinity group. Must be used with domainId.")
+    private String accountName;
+
+    @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, required = true, description = "domainId of the account owning the affinity group", entityType = DomainResponse.class)
+    private Long domainId;
+
+    @Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "optional description of the affinity group")
+    private String description;
+
+    @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "name of the affinity group")
+    private String affinityGroupName;
+
+    @Parameter(name = ApiConstants.TYPE, type = CommandType.STRING, required = true, description = "Type of the affinity group from the available affinity/anti-affinity group types")
+    private String affinityGroupType;
+
+
+    // ///////////////////////////////////////////////////
+    // ///////////////// Accessors ///////////////////////
+    // ///////////////////////////////////////////////////
+
+    public String getAccountName() {
+        return accountName;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public Long getDomainId() {
+        return domainId;
+    }
+
+    public String getAffinityGroupName() {
+        return affinityGroupName;
+    }
+
+    public String getAffinityGroupType() {
+        return affinityGroupType;
+    }
+
+    // ///////////////////////////////////////////////////
+    // ///////////// API Implementation///////////////////
+    // ///////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        Account account = UserContext.current().getCaller();
+        if ((account == null) || isAdmin(account.getType())) {
+            if ((domainId != null) && (accountName != null)) {
+                Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId);
+                if (userAccount != null) {
+                    return userAccount.getId();
+                }
+            }
+        }
+
+        if (account != null) {
+            return account.getId();
+        }
+
+        return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this
+                                          // command to SYSTEM so ERROR events
+                                          // are tracked
+    }
+
+    @Override
+    public void execute() {
+        AffinityGroup group = _affinityGroupService.createAffinityGroup(accountName, domainId, affinityGroupName,
+                affinityGroupType, description);
+        if (group != null) {
+            AffinityGroupResponse response = _responseGenerator.createAffinityGroupResponse(group);
+            response.setResponseName(getCommandName());
+            this.setResponseObject(response);
+        } else {
+            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create affinity group:"
+                    + affinityGroupName);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1e205a3d/server/src/com/cloud/api/ApiResponseHelper.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java
index 93b755a..7b23b3b 100755
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -270,8 +270,41 @@ import com.cloud.vm.NicVO;
 import com.cloud.vm.VMInstanceVO;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachine.Type;
+<<<<<<< HEAD
 import com.cloud.vm.dao.NicSecondaryIpVO;
 import com.cloud.vm.snapshot.VMSnapshot;
+=======
+import org.apache.cloudstack.acl.ControlledEntity;
+import org.apache.cloudstack.acl.ControlledEntity.ACLType;
+import org.apache.cloudstack.affinity.AffinityGroup;
+import org.apache.cloudstack.affinity.AffinityGroupResponse;
+import org.apache.cloudstack.api.ApiConstants.HostDetails;
+import org.apache.cloudstack.api.ApiConstants.VMDetails;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.ResponseGenerator;
+import org.apache.cloudstack.api.command.user.job.QueryAsyncJobResultCmd;
+import org.apache.cloudstack.api.response.*;
+import org.apache.cloudstack.region.Region;
+import org.apache.cloudstack.usage.Usage;
+import org.apache.cloudstack.usage.UsageService;
+import org.apache.cloudstack.usage.UsageTypes;
+import com.cloud.vm.VmStats;
+import com.cloud.vm.dao.UserVmData;
+import com.cloud.vm.dao.UserVmData.NicData;
+import com.cloud.vm.dao.UserVmData.SecurityGroupData;
+import com.cloud.vm.snapshot.VMSnapshot;
+import org.apache.cloudstack.api.ResponseGenerator;
+import org.apache.cloudstack.api.response.VMSnapshotResponse;
+import org.apache.log4j.Logger;
+
+import java.text.DecimalFormat;
+import java.util.*;
+
+import javax.inject.Inject;
+
+import static java.util.Collections.emptyList;
+import static java.util.Collections.singletonList;
+>>>>>>> More API changes
 
 @Component
 public class ApiResponseHelper implements ResponseGenerator {
@@ -439,7 +472,7 @@ public class ApiResponseHelper implements ResponseGenerator {
         vmSnapshotResponse.setCreated(vmSnapshot.getCreated());
         vmSnapshotResponse.setDescription(vmSnapshot.getDescription());
         vmSnapshotResponse.setDisplayName(vmSnapshot.getDisplayName());
-        UserVm vm = ApiDBUtils.findUserVmById(vmSnapshot.getVmId());        
+        UserVm vm = ApiDBUtils.findUserVmById(vmSnapshot.getVmId());
         if(vm!=null)
             vmSnapshotResponse.setVirtualMachineid(vm.getUuid());
         if(vmSnapshot.getParent() != null)
@@ -449,7 +482,7 @@ public class ApiResponseHelper implements ResponseGenerator {
         vmSnapshotResponse.setObjectName("vmsnapshot");
         return vmSnapshotResponse;
     }
-    
+
     @Override
     public SnapshotPolicyResponse createSnapshotPolicyResponse(SnapshotPolicy policy) {
         SnapshotPolicyResponse policyResponse = new SnapshotPolicyResponse();
@@ -546,7 +579,7 @@ public class ApiResponseHelper implements ResponseGenerator {
 
         vlanResponse.setIp6Gateway(vlan.getIp6Gateway());
         vlanResponse.setIp6Cidr(vlan.getIp6Cidr());
-        
+
         String ip6Range = vlan.getIp6Range();
         if (ip6Range != null) {
         	String[] range = ip6Range.split("-");
@@ -2250,7 +2283,7 @@ public class ApiResponseHelper implements ResponseGenerator {
         if (((network.getCidr()) != null) && (network.getNetworkCidr() == null)) {
             response.setNetmask(NetUtils.cidr2Netmask(network.getCidr()));
         }
-        
+
         response.setIp6Gateway(network.getIp6Gateway());
         response.setIp6Cidr(network.getIp6Cidr());
 
@@ -2445,7 +2478,7 @@ public class ApiResponseHelper implements ResponseGenerator {
 
         List<String> cidrs = ApiDBUtils.findFirewallSourceCidrs(fwRule.getId());
         response.setCidrList(StringUtils.join(cidrs, ","));
-        
+
         if (fwRule.getTrafficType() == FirewallRule.TrafficType.Ingress) {
             IpAddress ip = ApiDBUtils.findIpAddressById(fwRule.getSourceIpAddressId());
             response.setPublicIpAddressId(ip.getId());
@@ -3476,7 +3509,7 @@ public class ApiResponseHelper implements ResponseGenerator {
 		return usageRecResponse;
 	}
 
-	
+
     public String getDateStringInternal(Date inputDate) {
         if (inputDate == null) return null;
 
@@ -3560,7 +3593,7 @@ public class ApiResponseHelper implements ResponseGenerator {
 
         return sb.toString();
     }
-    
+
     @Override
     public TrafficMonitorResponse createTrafficMonitorResponse(Host trafficMonitor) {
         Map<String, String> tmDetails = ApiDBUtils.findHostDetailsById(trafficMonitor.getId());
@@ -3620,4 +3653,19 @@ public class ApiResponseHelper implements ResponseGenerator {
         response.setIsDefault(result.isDefaultNic());
         return response;
     }
+
+    @Override
+    public AffinityGroupResponse createAffinityGroupResponse(AffinityGroup group) {
+
+        AffinityGroupResponse response = new AffinityGroupResponse();
+
+        Account account = ApiDBUtils.findAccountById(group.getAccountId());
+        response.setAccountName(account.getAccountName());
+        response.setName(group.getName());
+        response.setType(group.getType());
+        response.setDescription(group.getDescription());
+        // response.setDomainId(account.)
+
+        return response;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1e205a3d/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
new file mode 100644
index 0000000..eee3e6f
--- /dev/null
+++ b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
@@ -0,0 +1,94 @@
+package org.apache.cloudstack.affinity;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+
+import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
+import org.apache.log4j.Logger;
+
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.user.Account;
+import com.cloud.user.AccountManager;
+import com.cloud.user.UserContext;
+import com.cloud.utils.component.Manager;
+import com.cloud.utils.component.ManagerBase;
+
+@Local(value = { AffinityGroupService.class })
+public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGroupService, Manager {
+
+    public static final Logger s_logger = Logger.getLogger(AffinityGroupServiceImpl.class);
+    private String _name;
+
+    @Inject
+    AccountManager _accountMgr;
+
+    @Inject
+    AffinityGroupDao _affinityGroupDao;
+
+    @Override
+    public AffinityGroup createAffinityGroup(String account, Long domainId, String affinityGroupName,
+            String affinityGroupType, String description) {
+
+        Account caller = UserContext.current().getCaller();
+        Account owner = _accountMgr.finalizeOwner(caller, account, domainId, null);
+
+        if (_affinityGroupDao.isNameInUse(owner.getId(), owner.getDomainId(), affinityGroupName)) {
+            throw new InvalidParameterValueException("Unable to create affinity group, a group with name "
+                    + affinityGroupName
+                    + " already exisits.");
+        }
+
+        AffinityGroupVO group = new AffinityGroupVO(affinityGroupName, affinityGroupType, description, domainId,
+                owner.getId());
+        _affinityGroupDao.persist(group);
+
+        return group;
+    }
+
+    @Override
+    public void deleteAffinityGroup(Long affinityGroupId, String account, Long domainId, String affinityGroupName,
+            Long vmId) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public List<AffinityGroup> listAffinityGroups(String account, Long domainId, Long affinityGroupId,
+            String affinityGroupName, String affinityGroupType, Long vmId) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public List<String> listAffinityGroupTypes() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
+        _name = name;
+        return true;
+    }
+
+    @Override
+    public boolean start() {
+        return true;
+    }
+
+    @Override
+    public boolean stop() {
+        return true;
+    }
+
+    @Override
+    public String getName() {
+        return _name;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1e205a3d/server/src/org/apache/cloudstack/affinity/AffinityGroupVMMapVO.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/AffinityGroupVMMapVO.java b/server/src/org/apache/cloudstack/affinity/AffinityGroupVMMapVO.java
new file mode 100644
index 0000000..5401b4a
--- /dev/null
+++ b/server/src/org/apache/cloudstack/affinity/AffinityGroupVMMapVO.java
@@ -0,0 +1,74 @@
+// 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 org.apache.cloudstack.affinity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.PrimaryKeyJoinColumn;
+import javax.persistence.SecondaryTable;
+import javax.persistence.SecondaryTables;
+import javax.persistence.Table;
+
+import org.apache.cloudstack.api.InternalIdentity;
+
+@Entity
+@Table(name = ("affinity_group_vm_map"))
+@SecondaryTables({ @SecondaryTable(name = "affinity_group", pkJoinColumns = { @PrimaryKeyJoinColumn(name = "affinity_group_id", referencedColumnName = "id") }) })
+public class AffinityGroupVMMapVO implements InternalIdentity {
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id")
+    private Long id;
+
+    @Column(name = "affinity_group_id")
+    private long affinityGroupId;
+
+    @Column(name = "instance_id")
+    private long instanceId;
+
+    @Column(name = "name", table = "affinity_group", insertable = false, updatable = false)
+    private String groupName;
+
+    public AffinityGroupVMMapVO() {
+    }
+
+    public AffinityGroupVMMapVO(long affinityGroupId, long instanceId) {
+        this.affinityGroupId = affinityGroupId;
+        this.instanceId = instanceId;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public long getAffinityGroupId() {
+        return affinityGroupId;
+    }
+
+
+    public long getInstanceId() {
+        return instanceId;
+    }
+
+
+    public String getGroupName() {
+        return groupName;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1e205a3d/server/src/org/apache/cloudstack/affinity/AffinityGroupVO.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/AffinityGroupVO.java b/server/src/org/apache/cloudstack/affinity/AffinityGroupVO.java
new file mode 100644
index 0000000..fab3835
--- /dev/null
+++ b/server/src/org/apache/cloudstack/affinity/AffinityGroupVO.java
@@ -0,0 +1,107 @@
+// 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 org.apache.cloudstack.affinity;
+
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+
+@Entity
+@Table(name = ("affinity_group"))
+public class AffinityGroupVO implements AffinityGroup {
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id")
+    private long id;
+
+    @Column(name = "name")
+    private String name;
+
+    @Column(name = "type")
+    private String type;
+
+    @Column(name = "description")
+    private String description;
+
+    @Column(name = "domain_id")
+    private long domainId;
+
+    @Column(name = "account_id")
+    private long accountId;
+
+    @Column(name = "uuid")
+    private String uuid;
+
+    public AffinityGroupVO() {
+    	this.uuid = UUID.randomUUID().toString();
+    }
+
+    public AffinityGroupVO(String name, String type, String description, long domainId, long accountId) {
+        this.name = name;
+        this.description = description;
+        this.domainId = domainId;
+        this.accountId = accountId;
+    	this.uuid = UUID.randomUUID().toString();
+        this.type = type;
+    }
+
+    @Override
+    public long getId() {
+        return id;
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public String getDescription() {
+        return description;
+    }
+
+    @Override
+    public long getDomainId() {
+        return domainId;
+    }
+
+    @Override
+    public long getAccountId() {
+        return accountId;
+    }
+
+    @Override
+    public String getUuid() {
+    	return this.uuid;
+    }
+
+    public void setUuid(String uuid) {
+    	this.uuid = uuid;
+    }
+
+    @Override
+    public String getType() {
+        return type;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1e205a3d/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupDao.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupDao.java b/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupDao.java
new file mode 100644
index 0000000..296e7b1
--- /dev/null
+++ b/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupDao.java
@@ -0,0 +1,30 @@
+// 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 org.apache.cloudstack.affinity.dao;
+
+import java.util.List;
+
+import org.apache.cloudstack.affinity.AffinityGroupVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface AffinityGroupDao extends GenericDao<AffinityGroupVO, Long> {
+    List<AffinityGroupVO> listByAccountId(long accountId);
+    boolean isNameInUse(Long accountId, Long domainId, String name);
+    AffinityGroupVO findByAccountAndName(Long accountId, String name);
+    List<AffinityGroupVO> findByAccountAndNames(Long accountId, String... names);
+    int removeByAccountId(long accountId); 
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1e205a3d/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupDaoImpl.java b/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupDaoImpl.java
new file mode 100644
index 0000000..bfa06c7
--- /dev/null
+++ b/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupDaoImpl.java
@@ -0,0 +1,97 @@
+// 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 org.apache.cloudstack.affinity.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+import org.apache.cloudstack.affinity.AffinityGroupVO;
+import org.springframework.stereotype.Component;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+
+@Component
+@Local(value = { AffinityGroupDao.class })
+public class AffinityGroupDaoImpl extends GenericDaoBase<AffinityGroupVO, Long> implements AffinityGroupDao {
+    private SearchBuilder<AffinityGroupVO> AccountIdSearch;
+    private SearchBuilder<AffinityGroupVO> AccountIdNameSearch;
+    private SearchBuilder<AffinityGroupVO> AccountIdNamesSearch;
+
+
+    protected AffinityGroupDaoImpl() {
+        AccountIdSearch = createSearchBuilder();
+        AccountIdSearch.and("accountId", AccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
+        AccountIdSearch.done();
+
+        AccountIdNameSearch = createSearchBuilder();
+        AccountIdNameSearch.and("accountId", AccountIdNameSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
+        AccountIdNameSearch.and("name", AccountIdNameSearch.entity().getName(), SearchCriteria.Op.EQ);
+
+        AccountIdNamesSearch = createSearchBuilder();
+        AccountIdNamesSearch.and("accountId", AccountIdNamesSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
+        AccountIdNamesSearch.and("groupNames", AccountIdNamesSearch.entity().getName(), SearchCriteria.Op.IN);
+        AccountIdNameSearch.done();
+    }
+
+    @Override
+    public List<AffinityGroupVO> listByAccountId(long accountId) {
+        SearchCriteria<AffinityGroupVO> sc = AccountIdSearch.create();
+        sc.setParameters("accountId", accountId);
+        return listBy(sc);
+    }
+
+    @Override
+    public boolean isNameInUse(Long accountId, Long domainId, String name) {
+        SearchCriteria<AffinityGroupVO> sc = createSearchCriteria();
+        sc.addAnd("name", SearchCriteria.Op.EQ, name);
+        if (accountId != null) {
+            sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+        } else {
+            sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+            sc.addAnd("accountId", SearchCriteria.Op.NULL);
+        }
+
+        List<AffinityGroupVO> AffinityGroups = listBy(sc);
+        return ((AffinityGroups != null) && !AffinityGroups.isEmpty());
+    }
+
+	@Override
+    public AffinityGroupVO findByAccountAndName(Long accountId, String name) {
+        SearchCriteria<AffinityGroupVO> sc = AccountIdNameSearch.create();
+		sc.setParameters("accountId", accountId);
+		sc.setParameters("name", name);
+
+		return findOneIncludingRemovedBy(sc);
+	}
+
+	@Override
+    public List<AffinityGroupVO> findByAccountAndNames(Long accountId, String... names) {
+        SearchCriteria<AffinityGroupVO> sc = AccountIdNamesSearch.create();
+		sc.setParameters("accountId", accountId);
+
+		sc.setParameters("groupNames", (Object [])names);
+
+		return listBy(sc);
+	}
+	@Override
+	public int removeByAccountId(long accountId) {
+        SearchCriteria<AffinityGroupVO> sc = AccountIdSearch.create();
+	    sc.setParameters("accountId", accountId);
+	    return expunge(sc);
+	}
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1e205a3d/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDao.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDao.java b/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDao.java
new file mode 100644
index 0000000..9841de4
--- /dev/null
+++ b/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDao.java
@@ -0,0 +1,43 @@
+// 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 org.apache.cloudstack.affinity.dao;
+
+import java.util.List;
+
+import org.apache.cloudstack.affinity.AffinityGroupVMMapVO;
+
+import com.cloud.utils.Pair;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDao;
+import com.cloud.vm.VirtualMachine.State;
+
+public interface AffinityGroupVMMapDao extends GenericDao<AffinityGroupVMMapVO, Long> {
+
+    List<AffinityGroupVMMapVO> listByInstanceId(long instanceId);
+
+    Pair<List<AffinityGroupVMMapVO>, Integer> listByInstanceId(long instanceId, Filter filter);
+
+    List<AffinityGroupVMMapVO> listByAffinityGroup(long affinityGroupId);
+
+    List<Long> listVmIdsByAffinityGroup(long affinityGroupId);
+
+    AffinityGroupVMMapVO findByVmIdGroupId(long instanceId, long affinityGroupId);
+
+    long countAffinityGroupsForVm(long instanceId);
+
+    int deleteVM(long instanceId);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1e205a3d/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java b/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java
new file mode 100644
index 0000000..e9286db
--- /dev/null
+++ b/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java
@@ -0,0 +1,120 @@
+// 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 org.apache.cloudstack.affinity.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.apache.cloudstack.affinity.AffinityGroupVMMapVO;
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.Pair;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Func;
+
+@Component
+@Local(value = { AffinityGroupVMMapDao.class })
+public class AffinityGroupVMMapDaoImpl extends GenericDaoBase<AffinityGroupVMMapVO, Long> implements
+        AffinityGroupVMMapDao {
+    private SearchBuilder<AffinityGroupVMMapVO> ListByVmId;
+    private SearchBuilder<AffinityGroupVMMapVO> ListByVmIdGroupId;
+    protected GenericSearchBuilder<AffinityGroupVMMapVO, Long> CountSGForVm;
+    private GenericSearchBuilder<AffinityGroupVMMapVO, Long> ListVmIdByAffinityGroup;
+    private SearchBuilder<AffinityGroupVMMapVO> ListByAffinityGroup;
+
+    protected AffinityGroupVMMapDaoImpl() {
+        ListVmIdByAffinityGroup = createSearchBuilder(Long.class);
+        ListVmIdByAffinityGroup.and("affinityGroupId", ListVmIdByAffinityGroup.entity().getAffinityGroupId(),
+                SearchCriteria.Op.EQ);
+        ListVmIdByAffinityGroup.selectField(ListVmIdByAffinityGroup.entity().getInstanceId());
+        ListVmIdByAffinityGroup.done();
+
+        ListByAffinityGroup = createSearchBuilder();
+        ListByAffinityGroup.and("affinityGroupId", ListByAffinityGroup.entity().getAffinityGroupId(),
+                SearchCriteria.Op.EQ);
+        ListByAffinityGroup.done();
+
+        ListByVmId  = createSearchBuilder();
+        ListByVmId.and("instanceId", ListByVmId.entity().getInstanceId(), SearchCriteria.Op.EQ);
+        ListByVmId.done();
+
+        ListByVmIdGroupId  = createSearchBuilder();
+        ListByVmIdGroupId.and("instanceId", ListByVmIdGroupId.entity().getInstanceId(), SearchCriteria.Op.EQ);
+        ListByVmIdGroupId.and("affinityGroupId", ListByVmIdGroupId.entity().getAffinityGroupId(), SearchCriteria.Op.EQ);
+        ListByVmIdGroupId.done();
+
+        CountSGForVm = createSearchBuilder(Long.class);
+        CountSGForVm.select(null, Func.COUNT, null);
+        CountSGForVm.and("vmId", CountSGForVm.entity().getInstanceId(), SearchCriteria.Op.EQ);
+        CountSGForVm.done();
+    }
+
+    @Override
+    public List<AffinityGroupVMMapVO> listByAffinityGroup(long affinityGroupId) {
+        SearchCriteria<AffinityGroupVMMapVO> sc = ListByAffinityGroup.create();
+        sc.setParameters("affinityGroupId", affinityGroupId);
+        return listBy(sc);
+    }
+
+    @Override
+    public List<AffinityGroupVMMapVO> listByInstanceId(long vmId) {
+        SearchCriteria<AffinityGroupVMMapVO> sc = ListByVmId.create();
+        sc.setParameters("instanceId", vmId);
+        return listBy(sc);
+    }
+
+    @Override
+    public Pair<List<AffinityGroupVMMapVO>, Integer> listByInstanceId(long instanceId, Filter filter) {
+        SearchCriteria<AffinityGroupVMMapVO> sc = ListByVmId.create();
+        sc.setParameters("instanceId", instanceId);
+        return this.searchAndCount(sc, filter);
+    }
+
+    @Override
+    public int deleteVM(long instanceId) {
+        SearchCriteria<AffinityGroupVMMapVO> sc = ListByVmId.create();
+        sc.setParameters("instanceId", instanceId);
+        return super.expunge(sc);
+    }
+
+    @Override
+    public List<Long> listVmIdsByAffinityGroup(long affinityGroupId) {
+        SearchCriteria<Long> sc = ListVmIdByAffinityGroup.create();
+        sc.setParameters("affinityGroupId", affinityGroupId);
+        return customSearchIncludingRemoved(sc, null);
+    }
+
+	@Override
+    public AffinityGroupVMMapVO findByVmIdGroupId(long instanceId, long affinityGroupId) {
+        SearchCriteria<AffinityGroupVMMapVO> sc = ListByVmIdGroupId.create();
+        sc.setParameters("affinityGroupId", affinityGroupId);
+        sc.setParameters("instanceId", instanceId);
+		return findOneIncludingRemovedBy(sc);
+	}
+
+	@Override
+    public long countAffinityGroupsForVm(long instanceId) {
+		SearchCriteria<Long> sc = CountSGForVm.create();
+    	sc.setParameters("vmId", instanceId);
+        return customSearch(sc, null).get(0);
+	}
+}


[21/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
Added cleanup of affinitygroups when a VM is expunging and when the account is deleted.


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

Branch: refs/heads/master
Commit: 0b3850c14f9f3420d92bf6eb3477959b8f28e4ad
Parents: ec3f844
Author: Prachi Damle <pr...@cloud.com>
Authored: Wed Apr 3 16:53:57 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:23:18 2013 -0700

----------------------------------------------------------------------
 server/src/com/cloud/user/AccountManagerImpl.java  |    9 ++++++++-
 .../affinity/AffinityGroupServiceImpl.java         |    5 ++---
 2 files changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0b3850c1/server/src/com/cloud/user/AccountManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java
index bc93df8..fe714c5 100755
--- a/server/src/com/cloud/user/AccountManagerImpl.java
+++ b/server/src/com/cloud/user/AccountManagerImpl.java
@@ -42,6 +42,7 @@ import org.apache.cloudstack.acl.ControlledEntity;
 import org.apache.cloudstack.acl.RoleType;
 import org.apache.cloudstack.acl.SecurityChecker;
 import org.apache.cloudstack.acl.SecurityChecker.AccessType;
+import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
 import org.apache.cloudstack.api.command.admin.account.UpdateAccountCmd;
 import org.apache.cloudstack.api.command.admin.user.DeleteUserCmd;
 import org.apache.cloudstack.api.command.admin.user.RegisterCmd;
@@ -220,6 +221,8 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
     @Inject
     private AutoScaleManager _autoscaleMgr;
     @Inject VolumeManager volumeMgr;
+    @Inject
+    private AffinityGroupDao _affinityGroupDao;
 
     private List<UserAuthenticator> _userAuthenticators;
     List<UserAuthenticator> _userPasswordEncoders;
@@ -238,7 +241,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
     public List<UserAuthenticator> getUserAuthenticators() {
     	return _userAuthenticators;
     }
-    
+
     public void setUserAuthenticators(List<UserAuthenticator> authenticators) {
     	_userAuthenticators = authenticators;
     }
@@ -623,6 +626,10 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
             int numRemoved = _securityGroupDao.removeByAccountId(accountId);
             s_logger.info("deleteAccount: Deleted " + numRemoved + " network groups for account " + accountId);
 
+            // Cleanup affinity groups
+            int numAGRemoved = _affinityGroupDao.removeByAccountId(accountId);
+            s_logger.info("deleteAccount: Deleted " + numAGRemoved + " affinity groups for account " + accountId);
+
             // Delete all the networks
             boolean networksDeleted = true;
             s_logger.debug("Deleting networks for account " + account.getId());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0b3850c1/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
index e143db4..17f7401 100644
--- a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
+++ b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
@@ -240,6 +240,7 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
     @Override
     public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
         _name = name;
+        VirtualMachine.State.getStateMachine().registerListener(this);
         return true;
     }
 
@@ -308,9 +309,7 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
                 throw new InvalidParameterValueException("Unable to find affinity group by id " + affinityGroupId);
             }
         }
-        if (affinityGroupIds != null && !affinityGroupIds.isEmpty()) {
-            _affinityGroupVMMapDao.updateMap(vmId, affinityGroupIds);
-        }
+        _affinityGroupVMMapDao.updateMap(vmId, affinityGroupIds);
         // APIResponseHelper will pull out the updated affinitygroups.
         return vmInstance;
 


[31/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
ACl on affinity group


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

Branch: refs/heads/master
Commit: fc248cb99c2febfa165e215dc2d2c38fddf980b5
Parents: 9de7a68
Author: Prachi Damle <pr...@cloud.com>
Authored: Mon Apr 8 13:27:18 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:23:41 2013 -0700

----------------------------------------------------------------------
 server/src/com/cloud/vm/UserVmManagerImpl.java |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fc248cb9/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java
index 8b6ad3b..d281e5b 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -2289,6 +2289,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
                 AffinityGroupVO ag = _affinityGroupDao.findById(affinityGroupId);
                 if (ag == null) {
                     throw new InvalidParameterValueException("Unable to find affinity group by id " + affinityGroupId);
+                } else {
+                    // verify permissions
+                    _accountMgr.checkAccess(caller, null, true, owner, ag);
                 }
             }
         }


[34/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
Fixes to unit-test dues to changes in master


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

Branch: refs/heads/master
Commit: 6137d327a8969e403c4fe0ae05c2bd1d7a12033e
Parents: eea0ed5
Author: Prachi Damle <pr...@cloud.com>
Authored: Thu Apr 11 13:09:49 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:23:48 2013 -0700

----------------------------------------------------------------------
 .../affinity/AffinityGroupServiceImpl.java         |    3 +-
 .../affinity/AffinityApiTestConfiguration.java     |   18 +++++++++++-
 .../cloudstack/affinity/AffinityApiUnitTest.java   |   10 +++++++
 server/test/resources/affinityContext.xml          |   21 ++++++++------
 4 files changed, 40 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6137d327/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
index 613c095..2ea887c 100644
--- a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
+++ b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
@@ -64,6 +64,7 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
     private UserVmDao _userVmDao;
 
     @Override
+    @ActionEvent(eventType = EventTypes.EVENT_AFFINITY_GROUP_CREATE, eventDescription = "Creating Affinity Group", create = true)
     public AffinityGroup createAffinityGroup(String account, Long domainId, String affinityGroupName,
             String affinityGroupType, String description) {
 
@@ -106,7 +107,7 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
 
     @DB
     @Override
-    @ActionEvent(eventType = EventTypes.EVENT_SECURITY_GROUP_DELETE, eventDescription = "deleting affinity group")
+    @ActionEvent(eventType = EventTypes.EVENT_AFFINITY_GROUP_DELETE, eventDescription = "Deleting affinity group")
     public boolean deleteAffinityGroup(Long affinityGroupId, String account, Long domainId, String affinityGroupName)
             throws ResourceInUseException {
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6137d327/server/test/org/apache/cloudstack/affinity/AffinityApiTestConfiguration.java
----------------------------------------------------------------------
diff --git a/server/test/org/apache/cloudstack/affinity/AffinityApiTestConfiguration.java b/server/test/org/apache/cloudstack/affinity/AffinityApiTestConfiguration.java
index d778ed4..c6a0755 100644
--- a/server/test/org/apache/cloudstack/affinity/AffinityApiTestConfiguration.java
+++ b/server/test/org/apache/cloudstack/affinity/AffinityApiTestConfiguration.java
@@ -50,6 +50,8 @@ import com.cloud.dc.dao.PodVlanDaoImpl;
 import com.cloud.dc.dao.PodVlanMapDaoImpl;
 import com.cloud.dc.dao.VlanDaoImpl;
 import com.cloud.domain.dao.DomainDaoImpl;
+import com.cloud.event.EventUtils;
+import com.cloud.event.dao.EventDaoImpl;
 import com.cloud.event.dao.UsageEventDaoImpl;
 import com.cloud.host.dao.HostDaoImpl;
 import com.cloud.host.dao.HostDetailsDaoImpl;
@@ -100,6 +102,7 @@ import com.cloud.user.AccountManager;
 import com.cloud.user.ResourceLimitService;
 import com.cloud.user.UserContext;
 import com.cloud.user.UserContextInitializer;
+import com.cloud.user.dao.AccountDao;
 import com.cloud.user.dao.AccountDaoImpl;
 import com.cloud.user.dao.UserDaoImpl;
 import com.cloud.utils.component.SpringComponentScanUtils;
@@ -115,7 +118,7 @@ import com.cloud.vm.dao.VMInstanceDaoImpl;
 @Configuration
 @ComponentScan(basePackageClasses = { AccountVlanMapDaoImpl.class, VolumeDaoImpl.class, HostPodDaoImpl.class,
         DomainDaoImpl.class, SwiftDaoImpl.class, ServiceOfferingDaoImpl.class, VlanDaoImpl.class,
-        IPAddressDaoImpl.class, ResourceTagsDaoImpl.class, AccountDaoImpl.class, InstanceGroupDaoImpl.class,
+        IPAddressDaoImpl.class, ResourceTagsDaoImpl.class, InstanceGroupDaoImpl.class,
         UserAccountJoinDaoImpl.class, CapacityDaoImpl.class, SnapshotDaoImpl.class, HostDaoImpl.class,
         VMInstanceDaoImpl.class, HostTransferMapDaoImpl.class, PortForwardingRulesDaoImpl.class,
         PrivateIpDaoImpl.class, UsageEventDaoImpl.class, PodVlanMapDaoImpl.class, DiskOfferingDaoImpl.class,
@@ -126,10 +129,21 @@ import com.cloud.vm.dao.VMInstanceDaoImpl;
         FirewallRulesCidrsDaoImpl.class, PhysicalNetworkDaoImpl.class, PhysicalNetworkTrafficTypeDaoImpl.class,
         PhysicalNetworkServiceProviderDaoImpl.class, LoadBalancerDaoImpl.class, NetworkServiceMapDaoImpl.class,
         PrimaryDataStoreDaoImpl.class, StoragePoolDetailsDaoImpl.class, AffinityGroupServiceImpl.class,
-        ComponentContext.class, AffinityGroupProcessor.class, UserVmVO.class }, includeFilters = { @Filter(value = AffinityApiTestConfiguration.Library.class, type = FilterType.CUSTOM) }, useDefaultFilters = false)
+        ComponentContext.class, AffinityGroupProcessor.class, UserVmVO.class, EventUtils.class, UserVmVO.class,
+        EventDaoImpl.class }, includeFilters = { @Filter(value = AffinityApiTestConfiguration.Library.class, type = FilterType.CUSTOM) }, useDefaultFilters = false)
 public class AffinityApiTestConfiguration {
 
     @Bean
+    public AccountDao accountDao() {
+        return Mockito.mock(AccountDao.class);
+    }
+
+    @Bean
+    public EventUtils eventUtils() {
+        return Mockito.mock(EventUtils.class);
+    }
+
+    @Bean
     public AffinityGroupProcessor affinityGroupProcessor() {
         return Mockito.mock(AffinityGroupProcessor.class);
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6137d327/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
----------------------------------------------------------------------
diff --git a/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java b/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
index 17f165d..86cf017 100644
--- a/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
+++ b/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
@@ -34,6 +34,7 @@ import org.junit.runner.RunWith;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
+import com.cloud.event.EventUtils;
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.ResourceInUseException;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
@@ -43,6 +44,7 @@ import com.cloud.user.AccountManagerImpl;
 import com.cloud.user.AccountVO;
 import com.cloud.user.UserContext;
 import com.cloud.user.UserContextInitializer;
+import com.cloud.user.dao.AccountDao;
 import com.cloud.utils.component.ComponentContext;
 import com.cloud.vm.UserVmVO;
 import com.cloud.vm.VirtualMachine;
@@ -73,6 +75,12 @@ public class AffinityApiUnitTest {
     @Inject
     AffinityGroupVMMapDao _affinityGroupVMMapDao;
 
+    @Inject
+    EventUtils _eventUtils;
+
+    @Inject
+    AccountDao _accountDao;
+
     private static long domainId = 5L;
 
 
@@ -83,6 +91,7 @@ public class AffinityApiUnitTest {
 
     @Before
     public void testSetUp() {
+        ComponentContext.initComponentsLifeCycle();
         AccountVO acct = new AccountVO(200L);
         acct.setType(Account.ACCOUNT_TYPE_NORMAL);
         acct.setAccountName("user");
@@ -92,6 +101,7 @@ public class AffinityApiUnitTest {
 
         when(_acctMgr.finalizeOwner((Account) anyObject(), anyString(), anyLong(), anyLong())).thenReturn(acct);
         when(_processor.getType()).thenReturn("mock");
+        when(_accountDao.findByIdIncludingRemoved(0L)).thenReturn(acct);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6137d327/server/test/resources/affinityContext.xml
----------------------------------------------------------------------
diff --git a/server/test/resources/affinityContext.xml b/server/test/resources/affinityContext.xml
index 652905c..15476c1 100644
--- a/server/test/resources/affinityContext.xml
+++ b/server/test/resources/affinityContext.xml
@@ -23,13 +23,18 @@
      <context:annotation-config />
 
     <!-- @DB support -->
-    <aop:config proxy-target-class="true">
-    <aop:aspect id="dbContextBuilder" ref="transactionContextBuilder">
-    <aop:pointcut id="captureAnyMethod" expression="execution(* *(..))" />
-
-    <aop:around pointcut-ref="captureAnyMethod" method="AroundAnyMethod" />
-    </aop:aspect>
-    </aop:config>
+	<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 id="ConfigurationManager" class="com.cloud.configuration.ConfigurationManagerImpl">
@@ -38,7 +43,5 @@
   
     <bean class="org.apache.cloudstack.affinity.AffinityApiTestConfiguration" />
     
-    <bean id="transactionContextBuilder" class="com.cloud.utils.db.TransactionContextBuilder" />
-    
 
 </beans>
\ No newline at end of file


[17/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
Build failure fixes after rebase.


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

Branch: refs/heads/master
Commit: ee45437036afa743390c5d39e965cd6c85eafb87
Parents: e312158
Author: Prachi Damle <pr...@cloud.com>
Authored: Fri Mar 29 13:10:29 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:23:08 2013 -0700

----------------------------------------------------------------------
 api/src/org/apache/cloudstack/api/BaseCmd.java     |    1 +
 .../apache/cloudstack/api/ResponseGenerator.java   |    4 +++-
 server/src/com/cloud/api/ApiResponseHelper.java    |    3 ---
 3 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ee454370/api/src/org/apache/cloudstack/api/BaseCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/BaseCmd.java b/api/src/org/apache/cloudstack/api/BaseCmd.java
index c94f3fb..42c0680 100644
--- a/api/src/org/apache/cloudstack/api/BaseCmd.java
+++ b/api/src/org/apache/cloudstack/api/BaseCmd.java
@@ -61,6 +61,7 @@ import com.cloud.projects.ProjectService;
 import com.cloud.resource.ResourceService;
 import com.cloud.server.ManagementService;
 import com.cloud.server.TaggedResourceService;
+import com.cloud.storage.DataStoreProviderApiService;
 import com.cloud.storage.StorageService;
 import com.cloud.storage.VolumeApiService;
 import com.cloud.storage.snapshot.SnapshotService;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ee454370/api/src/org/apache/cloudstack/api/ResponseGenerator.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ResponseGenerator.java b/api/src/org/apache/cloudstack/api/ResponseGenerator.java
index 9777130..c0dd57e 100644
--- a/api/src/org/apache/cloudstack/api/ResponseGenerator.java
+++ b/api/src/org/apache/cloudstack/api/ResponseGenerator.java
@@ -22,6 +22,8 @@ import java.util.List;
 
 import org.apache.cloudstack.affinity.AffinityGroup;
 import org.apache.cloudstack.affinity.AffinityGroupResponse;
+import org.apache.cloudstack.api.ApiConstants.HostDetails;
+import org.apache.cloudstack.api.ApiConstants.VMDetails;
 import org.apache.cloudstack.api.command.user.job.QueryAsyncJobResultCmd;
 import org.apache.cloudstack.api.response.AccountResponse;
 import org.apache.cloudstack.api.response.AsyncJobResponse;
@@ -138,6 +140,7 @@ import com.cloud.org.Cluster;
 import com.cloud.projects.Project;
 import com.cloud.projects.ProjectAccount;
 import com.cloud.projects.ProjectInvitation;
+import com.cloud.region.ha.GlobalLoadBalancerRule;
 import com.cloud.server.ResourceTag;
 import com.cloud.storage.*;
 import com.cloud.storage.snapshot.SnapshotPolicy;
@@ -149,7 +152,6 @@ import com.cloud.user.UserAccount;
 import com.cloud.uservm.UserVm;
 import com.cloud.vm.InstanceGroup;
 import com.cloud.vm.Nic;
-import com.cloud.vm.NicSecondaryIp;
 import com.cloud.vm.snapshot.VMSnapshot;
 import com.cloud.vm.VirtualMachine;
 import org.apache.cloudstack.api.response.*;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ee454370/server/src/com/cloud/api/ApiResponseHelper.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java
index d651f1f..651a8be 100755
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -270,10 +270,8 @@ import com.cloud.vm.NicVO;
 import com.cloud.vm.VMInstanceVO;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachine.Type;
-<<<<<<< HEAD
 import com.cloud.vm.dao.NicSecondaryIpVO;
 import com.cloud.vm.snapshot.VMSnapshot;
-=======
 import org.apache.cloudstack.acl.ControlledEntity;
 import org.apache.cloudstack.acl.ControlledEntity.ACLType;
 import org.apache.cloudstack.affinity.AffinityGroup;
@@ -304,7 +302,6 @@ import javax.inject.Inject;
 
 import static java.util.Collections.emptyList;
 import static java.util.Collections.singletonList;
->>>>>>> More API changes
 
 @Component
 public class ApiResponseHelper implements ResponseGenerator {


[30/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
affinitygroup bvt: changes to the bvt for affinity groups

Added tags for the test, base.py extensions for list, craete, delete and
fixes to the test

Signed-off-by: Prasanna Santhanam <ts...@apache.org>


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

Branch: refs/heads/master
Commit: 9de7a68e922951d9a92c6f6ac3ae1f06199a943c
Parents: 7201eb9
Author: Prasanna Santhanam <ts...@apache.org>
Authored: Tue Apr 9 16:31:18 2013 +0530
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:23:39 2013 -0700

----------------------------------------------------------------------
 test/integration/smoke/test_affinity_groups.py |   23 +++++++++--------
 tools/marvin/marvin/integration/lib/base.py    |   25 +++++++++++-------
 2 files changed, 27 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9de7a68e/test/integration/smoke/test_affinity_groups.py
----------------------------------------------------------------------
diff --git a/test/integration/smoke/test_affinity_groups.py b/test/integration/smoke/test_affinity_groups.py
index 0d06e64..832c4a4 100644
--- a/test/integration/smoke/test_affinity_groups.py
+++ b/test/integration/smoke/test_affinity_groups.py
@@ -52,12 +52,12 @@ class Services:
                 # In MBs
             },
             "ostype": 'CentOS 5.3 (64-bit)',
-            "mode": 'advanced',
             "virtual_machine" : {
                 "affinity": {
                     "name": "webvms",
                     "type": "host anti-affinity",
-                }
+                },
+                "hypervisor" : "XenServer",
             }
         }
 
@@ -98,19 +98,22 @@ class TestDeployVmWithAffinityGroup(cloudstackTestCase):
             cls.services["service_offering"]
         )
 
-        cls.ag = AffinityGroup.create(cls.api_client, cls.services["virtual_machine"]["affinity"], domainid=cls.domain.id)
+        cls.ag = AffinityGroup.create(cls.api_client, cls.services["virtual_machine"]["affinity"],
+            account=cls.services["account"], domainid=cls.domain.id)
 
         cls._cleanup = [
             cls.service_offering,
-            cls.disk_offering,
             cls.account,
         ]
         return
 
-    @attr(tags=["simulator", "basic", "advanced"])
+    @attr(tags=["simulator", "basic", "advanced", "multihost"])
     def test_DeployVmAntiAffinityGroup(self):
         """
-        Deploys a couple of VMs in the same affinity group and verifies they are not on the same host
+        test DeployVM in anti-affinity groups
+
+        deploy VM1 and VM2 in the same host-anti-affinity groups
+        Verify that the vms are deployed on separate hosts
         """
         #deploy VM1 in affinity group created in setUp
         vm1 = VirtualMachine.create(
@@ -120,8 +123,7 @@ class TestDeployVmWithAffinityGroup(cloudstackTestCase):
             accountid=self.account.account.name,
             domainid=self.account.account.domainid,
             serviceofferingid=self.service_offering.id,
-            affinitygroupnames=self.ag.name,
-            mode=self.services["mode"]
+            affinitygroupnames=[self.ag.name]
         )
 
         list_vm1 = list_virtual_machines(
@@ -154,12 +156,11 @@ class TestDeployVmWithAffinityGroup(cloudstackTestCase):
             accountid=self.account.account.name,
             domainid=self.account.account.domainid,
             serviceofferingid=self.service_offering.id,
-            affinitygroupnames=self.ag.name,
-            mode=self.services["mode"]
+            affinitygroupnames=[self.ag.name]
         )
         list_vm2 = list_virtual_machines(
             self.api_client,
-            id=self.vm1.id
+            id=vm2.id
         )
         self.assertEqual(
             isinstance(list_vm2, list),

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9de7a68e/tools/marvin/marvin/integration/lib/base.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/integration/lib/base.py b/tools/marvin/marvin/integration/lib/base.py
index 8c7470e..d27ab3b 100644
--- a/tools/marvin/marvin/integration/lib/base.py
+++ b/tools/marvin/marvin/integration/lib/base.py
@@ -90,10 +90,7 @@ class Account:
         cmd.firstname = services["firstname"]
         cmd.lastname = services["lastname"]
 
-        # Password Encoding
-        mdf = hashlib.md5()
-        mdf.update(services["password"])
-        cmd.password = mdf.hexdigest()
+        cmd.password = services["password"]
         cmd.username = "-".join([services["username"], random_gen()])
 
         if domainid:
@@ -223,7 +220,7 @@ class VirtualMachine:
     def create(cls, apiclient, services, templateid=None, accountid=None,
                     domainid=None, zoneid=None, networkids=None, serviceofferingid=None,
                     securitygroupids=None, projectid=None, startvm=None,
-                    diskofferingid=None, affinitygroupname=None, hostid=None, mode='basic'):
+                    diskofferingid=None, affinitygroupnames=None, hostid=None, mode='basic'):
         """Create the instance"""
 
         cmd = deployVirtualMachine.deployVirtualMachineCmd()
@@ -270,6 +267,8 @@ class VirtualMachine:
 
         if "affinitygroupnames" in services:
             cmd.affinitygroupnames  = services["affinitygroupnames"]
+        elif affinitygroupnames:
+            cmd.affinitygroupnames  = affinitygroupnames
 
         if projectid:
             cmd.projectid = projectid
@@ -2441,13 +2440,19 @@ class AffinityGroup:
         agCmd.type = services['type']
         agCmd.account = services['account'] if 'account' in services else account
         agCmd.domainid = services['domainid'] if 'domainid' in services else domainid
+        return AffinityGroup(apiclient.createAffinityGroup(agCmd).__dict__)
 
-    def update(self):
+    def update(self, apiclient):
         pass
 
-    def delete(self):
-        pass
+    def delete(self, apiclient):
+        cmd = deleteAffinityGroup.deleteAffinityGroupCmd()
+        cmd.id = self.id
+        return apiclient.deleteVPC(cmd)
+
 
     @classmethod
-    def list(cls):
-        pass
\ No newline at end of file
+    def list(cls, apiclient, **kwargs):
+        cmd = listAffinityGroups.listAffinityGroupsCmd()
+        [setattr(cmd, k, v) for k, v in kwargs.items()]
+        return(apiclient.listVPCs(cmd))


[33/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
Fixes for issues found while testing after the merge


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

Branch: refs/heads/master
Commit: eea0ed5c4e9b55b4ded12dc268c93f1cf3bb20a0
Parents: bbf7900
Author: Prachi Damle <pr...@cloud.com>
Authored: Thu Apr 11 12:17:31 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:23:46 2013 -0700

----------------------------------------------------------------------
 .../user/affinitygroup/DeleteAffinityGroupCmd.java |    2 +-
 .../affinity/HostAntiAffinityProcessor.java        |    1 +
 .../affinity/AffinityGroupServiceImpl.java         |   10 +++++++++-
 3 files changed, 11 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eea0ed5c/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java
index 4ceba29..ea4a010 100644
--- a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java
@@ -52,7 +52,7 @@ public class DeleteAffinityGroupCmd extends BaseAsyncCmd {
     @Parameter(name = ApiConstants.ID, type = CommandType.UUID, description = "The ID of the affinity group. Mutually exclusive with name parameter", entityType = AffinityGroupResponse.class)
     private Long id;
 
-    @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "The ID of the affinity group. Mutually exclusive with id parameter")
+    @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "The name of the affinity group. Mutually exclusive with id parameter")
     private String name;
 
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eea0ed5c/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
----------------------------------------------------------------------
diff --git a/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java b/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
index 4011c02..430cf92 100644
--- a/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
+++ b/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java
@@ -62,6 +62,7 @@ public class HostAntiAffinityProcessor extends AffinityProcessorBase implements
             }
 
             List<Long> groupVMIds = _affinityGroupVMMapDao.listVmIdsByAffinityGroup(group.getId());
+            groupVMIds.remove(vm.getId());
 
             for (Long groupVMId : groupVMIds) {
                 VMInstanceVO groupVM = _vmInstanceDao.findById(groupVMId);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eea0ed5c/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
index 5c7edc5..613c095 100644
--- a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
+++ b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
@@ -130,7 +130,9 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
             throw new InvalidParameterValueException(
                     "Either the affinity group Id or group name must be specified to delete the group");
         }
-
+        if (affinityGroupId == null) {
+            affinityGroupId = group.getId();
+        }
         // check permissions
         _accountMgr.checkAccess(caller, null, true, group);
 
@@ -302,11 +304,17 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
                     + "; make sure the virtual machine is stopped and not in an error state before updating.");
         }
 
+        Account caller = UserContext.current().getCaller();
+        Account owner = _accountMgr.getAccount(vmInstance.getAccountId());
+
         // check that the affinity groups exist
         for (Long affinityGroupId : affinityGroupIds) {
             AffinityGroupVO ag = _affinityGroupDao.findById(affinityGroupId);
             if (ag == null) {
                 throw new InvalidParameterValueException("Unable to find affinity group by id " + affinityGroupId);
+            } else {
+                // verify permissions
+                _accountMgr.checkAccess(caller, null, true, owner, ag);
             }
         }
         _affinityGroupVMMapDao.updateMap(vmId, affinityGroupIds);


[18/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
Adding a unit test for the new affinity groups API


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

Branch: refs/heads/master
Commit: b633dde744057d8fbeb8bfa2b05b04ca8159793a
Parents: ee45437
Author: Prachi Damle <pr...@cloud.com>
Authored: Mon Apr 1 11:08:16 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:23:11 2013 -0700

----------------------------------------------------------------------
 .../affinity/AffinityGroupServiceImpl.java         |    5 +-
 .../affinity/AffinityApiTestConfiguration.java     |  318 +++++++++++++++
 .../cloudstack/affinity/AffinityApiUnitTest.java   |  164 ++++++++
 server/test/resources/affinityContext.xml          |   44 ++
 4 files changed, 529 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b633dde7/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
index b22ed83..e143db4 100644
--- a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
+++ b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
@@ -308,8 +308,9 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
                 throw new InvalidParameterValueException("Unable to find affinity group by id " + affinityGroupId);
             }
         }
-        _affinityGroupVMMapDao.updateMap(vmId, affinityGroupIds);
-
+        if (affinityGroupIds != null && !affinityGroupIds.isEmpty()) {
+            _affinityGroupVMMapDao.updateMap(vmId, affinityGroupIds);
+        }
         // APIResponseHelper will pull out the updated affinitygroups.
         return vmInstance;
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b633dde7/server/test/org/apache/cloudstack/affinity/AffinityApiTestConfiguration.java
----------------------------------------------------------------------
diff --git a/server/test/org/apache/cloudstack/affinity/AffinityApiTestConfiguration.java b/server/test/org/apache/cloudstack/affinity/AffinityApiTestConfiguration.java
new file mode 100644
index 0000000..d778ed4
--- /dev/null
+++ b/server/test/org/apache/cloudstack/affinity/AffinityApiTestConfiguration.java
@@ -0,0 +1,318 @@
+// 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 org.apache.cloudstack.affinity;
+
+import java.io.IOException;
+
+import org.apache.cloudstack.acl.SecurityChecker;
+import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
+import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
+import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl;
+import org.mockito.Mockito;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.FilterType;
+import org.springframework.context.annotation.ComponentScan.Filter;
+import org.springframework.core.type.classreading.MetadataReader;
+import org.springframework.core.type.classreading.MetadataReaderFactory;
+import org.springframework.core.type.filter.TypeFilter;
+import com.cloud.utils.component.ComponentContext;
+import com.cloud.agent.AgentManager;
+import com.cloud.alert.AlertManager;
+import com.cloud.api.query.dao.UserAccountJoinDaoImpl;
+import com.cloud.capacity.dao.CapacityDaoImpl;
+import com.cloud.cluster.agentlb.dao.HostTransferMapDaoImpl;
+import com.cloud.configuration.dao.ConfigurationDao;
+import com.cloud.dc.dao.AccountVlanMapDaoImpl;
+import com.cloud.dc.dao.ClusterDaoImpl;
+import com.cloud.dc.dao.DataCenterDaoImpl;
+import com.cloud.dc.dao.DataCenterIpAddressDaoImpl;
+import com.cloud.dc.dao.DataCenterLinkLocalIpAddressDaoImpl;
+import com.cloud.dc.dao.DataCenterVnetDaoImpl;
+import com.cloud.dc.dao.DcDetailsDaoImpl;
+import com.cloud.dc.dao.HostPodDaoImpl;
+import com.cloud.dc.dao.PodVlanDaoImpl;
+import com.cloud.dc.dao.PodVlanMapDaoImpl;
+import com.cloud.dc.dao.VlanDaoImpl;
+import com.cloud.domain.dao.DomainDaoImpl;
+import com.cloud.event.dao.UsageEventDaoImpl;
+import com.cloud.host.dao.HostDaoImpl;
+import com.cloud.host.dao.HostDetailsDaoImpl;
+import com.cloud.host.dao.HostTagsDaoImpl;
+import com.cloud.network.Ipv6AddressManager;
+import com.cloud.network.NetworkManager;
+import com.cloud.network.NetworkModel;
+import com.cloud.network.NetworkService;
+import com.cloud.network.StorageNetworkManager;
+import com.cloud.network.dao.FirewallRulesCidrsDaoImpl;
+import com.cloud.network.dao.FirewallRulesDaoImpl;
+import com.cloud.network.dao.IPAddressDaoImpl;
+import com.cloud.network.dao.LoadBalancerDaoImpl;
+import com.cloud.network.dao.NetworkDao;
+import com.cloud.network.dao.NetworkDomainDaoImpl;
+import com.cloud.network.dao.NetworkServiceMapDaoImpl;
+import com.cloud.network.dao.PhysicalNetworkDaoImpl;
+import com.cloud.network.dao.PhysicalNetworkServiceProviderDaoImpl;
+import com.cloud.network.dao.PhysicalNetworkTrafficTypeDaoImpl;
+import com.cloud.network.dao.UserIpv6AddressDaoImpl;
+import com.cloud.network.element.DhcpServiceProvider;
+import com.cloud.network.element.IpDeployer;
+import com.cloud.network.element.NetworkElement;
+import com.cloud.network.guru.NetworkGuru;
+import com.cloud.network.lb.LoadBalancingRulesManager;
+import com.cloud.network.rules.FirewallManager;
+import com.cloud.network.rules.RulesManager;
+import com.cloud.network.rules.dao.PortForwardingRulesDaoImpl;
+import com.cloud.network.vpc.NetworkACLManager;
+import com.cloud.network.vpc.VpcManager;
+import com.cloud.network.vpc.dao.PrivateIpDaoImpl;
+import com.cloud.network.vpn.RemoteAccessVpnService;
+import com.cloud.offerings.dao.NetworkOfferingDao;
+import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
+import com.cloud.projects.ProjectManager;
+import com.cloud.service.dao.ServiceOfferingDaoImpl;
+import com.cloud.storage.dao.DiskOfferingDaoImpl;
+import com.cloud.storage.dao.S3DaoImpl;
+import com.cloud.storage.dao.SnapshotDaoImpl;
+import com.cloud.storage.dao.StoragePoolDetailsDaoImpl;
+import com.cloud.storage.dao.SwiftDaoImpl;
+import com.cloud.storage.dao.VolumeDaoImpl;
+import com.cloud.storage.s3.S3Manager;
+import com.cloud.storage.secondary.SecondaryStorageVmManager;
+import com.cloud.storage.swift.SwiftManager;
+import com.cloud.tags.dao.ResourceTagsDaoImpl;
+import com.cloud.user.AccountManager;
+import com.cloud.user.ResourceLimitService;
+import com.cloud.user.UserContext;
+import com.cloud.user.UserContextInitializer;
+import com.cloud.user.dao.AccountDaoImpl;
+import com.cloud.user.dao.UserDaoImpl;
+import com.cloud.utils.component.SpringComponentScanUtils;
+import com.cloud.utils.db.GenericDao;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.vm.UserVmVO;
+import com.cloud.vm.dao.InstanceGroupDaoImpl;
+import com.cloud.vm.dao.NicDaoImpl;
+import com.cloud.vm.dao.NicSecondaryIpDaoImpl;
+import com.cloud.vm.dao.UserVmDao;
+import com.cloud.vm.dao.VMInstanceDaoImpl;
+
+@Configuration
+@ComponentScan(basePackageClasses = { AccountVlanMapDaoImpl.class, VolumeDaoImpl.class, HostPodDaoImpl.class,
+        DomainDaoImpl.class, SwiftDaoImpl.class, ServiceOfferingDaoImpl.class, VlanDaoImpl.class,
+        IPAddressDaoImpl.class, ResourceTagsDaoImpl.class, AccountDaoImpl.class, InstanceGroupDaoImpl.class,
+        UserAccountJoinDaoImpl.class, CapacityDaoImpl.class, SnapshotDaoImpl.class, HostDaoImpl.class,
+        VMInstanceDaoImpl.class, HostTransferMapDaoImpl.class, PortForwardingRulesDaoImpl.class,
+        PrivateIpDaoImpl.class, UsageEventDaoImpl.class, PodVlanMapDaoImpl.class, DiskOfferingDaoImpl.class,
+        DataCenterDaoImpl.class, DataCenterIpAddressDaoImpl.class, DataCenterLinkLocalIpAddressDaoImpl.class,
+        DataCenterVnetDaoImpl.class, PodVlanDaoImpl.class, DcDetailsDaoImpl.class, NicSecondaryIpDaoImpl.class,
+        UserIpv6AddressDaoImpl.class, S3DaoImpl.class, UserDaoImpl.class, NicDaoImpl.class, NetworkDomainDaoImpl.class,
+        HostDetailsDaoImpl.class, HostTagsDaoImpl.class, ClusterDaoImpl.class, FirewallRulesDaoImpl.class,
+        FirewallRulesCidrsDaoImpl.class, PhysicalNetworkDaoImpl.class, PhysicalNetworkTrafficTypeDaoImpl.class,
+        PhysicalNetworkServiceProviderDaoImpl.class, LoadBalancerDaoImpl.class, NetworkServiceMapDaoImpl.class,
+        PrimaryDataStoreDaoImpl.class, StoragePoolDetailsDaoImpl.class, AffinityGroupServiceImpl.class,
+        ComponentContext.class, AffinityGroupProcessor.class, UserVmVO.class }, includeFilters = { @Filter(value = AffinityApiTestConfiguration.Library.class, type = FilterType.CUSTOM) }, useDefaultFilters = false)
+public class AffinityApiTestConfiguration {
+
+    @Bean
+    public AffinityGroupProcessor affinityGroupProcessor() {
+        return Mockito.mock(AffinityGroupProcessor.class);
+    }
+
+    @Bean
+    public ComponentContext componentContext() {
+        return Mockito.mock(ComponentContext.class);
+    }
+
+
+    @Bean
+    public UserContextInitializer userContextInitializer() {
+        return Mockito.mock(UserContextInitializer.class);
+    }
+
+    @Bean
+    public UserVmVO userVmVO() {
+        return Mockito.mock(UserVmVO.class);
+    }
+
+    @Bean
+    public AffinityGroupDao affinityGroupDao() {
+        return Mockito.mock(AffinityGroupDao.class);
+    }
+
+    @Bean
+    public AffinityGroupVMMapDao affinityGroupVMMapDao() {
+        return Mockito.mock(AffinityGroupVMMapDao.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 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);
+    }
+
+    public static class Library implements TypeFilter {
+
+        @Override
+        public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
+            mdr.getClassMetadata().getClassName();
+            ComponentScan cs = AffinityApiTestConfiguration.class.getAnnotation(ComponentScan.class);
+            return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b633dde7/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
----------------------------------------------------------------------
diff --git a/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java b/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
new file mode 100644
index 0000000..17f165d
--- /dev/null
+++ b/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
@@ -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.
+package org.apache.cloudstack.affinity;
+
+import static org.junit.Assert.*;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Mockito.*;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
+import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.ResourceInUseException;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.user.Account;
+import com.cloud.user.AccountManager;
+import com.cloud.user.AccountManagerImpl;
+import com.cloud.user.AccountVO;
+import com.cloud.user.UserContext;
+import com.cloud.user.UserContextInitializer;
+import com.cloud.utils.component.ComponentContext;
+import com.cloud.vm.UserVmVO;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.dao.UserVmDao;
+
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = "classpath:/affinityContext.xml")
+public class AffinityApiUnitTest {
+
+    @Inject
+    AffinityGroupServiceImpl _affinityService;
+
+    @Inject
+    AccountManager _acctMgr;
+
+    @Inject
+    AffinityGroupProcessor _processor;
+
+    @Inject
+    AffinityGroupDao _groupDao;
+
+    @Inject
+    UserVmDao _vmDao;
+
+    @Inject
+    AffinityGroupVMMapDao _affinityGroupVMMapDao;
+
+    private static long domainId = 5L;
+
+
+    @BeforeClass
+    public static void setUp() throws ConfigurationException {
+
+    }
+
+    @Before
+    public void testSetUp() {
+        AccountVO acct = new AccountVO(200L);
+        acct.setType(Account.ACCOUNT_TYPE_NORMAL);
+        acct.setAccountName("user");
+        acct.setDomainId(domainId);
+
+        UserContext.registerContext(1, acct, null, true);
+
+        when(_acctMgr.finalizeOwner((Account) anyObject(), anyString(), anyLong(), anyLong())).thenReturn(acct);
+        when(_processor.getType()).thenReturn("mock");
+    }
+
+    @Test
+    public void createAffinityGroupTest() {
+        AffinityGroup group = _affinityService.createAffinityGroup("user", domainId, "group1", "mock",
+                "affinity group one");
+        assertNotNull("Affinity group 'group1' of type 'mock' failed to create ", group);
+
+    }
+
+    @Test(expected = InvalidParameterValueException.class)
+    public void invalidAffinityTypeTest() {
+        AffinityGroup group = _affinityService.createAffinityGroup("user", domainId, "group1", "invalid",
+                "affinity group one");
+
+    }
+
+    @Test(expected = InvalidParameterValueException.class)
+    public void uniqueAffinityNameTest() {
+        when(_groupDao.isNameInUse(anyLong(), anyLong(), eq("group1"))).thenReturn(true);
+        AffinityGroup group2 = _affinityService.createAffinityGroup("user", domainId, "group1", "mock",
+                "affinity group two");
+    }
+
+    @Test(expected = InvalidParameterValueException.class)
+    public void deleteAffinityGroupInvalidIdTest() throws ResourceInUseException {
+        when(_groupDao.findById(20L)).thenReturn(null);
+        _affinityService.deleteAffinityGroup(20L, "user", domainId, "group1");
+    }
+
+    @Test(expected = InvalidParameterValueException.class)
+    public void deleteAffinityGroupInvalidIdName() throws ResourceInUseException {
+        when(_groupDao.findByAccountAndName(200L, "group1")).thenReturn(null);
+        _affinityService.deleteAffinityGroup(null, "user", domainId, "group1");
+    }
+
+    @Test(expected = InvalidParameterValueException.class)
+    public void deleteAffinityGroupNullIdName() throws ResourceInUseException {
+        _affinityService.deleteAffinityGroup(null, "user", domainId, null);
+    }
+
+    @Test(expected = ResourceInUseException.class)
+    public void deleteAffinityGroupInUse() throws ResourceInUseException {
+        List<AffinityGroupVMMapVO> affinityGroupVmMap = new ArrayList<AffinityGroupVMMapVO>();
+        AffinityGroupVMMapVO mapVO = new AffinityGroupVMMapVO(20L, 10L);
+        affinityGroupVmMap.add(mapVO);
+        when(_affinityGroupVMMapDao.listByAffinityGroup(20L)).thenReturn(affinityGroupVmMap);
+
+        AffinityGroupVO groupVO = new AffinityGroupVO();
+        when(_groupDao.findById(20L)).thenReturn(groupVO);
+        when(_groupDao.lockRow(20L, true)).thenReturn(groupVO);
+
+        _affinityService.deleteAffinityGroup(20L, "user", domainId, null);
+    }
+
+    @Test(expected = InvalidParameterValueException.class)
+    public void updateAffinityGroupVMRunning() throws ResourceInUseException {
+
+        UserVmVO vm = new UserVmVO(10L, "test", "test", 101L, HypervisorType.Any, 21L, false, false, domainId, 200L,
+                5L, "", "test", 1L);
+        vm.setState(VirtualMachine.State.Running);
+        when(_vmDao.findById(10L)).thenReturn(vm);
+
+        List<Long> affinityGroupIds = new ArrayList<Long>();
+        affinityGroupIds.add(20L);
+
+        _affinityService.updateVMAffinityGroups(10L, affinityGroupIds);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b633dde7/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..652905c
--- /dev/null
+++ b/server/test/resources/affinityContext.xml
@@ -0,0 +1,44 @@
+<!-- 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 -->
+    <aop:config proxy-target-class="true">
+    <aop:aspect id="dbContextBuilder" ref="transactionContextBuilder">
+    <aop:pointcut id="captureAnyMethod" expression="execution(* *(..))" />
+
+    <aop:around pointcut-ref="captureAnyMethod" method="AroundAnyMethod" />
+    </aop:aspect>
+    </aop:config>
+    
+
+    <bean id="ConfigurationManager" class="com.cloud.configuration.ConfigurationManagerImpl">
+        <property name="name" value="ConfigurationManager"/>
+    </bean>
+  
+    <bean class="org.apache.cloudstack.affinity.AffinityApiTestConfiguration" />
+    
+    <bean id="transactionContextBuilder" class="com.cloud.utils.db.TransactionContextBuilder" />
+    
+
+</beans>
\ No newline at end of file


[16/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
Adding the missing header!


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

Branch: refs/heads/master
Commit: e312158f1c32de9c2f713c42c9175041b68920bf
Parents: c7c899f
Author: Prachi Damle <pr...@cloud.com>
Authored: Fri Mar 29 00:20:31 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:23:06 2013 -0700

----------------------------------------------------------------------
 .../cloudstack/affinity/AffinityProcessorBase.java |   16 +++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e312158f/api/src/org/apache/cloudstack/affinity/AffinityProcessorBase.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/affinity/AffinityProcessorBase.java b/api/src/org/apache/cloudstack/affinity/AffinityProcessorBase.java
index 74fdde1..70ecd08 100644
--- a/api/src/org/apache/cloudstack/affinity/AffinityProcessorBase.java
+++ b/api/src/org/apache/cloudstack/affinity/AffinityProcessorBase.java
@@ -1,3 +1,19 @@
+// 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 org.apache.cloudstack.affinity;
 
 import com.cloud.deploy.DeploymentPlan;


[32/34] git commit: updated refs/heads/master to 6137d32

Posted by pr...@apache.org.
Adding pretty toString() to AffinityGroup


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

Branch: refs/heads/master
Commit: bbf7900732d46e60a4708901b4767e3ef73dbb10
Parents: fc248cb
Author: Prachi Damle <pr...@cloud.com>
Authored: Wed Apr 10 14:18:36 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Thu Apr 11 13:23:43 2013 -0700

----------------------------------------------------------------------
 .../cloudstack/affinity/AffinityGroupVO.java       |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bbf79007/server/src/org/apache/cloudstack/affinity/AffinityGroupVO.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/AffinityGroupVO.java b/server/src/org/apache/cloudstack/affinity/AffinityGroupVO.java
index fab3835..b6c4a02 100644
--- a/server/src/org/apache/cloudstack/affinity/AffinityGroupVO.java
+++ b/server/src/org/apache/cloudstack/affinity/AffinityGroupVO.java
@@ -104,4 +104,11 @@ public class AffinityGroupVO implements AffinityGroup {
         return type;
     }
 
+    @Override
+    public String toString() {
+        StringBuilder buf = new StringBuilder("AffinityGroup[");
+        buf.append(id).append("|").append(name).append("|").append(type).append("]");
+        return buf.toString();
+    }
+
 }