cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kous...@apache.org
Subject git commit: updated refs/heads/4.3 to 8970c95
Date Tue, 26 Nov 2013 12:40:39 GMT
Updated Branches:
  refs/heads/4.3 6af8021ef -> 8970c9515


CLOUDSTACK-4737: handling usage events for dynamic compute offering

Signed-off-by: Koushik Das <koushik@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/8970c951
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/8970c951
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/8970c951

Branch: refs/heads/4.3
Commit: 8970c9515441c50a0249b9624b120d4e5348b5af
Parents: 6af8021
Author: Harikrishna Patnala <harikrishna.patnala@citrix.com>
Authored: Mon Nov 25 20:22:59 2013 +0530
Committer: Koushik Das <koushik@apache.org>
Committed: Tue Nov 26 18:00:27 2013 +0530

----------------------------------------------------------------------
 .../event/dao/UsageEventDetailsDaoImpl.java     | 46 +++++++++++++++++---
 .../src/com/cloud/usage/UsageVMInstanceVO.java  | 37 ++++++++++++++++
 setup/db/db/schema-421to430.sql                 |  3 ++
 usage/src/com/cloud/usage/UsageManagerImpl.java | 31 +++++++++++++
 4 files changed, 110 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8970c951/engine/schema/src/com/cloud/event/dao/UsageEventDetailsDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/event/dao/UsageEventDetailsDaoImpl.java b/engine/schema/src/com/cloud/event/dao/UsageEventDetailsDaoImpl.java
index a4382c4..36afc75 100644
--- a/engine/schema/src/com/cloud/event/dao/UsageEventDetailsDaoImpl.java
+++ b/engine/schema/src/com/cloud/event/dao/UsageEventDetailsDaoImpl.java
@@ -21,10 +21,15 @@ import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.TransactionLegacy;
+import com.cloud.utils.exception.CloudRuntimeException;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
 import javax.ejb.Local;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -34,6 +39,8 @@ import java.util.Map;
 public class UsageEventDetailsDaoImpl extends GenericDaoBase<UsageEventDetailsVO, Long>
