rajiv-jain-netapp commented on code in PR #14243:
URL: https://github.com/apache/cloudstack/pull/14243#discussion_r4765042206


##########
plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedNASStrategy.java:
##########
@@ -119,9 +138,107 @@ public void deleteCloudStackVolume(CloudStackVolume 
cloudstackVolume) {
         }
     }
 
+    /**
+     * Clones a file inside the FlexVolume using ONTAP's file clone API.
+     *
+     * <p>The source is taken from {@code file.path} and the destination from
+     * {@code destinationPath}, both relative to the root of the FlexVolume 
backing the pool.</p>
+     */
     @Override
-    public void copyCloudStackVolume(CloudStackVolume cloudstackVolume) {
+    public CloudStackVolume cloneCloudStackVolume(CloudStackVolume 
cloudstackVolume) {
+        if (cloudstackVolume == null || cloudstackVolume.getFile() == null
+                || cloudstackVolume.getFile().getPath() == null || 
cloudstackVolume.getDestinationPath() == null) {
+            logger.error("cloneCloudStackVolume: File clone failed. Invalid 
request: {}", cloudstackVolume);
+            throw new CloudRuntimeException("Failed to clone file, invalid 
request");
+        }
+        if (cloudstackVolume.getDatastoreId() == null) {
+            throw new CloudRuntimeException("Failed to clone file, no 
datastore id in the request");
+        }
+        if (cloudstackVolume.getVolumeInfo() == null) {
+            throw new CloudRuntimeException("Failed to clone file, volume info 
is missing from the request");
+        }
+        final long poolId = 
parseDatastoreId(cloudstackVolume.getDatastoreId());
+
+        Map<String, String> details = 
storagePoolDetailsDao.listDetailsKeyPairs(poolId);
+        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, FlexVolume 
uuid is missing from pool details");
+        }
+        String sourcePath = cloudstackVolume.getFile().getPath();
+        String destinationPath = cloudstackVolume.getDestinationPath();
+
+        logger.info("cloneCloudStackVolume: Cloning file [{}] to [{}] in 
FlexVol [{}]", sourcePath, destinationPath, flexVolName);
+        try {
+            FileCloneRequest request = new FileCloneRequest(flexVolUuid, 
flexVolName, sourcePath, destinationPath);
+            JobResponse jobResponse = 
nasFeignClient.cloneFile(getAuthHeader(), request);
+            pollJobIfPresent(jobResponse, "clone file [" + sourcePath + "] to 
[" + destinationPath + "]");
 
+            updateCloudStackVolumeMetadata(cloudstackVolume.getDatastoreId(), 
cloudstackVolume.getVolumeInfo());
+
+            FileInfo clonedFile = new FileInfo();
+            clonedFile.setPath(destinationPath);
+
+            CloudStackVolume clonedCloudStackVolume = new CloudStackVolume();
+            clonedCloudStackVolume.setFile(clonedFile);
+            
clonedCloudStackVolume.setDatastoreId(cloudstackVolume.getDatastoreId());
+            
clonedCloudStackVolume.setVolumeInfo(cloudstackVolume.getVolumeInfo());
+            return clonedCloudStackVolume;
+        } catch (FeignException e) {
+            logger.error("FeignException occurred while cloning file [{}], 
Status: {}, Exception: {}",
+                    sourcePath, e.status(), e.getMessage());
+            throw new CloudRuntimeException("Failed to clone file: " + 
e.getMessage());
+        } catch (Exception e) {
+            logger.error("Exception occurred while cloning file [{}], 
Exception: {}", sourcePath, e.getMessage());
+            throw new CloudRuntimeException("Failed to clone file: " + 
e.getMessage());
+        }
+    }
+
+    /**
+     * Grows the cloned qcow2 to the requested size via a host-side {@code 
qemu-img resize}.
+     */
+    @Override
+    public void resizeCloudStackVolume(CloudStackVolume cloudstackVolume, long 
sizeInBytes) {
+        if (cloudstackVolume == null || cloudstackVolume.getVolumeInfo() == 
null) {
+            logger.error("resizeCloudStackVolume: Resize failed. Invalid 
request: {}", cloudstackVolume);
+            throw new CloudRuntimeException("Failed to resize file, invalid 
request");
+        }
+        if (sizeInBytes <= 0) {
+            throw new CloudRuntimeException("Failed to resize file, invalid 
size " + sizeInBytes);
+        }
+
+        DataObject volumeInfo = cloudstackVolume.getVolumeInfo();
+        Answer answer = resizeVolumeOnKVMHost(volumeInfo, sizeInBytes);
+        if (answer == null || !answer.getResult()) {
+            String errMsg = answer != null ? answer.getDetails() : "Failed to 
resize qcow2 on KVM host";
+            logger.error("resizeCloudStackVolume: " + errMsg);
+            throw new CloudRuntimeException(errMsg);
+        }
+        logger.info("resizeCloudStackVolume: Resized volume [{}] to {} bytes", 
volumeInfo.getUuid(), sizeInBytes);
+    }
+
+    private Answer resizeVolumeOnKVMHost(DataObject volumeInfo, long 
sizeInBytes) {
+        VolumeObject volumeObject = (VolumeObject) volumeInfo;

Review Comment:
   same as earlier



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to