Skip to content

Commit bcab7f3

Browse files
authored
Merge pull request #757 from jschoiRR/mold-main#2025
[Mold API] Refactoring retention of backup schedules apache#11223, Add Resource Limits to Backups and Object Storage apache#10017 PR 병합 후 빌드 오류 수정
2 parents 632e5ed + 674f697 commit bcab7f3

17 files changed

Lines changed: 134 additions & 41 deletions

File tree

api/src/main/java/com/cloud/event/EventTypes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ public class EventTypes {
799799

800800
// DISASTER RECOVERY
801801
public static final String EVENT_DISASTER_RECOVERY_CLUSTER = "DISASTER.RECOVERY.CLUSTER";
802-
802+
803803
// Resource Limit
804804
public static final String EVENT_RESOURCE_LIMIT_UPDATE = "RESOURCE.LIMIT.UPDATE";
805805

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,6 @@ Snapshot takeSnapshot(Long volumeId, Long policyId, Long snapshotId, Account acc
197197
Volume cloneVolumeFromSnapshot(Volume volume, long snapshotId, Long vmId) throws StorageUnavailableException;
198198

199199
Volume updateCompressDedupVolume(UpdateCompressDedupCmd cmd);
200-
200+
201201
Long getVolumePhysicalSize(Storage.ImageFormat format, String path, String chainInfo);
202202
}

api/src/main/java/org/apache/cloudstack/api/command/user/backup/DeleteBackupScheduleCmd.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.cloudstack.api.BaseCmd;
2727
import org.apache.cloudstack.api.Parameter;
2828
import org.apache.cloudstack.api.ServerApiException;
29+
import org.apache.cloudstack.api.response.BackupScheduleResponse;
2930
import org.apache.cloudstack.api.response.SuccessResponse;
3031
import org.apache.cloudstack.api.response.UserVmResponse;
3132
import org.apache.cloudstack.backup.BackupManager;
@@ -51,13 +52,15 @@ public class DeleteBackupScheduleCmd extends BaseCmd {
5152
//////////////// API parameters /////////////////////
5253
/////////////////////////////////////////////////////
5354

54-
@Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID,
55-
type = CommandType.UUID,
56-
entityType = UserVmResponse.class,
57-
required = true,
58-
description = "ID of the VM")
55+
@Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, type = CommandType.UUID, entityType = UserVmResponse.class,
56+
description = "ID of the VM from which all backup schedules will be deleted.")
5957
private Long vmId;
6058

59+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = BackupScheduleResponse.class,
60+
since = "4.20.1", description = "ID of the backup schedule to be deleted. It has precedence over the 'virtualmachineid' parameter, " +
61+
"i.e., when the 'id' parameter is specified, the 'virtualmachineid' parameter will be ignored.")
62+
private Long id;
63+
6164
/////////////////////////////////////////////////////
6265
/////////////////// Accessors ///////////////////////
6366
/////////////////////////////////////////////////////
@@ -66,14 +69,17 @@ public Long getVmId() {
6669
return vmId;
6770
}
6871

72+
public Long getId() { return id; }
73+
74+
6975
/////////////////////////////////////////////////////
7076
/////////////// API Implementation///////////////////
7177
/////////////////////////////////////////////////////
7278

