Skip to content

Commit b2b2218

Browse files
julien-vazJulien Hervot de Mattos VazDaanHoogland
authored
Launch RESIZE event on volume snapshot revert (#10482)
Co-authored-by: Julien Hervot de Mattos Vaz <[email protected]> Co-authored-by: dahn <[email protected]>
1 parent 4d572fa commit b2b2218

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

Diff for: server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java

+17-5
Original file line numberDiff line numberDiff line change
@@ -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
}

Diff for: server/src/test/java/com/cloud/storage/snapshot/SnapshotManagerTest.java

-2
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ public void setup() throws ResourceAllocationException {
235235

236236
doNothing().when(_resourceLimitMgr).checkResourceLimit(any(Account.class), any(ResourceType.class));
237237
doNothing().when(_resourceLimitMgr).checkResourceLimit(any(Account.class), any(ResourceType.class), anyLong());
238-
doNothing().when(_resourceLimitMgr).decrementResourceCount(anyLong(), any(ResourceType.class), anyLong());
239238
doNothing().when(_resourceLimitMgr).incrementResourceCount(anyLong(), any(ResourceType.class));
240239
doNothing().when(_resourceLimitMgr).incrementResourceCount(anyLong(), any(ResourceType.class), anyLong());
241240

@@ -352,7 +351,6 @@ public void testRevertSnapshotF3() {
352351
when(_vmDao.findById(anyLong())).thenReturn(vmMock);
353352
when(vmMock.getState()).thenReturn(State.Stopped);
354353
when (snapshotStrategy.revertSnapshot(any(SnapshotInfo.class))).thenReturn(true);
355-
when(_volumeDao.update(anyLong(), any(VolumeVO.class))).thenReturn(true);
356354
doReturn(DataStoreRole.Image).when(snapshotHelperMock).getDataStoreRole(any());
357355
Snapshot snapshot = _snapshotMgr.revertSnapshot(TEST_SNAPSHOT_ID);
358356
Assert.assertNotNull(snapshot);

Diff for: utils/src/test/java/com/cloud/utils/UriUtilsTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ public void testIsUrlForCompressedFile() {
276276

277277
@Test
278278
public void validateUrl() {
279-
Pair<String, Integer> url1 = UriUtils.validateUrl("https://www.cloudstack.org");
280-
Assert.assertEquals(url1.first(), "www.cloudstack.org");
279+
Pair<String, Integer> url1 = UriUtils.validateUrl("https://cloudstack.apache.org/");
280+
Assert.assertEquals(url1.first(), "cloudstack.apache.org");
281281

282282
Pair<String, Integer> url2 = UriUtils.validateUrl("https://www.apache.org");
283283
Assert.assertEquals(url2.first(), "www.apache.org");

0 commit comments

Comments
 (0)