implements UsageEventDetailsDao {
     public static final Logger s_logger = Logger.getLogger(UsageEventDetailsDaoImpl.class.getName());
 
+    private static final String EVENT_DETAILS_QUERY = "SELECT details.id, details.usage_event_id,
details.name, details.value FROM `cloud`.`usage_event_details` details WHERE details.usage_event_id
= ?";
+
     protected final SearchBuilder<UsageEventDetailsVO> EventDetailsSearch;
     protected final SearchBuilder<UsageEventDetailsVO> DetailSearch;
 
@@ -73,13 +80,38 @@ public class UsageEventDetailsDaoImpl extends GenericDaoBase<UsageEventDetailsVO
 
     @Override
     public Map<String, String> findDetails(long eventId) {
-        SearchCriteria<UsageEventDetailsVO> sc = EventDetailsSearch.create();
-        sc.setParameters("eventId", eventId);
-
-        List<UsageEventDetailsVO> results = search(sc, null);
-        Map<String, String> details = new HashMap<String, String>(results.size());
-        for (UsageEventDetailsVO result : results) {
-            details.put(result.getKey(), result.getValue());
+        Connection conn = null;
+        PreparedStatement pstmt = null;
+        ResultSet resultSet = null;
+        Map<String, String> details = new HashMap<String, String>();
+        try {
+            conn = TransactionLegacy.getStandaloneConnection();
+
+            pstmt = conn.prepareStatement(EVENT_DETAILS_QUERY);
+            pstmt.setLong(1, eventId);
+            resultSet = pstmt.executeQuery();
+
+            while (resultSet.next()) {
+                details.put(resultSet.getString(3), resultSet.getString(4));
+            }
+
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Error while executing SQL prepared statement",
e);
+        }  catch (Throwable e) {
+            throw new CloudRuntimeException("Caught: " + e);
+        } finally {
+            if (pstmt != null) {
+                try {
+                    pstmt.close();
+                } catch (SQLException e) {
+                }
+            }
+            if (conn != null) {
+                try {
+                    conn.close();
+                } catch (SQLException e) {
+                }
+            }
         }
 
         return details;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8970c951/engine/schema/src/com/cloud/usage/UsageVMInstanceVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/usage/UsageVMInstanceVO.java b/engine/schema/src/com/cloud/usage/UsageVMInstanceVO.java
index 2fe346e..1178cc8 100644
--- a/engine/schema/src/com/cloud/usage/UsageVMInstanceVO.java
+++ b/engine/schema/src/com/cloud/usage/UsageVMInstanceVO.java
@@ -27,6 +27,10 @@ import javax.persistence.TemporalType;
 @Entity
 @Table(name="usage_vm_instance")
 public class UsageVMInstanceVO {
+    public enum DynamicParameters {
+        cpuSpeed, cpuNumber, memory
+    };
+
     @Column(name="usage_type")
     private int usageType;
 
@@ -45,6 +49,15 @@ public class UsageVMInstanceVO {
 	@Column(name="service_offering_id")
 	private long serviceOfferingId;
 
+    @Column(name="cpu_cores")
+    private  Long cpuCores;
+
+    @Column(name="memory")
+    private  Long memory;
+
+    @Column(name="cpu_speed")
+    private  Long cpuSpeed;
+
     @Column(name="template_id")
     private long templateId;
 
@@ -126,4 +139,28 @@ public class UsageVMInstanceVO {
 	public void setEndDate(Date endDate) {
 	    this.endDate = endDate;
 	}
+
+    public Long getMemory() {
+        return memory;
+    }
+
+    public void setMemory(Long memory) {
+        this.memory = memory;
+    }
+
+    public Long getCpuCores() {
+        return cpuCores;
+    }
+
+    public void setCpuCores(Long cpuCores) {
+        this.cpuCores = cpuCores;
+    }
+
+    public Long getCpuSpeed() {
+        return cpuSpeed;
+    }
+
+    public void setCpuSpeed(Long cpuSpeed) {
+        this.cpuSpeed = cpuSpeed;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8970c951/setup/db/db/schema-421to430.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-421to430.sql b/setup/db/db/schema-421to430.sql
index 8be0fb1..521ac16 100644
--- a/setup/db/db/schema-421to430.sql
+++ b/setup/db/db/schema-421to430.sql
@@ -755,6 +755,9 @@ CREATE VIEW `cloud`.`domain_router_view` AS
 INSERT IGNORE INTO `cloud`.`configuration` VALUES ("Advanced", 'DEFAULT', 'management-server',
"vmware.vcenter.session.timeout", "1200", "VMware client timeout in seconds", "1200", NULL,NULL,0);
 INSERT IGNORE INTO `cloud`.`configuration` VALUES ("Advanced", 'DEFAULT', 'management-server',
"mgt.server.vendor", "ACS", "the vendor of management server", "ACS", NULL,NULL,0);
 
+ALTER TABLE `cloud_usage`.`usage_vm_instance` ADD COLUMN `cpu_speed` INT(10) UNSIGNED NULL
 COMMENT 'speed per core in Mhz',
+    ADD COLUMN `cpu_cores` INT(10) UNSIGNED NULL  COMMENT 'number of cpu cores',
+    ADD COLUMN  `memory` INT(10) UNSIGNED NULL  COMMENT 'memory in MB';
 
 CREATE TABLE `cloud`.`vpc_details` (
   `id` bigint unsigned NOT NULL auto_increment,

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8970c951/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 1ee21c9..ea04dd0 100644
--- a/usage/src/com/cloud/usage/UsageManagerImpl.java
+++ b/usage/src/com/cloud/usage/UsageManagerImpl.java
@@ -34,6 +34,7 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
+import com.cloud.service.ServiceOfferingVO;
 import org.apache.log4j.Logger;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.managed.context.ManagedContext;
@@ -85,6 +86,7 @@ import com.cloud.utils.db.Filter;
 import com.cloud.utils.db.GlobalLock;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.TransactionLegacy;
+import com.cloud.event.dao.UsageEventDetailsDao;
 
 @Component
 @Local(value={UsageManager.class})
@@ -118,6 +120,7 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager,
Runna
     @Inject private UsageVmDiskDao m_usageVmDiskDao;
     @Inject protected AlertManager _alertMgr;
     @Inject protected UsageEventDao _usageEventDao;
+    @Inject protected UsageEventDetailsDao _usageEventDetailsDao;
     @Inject ConfigurationDao _configDao;
     @Inject private UsageVMSnapshotDao m_usageVMSnapshotDao;
     
@@ -1063,9 +1066,37 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager,
Runna
             try {
                 Long templateId = event.getTemplateId();
                 String hypervisorType = event.getResourceType();
+                Long cpuCores= null;
+                Long memory = null;
+                Long cpuSpeed = null;
+
+                //populate the cpu, memory and cpuSpeed of the vm when created from a dynamic
offering.
+                Map<String, String> usageDetails = _usageEventDetailsDao.findDetails(event.getId());
+
+                if (usageDetails != null && usageDetails.size() != 0) {
+                    if (usageDetails.get(UsageVMInstanceVO.DynamicParameters.cpuNumber.name())
!= null) {
+                        cpuCores = Long.parseLong(usageDetails.get(UsageVMInstanceVO.DynamicParameters.cpuNumber.name()));
+                    }
+                    if (usageDetails.get(UsageVMInstanceVO.DynamicParameters.cpuSpeed.name())
!= null) {
+                        cpuSpeed = Long.parseLong(usageDetails.get(UsageVMInstanceVO.DynamicParameters.cpuSpeed.name()));
+                    }
+                    if (usageDetails.get(UsageVMInstanceVO.DynamicParameters.memory.name())
!= null) {
+                        memory = Long.parseLong(usageDetails.get(UsageVMInstanceVO.DynamicParameters.memory.name()));
+                    }
+                }
+
                 // add this VM to the usage helper table
                 UsageVMInstanceVO usageInstanceNew = new UsageVMInstanceVO(UsageTypes.ALLOCATED_VM,
zoneId, event.getAccountId(), vmId, vmName,
                         soId, templateId, hypervisorType, event.getCreateDate(), null);
+                if (cpuCores != null) {
+                    usageInstanceNew.setCpuCores(cpuCores);
+                }
+                if (cpuSpeed != null) {
+                    usageInstanceNew.setCpuSpeed(cpuSpeed);
+                }
+                if (memory != null) {
+                    usageInstanceNew.setMemory(memory);
+                }
                 m_usageInstanceDao.persist(usageInstanceNew);
             } catch (Exception ex) {
                 s_logger.error("Error saving usage instance for vm: " + vmId, ex);


Mime
View raw message