mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
changed expunge to do stop earlier.
This commit is contained in:
parent
da4ed648ac
commit
d4b56e89c3
@ -23,12 +23,8 @@ import java.util.Enumeration;
|
||||
import java.util.Formatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
@ -262,20 +258,14 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
||||
ScheduledExecutorService _executor = null;
|
||||
int _expungeInterval;
|
||||
int _expungeDelay;
|
||||
int _retry = 2;
|
||||
|
||||
String _name;
|
||||
String _instance;
|
||||
String _zone;
|
||||
String _defaultNetworkDomain;
|
||||
|
||||
Random _rand = new Random(System.currentTimeMillis());
|
||||
|
||||
private ConfigurationDao _configDao;
|
||||
|
||||
int _userVMCap = 0;
|
||||
final int _maxWeight = 256;
|
||||
|
||||
@Override
|
||||
public UserVmVO getVirtualMachine(long vmId) {
|
||||
return _vmDao.findById(vmId);
|
||||
@ -928,57 +918,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
||||
return vmStatsById;
|
||||
}
|
||||
|
||||
@DB
|
||||
protected String acquireGuestIpAddress(long dcId, long accountId, UserVmVO userVm) throws CloudRuntimeException {
|
||||
boolean routerLock = false;
|
||||
DomainRouterVO router = _routerDao.findBy(accountId, dcId);
|
||||
long routerId = router.getId();
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
try {
|
||||
txn.start();
|
||||
router = _routerDao.acquireInLockTable(routerId);
|
||||
if (router == null) {
|
||||
throw new CloudRuntimeException("Unable to lock up the router:" + routerId);
|
||||
}
|
||||
routerLock = true;
|
||||
List<UserVmVO> userVms = _vmDao.listByAccountAndDataCenter(accountId, dcId);
|
||||
Set<Long> allPossibleIps = NetUtils.getAllIpsFromCidr(router.getGuestIpAddress(), NetUtils.getCidrSize(router.getGuestNetmask()));
|
||||
Set<Long> usedIps = new TreeSet<Long> ();
|
||||
for (UserVmVO vm: userVms) {
|
||||
if (vm.getGuestIpAddress() != null) {
|
||||
usedIps.add(NetUtils.ip2Long(vm.getGuestIpAddress()));
|
||||
}
|
||||
}
|
||||
if (usedIps.size() != 0) {
|
||||
allPossibleIps.removeAll(usedIps);
|
||||
}
|
||||
if (allPossibleIps.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
Iterator<Long> iterator = allPossibleIps.iterator();
|
||||
long ipAddress = iterator.next().longValue();
|
||||
String ipAddressStr = NetUtils.long2Ip(ipAddress);
|
||||
userVm.setGuestIpAddress(ipAddressStr);
|
||||
userVm.setGuestNetmask(router.getGuestNetmask());
|
||||
String vmMacAddress = NetUtils.long2Mac(
|
||||
(NetUtils.mac2Long(router.getGuestMacAddress()) & 0xffffffff0000L) | (ipAddress & 0xffff)
|
||||
);
|
||||
userVm.setGuestMacAddress(vmMacAddress);
|
||||
_vmDao.update(userVm.getId(), userVm);
|
||||
txn.commit();
|
||||
if (routerLock) {
|
||||
_routerDao.releaseFromLockTable(routerId);
|
||||
routerLock = false;
|
||||
}
|
||||
return ipAddressStr;
|
||||
}finally {
|
||||
if (routerLock) {
|
||||
_routerDao.releaseFromLockTable(routerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void releaseGuestIpAddress(UserVmVO userVm) {
|
||||
ServiceOffering offering = _offeringDao.findById(userVm.getServiceOfferingId());
|
||||
@ -1118,9 +1057,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
||||
_defaultNetworkDomain = "." + _defaultNetworkDomain;
|
||||
}
|
||||
|
||||
String value = configs.get("start.retry");
|
||||
_retry = NumbersUtil.parseInt(value, 2);
|
||||
|
||||
_instance = configs.get("instance.name");
|
||||
if (_instance == null) {
|
||||
_instance = "DEFAULT";
|
||||
@ -1135,10 +1071,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
||||
time = configs.get("expunge.delay");
|
||||
_expungeDelay = NumbersUtil.parseInt(time, _expungeInterval);
|
||||
|
||||
String maxCap = configs.get("cpu.uservm.cap");
|
||||
_userVMCap = NumbersUtil.parseInt(maxCap, 0);
|
||||
|
||||
|
||||
_executor = Executors.newScheduledThreadPool(wrks, new NamedThreadFactory("UserVm-Scavenger"));
|
||||
|
||||
_haMgr.registerHandler(Type.User, this);
|
||||
@ -1776,8 +1708,9 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
||||
privateTemplate.setFormat(ImageFormat.RAW);
|
||||
}
|
||||
|
||||
if(snapshot != null)
|
||||
privateTemplate.setHypervisorType(snapshot.getHypervisorType());
|
||||
if(snapshot != null) {
|
||||
privateTemplate.setHypervisorType(snapshot.getHypervisorType());
|
||||
}
|
||||
|
||||
_templateDao.update(templateId, privateTemplate);
|
||||
|
||||
|
||||
@ -49,8 +49,6 @@ import com.cloud.deploy.DeploymentPlanner;
|
||||
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.event.EventUtils;
|
||||
import com.cloud.event.EventVO;
|
||||
import com.cloud.event.UsageEventVO;
|
||||
import com.cloud.event.dao.UsageEventDao;
|
||||
import com.cloud.exception.AgentUnavailableException;
|
||||
@ -253,6 +251,12 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Cluster
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!this.advanceStop(vm, caller, account)) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Unable to stop the VM so we can't expunge it.");
|
||||
}
|
||||
}
|
||||
|
||||
if (!stateTransitTo(vm, VirtualMachine.Event.ExpungeOperation, vm.getHostId())) {
|
||||
s_logger.debug("Unable to destroy the vm because it is not in the correct state: " + vm.toString());
|
||||
@ -262,16 +266,6 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Cluster
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Destroying vm " + vm);
|
||||
}
|
||||
long userId = caller.getId();
|
||||
long startEventId = EventUtils.saveStartedEvent(userId, vm.getAccountId(), EventTypes.EVENT_VM_STOP, "stopping Vm with Id: "+vm.getId());
|
||||
|
||||
if (!stop(vm, caller, account)) {
|
||||
s_logger.error("Unable to stop vm so we can't destroy it: " + vm);
|
||||
EventUtils.saveEvent(userId, vm.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_STOP, "Error stopping VM instance : " + vm.getId(), startEventId);
|
||||
return false;
|
||||
} else {
|
||||
EventUtils.saveEvent(userId, vm.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_VM_STOP, "Successfully stopped VM instance : " + vm.getId(), startEventId);
|
||||
}
|
||||
|
||||
VirtualMachineProfile<T> profile = new VirtualMachineProfileImpl<T>(vm);
|
||||
|
||||
@ -279,15 +273,8 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Cluster
|
||||
//Clean up volumes based on the vm's instance id
|
||||
_storageMgr.cleanupVolumes(vm.getId());
|
||||
|
||||
VirtualMachineGuru<T> guru = getVmGuru(vm);
|
||||
vm = guru.findById(vm.getId());
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Destroying vm " + vm);
|
||||
}
|
||||
if (!stateTransitTo(vm, VirtualMachine.Event.DestroyRequested, vm.getHostId())) {
|
||||
s_logger.debug("Unable to destroy the vm because it is not in the correct state: " + vm.toString());
|
||||
return false;
|
||||
s_logger.debug("Expunged " + vm);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -499,7 +486,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Cluster
|
||||
}
|
||||
|
||||
if (state == State.Creating || state == State.Destroyed || state == State.Expunging || state == State.Error) {
|
||||
s_logger.warn("Stopped called on " + vm.toString() + " but the state is " + state.toString());
|
||||
s_logger.debug("Stopped called on " + vm + " but the state is " + state);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user