cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kis...@apache.org
Subject [1/2] git commit: updated refs/heads/master to 2b9d9cf
Date Wed, 24 Jul 2013 12:50:17 GMT
Updated Branches:
  refs/heads/master 64c120c0d -> 2b9d9cf03


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/135a2e66
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/135a2e66
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/135a2e66

Branch: refs/heads/master
Commit: 135a2e66c565044b6597e9178c3cf3d544712cca
Parents: 64c120c
Author: Saksham Srivastava <saksham.srivastava@citrix.com>
Authored: Mon Jul 22 12:52:55 2013 +0530
Committer: Kishan Kavala <kishan@cloud.com>
Committed: Wed Jul 24 18:17:09 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/135a2e66/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/135a2e66/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/135a2e66/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/135a2e66/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/135a2e66/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/135a2e66/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/135a2e66/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/135a2e66/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/135a2e66/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 19f8037..e49e169 100755
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -3369,6 +3369,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/135a2e66/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/135a2e66/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 6b850d7..228591b 100755
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@ -148,6 +148,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;
@@ -279,6 +280,8 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
     EndPointSelector _epSelector;
     @Inject
     UserVmJoinDao _userVmJoinDao;
+    @Inject
+    VMTemplateHostDao _vmTemplateHostDao;
 
     @Inject
     ConfigurationServer _configServer;
@@ -655,7 +658,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;
@@ -1369,8 +1372,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/135a2e66/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/135a2e66/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;
         }        


Mime
View raw message