cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prachida...@apache.org
Subject [49/50] [abbrv] Merge branch 'master' into affinity_groups
Date Fri, 05 Apr 2013 21:03:44 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ca1a7948/client/tomcatconf/componentContext.xml.in
----------------------------------------------------------------------
diff --cc client/tomcatconf/componentContext.xml.in
index fac17f0,a006708..95737ce
--- a/client/tomcatconf/componentContext.xml.in
+++ b/client/tomcatconf/componentContext.xml.in
@@@ -30,317 -31,221 +31,228 @@@
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-3.0.xsd">                     
  
- 
-   <!--
-       Compose a CloudStack deployment with selected components here
-   -->
-   <bean id="databaseUpgradeChecker" class="com.cloud.upgrade.DatabaseUpgradeChecker" />
-   <bean id="encryptionSecretKeyChecker" class="com.cloud.utils.crypt.EncryptionSecretKeyChecker" />
-   <bean id="configurationServerImpl" class="com.cloud.server.ConfigurationServerImpl" />
-   
-   <bean id="managementServerImpl" class ="com.cloud.server.ManagementServerImpl" >
-     <property name="UserAuthenticators">
-         <list>
-             <ref bean="MD5UserAuthenticator"/>
-             <ref bean="LDAPUserAuthenticator"/>
-         </list>
-     </property>
-   </bean>
-  
-   <bean id ="AccountManagerImpl" class="com.cloud.user.AccountManagerImpl">
-     <property name="UserAuthenticators">
-         <list>
-             <ref bean="MD5UserAuthenticator"/>
-             <ref bean="LDAPUserAuthenticator"/>
-         </list>
-     </property>
-   </bean>
-    
-   <bean id="clusterManagerImpl" class="com.cloud.cluster.ClusterManagerImpl" />
-   <bean id="clusteredAgentManagerImpl" class="com.cloud.agent.manager.ClusteredAgentManagerImpl" />
-   <bean id="clusteredVirtualMachineManagerImpl" class="com.cloud.vm.ClusteredVirtualMachineManagerImpl" />
-   <bean id="highAvailabilityManagerExtImpl" class="com.cloud.ha.HighAvailabilityManagerExtImpl" />
-   <bean id="userVmManagerImpl" class="com.cloud.vm.UserVmManagerImpl" />
-   <bean id="consoleProxyManagerImpl" class="com.cloud.consoleproxy.ConsoleProxyManagerImpl" />
-   <bean id="securityGroupManagerImpl2" class="com.cloud.network.security.SecurityGroupManagerImpl2" />
-   <bean id="premiumSecondaryStorageManagerImpl" class="com.cloud.secstorage.PremiumSecondaryStorageManagerImpl" />
-   <bean id="userVmDaoImpl" class="com.cloud.vm.dao.UserVmDaoImpl" />
-   <bean id="ipv6AddressManagerImpl" class="com.cloud.network.Ipv6AddressManagerImpl" />
- 
-   <bean id="apiRateLimitServiceImpl" class="org.apache.cloudstack.ratelimit.ApiRateLimitServiceImpl"/>
-   <bean id="BaremetalManager" class="com.cloud.baremetal.manager.BaremetalManagerImpl"/>
-   <bean id="BaremetalDhcpManager" class="com.cloud.baremetal.networkservice.BaremetalDhcpManagerImpl"/>
-   <bean id="BaremetalKickStartPxeService" class="com.cloud.baremetal.networkservice.BaremetalKickStartServiceImpl"/>
-   <bean id="BaremetalPingPxeService" class="com.cloud.baremetal.networkservice.BareMetalPingServiceImpl" />
-   <bean id="BaremetalPxeManager" class="com.cloud.baremetal.networkservice.BaremetalPxeManagerImpl" />
-   <bean id="UcsManager" class="com.cloud.ucs.manager.UcsManagerImpl" />
-   <bean id="UcsBladeDao" class="com.cloud.ucs.database.UcsBladeDaoImpl" />
-   <bean id="UcsManagerDao" class="com.cloud.ucs.database.UcsManagerDaoImpl" />
- 
-   <!--
-       Network Elements
-   -->
-   <bean id="Ovs" class="com.cloud.network.element.OvsElement">
-     <property name="name" value="Ovs"/>
-   </bean>
-   <bean id="BareMetalDhcp" class="com.cloud.baremetal.networkservice.BaremetalDhcpElement">
-       <property name="name" value="BareMetalDhcp"/>
-   </bean>
-   <bean id="BareMetalPxe" class="com.cloud.baremetal.networkservice.BaremetalPxeElement">
-       <property name="name" value="BareMetalPxe"/>
-   </bean>
-   <bean id="BareMetalUserdata" class="com.cloud.baremetal.networkservice.BaremetalUserdataElement">
-       <property name="name" value="BareMetalUserdata"/>
-   </bean>
-   <bean id="SecurityGroupProvider" class="com.cloud.network.element.SecurityGroupElement">
-     <property name="name" value="SecurityGroupProvider"/>
-   </bean>
-   <bean id="VirtualRouter" class="com.cloud.network.element.VirtualRouterElement">
-     <property name="name" value="VirtualRouter"/>
-   </bean>
-   <bean id="VpcVirtualRouter" class="com.cloud.network.element.VpcVirtualRouterElement">
-     <property name="name" value="VpcVirtualRouter"/>
-   </bean>
-   <!--
-   <bean id="NiciraNvp" class="com.cloud.network.element.NiciraNvpElement">
-     <property name="name" value="NiciraNvp"/>
-   </bean>
-   -->
-   
  <!--
