Merge VirtualMachineManagerImpl for sync changes

This commit is contained in:
Kelven Yang 2013-10-18 14:08:58 -07:00
parent cf94cfb3f2
commit 6e70816169
7 changed files with 61 additions and 26 deletions

View File

@ -85,9 +85,9 @@ public interface VirtualMachineManager extends Manager {
DeploymentPlan plan,
HypervisorType hyperType) throws InsufficientCapacityException;
void start(String vmUuid, Map<VirtualMachineProfile.Param, Object> params);
void easyStart(String vmUuid, Map<VirtualMachineProfile.Param, Object> params);
void start(String vmUuid, Map<VirtualMachineProfile.Param, Object> params, DeploymentPlan planToDeploy);
void easyStart(String vmUuid, Map<VirtualMachineProfile.Param, Object> params, DeploymentPlan planToDeploy);
void stop(String vmUuid) throws ResourceUnavailableException;

View File

@ -35,6 +35,7 @@ import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.ejb.Local;
import javax.inject.Inject;
@ -53,9 +54,11 @@ import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.Configurable;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.framework.jobs.AsyncJobManager;
import org.apache.cloudstack.framework.jobs.Outcome;
import org.apache.cloudstack.framework.jobs.dao.VmWorkJobDao;
import org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO;
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.jobs.JobInfo;
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
@ -291,10 +294,17 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
@Inject
DeploymentPlanningManager _dpMgr;
@Inject protected MessageBus _messageBus;
@Inject protected VirtualMachinePowerStateSync _syncMgr;
@Inject protected VmWorkJobDao _workJobDao;
@Inject protected AsyncJobManager _jobMgr;
@Inject
protected MessageBus _messageBus;
@Inject
protected VirtualMachinePowerStateSync _syncMgr;
@Inject
protected VmWorkJobDao _workJobDao;
@Inject
protected AsyncJobManager _jobMgr;
Map<VirtualMachine.Type, VirtualMachineGuru> _vmGurus = new HashMap<VirtualMachine.Type, VirtualMachineGuru>();
protected StateMachine2<State, VirtualMachine.Event, VirtualMachine> _stateMachine;
@ -315,9 +325,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
"On destroy, force-stop takes this value ", true);
static final ConfigKey<Integer> ClusterDeltaSyncInterval = new ConfigKey<Integer>("Advanced", Integer.class, "sync.interval", "60", "Cluster Delta sync interval in seconds",
false);
protected static final ConfigKey<Long> PingInterval = new ConfigKey<Long>("Advanced",
Long.class, "ping.interval", "60", "Ping interval in seconds", false);
static final ConfigKey<Long> VmJobCheckInterval = new ConfigKey<Long>("Advanced",
Long.class, "vm.job.check.interval", "3000", "Interval in milliseconds to check if the job is complete", true);
static final ConfigKey<Long> VmJobTimeout = new ConfigKey<Long>("Advanced",
Long.class, "vm.job.timeout", "600000", "Time in milliseconds to wait before attempting to cancel a job", true);
static final ConfigKey<Long> PingInterval = new ConfigKey<Long>("Advanced",
Long.class, "ping.interval", "60", "Ping interval in seconds", true);
ScheduledExecutorService _executor = null;
@ -493,6 +507,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
@Override
public boolean start() {
_executor.scheduleAtFixedRate(new TransitionTask(), PingInterval.value(), PingInterval.value(), TimeUnit.SECONDS);
_executor.scheduleAtFixedRate(new CleanupTask(), VmOpCleanupInterval.value(), VmOpCleanupInterval.value(), TimeUnit.SECONDS);
cancelWorkItems(_nodeId);
return true;
@ -512,6 +527,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
_nodeId = ManagementServerNode.getManagementServerId();
_agentMgr.registerForHostEvents(this, true, true, true);
_messageBus.subscribe(Topics.VM_POWER_STATE, MessageDispatcher.getDispatcher(this));
return true;
}
@ -521,20 +537,21 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
}
@Override
public void start(String vmUuid, Map<VirtualMachineProfile.Param, Object> params) {
start(vmUuid, params, null);
public void easyStart(String vmUuid, Map<VirtualMachineProfile.Param, Object> params) {
easyStart(vmUuid, params, null);
}
@Override
public void start(String vmUuid, Map<VirtualMachineProfile.Param, Object> params, DeploymentPlan planToDeploy) {
public void easyStart(String vmUuid, Map<VirtualMachineProfile.Param, Object> params, DeploymentPlan planToDeploy) {
Outcome<VirtualMachine> outcome = start(vmUuid, params, planToDeploy);
try {
advanceStart(vmUuid, params, planToDeploy);
} catch (ConcurrentOperationException e) {
throw new CloudRuntimeException("Unable to start a VM due to concurrent operation", e).add(VirtualMachine.class, vmUuid);
} catch (InsufficientCapacityException e) {
throw new CloudRuntimeException("Unable to start a VM due to insufficient capacity", e).add(VirtualMachine.class, vmUuid);
} catch (ResourceUnavailableException e) {
throw new CloudRuntimeException("Unable to start a VM due to concurrent operation", e).add(VirtualMachine.class, vmUuid);
outcome.get(VmJobTimeout.value(), TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
// FIXME: What to do
} catch (java.util.concurrent.ExecutionException e) {
// FIXME: What to do
} catch (TimeoutException e) {
// FIXME: What to do
}
}
@ -639,6 +656,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
throw new ConcurrentOperationException("Unable to change the state of " + vm);
}
/*
protected <T extends VMInstanceVO> boolean changeState(T vm, Event event, Long hostId, ItWorkVO work, Step step) throws NoTransitionException {
// FIXME: We should do this better.
Step previousStep = work.getStep();
@ -653,7 +671,24 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
}
}
}
*/
protected boolean changeState(VMInstanceVO vm, Event event, Long hostId, VmWorkJobVO work, Step step) throws NoTransitionException {
VmWorkJobVO.Step previousStep = work.getStep();
Transaction txn = Transaction.currentTxn();
txn.start();
work.setStep(step);
boolean result = stateTransitTo(vm, event, hostId);
if (!result) {
work.setStep(previousStep);
}
_workJobDao.update(work.getId(), work);
txn.commit();
return result;
}
protected boolean areAffinityGroupsAssociated(VirtualMachineProfile vmProfile) {
VirtualMachine vm = vmProfile.getVirtualMachine();
long vmGroupCount = _affinityGroupVMMapDao.countAffinityGroupsForVm(vm.getId());

View File

@ -224,7 +224,7 @@ public class VMEntityManagerImpl implements VMEntityManager {
DataCenterDeployment reservedPlan = new DataCenterDeployment(vm.getDataCenterId(),
vmReservation.getPodId(), vmReservation.getClusterId(), vmReservation.getHostId(), null, null);
try {
_itMgr.start(vm.getUuid(), params, reservedPlan);
_itMgr.easyStart(vm.getUuid(), params, reservedPlan);
} catch (Exception ex) {
// Retry the deployment without using the reservation plan
DataCenterDeployment plan = new DataCenterDeployment(0, null, null, null, null, null);
@ -233,11 +233,11 @@ public class VMEntityManagerImpl implements VMEntityManager {
plan.setAvoids(reservedPlan.getAvoids());
}
_itMgr.start(vm.getUuid(), params, plan);
_itMgr.easyStart(vm.getUuid(), params, plan);
}
} else {
// no reservation found. Let VirtualMachineManager retry
_itMgr.start(vm.getUuid(), params, null);
_itMgr.easyStart(vm.getUuid(), params, null);
}
}

View File

@ -536,7 +536,7 @@ public class ElasticLoadBalancerManagerImpl extends ManagerBase implements Elast
private DomainRouterVO start(DomainRouterVO elbVm, User user, Account caller, Map<Param, Object> params) throws StorageUnavailableException, InsufficientCapacityException,
ConcurrentOperationException, ResourceUnavailableException {
s_logger.debug("Starting ELB VM " + elbVm);
_itMgr.start(elbVm.getUuid(), params);
_itMgr.easyStart(elbVm.getUuid(), params);
return _routerDao.findById(elbVm.getId());
}

View File

@ -808,7 +808,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements In
throws StorageUnavailableException, InsufficientCapacityException,
ConcurrentOperationException, ResourceUnavailableException {
s_logger.debug("Starting Internal LB VM " + internalLbVm);
_itMgr.start(internalLbVm.getUuid(), params, null);
_itMgr.easyStart(internalLbVm.getUuid(), params, null);
if (internalLbVm.isStopPending()) {
s_logger.info("Clear the stop pending flag of Internal LB VM " + internalLbVm.getHostName() + " after start router successfully!");
internalLbVm.setStopPending(false);

View File

@ -2737,7 +2737,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
throws StorageUnavailableException, InsufficientCapacityException,
ConcurrentOperationException, ResourceUnavailableException {
s_logger.debug("Starting router " + router);
_itMgr.start(router.getUuid(), params, planToDeploy);
_itMgr.easyStart(router.getUuid(), params, planToDeploy);
if (router.isStopPending()) {
s_logger.info("Clear the stop pending flag of router " + router.getHostName() + " after start router successfully!");
router.setStopPending(false);

View File

@ -4832,7 +4832,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
if (needRestart) {
try {
_itMgr.start(vm.getUuid(), null);
_itMgr.easyStart(vm.getUuid(), null);
} catch (Exception e) {
s_logger.debug("Unable to start VM " + vm.getUuid(), e);
CloudRuntimeException ex = new CloudRuntimeException(