CLOUDSTACK-3231: Update service offering Id of allocated Vm usage whem service offering changes for a Vm

This commit is contained in:
Kishan Kavala 2013-06-27 16:01:09 +05:30
parent 3c0c6cb0b3
commit f96442a45b
2 changed files with 24 additions and 3 deletions

View File

@ -47,7 +47,7 @@ public class UsageVMInstanceVO {
@Column(name="template_id")
private long templateId;
@Column(name="hypervisor_type")
private String hypervisorType;
@ -104,6 +104,10 @@ public class UsageVMInstanceVO {
return templateId;
}
public void setServiceOfferingId(long serviceOfferingId) {
this.serviceOfferingId = serviceOfferingId;
}
public String getHypervisorType() {
return hypervisorType;
}
@ -112,7 +116,11 @@ public class UsageVMInstanceVO {
return startDate;
}
public Date getEndDate() {
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {

View File

@ -988,8 +988,21 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager, Runna
usageInstances = m_usageInstanceDao.search(sc, null);
if (usageInstances == null || (usageInstances.size() == 0)) {
s_logger.error("Cannot find allocated vm entry for a vm running with id: " + vmId);
} else if (usageInstances.size() == 1) {
UsageVMInstanceVO usageInstance = usageInstances.get(0);
if(usageInstance.getSerivceOfferingId() != soId){
//Service Offering changed after Vm creation
//End current Allocated usage and create new Allocated Vm entry with new soId
usageInstance.setEndDate(event.getCreateDate());
m_usageInstanceDao.update(usageInstance);
usageInstance.setServiceOfferingId(soId);
usageInstance.setStartDate(event.getCreateDate());
usageInstance.setEndDate(null);
m_usageInstanceDao.persist(usageInstance);
}
}
Long templateId = event.getTemplateId();
String hypervisorType = event.getResourceType();