-   <bean id="BigSwitchVnsElementService" class="com.cloud.network.element.BigSwitchVnsElement">
-     <property name="name" value="BigSwitchVnsElementService"/>
-   </bean>
+  
+   OSS deployment configuration
+       
+   OSS/non-OSS counter-exclusive components and related configurations should be put here
+   for example, configurationDaoImpl component, it has exclusive configuration settings in OSS and non-OSS deployment,
+   its component declaration should be put in both componentContext.xml.in and nonossComponentContext.xml.in, each with
+   independent configuration
+     
  -->
-                    
-   <!--
-      Adapters
-   -->
-   <bean id="FirstFitRouting" class="com.cloud.agent.manager.allocator.impl.FirstFitRoutingAllocator">
-     <property name="name" value="FirstFitRouting"/>
-   </bean>
    
-   <bean id="hypervisorTemplateAdapter" class="com.cloud.template.HypervisorTemplateAdapter">
-     <property name="name" value="HypervisorAdapter"/>
-   </bean>
+   <bean id="databaseUpgradeChecker" class="com.cloud.upgrade.DatabaseUpgradeChecker" />
+   <bean id="configurationDaoImpl" class="com.cloud.configuration.dao.ConfigurationDaoImpl" />
    
-   <!--
-     Storage pool allocators
-   -->
+   <bean id="GlobalLoadBalancingRulesServiceImpl" class ="org.apache.cloudstack.region.gslb.GlobalLoadBalancingRulesServiceImpl" />
  
-   <bean id="LocalStoragePoolAllocator" class="org.apache.cloudstack.storage.allocator.LocalStoragePoolAllocator">
-     <property name="name" value="LocalStorage"/>
-   </bean>
    <!--
-   <bean id="FirstFitStoragePoolAllocator" class="org.apache.cloudstack.storage.allocator.FirstFitStoragePoolAllocator">
-     <property name="name" value="Storage"/>
-   </bean>
+     Nicira support components
    -->
- 
-   <bean id="UserConcentratedAllocator" class="com.cloud.agent.manager.allocator.impl.UserConcentratedAllocator">
-     <property name="name" value="User First"/>
-   </bean>
- 
-   <bean id="ConsoleProxyAllocator" class="com.cloud.consoleproxy.ConsoleProxyBalanceAllocator">
-     <property name="name" value="Balance"/>
-   </bean>
- 
-   <bean id="StaticRoleBasedAPIAccessChecker" class="org.apache.cloudstack.acl.StaticRoleBasedAPIAccessChecker"/>
- 
-   <bean id="ExteralIpAddressAllocator" class="com.cloud.network.ExteralIpAddressAllocator">
-     <property name="name" value="Basic"/>
-   </bean>
- 
-   <bean id="HypervisorTemplateAdapter" class="com.cloud.template.HypervisorTemplateAdapter">
-     <property name="name" value="HypervisorAdapter"/>
-   </bean>
- 
-   <bean id="BareMetalTemplateAdapter" class="com.cloud.baremetal.manager.BareMetalTemplateAdapter" >
-     <property name="name" value="BareMetalTemplateAdapter"/>
-   </bean>
- 
-   <!--
-     Authenticators
-   -->
-   <bean id="MD5UserAuthenticator" class="com.cloud.server.auth.MD5UserAuthenticator">
-     <property name="name" value="MD5"/>
+   <bean id="niciraNvpDaoImpl" class="com.cloud.network.dao.NiciraNvpDaoImpl" />
+   <bean id="niciraNvpNicMappingDaoImpl" class="com.cloud.network.dao.NiciraNvpNicMappingDaoImpl" />
+   <bean id="niciraNvpRouterMappingDaoImpl" class="com.cloud.network.dao.NiciraNvpRouterMappingDaoImpl" />
+   <bean id="NiciraNvpGuestNetworkGuru" class="com.cloud.network.guru.NiciraNvpGuestNetworkGuru">
+     <property name="name" value="NiciraNvpGuestNetworkGuru"/>
    </bean>
- 
-   <bean id="LDAPUserAuthenticator" class="com.cloud.server.auth.LDAPUserAuthenticator">
-     <property name="name" value="LDAP"/>
+   <bean id="NiciraNvp" class="com.cloud.network.element.NiciraNvpElement">
+     <property name="name" value="NiciraNvp"/>
    </bean>
  
