Skip to content

Commit aa22dc5

Browse files
author
SadiJr
committed
Merge branch '1148-recurrying-snapshots' into '4.20.0.0-scclouds'
Refatoração nas APIs `listSnapshotPolicies` e `listBackupSchedules` Closes #1148 See merge request scclouds/scclouds!985
2 parents e633154 + fa8813c commit aa22dc5

40 files changed

Lines changed: 1910 additions & 81 deletions

File tree

api/src/main/java/com/cloud/storage/snapshot/SnapshotApiService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public interface SnapshotApiService {
8585
* the command that specifies the volume criteria
8686
* @return list of snapshot policies
8787
*/
88-
Pair<List<? extends SnapshotPolicy>, Integer> listPoliciesforVolume(ListSnapshotPoliciesCmd cmd);
88+
Pair<List<? extends SnapshotPolicy>, Integer> listSnapshotPolicies(ListSnapshotPoliciesCmd cmd);
8989

9090
boolean deleteSnapshotPolicies(DeleteSnapshotPoliciesCmd cmd);
9191

api/src/main/java/com/cloud/storage/snapshot/SnapshotPolicy.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
// under the License.
1717
package com.cloud.storage.snapshot;
1818

19+
import org.apache.cloudstack.acl.ControlledEntity;
1920
import org.apache.cloudstack.api.Displayable;
2021
import org.apache.cloudstack.api.Identity;
2122
import org.apache.cloudstack.api.InternalIdentity;
2223

23-
public interface SnapshotPolicy extends Identity, InternalIdentity, Displayable {
24+
public interface SnapshotPolicy extends ControlledEntity, Identity, InternalIdentity, Displayable {
2425

2526
long getVolumeId();
2627

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

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.apache.cloudstack.acl.RoleType;
2323
import org.apache.cloudstack.api.APICommand;
2424
import org.apache.cloudstack.api.ApiConstants;
25-
import org.apache.cloudstack.api.BaseCmd;
25+
import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
2626
import org.apache.cloudstack.api.Parameter;
2727
import org.apache.cloudstack.api.response.BackupScheduleResponse;
2828
import org.apache.cloudstack.api.response.ListResponse;
@@ -38,10 +38,10 @@
3838
description = "List backup schedule of a VM",
3939
responseObject = BackupScheduleResponse.class, since = "4.14.0",
4040
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
41-
public class ListBackupScheduleCmd extends BaseCmd {
41+
public class ListBackupScheduleCmd extends BaseListProjectAndAccountResourcesCmd {
4242

4343
@Inject
44-
private BackupManager backupManager;
44+
protected BackupManager backupManager;
4545

4646
/////////////////////////////////////////////////////
4747
//////////////// API parameters /////////////////////
@@ -50,10 +50,31 @@ public class ListBackupScheduleCmd extends BaseCmd {
5050
@Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID,
5151
type = CommandType.UUID,
5252
entityType = UserVmResponse.class,
53-
required = true,
5453
description = "ID of the VM")
5554
private Long vmId;
5655

56+
@Parameter(name = ApiConstants.ID,
57+
type = CommandType.UUID,
58+
entityType = BackupScheduleResponse.class,
59+
description = "the ID of the backup schedule",
60+
since = "4.20.0.6-scclouds")
61+
private Long id;
62+
63+
@Parameter(name = ApiConstants.INTERVAL_TYPE,
64+
type = CommandType.STRING,
65+
description = "valid values are HOURLY, DAILY, WEEKLY, and MONTHLY")
66+
private String intervalType;
67+
68+
@Parameter(name = ApiConstants.VM_SNAPSHOT_QUIESCEVM,
69+
type = CommandType.BOOLEAN,
70+
since = "4.20.0.6-scclouds")
71+
private Boolean quiescevm;
72+
73+
@Parameter(name = ApiConstants.ISOLATED,
74+
type = CommandType.BOOLEAN,
75+
since = "4.20.0.6-scclouds")
76+
private Boolean isolated;
77+
5778
/////////////////////////////////////////////////////
5879
/////////////////// Accessors ///////////////////////
5980
/////////////////////////////////////////////////////
@@ -62,13 +83,29 @@ public Long getVmId() {
6283
return vmId;
6384
}
6485

86+
public Long getId() {
87+
return id;
88+
}
89+
90+
public String getIntervalType() {
91+
return intervalType;
92+
}
93+
94+
public Boolean getIsolated() {
95+
return isolated;
96+
}
97+
98+
public Boolean getQuiescevm() {
99+
return quiescevm;
100+
}
101+
65102
/////////////////////////////////////////////////////
66103
/////////////// API Implementation///////////////////
67104
/////////////////////////////////////////////////////
68105

69106
@Override
70107
public void execute() {
71-
List<BackupSchedule> schedules = backupManager.listBackupSchedules(getVmId());
108+
List<BackupSchedule> schedules = backupManager.listBackupSchedules(this);
72109
ListResponse<BackupScheduleResponse> response = new ListResponse<>();
73110
List<BackupScheduleResponse> scheduleResponses = new ArrayList<>();
74111
for (BackupSchedule schedule : schedules) {

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import org.apache.cloudstack.api.APICommand;
2525
import org.apache.cloudstack.api.ApiConstants;
26-
import org.apache.cloudstack.api.BaseListCmd;
26+
import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
2727
import org.apache.cloudstack.api.Parameter;
2828
import org.apache.cloudstack.api.response.ListResponse;
2929
import org.apache.cloudstack.api.response.SnapshotPolicyResponse;
@@ -34,7 +34,7 @@
3434

3535
@APICommand(name = "listSnapshotPolicies", description = "Lists snapshot policies.", responseObject = SnapshotPolicyResponse.class,
3636
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
37-
public class ListSnapshotPoliciesCmd extends BaseListCmd {
37+
public class ListSnapshotPoliciesCmd extends BaseListProjectAndAccountResourcesCmd {
3838

3939

4040
/////////////////////////////////////////////////////
@@ -50,6 +50,11 @@ public class ListSnapshotPoliciesCmd extends BaseListCmd {
5050
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "list resources by display flag; only ROOT admin is eligible to pass this parameter", since = "4.4", authorized = {RoleType.Admin})
5151
private Boolean display;
5252

53+
@Parameter(name = ApiConstants.INTERVAL_TYPE,
54+
type = CommandType.STRING,
55+
description = "valid values are HOURLY, DAILY, WEEKLY, and MONTHLY")
56+
private String intervalType;
57+
5358
/////////////////////////////////////////////////////
5459
/////////////////// Accessors ///////////////////////
5560
/////////////////////////////////////////////////////
@@ -69,13 +74,18 @@ public boolean isDisplay() {
6974
public Long getId() {
7075
return id;
7176
}
77+
78+
public String getIntervalType() {
79+
return intervalType;
80+
}
81+
7282
/////////////////////////////////////////////////////
7383
/////////////// API Implementation///////////////////
7484
/////////////////////////////////////////////////////
7585

7686
@Override
7787
public void execute() {
78-
Pair<List<? extends SnapshotPolicy>, Integer> result = _snapshotService.listPoliciesforVolume(this);
88+
Pair<List<? extends SnapshotPolicy>, Integer> result = _snapshotService.listSnapshotPolicies(this);
7989
ListResponse<SnapshotPolicyResponse> response = new ListResponse<SnapshotPolicyResponse>();
8090
List<SnapshotPolicyResponse> policyResponses = new ArrayList<SnapshotPolicyResponse>();
8191
for (SnapshotPolicy policy : result.first()) {

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

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,30 @@ public class BackupScheduleResponse extends BaseResponse {
6464
@Param(description = ApiConstants.PARAMETER_DESCRIPTION_ISOLATED_BACKUPS)
6565
private boolean isolated;
6666

67+
@SerializedName(ApiConstants.ACCOUNT)
68+
@Param(description = "the account that the backup schedule is associated with")
69+
private String account;
70+
71+
@SerializedName(ApiConstants.ACCOUNT_ID)
72+
@Param(description = "the ID of the account that the backup schedule is associated with")
73+
private String accountId;
74+
75+
@SerializedName(ApiConstants.PROJECT)
76+
@Param(description = "the project name of the backup schedule")
77+
private String projectName;
78+
79+
@SerializedName(ApiConstants.PROJECT_ID)
80+
@Param(description = "the project ID of the backup schedule")
81+
private String projectId;
82+
83+
@SerializedName(ApiConstants.DOMAIN)
84+
@Param(description = "the domain that the backup schedule is associated with")
85+
private String domain;
86+
87+
@SerializedName(ApiConstants.DOMAIN_ID)
88+
@Param(description = "the domain ID that the backup schedule is associated with")
89+
private String domainid;
90+
6791
public void setId(String id) {
6892
this.id = id;
6993
}
@@ -119,4 +143,52 @@ public void setMaxBackups(int maxBackups) {
119143
public void setIsolated(boolean isolated) {
120144
this.isolated = isolated;
121145
}
146+
147+
public String getAccount() {
148+
return account;
149+
}
150+
151+
public void setAccount(String account) {
152+
this.account = account;
153+
}
154+
155+
public String getAccountId() {
156+
return accountId;
157+
}
158+
159+
public void setAccountId(String accountId) {
160+
this.accountId = accountId;
161+
}
162+
163+
public String getProjectName() {
164+
return projectName;
165+
}
166+
167+
public void setProjectName(String projectName) {
168+
this.projectName = projectName;
169+
}
170+
171+
public String getProjectId() {
172+
return projectId;
173+
}
174+
175+
public void setProjectId(String projectId) {
176+
this.projectId = projectId;
177+
}
178+
179+
public String getDomain() {
180+
return domain;
181+
}
182+
183+
public void setDomain(String domain) {
184+
this.domain = domain;
185+
}
186+
187+
public String getDomainid() {
188+
return domainid;
189+
}
190+
191+
public void setDomainid(String domainid) {
192+
this.domainid = domainid;
193+
}
122194
}

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

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,17 @@ public class SnapshotPolicyResponse extends BaseResponseWithTagInformation {
3838
@Param(description = "the ID of the disk volume")
3939
private String volumeId;
4040

41+
@SerializedName("volumename")
42+
@Param(description = "the name of the disk volume")
43+
private String volumeName;
44+
4145
@SerializedName("schedule")
4246
@Param(description = "time the snapshot is scheduled to be taken.")
4347
private String schedule;
4448

4549
@SerializedName("intervaltype")
4650
@Param(description = "the interval type of the snapshot policy")
47-
private short intervalType;
51+
private String intervalType;
4852

4953
@SerializedName("maxsnaps")
5054
@Param(description = "maximum number of snapshots retained")
@@ -62,6 +66,30 @@ public class SnapshotPolicyResponse extends BaseResponseWithTagInformation {
6266
@Param(description = "The list of zones in which snapshot backup is scheduled", responseObject = ZoneResponse.class, since = "4.19.0")
6367
protected Set<ZoneResponse> zones;
6468

69+
@SerializedName(ApiConstants.ACCOUNT)
70+
@Param(description = "the account that the snapshot policy is associated with")
71+
private String account;
72+
73+
@SerializedName(ApiConstants.ACCOUNT_ID)
74+
@Param(description = "the ID of the account that the snapshot policy is associated with")
75+
private String accountId;
76+
77+
@SerializedName(ApiConstants.PROJECT)
78+
@Param(description = "the project name of the snapshot policy")
79+
private String projectName;
80+
81+
@SerializedName(ApiConstants.PROJECT_ID)
82+
@Param(description = "the project ID of the snapshot policy")
83+
private String projectId;
84+
85+
@SerializedName(ApiConstants.DOMAIN)
86+
@Param(description = "the domain that the snapshot policy is associated with")
87+
private String domain;
88+
89+
@SerializedName(ApiConstants.DOMAIN_ID)
90+
@Param(description = "the domain ID that the snapshot policy is associated with")
91+
private String domainid;
92+
6593
public SnapshotPolicyResponse() {
6694
tags = new LinkedHashSet<ResourceTagResponse>();
6795
zones = new LinkedHashSet<>();
@@ -83,6 +111,10 @@ public void setVolumeId(String volumeId) {
83111
this.volumeId = volumeId;
84112
}
85113

114+
public void setVolumeName(String volumeName) {
115+
this.volumeName = volumeName;
116+
}
117+
86118
public String getSchedule() {
87119
return schedule;
88120
}
@@ -91,11 +123,11 @@ public void setSchedule(String schedule) {
91123
this.schedule = schedule;
92124
}
93125

94-
public short getIntervalType() {
126+
public String getIntervalType() {
95127
return intervalType;
96128
}
97129

98-
public void setIntervalType(short intervalType) {
130+
public void setIntervalType(String intervalType) {
99131
this.intervalType = intervalType;
100132
}
101133

@@ -130,4 +162,52 @@ public void setTags(Set<ResourceTagResponse> tags) {
130162
public void setZones(Set<ZoneResponse> zones) {
131163
this.zones = zones;
132164
}
165+
166+
public String getAccount() {
167+
return account;
168+
}
169+
170+
public void setAccount(String account) {
171+
this.account = account;
172+
}
173+
174+
public String getAccountId() {
175+
return accountId;
176+
}
177+
178+
public void setAccountId(String accountId) {
179+
this.accountId = accountId;
180+
}
181+
182+
public String getProjectName() {
183+
return projectName;
184+
}
185+
186+
public void setProjectName(String projectName) {
187+
this.projectName = projectName;
188+
}
189+
190+
public String getProjectId() {
191+
return projectId;
192+
}
193+
194+
public void setProjectId(String projectId) {
195+
this.projectId = projectId;
196+
}
197+
198+
public String getDomain() {
199+
return domain;
200+
}
201+
202+
public void setDomain(String domain) {
203+
this.domain = domain;
204+
}
205+
206+
public String getDomainid() {
207+
return domainid;
208+
}
209+
210+
public void setDomainid(String domainid) {
211+
this.domainid = domainid;
212+
}
133213
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.cloudstack.api.command.admin.backup.UpdateBackupOfferingCmd;
2727
import org.apache.cloudstack.api.command.user.backup.CreateBackupScheduleCmd;
2828
import org.apache.cloudstack.api.command.user.backup.ListBackupOfferingsCmd;
29+
import org.apache.cloudstack.api.command.user.backup.ListBackupScheduleCmd;
2930
import org.apache.cloudstack.api.command.user.backup.ListBackupsCmd;
3031
import org.apache.cloudstack.framework.config.ConfigKey;
3132
import org.apache.cloudstack.framework.config.Configurable;
@@ -106,11 +107,11 @@ public interface BackupManager extends BackupService, Configurable, PluggableSer
106107
BackupSchedule configureBackupSchedule(CreateBackupScheduleCmd cmd);
107108

108109
/**
109-
* Lists backup schedules for a VM
110-
* @param vmId ID of the VM from which all backup schedules will be listed
111-
* @return
110+
* Lists backup schedules
111+
* @param cmd
112+
* @return a list of backup schedules that match the informed parameters
112113
*/
113-
List<BackupSchedule> listBackupSchedules(Long vmId);
114+
List<BackupSchedule> listBackupSchedules(ListBackupScheduleCmd cmd);
114115

115116
/**
116117
* Deletes a VM backup schedule for a VM

0 commit comments

Comments
 (0)