Skip to content

Commit 29d4daa

Browse files
authored
Merge pull request #759 from Dajeong-Park/ablestack-diplo
[Mold API] Diplo 백업 스케줄 관련 추가 반영 및 NAS 백업 통합 기능테스트 오류 수정
2 parents bcab7f3 + 105fec0 commit 29d4daa

6 files changed

Lines changed: 37 additions & 14 deletions

File tree

api/src/main/java/org/apache/cloudstack/api/response/BackupScheduleResponse.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828

2929
@EntityReference(value = BackupSchedule.class)
3030
public class BackupScheduleResponse extends BaseResponse {
31+
@SerializedName(ApiConstants.ID)
32+
@Param(description = "ID of the backup schedule.")
33+
private String id;
3134

3235
@SerializedName(ApiConstants.VIRTUAL_MACHINE_NAME)
3336
@Param(description = "name of the VM")
@@ -51,7 +54,11 @@ public class BackupScheduleResponse extends BaseResponse {
5154

5255
@SerializedName(ApiConstants.MAX_BACKUPS)
5356
@Param(description = "maximum number of backups retained")
54-
private Integer maxBakups;
57+
private Integer maxBackups;
58+
59+
public void setId(String id) {
60+
this.id = id;
61+
}
5562

5663
public String getVmName() {
5764
return vmName;
@@ -93,7 +100,7 @@ public void setTimezone(String timezone) {
93100
this.timezone = timezone;
94101
}
95102

96-
public void setMaxBakups(Integer maxBakups) {
97-
this.maxBakups = maxBakups;
103+
public void setMaxBackups(Integer maxBackups) {
104+
this.maxBackups = maxBackups;
98105
}
99106
}

engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupScheduleDaoImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,13 @@ public List<BackupScheduleVO> getSchedulesToExecute(Date currentTimestamp) {
9292
public BackupScheduleResponse newBackupScheduleResponse(BackupSchedule schedule) {
9393
VMInstanceVO vm = vmInstanceDao.findByIdIncludingRemoved(schedule.getVmId());
9494
BackupScheduleResponse response = new BackupScheduleResponse();
95+
response.setId(schedule.getUuid());
9596
response.setVmId(vm.getUuid());
9697
response.setVmName(vm.getHostName());
9798
response.setIntervalType(schedule.getScheduleType());
9899
response.setSchedule(schedule.getSchedule());
99100
response.setTimezone(schedule.getTimezone());
100-
response.setMaxBakups(schedule.getMaxBackups());
101+
response.setMaxBackups(schedule.getMaxBackups());
101102
response.setObjectName("backupschedule");
102103
return response;
103104
}

engine/schema/src/main/resources/META-INF/db/schema-42010to42100.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.console_session', 'console_endpoint_
2727

2828
-- Add client_address column to cloud.console_session table
2929
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.console_session', 'client_address', 'VARCHAR(45)');
30+
31+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.backup_schedule', 'uuid', 'VARCHAR(40) NOT NULL');
32+
UPDATE `cloud`.`backup_schedule` SET uuid = UUID();

plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@
2727
import com.cloud.hypervisor.Hypervisor;
2828
import com.cloud.storage.ScopeType;
2929
import com.cloud.storage.Storage;
30-
import com.cloud.storage.StoragePoolHostVO;
3130
import com.cloud.storage.Volume;
3231
import com.cloud.storage.VolumeVO;
33-
import com.cloud.storage.dao.StoragePoolHostDao;
3432
import com.cloud.storage.dao.VolumeDao;
3533
import com.cloud.utils.Pair;
3634
import com.cloud.utils.component.AdapterBase;
@@ -84,9 +82,6 @@ public class NASBackupProvider extends AdapterBase implements BackupProvider, Co
8482
@Inject
8583
private VolumeDao volumeDao;
8684

87-
@Inject
88-
private StoragePoolHostDao storagePoolHostDao;
89-
9085
@Inject
9186
private VMInstanceDao vmInstanceDao;
9287

@@ -268,12 +263,28 @@ private List<String> getVolumePaths(List<VolumeVO> volumes) {
268263
return volumePaths;
269264
}
270265

266+
private String getVolumePathPrefix(StoragePoolVO storagePool) {
267+
String volumePathPrefix;
268+
if (ScopeType.HOST.equals(storagePool.getScope()) ||
269+
Storage.StoragePoolType.SharedMountPoint.equals(storagePool.getPoolType()) ||
270+
Storage.StoragePoolType.RBD.equals(storagePool.getPoolType())) {
271+
volumePathPrefix = storagePool.getPath();
272+
} else {
273+
// Should be Storage.StoragePoolType.NetworkFilesystem
274+
volumePathPrefix = String.format("/mnt/%s", storagePool.getUuid());
275+
}
276+
return volumePathPrefix;
277+
}
278+
271279
@Override
272280
public Pair<Boolean, String> restoreBackedUpVolume(Backup backup, String volumeUuid, String hostIp, String dataStoreUuid, Pair<String, VirtualMachine.State> vmNameAndState) {
273281
final VolumeVO volume = volumeDao.findByUuid(volumeUuid);
274282
final VirtualMachine backupSourceVm = vmInstanceDao.findById(backup.getVmId());
275-
final StoragePoolHostVO dataStore = storagePoolHostDao.findByUuid(dataStoreUuid);
276-
final HostVO hostVO = hostDao.findByIp(hostIp);
283+
final StoragePoolVO pool = primaryDataStoreDao.findByUuid(dataStoreUuid);
284+
HostVO hostVO = hostDao.findByIp(hostIp);
285+
if(hostVO == null) {
286+
hostVO = hostDao.findByName(hostIp);
287+
}
277288

278289
Optional<Backup.VolumeInfo> matchingVolume = getBackedUpVolumeInfo(backupSourceVm.getBackupVolumeList(), volumeUuid);
279290
Long backedUpVolumeSize = matchingVolume.isPresent() ? matchingVolume.get().getSize() : 0L;
@@ -291,7 +302,7 @@ public Pair<Boolean, String> restoreBackedUpVolume(Backup backup, String volumeU
291302
restoredVolume.setUuid(volumeUUID);
292303
restoredVolume.setRemoved(null);
293304
restoredVolume.setDisplayVolume(true);
294-
restoredVolume.setPoolId(dataStore.getPoolId());
305+
restoredVolume.setPoolId(pool.getId());
295306
restoredVolume.setPath(restoredVolume.getUuid());
296307
restoredVolume.setState(Volume.State.Copying);
297308
restoredVolume.setFormat(Storage.ImageFormat.QCOW2);
@@ -303,7 +314,7 @@ public Pair<Boolean, String> restoreBackedUpVolume(Backup backup, String volumeU
303314
restoreCommand.setBackupRepoType(backupRepository.getType());
304315
restoreCommand.setBackupRepoAddress(backupRepository.getAddress());
305316
restoreCommand.setVmName(vmNameAndState.first());
306-
restoreCommand.setVolumePaths(Collections.singletonList(String.format("%s/%s", dataStore.getLocalPath(), volumeUUID)));
317+
restoreCommand.setVolumePaths(Collections.singletonList(String.format("%s/%s", getVolumePathPrefix(pool), volumeUUID)));
307318
restoreCommand.setDiskType(volume.getVolumeType().name().toLowerCase(Locale.ROOT));
308319
restoreCommand.setVmExists(null);
309320
restoreCommand.setVmState(vmNameAndState.second());

server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,7 @@ private void syncBackups(BackupProvider backupProvider, VirtualMachine vm, Backu
16501650
Transaction.execute(new TransactionCallbackNoReturn() {
16511651
@Override
16521652
public void doInTransactionWithoutResult(TransactionStatus status) {
1653+
backupProvider.syncBackups(vm, metric);
16531654
final List<Backup> backupsInDb = backupDao.listByVmId(null, vm.getId());
16541655
List<Backup.RestorePoint> restorePoints = backupProvider.listRestorePoints(vm);
16551656
if (restorePoints == null) {

ui/src/views/compute/backup/BackupSchedule.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export default {
172172
methods: {
173173
handleClickDelete (record) {
174174
const params = {}
175-
params.virtualmachineid = record.virtualmachineid
175+
params.id = record.id
176176
this.actionLoading = true
177177
api('deleteBackupSchedule', params).then(json => {
178178
if (json.deletebackupscheduleresponse.success) {

0 commit comments

Comments
 (0)