Skip to content

Commit 51e4f59

Browse files
author
Mice Xia
committed
fix CLOUDSTACK-3591 add usage recording for VM snapshots
Conflicts: plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java setup/db/db/schema-410to420.sql
1 parent 7e9e804 commit 51e4f59

17 files changed

Lines changed: 1699 additions & 46 deletions

File tree

api/src/com/cloud/agent/api/to/VolumeTO.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ protected VolumeTO() {
4141
private Long bytesWriteRate;
4242
private Long iopsReadRate;
4343
private Long iopsWriteRate;
44+
private Long chainSize;
4445

4546
public VolumeTO(long id, Volume.Type type, StoragePoolType poolType, String poolUuid, String name, String mountPoint, String path, long size, String chainInfo) {
4647
this.id = id;
@@ -77,6 +78,7 @@ public VolumeTO(Volume volume, StoragePool pool) {
7778
this.storagePoolUuid = pool.getUuid();
7879
this.mountPoint = volume.getFolder();
7980
this.chainInfo = volume.getChainInfo();
81+
this.chainSize = volume.getVmSnapshotChainSize();
8082
if (volume.getDeviceId() != null)
8183
this.deviceId = volume.getDeviceId();
8284
}
@@ -170,4 +172,11 @@ public Long getIopsWriteRate() {
170172
return iopsWriteRate;
171173
}
172174

175+
public Long getChainSize() {
176+
return chainSize;
177+
}
178+
179+
public void setChainSize(Long chainSize) {
180+
this.chainSize = chainSize;
181+
}
173182
}

api/src/com/cloud/storage/Volume.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,5 @@ enum Event {
184184
*/
185185
void setReservationId(String reserv);
186186
Storage.ImageFormat getFormat();
187+
Long getVmSnapshotChainSize();
187188
}

api/src/org/apache/cloudstack/usage/UsageTypes.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class UsageTypes {
4040
public static final int VM_DISK_IO_WRITE = 22;
4141
public static final int VM_DISK_BYTES_READ = 23;
4242
public static final int VM_DISK_BYTES_WRITE = 24;
43+
public static final int VM_SNAPSHOT = 25;
4344

4445
public static List<UsageTypeResponse> listUsageTypes(){
4546
List<UsageTypeResponse> responseList = new ArrayList<UsageTypeResponse>();
@@ -61,6 +62,7 @@ public static List<UsageTypeResponse> listUsageTypes(){
6162
responseList.add(new UsageTypeResponse(VM_DISK_IO_WRITE, "VM Disk usage(I/O Write)"));
6263
responseList.add(new UsageTypeResponse(VM_DISK_BYTES_READ, "VM Disk usage(Bytes Read)"));
6364
responseList.add(new UsageTypeResponse(VM_DISK_BYTES_WRITE, "VM Disk usage(Bytes Write)"));
65+
responseList.add(new UsageTypeResponse(VM_SNAPSHOT, "VM Snapshot storage usage"));
6466
return responseList;
6567
}
6668
}

engine/schema/src/com/cloud/storage/VolumeVO.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ public class VolumeVO implements Volume {
150150
@Column(name = "iscsi_name")
151151
private String _iScsiName;
152152

153+
@Column(name = "vm_snapshot_chain_size")
154+
private Long vmSnapshotChainSize;
155+
153156
@Transient
154157
// @Column(name="reservation")
155158
String reservationId;
@@ -550,4 +553,12 @@ public Storage.ImageFormat getFormat() {
550553
public void setFormat(Storage.ImageFormat format) {
551554
this.format = format;
552555
}
556+
557+
public void setVmSnapshotChainSize(Long vmSnapshotChainSize){
558+
this.vmSnapshotChainSize = vmSnapshotChainSize;
559+
}
560+
561+
public Long getVmSnapshotChainSize(){
562+
return this.vmSnapshotChainSize;
563+
}
553564
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.usage;
18+
19+
import java.util.Date;
20+
21+
import javax.persistence.Column;
22+
import javax.persistence.Entity;
23+
import javax.persistence.Table;
24+
import javax.persistence.Temporal;
25+
import javax.persistence.TemporalType;
26+
27+
import org.apache.cloudstack.api.InternalIdentity;
28+
29+
@Entity
30+
@Table(name="usage_vmsnapshot")
31+
public class UsageVMSnapshotVO implements InternalIdentity {
32+
33+
@Column(name="id") // volumeId
34+
private long id;
35+
36+
@Column(name="zone_id")
37+
private long zoneId;
38+
39+
@Column(name="account_id")
40+
private long accountId;
41+
42+
@Column(name="domain_id")
43+
private long domainId;
44+
45+
@Column(name="vm_id")
46+
private long vmId;
47+
48+
@Column(name="disk_offering_id")
49+
private Long diskOfferingId;
50+
51+
@Column(name="size")
52+
private long size;
53+
54+
@Column(name="created")
55+
@Temporal(value=TemporalType.TIMESTAMP)
56+
private Date created = null;
57+
58+
@Column(name="processed")
59+
@Temporal(value=TemporalType.TIMESTAMP)
60+
private Date processed;
61+
62+
protected UsageVMSnapshotVO() {
63+
}
64+
65+
public UsageVMSnapshotVO(long id, long zoneId, long accountId, long domainId,
66+
long vmId, Long diskOfferingId, long size, Date created, Date processed) {
67+
this.zoneId = zoneId;
68+
this.accountId = accountId;
69+
this.domainId = domainId;
70+
this.diskOfferingId = diskOfferingId;
71+
this.id = id;
72+
this.size = size;
73+
this.created = created;
74+
this.vmId = vmId;
75+
this.processed = processed;
76+
}
77+
78+
public long getZoneId() {
79+
return zoneId;
80+
}
81+
82+
public long getAccountId() {
83+
return accountId;
84+
}
85+
86+
public long getDomainId() {
87+
return domainId;
88+
}
89+
90+
public Long getDiskOfferingId() {
91+
return diskOfferingId;
92+
}
93+
94+
public long getSize() {
95+
return size;
96+
}
97+
98+
public Date getProcessed() {
99+
return processed;
100+
}
101+
102+
public void setProcessed(Date processed) {
103+
this.processed = processed;
104+
}
105+
106+
public Date getCreated() {
107+
return created;
108+
}
109+
110+
public void setCreated(Date created) {
111+
this.created = created;
112+
}
113+
114+
public long getVmId() {
115+
return vmId;
116+
}
117+
118+
public long getId(){
119+
return this.id;
120+
}
121+
122+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.usage.dao;
18+
19+
import java.util.Date;
20+
import java.util.List;
21+
22+
import com.cloud.usage.UsageVMSnapshotVO;
23+
import com.cloud.utils.db.GenericDao;
24+
25+
public interface UsageVMSnapshotDao extends GenericDao<UsageVMSnapshotVO, Long> {
26+
public void update(UsageVMSnapshotVO usage);
27+
public List<UsageVMSnapshotVO> getUsageRecords(Long accountId, Long domainId, Date startDate, Date endDate);
28+
UsageVMSnapshotVO getPreviousUsageRecord(UsageVMSnapshotVO rec);
29+
}

0 commit comments

Comments
 (0)