diff --git a/api/src/main/java/com/cloud/event/EventTypes.java b/api/src/main/java/com/cloud/event/EventTypes.java
index 01ad12a71e08..113757f28b53 100644
--- a/api/src/main/java/com/cloud/event/EventTypes.java
+++ b/api/src/main/java/com/cloud/event/EventTypes.java
@@ -319,6 +319,8 @@ public class EventTypes {
public static final String EVENT_VOLUME_IMPORT = "VOLUME.IMPORT";
public static final String EVENT_VOLUME_UNMANAGE = "VOLUME.UNMANAGE";
public static final String EVENT_VOLUME_CHANGE_DISK_OFFERING = "VOLUME.CHANGE.DISK.OFFERING";
+ public static final String EVENT_VOLUME_ASSIGN = "VOLUME.ASSIGN";
+ public static final String EVENT_VOLUME_RELEASE = "VOLUME.RELEASE";
// Domains
public static final String EVENT_DOMAIN_CREATE = "DOMAIN.CREATE";
@@ -884,6 +886,8 @@ public class EventTypes {
entityEventDetails.put(EVENT_VOLUME_DESTROY, Volume.class);
entityEventDetails.put(EVENT_VOLUME_RECOVER, Volume.class);
entityEventDetails.put(EVENT_VOLUME_CHANGE_DISK_OFFERING, Volume.class);
+ entityEventDetails.put(EVENT_VOLUME_ASSIGN, Volume.class);
+ entityEventDetails.put(EVENT_VOLUME_RELEASE, Volume.class);
// Domains
entityEventDetails.put(EVENT_DOMAIN_CREATE, Domain.class);
diff --git a/api/src/main/java/com/cloud/event/UsageEvent.java b/api/src/main/java/com/cloud/event/UsageEvent.java
index 3921e704aa9c..16be3bafe0e5 100644
--- a/api/src/main/java/com/cloud/event/UsageEvent.java
+++ b/api/src/main/java/com/cloud/event/UsageEvent.java
@@ -29,6 +29,8 @@ public interface UsageEvent extends InternalIdentity {
Long getSize();
+ Long getVmInstanceId();
+
Long getTemplateId();
Long getOfferingId();
diff --git a/engine/schema/src/main/java/com/cloud/event/UsageEventVO.java b/engine/schema/src/main/java/com/cloud/event/UsageEventVO.java
index 3fc9fda94873..50cf90adab53 100644
--- a/engine/schema/src/main/java/com/cloud/event/UsageEventVO.java
+++ b/engine/schema/src/main/java/com/cloud/event/UsageEventVO.java
@@ -57,6 +57,9 @@ public enum DynamicParameters {
@Column(name = "resource_name")
private String resourceName;
+ @Column(name = "vm_instance_id")
+ private Long vmInstanceId;
+
@Column(name = "offering_id")
private Long offeringId;
@@ -134,6 +137,18 @@ public UsageEventVO(String usageType, long accountId, long zoneId, long resource
this.resourceType = resourceType;
}
+ public UsageEventVO(String usageType, long accountId, long zoneId, long resourceId, String resourceName, Long vmInstanceId, Long offeringId, Long templateId, String resourceType) {
+ this.type = usageType;
+ this.accountId = accountId;
+ this.zoneId = zoneId;
+ this.resourceId = resourceId;
+ this.resourceName = resourceName;
+ this.vmInstanceId = vmInstanceId;
+ this.offeringId = offeringId;
+ this.templateId = templateId;
+ this.resourceType = resourceType;
+ }
+
//Security Group usage event
public UsageEventVO(String usageType, long accountId, long zoneId, long vmId, long securityGroupId) {
this.type = usageType;
@@ -201,6 +216,11 @@ public String getResourceName() {
return resourceName;
}
+ @Override
+ public Long getVmInstanceId() {
+ return vmInstanceId;
+ }
+
public void setOfferingId(long offeringId) {
this.offeringId = offeringId;
}
diff --git a/engine/schema/src/main/java/com/cloud/usage/UsageVolumeVO.java b/engine/schema/src/main/java/com/cloud/usage/UsageVolumeVO.java
index 96abd2d69c08..56fb38585b1d 100644
--- a/engine/schema/src/main/java/com/cloud/usage/UsageVolumeVO.java
+++ b/engine/schema/src/main/java/com/cloud/usage/UsageVolumeVO.java
@@ -50,6 +50,9 @@ public class UsageVolumeVO implements InternalIdentity {
@Column(name = "volume_id")
private long volumeId;
+ @Column(name = "vm_instance_id")
+ private Long vmInstanceId;
+
@Column(name = "disk_offering_id")
private Long diskOfferingId;
@@ -99,6 +102,10 @@ public long getId() {
return id;
}
+ public Long getVmInstanceId() {
+ return vmInstanceId;
+ }
+
public Long getDiskOfferingId() {
return diskOfferingId;
}
diff --git a/engine/schema/src/main/resources/META-INF/db/schema-41900to41910.sql b/engine/schema/src/main/resources/META-INF/db/schema-41900to41910.sql
index bdb23d9844cd..17bb49015e59 100644
--- a/engine/schema/src/main/resources/META-INF/db/schema-41900to41910.sql
+++ b/engine/schema/src/main/resources/META-INF/db/schema-41900to41910.sql
@@ -65,3 +65,7 @@ CREATE TABLE IF NOT EXISTS `cloud_usage`.`usage_vpc` (
CALL `cloud_usage`.`IDEMPOTENT_ADD_COLUMN`('cloud_usage.cloud_usage', 'state', 'VARCHAR(100) DEFAULT NULL');
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.user_data', 'removed', 'datetime COMMENT "date removed or null, if still present"');
+
+CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.usage_event', 'vm_instance_id', 'bigint(20) unsigned DEFAULT NULL');
+
+CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud_usage.usage_volume', 'vm_instance_id', 'bigint(20) unsigned DEFAULT NULL');
diff --git a/usage/src/main/java/com/cloud/usage/UsageManagerImpl.java b/usage/src/main/java/com/cloud/usage/UsageManagerImpl.java
index a52312095745..bae650f60d7a 100644
--- a/usage/src/main/java/com/cloud/usage/UsageManagerImpl.java
+++ b/usage/src/main/java/com/cloud/usage/UsageManagerImpl.java
@@ -1112,7 +1112,10 @@ private boolean isIPEvent(String eventType) {
private boolean isVolumeEvent(String eventType) {
return eventType != null &&
- (eventType.equals(EventTypes.EVENT_VOLUME_CREATE) || eventType.equals(EventTypes.EVENT_VOLUME_DELETE) || eventType.equals(EventTypes.EVENT_VOLUME_RESIZE) || eventType.equals(EventTypes.EVENT_VOLUME_UPLOAD));
+ (eventType.equals(EventTypes.EVENT_VOLUME_CREATE) || eventType.equals(EventTypes.EVENT_VOLUME_DELETE) ||
+ eventType.equals(EventTypes.EVENT_VOLUME_RESIZE) || eventType.equals(EventTypes.EVENT_VOLUME_UPLOAD) ||
+ eventType.equals(EventTypes.EVENT_VOLUME_ASSIGN) || eventType.equals(EventTypes.EVENT_VOLUME_RELEASE) ||
+ eventType.equals(EventTypes.EVENT_VOLUME_ATTACH) || eventType.equals(EventTypes.EVENT_VOLUME_DETACH));
}
private boolean isTemplateEvent(String eventType) {
diff --git a/usage/src/main/java/com/cloud/usage/parser/VolumeUsageParser.java b/usage/src/main/java/com/cloud/usage/parser/VolumeUsageParser.java
index 79ed8bcbb943..aaac4d76ceb5 100644
--- a/usage/src/main/java/com/cloud/usage/parser/VolumeUsageParser.java
+++ b/usage/src/main/java/com/cloud/usage/parser/VolumeUsageParser.java
@@ -87,9 +87,10 @@ public static boolean parse(AccountVO account, Date startDate, Date endDate) {
long zoneId = usageVol.getZoneId();
Long templateId = usageVol.getTemplateId();
long size = usageVol.getSize();
+ Long vmId = usageVol.getVmInstanceId();
String key = volId + "-" + doId + "-" + size;
- diskOfferingMap.put(key, new VolInfo(volId, zoneId, doId, templateId, size));
+ diskOfferingMap.put(key, new VolInfo(volId, vmId, zoneId, doId, templateId, size));
Date volCreateDate = usageVol.getCreated();
Date volDeleteDate = usageVol.getDeleted();
@@ -120,7 +121,7 @@ public static boolean parse(AccountVO account, Date startDate, Date endDate) {
// Only create a usage record if we have a runningTime of bigger than zero.
if (useTime > 0L) {
VolInfo info = diskOfferingMap.get(volIdKey);
- createUsageRecord(UsageTypes.VOLUME, useTime, startDate, endDate, account, info.getVolumeId(), info.getZoneId(), info.getDiskOfferingId(),
+ createUsageRecord(UsageTypes.VOLUME, useTime, startDate, endDate, account, info.getVolumeId(), info.getVmInstanceId(), info.getZoneId(), info.getDiskOfferingId(),
info.getTemplateId(), info.getSize());
}
}
@@ -140,7 +141,7 @@ private static void updateVolUsageData(Map> usageDataMa
usageDataMap.put(key, volUsageInfo);
}
- private static void createUsageRecord(int type, long runningTime, Date startDate, Date endDate, AccountVO account, long volId, long zoneId, Long doId,
+ private static void createUsageRecord(int type, long runningTime, Date startDate, Date endDate, AccountVO account, long volId, Long vmId, long zoneId, Long doId,
Long templateId, long size) {
// Our smallest increment is hourly for now
if (s_logger.isDebugEnabled()) {
@@ -166,20 +167,22 @@ private static void createUsageRecord(int type, long runningTime, Date startDate
usageDesc += " (DiskOffering: " + doId + ")";
}
- UsageVO usageRecord = new UsageVO(zoneId, account.getId(), account.getDomainId(), usageDesc, usageDisplay + " Hrs", type, new Double(usage), null, null, doId, templateId, volId,
+ UsageVO usageRecord = new UsageVO(zoneId, account.getId(), account.getDomainId(), usageDesc, usageDisplay + " Hrs", type, new Double(usage), vmId, null, doId, templateId, volId,
size, startDate, endDate);
s_usageDao.persist(usageRecord);
}
private static class VolInfo {
private long volId;
+ private Long vmId;
private long zoneId;
private Long diskOfferingId;
private Long templateId;
private long size;
- public VolInfo(long volId, long zoneId, Long diskOfferingId, Long templateId, long size) {
+ public VolInfo(long volId, Long vmId, long zoneId, Long diskOfferingId, Long templateId, long size) {
this.volId = volId;
+ this.vmId = vmId;
this.zoneId = zoneId;
this.diskOfferingId = diskOfferingId;
this.templateId = templateId;
@@ -194,6 +197,10 @@ public long getVolumeId() {
return volId;
}
+ public Long getVmInstanceId() {
+ return vmId;
+ }
+
public Long getDiskOfferingId() {
return diskOfferingId;
}