Skip to content

Commit 573ad8e

Browse files
committed
remove usage of volumeFreeze API call
1 parent fedcf66 commit 573ad8e

File tree

3 files changed

+67
-81
lines changed

3 files changed

+67
-81
lines changed

plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/driver/StorPoolPrimaryDataStoreDriver.java

Lines changed: 55 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
import com.cloud.storage.VolumeDetailVO;
9797
import com.cloud.storage.VolumeVO;
9898
import com.cloud.storage.dao.SnapshotDetailsDao;
99-
import com.cloud.storage.dao.SnapshotDetailsVO;
10099
import com.cloud.storage.dao.StoragePoolHostDao;
101100
import com.cloud.storage.dao.VMTemplateDetailsDao;
102101
import com.cloud.storage.dao.VolumeDao;
@@ -132,9 +131,9 @@ public class StorPoolPrimaryDataStoreDriver implements PrimaryDataStoreDriver {
132131
@Inject
133132
private HostDao hostDao;
134133
@Inject
135-
private ResourceTagDao _resourceTagDao;
134+
private ResourceTagDao resourceTagDao;
136135
@Inject
137-
private SnapshotDetailsDao _snapshotDetailsDao;
136+
private SnapshotDetailsDao snapshotDetailsDao;
138137
@Inject
139138
private SnapshotDataStoreDao snapshotDataStoreDao;
140139
@Inject
@@ -464,7 +463,7 @@ public void copyAsync(DataObject srcData, DataObject dstData, AsyncCompletionCal
464463
try {
465464
if (srcType == DataObjectType.SNAPSHOT && dstType == DataObjectType.VOLUME) {
466465
SnapshotInfo sinfo = (SnapshotInfo)srcData;
467-
final String snapshotName = StorPoolHelper.getSnapshotName(srcData.getId(), srcData.getUuid(), snapshotDataStoreDao, _snapshotDetailsDao);
466+
final String snapshotName = StorPoolHelper.getSnapshotName(srcData.getId(), srcData.getUuid(), snapshotDataStoreDao, snapshotDetailsDao);
468467

469468
VolumeInfo vinfo = (VolumeInfo)dstData;
470469
final String volumeName = vinfo.getUuid();
@@ -485,55 +484,14 @@ public void copyAsync(DataObject srcData, DataObject dstData, AsyncCompletionCal
485484
StorPoolUtil.spLog("Snapshot %s does not exists on StorPool, will try to create a volume from a snopshot on secondary storage", snapshotName);
486485
SnapshotDataStoreVO snap = getSnapshotImageStoreRef(sinfo.getId(), vinfo.getDataCenterId());
487486
if (snap != null && StorPoolStorageAdaptor.getVolumeNameFromPath(snap.getInstallPath(), false) == null) {
488-
resp = StorPoolUtil.volumeCreate(srcData.getUuid(), null, size, null, "no", "snapshot", sinfo.getBaseVolume().getMaxIops(), conn);
489-
if (resp.getError() == null) {
490-
VolumeObjectTO dstTO = (VolumeObjectTO) dstData.getTO();
491-
dstTO.setSize(size);
492-
dstTO.setPath(StorPoolUtil.devPath(StorPoolUtil.getNameFromResponse(resp, false)));
493-
cmd = new StorPoolDownloadTemplateCommand(srcData.getTO(), dstTO, StorPoolHelper.getTimeout(StorPoolHelper.PrimaryStorageDownloadWait, configDao), VirtualMachineManager.ExecuteInSequence.value(), "volume");
494-
495-
EndPoint ep = selector.select(srcData, dstData);
496-
if (ep == null) {
497-
err = "No remote endpoint to send command, check if host or ssvm is down?";
498-
} else {
499-
answer = ep.sendMessage(cmd);
500-
}
501-
502-
if (answer != null && answer.getResult()) {
503-
SpApiResponse resp2 = StorPoolUtil.volumeFreeze(StorPoolUtil.getNameFromResponse(resp, true), conn);
504-
if (resp2.getError() != null) {
505-
err = String.format("Could not freeze Storpool volume %s. Error: %s", srcData.getUuid(), resp2.getError());
506-
} else {
507-
String name = StorPoolUtil.getNameFromResponse(resp, false);
508-
SnapshotDetailsVO snapshotDetails = _snapshotDetailsDao.findDetail(sinfo.getId(), sinfo.getUuid());
509-
if (snapshotDetails != null) {
510-
StorPoolHelper.updateSnapshotDetailsValue(snapshotDetails.getId(), StorPoolUtil.devPath(name), "snapshot");
511-
}else {
512-
StorPoolHelper.addSnapshotDetails(sinfo.getId(), sinfo.getUuid(), StorPoolUtil.devPath(name), _snapshotDetailsDao);
513-
}
514-
resp = StorPoolUtil.volumeCreate(volumeName, StorPoolUtil.getNameFromResponse(resp, true), size, null, null, "volume", sinfo.getBaseVolume().getMaxIops(), conn);
515-
if (resp.getError() == null) {
516-
updateStoragePool(dstData.getDataStore().getId(), size);
517-
518-
VolumeObjectTO to = (VolumeObjectTO) dstData.getTO();
519-
to.setPath(StorPoolUtil.devPath(StorPoolUtil.getNameFromResponse(resp, false)));
520-
to.setSize(size);
521-
// successfully downloaded snapshot to primary storage
522-
answer = new CopyCmdAnswer(to);
523-
StorPoolUtil.spLog("Created volume=%s with uuid=%s from snapshot=%s with uuid=%s", name, to.getUuid(), snapshotName, sinfo.getUuid());
524-
525-
} else {
526-
err = String.format("Could not create Storpool volume %s from snapshot %s. Error: %s", volumeName, snapshotName, resp.getError());
527-
}
528-
}
529-
} else {
530-
err = answer != null ? answer.getDetails() : "Unknown error while downloading template. Null answer returned.";
531-
}
487+
SpApiResponse emptyVolumeCreateResp = StorPoolUtil.volumeCreate(volumeName, null, size, null, null, "volume", null, conn);
488+
if (emptyVolumeCreateResp.getError() == null) {
489+
answer = createVolumeFromSnapshot(srcData, dstData, size, emptyVolumeCreateResp);
532490
} else {
533-
err = String.format("Could not create Storpool volume %s from snapshot %s. Error: %s", volumeName, snapshotName, resp.getError());
491+
answer = new Answer(cmd, false, String.format("Could not create Storpool volume %s from snapshot %s. Error: %s", volumeName, snapshotName, emptyVolumeCreateResp.getError()));
534492
}
535493
} else {
536-
err = String.format("The snapshot %s does not exists neither on primary, neither on secondary storage. Cannot create volume from snapshot", snapshotName);
494+
answer = new Answer(cmd, false, String.format("The snapshot %s does not exists neither on primary, neither on secondary storage. Cannot create volume from snapshot", snapshotName));
537495
}
538496
} else {
539497
err = String.format("Could not create Storpool volume %s from snapshot %s. Error: %s", volumeName, snapshotName, resp.getError());
@@ -632,22 +590,17 @@ public void copyAsync(DataObject srcData, DataObject dstData, AsyncCompletionCal
632590
err = String.format("Could not create Storpool volume for CS template %s. Error: %s", name, resp.getError());
633591
} else {
634592
String volumeNameToSnapshot = StorPoolUtil.getNameFromResponse(resp, true);
635-
SpApiResponse resp2 = StorPoolUtil.volumeFreeze(volumeNameToSnapshot, conn);
636-
if (resp2.getError() != null) {
637-
err = String.format("Could not freeze Storpool volume %s. Error: %s", name, resp2.getError());
638-
} else {
639-
StorPoolUtil.spLog("Storpool snapshot [%s] for a template exists. Creating template on Storpool with name [%s]", tinfo.getUuid(), name);
640-
TemplateObjectTO dstTO = (TemplateObjectTO) dstData.getTO();
641-
dstTO.setPath(StorPoolUtil.devPath(StorPoolUtil.getNameFromResponse(resp, false)));
642-
dstTO.setSize(size);
643-
answer = new CopyCmdAnswer(dstTO);
644-
}
593+
TemplateObjectTO dstTO = (TemplateObjectTO) dstData.getTO();
594+
595+
answer = createVolumeSnapshot(cmd, size, conn, volumeNameToSnapshot, dstTO);
596+
StorPoolUtil.volumeDelete(volumeNameToSnapshot, conn);
645597
}
646598
} else {
647599
resp = StorPoolUtil.volumeCreate(name, null, size, null, "no", "template", null, conn);
648600
if (resp.getError() != null) {
649601
err = String.format("Could not create Storpool volume for CS template %s. Error: %s", name, resp.getError());
650602
} else {
603+
String volName = StorPoolUtil.getNameFromResponse(resp, true);
651604
TemplateObjectTO dstTO = (TemplateObjectTO)dstData.getTO();
652605
dstTO.setPath(StorPoolUtil.devPath(StorPoolUtil.getNameFromResponse(resp, false)));
653606
dstTO.setSize(size);
@@ -663,19 +616,11 @@ public void copyAsync(DataObject srcData, DataObject dstData, AsyncCompletionCal
663616

664617
if (answer != null && answer.getResult()) {
665618
// successfully downloaded template to primary storage
666-
SpApiResponse resp2 = StorPoolUtil.volumeFreeze(StorPoolUtil.getNameFromResponse(resp, true), conn);
667-
if (resp2.getError() != null) {
668-
err = String.format("Could not freeze Storpool volume %s. Error: %s", name, resp2.getError());
669-
}
619+
answer = createVolumeSnapshot(cmd, size, conn, volName, dstTO);
670620
} else {
671621
err = answer != null ? answer.getDetails() : "Unknown error while downloading template. Null answer returned.";
672622
}
673-
}
674-
}
675-
if (err != null) {
676-
resp = StorPoolUtil.volumeDelete(StorPoolUtil.getNameFromResponse(resp, true), conn);
677-
if (resp.getError() != null) {
678-
log.warn(String.format("Could not clean-up Storpool volume %s. Error: %s", name, resp.getError()));
623+
StorPoolUtil.volumeDelete(volName, conn);
679624
}
680625
}
681626
} else if (srcType == DataObjectType.TEMPLATE && dstType == DataObjectType.VOLUME) {
@@ -846,6 +791,42 @@ public void copyAsync(DataObject srcData, DataObject dstData, AsyncCompletionCal
846791
callback.complete(res);
847792
}
848793

794+
private Answer createVolumeSnapshot(StorageSubSystemCommand cmd, Long size, SpConnectionDesc conn,
795+
String volName, TemplateObjectTO dstTO) {
796+
Answer answer;
797+
SpApiResponse resp2 = StorPoolUtil.volumeSnapshot(volName, dstTO.getUuid(), null, "template", null, conn);
798+
if (resp2.getError() != null) {
799+
answer = new Answer(cmd, false, String.format("Could not snapshot volume. Error: %s", resp2.getError()));
800+
} else {
801+
dstTO.setPath(StorPoolUtil.devPath(
802+
StorPoolUtil.getSnapshotNameFromResponse(resp2, false, StorPoolUtil.GLOBAL_ID)));
803+
dstTO.setSize(size);
804+
answer = new CopyCmdAnswer(dstTO);
805+
}
806+
return answer;
807+
}
808+
809+
private Answer createVolumeFromSnapshot(DataObject srcData, DataObject dstData, final Long size,
810+
SpApiResponse emptyVolumeCreateResp) {
811+
Answer answer;
812+
String name = StorPoolUtil.getNameFromResponse(emptyVolumeCreateResp, false);
813+
VolumeObjectTO dstTO = (VolumeObjectTO) dstData.getTO();
814+
dstTO.setSize(size);
815+
dstTO.setPath(StorPoolUtil.devPath(name));
816+
StorageSubSystemCommand cmd1 = new StorPoolDownloadTemplateCommand(srcData.getTO(), dstTO, StorPoolHelper.getTimeout(StorPoolHelper.PrimaryStorageDownloadWait, configDao), VirtualMachineManager.ExecuteInSequence.value(), "volume");
817+
818+
EndPoint ep = selector.select(srcData, dstData);
819+
if (ep == null) {
820+
answer = new Answer(cmd1, false, "\"No remote endpoint to send command, check if host or ssvm is down?\"");
821+
} else {
822+
answer = ep.sendMessage(cmd1);
823+
}
824+
if (answer == null || !answer.getResult()) {
825+
answer = new Answer(cmd1, false, answer != null ? answer.getDetails() : "Unknown error while downloading template. Null answer returned.");
826+
}
827+
return answer;
828+
}
829+
849830
private void updateVolumePoolType(VolumeInfo vinfo) {
850831
VolumeVO volumeVO = volumeDao.findById(vinfo.getId());
851832
volumeVO.setPoolType(StoragePoolType.StorPool);
@@ -977,9 +958,9 @@ public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback<CreateCm
977958
SnapshotObjectTO snapTo = (SnapshotObjectTO)snapshot.getTO();
978959
snapTo.setPath(StorPoolUtil.devPath(name.split("~")[1]));
979960
answer = new CreateObjectAnswer(snapTo);
980-
StorPoolHelper.addSnapshotDetails(snapshot.getId(), snapshot.getUuid(), snapTo.getPath(), _snapshotDetailsDao);
961+
StorPoolHelper.addSnapshotDetails(snapshot.getId(), snapshot.getUuid(), snapTo.getPath(), snapshotDetailsDao);
981962
//add primary storage of snapshot
982-
StorPoolHelper.addSnapshotDetails(snapshot.getId(), StorPoolUtil.SP_STORAGE_POOL_ID, String.valueOf(snapshot.getDataStore().getId()), _snapshotDetailsDao);
963+
StorPoolHelper.addSnapshotDetails(snapshot.getId(), StorPoolUtil.SP_STORAGE_POOL_ID, String.valueOf(snapshot.getDataStore().getId()), snapshotDetailsDao);
983964
StorPoolUtil.spLog("StorpoolPrimaryDataStoreDriverImpl.takeSnapshot: snapshot: name=%s, uuid=%s, volume: name=%s, uuid=%s", name, snapshot.getUuid(), volumeName, vinfo.getUuid());
984965
}
985966
} catch (Exception e) {
@@ -994,7 +975,7 @@ public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback<CreateCm
994975
@Override
995976
public void revertSnapshot(final SnapshotInfo snapshot, final SnapshotInfo snapshotOnPrimaryStore, final AsyncCompletionCallback<CommandResult> callback) {
996977
final VolumeInfo vinfo = snapshot.getBaseVolume();
997-
final String snapshotName = StorPoolHelper.getSnapshotName(snapshot.getId(), snapshot.getUuid(), snapshotDataStoreDao, _snapshotDetailsDao);
978+
final String snapshotName = StorPoolHelper.getSnapshotName(snapshot.getId(), snapshot.getUuid(), snapshotDataStoreDao, snapshotDetailsDao);
998979
final String volumeName = StorPoolStorageAdaptor.getVolumeNameFromPath(vinfo.getPath(), true);
999980
StorPoolUtil.spLog("StorpoolPrimaryDataStoreDriverImpl.revertSnapshot: snapshot: name=%s, uuid=%s, volume: name=%s, uuid=%s", snapshotName, snapshot.getUuid(), volumeName, vinfo.getUuid());
1000981
String err = null;
@@ -1049,7 +1030,7 @@ public void revertSnapshot(final SnapshotInfo snapshot, final SnapshotInfo snaps
10491030
}
10501031

10511032
private String getVcPolicyTag(Long vmId) {
1052-
ResourceTag resourceTag = vmId != null ? _resourceTagDao.findByKey(vmId, ResourceObjectType.UserVm, StorPoolUtil.SP_VC_POLICY) : null;
1033+
ResourceTag resourceTag = vmId != null ? resourceTagDao.findByKey(vmId, ResourceObjectType.UserVm, StorPoolUtil.SP_VC_POLICY) : null;
10531034
return resourceTag != null ? resourceTag.getValue() : "";
10541035
}
10551036

plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/util/StorPoolUtil.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,12 @@ public static SpApiResponse volumeRevert(final String name, final String snapsho
580580
return POST("MultiCluster/VolumeRevert/" + name, json, conn);
581581
}
582582

583+
/**
584+
* @deprecated Use volumeSnapshot instead
585+
* @param volumeName
586+
* @param conn
587+
* @return
588+
*/
583589
public static SpApiResponse volumeFreeze(final String volumeName, SpConnectionDesc conn) {
584590
return POST("MultiCluster/VolumeFreeze/" + volumeName, null, conn);
585591
}

plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/motion/StorPoolDataMotionStrategy.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,24 +215,23 @@ public void copyAsync(DataObject srcData, DataObject destData, Host destHost,
215215
} else {
216216
answer = (CopyCmdAnswer) ep2.sendMessage(backupSnapshot);
217217
if (answer != null && answer.getResult()) {
218-
SpApiResponse resSnapshot = StorPoolUtil.volumeFreeze(volumeName, conn);
218+
SpApiResponse resSnapshot = StorPoolUtil.volumeSnapshot(volumeName, template.getUuid(), null, "template", null, conn);
219219
if (resSnapshot.getError() != null) {
220220
log.debug(String.format("Could not snapshot volume with ID=%s", snapshot.getId()));
221-
StorPoolUtil.spLog("Volume freeze failed with error=%s", resSnapshot.getError().getDescr());
221+
StorPoolUtil.spLog("VolumeSnapshot failed with error=%s", resSnapshot.getError().getDescr());
222222
err = resSnapshot.getError().getDescr();
223-
StorPoolUtil.volumeDelete(volumeName, conn);
224223
} else {
224+
String templPath = StorPoolUtil.devPath(
225+
StorPoolUtil.getSnapshotNameFromResponse(resSnapshot, false, StorPoolUtil.GLOBAL_ID));
225226
StorPoolHelper.updateVmStoreTemplate(template.getId(), template.getDataStore().getRole(),
226-
StorPoolUtil.devPath(StorPoolUtil.getNameFromResponse(res, false)), _templStoreDao);
227+
templPath, _templStoreDao);
227228
}
228-
} else {
229-
err = "Could not copy template to secondary " + answer.getResult();
230-
StorPoolUtil.volumeDelete(StorPoolUtil.getNameFromResponse(res, true), conn);
231229
}
232230
}
233231
} catch (CloudRuntimeException e) {
234232
err = e.getMessage();
235233
}
234+
StorPoolUtil.volumeDelete(volumeName, conn);
236235
}
237236
_vmTemplateDetailsDao.persist(new VMTemplateDetailVO(template.getId(), StorPoolUtil.SP_STORAGE_POOL_ID,
238237
String.valueOf(vInfo.getDataStore().getId()), false));

0 commit comments

Comments
 (0)