Complete the move of the virtualmachinemanager to cloud-engine

This commit is contained in:
Alex Huang 2013-06-13 13:48:28 -07:00
parent fbe76f0b0f
commit 3ef77bc85a
29 changed files with 100 additions and 160 deletions

View File

@ -22,7 +22,6 @@ import com.cloud.deploy.DeploymentPlan;
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
import com.cloud.host.Host;
import com.cloud.host.Host.Type;
import com.cloud.host.HostVO;
import com.cloud.offering.ServiceOffering;
import com.cloud.utils.component.Adapter;
import com.cloud.vm.VirtualMachine;
@ -78,7 +77,7 @@ public interface HostAllocator extends Adapter {
* @param boolean considerReservedCapacity (default should be true, set to false if host capacity calculation should not look at reserved capacity)
* @return List<Host> List of hosts that are suitable for VM allocation
**/
public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, List<HostVO> hosts, int returnUpTo,
public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, List<? extends Host> hosts, int returnUpTo,
boolean considerReservedCapacity);
public static int RETURN_UPTO_ALL = -1;

View File

@ -65,6 +65,9 @@ import com.cloud.utils.fsm.NoTransitionException;
*
*/
public interface VirtualMachineManager extends Manager {
public interface Topics {
public static final String VM_POWER_STATE = "vm.powerstate";
}
boolean allocate(String vmInstanceName,
VMTemplateVO template,

View File

@ -33,6 +33,10 @@ import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import org.apache.log4j.lf5.viewer.configure.ConfigurationManager;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
import org.apache.cloudstack.config.ConfigRepo;
@ -41,12 +45,12 @@ import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.config.Configs;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
import org.apache.cloudstack.framework.jobs.AsyncJob;
import org.apache.cloudstack.framework.jobs.AsyncJobConstants;
import org.apache.cloudstack.framework.jobs.AsyncJobManager;
import org.apache.cloudstack.framework.messagebus.MessageBus;
import org.apache.cloudstack.framework.messagebus.MessageDispatcher;
import org.apache.cloudstack.framework.messagebus.MessageHandler;
import org.apache.cloudstack.messagebus.TopicConstants;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.cloudstack.vm.jobs.VmWorkJobDao;
import org.apache.cloudstack.vm.jobs.VmWorkJobVO;
@ -80,9 +84,8 @@ import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.agent.manager.Commands;
import com.cloud.agent.manager.allocator.HostAllocator;
import com.cloud.alert.AlertManager;
import com.cloud.api.ApiSerializerHelper;
import com.cloud.api.StringMapTypeAdapter;
import com.cloud.async.AsyncJobExecutionContext;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dao.EntityManager;
import com.cloud.dc.ClusterDetailsDao;
@ -97,8 +100,6 @@ import com.cloud.deploy.DeploymentPlan;
import com.cloud.deploy.DeploymentPlanner;
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
import com.cloud.deploy.DeploymentPlanningManager;
import com.cloud.event.EventTypes;
import com.cloud.event.UsageEventUtils;
import com.cloud.exception.AffinityConflictException;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.ConcurrentOperationException;
@ -132,7 +133,6 @@ import com.cloud.resource.ResourceManager;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.storage.DiskOfferingVO;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.StorageManager;
import com.cloud.storage.StoragePool;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.Volume;
@ -142,12 +142,12 @@ import com.cloud.storage.VolumeVO;
import com.cloud.storage.dao.StoragePoolHostDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.User;
import com.cloud.utils.DateUtil;
import com.cloud.utils.Journal;
import com.cloud.utils.Pair;
import com.cloud.utils.Predicate;
import com.cloud.utils.StringUtils;
import com.cloud.utils.Ternary;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.concurrency.NamedThreadFactory;
@ -177,8 +177,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
@Inject
ConfigRepo _configRepo;
@Inject
protected StorageManager _storageMgr;
@Inject
DataStoreManager _dataStoreMgr;
@Inject
protected NetworkManager _networkMgr;
@ -196,8 +194,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
@Inject
protected NicDao _nicsDao;
@Inject
protected AccountManager _accountMgr;
@Inject
protected HostDao _hostDao;
@Inject
protected AlertManager _alertMgr;
@ -271,6 +267,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
protected ConfigValue<Integer> _operationTimeout;
protected ConfigValue<Boolean> _forceStop;
protected long _nodeId;
protected Gson _gson;
SearchBuilder<VolumeVO> RootVolumeSearch;
@ -479,7 +476,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
.done();
_messageBus.subscribe(TopicConstants.VM_POWER_STATE, MessageDispatcher.getDispatcher(this));
_messageBus.subscribe(Topics.VM_POWER_STATE, MessageDispatcher.getDispatcher(this));
GsonBuilder gBuilder = new GsonBuilder();
gBuilder.setVersion(1.3);
gBuilder.registerTypeAdapter(Map.class, new StringMapTypeAdapter());
_gson = gBuilder.create();
return true;
}
@ -666,6 +668,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
return false;
}
public String serialize(VmWork work) {
return _gson.toJson(work);
}
public <T extends VmWork> T deserialize(Class<T> clazz, String work) {
return _gson.fromJson(work, clazz);
}
@Override
@DB
public void advanceStart(String vmUuid, Map<VirtualMachineProfile.Param, Object> params, DeploymentPlan planToDeploy)
@ -708,7 +718,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
workInfo.setVmId(vm.getId());
workInfo.setPlan(planToDeploy);
workInfo.setParams(params);
workJob.setCmdInfo(ApiSerializerHelper.toSerializedString(workInfo));
workJob.setCmdInfo(serialize(workInfo));
_jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
}
@ -730,7 +740,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
//
//
_jobMgr.waitAndCheck(
new String[] { TopicConstants.VM_POWER_STATE, TopicConstants.JOB_STATE },
new String[] {Topics.VM_POWER_STATE, AsyncJob.Topics.JOB_STATE},
3000L, 600000L, new Predicate() {
@Override
@ -976,10 +986,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
VmWorkJobVO.Step prevStep = work.getStep();
_workJobDao.updateStep(work.getId(), VmWorkJobVO.Step.Release);
if (prevStep == VmWorkJobVO.Step.Started || prevStep == VmWorkJobVO.Step.Starting) {
cleanup(vmGuru, vmProfile, work, Event.OperationFailed, false, caller, account);
cleanup(vmGuru, vmProfile, work, Event.OperationFailed, false);
} else {
//if step is not starting/started, send cleanup command with force=true
cleanup(vmGuru, vmProfile, work, Event.OperationFailed, true, caller, account);
cleanup(vmGuru, vmProfile, work, Event.OperationFailed, true);
}
}
}
@ -1039,8 +1049,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
return true;
}
protected boolean cleanup(VirtualMachineGuru guru, VirtualMachineProfile profile, VmWorkJobVO work, Event event, boolean force, User user,
Account account) {
protected boolean cleanup(VirtualMachineGuru guru, VirtualMachineProfile profile, VmWorkJobVO work, Event event, boolean force) {
VirtualMachine vm = profile.getVirtualMachine();
State state = vm.getState();
s_logger.debug("Cleaning up resources for the vm " + vm + " in " + state + " state");
@ -1142,7 +1151,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
workInfo.setUserId(user.getId());
workInfo.setVmId(vm.getId());
workInfo.setForceStop(forced);
workJob.setCmdInfo(ApiSerializerHelper.toSerializedString(workInfo));
workJob.setCmdInfo(serialize(workInfo));
_jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
}
@ -1158,7 +1167,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
_jobMgr.waitAndCheck(
new String[] { TopicConstants.VM_POWER_STATE, TopicConstants.JOB_STATE },
new String[] {Topics.VM_POWER_STATE, AsyncJob.Topics.JOB_STATE},
3000L, 600000L, new Predicate() {
@Override
@ -1234,7 +1243,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
}
if (doCleanup) {
if (cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.StopRequested, forced, user, account)) {
if (cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.StopRequested, forced)) {
try {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Updating work item to Done, id:" + work.getId());
@ -1774,8 +1783,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
} catch (AgentUnavailableException e) {
s_logger.error("AgentUnavailableException while cleanup on source host: " + srcHostId);
}
cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.AgentReportStopped, true,
_accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.AgentReportStopped, true);
return null;
}
} catch (OperationTimedoutException e) {
@ -2858,8 +2866,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
}
// Check that the service offering being upgraded to has all the tags of the current service offering
List<String> currentTags = _configMgr.csvTagsToList(currentServiceOffering.getTags());
List<String> newTags = _configMgr.csvTagsToList(newServiceOffering.getTags());
List<String> currentTags = StringUtils.csvTagsToList(currentServiceOffering.getTags());
List<String> newTags = StringUtils.csvTagsToList(newServiceOffering.getTags());
if (!newTags.containsAll(currentTags)) {
throw new InvalidParameterValueException("Unable to upgrade virtual machine; the new service offering " +
"does not have all the tags of the "
@ -2872,7 +2880,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
public boolean upgradeVmDb(long vmId, long serviceOfferingId) {
VMInstanceVO vmForUpdate = _vmDao.createForUpdate();
vmForUpdate.setServiceOfferingId(serviceOfferingId);
ServiceOffering newSvcOff = _configMgr.getServiceOffering(serviceOfferingId);
ServiceOffering newSvcOff = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
vmForUpdate.setHaEnabled(newSvcOff.getOfferHA());
vmForUpdate.setLimitCpuUse(newSvcOff.getLimitCpuUse());
vmForUpdate.setServiceOfferingId(newSvcOff.getId());
@ -2955,7 +2963,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null, null, null, null);
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
DataCenter dc = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
Host host = _hostDao.findById(vm.getHostId());
DeployDestination dest = new DeployDestination(dc, null, null, host);
@ -2980,9 +2988,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
s_logger.debug("Nic is plugged successfully for vm " + vm + " in network " + network + ". Vm is a part of network now");
long isDefault = (nic.isDefaultNic()) ? 1 : 0;
// insert nic's Id into DB as resource_name
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vmVO.getAccountId(),
vmVO.getDataCenterId(), vmVO.getId(), Long.toString(nic.getId()), network.getNetworkOfferingId(),
null, isDefault, VirtualMachine.class.getName(), vmVO.getUuid());
//FIXME
// UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vmVO.getAccountId(),
// vmVO.getDataCenterId(), vmVO.getId(), Long.toString(nic.getId()), network.getNetworkOfferingId(),
// null, isDefault, VirtualMachine.class.getName(), vmVO.getUuid());
return nic;
} else {
s_logger.warn("Failed to plug nic to the vm " + vm + " in network " + network);
@ -3022,7 +3031,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null,
null, null, null);
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
DataCenter dc = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
Host host = _hostDao.findById(vm.getHostId());
DeployDestination dest = new DeployDestination(dc, null, null, host);
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
@ -3053,9 +3062,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
if (result) {
s_logger.debug("Nic is unplugged successfully for vm " + vm + " in network " + network );
long isDefault = (nic.isDefaultNic()) ? 1 : 0;
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vm.getAccountId(), vm.getDataCenterId(),
vm.getId(), Long.toString(nic.getId()), network.getNetworkOfferingId(), null,
isDefault, VirtualMachine.class.getName(), vm.getUuid());
//FIXME
// UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vm.getAccountId(), vm.getDataCenterId(),
// vm.getId(), Long.toString(nic.getId()), network.getNetworkOfferingId(), null,
// isDefault, VirtualMachine.class.getName(), vm.getUuid());
} else {
s_logger.warn("Failed to unplug nic for the vm " + vm + " from network " + network);
return false;
@ -3086,7 +3096,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null,
null, null, null);
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
DataCenter dc = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
Host host = _hostDao.findById(vm.getHostId());
DeployDestination dest = new DeployDestination(dc, null, null, host);
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
@ -3418,7 +3428,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
// PowerState report handling for out-of-band changes and handling of left-over transitional VM states
//
@MessageHandler(topic=TopicConstants.VM_POWER_STATE)
@MessageHandler(topic = Topics.VM_POWER_STATE)
private void HandlePownerStateReport(Object target, String subject, String senderAddress, Object args) {
assert(args != null);
Long vmId = (Long)args;
@ -3438,7 +3448,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
HandlePowerOffReportWithNoPendingJobsOnVM(vm);
break;
// PowerUnknown shouldn't be reported, it is a derived
// PowerUnknown shouldn't be reported, it is a derived
// VM power state from host state (host un-reachable
case PowerUnknown :
default :
@ -3492,7 +3502,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
case Destroyed :
case Expunging :
s_logger.info("Receive power on report when VM is in destroyed or expunging state. vm: "
s_logger.info("Receive power on report when VM is in destroyed or expunging state. vm: "
+ vm.getId() + ", state: " + vm.getState());
break;
@ -3506,7 +3516,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
case Error :
default :
s_logger.info("Receive power on report when VM is in error or unexpected state. vm: "
s_logger.info("Receive power on report when VM is in error or unexpected state. vm: "
+ vm.getId() + ", state: " + vm.getState());
break;
}
@ -3517,7 +3527,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
// TODO :
// 1) handle left-over transitional VM states
// 2) handle out of sync stationary states, schedule force-stop to release resources
//
//
switch(vm.getState()) {
case Starting :
break;
@ -3546,7 +3556,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
private void scanStalledVMInTransitionState(long hostId) {
//
// TODO check VM that is stuck in Starting, Stopping, Migrating states, we won't check
// TODO check VM that is stuck in Starting, Stopping, Migrating states, we won't check
// VMs in expunging state (this need to be handled specially)
//
// checking condition

View File

@ -25,7 +25,6 @@ import org.apache.log4j.Logger;
import org.apache.cloudstack.framework.messagebus.MessageBus;
import org.apache.cloudstack.framework.messagebus.PublishScope;
import org.apache.cloudstack.messagebus.TopicConstants;
import com.cloud.agent.api.HostVmStateReportEntry;
import com.cloud.vm.VirtualMachine.PowerState;
@ -78,7 +77,7 @@ public class VirtualMachinePowerStateSyncImpl implements VirtualMachinePowerStat
if(s_logger.isDebugEnabled())
s_logger.debug("VM state report is updated. host: " + hostId + ", vm id: " + entry.getKey() + ", power state: " + entry.getValue());
_messageBus.publish(null, TopicConstants.VM_POWER_STATE, PublishScope.GLOBAL, entry.getKey());
_messageBus.publish(null, VirtualMachineManager.Topics.VM_POWER_STATE, PublishScope.GLOBAL, entry.getKey());
}
}

View File

@ -26,7 +26,6 @@ import org.apache.cloudstack.framework.jobs.AsyncJobConstants;
import org.apache.cloudstack.framework.jobs.AsyncJobDispatcher;
import org.apache.cloudstack.framework.jobs.AsyncJobManager;
import com.cloud.api.ApiSerializerHelper;
import com.cloud.dao.EntityManager;
import com.cloud.user.dao.AccountDao;
import com.cloud.utils.component.AdapterBase;
@ -56,7 +55,11 @@ public class VmWorkJobDispatcher extends AdapterBase implements AsyncJobDispatch
String cmd = job.getCmd();
assert(cmd != null);
work = (VmWork)ApiSerializerHelper.fromSerializedString(job.getCmdInfo());
if (cmd.equals(Start)) {
work = _vmMgr.deserialize(VmWorkStart.class, job.getCmdInfo());
} else {
work = _vmMgr.deserialize(VmWorkStop.class, job.getCmdInfo());
}
assert(work != null);
CallContext.register(work.getUserId(), work.getAccountId(), job.getRelated());

View File

@ -11,7 +11,7 @@
// 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
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.agent.manager.allocator.impl;
@ -19,13 +19,11 @@ package com.cloud.agent.manager.allocator.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.agent.manager.allocator.HostAllocator;
import com.cloud.deploy.DeploymentPlan;
@ -40,7 +38,6 @@ import com.cloud.utils.component.AdapterBase;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
@Component
@Local(value=HostAllocator.class)
public class RandomAllocator extends AdapterBase implements HostAllocator {
private static final Logger s_logger = Logger.getLogger(RandomAllocator.class);
@ -55,7 +52,7 @@ public class RandomAllocator extends AdapterBase implements HostAllocator {
@Override
public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type,
ExcludeList avoid, List<HostVO> hosts, int returnUpTo, boolean considerReservedCapacity) {
ExcludeList avoid, List<Host> hosts, int returnUpTo, boolean considerReservedCapacity) {
long dcId = plan.getDataCenterId();
Long podId = plan.getPodId();
Long clusterId = plan.getClusterId();

View File

@ -40,7 +40,6 @@ import com.cloud.deploy.DeploymentPlanner.ExcludeList;
import com.cloud.host.DetailVO;
import com.cloud.host.Host;
import com.cloud.host.Host.Type;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.host.dao.HostDetailsDao;
import com.cloud.offering.ServiceOffering;
@ -121,7 +120,7 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
boolean hasSvcOfferingTag = hostTagOnOffering != null ? true : false;
boolean hasTemplateTag = hostTagOnTemplate != null ? true : false;
List<HostVO> clusterHosts = new ArrayList<HostVO>();
List<? extends Host> clusterHosts = new ArrayList<Host>();
String haVmTag = (String)vmProfile.getParameter(VirtualMachineProfile.Param.HaTag);
if (haVmTag != null) {
@ -130,8 +129,8 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
if (hostTagOnOffering == null && hostTagOnTemplate == null){
clusterHosts = _resourceMgr.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId);
} else {
List<HostVO> hostsMatchingOfferingTag = new ArrayList<HostVO>();
List<HostVO> hostsMatchingTemplateTag = new ArrayList<HostVO>();
List<? extends Host> hostsMatchingOfferingTag = new ArrayList<Host>();
List<? extends Host> hostsMatchingTemplateTag = new ArrayList<Host>();
if (hasSvcOfferingTag){
if (s_logger.isDebugEnabled()){
s_logger.debug("Looking for hosts having tag specified on SvcOffering:" + hostTagOnOffering);
@ -170,9 +169,9 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
}
// add all hosts that we are not considering to the avoid list
List<HostVO> allhostsInCluster = _hostDao.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId, null);
List<? extends Host> allhostsInCluster = _hostDao.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId, null);
allhostsInCluster.removeAll(clusterHosts);
for (HostVO host : allhostsInCluster) {
for (Host host : allhostsInCluster) {
avoid.addHost(host.getId());
}
@ -181,7 +180,7 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
@Override
public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan,
Type type, ExcludeList avoid, List<HostVO> hosts, int returnUpTo, boolean considerReservedCapacity) {
Type type, ExcludeList avoid, List<Host> hosts, int returnUpTo, boolean considerReservedCapacity) {
long dcId = plan.getDataCenterId();
Long podId = plan.getPodId();
Long clusterId = plan.getClusterId();
@ -226,7 +225,8 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
return suitableHosts;
}
protected List<Host> allocateTo(DeploymentPlan plan, ServiceOffering offering, VMTemplateVO template, ExcludeList avoid, List<HostVO> hosts, int returnUpTo, boolean considerReservedCapacity, Account account) {
protected List<Host> allocateTo(DeploymentPlan plan, ServiceOffering offering, VMTemplateVO template, ExcludeList avoid, List<? extends Host> hosts, int returnUpTo,
boolean considerReservedCapacity, Account account) {
if (_allocationAlgorithm.equals("random") || _allocationAlgorithm.equals("userconcentratedpod_random")) {
// Shuffle this so that we don't check the hosts in the same order.
Collections.shuffle(hosts);
@ -252,7 +252,7 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
List<Host> suitableHosts = new ArrayList<Host>();
for (HostVO host : hosts) {
for (Host host : hosts) {
if(suitableHosts.size() == returnUpTo){
break;
}
@ -303,7 +303,7 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
return suitableHosts;
}
private List<HostVO> reorderHostsByNumberOfVms(DeploymentPlan plan, List<HostVO> hosts, Account account) {
private List<? extends Host> reorderHostsByNumberOfVms(DeploymentPlan plan, List<? extends Host> hosts, Account account) {
if(account == null){
return hosts;
}
@ -317,15 +317,15 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
}
//now filter the given list of Hosts by this ordered list
Map<Long, HostVO> hostMap = new HashMap<Long, HostVO>();
for (HostVO host : hosts) {
Map<Long, Host> hostMap = new HashMap<Long, Host>();
for (Host host : hosts) {
hostMap.put(host.getId(), host);
}
List<Long> matchingHostIds = new ArrayList<Long>(hostMap.keySet());
hostIdsByVmCount.retainAll(matchingHostIds);
List<HostVO> reorderedHosts = new ArrayList<HostVO>();
List<Host> reorderedHosts = new ArrayList<Host>();
for(Long id: hostIdsByVmCount){
reorderedHosts.add(hostMap.get(id));
}
@ -340,7 +340,7 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
return true;
}
protected List<HostVO> prioritizeHosts(VMTemplateVO template, List<HostVO> hosts) {
protected List<? extends Host> prioritizeHosts(VMTemplateVO template, List<? extends Host> hosts) {
if (template == null) {
return hosts;
}
@ -348,13 +348,13 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
// Determine the guest OS category of the template
String templateGuestOSCategory = getTemplateGuestOSCategory(template);
List<HostVO> prioritizedHosts = new ArrayList<HostVO>();
List<HostVO> noHvmHosts = new ArrayList<HostVO>();
List<Host> prioritizedHosts = new ArrayList<Host>();
List<Host> noHvmHosts = new ArrayList<Host>();
// If a template requires HVM and a host doesn't support HVM, remove it from consideration
List<HostVO> hostsToCheck = new ArrayList<HostVO>();
List<Host> hostsToCheck = new ArrayList<Host>();
if (template.isRequiresHvm()) {
for (HostVO host : hosts) {
for (Host host : hosts) {
if (hostSupportsHVM(host)) {
hostsToCheck.add(host);
} else {
@ -372,9 +372,9 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
}
// If a host is tagged with the same guest OS category as the template, move it to a high priority list
// If a host is tagged with a different guest OS category than the template, move it to a low priority list
List<HostVO> highPriorityHosts = new ArrayList<HostVO>();
List<HostVO> lowPriorityHosts = new ArrayList<HostVO>();
for (HostVO host : hostsToCheck) {
List<Host> highPriorityHosts = new ArrayList<Host>();
List<Host> lowPriorityHosts = new ArrayList<Host>();
for (Host host : hostsToCheck) {
String hostGuestOSCategory = getHostGuestOSCategory(host);
if (hostGuestOSCategory == null) {
continue;
@ -389,7 +389,7 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
hostsToCheck.removeAll(lowPriorityHosts);
// Prioritize the remaining hosts by HVM capability
for (HostVO host : hostsToCheck) {
for (Host host : hostsToCheck) {
if (!template.isRequiresHvm() && !hostSupportsHVM(host)) {
// Host and template both do not support hvm, put it as first consideration
prioritizedHosts.add(0, host);
@ -406,7 +406,7 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
return prioritizedHosts;
}
protected boolean hostSupportsHVM(HostVO host) {
protected boolean hostSupportsHVM(Host host) {
if ( !_checkHvm ) {
return true;
}
@ -425,7 +425,7 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
return false;
}
protected String getHostGuestOSCategory(HostVO host) {
protected String getHostGuestOSCategory(Host host) {
DetailVO hostDetail = _hostDetailsDao.findDetail(host.getId(), "guest.os.category.id");
if (hostDetail != null) {
String guestOSCategoryIdString = hostDetail.getValue();

View File

@ -29,7 +29,6 @@ import com.cloud.agent.manager.allocator.HostAllocator;
import com.cloud.deploy.DeploymentPlan;
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.host.Host.Type;
import com.cloud.host.dao.HostDao;
import com.cloud.offering.ServiceOffering;
@ -53,7 +52,7 @@ public class TestingAllocator extends AdapterBase implements HostAllocator {
@Override
public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type,
ExcludeList avoid, List<HostVO> hosts, int returnUpTo, boolean considerReservedCapacity) {
ExcludeList avoid, List<Host> hosts, int returnUpTo, boolean considerReservedCapacity) {
return allocateTo(vmProfile, plan, type, avoid, returnUpTo, considerReservedCapacity);
}
@ -61,7 +60,7 @@ public class TestingAllocator extends AdapterBase implements HostAllocator {
public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type,
ExcludeList avoid, int returnUpTo, boolean considerReservedCapacity) {
List<Host> availableHosts = new ArrayList<Host>();
Host host = null;
Host host = null;
if (type == Host.Type.Routing && _routingHost != null) {
host = _hostDao.findById(_routingHost);
} else if (type == Host.Type.Storage && _storageHost != null) {

View File

@ -58,7 +58,6 @@ import org.apache.cloudstack.framework.jobs.impl.SyncQueueVO;
import org.apache.cloudstack.framework.messagebus.MessageBus;
import org.apache.cloudstack.framework.messagebus.MessageDetector;
import org.apache.cloudstack.framework.messagebus.PublishScope;
import org.apache.cloudstack.messagebus.TopicConstants;
import com.cloud.api.ApiSerializerHelper;
import com.cloud.cluster.ClusterManager;
@ -254,7 +253,7 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager,
scheduleExecution(jobToWakeup, false);
}
_messageBus.publish(null, TopicConstants.JOB_STATE, PublishScope.GLOBAL, jobId);
_messageBus.publish(null, AsyncJob.Topics.JOB_STATE, PublishScope.GLOBAL, jobId);
} catch(Exception e) {
s_logger.error("Unexpected exception while completing async job-" + jobId, e);
txn.rollback();
@ -511,7 +510,7 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager,
private long getJobRunNumber() {
synchronized(this) {
return this._executionRunNumber++;
return _executionRunNumber++;
}
}

View File

@ -18,6 +18,7 @@ package com.cloud.capacity;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.storage.VMTemplateVO;
import com.cloud.utils.component.Manager;
@ -45,7 +46,7 @@ public interface CapacityManager extends Manager {
/**
* @param pool storage pool
* @param templateForVmCreation template that will be used for vm creation
* @param templateForVmCreation template that will be used for vm creation
* @return total allocated capacity for the storage pool
*/
long getAllocatedPoolCapacity(StoragePoolVO pool, VMTemplateVO templateForVmCreation);
@ -55,5 +56,5 @@ public interface CapacityManager extends Manager {
* @param host the host to be checked
* @return true if the count of host's running VMs >= hypervisor limit
*/
boolean checkIfHostReachMaxGuestLimit(HostVO host);
boolean checkIfHostReachMaxGuestLimit(Host host);
}

View File

@ -27,11 +27,12 @@ import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.apache.cloudstack.framework.messagebus.MessageBus;
import org.apache.cloudstack.framework.messagebus.PublishScope;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.agent.AgentManager;
import com.cloud.agent.Listener;
@ -899,7 +900,7 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
}
@Override
public boolean checkIfHostReachMaxGuestLimit(HostVO host) {
public boolean checkIfHostReachMaxGuestLimit(Host host) {
Long vmCount = _vmDao.countRunningByHostId(host.getId());
HypervisorType hypervisorType = host.getHypervisorType();
String hypervisorVersion = host.getHypervisorVersion();

View File

@ -160,7 +160,8 @@ public enum Config {
HostStatsInterval("Advanced", ManagementServer.class, Integer.class, "host.stats.interval", "60000", "The interval (in milliseconds) when host stats are retrieved from agents.", null),
HostRetry("Advanced", AgentManager.class, Integer.class, "host.retry", "2", "Number of times to retry hosts for creating a volume", null),
IntegrationAPIPort("Advanced", ManagementServer.class, Integer.class, "integration.api.port", null, "Defaul API port", null),
InvestigateRetryInterval("Advanced", HighAvailabilityManager.class, Integer.class, "investigate.retry.interval", "60", "Time (in seconds) between VM pings when agent is disconnected", null),
InvestigateRetryInterval("Advanced", HighAvailabilityManager.class, Integer.class, "investigate.retry.interval", "60",
"Time (in seconds) between VM pings when agent is disconnected", null),
MigrateRetryInterval("Advanced", HighAvailabilityManager.class, Integer.class, "migrate.retry.interval", "120", "Time (in seconds) between migration retries", null),
PingInterval("Advanced", AgentManager.class, Integer.class, "ping.interval", "60", "Ping interval in seconds", null),
PingTimeout("Advanced", AgentManager.class, Float.class, "ping.timeout", "2.5", "Multiplier to ping.interval before announcing an agent has timed out", null),

View File

@ -16,7 +16,6 @@
// under the License.
package com.cloud.configuration;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -154,22 +153,6 @@ public interface ConfigurationManager extends ConfigurationService, Manager {
*/
boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId, Account caller);
/**
* Converts a comma separated list of tags to a List
*
* @param tags
* @return List of tags
*/
List<String> csvTagsToList(String tags);
/**
* Converts a List of tags to a comma separated list
*
* @param tags
* @return String containing a comma separated list of tags
*/
String listToCsvTags(List<String> tags);
void checkZoneAccess(Account caller, DataCenter zone);
void checkDiskOfferingAccess(Account caller, DiskOffering dof);

View File

@ -3216,35 +3216,6 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
}
}
@Override
public List<String> csvTagsToList(String tags) {
List<String> tagsList = new ArrayList<String>();
if (tags != null) {
String[] tokens = tags.split(",");
for (int i = 0; i < tokens.length; i++) {
tagsList.add(tokens[i].trim());
}
}
return tagsList;
}
@Override
public String listToCsvTags(List<String> tagsList) {
String tags = "";
if (tagsList.size() > 0) {
for (int i = 0; i < tagsList.size(); i++) {
tags += tagsList.get(i);
if (i != tagsList.size() - 1) {
tags += ",";
}
}
}
return tags;
}
@Override
public String cleanupTags(String tags) {
if (tags != null) {

View File

@ -1,26 +0,0 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.messagebus;
public interface TopicConstants {
// VM power state messages on message bus
public static final String VM_POWER_STATE = "vm.powerstate"; // args <Long> vmid
// job messages on message bus
public static final String JOB_HEARTBEAT = "job.heartbeat"; // args <Long> jobid
public static final String JOB_STATE = "job.state"; // args <Long> jobid
}