Skip to content

Commit 5cf8edd

Browse files
committed
CLOUDSTACK-6987: Add support for storing metadata for snapshot policy and controlling policy using display flag
1 parent 8de18f1 commit 5cf8edd

19 files changed

Lines changed: 222 additions & 28 deletions

File tree

‎api/src/com/cloud/server/ResourceTag.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public enum ResourceObjectType {
5555
AutoScaleVmProfile(false, true),
5656
AutoScaleVmGroup(false, true),
5757
LBStickinessPolicy(false, true),
58-
LBHealthCheckPolicy(false, true);
58+
LBHealthCheckPolicy(false, true),
59+
SnapshotPolicy(false, true);
5960

6061

6162
ResourceObjectType(boolean resourceTagsSupport, boolean resourceMetadataSupport) {

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

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

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

22-
public interface SnapshotPolicy extends Identity, InternalIdentity {
23+
public interface SnapshotPolicy extends Identity, InternalIdentity, Displayable {
2324

2425
long getVolumeId();
2526

‎api/src/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotPolicyCmd.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.snapshot;
1818

19+
import org.apache.cloudstack.acl.RoleType;
1920
import org.apache.log4j.Logger;
2021

2122
import org.apache.cloudstack.api.APICommand;
@@ -64,6 +65,9 @@ public class CreateSnapshotPolicyCmd extends BaseCmd {
6465
@Parameter(name = ApiConstants.VOLUME_ID, type = CommandType.UUID, entityType = VolumeResponse.class, required = true, description = "the ID of the disk volume")
6566
private Long volumeId;
6667

68+
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the policy to the end user or not", since = "4.4", authorized = {RoleType.Admin})
69+
private Boolean display;
70+
6771
/////////////////////////////////////////////////////
6872
/////////////////// Accessors ///////////////////////
6973
/////////////////////////////////////////////////////
@@ -88,6 +92,14 @@ public Long getVolumeId() {
8892
return volumeId;
8993
}
9094

95+
@Override
96+
public boolean isDisplay() {
97+
if(display == null)
98+
return true;
99+
else
100+
return display;
101+
}
102+
91103
/////////////////////////////////////////////////////
92104
/////////////// API Implementation///////////////////
93105
/////////////////////////////////////////////////////

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22+
import org.apache.cloudstack.acl.RoleType;
2223
import org.apache.log4j.Logger;
2324

2425
import org.apache.cloudstack.api.APICommand;
@@ -46,6 +47,9 @@ public class ListSnapshotPoliciesCmd extends BaseListCmd {
4647
@Parameter(name = ApiConstants.VOLUME_ID, type = CommandType.UUID, entityType = VolumeResponse.class, required = true, description = "the ID of the disk volume")
4748
private Long volumeId;
4849

50+
@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})
51+
private Boolean display;
52+
4953
/////////////////////////////////////////////////////
5054
/////////////////// Accessors ///////////////////////
5155
/////////////////////////////////////////////////////
@@ -54,6 +58,14 @@ public Long getVolumeId() {
5458
return volumeId;
5559
}
5660

61+
@Override
62+
public boolean isDisplay() {
63+
if (display != null) {
64+
return display;
65+
}
66+
return true;
67+
}
68+
5769
/////////////////////////////////////////////////////
5870
/////////////// API Implementation///////////////////
5971
/////////////////////////////////////////////////////

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import com.google.gson.annotations.SerializedName;
2020

21+
import org.apache.cloudstack.acl.RoleType;
22+
import org.apache.cloudstack.api.ApiConstants;
2123
import org.apache.cloudstack.api.BaseResponse;
2224
import org.apache.cloudstack.api.EntityReference;
2325

@@ -50,6 +52,10 @@ public class SnapshotPolicyResponse extends BaseResponse {
5052
@Param(description = "the time zone of the snapshot policy")
5153
private String timezone;
5254

55+
@SerializedName(ApiConstants.FOR_DISPLAY)
56+
@Param(description = "is this policy for display to the regular user", since = "4.4", authorized = {RoleType.Admin})
57+
private Boolean forDisplay;
58+
5359
public String getId() {
5460
return id;
5561
}
@@ -97,4 +103,12 @@ public String getTimezone() {
97103
public void setTimezone(String timezone) {
98104
this.timezone = timezone;
99105
}
106+
107+
public Boolean getForDisplay() {
108+
return forDisplay;
109+
}
110+
111+
public void setForDisplay(Boolean forDisplay) {
112+
this.forDisplay = forDisplay;
113+
}
100114
}

‎engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@
254254
<bean id="snapshotDaoImpl" class="com.cloud.storage.dao.SnapshotDaoImpl" />
255255
<bean id="snapshotDetailsDaoImpl" class="com.cloud.storage.dao.SnapshotDetailsDaoImpl" />
256256
<bean id="snapshotPolicyDaoImpl" class="com.cloud.storage.dao.SnapshotPolicyDaoImpl" />
257+
<bean id="snapshotPolicyDetailsDaoImpl" class="org.apache.cloudstack.resourcedetail.dao.SnapshotPolicyDetailsDaoImpl" />
257258
<bean id="snapshotScheduleDaoImpl" class="com.cloud.storage.dao.SnapshotScheduleDaoImpl" />
258259
<bean id="sslCertDao" class="com.cloud.network.dao.SslCertDaoImpl" />
259260
<bean id="staticRouteDaoImpl" class="com.cloud.network.vpc.dao.StaticRouteDaoImpl" />

‎engine/schema/src/com/cloud/storage/SnapshotPolicyVO.java‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,21 @@ public class SnapshotPolicyVO implements SnapshotPolicy {
5858
@Column(name = "uuid")
5959
String uuid;
6060

61+
@Column(name = "display", updatable = true, nullable = false)
62+
protected boolean display = true;
63+
6164
public SnapshotPolicyVO() {
6265
this.uuid = UUID.randomUUID().toString();
6366
}
6467

65-
public SnapshotPolicyVO(long volumeId, String schedule, String timezone, IntervalType intvType, int maxSnaps) {
68+
public SnapshotPolicyVO(long volumeId, String schedule, String timezone, IntervalType intvType, int maxSnaps, boolean display) {
6669
this.volumeId = volumeId;
6770
this.schedule = schedule;
6871
this.timezone = timezone;
6972
this.interval = (short)intvType.ordinal();
7073
this.maxSnaps = maxSnaps;
7174
this.active = true;
75+
this.display = display;
7276
this.uuid = UUID.randomUUID().toString();
7377
}
7478

@@ -140,4 +144,12 @@ public String getUuid() {
140144
public void setUuid(String uuid) {
141145
this.uuid = uuid;
142146
}
147+
148+
public boolean isDisplay() {
149+
return display;
150+
}
151+
152+
public void setDisplay(boolean display) {
153+
this.display = display;
154+
}
143155
}

‎engine/schema/src/com/cloud/storage/dao/SnapshotPolicyDao.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public interface SnapshotPolicyDao extends GenericDao<SnapshotPolicyVO, Long> {
3232

3333
List<SnapshotPolicyVO> listByVolumeId(long volumeId, Filter filter);
3434

35-
Pair<List<SnapshotPolicyVO>, Integer> listAndCountByVolumeId(long volumeId);
35+
Pair<List<SnapshotPolicyVO>, Integer> listAndCountByVolumeId(long volumeId, boolean display);
3636

37-
Pair<List<SnapshotPolicyVO>, Integer> listAndCountByVolumeId(long volumeId, Filter filter);
37+
Pair<List<SnapshotPolicyVO>, Integer> listAndCountByVolumeId(long volumeId, boolean display, Filter filter);
3838

3939
SnapshotPolicyVO findOneByVolumeInterval(long volumeId, IntervalType intvType);
4040

‎engine/schema/src/com/cloud/storage/dao/SnapshotPolicyDaoImpl.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,15 @@ public List<SnapshotPolicyVO> listByVolumeId(long volumeId, Filter filter) {
6666
}
6767

6868
@Override
69-
public Pair<List<SnapshotPolicyVO>, Integer> listAndCountByVolumeId(long volumeId) {
70-
return listAndCountByVolumeId(volumeId, null);
69+
public Pair<List<SnapshotPolicyVO>, Integer> listAndCountByVolumeId(long volumeId, boolean display) {
70+
return listAndCountByVolumeId(volumeId, display, null);
7171
}
7272

7373
@Override
74-
public Pair<List<SnapshotPolicyVO>, Integer> listAndCountByVolumeId(long volumeId, Filter filter) {
74+
public Pair<List<SnapshotPolicyVO>, Integer> listAndCountByVolumeId(long volumeId, boolean display, Filter filter) {
7575
SearchCriteria<SnapshotPolicyVO> sc = VolumeIdSearch.create();
7676
sc.setParameters("volumeId", volumeId);
77+
sc.setParameters("display", display);
7778
sc.setParameters("active", true);
7879
return searchAndCount(sc, filter);
7980
}
@@ -82,6 +83,7 @@ protected SnapshotPolicyDaoImpl() {
8283
VolumeIdSearch = createSearchBuilder();
8384
VolumeIdSearch.and("volumeId", VolumeIdSearch.entity().getVolumeId(), SearchCriteria.Op.EQ);
8485
VolumeIdSearch.and("active", VolumeIdSearch.entity().isActive(), SearchCriteria.Op.EQ);
86+
VolumeIdSearch.and("display", VolumeIdSearch.entity().isDisplay(), SearchCriteria.Op.EQ);
8587
VolumeIdSearch.done();
8688

8789
VolumeIdIntervalSearch = createSearchBuilder();
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package org.apache.cloudstack.resourcedetail;
2+
3+
import org.apache.cloudstack.api.ResourceDetail;
4+
5+
import javax.persistence.Column;
6+
import javax.persistence.Entity;
7+
import javax.persistence.GeneratedValue;
8+
import javax.persistence.GenerationType;
9+
import javax.persistence.Id;
10+
import javax.persistence.Table;
11+
12+
@Entity
13+
@Table(name = "snapshot_policy_details")
14+
public class SnapshotPolicyDetailVO implements ResourceDetail {
15+
@Id
16+
@GeneratedValue(strategy = GenerationType.IDENTITY)
17+
@Column(name = "id")
18+
private long id;
19+
20+
@Column(name = "policy_id")
21+
private long resourceId;
22+
23+
@Column(name = "name")
24+
private String name;
25+
26+
@Column(name = "value", length = 1024)
27+
private String value;
28+
29+
@Column(name = "display")
30+
private boolean display = true;
31+
32+
public SnapshotPolicyDetailVO() {
33+
}
34+
35+
public SnapshotPolicyDetailVO(long id, String name, String value) {
36+
this.resourceId = id;
37+
this.name = name;
38+
this.value = value;
39+
}
40+
41+
@Override
42+
public long getId() {
43+
return id;
44+
}
45+
46+
@Override
47+
public String getName() {
48+
return name;
49+
}
50+
51+
@Override
52+
public String getValue() {
53+
return value;
54+
}
55+
56+
@Override
57+
public long getResourceId() {
58+
return resourceId;
59+
}
60+
61+
@Override
62+
public boolean isDisplay() {
63+
return display;
64+
}
65+
}

0 commit comments

Comments
 (0)