-   <!--
-     Investigators
+   <!-- 
+     Midonet support components
    -->
-   <bean id="CheckOnAgentInvestigator" class="com.cloud.ha.CheckOnAgentInvestigator">
-     <property name="name" value="SimpleInvestigator"/>
+   <bean id="MidoNetGuestNetworkGuru" class="com.cloud.network.guru.MidoNetGuestNetworkGuru">
+     <property name="name" value="MidoNetGuestNetworkGuru"/>
    </bean>
- 
-   <bean id="XenServerInvestigator" class="com.cloud.ha.XenServerInvestigator">
-     <property name="name" value="XenServerInvestigator"/>
+   <bean id="MidoNetElement" class="com.cloud.network.element.MidoNetElement">
+     <property name="name" value="MidoNetElement"/>
    </bean>
    
-   <bean id="UserVmDomRInvestigator" class="com.cloud.ha.UserVmDomRInvestigator">
-     <property name="name" value="PingInvestigator"/>
-   </bean>
- 
-   <bean id="ManagementIPSystemVMInvestigator" class="com.cloud.ha.ManagementIPSystemVMInvestigator">
-     <property name="name" value="ManagementIPSysVMInvestigator"/>
-   </bean>
+ <!--
  
-   <!--
-     Fencers
-   -->
-   <bean id="XenServerFencer" class="com.cloud.ha.XenServerFencer">
-     <property name="name" value="XenServerFenceBuilder"/>
-   </bean>
-   <bean id="KVMFencer" class="com.cloud.ha.KVMFencer">
-     <property name="name" value="KVMFenceBuilder"/>
+   Deployment configurations of various adapters
+     
+   It determines whether or not a adapter is activated or how it is loaded in order in its managing provider,
+      
+ --> 
+ 
+   <!-- Security adapters -->
+   <bean id="userAuthenticators" class="com.cloud.utils.component.AdapterList">
+     <property name="Adapters">
+       <list>
+           <ref bean="SHA256SaltedUserAuthenticator"/>
+           <ref bean="MD5UserAuthenticator"/>
+           <ref bean="LDAPUserAuthenticator"/>
+           <ref bean="PlainTextUserAuthenticator"/>
+       </list>
+     </property>
    </bean>
-   <bean id="OvmFencer" class="com.cloud.ovm.hypervisor.OvmFencer">
-     <property name="name" value="OvmFenceBuilder"/>
+   <bean id="userPasswordEncoders" class="com.cloud.utils.component.AdapterList">
+     <property name="Adapters">
+       <list>
+           <ref bean="SHA256SaltedUserAuthenticator"/>
+           <ref bean="MD5UserAuthenticator"/>
+           <ref bean="LDAPUserAuthenticator"/>
+           <ref bean="PlainTextUserAuthenticator"/>
+       </list>
+     </property>
    </bean>
  
-   <bean id="XcpServerDiscoverer" class="com.cloud.hypervisor.xen.discoverer.XcpServerDiscoverer">
-     <property name="name" value="XCP Agent"/>
+   <bean id="securityCheckers" class="com.cloud.utils.component.AdapterList">
+     <property name="Adapters">
+       <list>
+           <ref bean="domainChecker"/>
+       </list>
+     </property>
    </bean>
  
+   <!-- Resource discoverers -->
+   <bean id="resourceDiscoverers" class="com.cloud.utils.component.AdapterList">
+     <property name="Adapters">
+       <list>
+           <ref bean="XcpServerDiscoverer"/>
+           <ref bean="SecondaryStorageDiscoverer"/>
+           <ref bean="KvmServerDiscoverer"/>
+           <ref bean="LxcServerDiscoverer"/>
+ 
    <!--
-   <bean id="SimulatorSecondaryStorageDiscoverer" class="com.cloud.resource.SimulatorSecondaryDiscoverer">
-     <property name="name" value="SecondaryStorage"/>
-   </bean>
+           <ref bean="BareMetalDiscoverer"/>
    -->
  
-   <bean id="SecondaryStorageDiscoverer" class="com.cloud.storage.secondary.SecondaryStorageDiscoverer">
-     <property name="name" value="SecondaryStorage"/>
-   </bean>
- 
-   <bean id="KvmServerDiscoverer" class="com.cloud.hypervisor.kvm.discoverer.KvmServerDiscoverer">
-     <property name="name" value="KVM Agent"/>
+           <ref bean="OvmDiscoverer"/>
+       </list>
+     </property>
    </bean>
  
-   <bean id="SimulatorDiscoverer" class="com.cloud.resource.SimulatorDiscoverer">
-     <property name="name" value="Simulator Agent"/>
+   <!-- HA adapters -->
+   <bean id="haInvestigators" class="com.cloud.utils.component.AdapterList">
+     <property name="Adapters">
+       <list>
+           <ref bean="CheckOnAgentInvestigator"/>
+           <ref bean="XenServerInvestigator"/>
+           <ref bean="UserVmDomRInvestigator"/>
+           <ref bean="ManagementIPSystemVMInvestigator"/>
+       </list>
+     </property>
    </bean>
  
- 
-   <bean id="BareMetalDiscoverer" class="com.cloud.baremetal.manager.BareMetalDiscoverer">
-     <property name="name" value="Bare Metal Agent"/>
+   <bean id="haFenceBuilders" class="com.cloud.utils.component.AdapterList">
+     <property name="Adapters">
+       <list>
+           <ref bean="XenServerFencer"/>
+           <ref bean="KVMFencer"/>
+           <ref bean="OvmFencer"/>
+       </list>
+     </property>
    </bean>
  
-   <bean id="HypervServerDiscoverer" class="com.cloud.hypervisor.hyperv.HypervServerDiscoverer">
-     <property name="name" value="SCVMMServer"/>
-   </bean>
+   <!-- Deployment/allocation adapters -->
+   <bean id="deploymentPlanners" class="com.cloud.utils.component.AdapterList">
+     <property name="Adapters">
+       <list>
+           <ref bean="FirstFitPlanner" />
+           <ref bean="UserDispersingPlanner" />
+           <ref bean="UserConcentratedPodPlanner" />
  
-   <bean id="OvmDiscoverer" class="com.cloud.ovm.hypervisor.OvmDiscoverer">
-     <property name="name" value="Ovm Discover"/>
-   </bean>
- 
-   <bean id="FirstFitPlanner" class="com.cloud.deploy.FirstFitPlanner">
-     <property name="name" value="FirstFitPlanner"/>
+ <!--
+           <ref bean="BareMetalPlanner" />
+ -->
+       </list>
+     </property>
    </bean>
  
-   <bean id="UserDispersingPlanner" class="com.cloud.deploy.UserDispersingPlanner">
-     <property name="name" value="UserDispersingPlanner"/>
+   <bean id="podAllocators" class="com.cloud.utils.component.AdapterList">
+     <property name="Adapters">
+       <list>
+           <ref bean="UserConcentratedAllocator"/>
+       </list>
+     </property>
    </bean>
    
-   <bean id="UserConcentratedPodPlanner" class="com.cloud.deploy.UserConcentratedPodPlanner">
-     <property name="name" value="UserConcentratedPodPlanner"/>
+   <bean id="hostAllocators" class="com.cloud.utils.component.AdapterList">
+     <property name="Adapters">
+       <list>
+           <ref bean="FirstFitRouting"/>
+       </list>
+     </property>
    </bean>
  
-   <bean id="BareMetalPlanner" class="com.cloud.baremetal.manager.BareMetalPlanner">
-     <property name="name" value="BareMetalPlanner"/>
-   </bean>
-     
-   <bean id="BaremetalPlannerSelector" class="com.cloud.baremetal.manager.BaremetalPlannerSelector">
-     <property name="name" value="BaremetalPlannerSelector"/>
+   <bean id="storagePoolAllocators" class="com.cloud.utils.component.AdapterList">
+     <property name="Adapters">
+       <list>
+           <ref bean="LocalStoragePoolAllocator"/>
+           <ref bean="clusterScopeStoragePoolAllocator"/>
+           <ref bean="zoneWideStoragePoolAllocator"/>
+           <ref bean="garbageCollectingStoragePoolAllocator"/>
+       </list>
+     </property>
    </bean>
  
-   <bean id="HypervisorPlannerSelector" class="com.cloud.deploy.HypervisorVmPlannerSelector">
-     <property name="name" value="HypervisorPlannerSelector"/>
-   </bean>
-     
-    
-   <!--
-     Network Gurus
-   -->
-   <bean id="StorageNetworkGuru" class="com.cloud.network.guru.StorageNetworkGuru">
-     <property name="name" value="StorageNetworkGuru"/>
-   </bean>
-   <bean id="ExternalGuestNetworkGuru" class="com.cloud.network.guru.ExternalGuestNetworkGuru">
-     <property name="name" value="ExternalGuestNetworkGuru"/>
-   </bean>
-   <bean id="PublicNetworkGuru" class="com.cloud.network.guru.PublicNetworkGuru">
-     <property name="name" value="PublicNetworkGuru"/>
-   </bean>
-   <bean id="PodBasedNetworkGuru" class="com.cloud.network.guru.PodBasedNetworkGuru">
-     <property name="name" value="PodBasedNetworkGuru"/>
-   </bean>
-   <bean id="ControlNetworkGuru" class="com.cloud.network.guru.ControlNetworkGuru">
-     <property name="name" value="ControlNetworkGuru"/>
-   </bean>
-   <bean id="DirectNetworkGuru" class="com.cloud.network.guru.DirectNetworkGuru">
-     <property name="name" value="DirectNetworkGuru"/>
-   </bean>
-   <bean id="DirectPodBasedNetworkGuru" class="com.cloud.network.guru.DirectPodBasedNetworkGuru">
-     <property name="name" value="DirectPodBasedNetworkGuru"/>
-   </bean>
-   <bean id="OvsGuestNetworkGuru" class="com.cloud.network.guru.OvsGuestNetworkGuru">
-     <property name="name" value="OvsGuestNetworkGuru"/>
-   </bean>
-   <bean id="PrivateNetworkGuru" class="com.cloud.network.guru.PrivateNetworkGuru">
-     <property name="name" value="PrivateNetworkGuru"/>
-   </bean>
-   <bean id="NiciraNvpGuestNetworkGuru" class="com.cloud.network.guru.NiciraNvpGuestNetworkGuru">
-     <property name="name" value="NiciraNvpGuestNetworkGuru"/>
-   </bean>
-   
- <!--  
-   <bean id="BigSwitchVnsGuestNetworkGuru" class=".BigSwitchVnsGuestNetworkGuru">
-     <property name="name" value="com.cloud.network.guru.BigSwitchVnsGuestNetworkGuru"/>
+   <!-- Networking adapters -->
+   <bean id="ipDeployers" class="com.cloud.utils.component.AdapterList">
+     <property name="Adapters">
+       <list>
+           <ref bean="elasticLoadBalancerElement"/>
+           <ref bean="VirtualRouter"/>
+           <ref bean="VpcVirtualRouter"/>
+       </list>
+     </property>
    </bean>
