@@ -8208,18 +8208,22 @@ private void postProcessingUnmanageVM(UserVmVO vm) {
82088208 Long cpu = offering .getCpu () != null ? new Long (offering .getCpu ()) : 0L ;
82098209 Long ram = offering .getRamSize () != null ? new Long (offering .getRamSize ()) : 0L ;
82108210 // First generate a VM stop event if the VM was not stopped already
8211+ boolean resourceCountNotDecremented = true ;
82118212 if (vm .getState () != State .Stopped ) {
82128213 UsageEventUtils .publishUsageEvent (EventTypes .EVENT_VM_STOP , vm .getAccountId (), vm .getDataCenterId (),
82138214 vm .getId (), vm .getHostName (), vm .getServiceOfferingId (), vm .getTemplateId (),
82148215 vm .getHypervisorType ().toString (), VirtualMachine .class .getName (), vm .getUuid (), vm .isDisplayVm ());
82158216 resourceCountDecrement (vm .getAccountId (), vm .isDisplayVm (), cpu , ram );
8217+ resourceCountNotDecremented = false ;
82168218 }
82178219
82188220 // VM destroy usage event
82198221 UsageEventUtils .publishUsageEvent (EventTypes .EVENT_VM_DESTROY , vm .getAccountId (), vm .getDataCenterId (),
82208222 vm .getId (), vm .getHostName (), vm .getServiceOfferingId (), vm .getTemplateId (),
82218223 vm .getHypervisorType ().toString (), VirtualMachine .class .getName (), vm .getUuid (), vm .isDisplayVm ());
8222- resourceCountDecrement (vm .getAccountId (), vm .isDisplayVm (), cpu , ram );
8224+ if (resourceCountNotDecremented ) {
8225+ resourceCountDecrement (vm .getAccountId (), vm .isDisplayVm (), cpu , ram );
8226+ }
82238227 }
82248228
82258229 /*
0 commit comments