Skip to content

Commit 6668140

Browse files
committed
allocate snapshot if the storage allows copy
1 parent 68ddc6d commit 6668140

File tree

9 files changed

+21
-7
lines changed

9 files changed

+21
-7
lines changed

api/src/main/java/com/cloud/storage/VolumeApiService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public interface VolumeApiService {
116116
Snapshot takeSnapshot(Long volumeId, Long policyId, Long snapshotId, Account account, boolean quiescevm, Snapshot.LocationType locationType, boolean asyncBackup, Map<String, String> tags, List<Long> zoneIds, List<Long> poolIds, Boolean useStorageReplication)
117117
throws ResourceAllocationException;
118118

119-
Snapshot allocSnapshot(Long volumeId, Long policyId, String snapshotName, Snapshot.LocationType locationType, List<Long> zoneIds, Boolean useStorageReplication) throws ResourceAllocationException;
119+
Snapshot allocSnapshot(Long volumeId, Long policyId, String snapshotName, Snapshot.LocationType locationType, List<Long> zoneIds, List<Long> storagePoolIds, Boolean useStorageReplication) throws ResourceAllocationException;
120120

121121
Volume updateVolume(long volumeId, String path, String state, Long storageId,
122122
Boolean displayVolume, Boolean deleteProtection,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public ApiCommandResourceType getApiResourceType() {
236236

237237
@Override
238238
public void create() throws ResourceAllocationException {
239-
Snapshot snapshot = _volumeService.allocSnapshot(getVolumeId(), getPolicyId(), getSnapshotName(), getLocationType(), getZoneIds(), useStorageReplication());
239+
Snapshot snapshot = _volumeService.allocSnapshot(getVolumeId(), getPolicyId(), getSnapshotName(), getLocationType(), getZoneIds(), getStoragePoolIds(), useStorageReplication());
240240
if (snapshot != null) {
241241
setEntityId(snapshot.getId());
242242
setEntityUuid(snapshot.getUuid());

server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3988,7 +3988,7 @@ private boolean isOperationSupported(VMTemplateVO template, UserVmVO userVm) {
39883988

39893989
@Override
39903990
@ActionEvent(eventType = EventTypes.EVENT_SNAPSHOT_CREATE, eventDescription = "allocating snapshot", create = true)
3991-
public Snapshot allocSnapshot(Long volumeId, Long policyId, String snapshotName, Snapshot.LocationType locationType, List<Long> zoneIds, Boolean useStorageReplication) throws ResourceAllocationException {
3991+
public Snapshot allocSnapshot(Long volumeId, Long policyId, String snapshotName, Snapshot.LocationType locationType, List<Long> zoneIds, List<Long> poolIds, Boolean useStorageReplication) throws ResourceAllocationException {
39923992
Account caller = CallContext.current().getCallingAccount();
39933993

39943994
VolumeInfo volume = volFactory.getVolume(volumeId);
@@ -4022,6 +4022,8 @@ public Snapshot allocSnapshot(Long volumeId, Long policyId, String snapshotName,
40224022
throw new InvalidParameterValueException(String.format("Volume: %s is for System VM , Creating snapshot against System VM volumes is not supported", volume.getVolume()));
40234023
}
40244024
}
4025+
snapshotHelper.addStoragePoolsForCopyToPrimary(volume, zoneIds, poolIds, useStorageReplication);
4026+
canCopyOnPrimary(poolIds, volume,CollectionUtils.isEmpty(poolIds));
40254027

40264028
StoragePoolVO storagePoolVO = _storagePoolDao.findById(volume.getPoolId());
40274029

server/src/main/java/org/apache/cloudstack/snapshot/SnapshotHelper.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ public List<Long> addStoragePoolsForCopyToPrimary(VolumeInfo volume, List<Long>
344344
if (useStorageReplication) {
345345
if (volume == null) {
346346
throw new InvalidParameterValueException("Could not find volume of a snapshot");
347+
} else if (!doesStorageSupportCopyBetweenZones(volume.getPoolId())){
348+
throw new InvalidParameterValueException("The storage pool does not support copy between zones");
347349
}
348350
if (CollectionUtils.isEmpty(destZoneIds)) {
349351
throw new InvalidParameterValueException("There is no destination zone provided");
@@ -365,4 +367,13 @@ public List<Long> addStoragePoolsForCopyToPrimary(VolumeInfo volume, List<Long>
365367
}
366368
return storagePoolIds;
367369
}
370+
371+
public boolean doesStorageSupportCopyBetweenZones(Long poolId) {
372+
DataStore dataStore = dataStorageManager.getDataStore(poolId, DataStoreRole.Primary);
373+
if (dataStore != null
374+
&& dataStore.getDriver().getCapabilities().containsKey(DataStoreCapabilities.CAN_COPY_SNAPSHOT_BETWEEN_ZONES_AND_SAME_POOL_TYPE.toString())) {
375+
return true;
376+
}
377+
return false;
378+
}
368379
}

server/src/test/java/com/cloud/storage/VolumeApiServiceImplTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ public void testUpdateMissingRootDiskControllerWithValidChainInfo() {
640640
@Test
641641
public void testAllocSnapshotNonManagedStorageArchive() {
642642
try {
643-
volumeApiServiceImpl.allocSnapshot(6L, 1L, "test", Snapshot.LocationType.SECONDARY, null, null);
643+
volumeApiServiceImpl.allocSnapshot(6L, 1L, "test", Snapshot.LocationType.SECONDARY, null, null, null);
644644
} catch (InvalidParameterValueException e) {
645645
Assert.assertEquals(e.getMessage(), "VolumeId: 6 LocationType is supported only for managed storage");
646646
return;

ui/public/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2848,6 +2848,7 @@
28482848
"label.leaseexpiryaction": "Lease expiry action",
28492849
"label.remainingdays": "Lease",
28502850
"label.leased": "Leased",
2851+
"label.usestoragereplication": "Use primary storage replication",
28512852
"message.acquire.ip.failed": "Failed to acquire IP.",
28522853
"message.action.acquire.ip": "Please confirm that you want to acquire new IP.",
28532854
"message.action.cancel.maintenance": "Your host has been successfully canceled for maintenance. This process can take up to several minutes.",

ui/src/views/storage/FormSchedule.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
</a-form-item>
171171
</a-col>
172172
<a-col :md="24" :lg="24" v-if="resourceType === 'Volume'">
173-
<a-form-item :label="$t('label.useStorageReplication')" name="useStorageReplication" ref="useStorageReplication">
173+
<a-form-item :label="$t('label.usestoragereplication')" name="useStorageReplication" ref="useStorageReplication">
174174
<a-switch v-model:checked="form.useStorageReplication" />
175175
</a-form-item>
176176
<a-form-item v-if="isAdmin && form.useStorageReplication" ref="storageids" name="storageids">

ui/src/views/storage/SnapshotZones.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
</a-select-option>
138138
</a-select>
139139
</a-form-item>
140-
<a-form-item :label="$t('label.useStorageReplication')" name="useStorageReplication" ref="useStorageReplication">
140+
<a-form-item :label="$t('label.usestoragereplication')" name="useStorageReplication" ref="useStorageReplication">
141141
<a-switch v-model:checked="form.useStorageReplication" />
142142
</a-form-item>
143143
<a-form-item v-if="isAdmin && form.useStorageReplication" ref="storageid" name="storageid" :label="$t('label.storagepools')">

ui/src/views/storage/TakeSnapshot.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
</a-select-option>
6767
</a-select>
6868
</a-form-item>
69-
<a-form-item :label="$t('label.useStorageReplication')" name="useStorageReplication" ref="useStorageReplication">
69+
<a-form-item :label="$t('label.usestoragereplication')" name="useStorageReplication" ref="useStorageReplication">
7070
<a-switch v-model:checked="form.useStorageReplication" />
7171
</a-form-item>
7272
<a-form-item v-if="isAdmin && form.useStorageReplication" ref="storageids" name="storageids">

0 commit comments

Comments
 (0)