@@ -390,15 +390,27 @@ public Snapshot revertSnapshot(Long snapshotId) {
390
390
391
391
boolean result = snapshotStrategy .revertSnapshot (snapshotInfo );
392
392
if (result ) {
393
- // update volume size and primary storage count
394
- _resourceLimitMgr .decrementResourceCount (snapshot .getAccountId (), ResourceType .primary_storage , new Long (volume .getSize () - snapshot .getSize ()));
395
- volume .setSize (snapshot .getSize ());
396
- _volsDao .update (volume .getId (), volume );
393
+ updateVolumeSizeAndPrimaryStorageCount (volume , snapshot );
397
394
return snapshotInfo ;
398
395
}
399
396
return null ;
400
397
}
401
398
399
+ public void updateVolumeSizeAndPrimaryStorageCount (VolumeVO volume , SnapshotVO snapshot ) {
400
+ Long differenceBetweenVolumeAndSnapshotSize = new Long (volume .getSize () - snapshot .getSize ());
401
+ if (differenceBetweenVolumeAndSnapshotSize != 0 ) {
402
+ if (differenceBetweenVolumeAndSnapshotSize > 0 ) {
403
+ _resourceLimitMgr .decrementResourceCount (snapshot .getAccountId (), ResourceType .primary_storage , differenceBetweenVolumeAndSnapshotSize );
404
+ } else if (differenceBetweenVolumeAndSnapshotSize < 0 ) {
405
+ _resourceLimitMgr .incrementResourceCount (snapshot .getAccountId (), ResourceType .primary_storage , differenceBetweenVolumeAndSnapshotSize * -1L );
406
+ }
407
+ volume .setSize (snapshot .getSize ());
408
+ _volsDao .update (volume .getId (), volume );
409
+ UsageEventUtils .publishUsageEvent (EventTypes .EVENT_VOLUME_RESIZE , volume .getAccountId (), volume .getDataCenterId (), volume .getId (), volume .getName (),
410
+ volume .getDiskOfferingId (), volume .getTemplateId (), volume .getSize (), Volume .class .getName (), volume .getUuid ());
411
+ }
412
+ }
413
+
402
414
@ Override
403
415
@ ActionEvent (eventType = EventTypes .EVENT_SNAPSHOT_POLICY_UPDATE , eventDescription = "updating snapshot policy" , async = true )
404
416
public SnapshotPolicy updateSnapshotPolicy (UpdateSnapshotPolicyCmd cmd ) {
@@ -805,7 +817,7 @@ public boolean deleteSnapshot(long snapshotId, Long zoneId) {
805
817
806
818
return result ;
807
819
} catch (Exception e ) {
808
- logger .debug ("Failed to delete snapshot {}:{}" , snapshotCheck , e .toString ());
820
+ logger .debug ("Failed to delete snapshot {}:{}" , snapshotCheck . getId () , e .toString ());
809
821
810
822
throw new CloudRuntimeException ("Failed to delete snapshot:" + e .toString ());
811
823
}
0 commit comments