+ 
+   <bean id="dhcpProviders" class="com.cloud.utils.component.AdapterList">
+     <property name="Adapters">
+       <list>
+           <ref bean="VirtualRouter"/>
+           <ref bean="VpcVirtualRouter"/>
+ <!--
+           <ref bean="BareMetalDhcp"/>
  -->
-  
-   <!--
-    Hypervisor Gurus
-   -->
-   <bean id="XenServerGuru" class="com.cloud.hypervisor.XenServerGuru">
-     <property name="name" value="XenServerGuru"/>
-   </bean>
-   
-   <bean id="KVMGuru" class="com.cloud.hypervisor.KVMGuru">
-     <property name="name" value="KVMGuru"/>
-   </bean>
-   
-   <bean id="HypervGuru" class="com.cloud.hypervisor.guru.HypervGuru">
-     <property name="name" value="HypervGuru"/>
+       </list>
+     </property>
    </bean>
  
-   <bean id="OvmGuru" class="com.cloud.ovm.hypervisor.OvmGuru">
-     <property name="name" value="OvmGuru"/>
+   <bean id="networkGurus" class="com.cloud.utils.component.AdapterList">
+     <property name="Adapters">
+       <list>
+           <ref bean="StorageNetworkGuru"/>
+           <ref bean="ExternalGuestNetworkGuru"/>
+           <ref bean="PublicNetworkGuru"/>
+           <ref bean="PodBasedNetworkGuru"/>
+           <ref bean="DirectPodBasedNetworkGuru"/>
+           <ref bean="ControlNetworkGuru"/>
+           <ref bean="DirectNetworkGuru"/>
+           <ref bean="OvsGuestNetworkGuru"/>
+           <ref bean="PrivateNetworkGuru"/>
+       </list>
+     </property>
    </bean>
    
-   <bean id="SimulatorGuru" class="com.cloud.simulator.SimulatorGuru">
-     <property name="name" value="SimulatorGuru"/>
-   </bean>
- 
-   <bean id="BaremetalGuru" class="com.cloud.baremetal.manager.BareMetalGuru">
-     <property name="name" value="BaremetalGuru"/>
+   <bean id="networkElements" class="com.cloud.utils.component.AdapterList">
+     <property name="Adapters">
+       <list>
+           <ref bean="VirtualRouter"/>
+           <ref bean="Ovs"/>
+           <ref bean="SecurityGroupProvider"/>
+           <ref bean="VpcVirtualRouter"/>
+           <ref bean="NiciraNvp" />
+           <ref bean="MidoNetElement"/>
+ <!--
+           <ref bean="BareMetalDhcp"/>
+           <ref bean="BareMetalPxe"/>
+           <ref bean="BareMetalUserdata"/>
+ -->
+       </list>
+     </property>
    </bean>
  
-   <bean id="ClassicalPrimaryDataStoreProvider" class="org.apache.cloudstack.storage.datastore.provider.CloudStackPrimaryDataStoreProviderImpl">
-   </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/ca1a7948/plugins/pom.xml
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ca1a7948/server/src/com/cloud/api/ApiDBUtils.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/api/ApiDBUtils.java
index 332157a,7b44190..339c31d
--- a/server/src/com/cloud/api/ApiDBUtils.java
+++ b/server/src/com/cloud/api/ApiDBUtils.java
@@@ -329,8 -378,7 +383,9 @@@ public class ApiDBUtils 
      static VMSnapshotDao _vmSnapshotDao;
      static ClusterDetailsDao _clusterDetailsDao;
      static NicSecondaryIpDao _nicSecondaryIpDao;
 +    static AffinityGroupDao _affinityGroupDao;
 +    static AffinityGroupJoinDao _affinityGroupJoinDao;
