sureshanaparti commented on code in PR #8575:
URL: https://github.com/apache/cloudstack/pull/8575#discussion_r1472919065


##########
plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/driver/StorPoolPrimaryDataStoreDriver.java:
##########
@@ -485,55 +484,14 @@ public void copyAsync(DataObject srcData, DataObject 
dstData, AsyncCompletionCal
                     StorPoolUtil.spLog("Snapshot %s does not exists on 
StorPool, will try to create a volume from a snopshot on secondary storage", 
snapshotName);
                     SnapshotDataStoreVO snap = 
getSnapshotImageStoreRef(sinfo.getId(), vinfo.getDataCenterId());
                     if (snap != null && 
StorPoolStorageAdaptor.getVolumeNameFromPath(snap.getInstallPath(), false) == 
null) {
-                        resp = StorPoolUtil.volumeCreate(srcData.getUuid(), 
null, size, null, "no", "snapshot", sinfo.getBaseVolume().getMaxIops(), conn);
-                        if (resp.getError() == null) {
-                            VolumeObjectTO dstTO = (VolumeObjectTO) 
dstData.getTO();
-                            dstTO.setSize(size);
-                            
dstTO.setPath(StorPoolUtil.devPath(StorPoolUtil.getNameFromResponse(resp, 
false)));
-                            cmd = new 
StorPoolDownloadTemplateCommand(srcData.getTO(), dstTO, 
StorPoolHelper.getTimeout(StorPoolHelper.PrimaryStorageDownloadWait, 
configDao), VirtualMachineManager.ExecuteInSequence.value(), "volume");
-
-                            EndPoint ep = selector.select(srcData, dstData);
-                            if (ep == null) {
-                                err = "No remote endpoint to send command, 
check if host or ssvm is down?";
-                            } else {
-                                answer = ep.sendMessage(cmd);
-                            }
-
-                            if (answer != null && answer.getResult()) {
-                                SpApiResponse resp2 = 
StorPoolUtil.volumeFreeze(StorPoolUtil.getNameFromResponse(resp, true), conn);
-                                if (resp2.getError() != null) {
-                                    err = String.format("Could not freeze 
Storpool volume %s. Error: %s", srcData.getUuid(), resp2.getError());
-                                } else {
-                                    String name = 
StorPoolUtil.getNameFromResponse(resp, false);
-                                    SnapshotDetailsVO snapshotDetails = 
_snapshotDetailsDao.findDetail(sinfo.getId(), sinfo.getUuid());
-                                    if (snapshotDetails != null) {
-                                        
StorPoolHelper.updateSnapshotDetailsValue(snapshotDetails.getId(), 
StorPoolUtil.devPath(name), "snapshot");
-                                    }else {
-                                        
StorPoolHelper.addSnapshotDetails(sinfo.getId(), sinfo.getUuid(), 
StorPoolUtil.devPath(name), _snapshotDetailsDao);
-                                    }
-                                    resp = 
StorPoolUtil.volumeCreate(volumeName, StorPoolUtil.getNameFromResponse(resp, 
true), size, null, null, "volume", sinfo.getBaseVolume().getMaxIops(), conn);
-                                    if (resp.getError() == null) {
-                                        
updateStoragePool(dstData.getDataStore().getId(), size);
-
-                                        VolumeObjectTO to = (VolumeObjectTO) 
dstData.getTO();
-                                        
to.setPath(StorPoolUtil.devPath(StorPoolUtil.getNameFromResponse(resp, false)));
-                                        to.setSize(size);
-                                        // successfully downloaded snapshot to 
primary storage
-                                        answer = new CopyCmdAnswer(to);
-                                        StorPoolUtil.spLog("Created volume=%s 
with uuid=%s from snapshot=%s with uuid=%s", name, to.getUuid(), snapshotName, 
sinfo.getUuid());
-
-                                    } else {
-                                        err = String.format("Could not create 
Storpool volume %s from snapshot %s. Error: %s", volumeName, snapshotName, 
resp.getError());
-                                    }
-                                }
-                            } else {
-                                err = answer != null ? answer.getDetails() : 
"Unknown error while downloading template. Null answer returned.";
-                            }
+                        SpApiResponse emptyVolumeCreateResp = 
StorPoolUtil.volumeCreate(volumeName, null, size, null, null, "volume", null, 
conn);
+                        if (emptyVolumeCreateResp.getError() == null) {
+                            answer = createVolumeFromSnapshot(srcData, 
dstData, size, emptyVolumeCreateResp);

Review Comment:
   If create volume from snapshot always requires empty volume response, I 
think it's better to move the call `StorPoolUtil.volumeCreate()` to 
`createVolumeFromSnapshot()`



-- 
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