Skip to content

Commit 6ebfd7d

Browse files
committed
small fixes
fix copy when reccuring snapshot fix UI after rebasing
1 parent a0bd3c1 commit 6ebfd7d

File tree

6 files changed

+23
-7
lines changed

6 files changed

+23
-7
lines changed

api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotPolicyCmd.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.util.HashMap;
4242
import java.util.List;
4343
import java.util.Map;
44+
import org.apache.commons.lang3.BooleanUtils;
4445

4546
@APICommand(name = "createSnapshotPolicy", description = "Creates a snapshot policy for the account.", responseObject = SnapshotPolicyResponse.class,
4647
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
@@ -92,6 +93,9 @@ public class CreateSnapshotPolicyCmd extends BaseCmd {
9293
"The snapshot will always be made available in the zone in which the volume is present.",
9394
since = "4.21.0")
9495
protected List<Long> storagePoolIds;
96+
97+
@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")
98+
protected Boolean useStorageReplication;
9599
/////////////////////////////////////////////////////
96100
/////////////////// Accessors ///////////////////////
97101
/////////////////////////////////////////////////////
@@ -132,6 +136,10 @@ public List<Long> getStoragePoolIds() {
132136
return storagePoolIds == null ? new ArrayList<>() : storagePoolIds;
133137
}
134138

139+
public Boolean useStorageReplication() {
140+
return BooleanUtils.toBoolean(useStorageReplication);
141+
}
142+
135143
/////////////////////////////////////////////////////
136144
/////////////// API Implementation///////////////////
137145
/////////////////////////////////////////////////////

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,12 @@ public void copyAsync(DataObject srcData, DataObject dstData, AsyncCompletionCal
672672
SpApiResponse resp = StorPoolUtil.volumeCreate(spVolume, conn);
673673
if (resp.getError() == null) {
674674
updateStoragePool(dstData.getDataStore().getId(), size);
675+
676+
VolumeObjectTO to = (VolumeObjectTO)dstData.getTO();
677+
to.setPath(StorPoolUtil.devPath(StorPoolUtil.getNameFromResponse(resp, false)));
678+
to.setSize(size);
679+
680+
answer = new CopyCmdAnswer(to);
675681
StorPoolUtil.spLog("Created volume=%s with uuid=%s from snapshot=%s with uuid=%s", StorPoolUtil.getNameFromResponse(resp, false), volumeName, snapshotName, sinfo.getUuid());
676682
} else if (resp.getError().getName().equals("objectDoesNotExist")) {
677683
//check if snapshot is on secondary storage

server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ protected void validatePolicyZones(List<Long> zoneIds, List<Long> poolIds, Volum
11371137
if (!hasZones && !hasPools) {
11381138
return;
11391139
}
1140-
if (Boolean.FALSE.equals(SnapshotInfo.BackupSnapshotAfterTakingSnapshot.value()) && hasZones) {
1140+
if (Boolean.FALSE.equals(SnapshotInfo.BackupSnapshotAfterTakingSnapshot.value()) && hasZones && !hasPools) {
11411141
throw new InvalidParameterValueException("Backing up of snapshot has been disabled. Snapshot can not be taken for multiple zones");
11421142
}
11431143
final DataCenterVO zone = dataCenterDao.findById(volume.getDataCenterId());
@@ -1258,7 +1258,9 @@ public SnapshotPolicyVO createPolicy(CreateSnapshotPolicyCmd cmd, Account policy
12581258
}
12591259

12601260
final List<Long> zoneIds = cmd.getZoneIds();
1261-
final List<Long> poolIds = cmd.getStoragePoolIds();
1261+
VolumeInfo volumeInfo = volFactory.getVolume(volumeId);
1262+
final List<Long> poolIds = snapshotHelper.addStoragePoolsForCopyToPrimary(volumeInfo, zoneIds, cmd.getStoragePoolIds(), cmd.useStorageReplication());
1263+
12621264
validatePolicyZones(zoneIds, poolIds, volume, caller);
12631265

12641266
Map<String, String> tags = cmd.getTags();
@@ -1777,7 +1779,7 @@ public BackupSnapshotTask(SnapshotInfo snap, int maxRetries, SnapshotStrategy st
17771779
protected void runInContext() {
17781780
try {
17791781
logger.debug("Value of attempts is " + (snapshotBackupRetries - attempts));
1780-
if (Boolean.TRUE.equals(SnapshotInfo.BackupSnapshotAfterTakingSnapshot.value()) && CollectionUtils.isEmpty(zoneIds)) {
1782+
if (Boolean.TRUE.equals(SnapshotInfo.BackupSnapshotAfterTakingSnapshot.value()) && CollectionUtils.isEmpty(poolIds)) {
17811783
SnapshotInfo backupedSnapshot = snapshotStrategy.backupSnapshot(snapshot);
17821784

17831785
if (backupedSnapshot != null) {
@@ -2228,7 +2230,7 @@ protected DataCenterVO getCheckedDestinationZoneForSnapshotCopy(long zoneId, boo
22282230
protected StoragePoolVO getCheckedDestinationStorageForSnapshotCopy(long poolId, boolean isRootAdmin) {
22292231
StoragePoolVO destPool = _storagePoolDao.findById(poolId);
22302232
if (destPool == null) {
2231-
throw new InvalidParameterValueException("Please specify a valid destination zone.");
2233+
throw new InvalidParameterValueException("Please specify a valid destination pool.");
22322234
}
22332235
if (!StoragePoolStatus.Up.equals(destPool.getStatus()) && !isRootAdmin) {
22342236
throw new PermissionDeniedException("Cannot perform this operation, the storage pool is not in Up state or the user is not the Root Admin " + destPool.getName());

ui/src/views/storage/FormSchedule.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ export default {
363363
const params = {}
364364
params.showicon = true
365365
this.storagePoolsLoading = true
366-
api('listStoragePools', params).then(json => {
366+
getAPI('listStoragePools', params).then(json => {
367367
const listStoragePools = json.liststoragepoolsresponse.storagepool
368368
if (listStoragePools) {
369369
this.storagePools = listStoragePools

ui/src/views/storage/SnapshotZones.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ export default {
537537
const params = {}
538538
params.showicon = true
539539
this.storagePoolsLoading = true
540-
api('listStoragePools', params).then(json => {
540+
getAPI('listStoragePools', params).then(json => {
541541
const listStoragePools = json.liststoragepoolsresponse.storagepool
542542
if (listStoragePools) {
543543
this.storagePools = listStoragePools

ui/src/views/storage/TakeSnapshot.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export default {
249249
const params = {}
250250
params.showicon = true
251251
this.storagePoolsLoading = true
252-
api('listStoragePools', params).then(json => {
252+
getAPI('listStoragePools', params).then(json => {
253253
const listStoragePools = json.liststoragepoolsresponse.storagepool
254254
if (listStoragePools) {
255255
this.storagePools = listStoragePools

0 commit comments

Comments
 (0)