+     static VpcProvisioningService _vpcProvSvc;
  
      @Inject private ManagementServer ms;
      @Inject public AsyncJobManager asyncMgr;
@@@ -434,9 -482,7 +489,11 @@@
      @Inject private ClusterDetailsDao clusterDetailsDao;
      @Inject private VMSnapshotDao vmSnapshotDao;
      @Inject private NicSecondaryIpDao nicSecondaryIpDao;
 +    @Inject private AffinityGroupDao affinityGroupDao;
 +    @Inject private AffinityGroupJoinDao affinityGroupJoinDao;
 +
+     @Inject private VpcProvisioningService vpcProvSvc;
++
      @PostConstruct
      void init() {
          _ms = ms;
@@@ -538,8 -584,7 +595,9 @@@
          _clusterDetailsDao = clusterDetailsDao;
          _vmSnapshotDao = vmSnapshotDao;
          _nicSecondaryIpDao = nicSecondaryIpDao;
 +        _affinityGroupDao = affinityGroupDao;
 +        _affinityGroupJoinDao = affinityGroupJoinDao;
+         _vpcProvSvc = vpcProvSvc;
          // Note: stats collector should already have been initialized by this time, otherwise a null instance is returned
          _statsCollector = StatsCollector.getInstance();
      }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ca1a7948/server/src/com/cloud/api/ApiResponseHelper.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/api/ApiResponseHelper.java
index 5a50ebb,64be7f8..45d8954
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@@ -476,9 -446,10 +476,10 @@@ public class ApiResponseHelper implemen
              vmSnapshotResponse.setParentName(ApiDBUtils.getVMSnapshotById(vmSnapshot.getParent()).getDisplayName());
          vmSnapshotResponse.setCurrent(vmSnapshot.getCurrent());
          vmSnapshotResponse.setType(vmSnapshot.getType().toString());
+         vmSnapshotResponse.setObjectName("vmsnapshot");
          return vmSnapshotResponse;
      }
 -    
 +
      @Override
      public SnapshotPolicyResponse createSnapshotPolicyResponse(SnapshotPolicy policy) {
          SnapshotPolicyResponse policyResponse = new SnapshotPolicyResponse();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ca1a7948/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ca1a7948/server/src/com/cloud/deploy/DeploymentPlanningManager.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/deploy/DeploymentPlanningManager.java
index 4ac71e3,0000000..13f1c67
mode 100644,000000..100644
--- a/server/src/com/cloud/deploy/DeploymentPlanningManager.java
+++ b/server/src/com/cloud/deploy/DeploymentPlanningManager.java
@@@ -1,29 -1,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.
 +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/ca1a7948/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java
index 11e5b82,0000000..92aac37
mode 100644,000000..100644
--- a/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java
+++ b/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java
@@@ -1,80 -1,0 +1,96 @@@
++// 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.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/ca1a7948/server/src/com/cloud/deploy/FirstFitPlanner.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ca1a7948/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/server/ManagementServerImpl.java
index c0744de,af77ba5..2128d6c
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@@ -47,17 -47,67 +47,74 @@@ import javax.management.MalformedObject
  import javax.management.NotCompliantMBeanException;
  import javax.naming.ConfigurationException;
  
- import org.apache.cloudstack.acl.SecurityChecker.AccessType;
 +import org.apache.cloudstack.affinity.AffinityGroupProcessor;
 +import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
- import org.apache.cloudstack.api.ApiConstants;
- 
- import com.cloud.event.ActionEventUtils;
 +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.storage.dao.*;
+ import org.apache.cloudstack.acl.SecurityChecker.AccessType;
+ 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 com.cloud.agent.AgentManager;
  import com.cloud.agent.api.GetVncPortAnswer;
  import com.cloud.agent.api.GetVncPortCommand;
@@@ -400,11 -457,9 +465,12 @@@ public class ManagementServerImpl exten
  
      private Map<String, Boolean> _availableIdsMap;
  
-     List<UserAuthenticator> _userAuthenticators;
+     private List<UserAuthenticator> _userAuthenticators;
+     private List<UserAuthenticator> _userPasswordEncoders;
  
 +    @Inject
 +    protected List<DeploymentPlanner> _planners;
 +
      @Inject ClusterManager _clusterMgr;
      private String _hashKey = null;
  

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ca1a7948/server/src/com/cloud/user/AccountManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/user/AccountManagerImpl.java
index d7e27ef,52ca79d..12ada66
--- a/server/src/com/cloud/user/AccountManagerImpl.java
+++ b/server/src/com/cloud/user/AccountManagerImpl.java
@@@ -221,10 -220,9 +221,11 @@@ public class AccountManagerImpl extend
      @Inject
      private AutoScaleManager _autoscaleMgr;
      @Inject VolumeManager volumeMgr;
 +    @Inject
 +    private AffinityGroupDao _affinityGroupDao;
  
      private List<UserAuthenticator> _userAuthenticators;
+     List<UserAuthenticator> _userPasswordEncoders;
  
      private final ScheduledExecutorService _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("AccountChecker"));
  

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ca1a7948/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/vm/VirtualMachineManagerImpl.java
index 912ee52,af22716..4072531
--- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@@ -210,16 -208,26 +210,26 @@@ public class VirtualMachineManagerImpl 
      @Inject
      protected VMSnapshotDao _vmSnapshotDao;
  