7379
@Override
7480
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
7581
try {
76-
boolean result = backupManager.deleteBackupSchedule(getVmId());
82+
boolean result = backupManager.deleteBackupSchedule(this);
7783
if (result) {
7884
SuccessResponse response = new SuccessResponse(getCommandName());
7985
response.setResponseName(getCommandName());

api/src/main/java/org/apache/cloudstack/backup/BackupManager.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.cloudstack.api.command.admin.backup.ImportBackupOfferingCmd;
2424
import org.apache.cloudstack.api.command.admin.backup.UpdateBackupOfferingCmd;
2525
import org.apache.cloudstack.api.command.user.backup.CreateBackupScheduleCmd;
26+
import org.apache.cloudstack.api.command.user.backup.DeleteBackupScheduleCmd;
2627
import org.apache.cloudstack.api.command.user.backup.ListBackupOfferingsCmd;
2728
import org.apache.cloudstack.api.command.user.backup.ListBackupsCmd;
2829
import org.apache.cloudstack.framework.config.ConfigKey;
@@ -159,12 +160,12 @@ public interface BackupManager extends BackupService, Configurable, PluggableSer
159160
*/
160161
List<BackupSchedule> listBackupSchedule(Long vmId);
161162

162-
/**
163+
/**
163164
* Deletes VM backup schedule for a VM
164-
* @param vmId
165+
* @param cmd
165166
* @return
166167
*/
167-
boolean deleteBackupSchedule(Long vmId);
168+
boolean deleteBackupSchedule(DeleteBackupScheduleCmd cmd);
168169

169170
/**
170171
* Creates backup of a VM

engine/schema/src/main/java/org/apache/cloudstack/backup/BackupScheduleVO.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.cloudstack.backup;
1919

2020
import java.util.Date;
21+
import java.util.UUID;
2122

2223
import javax.persistence.Column;
2324
import javax.persistence.Entity;
@@ -42,6 +43,9 @@ public class BackupScheduleVO implements BackupSchedule {
4243
@Column(name = "vm_id")
4344
private Long vmId;
4445

46+
@Column(name = "uuid", nullable = false)
47+
private String uuid = UUID.randomUUID().toString();
48+
4549
@Column(name = "schedule_type")
4650
private Short scheduleType;
4751

@@ -84,6 +88,11 @@ public long getId() {
8488
return id;
8589
}
8690

91+
@Override
92+
public String getUuid() {
93+
return uuid;
94+
}
95+
8796
public Long getVmId() {
8897
return vmId;
8998
}

engine/schema/src/main/java/org/apache/cloudstack/backup/BackupVO.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@
2222
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
2323
import org.apache.commons.lang3.StringUtils;
2424

25-
import java.beans.Transient;
2625
import java.util.Arrays;
2726
import java.util.Collections;
2827
import java.util.Date;
2928
import java.util.List;
30-
import java.util.Map;
3129
import java.util.UUID;
3230

3331
import javax.persistence.Column;

framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,4 +2445,12 @@ private Optional<AttributeConverter<Object, Object>> getConverter(Field field) {
24452445
}
24462446
}
24472447

2448+
public static class SumCount {
2449+
public long sum;
2450+
public long count;
2451+
2452+
public SumCount() {
2453+
}
2454+
}
2455+
24482456
}

plugins/backup/commvault/src/main/java/org/apache/cloudstack/backup/CommvaultBackupProvider.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ public Pair<Boolean, String> restoreBackedUpVolume(Backup backup, String volumeU
763763
}
764764

765765
@Override
766-
public boolean takeBackup(VirtualMachine vm) {
766+
public Pair<Boolean, Backup> takeBackup(VirtualMachine vm) {
767767
String hostName = null;
768768
try {
769769
String commvaultServer = getUrlDomain(CommvaultUrl.value());
@@ -821,7 +821,7 @@ public boolean takeBackup(VirtualMachine vm) {
821821
}
822822
}
823823
LOG.error("Failed to request createSnapshot Mold-API.");
824-
return false;
824+
return new Pair<>(false, null);
825825
} else {
826826
JSONObject jsonObject = new JSONObject(createSnapResult);
827827
String jobId = jsonObject.get("jobid").toString();
@@ -843,7 +843,7 @@ public boolean takeBackup(VirtualMachine vm) {
843843
}
844844
}
845845
LOG.error("createSnapshot Mold-API async job resulted in failure.");
846-
return false;
846+
return new Pair<>(false, null);
847847
}
848848
checkResult.put(vol.getId(), snapId);
849849
SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findLatestSnapshotForVolume(vol.getId(), DataStoreRole.Primary);
@@ -1001,7 +1001,7 @@ public boolean takeBackup(VirtualMachine vm) {
10011001
command = String.format(RM_COMMAND, storagePath + "/" + vm.getInstanceName());
10021002
executeDeleteXmlCommand(hostVO, credentials.first(), credentials.second(), sshPort, command);
10031003
}
1004-
return true;
1004+
return new Pair<>(true, backup);
10051005
} else {
10061006
// 백업 실패
10071007
if (!checkResult.isEmpty()) {
@@ -1018,7 +1018,7 @@ public boolean takeBackup(VirtualMachine vm) {
10181018
executeDeleteXmlCommand(hostVO, credentials.first(), credentials.second(), sshPort, command);
10191019
}
10201020
LOG.error("createBackup commvault api resulted in " + jobStatus);
1021-
return false;
1021+
return new Pair<>(false, null);
10221022
}
10231023
} else {
10241024
// 백업 실패
@@ -1036,7 +1036,7 @@ public boolean takeBackup(VirtualMachine vm) {
10361036
executeDeleteXmlCommand(hostVO, credentials.first(), credentials.second(), sshPort, command);
10371037
}
10381038
LOG.error("createBackup commvault api resulted in " + jobStatus);
1039-
return false;
1039+
return new Pair<>(false, null);
10401040
}
10411041
} else {
10421042
// 백업 실패
@@ -1054,7 +1054,7 @@ public boolean takeBackup(VirtualMachine vm) {
10541054
executeDeleteXmlCommand(hostVO, credentials.first(), credentials.second(), sshPort, command);
10551055
}
10561056
LOG.error("failed request createBackup commvault api");
1057-
return false;
1057+
return new Pair<>(false, null);
10581058
}
10591059
} else {
10601060
// 백업 경로 업데이트 실패
@@ -1072,7 +1072,7 @@ public boolean takeBackup(VirtualMachine vm) {
10721072
executeDeleteXmlCommand(hostVO, credentials.first(), credentials.second(), sshPort, command);
10731073
}
10741074
LOG.error("updateBackupSet commvault api resulted in failure.");
1075-
return false;
1075+
return new Pair<>(false, null);
10761076
}
10771077
}
10781078

@@ -1559,4 +1559,16 @@ public static boolean versionCheck(String csVersionInfo) {
15591559
}
15601560
return true;
15611561
}
1562+
1563+
@Override
1564+
public List<Backup.RestorePoint> listRestorePoints(VirtualMachine vm) {
1565+
return null;
1566+
}
1567+
1568+
1569+
@Override
1570+
public Backup createNewBackupEntryForRestorePoint(Backup.RestorePoint restorePoint, VirtualMachine vm, Backup.Metric metric) {
1571+
return null;
1572+
}
1573+
15621574
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,10 @@ public String getConfigComponentName() {
461461
return BackupService.class.getSimpleName();
462462
}
463463

464+
@Override
465+
public void syncBackups(VirtualMachine vm, Backup.Metric metric) {
466+
}
467+
464468
@Override
465469
public boolean checkBackupAgent(final Long zoneId) { return true; }
466470

plugins/backup/networker/src/main/java/org/apache/cloudstack/backup/NetworkerBackupProvider.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.cloud.vm.VMInstanceVO;
3535
import com.cloud.vm.VirtualMachine;
3636
import com.cloud.vm.dao.VMInstanceDao;
37+
3738
import org.apache.cloudstack.backup.dao.BackupDao;
3839
import org.apache.cloudstack.backup.dao.BackupOfferingDaoImpl;
3940
import org.apache.cloudstack.backup.networker.NetworkerClient;
@@ -624,4 +625,8 @@ public List<Backup.RestorePoint> listRestorePoints(VirtualMachine vm) {
624625

625626
@Override
626627
public boolean updateBackupPlan(final Long zoneId, final String retentionPeriod, final String externalId) { return true; }
628+
629+
@Override
630+
public void syncBackups(VirtualMachine vm, Backup.Metric metric) {
631+
}
627632
}

0 commit comments

Comments
 (0)