Skip to content

Commit 226e82a

Browse files
committed
Merge remote-tracking branch 'upstream/main' into instance-from-backup
2 parents f9cf862 + 70468a6 commit 226e82a

File tree

24 files changed

+555
-353
lines changed

24 files changed

+555
-353
lines changed

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,10 @@ public class ApiConstants {
13211321
"however, the following formats are also accepted: \"yyyy-MM-dd HH:mm:ss\" (e.g.: \"2023-01-01 12:00:00\") and \"yyyy-MM-dd\" (e.g.: \"2023-01-01\" - if the time is not " +
13221322
"added, it will be interpreted as \"23:59:59\"). If the recommended format is not used, the date will be considered in the server timezone.";
13231323

1324+
public static final String PARAMETER_DESCRIPTION_MAX_BACKUPS = "The maximum number of backups to keep for a VM. " +
1325+
"If \"0\", no retention policy will be applied and, thus, no backups from the schedule will be automatically deleted. " +
1326+
"This parameter is only supported for the Dummy, NAS and EMC Networker backup provider.";
1327+
13241328
public static final String VMWARE_DC = "vmwaredc";
13251329

13261330
public static final String CSS = "css";

api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListCapacityCmd.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,12 @@ public void execute() {
132132
Collections.sort(capacityResponses, new Comparator<CapacityResponse>() {
133133
public int compare(CapacityResponse resp1, CapacityResponse resp2) {
134134
int res = resp1.getZoneName().compareTo(resp2.getZoneName());
135+
// Group by zone
135136
if (res != 0) {
136137
return res;
137-
} else if (getSortBy() != null) {
138-
return 0;
139-
} else {
140-
return resp1.getCapacityType().compareTo(resp2.getCapacityType());
141138
}
139+
// Sort by capacity type only if not already sorted by usage
140+
return (getSortBy() != null) ? 0 : resp1.getCapacityType().compareTo(resp2.getCapacityType());
142141
}
143142
});
144143

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import javax.inject.Inject;
2121

22-
import com.cloud.storage.Snapshot;
2322
import org.apache.cloudstack.acl.RoleType;
2423
import org.apache.cloudstack.api.APICommand;
2524
import org.apache.cloudstack.api.ApiCommandResourceType;
@@ -28,7 +27,6 @@
2827
import org.apache.cloudstack.api.BaseAsyncCreateCmd;
2928
import org.apache.cloudstack.api.Parameter;
3029
import org.apache.cloudstack.api.ServerApiException;
31-
import org.apache.cloudstack.api.response.BackupScheduleResponse;
3230
import org.apache.cloudstack.api.response.SuccessResponse;
3331
import org.apache.cloudstack.api.response.UserVmResponse;
3432
import org.apache.cloudstack.backup.BackupManager;
@@ -74,13 +72,6 @@ public class CreateBackupCmd extends BaseAsyncCreateCmd {
7472
since = "4.21.0")
7573
private String description;
7674

77-
@Parameter(name = ApiConstants.SCHEDULE_ID,
78-
type = CommandType.LONG,
79-
entityType = BackupScheduleResponse.class,
80-
description = "backup schedule ID of the VM, if this is null, it indicates that it is a manual backup.",
81-
since = "4.21.0")
82-
private Long scheduleId;
83-
8475
@Parameter(name = ApiConstants.QUIESCE_VM,
8576
type = CommandType.BOOLEAN,
8677
required = false,
@@ -106,14 +97,6 @@ public String getDescription() {
10697
return description;
10798
}
10899

109-
public Long getScheduleId() {
110-
if (scheduleId != null) {
111-
return scheduleId;
112-
} else {
113-
return Snapshot.MANUAL_POLICY_ID;
114-
}
115-
}
116-
117100
public Boolean getQuiesceVM() {
118101
return quiesceVM;
119102
}
@@ -125,7 +108,7 @@ public Boolean getQuiesceVM() {
125108
@Override
126109
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
127110
try {
128-
boolean result = backupManager.createBackup(this);
111+
boolean result = backupManager.createBackup(this, getJob());
129112
if (result) {
130113
SuccessResponse response = new SuccessResponse(getCommandName());
131114
response.setResponseName(getCommandName());

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,8 @@ public class CreateBackupScheduleCmd extends BaseCmd {
7575
description = "Specifies a timezone for this command. For more information on the timezone parameter, see TimeZone Format.")
7676
private String timezone;
7777

78-
@Parameter(name = ApiConstants.MAX_BACKUPS,
79-
type = CommandType.INTEGER,
80-
description = "maximum number of backups to retain",
81-
since = "4.21.0")
78+
@Parameter(name = ApiConstants.MAX_BACKUPS, type = CommandType.INTEGER,
79+
since = "4.21.0", description = ApiConstants.PARAMETER_DESCRIPTION_MAX_BACKUPS)
8280
private Integer maxBackups;
8381

8482
@Parameter(name = ApiConstants.QUIESCE_VM,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public class BackupResponse extends BaseResponse {
116116
private Map<String, String> vmDetails;
117117

118118
@SerializedName(ApiConstants.INTERVAL_TYPE)
119-
@Param(description = "the interval type of the backup schedule", since = "4.21.0")
119+
@Param(description = "Interval type of the backup", since = "4.21.0")
120120
private String intervalType;
121121

122122
@SerializedName(ApiConstants.BACKUP_VM_OFFERING_REMOVED)

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

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,6 @@ enum Status {
3434
Allocated, Queued, BackingUp, BackedUp, Error, Failed, Restoring, Removed, Expunged
3535
}
3636

37-
public enum Type {
38-
MANUAL, HOURLY, DAILY, WEEKLY, MONTHLY;
39-
private int max = 8;
40-
41-
public void setMax(int max) {
42-
this.max = max;
43-
}
44-
45-
public int getMax() {
46-
return max;
47-
}
48-
49-
@Override
50-
public String toString() {
51-
return this.name();
52-
}
53-
54-
public boolean equals(String snapshotType) {
55-
return this.toString().equalsIgnoreCase(snapshotType);
56-
}
57-
}
58-
5937
class Metric {
6038
private Long backupSize = 0L;
6139
private Long dataSize = 0L;
@@ -216,9 +194,9 @@ public String toString() {
216194
void setName(String name);
217195
String getDescription();
218196
void setDescription(String description);
219-
Short getBackupIntervalType();
220197
List<VolumeInfo> getBackedUpVolumes();
221198
long getZoneId();
222199
Map<String, String> getDetails();
223200
String getDetail(String name);
201+
Long getBackupScheduleId();
224202
}

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

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -67,38 +67,6 @@ public interface BackupManager extends BackupService, Configurable, PluggableSer
6767
"false",
6868
"Enable volume attach/detach operations for VMs that are assigned to Backup Offerings.", true);
6969

70-
ConfigKey<Integer> BackupHourlyMax = new ConfigKey<Integer>("Advanced", Integer.class,
71-
"backup.max.hourly",
72-
"8",
73-
"Maximum recurring hourly backups to be retained for an instance. If the limit is reached, early backups from the start of the hour are deleted so that newer ones can be saved. This limit does not apply to manual backups. If set to 0, recurring hourly backups can not be scheduled.",
74-
false,
75-
ConfigKey.Scope.Global,
76-
null);
77-
78-
ConfigKey<Integer> BackupDailyMax = new ConfigKey<Integer>("Advanced", Integer.class,
79-
"backup.max.daily",
80-
"8",
81-
"Maximum recurring daily backups to be retained for an instance. If the limit is reached, backups from the start of the day are deleted so that newer ones can be saved. This limit does not apply to manual backups. If set to 0, recurring daily backups can not be scheduled.",
82-
false,
83-
ConfigKey.Scope.Global,
84-
null);
85-
86-
ConfigKey<Integer> BackupWeeklyMax = new ConfigKey<Integer>("Advanced", Integer.class,
87-
"backup.max.weekly",
88-
"8",
89-
"Maximum recurring weekly backups to be retained for an instance. If the limit is reached, backups from the beginning of the week are deleted so that newer ones can be saved. This limit does not apply to manual backups. If set to 0, recurring weekly backups can not be scheduled.",
90-
false,
91-
ConfigKey.Scope.Global,
92-
null);
93-
94-
ConfigKey<Integer> BackupMonthlyMax = new ConfigKey<Integer>("Advanced", Integer.class,
95-
"backup.max.monthly",
96-
"8",
97-
"Maximum recurring monthly backups to be retained for an instance. If the limit is reached, backups from the beginning of the month are deleted so that newer ones can be saved. This limit does not apply to manual backups. If set to 0, recurring monthly backups can not be scheduled.",
98-
false,
99-
ConfigKey.Scope.Global,
100-
null);
101-
10270
ConfigKey<Long> DefaultMaxAccountBackups = new ConfigKey<Long>("Account Defaults", Long.class,
10371
"max.account.backups",
10472
"20",
@@ -217,11 +185,11 @@ public interface BackupManager extends BackupService, Configurable, PluggableSer
217185

218186
/**
219187
* Creates backup of a VM
220-
*
221-
* @param cmd
188+
* @param cmd CreateBackupCmd
189+
* @param job The async job associated with the backup retention
222190
* @return returns operation success
223191
*/
224-
boolean createBackup(CreateBackupCmd cmd) throws ResourceAllocationException;
192+
boolean createBackup(CreateBackupCmd cmd, Object job) throws ResourceAllocationException;
225193

226194
/**
227195
* List existing backups for a VM

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public interface BackupSchedule extends InternalIdentity {
3030
String getTimezone();
3131
Date getScheduledTimestamp();
3232
Long getAsyncJobId();
33-
Integer getMaxBackups();
3433
Boolean getQuiesceVM();
34+
int getMaxBackups();
3535
String getUuid();
3636
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ public class BackupScheduleVO implements BackupSchedule {
6363
Long asyncJobId;
6464

6565
@Column(name = "max_backups")
66-
Integer maxBackups = 0;
66+
private int maxBackups = 0;
6767

6868
@Column(name = "quiescevm")
6969
Boolean quiesceVM = false;
7070

7171
public BackupScheduleVO() {
7272
}
7373

74-
public BackupScheduleVO(Long vmId, DateUtil.IntervalType scheduleType, String schedule, String timezone, Date scheduledTimestamp, Integer maxBackups, Boolean quiesceVM) {
74+
public BackupScheduleVO(Long vmId, DateUtil.IntervalType scheduleType, String schedule, String timezone, Date scheduledTimestamp, int maxBackups, Boolean quiesceVM) {
7575
this.vmId = vmId;
7676
this.scheduleType = (short) scheduleType.ordinal();
7777
this.schedule = schedule;
@@ -146,11 +146,11 @@ public void setAsyncJobId(Long asyncJobId) {
146146
this.asyncJobId = asyncJobId;
147147
}
148148

149-
public Integer getMaxBackups() {
149+
public int getMaxBackups() {
150150
return maxBackups;
151151
}
152152

153-
public void setMaxBackups(Integer maxBackups) {
153+
public void setMaxBackups(int maxBackups) {
154154
this.maxBackups = maxBackups;
155155
}
156156

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ public class BackupVO implements Backup {
9797
@Column(name = "zone_id")
9898
private long zoneId;
9999

100-
@Column(name = "backup_interval_type")
101-
private Short backupIntervalType;
102-
103100
@Column(name = "backed_volumes", length = 65535)
104101
protected String backedUpVolumes;
105102

103+
@Column(name = "backup_schedule_id")
104+
private Long backupScheduleId;
105+
106106
@Transient
107107
Map<String, String> details;
108108

@@ -223,15 +223,6 @@ public void setZoneId(long zoneId) {
223223
this.zoneId = zoneId;
224224
}
225225

226-
@Override
227-
public Short getBackupIntervalType() {
228-
return backupIntervalType;
229-
}
230-
231-
public void setBackupIntervalType(short backupIntervalType) {
232-
this.backupIntervalType = backupIntervalType;
233-
}
234-
235226
@Override
236227
public Class<?> getEntityType() {
237228
return Backup.class;
@@ -288,4 +279,13 @@ public Date getRemoved() {
288279
public void setRemoved(Date removed) {
289280
this.removed = removed;
290281
}
282+
283+
@Override
284+
public Long getBackupScheduleId() {
285+
return backupScheduleId;
286+
}
287+
288+
public void setBackupScheduleId(Long backupScheduleId) {
289+
this.backupScheduleId = backupScheduleId;
290+
}
291291
}

0 commit comments

Comments
 (0)