forked from apache/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 0
CSTACKEX-306: support for create CS colume from CS snapshot on the lo… #107
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
Open
rajiv-jain-netapp
wants to merge
1
commit into
main
Choose a base branch
from
feature/CSTACKEX-306
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
216 changes: 173 additions & 43 deletions
216
...ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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 |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ | |
| import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint; | ||
| import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector; | ||
| import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo; | ||
| import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; | ||
| import org.apache.cloudstack.storage.command.CreateObjectCommand; | ||
| import org.apache.cloudstack.storage.command.DeleteCommand; | ||
| import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; | ||
|
|
@@ -188,6 +189,76 @@ public CloudStackVolume cloneCloudStackVolume(CloudStackVolume cloudstackVolume) | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new qcow2 (or other file) in the FlexVol by cloning from a FlexVolume snapshot | ||
| * via {@code POST /api/storage/file/clone} with {@code snapshot.name}. | ||
| * | ||
| * <p>Builds the NFS request and executes it (mirrors {@link #createTemplateCache}). | ||
| * SAN uses the LUN REST clone path instead.</p> | ||
| * | ||
| * <p><b>Combinations covered here:</b></p> | ||
| * <ul> | ||
| * <li>DATA or ROOT snapshot → new data volume (ROOT restore is never bootable as a volume; | ||
| * CloudStack still uses this path for {@code createVolume(snapshotid)}; bootable ROOT | ||
| * recovery remains {@code createTemplate} → deploy)</li> | ||
| * <li>Same pool / FlexVol only (v1)</li> | ||
| * <li>IOPS from snapshot_details are not applied here — see driver TODO</li> | ||
| * </ul> | ||
| */ | ||
| @Override | ||
| public CloudStackVolume cloneCloudStackVolumeFromSnapshot(StoragePoolVO storagePool, Map<String, String> details, | ||
| VolumeInfo volumeInfo, String sourceVolumePath, | ||
| String snapshotName) { | ||
| if (storagePool == null || details == null || volumeInfo == null) { | ||
| throw new CloudRuntimeException("Failed to clone file from snapshot, invalid request"); | ||
| } | ||
| if (sourceVolumePath == null || sourceVolumePath.isEmpty()) { | ||
| throw new CloudRuntimeException("Failed to clone file from snapshot, source path is required"); | ||
| } | ||
| if (snapshotName == null || snapshotName.isEmpty()) { | ||
| throw new CloudRuntimeException("Failed to clone file from snapshot, snapshot name is required"); | ||
| } | ||
|
|
||
| String flexVolUuid = details.get(OntapStorageConstants.VOLUME_UUID); | ||
| String flexVolName = details.get(OntapStorageConstants.VOLUME_NAME); | ||
| if (flexVolUuid == null || flexVolUuid.isEmpty()) { | ||
| throw new CloudRuntimeException("Failed to clone file from snapshot, FlexVolume uuid is missing from pool details"); | ||
| } | ||
|
|
||
| String sourcePath = OntapStorageUtils.toFlexVolRelativePath(sourceVolumePath, flexVolName); | ||
| String destinationPath = OntapStorageUtils.toFlexVolRelativePath(volumeInfo.getUuid(), flexVolName); | ||
|
|
||
| logger.info("cloneCloudStackVolumeFromSnapshot [NFS]: Cloning file [{}] -> [{}] from snapshot [{}] on FlexVol [{}]", | ||
| sourcePath, destinationPath, snapshotName, flexVolName); | ||
| try { | ||
| FileCloneRequest request = new FileCloneRequest(flexVolUuid, flexVolName, sourcePath, destinationPath, snapshotName); | ||
| JobResponse jobResponse = nasFeignClient.cloneFile(getAuthHeader(), request); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Till the new adapter for nfs is brought in, we wanted to continue using kvm commands only right? |
||
| pollJobIfPresent(jobResponse, "clone file from snapshot [" + snapshotName + "] [" + sourcePath | ||
| + "] to [" + destinationPath + "]"); | ||
|
|
||
| updateCloudStackVolumeMetadata(String.valueOf(storagePool.getId()), volumeInfo); | ||
|
|
||
| FileInfo clonedFile = new FileInfo(); | ||
| clonedFile.setPath(destinationPath); | ||
|
|
||
| CloudStackVolume clonedCloudStackVolume = new CloudStackVolume(); | ||
| clonedCloudStackVolume.setFile(clonedFile); | ||
| clonedCloudStackVolume.setDatastoreId(String.valueOf(storagePool.getId())); | ||
| clonedCloudStackVolume.setVolumeInfo(volumeInfo); | ||
| clonedCloudStackVolume.setSnapshotName(snapshotName); | ||
| return clonedCloudStackVolume; | ||
| } catch (FeignException e) { | ||
| logger.error("FeignException while cloning file from snapshot [{}], Status: {}, Exception: {}", | ||
| snapshotName, e.status(), e.getMessage()); | ||
| throw new CloudRuntimeException("Failed to clone file from snapshot: " + e.getMessage()); | ||
| } catch (CloudRuntimeException e) { | ||
| throw e; | ||
| } catch (Exception e) { | ||
| logger.error("Exception while cloning file from snapshot [{}]: {}", snapshotName, e.getMessage()); | ||
| throw new CloudRuntimeException("Failed to clone file from snapshot: " + e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Grows the cloned qcow2 to the requested size via a host-side {@code qemu-img resize}. | ||
| */ | ||
|
|
||
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
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
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.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For clarity, do mention that its poolDetails, else it could be interpreted as volumeDetails