This is an automated email from the ASF dual-hosted git repository.
dahn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/main by this push:
new b2b2218a8ab Launch RESIZE event on volume snapshot revert (#10482)
b2b2218a8ab is described below
commit b2b2218a8abf750c92a31bd89078d96b5c65159e
Author: julien-vaz <[email protected]>
AuthorDate: Tue Apr 15 04:49:53 2025 -0300
Launch RESIZE event on volume snapshot revert (#10482)
Co-authored-by: Julien Hervot de Mattos Vaz <[email protected]>
Co-authored-by: dahn <[email protected]>
---
.../storage/snapshot/SnapshotManagerImpl.java | 22 +++++++++++++++++-----
.../storage/snapshot/SnapshotManagerTest.java | 2 --
.../test/java/com/cloud/utils/UriUtilsTest.java | 4 ++--
3 files changed, 19 insertions(+), 9 deletions(-)
diff --git
a/server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java
b/server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java
index 572e0ace723..ca2676f8dc4 100755
--- a/server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java
+++ b/server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java
@@ -390,15 +390,27 @@ public class SnapshotManagerImpl extends
MutualExclusiveIdsManagerBase implement
boolean result = snapshotStrategy.revertSnapshot(snapshotInfo);
if (result) {
- // update volume size and primary storage count
- _resourceLimitMgr.decrementResourceCount(snapshot.getAccountId(),
ResourceType.primary_storage, new Long(volume.getSize() - snapshot.getSize()));
- volume.setSize(snapshot.getSize());
- _volsDao.update(volume.getId(), volume);
+ updateVolumeSizeAndPrimaryStorageCount(volume, snapshot);
return snapshotInfo;
}
return null;
}
+ public void updateVolumeSizeAndPrimaryStorageCount(VolumeVO volume,
SnapshotVO snapshot) {
+ Long differenceBetweenVolumeAndSnapshotSize = new
Long(volume.getSize() - snapshot.getSize());
+ if (differenceBetweenVolumeAndSnapshotSize != 0) {
+ if (differenceBetweenVolumeAndSnapshotSize > 0) {
+
_resourceLimitMgr.decrementResourceCount(snapshot.getAccountId(),
ResourceType.primary_storage, differenceBetweenVolumeAndSnapshotSize);
+ } else if (differenceBetweenVolumeAndSnapshotSize < 0) {
+
_resourceLimitMgr.incrementResourceCount(snapshot.getAccountId(),
ResourceType.primary_storage, differenceBetweenVolumeAndSnapshotSize * -1L);
+ }
+ volume.setSize(snapshot.getSize());
+ _volsDao.update(volume.getId(), volume);
+ UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_RESIZE,
volume.getAccountId(), volume.getDataCenterId(), volume.getId(),
volume.getName(),
+ volume.getDiskOfferingId(), volume.getTemplateId(),
volume.getSize(), Volume.class.getName(), volume.getUuid());
+ }
+ }
+
@Override
@ActionEvent(eventType = EventTypes.EVENT_SNAPSHOT_POLICY_UPDATE,
eventDescription = "updating snapshot policy", async = true)
public SnapshotPolicy updateSnapshotPolicy(UpdateSnapshotPolicyCmd cmd) {
@@ -805,7 +817,7 @@ public class SnapshotManagerImpl extends
MutualExclusiveIdsManagerBase implement
return result;
} catch (Exception e) {
- logger.debug("Failed to delete snapshot {}:{}", snapshotCheck,
e.toString());
+ logger.debug("Failed to delete snapshot {}:{}",
snapshotCheck.getId(), e.toString());
throw new CloudRuntimeException("Failed to delete snapshot:" +
e.toString());
}
diff --git
a/server/src/test/java/com/cloud/storage/snapshot/SnapshotManagerTest.java
b/server/src/test/java/com/cloud/storage/snapshot/SnapshotManagerTest.java
index 28903c72cc3..4ccc6e99961 100755
--- a/server/src/test/java/com/cloud/storage/snapshot/SnapshotManagerTest.java
+++ b/server/src/test/java/com/cloud/storage/snapshot/SnapshotManagerTest.java
@@ -235,7 +235,6 @@ public class SnapshotManagerTest {
doNothing().when(_resourceLimitMgr).checkResourceLimit(any(Account.class),
any(ResourceType.class));
doNothing().when(_resourceLimitMgr).checkResourceLimit(any(Account.class),
any(ResourceType.class), anyLong());
- doNothing().when(_resourceLimitMgr).decrementResourceCount(anyLong(),
any(ResourceType.class), anyLong());
doNothing().when(_resourceLimitMgr).incrementResourceCount(anyLong(),
any(ResourceType.class));
doNothing().when(_resourceLimitMgr).incrementResourceCount(anyLong(),
any(ResourceType.class), anyLong());
@@ -352,7 +351,6 @@ public class SnapshotManagerTest {
when(_vmDao.findById(anyLong())).thenReturn(vmMock);
when(vmMock.getState()).thenReturn(State.Stopped);
when
(snapshotStrategy.revertSnapshot(any(SnapshotInfo.class))).thenReturn(true);
- when(_volumeDao.update(anyLong(),
any(VolumeVO.class))).thenReturn(true);
doReturn(DataStoreRole.Image).when(snapshotHelperMock).getDataStoreRole(any());
Snapshot snapshot = _snapshotMgr.revertSnapshot(TEST_SNAPSHOT_ID);
Assert.assertNotNull(snapshot);
diff --git a/utils/src/test/java/com/cloud/utils/UriUtilsTest.java
b/utils/src/test/java/com/cloud/utils/UriUtilsTest.java
index 04a74289122..47fd389e3ae 100644
--- a/utils/src/test/java/com/cloud/utils/UriUtilsTest.java
+++ b/utils/src/test/java/com/cloud/utils/UriUtilsTest.java
@@ -276,8 +276,8 @@ public class UriUtilsTest {
@Test
public void validateUrl() {
- Pair<String, Integer> url1 =
UriUtils.validateUrl("https://www.cloudstack.org");
- Assert.assertEquals(url1.first(), "www.cloudstack.org");
+ Pair<String, Integer> url1 =
UriUtils.validateUrl("https://cloudstack.apache.org/");
+ Assert.assertEquals(url1.first(), "cloudstack.apache.org");
Pair<String, Integer> url2 =
UriUtils.validateUrl("https://www.apache.org");
Assert.assertEquals(url2.first(), "www.apache.org");