-     @Inject
      protected List<DeploymentPlanner> _planners;
+     public List<DeploymentPlanner> getPlanners() {
+ 		return _planners;
+ 	}
+ 	public void setPlanners(List<DeploymentPlanner> _planners) {
+ 		this._planners = _planners;
+ 	}
  
-     @Inject
      protected List<HostAllocator> _hostAllocators;
- 
-     @Inject
+     public List<HostAllocator> getHostAllocators() {
+ 		return _hostAllocators;
+ 	}
+ 	public void setHostAllocators(List<HostAllocator> _hostAllocators) {
+ 		this._hostAllocators = _hostAllocators;
+ 	}
+ 
+ 	@Inject
      protected ResourceManager _resourceMgr;
 -    
 -    @Inject 
 +
 +    @Inject
      protected VMSnapshotManager _vmSnapshotMgr = null;
      @Inject
      protected ClusterDetailsDao  _clusterDetailsDao;
@@@ -790,10 -794,10 +800,10 @@@
                                  s_logger.info("The guru did not like the answers so stopping " + vm);
                              }
  
-                             StopCommand cmd = new StopCommand(vm.getInstanceName());
+                             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");
                              }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ca1a7948/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
----------------------------------------------------------------------
diff --cc server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
index 17f7401,0000000..e6a1254
mode 100644,000000..100644
--- a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
+++ b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
@@@ -1,318 -1,0 +1,335 @@@
++// 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.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;
 +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.deploy.DeploymentPlanner;
 +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.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.ComponentContext;
 +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;
 +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;
 +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,
 +        StateListener<State, VirtualMachine.Event, VirtualMachine> {
 +
 +    public static final Logger s_logger = Logger.getLogger(AffinityGroupServiceImpl.class);
 +    private String _name;
 +
 +    @Inject
 +    AccountManager _accountMgr;
 +
 +    @Inject
 +    AffinityGroupDao _affinityGroupDao;
 +
 +    @Inject
 +    AffinityGroupVMMapDao _affinityGroupVMMapDao;
 +
 +    @Inject
 +    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) {
 +
 +        Account caller = UserContext.current().getCaller();
 +        Account owner = _accountMgr.finalizeOwner(caller, account, domainId, null);
 +
 +        if (_affinityGroupDao.isNameInUse(owner.getAccountId(), owner.getDomainId(), affinityGroupName)) {
 +            throw new InvalidParameterValueException("Unable to create affinity group, a group with name "
 +                    + affinityGroupName
 +                    + " already exisits.");
 +        }
 +
 +
 +        //validate the affinityGroupType
 +        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 {
 +            throw new InvalidParameterValueException(
 +                    "Unable to create affinity group, no Affinity Group Types configured");
 +        }
 +
 +        if (domainId == null) {
 +            domainId = owner.getDomainId();
 +        }
 +
 +        AffinityGroupVO group = new AffinityGroupVO(affinityGroupName, affinityGroupType, description, domainId,
 +                owner.getId());
 +        _affinityGroupDao.persist(group);
 +
 +        if (s_logger.isDebugEnabled()) {
 +            s_logger.debug("Created affinity group =" + affinityGroupName);
 +        }
 +
 +        return group;
 +    }
 +
 +    @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 {
 +
 +        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
 +    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();
 +
 +        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
 +            groupSearch.join("vmInstanceSearch", vmInstanceSearch, groupSearch.entity().getId(), vmInstanceSearch
 +                    .entity().getAffinityGroupId(), JoinBuilder.JoinType.INNER);
 +            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() {
 +        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()) {
 +                types.add(entry.getValue().getType());
 +            }
 +
 +        }
 +        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()) {
 +                typeProcessorMap.put(entry.getValue().getType(), entry.getValue());
 +            }
 +        }
 +        return typeProcessorMap;
 +    }
 +
 +    @Override
 +    public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
 +        _name = name;
 +        VirtualMachine.State.getStateMachine().registerListener(this);
 +        return true;
 +    }
 +
 +    @Override
 +    public boolean start() {
 +        return true;
 +    }
 +
 +    @Override
 +    public boolean stop() {
 +        return true;
 +    }
 +
 +    @Override
 +    public String getName() {
 +        return _name;
 +    }
 +
 +    @Override
 +    public AffinityGroup getAffinityGroup(Long groupId) {
 +        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 associations of 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/ca1a7948/server/test/org/apache/cloudstack/affinity/AffinityApiTestConfiguration.java
----------------------------------------------------------------------
diff --cc server/test/org/apache/cloudstack/affinity/AffinityApiTestConfiguration.java
index d778ed4,0000000..2191a24
mode 100644,000000..100644
--- a/server/test/org/apache/cloudstack/affinity/AffinityApiTestConfiguration.java
+++ b/server/test/org/apache/cloudstack/affinity/AffinityApiTestConfiguration.java
@@@ -1,318 -1,0 +1,328 @@@
 +// 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.EventUtils;
++import com.cloud.event.dao.EventDao;
++import com.cloud.event.dao.EventDaoImpl;
 +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.AccountDao;
 +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,
++        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,
 +        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)
