Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.4k
Support of snapshot copy to primary storage in different zones.#9478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sureshanaparti
merged 15 commits into
apache:main
from
storpool:support-snapshot-copy-on-primaryAug 4, 2025
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
209e9fc
Support of snapshot copy to different StorPool primary storage betwee…
slavkap 6c1f2cc
added option in the UI for the storage pools
slavkap baa2f93
Addressed comments
slavkap 39923f4
Address reviews
slavkap 8496965
fix snapshot deletion
slavkap f720b47
Address comments and fix conflicts
slavkap e06de93
small rearranges
slavkap bc27420
removed unused imports
slavkap 2e416af
hide the primary storage when a user copies the snapshots
slavkap f33b615
hide the primary storage from users in UI
slavkap 81529e4
Addressed reviews
slavkap a0bd3c1
Fix of publish event for deleted snapshot
slavkap 6ebfd7d
small fixes
slavkap 68ddc6d
Added pool type to volumes created from snapshots
slavkap 6668140
allocate snapshot if the storage allows copy
slavkap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4 api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 45 additions & 14 deletions
59 api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CopySnapshotCmd.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -17,9 +17,13 @@ | ||
| package org.apache.cloudstack.api.command.user.snapshot; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import com.cloud.dc.DataCenter; | ||
| import com.cloud.event.EventTypes; | ||
| import com.cloud.exception.ResourceAllocationException; | ||
| import com.cloud.exception.ResourceUnavailableException; | ||
| import com.cloud.exception.StorageUnavailableException; | ||
| import com.cloud.storage.Snapshot; | ||
| import com.cloud.user.Account; | ||
| import org.apache.cloudstack.acl.RoleType; | ||
| import org.apache.cloudstack.api.APICommand; | ||
| import org.apache.cloudstack.api.ApiCommandResourceType; | ||
| @@ -31,26 +35,24 @@ | ||
| import org.apache.cloudstack.api.ServerApiException; | ||
| import org.apache.cloudstack.api.command.user.UserCmd; | ||
| import org.apache.cloudstack.api.response.SnapshotResponse; | ||
| import org.apache.cloudstack.api.response.StoragePoolResponse; | ||
| import org.apache.cloudstack.api.response.ZoneResponse; | ||
| import org.apache.cloudstack.context.CallContext; | ||
| import org.apache.commons.collections.CollectionUtils; | ||
| import com.cloud.dc.DataCenter; | ||
| import com.cloud.event.EventTypes; | ||
| import com.cloud.exception.ResourceAllocationException; | ||
| import com.cloud.exception.ResourceUnavailableException; | ||
| import com.cloud.exception.StorageUnavailableException; | ||
| import com.cloud.storage.Snapshot; | ||
| import com.cloud.user.Account; | ||
| import org.apache.commons.lang3.BooleanUtils; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| @APICommand(name = "copySnapshot", description = "Copies a snapshot from one zone to another.", | ||
| responseObject = SnapshotResponse.class, responseView = ResponseObject.ResponseView.Restricted, | ||
| requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.19.0", | ||
| authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) | ||
| public class CopySnapshotCmd extends BaseAsyncCmd implements UserCmd { | ||
| public static final Logger logger = LogManager.getLogger(CopySnapshotCmd.class.getName()); | ||
| private Snapshot snapshot; | ||
| ///////////////////////////////////////////////////// | ||
| //////////////// API parameters ///////////////////// | ||
| @@ -84,6 +86,20 @@ public class CopySnapshotCmd extends BaseAsyncCmd implements UserCmd { | ||
| "Do not specify destzoneid and destzoneids together, however one of them is required.") | ||
| protected List<Long> destZoneIds; | ||
| @Parameter(name = ApiConstants.STORAGE_ID_LIST, | ||
| type=CommandType.LIST, | ||
| collectionType = CommandType.UUID, | ||
| entityType = StoragePoolResponse.class, | ||
| required = false, | ||
| authorized = RoleType.Admin, | ||
| since = "4.21.0", | ||
| description = "A comma-separated list of IDs of the storage pools in other zones in which the snapshot will be made available. " + | ||
slavkap marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| "The snapshot will always be made available in the zone in which the volume is present. Currently supported for StorPool only") | ||
| protected List<Long> storagePoolIds; | ||
| @Parameter (name = ApiConstants.USE_STORAGE_REPLICATION, type=CommandType.BOOLEAN, required = false, since = "4.21.0", description = "This parameter enables the option the snapshot to be copied to supported primary storage") | ||
| protected Boolean useStorageReplication; | ||
| ///////////////////////////////////////////////////// | ||
| /////////////////// Accessors /////////////////////// | ||
| ///////////////////////////////////////////////////// | ||
| @@ -106,7 +122,15 @@ public List<Long> getDestinationZoneIds() { | ||
| destIds.add(destZoneId); | ||
| return destIds; | ||
| } | ||
| return null; | ||
| return new ArrayList<>(); | ||
| } | ||
| public List<Long> getStoragePoolIds() { | ||
| return storagePoolIds; | ||
| } | ||
| public Boolean useStorageReplication() { | ||
| return BooleanUtils.toBoolean(useStorageReplication); | ||
| } | ||
| @Override | ||
| @@ -152,7 +176,7 @@ public long getEntityOwnerId() { | ||
| @Override | ||
| public void execute() throws ResourceUnavailableException { | ||
| try { | ||
| if (destZoneId == null && CollectionUtils.isEmpty(destZoneIds)) | ||
| if (destZoneId == null && CollectionUtils.isEmpty(destZoneIds) && useStorageReplication()) | ||
| throw new ServerApiException(ApiErrorCode.PARAM_ERROR, | ||
| "Either destzoneid or destzoneids parameters have to be specified."); | ||
| @@ -161,7 +185,7 @@ public void execute() throws ResourceUnavailableException { | ||
| "Both destzoneid and destzoneids cannot be specified at the same time."); | ||
| CallContext.current().setEventDetails(getEventDescription()); | ||
| Snapshot snapshot = _snapshotService.copySnapshot(this); | ||
| snapshot = _snapshotService.copySnapshot(this); | ||
| if (snapshot != null) { | ||
| SnapshotResponse response = _queryService.listSnapshot(this); | ||
| @@ -177,6 +201,13 @@ public void execute() throws ResourceUnavailableException { | ||
| logger.warn("Exception: ", ex); | ||
| throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage()); | ||
| } | ||
| } | ||
| public Snapshot getSnapshot() { | ||
| return snapshot; | ||
| } | ||
| public void setSnapshot(Snapshot snapshot) { | ||
| this.snapshot = snapshot; | ||
| } | ||
| } | ||
33 changes: 30 additions & 3 deletions
33 api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotCmd.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 32 additions & 11 deletions
43 ...rc/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotPolicyCmd.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 12 additions & 6 deletions
18 api/src/main/java/org/apache/cloudstack/api/response/SnapshotPolicyResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4 api/src/test/java/org/apache/cloudstack/api/command/test/CreateSnapshotCmdTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5 api/src/test/java/org/apache/cloudstack/api/command/user/snapshot/CopySnapshotCmdTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.