@@ -390,15 +390,27 @@ public Snapshot revertSnapshot(Long snapshotId) {
390390
391391 boolean result = snapshotStrategy .revertSnapshot (snapshotInfo );
392392 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 );
397394 return snapshotInfo ;
398395 }
399396 return null ;
400397 }
401398
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+
402414 @ Override
403415 @ ActionEvent (eventType = EventTypes .EVENT_SNAPSHOT_POLICY_UPDATE , eventDescription = "updating snapshot policy" , async = true )
404416 public SnapshotPolicy updateSnapshotPolicy (UpdateSnapshotPolicyCmd cmd ) {
@@ -805,7 +817,7 @@ public boolean deleteSnapshot(long snapshotId, Long zoneId) {
805817
806818 return result ;
807819 } catch (Exception e ) {
808- logger .debug ("Failed to delete snapshot {}:{}" , snapshotCheck , e .toString ());
820+ logger .debug ("Failed to delete snapshot {}:{}" , snapshotCheck . getId () , e .toString ());
809821
810822 throw new CloudRuntimeException ("Failed to delete snapshot:" + e .toString ());
811823 }
0 commit comments