You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ki...@apache.org on 2013/07/24 14:50:53 UTC
[1/2] git commit: updated refs/heads/4.2 to 743d35c
Updated Branches:
refs/heads/4.2 1e64df854 -> 743d35cae
CLOUDSTACK-3612: DB changes for template virtual size usage
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/743d35ca
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/743d35ca
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/743d35ca
Branch: refs/heads/4.2
Commit: 743d35cae4985a8d898da06e5768ae282b32adb2
Parents: d89115b
Author: Saksham Srivastava <sa...@citrix.com>
Authored: Wed Jul 24 18:06:22 2013 +0530
Committer: Kishan Kavala <ki...@cloud.com>
Committed: Wed Jul 24 18:20:37 2013 +0530
----------------------------------------------------------------------
setup/db/db/schema-410to420.sql | 5 +++++
1 file changed, 5 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/743d35ca/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql
index f9417a0..8409c47 100644
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@ -2151,3 +2151,8 @@ INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'manag
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'vmsnapshot.max', '10', 'Maximum vm snapshots for a VM');
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'vmsnapshot.create.wait', '1800','In second, timeout for create vm snapshot');
+
+ALTER TABLE `cloud`.`usage_event` ADD COLUMN `virtual_size` bigint unsigned;
+ALTER TABLE `cloud_usage`.`usage_event` ADD COLUMN `virtual_size` bigint unsigned;
+ALTER TABLE `cloud_usage`.`usage_storage` ADD COLUMN `virtual_size` bigint unsigned;
+ALTER TABLE `cloud_usage`.`cloud_usage` ADD COLUMN `virtual_size` bigint unsigned;
[2/2] git commit: updated refs/heads/4.2 to 743d35c
Posted by ki...@apache.org.
CLOUDSTACK-2508: Template usage should report both physical and virtual sizes
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/d89115b5
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/d89115b5
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/d89115b5
Branch: refs/heads/4.2
Commit: d89115b5cff9013c917c8d2e984c596698389cfe
Parents: 1e64df8
Author: Saksham Srivastava <sa...@citrix.com>
Authored: Mon Jul 22 12:52:55 2013 +0530
Committer: Kishan Kavala <ki...@cloud.com>
Committed: Wed Jul 24 18:20:37 2013 +0530
----------------------------------------------------------------------
.../api/response/UsageRecordResponse.java | 7 ++++
api/src/org/apache/cloudstack/usage/Usage.java | 2 ++
.../src/com/cloud/event/UsageEventVO.java | 28 ++++++++++++++--
.../com/cloud/event/dao/UsageEventDaoImpl.java | 8 ++---
.../src/com/cloud/usage/UsageStorageVO.java | 22 ++++++++++++-
engine/schema/src/com/cloud/usage/UsageVO.java | 34 ++++++++++++++++++--
.../src/com/cloud/usage/dao/UsageDaoImpl.java | 7 +++-
.../cloud/usage/dao/UsageStorageDaoImpl.java | 9 +++---
server/src/com/cloud/api/ApiResponseHelper.java | 5 +++
server/src/com/cloud/event/UsageEventUtils.java | 11 +++++++
.../com/cloud/template/TemplateManagerImpl.java | 8 +++--
usage/src/com/cloud/usage/UsageManagerImpl.java | 4 +--
.../cloud/usage/parser/StorageUsageParser.java | 21 ++++++++----
13 files changed, 140 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d89115b5/api/src/org/apache/cloudstack/api/response/UsageRecordResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/response/UsageRecordResponse.java b/api/src/org/apache/cloudstack/api/response/UsageRecordResponse.java
index 4b355cb..4180ee9 100644
--- a/api/src/org/apache/cloudstack/api/response/UsageRecordResponse.java
+++ b/api/src/org/apache/cloudstack/api/response/UsageRecordResponse.java
@@ -78,6 +78,9 @@ public class UsageRecordResponse extends BaseResponse implements ControlledEntit
@SerializedName(ApiConstants.SIZE) @Param(description="resource size")
private Long size;
+ @SerializedName("virtualsize") @Param(description="virtual size of resource")
+ private Long virtualSize;
+
@SerializedName(ApiConstants.START_DATE) @Param(description="start date of the usage record")
private String startDate;
@@ -196,4 +199,8 @@ public class UsageRecordResponse extends BaseResponse implements ControlledEntit
public void setDefault(Boolean isDefault) {
this.isDefault = isDefault;
}
+
+ public void setVirtualSize(Long virtualSize) {
+ this.virtualSize = virtualSize;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d89115b5/api/src/org/apache/cloudstack/usage/Usage.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/usage/Usage.java b/api/src/org/apache/cloudstack/usage/Usage.java
index c74d3b7..23f9d42 100644
--- a/api/src/org/apache/cloudstack/usage/Usage.java
+++ b/api/src/org/apache/cloudstack/usage/Usage.java
@@ -66,4 +66,6 @@ public interface Usage {
public Date getStartDate();
public Date getEndDate();
+
+ public Long getVirtualSize();
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d89115b5/engine/schema/src/com/cloud/event/UsageEventVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/event/UsageEventVO.java b/engine/schema/src/com/cloud/event/UsageEventVO.java
index c92972b..6fad8c9 100644
--- a/engine/schema/src/com/cloud/event/UsageEventVO.java
+++ b/engine/schema/src/com/cloud/event/UsageEventVO.java
@@ -69,6 +69,9 @@ public class UsageEventVO implements UsageEvent {
@Column(name="processed")
boolean processed;
+ @Column(name="virtual_size")
+ private Long virtualSize;
+
public UsageEventVO() {
}
@@ -103,7 +106,20 @@ public class UsageEventVO implements UsageEvent {
this.resourceType = guestType;
this.templateId = (isSystem ? 1L : 0L);
}
-
+ //Snapshot usage event
+ //Snapshots have size as the actual (physical) size and virtual_size as the allocated size
+ public UsageEventVO(String usageType, long accountId, long zoneId, long resourceId, String resourceName, Long offeringId, Long templateId, Long size, Long virtualSize) {
+ this.type = usageType;
+ this.accountId = accountId;
+ this.zoneId = zoneId;
+ this.resourceId = resourceId;
+ this.resourceName = resourceName;
+ this.offeringId = offeringId;
+ this.templateId = templateId;
+ this.size = size;
+ this.virtualSize = virtualSize;
+ }
+
public UsageEventVO(String usageType, long accountId, long zoneId, long resourceId, String resourceName, Long offeringId, Long templateId, String resourceType) {
this.type = usageType;
this.accountId = accountId;
@@ -213,4 +229,12 @@ public class UsageEventVO implements UsageEvent {
return resourceType;
}
-}
+ public Long getVirtualSize() {
+ return virtualSize;
+ }
+
+ public void setVirtualSize(Long virtualSize) {
+ this.virtualSize = virtualSize;
+ }
+
+ }
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d89115b5/engine/schema/src/com/cloud/event/dao/UsageEventDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/event/dao/UsageEventDaoImpl.java b/engine/schema/src/com/cloud/event/dao/UsageEventDaoImpl.java
index 004ab7c..cda02ef 100644
--- a/engine/schema/src/com/cloud/event/dao/UsageEventDaoImpl.java
+++ b/engine/schema/src/com/cloud/event/dao/UsageEventDaoImpl.java
@@ -46,10 +46,10 @@ public class UsageEventDaoImpl extends GenericDaoBase<UsageEventVO, Long> implem
private final SearchBuilder<UsageEventVO> latestEventsSearch;
private final SearchBuilder<UsageEventVO> IpeventsSearch;
- private static final String COPY_EVENTS = "INSERT INTO cloud_usage.usage_event (id, type, account_id, created, zone_id, resource_id, resource_name, offering_id, template_id, size, resource_type) " +
- "SELECT id, type, account_id, created, zone_id, resource_id, resource_name, offering_id, template_id, size, resource_type FROM cloud.usage_event vmevt WHERE vmevt.id > ? and vmevt.id <= ? ";
- private static final String COPY_ALL_EVENTS = "INSERT INTO cloud_usage.usage_event (id, type, account_id, created, zone_id, resource_id, resource_name, offering_id, template_id, size, resource_type) " +
- "SELECT id, type, account_id, created, zone_id, resource_id, resource_name, offering_id, template_id, size, resource_type FROM cloud.usage_event vmevt WHERE vmevt.id <= ?";
+ private static final String COPY_EVENTS = "INSERT INTO cloud_usage.usage_event (id, type, account_id, created, zone_id, resource_id, resource_name, offering_id, template_id, size, resource_type, virtual_size) " +
+ "SELECT id, type, account_id, created, zone_id, resource_id, resource_name, offering_id, template_id, size, resource_type, virtual_size FROM cloud.usage_event vmevt WHERE vmevt.id > ? and vmevt.id <= ? ";
+ private static final String COPY_ALL_EVENTS = "INSERT INTO cloud_usage.usage_event (id, type, account_id, created, zone_id, resource_id, resource_name, offering_id, template_id, size, resource_type, virtual_size) " +
+ "SELECT id, type, account_id, created, zone_id, resource_id, resource_name, offering_id, template_id, size, resource_type, virtual_size FROM cloud.usage_event vmevt WHERE vmevt.id <= ?";
private static final String MAX_EVENT = "select max(id) from cloud.usage_event where created <= ?";
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d89115b5/engine/schema/src/com/cloud/usage/UsageStorageVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/usage/UsageStorageVO.java b/engine/schema/src/com/cloud/usage/UsageStorageVO.java
index 1337edc..ec4ea4c 100644
--- a/engine/schema/src/com/cloud/usage/UsageStorageVO.java
+++ b/engine/schema/src/com/cloud/usage/UsageStorageVO.java
@@ -59,6 +59,9 @@ public class UsageStorageVO implements InternalIdentity {
@Temporal(value=TemporalType.TIMESTAMP)
private Date deleted = null;
+ @Column(name="virtual_size")
+ private Long virtualSize;
+
protected UsageStorageVO() {
}
@@ -74,6 +77,19 @@ public class UsageStorageVO implements InternalIdentity {
this.deleted = deleted;
}
+ public UsageStorageVO(long id, long zoneId, long accountId, long domainId, int storageType, Long sourceId, long size, Long virtualSize, Date created, Date deleted) {
+ this.zoneId = zoneId;
+ this.accountId = accountId;
+ this.domainId = domainId;
+ this.id = id;
+ this.storageType = storageType;
+ this.sourceId = sourceId;
+ this.size = size;
+ this.virtualSize = virtualSize;
+ this.created = created;
+ this.deleted = deleted;
+ }
+
public long getZoneId() {
return zoneId;
}
@@ -101,7 +117,11 @@ public class UsageStorageVO implements InternalIdentity {
public long getSize(){
return size;
}
-
+
+ public Long getVirtualSize() {
+ return virtualSize;
+ }
+
public Date getCreated() {
return created;
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d89115b5/engine/schema/src/com/cloud/usage/UsageVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/usage/UsageVO.java b/engine/schema/src/com/cloud/usage/UsageVO.java
index 18a3a6b..21bd3e1 100644
--- a/engine/schema/src/com/cloud/usage/UsageVO.java
+++ b/engine/schema/src/com/cloud/usage/UsageVO.java
@@ -79,7 +79,10 @@ public class UsageVO implements Usage, InternalIdentity {
@Column(name="size")
private Long size = null;
-
+
+ @Column(name="virtual_size")
+ private Long virtualSize;
+
@Column(name="network_id")
private Long networkId = null;
@@ -114,7 +117,28 @@ public class UsageVO implements Usage, InternalIdentity {
this.startDate = startDate;
this.endDate = endDate;
}
-
+
+ public UsageVO(Long zoneId, Long accountId, Long domainId, String description, String usageDisplay,
+ int usageType, Double rawUsage, Long vmId, String vmName, Long offeringId, Long templateId,
+ Long usageId, Long size, Long virtualSize, Date startDate, Date endDate) {
+ this.zoneId = zoneId;
+ this.accountId = accountId;
+ this.domainId = domainId;
+ this.description = description;
+ this.usageDisplay = usageDisplay;
+ this.usageType = usageType;
+ this.rawUsage = rawUsage;
+ this.vmInstanceId = vmId;
+ this.vmName = vmName;
+ this.offeringId = offeringId;
+ this.templateId = templateId;
+ this.usageId = usageId;
+ this.size = size;
+ this.virtualSize = virtualSize;
+ this.startDate = startDate;
+ this.endDate = endDate;
+}
+
public UsageVO(Long zoneId, Long accountId, Long domainId, String description, String usageDisplay,
int usageType, Double rawUsage, Long usageId, String type, Long networkId, Date startDate, Date endDate) {
this.zoneId = zoneId;
@@ -247,7 +271,11 @@ public class UsageVO implements Usage, InternalIdentity {
public Long getSize() {
return size;
}
-
+
+ public Long getVirtualSize() {
+ return virtualSize;
+ }
+
@Override
public Date getStartDate() {
return startDate;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d89115b5/engine/schema/src/com/cloud/usage/dao/UsageDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/usage/dao/UsageDaoImpl.java b/engine/schema/src/com/cloud/usage/dao/UsageDaoImpl.java
index 2237d56..bd7b6b7 100644
--- a/engine/schema/src/com/cloud/usage/dao/UsageDaoImpl.java
+++ b/engine/schema/src/com/cloud/usage/dao/UsageDaoImpl.java
@@ -65,7 +65,7 @@ public class UsageDaoImpl extends GenericDaoBase<UsageVO, Long> implements Usage
private static final String UPDATE_VM_DISK_STATS = "UPDATE cloud_usage.vm_disk_statistics SET net_io_read=?, net_io_write=?, current_io_read=?, current_io_write=?, agg_io_read=?, agg_io_write=?, " +
"net_bytes_read=?, net_bytes_write=?, current_bytes_read=?, current_bytes_write=?, agg_bytes_read=?, agg_bytes_write=? WHERE id=?";
private static final String INSERT_USGAE_RECORDS = "INSERT INTO cloud_usage.cloud_usage (zone_id, account_id, domain_id, description, usage_display, usage_type, raw_usage, vm_instance_id, vm_name, offering_id, template_id, " +
- "usage_id, type, size, network_id, start_date, end_date) VALUES (?,?,?,?,?,?,?,?,?, ?, ?, ?,?,?,?,?,?)";
+ "usage_id, type, size, network_id, start_date, end_date, virtual_size) VALUES (?,?,?,?,?,?,?,?,?, ?, ?, ?,?,?,?,?,?)";
protected final static TimeZone s_gmtTimeZone = TimeZone.getTimeZone("GMT");
@@ -429,6 +429,11 @@ public class UsageDaoImpl extends GenericDaoBase<UsageVO, Long> implements Usage
}
pstmt.setTimestamp(16, new Timestamp(usageRecord.getStartDate().getTime()));
pstmt.setTimestamp(17, new Timestamp(usageRecord.getEndDate().getTime()));
+ if(usageRecord.getVirtualSize() != null){
+ pstmt.setLong(18, usageRecord.getSize());
+ } else {
+ pstmt.setNull(18, Types.BIGINT);
+ }
pstmt.addBatch();
}
pstmt.executeBatch();
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d89115b5/engine/schema/src/com/cloud/usage/dao/UsageStorageDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/usage/dao/UsageStorageDaoImpl.java b/engine/schema/src/com/cloud/usage/dao/UsageStorageDaoImpl.java
index 297c8f4..8f18adc 100644
--- a/engine/schema/src/com/cloud/usage/dao/UsageStorageDaoImpl.java
+++ b/engine/schema/src/com/cloud/usage/dao/UsageStorageDaoImpl.java
@@ -42,15 +42,15 @@ public class UsageStorageDaoImpl extends GenericDaoBase<UsageStorageVO, Long> im
protected static final String REMOVE_BY_USERID_STORAGEID = "DELETE FROM usage_storage WHERE account_id = ? AND id = ? AND storage_type = ?";
protected static final String UPDATE_DELETED = "UPDATE usage_storage SET deleted = ? WHERE account_id = ? AND id = ? AND storage_type = ? and deleted IS NULL";
- protected static final String GET_USAGE_RECORDS_BY_ACCOUNT = "SELECT id, zone_id, account_id, domain_id, storage_type, source_id, size, created, deleted " +
+ protected static final String GET_USAGE_RECORDS_BY_ACCOUNT = "SELECT id, zone_id, account_id, domain_id, storage_type, source_id, size, created, deleted, virtual_size " +
"FROM usage_storage " +
"WHERE account_id = ? AND ((deleted IS NULL) OR (created BETWEEN ? AND ?) OR " +
" (deleted BETWEEN ? AND ?) OR ((created <= ?) AND (deleted >= ?)))";
- protected static final String GET_USAGE_RECORDS_BY_DOMAIN = "SELECT id, zone_id, account_id, domain_id, storage_type, source_id, size, created, deleted " +
+ protected static final String GET_USAGE_RECORDS_BY_DOMAIN = "SELECT id, zone_id, account_id, domain_id, storage_type, source_id, size, created, deleted, virtual_size " +
"FROM usage_storage " +
"WHERE domain_id = ? AND ((deleted IS NULL) OR (created BETWEEN ? AND ?) OR " +
" (deleted BETWEEN ? AND ?) OR ((created <= ?) AND (deleted >= ?)))";
- protected static final String GET_ALL_USAGE_RECORDS = "SELECT id, zone_id, account_id, domain_id, storage_type, source_id, size, created, deleted " +
+ protected static final String GET_ALL_USAGE_RECORDS = "SELECT id, zone_id, account_id, domain_id, storage_type, source_id, size, created, deleted, virtual_size " +
"FROM usage_storage " +
"WHERE (deleted IS NULL) OR (created BETWEEN ? AND ?) OR " +
" (deleted BETWEEN ? AND ?) OR ((created <= ?) AND (deleted >= ?))";
@@ -184,6 +184,7 @@ public class UsageStorageDaoImpl extends GenericDaoBase<UsageStorageVO, Long> im
Integer type = Integer.valueOf(rs.getInt(5));
Long sourceId = Long.valueOf(rs.getLong(6));
Long size = Long.valueOf(rs.getLong(7));
+ Long virtualSize = Long.valueOf(rs.getLong(10));
Date createdDate = null;
Date deletedDate = null;
String createdTS = rs.getString(8);
@@ -197,7 +198,7 @@ public class UsageStorageDaoImpl extends GenericDaoBase<UsageStorageVO, Long> im
deletedDate = DateUtil.parseDateString(s_gmtTimeZone, deletedTS);
}
- usageRecords.add(new UsageStorageVO(id, zoneId, acctId, dId, type, sourceId, size, createdDate, deletedDate));
+ usageRecords.add(new UsageStorageVO(id, zoneId, acctId, dId, type, sourceId, size, virtualSize, createdDate, deletedDate));
}
} catch (Exception e) {
txn.rollback();
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d89115b5/server/src/com/cloud/api/ApiResponseHelper.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java
index e058105..ec977ec 100755
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -3366,6 +3366,11 @@ public class ApiResponseHelper implements ResponseGenerator {
usageRecResponse.setUsageId(tmpl.getUuid());
//Template/ISO Size
usageRecResponse.setSize(usageRecord.getSize());
+ if(usageRecord.getUsageType() == UsageTypes.ISO) {
+ usageRecResponse.setVirtualSize(usageRecord.getSize());
+ } else {
+ usageRecResponse.setVirtualSize(usageRecord.getVirtualSize());
+ }
} else if(usageRecord.getUsageType() == UsageTypes.SNAPSHOT){
//Snapshot ID
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d89115b5/server/src/com/cloud/event/UsageEventUtils.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/event/UsageEventUtils.java b/server/src/com/cloud/event/UsageEventUtils.java
index 2d92fae..2e42229 100644
--- a/server/src/com/cloud/event/UsageEventUtils.java
+++ b/server/src/com/cloud/event/UsageEventUtils.java
@@ -67,6 +67,14 @@ public class UsageEventUtils {
publishUsageEvent(usageType, accountId, zoneId, entityType, entityUUID);
}
+ public static void publishUsageEvent(String usageType, long accountId, long zoneId,
+ long resourceId, String resourceName,
+ Long offeringId, Long templateId, Long size, Long virtualSize,
+ String entityType, String entityUUID) {
+ saveUsageEvent(usageType, accountId, zoneId, resourceId, resourceName, offeringId, templateId, size, virtualSize);
+ publishUsageEvent(usageType, accountId, zoneId, entityType, entityUUID);
+ }
+
public static void publishUsageEvent(String usageType, long accountId, long zoneId, long resourceId,
String resourceName, String entityType, String entityUUID) {
saveUsageEvent(usageType, accountId, zoneId, resourceId, resourceName);
@@ -97,6 +105,9 @@ public class UsageEventUtils {
_usageEventDao.persist( new UsageEventVO(usageType, accountId, zoneId, resourceId, resourceName, offeringId, templateId, size));
}
+ public static void saveUsageEvent(String usageType, long accountId, long zoneId, long resourceId, String resourceName, Long offeringId, Long templateId, Long size, Long virtualSize) {
+ _usageEventDao.persist( new UsageEventVO(usageType, accountId, zoneId, resourceId, resourceName, offeringId, templateId, size, virtualSize));
+ }
public static void saveUsageEvent(String usageType, long accountId, long zoneId, long resourceId, String resourceName) {
_usageEventDao.persist( new UsageEventVO(usageType, accountId, zoneId, resourceId, resourceName));
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d89115b5/server/src/com/cloud/template/TemplateManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java
index c87f8eb..cde14ff 100755
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@ -149,6 +149,7 @@ import com.cloud.storage.dao.StoragePoolHostDao;
import com.cloud.storage.dao.UploadDao;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.storage.dao.VMTemplateDetailsDao;
+import com.cloud.storage.dao.VMTemplateHostDao;
import com.cloud.storage.dao.VMTemplatePoolDao;
import com.cloud.storage.dao.VMTemplateS3Dao;
import com.cloud.storage.dao.VMTemplateZoneDao;
@@ -282,6 +283,8 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
EndPointSelector _epSelector;
@Inject
UserVmJoinDao _userVmJoinDao;
+ @Inject
+ VMTemplateHostDao _vmTemplateHostDao;
@Inject
ConfigurationServer _configServer;
@@ -658,7 +661,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
_tmpltDao.addTemplateToZone(template, dstZoneId);
if (account.getId() != Account.ACCOUNT_ID_SYSTEM) {
- UsageEventUtils.publishUsageEvent(copyEventType, account.getId(), dstZoneId, tmpltId, null, null, null, srcTmpltStore.getSize(),
+ UsageEventUtils.publishUsageEvent(copyEventType, account.getId(), dstZoneId, tmpltId, null, null, null, srcTmpltStore.getPhysicalSize(), srcTmpltStore.getSize(),
template.getClass().getName(), template.getUuid());
}
return true;
@@ -1372,8 +1375,9 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
this._tmpltZoneDao.persist(templateZone);
privateTemplate = this._tmpltDao.findById(templateId);
+ TemplateDataStoreVO srcTmpltStore = this._tmplStoreDao.findByStoreTemplate(store.getId(), templateId);
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_TEMPLATE_CREATE, privateTemplate.getAccountId(), zoneId,
- privateTemplate.getId(), privateTemplate.getName(), null, privateTemplate.getSourceTemplateId(), privateTemplate.getSize());
+ privateTemplate.getId(), privateTemplate.getName(), null, privateTemplate.getSourceTemplateId(), srcTmpltStore.getPhysicalSize(), privateTemplate.getSize());
_usageEventDao.persist(usageEvent);
} catch (InterruptedException e) {
s_logger.debug("Failed to create template", e);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d89115b5/usage/src/com/cloud/usage/UsageManagerImpl.java
----------------------------------------------------------------------
diff --git a/usage/src/com/cloud/usage/UsageManagerImpl.java b/usage/src/com/cloud/usage/UsageManagerImpl.java
index 4901dd9..aa9def5 100644
--- a/usage/src/com/cloud/usage/UsageManagerImpl.java
+++ b/usage/src/com/cloud/usage/UsageManagerImpl.java
@@ -1297,7 +1297,7 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager, Runna
}
Account acct = m_accountDao.findByIdIncludingRemoved(event.getAccountId());
UsageStorageVO storageVO = new UsageStorageVO(templateId, zoneId, event.getAccountId(), acct.getDomainId(), StorageTypes.TEMPLATE, event.getTemplateId(),
- templateSize, event.getCreateDate(), null);
+ templateSize, event.getVirtualSize(), event.getCreateDate(), null);
m_usageStorageDao.persist(storageVO);
} else if (EventTypes.EVENT_TEMPLATE_DELETE.equals(event.getType())) {
List<UsageStorageVO> storageVOs;
@@ -1339,7 +1339,7 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager, Runna
}
Account acct = m_accountDao.findByIdIncludingRemoved(event.getAccountId());
UsageStorageVO storageVO = new UsageStorageVO( isoId, zoneId, event.getAccountId(), acct.getDomainId(), StorageTypes.ISO, null,
- isoSize, event.getCreateDate(), null);
+ isoSize, isoSize, event.getCreateDate(), null);
m_usageStorageDao.persist(storageVO);
} else if (EventTypes.EVENT_ISO_DELETE.equals(event.getType())) {
List<UsageStorageVO> storageVOs;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d89115b5/usage/src/com/cloud/usage/parser/StorageUsageParser.java
----------------------------------------------------------------------
diff --git a/usage/src/com/cloud/usage/parser/StorageUsageParser.java b/usage/src/com/cloud/usage/parser/StorageUsageParser.java
index 337e8e2..56c26e8 100644
--- a/usage/src/com/cloud/usage/parser/StorageUsageParser.java
+++ b/usage/src/com/cloud/usage/parser/StorageUsageParser.java
@@ -84,13 +84,14 @@ public class StorageUsageParser {
long storageId = usageStorage.getId();
int storage_type = usageStorage.getStorageType();
long size = usageStorage.getSize();
+ Long virtualSize = usageStorage.getVirtualSize();
long zoneId = usageStorage.getZoneId();
Long sourceId = usageStorage.getSourceId();
String key = ""+storageId+"Z"+zoneId+"T"+storage_type;
// store the info in the storage map
- storageMap.put(key, new StorageInfo(zoneId, storageId, storage_type, sourceId, size));
+ storageMap.put(key, new StorageInfo(zoneId, storageId, storage_type, sourceId, size, virtualSize));
Date storageCreateDate = usageStorage.getCreated();
Date storageDeleteDate = usageStorage.getDeleted();
@@ -116,7 +117,7 @@ public class StorageUsageParser {
// Only create a usage record if we have a runningTime of bigger than zero.
if (useTime > 0L) {
StorageInfo info = storageMap.get(storageIdKey);
- createUsageRecord(info.getZoneId(), info.getStorageType(), useTime, startDate, endDate, account, info.getStorageId(), info.getSourceId(), info.getSize());
+ createUsageRecord(info.getZoneId(), info.getStorageType(), useTime, startDate, endDate, account, info.getStorageId(), info.getSourceId(), info.getSize(), info.getVirtualSize());
}
}
@@ -135,7 +136,7 @@ public class StorageUsageParser {
usageDataMap.put(key, volUsageInfo);
}
- private static void createUsageRecord(long zoneId, int type, long runningTime, Date startDate, Date endDate, AccountVO account, long storageId, Long sourceId, long size) {
+ private static void createUsageRecord(long zoneId, int type, long runningTime, Date startDate, Date endDate, AccountVO account, long storageId, Long sourceId, long size, Long virtualSize) {
// Our smallest increment is hourly for now
if (s_logger.isDebugEnabled()) {
s_logger.debug("Total running time " + runningTime + "ms");
@@ -163,6 +164,7 @@ public class StorageUsageParser {
case StorageTypes.ISO:
usage_type = UsageTypes.ISO;
usageDesc += "ISO ";
+ virtualSize = size;
break;
case StorageTypes.SNAPSHOT:
usage_type = UsageTypes.SNAPSHOT;
@@ -170,11 +172,11 @@ public class StorageUsageParser {
break;
}
// Create the usage record
- usageDesc += "Id:"+storageId+" Size:"+size;
+ usageDesc += "Id:"+storageId+" Size:"+size+ "VirtualSize:" + virtualSize;
//ToDo: get zone id
UsageVO usageRecord = new UsageVO(zoneId, account.getId(), account.getDomainId(), usageDesc, usageDisplay + " Hrs", usage_type,
- new Double(usage), null, null, null, tmplSourceId, storageId, size, startDate, endDate);
+ new Double(usage), null, null, null, tmplSourceId, storageId, size, virtualSize, startDate, endDate);
m_usageDao.persist(usageRecord);
}
@@ -184,13 +186,19 @@ public class StorageUsageParser {
private int storageType;
private Long sourceId;
private long size;
+ private Long virtualSize;
- public StorageInfo(long zoneId, long storageId, int storageType, Long sourceId, long size) {
+ public StorageInfo(long zoneId, long storageId, int storageType, Long sourceId, long size, Long virtualSize) {
this.zoneId = zoneId;
this.storageId = storageId;
this.storageType = storageType;
this.sourceId = sourceId;
this.size = size;
+ this.virtualSize = virtualSize;
+ }
+
+ public Long getVirtualSize() {
+ return virtualSize;
}
public long getZoneId() {
@@ -209,7 +217,6 @@ public class StorageUsageParser {
return sourceId;
}
-
public long getSize() {
return size;
}