mirror of https://github.com/apache/cloudstack.git
bug 7952, 8363: Fixed usage events for Vm destroy and recover
status 7952, 8363: resolved fixed
This commit is contained in:
parent
310f0d0c51
commit
00c67f6b38
|
|
@ -1536,12 +1536,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
|||
_volsDao.update(volume, Volume.Event.Destroy);
|
||||
long volumeId = volume.getId();
|
||||
|
||||
if(volume.getPoolId() != null){
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_DELETE, volume.getAccountId(), volume.getDataCenterId(), volumeId,
|
||||
volume.getName(), null, null, null);
|
||||
_usageEventDao.persist(usageEvent);
|
||||
}
|
||||
|
||||
// Delete the recurring snapshot policies for this volume.
|
||||
_snapshotMgr.deletePoliciesForVolume(volumeId);
|
||||
|
||||
|
|
@ -2236,6 +2230,9 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
|||
// Check that the volume is not already destroyed
|
||||
if (volume.getState() != Volume.State.Destroy) {
|
||||
destroyVolume(volume);
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_DELETE, volume.getAccountId(), volume.getDataCenterId(), volumeId,
|
||||
volume.getName(), null, null, null);
|
||||
_usageEventDao.persist(usageEvent);
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
@ -2607,8 +2604,15 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
|||
for (VolumeVO vol : volumesForVm) {
|
||||
if (vol.getVolumeType().equals(VolumeType.ROOT)) {
|
||||
//This check is for VM in Error state (volume is already destroyed)
|
||||
if(!vol.getState().equals(Volume.State.Destroy))
|
||||
if(!vol.getState().equals(Volume.State.Destroy)){
|
||||
destroyVolume(vol);
|
||||
VMInstanceVO vm = _vmInstanceDao.findById(vmId);
|
||||
if(vm.getType() == VirtualMachine.Type.User){
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_DELETE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(),
|
||||
vol.getName(), null, null, null);
|
||||
_usageEventDao.persist(usageEvent);
|
||||
}
|
||||
}
|
||||
toBeExpunged.add(vol);
|
||||
} else {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
|
|
|
|||
|
|
@ -58,6 +58,9 @@ import com.cloud.configuration.dao.ResourceLimitDao;
|
|||
import com.cloud.domain.Domain;
|
||||
import com.cloud.domain.DomainVO;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.event.UsageEventVO;
|
||||
import com.cloud.event.dao.UsageEventDao;
|
||||
import com.cloud.exception.AgentUnavailableException;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
|
|
@ -131,6 +134,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
|||
@Inject private TemplateManager _tmpltMgr;
|
||||
@Inject private ConfigurationManager _configMgr;
|
||||
@Inject private VirtualMachineManager _itMgr;
|
||||
@Inject private UsageEventDao _usageEventDao;
|
||||
|
||||
private final ScheduledExecutorService _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("AccountChecker"));
|
||||
|
||||
|
|
@ -852,6 +856,8 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
|||
s_logger.error("Unable to destroy vm: " + vm.getId());
|
||||
accountCleanupNeeded = true;
|
||||
}
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_DESTROY, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), vm.getName(), vm.getServiceOfferingId(), vm.getTemplateId(), null);
|
||||
_usageEventDao.persist(usageEvent);
|
||||
}
|
||||
|
||||
// Mark the account's volumes as destroyed
|
||||
|
|
@ -859,6 +865,11 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
|||
for (VolumeVO volume : volumes) {
|
||||
if(!volume.getState().equals(Volume.State.Destroy)) {
|
||||
_storageMgr.destroyVolume(volume);
|
||||
if(volume.getPoolId() != null){
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_DELETE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(),
|
||||
volume.getName(), null, null, null);
|
||||
_usageEventDao.persist(usageEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ import com.cloud.api.commands.ResetVMPasswordCmd;
|
|||
import com.cloud.api.commands.StartVMCmd;
|
||||
import com.cloud.api.commands.UpdateVMCmd;
|
||||
import com.cloud.api.commands.UpgradeVMCmd;
|
||||
import com.cloud.async.AsyncInstanceCreateStatus;
|
||||
import com.cloud.async.AsyncJobExecutor;
|
||||
import com.cloud.async.AsyncJobManager;
|
||||
import com.cloud.async.AsyncJobVO;
|
||||
|
|
@ -1011,20 +1012,22 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
}
|
||||
|
||||
// Recover the VM's disks
|
||||
List<VolumeVO> volumes = _volsDao.findByInstanceIdDestroyed(vmId);
|
||||
List<VolumeVO> volumes = _volsDao.findByInstance(vmId);
|
||||
for (VolumeVO volume : volumes) {
|
||||
// Create an event
|
||||
Long templateId = volume.getTemplateId();
|
||||
Long diskOfferingId = volume.getDiskOfferingId();
|
||||
Long offeringId = null;
|
||||
if(diskOfferingId != null){
|
||||
DiskOfferingVO offering = _diskOfferingDao.findById(diskOfferingId);
|
||||
if(offering!=null && (offering.getType() == DiskOfferingVO.Type.Disk)){
|
||||
offeringId = offering.getId();
|
||||
if (volume.getVolumeType().equals(VolumeType.ROOT)) {
|
||||
// Create an event
|
||||
Long templateId = volume.getTemplateId();
|
||||
Long diskOfferingId = volume.getDiskOfferingId();
|
||||
Long offeringId = null;
|
||||
if(diskOfferingId != null){
|
||||
DiskOfferingVO offering = _diskOfferingDao.findById(diskOfferingId);
|
||||
if(offering!=null && (offering.getType() == DiskOfferingVO.Type.Disk)){
|
||||
offeringId = offering.getId();
|
||||
}
|
||||
}
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), offeringId, templateId , volume.getSize());
|
||||
_usageEventDao.persist(usageEvent);
|
||||
}
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), offeringId, templateId , volume.getSize());
|
||||
_usageEventDao.persist(usageEvent);
|
||||
}
|
||||
|
||||
_accountMgr.incrementResourceCount(account.getId(), ResourceType.volume, new Long(volumes.size()));
|
||||
|
|
@ -1477,6 +1480,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
for(VolumeVO volume : volumesForThisVm) {
|
||||
try {
|
||||
_storageMgr.destroyVolume(volume);
|
||||
if ((volume.getStatus() == AsyncInstanceCreateStatus.Created) && (volume.getVolumeType().equals(VolumeType.ROOT))) {
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_DELETE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(),
|
||||
volume.getName(), null, null, null);
|
||||
_usageEventDao.persist(usageEvent);
|
||||
}
|
||||
} catch (ConcurrentOperationException e) {
|
||||
s_logger.warn("Unable to delete volume:"+volume.getId()+" for vm:"+vmId+" whilst transitioning to error state");
|
||||
}
|
||||
|
|
@ -2338,6 +2346,15 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
}
|
||||
|
||||
if (status) {
|
||||
// Mark the account's volumes as destroyed
|
||||
List<VolumeVO> volumes = _volsDao.findByInstance(vmId);
|
||||
for (VolumeVO volume : volumes) {
|
||||
if (volume.getVolumeType().equals(VolumeType.ROOT)) {
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_DELETE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(),
|
||||
volume.getName(), null, null, null);
|
||||
_usageEventDao.persist(usageEvent);
|
||||
}
|
||||
}
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_DESTROY, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), vm.getName(), vm.getServiceOfferingId(), vm.getTemplateId(), null);
|
||||
_usageEventDao.persist(usageEvent);
|
||||
_accountMgr.decrementResourceCount(vm.getAccountId(), ResourceType.user_vm);
|
||||
|
|
|
|||
|
|
@ -405,10 +405,6 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, StateLi
|
|||
s_logger.debug("Expunged " + vm);
|
||||
}
|
||||
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_DESTROY, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), vm.getName(), vm.getServiceOfferingId(), vm.getTemplateId(), null);
|
||||
_usageEventDao.persist(usageEvent);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue