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/edb12b1d
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/edb12b1d
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/edb12b1d
Branch: refs/heads/affinity_groups
Commit: edb12b1d9c390579f433b085400dd563b233bd92
Parents: 71327ed
Author: Prachi Damle <[email protected]>
Authored: Fri Mar 29 00:17:44 2013 -0700
Committer: Prachi Damle <[email protected]>
Committed: Fri Mar 29 00:17:44 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 | 90 ++++++++-------
.../src/com/cloud/server/ManagementServerImpl.java | 20 +++
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, 213 insertions(+), 174 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/edb12b1d/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/edb12b1d/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/edb12b1d/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/edb12b1d/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/edb12b1d/client/tomcatconf/commands.properties.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/commands.properties.in
b/client/tomcatconf/commands.properties.in
index f346d25..937b0ea 100644
--- a/client/tomcatconf/commands.properties.in
+++ b/client/tomcatconf/commands.properties.in
@@ -552,3 +552,4 @@ createAffinityGroup=15
deleteAffinityGroup=15
listAffinityGroups=15
updateVMAffinityGroup=15
+listAffinityGroupTypes=15
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/edb12b1d/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 d7bab4a..ff09e03 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
@@ -35,7 +35,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 StoragePoolDao _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(), poolId , 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/edb12b1d/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/edb12b1d/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 187ceab..d94ad85 100755
--- a/server/src/com/cloud/deploy/FirstFitPlanner.java
+++ b/server/src/com/cloud/deploy/FirstFitPlanner.java
@@ -148,38 +148,44 @@ public class FirstFitPlanner extends PlannerBase
implements DeploymentPlanner {
s_logger.debug("DeploymentPlan has host_id specified, making
no checks on this host, looks like admin test: "+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.");
@@ -395,9 +401,9 @@ public class FirstFitPlanner extends PlannerBase implements
DeploymentPlanner {
}
/**
- * This method should reorder the given list of Cluster Ids by applying
any necessary heuristic
+ * This method should reorder the given list of Cluster Ids by applying
any necessary heuristic
* for this planner
- * For FirstFitPlanner there is no specific heuristic to be applied
+ * For FirstFitPlanner there is no specific heuristic to be applied
* other than the capacity based ordering which is done by default.
* @return List<Long> ordered list of Cluster Ids
*/
@@ -407,9 +413,9 @@ public class FirstFitPlanner extends PlannerBase implements
DeploymentPlanner {
}
/**
- * This method should reorder the given list of Pod Ids by applying any
necessary heuristic
+ * This method should reorder the given list of Pod Ids by applying any
necessary heuristic
* for this planner
- * For FirstFitPlanner there is no specific heuristic to be applied
+ * For FirstFitPlanner there is no specific heuristic to be applied
* other than the capacity based ordering which is done by default.
* @return List<Long> ordered list of Pod Ids
*/
@@ -431,7 +437,7 @@ public class FirstFitPlanner extends PlannerBase implements
DeploymentPlanner {
private List<Long> listDisabledPods(long zoneId){
List<Long> disabledPods = _podDao.listDisabledPods(zoneId);
return disabledPods;
- }
+ }
private Map<Short,Float> getCapacityThresholdMap(){
// Lets build this real time so that the admin wont have to restart MS
if he changes these values
@@ -449,9 +455,9 @@ public class FirstFitPlanner extends PlannerBase implements
DeploymentPlanner {
}
private List<Short> getCapacitiesForCheckingThreshold(){
- List<Short> capacityList = new ArrayList<Short>();
+ List<Short> capacityList = new ArrayList<Short>();
capacityList.add(Capacity.CAPACITY_TYPE_CPU);
- capacityList.add(Capacity.CAPACITY_TYPE_MEMORY);
+ capacityList.add(Capacity.CAPACITY_TYPE_MEMORY);
return capacityList;
}
@@ -467,7 +473,7 @@ public class FirstFitPlanner extends PlannerBase implements
DeploymentPlanner {
// For each capacity get the cluster list crossing the threshold
and remove it from the clusterList that will be used for vm allocation.
for(short capacity : capacityList){
-
+
if (clusterListForVmAllocation == null ||
clusterListForVmAllocation.size() == 0){
return;
}
@@ -480,17 +486,17 @@ public class FirstFitPlanner extends PlannerBase
implements DeploymentPlanner {
capacityThresholdMap.get(capacity), ram_requested );
}
-
+
if (clustersCrossingThreshold != null &&
clustersCrossingThreshold.size() != 0){
// addToAvoid Set
avoid.addClusterList(clustersCrossingThreshold);
// Remove clusters crossing disabled threshold
clusterListForVmAllocation.removeAll(clustersCrossingThreshold);
-
+
s_logger.debug("Cannot allocate cluster list " +
clustersCrossingThreshold.toString() + " for vm creation since their allocated
percentage" +
" crosses the disable capacity
threshold: " + capacityThresholdMap.get(capacity) + " for capacity Type : " +
capacity + ", skipping these clusters");
}
-
+
}
}
@@ -640,7 +646,7 @@ public class FirstFitPlanner extends PlannerBase implements
DeploymentPlanner {
public int compare(Volume v1, Volume v2) {
if(v1.getSize() < v2.getSize())
return 1;
- else
+ else
return -1;
}
});
@@ -737,7 +743,7 @@ public class FirstFitPlanner extends PlannerBase implements
DeploymentPlanner {
}else{
pool =
(StoragePool)this.dataStoreMgr.getPrimaryDataStore(plan.getPoolId());
}
-
+
if(!pool.isInMaintenance()){
if(!avoid.shouldAvoid(pool)){
long exstPoolDcId = pool.getDataCenterId();
@@ -769,13 +775,13 @@ public class FirstFitPlanner extends PlannerBase
implements DeploymentPlanner {
if(!isRootAdmin(plan.getReservationContext())){
if(!isEnabledForAllocation(plan.getDataCenterId(),
plan.getPodId(), plan.getClusterId())){
if(s_logger.isDebugEnabled()){
- s_logger.debug("Cannot allocate new storagepool for
this volume in this cluster, allocation state is disabled");
+ s_logger.debug("Cannot allocate new storagepool for
this volume in this cluster, allocation state is disabled");
s_logger.debug("Cannot deploy to this specified plan,
allocation state is disabled, returning.");
}
- //Cannot find suitable storage pools under this cluster
for this volume since allocation_state is disabled.
+ //Cannot find suitable storage pools under this cluster
for this volume since allocation_state is disabled.
//- remove any suitable pools found for other volumes.
//All volumes should get suitable pools under this
cluster; else we cant use this cluster.
- suitableVolumeStoragePools.clear();
+ suitableVolumeStoragePools.clear();
break;
}
}
@@ -865,7 +871,7 @@ public class FirstFitPlanner extends PlannerBase implements
DeploymentPlanner {
super.configure(name, params);
_allocationAlgorithm =
_configDao.getValue(Config.VmAllocationAlgorithm.key());
return true;
- }
+ }
private boolean isEnabledForAllocation(long zoneId, Long podId, Long
clusterId){
// Check if the zone exists in the system
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/edb12b1d/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 a0f4ba4..db70a3b 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -48,6 +48,8 @@ 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;
@@ -80,6 +82,7 @@ import org.apache.cloudstack.api.command.user.account.*;
import org.apache.cloudstack.api.command.user.address.*;
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 org.apache.cloudstack.api.command.user.autoscale.*;
@@ -436,6 +439,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);
}
@@ -725,6 +734,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()) {
@@ -2184,6 +2202,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/edb12b1d/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 e793476..ff22f09 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -2201,10 +2201,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);
+ }
}
}
@@ -2490,7 +2492,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/edb12b1d/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 010bb96..0a38a9e 100755
--- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -709,8 +709,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) {
@@ -724,6 +726,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();
@@ -1492,25 +1499,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/edb12b1d/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/edb12b1d/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/edb12b1d/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