Skip to content

Commit f96442a

Browse files
author
Kishan Kavala
committed
CLOUDSTACK-3231: Update service offering Id of allocated Vm usage whem service offering changes for a Vm
1 parent 3c0c6cb commit f96442a

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

engine/schema/src/com/cloud/usage/UsageVMInstanceVO.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class UsageVMInstanceVO {
4747

4848
@Column(name="template_id")
4949
private long templateId;
50-
50+
5151
@Column(name="hypervisor_type")
5252
private String hypervisorType;
5353

@@ -104,6 +104,10 @@ public long getTemplateId() {
104104
return templateId;
105105
}
106106

107+
public void setServiceOfferingId(long serviceOfferingId) {
108+
this.serviceOfferingId = serviceOfferingId;
109+
}
110+
107111
public String getHypervisorType() {
108112
return hypervisorType;
109113
}
@@ -112,7 +116,11 @@ public Date getStartDate() {
112116
return startDate;
113117
}
114118

115-
public Date getEndDate() {
119+
public void setStartDate(Date startDate) {
120+
this.startDate = startDate;
121+
}
122+
123+
public Date getEndDate() {
116124
return endDate;
117125
}
118126
public void setEndDate(Date endDate) {

usage/src/com/cloud/usage/UsageManagerImpl.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,8 +988,21 @@ private void createVMHelperEvent(UsageEventVO event) {
988988
usageInstances = m_usageInstanceDao.search(sc, null);
989989
if (usageInstances == null || (usageInstances.size() == 0)) {
990990
s_logger.error("Cannot find allocated vm entry for a vm running with id: " + vmId);
991+
} else if (usageInstances.size() == 1) {
992+
UsageVMInstanceVO usageInstance = usageInstances.get(0);
993+
if(usageInstance.getSerivceOfferingId() != soId){
994+
//Service Offering changed after Vm creation
995+
//End current Allocated usage and create new Allocated Vm entry with new soId
996+
usageInstance.setEndDate(event.getCreateDate());
997+
m_usageInstanceDao.update(usageInstance);
998+
usageInstance.setServiceOfferingId(soId);
999+
usageInstance.setStartDate(event.getCreateDate());
1000+
usageInstance.setEndDate(null);
1001+
m_usageInstanceDao.persist(usageInstance);
1002+
}
9911003
}
992-
1004+
1005+
9931006
Long templateId = event.getTemplateId();
9941007
String hypervisorType = event.getResourceType();
9951008

0 commit comments

Comments
 (0)