mirror of https://github.com/apache/cloudstack.git
made some changes to the vm expunge flow, also added a state transition to error for vm if creation fails
This commit is contained in:
parent
b9af2d4e7c
commit
6b1e4d92ef
|
|
@ -281,4 +281,6 @@ public interface StorageManager extends Manager {
|
|||
//void release(VirtualMachineProfile<? extends VirtualMachine> vm);
|
||||
|
||||
void release(VirtualMachineProfile<? extends VMInstanceVO> profile);
|
||||
|
||||
void cleanupVolumes(Long vmId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2878,10 +2878,13 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
|||
|
||||
@Override
|
||||
public void release(VirtualMachineProfile<? extends VMInstanceVO> profile) {
|
||||
//Clean up volumes based on the profile's instance id
|
||||
List<VolumeVO> volumesForProfile = _volsDao.findByInstance(profile.getId());
|
||||
|
||||
for(VolumeVO vol : volumesForProfile){
|
||||
//add code here
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanupVolumes(Long vmId){
|
||||
List<VolumeVO> volumesForVm = _volsDao.findByInstance(vmId);
|
||||
for(VolumeVO vol : volumesForVm){
|
||||
destroyVolume(vol);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1979,7 +1979,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
private void updateVmStateForFailedVmCreation(Long vmId) {
|
||||
UserVmVO vm = _vmDao.findById(vmId);
|
||||
if(vm != null){
|
||||
if(vm.getState().equals(State.Creating)){
|
||||
if(vm.getState().equals(State.Stopped)){
|
||||
_itMgr.stateTransitTo(vm, VirtualMachine.Event.OperationFailed, null);
|
||||
}
|
||||
}
|
||||
|
|
@ -2519,12 +2519,9 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
UserVmVO vm = new UserVmVO(id, instanceName, cmd.getDisplayName(),
|
||||
template.getId(), template.getGuestOSId(), offering.getOfferHA(), domainId, owner.getId(), offering.getId(), userData, hostName);
|
||||
|
||||
try{
|
||||
if (_itMgr.allocate(vm, template, offering, rootDiskOffering, dataDiskOfferings, networks, null, plan, cmd.getHypervisor(), owner) == null) {
|
||||
return null;
|
||||
}
|
||||
}finally{
|
||||
updateVmStateForFailedVmCreation(id);
|
||||
|
||||
if (_itMgr.allocate(vm, template, offering, rootDiskOffering, dataDiskOfferings, networks, null, plan, cmd.getHypervisor(), owner) == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
|
|
@ -2556,8 +2553,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
|
||||
AccountVO owner = _accountDao.findById(vm.getAccountId());
|
||||
|
||||
vm = _itMgr.start(vm, null, caller, owner, cmd.getHypervisor());
|
||||
vm.setPassword(password);
|
||||
try {
|
||||
vm = _itMgr.start(vm, null, caller, owner, cmd.getHypervisor());
|
||||
} finally {
|
||||
updateVmStateForFailedVmCreation(vm.getId());
|
||||
}
|
||||
vm.setPassword(password);
|
||||
return vm;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ import com.cloud.storage.DiskOfferingVO;
|
|||
import com.cloud.storage.Storage.ImageFormat;
|
||||
import com.cloud.storage.StorageManager;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.VolumeVO;
|
||||
import com.cloud.storage.Volume.VolumeType;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.user.Account;
|
||||
|
|
@ -257,6 +258,9 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Cluster
|
|||
return false;
|
||||
}
|
||||
|
||||
//Clean up volumes based on the vm's instance id
|
||||
_storageMgr.cleanupVolumes(vm.getId());
|
||||
|
||||
VirtualMachineGuru<T> guru = getVmGuru(vm);
|
||||
vm = guru.findById(vm.getId());
|
||||
|
||||
|
|
@ -569,6 +573,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Cluster
|
|||
_stateMachine.addTransition(State.Stopped, VirtualMachine.Event.DestroyRequested, State.Destroyed);
|
||||
_stateMachine.addTransition(State.Stopped, VirtualMachine.Event.StopRequested, State.Stopped);
|
||||
_stateMachine.addTransition(State.Stopped, VirtualMachine.Event.AgentReportStopped, State.Stopped);
|
||||
_stateMachine.addTransition(State.Stopped, VirtualMachine.Event.OperationFailed, State.Error);
|
||||
_stateMachine.addTransition(State.Starting, VirtualMachine.Event.OperationRetry, State.Starting);
|
||||
_stateMachine.addTransition(State.Starting, VirtualMachine.Event.OperationSucceeded, State.Running);
|
||||
_stateMachine.addTransition(State.Starting, VirtualMachine.Event.OperationFailed, State.Stopped);
|
||||
|
|
|
|||
Loading…
Reference in New Issue