++        ComponentContext.class, AffinityGroupProcessor.class, EventUtils.class, UserVmVO.class, EventDaoImpl.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 AccountDao accountDao() {
++        return Mockito.mock(AccountDao.class);
++    }
++
++    @Bean
++    public EventUtils eventUtils() {
++        return Mockito.mock(EventUtils.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/ca1a7948/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
----------------------------------------------------------------------
diff --cc server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
index 17f165d,0000000..3ddfd39
mode 100644,000000..100644
--- a/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
+++ b/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
@@@ -1,164 -1,0 +1,175 @@@
 +// 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.event.EventUtils;
 +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.user.dao.AccountDao;
 +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
++    EventUtils _eventUtils;
++
++    @Inject
++    AccountDao _accountDao;
++
++    @Inject
 +    UserVmDao _vmDao;
 +
 +    @Inject
 +    AffinityGroupVMMapDao _affinityGroupVMMapDao;
 +
 +    private static long domainId = 5L;
 +
 +
 +    @BeforeClass
 +    public static void setUp() throws ConfigurationException {
 +
 +    }
 +
++
++
 +    @Before
 +    public void testSetUp() {
++
++        ComponentContext.initComponentsLifeCycle();
++
 +        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");
++
++        when(_accountDao.findByIdIncludingRemoved(0L)).thenReturn(acct);
++
 +    }
 +
 +    @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/ca1a7948/server/test/resources/affinityContext.xml
----------------------------------------------------------------------
diff --cc server/test/resources/affinityContext.xml
index 652905c,0000000..a14ec9b
mode 100644,000000..100644
--- a/server/test/resources/affinityContext.xml
+++ b/server/test/resources/affinityContext.xml
@@@ -1,44 -1,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(* *(..))" />
++  <bean id="componentContext" class="com.cloud.utils.component.ComponentContext" />
 +
-     <aop:around pointcut-ref="captureAnyMethod" method="AroundAnyMethod" />
-     </aop:aspect>
-     </aop:config>
-     
++  <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">
 +        <property name="name" value="ConfigurationManager"/>
 +    </bean>
 +  
 +    <bean class="org.apache.cloudstack.affinity.AffinityApiTestConfiguration" />
-     
-     <bean id="transactionContextBuilder" class="com.cloud.utils.db.TransactionContextBuilder" />
-     
 +
 +</beans>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ca1a7948/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --cc setup/db/db/schema-410to420.sql
index cc759b8,ab9df05..e79bc11
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@@ -413,216 -391,17 +413,232 @@@ CREATE VIEW `cloud`.`account_view` A
              and async_job.instance_type = 'Account'
              and async_job.job_status = 0;
  
 +			
 +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;
 +
 +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;
 +		
++
+ ALTER TABLE `cloud`.`remote_access_vpn` ADD COLUMN `id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT COMMENT 'id';
+ ALTER TABLE `cloud`.`remote_access_vpn` ADD COLUMN `uuid` varchar(40) UNIQUE;
+ 
+ -- START: support for LXC
+  
+ INSERT IGNORE INTO `cloud`.`hypervisor_capabilities`(hypervisor_type, hypervisor_version, max_guests_limit, security_group_enabled) VALUES ('LXC', 'default', 50, 1);
+ ALTER TABLE `cloud`.`physical_network_traffic_types` ADD COLUMN `lxc_network_label` varchar(255) DEFAULT 'cloudbr0' COMMENT 'The network name label of the physical device dedicated to this traffic on a LXC host';
+  
+ UPDATE configuration SET value='KVM,XenServer,VMware,BareMetal,Ovm,LXC' WHERE name='hypervisor.list';
+  
+ INSERT INTO `cloud`.`vm_template` (id, unique_name, name, public, created, type, hvm, bits, account_id, url, checksum, enable_password, display_text, format, guest_os_id, featured, cross_zones, hypervisor_type)
+      VALUES (10, 'routing-10', 'SystemVM Template (LXC)', 0, now(), 'SYSTEM', 0, 64, 1, 'http://download.cloud.com/templates/acton/acton-systemvm-02062012.qcow2.bz2', '2755de1f9ef2ce4d6f2bee2efbb4da92', 0, 'SystemVM Template (LXC)', 'QCOW2', 15, 0, 1, 'LXC');
+ 
+ -- END: support for LXC
++
 +-- Re-enable foreign key checking, at the end of the upgrade path
- SET foreign_key_checks = 1;			
++SET foreign_key_checks = 1;			


Mime
View raw message