cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bfede...@apache.org
Subject [35/50] [abbrv] git commit: updated refs/heads/ui-vm-affinity to 922b51c
Date Mon, 22 Apr 2013 21:04:00 GMT
1) fix CLOUDSTACK-2129 and CLOUDSTACK-2128
2) include nicId in network.offerings.assign/remove event
3) use publishUsageEvent instead of saveUsageEvent to track usageEvent


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

Branch: refs/heads/ui-vm-affinity
Commit: 5118e9e29faeddd2408e925d43c2b8afdf170b6b
Parents: 9ae29bb
Author: Mice Xia <mice_xia@tcloudcomputing.com>
Authored: Mon Apr 22 19:37:53 2013 +0800
Committer: Mice Xia <mice_xia@tcloudcomputing.com>
Committed: Mon Apr 22 19:38:32 2013 +0800

----------------------------------------------------------------------
 .../src/com/cloud/network/NetworkServiceImpl.java  |    7 +++-
 .../com/cloud/usage/UsageNetworkOfferingVO.java    |   14 +++++++++-
 .../usage/dao/UsageNetworkOfferingDaoImpl.java     |    9 +++---
 server/src/com/cloud/vm/UserVmManagerImpl.java     |    2 +-
 server/src/com/cloud/vm/UserVmStateListener.java   |   21 +++++++++-----
 .../com/cloud/vm/VirtualMachineManagerImpl.java    |   11 ++++++++
 setup/db/db/schema-410to420.sql                    |    4 ++-
 usage/src/com/cloud/usage/UsageManagerImpl.java    |   10 +++++-
 8 files changed, 59 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5118e9e2/server/src/com/cloud/network/NetworkServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java
index 878d2a8..ac2ac45 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -1988,8 +1988,11 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
                         continue;
                     }
                     long isDefault = (nic.isDefaultNic()) ? 1 : 0;
-                    UsageEventUtils.saveUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE,
vm.getAccountId(), vm.getDataCenterId(), vm.getId(), null, oldNetworkOfferingId, null, 0L);
-                    UsageEventUtils.saveUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN,
vm.getAccountId(), vm.getDataCenterId(), vm.getId(), vm.getHostName(), networkOfferingId,
null, isDefault);
+                    String nicIdString = Long.toString(nic.getId());
+                    UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE,
vm.getAccountId(), vm.getDataCenterId(),
+                            vm.getId(), nicIdString, oldNetworkOfferingId, null, isDefault,
VirtualMachine.class.getName(), vm.getUuid());
+                    UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN,
vm.getAccountId(), vm.getDataCenterId(),
+                            vm.getId(), nicIdString, networkOfferingId, null, isDefault,
VirtualMachine.class.getName(), vm.getUuid());
                 }
                 txn.commit();
             }   else {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5118e9e2/server/src/com/cloud/usage/UsageNetworkOfferingVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/usage/UsageNetworkOfferingVO.java b/server/src/com/cloud/usage/UsageNetworkOfferingVO.java
index 7290334..fdf758b 100644
--- a/server/src/com/cloud/usage/UsageNetworkOfferingVO.java
+++ b/server/src/com/cloud/usage/UsageNetworkOfferingVO.java
@@ -53,11 +53,14 @@ public class UsageNetworkOfferingVO {
 	@Column(name="deleted")
 	@Temporal(value=TemporalType.TIMESTAMP)
 	private Date deleted = null;
+	
+	@Column(name="nic_id")
+	private Long nicId;
 
 	protected UsageNetworkOfferingVO() {
 	}
 
-	public UsageNetworkOfferingVO(long zoneId, long accountId, long domainId, long vmInstanceId,
long networkOfferingId, boolean isDefault, Date created, Date deleted) {
+	public UsageNetworkOfferingVO(long zoneId, long accountId, long domainId, long vmInstanceId,
long networkOfferingId, long nicId, boolean isDefault, Date created, Date deleted) {
 		this.zoneId = zoneId;
 		this.accountId = accountId;
 		this.domainId = domainId;
@@ -66,6 +69,7 @@ public class UsageNetworkOfferingVO {
 		this.isDefault = isDefault;
 		this.created = created;
 		this.deleted = deleted;
+		this.nicId = nicId;
 	}
 
 	public long getZoneId() {
@@ -102,4 +106,12 @@ public class UsageNetworkOfferingVO {
 	public void setDeleted(Date deleted) {
 	    this.deleted = deleted;
 	}
+
+    public Long getNicId() {
+        return nicId;
+    }
+
+    public void setNicId(Long nicId) {
+        this.nicId = nicId;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5118e9e2/server/src/com/cloud/usage/dao/UsageNetworkOfferingDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/usage/dao/UsageNetworkOfferingDaoImpl.java b/server/src/com/cloud/usage/dao/UsageNetworkOfferingDaoImpl.java
index a6539dd..c3fc5a6 100644
--- a/server/src/com/cloud/usage/dao/UsageNetworkOfferingDaoImpl.java
+++ b/server/src/com/cloud/usage/dao/UsageNetworkOfferingDaoImpl.java
@@ -39,15 +39,15 @@ public class UsageNetworkOfferingDaoImpl extends GenericDaoBase<UsageNetworkOffe
 	public static final Logger s_logger = Logger.getLogger(UsageNetworkOfferingDaoImpl.class.getName());
 
 	protected static final String UPDATE_DELETED = "UPDATE usage_network_offering SET deleted
= ? WHERE account_id = ? AND vm_instance_id = ? AND network_offering_id = ? and deleted IS
NULL";
-    protected static final String GET_USAGE_RECORDS_BY_ACCOUNT = "SELECT zone_id, account_id,
domain_id, vm_instance_id, network_offering_id, is_default, created, deleted " +
+    protected static final String GET_USAGE_RECORDS_BY_ACCOUNT = "SELECT zone_id, account_id,
domain_id, vm_instance_id, network_offering_id, nic_id, is_default, created, deleted " +
                                                                  "FROM usage_network_offering
" +
                                                                  "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 zone_id, account_id,
domain_id, vm_instance_id, network_offering_id, is_default, created, deleted " +
+    protected static final String GET_USAGE_RECORDS_BY_DOMAIN = "SELECT zone_id, account_id,
domain_id, vm_instance_id, network_offering_id, nic_id, is_default, created, deleted " +
                                                                 "FROM usage_network_offering
" +
                                                                 "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 zone_id, account_id, domain_id,
vm_instance_id, network_offering_id, is_default, created, deleted " +
+    protected static final String GET_ALL_USAGE_RECORDS = "SELECT zone_id, account_id, domain_id,
vm_instance_id, network_offering_id, nic_id, is_default, created, deleted " +
                                                           "FROM usage_network_offering "
+
                                                           "WHERE (deleted IS NULL) OR (created
BETWEEN ? AND ?) OR " +
                                                           "      (deleted BETWEEN ? AND ?)
OR ((created <= ?) AND (deleted >= ?))";
@@ -124,6 +124,7 @@ public class UsageNetworkOfferingDaoImpl extends GenericDaoBase<UsageNetworkOffe
                 Long dId = Long.valueOf(rs.getLong(3));
                 long vmId = Long.valueOf(rs.getLong(4));
                 long noId = Long.valueOf(rs.getLong(5));
+                long nicId = Long.valueOf(rs.getLong(6));
                 boolean isDefault = Boolean.valueOf(rs.getBoolean(6));
                 Date createdDate = null;
                 Date deletedDate = null;
@@ -138,7 +139,7 @@ public class UsageNetworkOfferingDaoImpl extends GenericDaoBase<UsageNetworkOffe
                 	deletedDate = DateUtil.parseDateString(s_gmtTimeZone, deletedTS);
                 }
 
-                usageRecords.add(new UsageNetworkOfferingVO(zoneId, acctId, dId, vmId, noId,
isDefault, createdDate, deletedDate));
+                usageRecords.add(new UsageNetworkOfferingVO(zoneId, acctId, dId, vmId, noId,
nicId, isDefault, createdDate, deletedDate));
             }
         } catch (Exception e) {
             txn.rollback();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5118e9e2/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java
index bc6237f..1843f60 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -2777,7 +2777,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Use
             NetworkVO network = _networkDao.findById(nic.getNetworkId());
             long isDefault = (nic.isDefaultNic()) ? 1 : 0;
             UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vm.getAccountId(),
-                    vm.getDataCenterId(), vm.getId(), vm.getHostName(), network.getNetworkOfferingId(),
+                    vm.getDataCenterId(), vm.getId(), Long.toString(nic.getId()), network.getNetworkOfferingId(),
                     null, isDefault, VirtualMachine.class.getName(), vm.getUuid());
             if (network.getTrafficType() == TrafficType.Guest) {
                 originalIp = nic.getIp4Address();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5118e9e2/server/src/com/cloud/vm/UserVmStateListener.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmStateListener.java b/server/src/com/cloud/vm/UserVmStateListener.java
index 04aa818..3feecbb 100644
--- a/server/src/com/cloud/vm/UserVmStateListener.java
+++ b/server/src/com/cloud/vm/UserVmStateListener.java
@@ -72,21 +72,26 @@ public class UserVmStateListener implements StateListener<State, VirtualMachine.
         pubishOnEventBus(event.name(), "postStateTransitionEvent", vo, oldState, newState);
 
         if (VirtualMachine.State.isVmCreated(oldState, event, newState)) {
-            UsageEventUtils.saveUsageEvent(EventTypes.EVENT_VM_CREATE, vo.getAccountId(),
vo.getDataCenterId(), vo.getId(), vo.getHostName(), vo.getServiceOfferingId(),
-                    vo.getTemplateId(), vo.getHypervisorType().toString());
+            UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_CREATE, vo.getAccountId(),
vo.getDataCenterId(), vo.getId(),
+                    vo.getHostName(), vo.getServiceOfferingId(),vo.getTemplateId(), vo.getHypervisorType().toString(),

+                    vo.getClass().getName(), vo.getUuid());
         } else if (VirtualMachine.State.isVmStarted(oldState, event, newState)) {
-            UsageEventUtils.saveUsageEvent(EventTypes.EVENT_VM_START, vo.getAccountId(),
vo.getDataCenterId(), vo.getId(), vo.getHostName(), vo.getServiceOfferingId(),
-                    vo.getTemplateId(), vo.getHypervisorType().toString());
+            UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_START, vo.getAccountId(),
vo.getDataCenterId(), vo.getId(),
+                    vo.getHostName(), vo.getServiceOfferingId(),vo.getTemplateId(), vo.getHypervisorType().toString(),

+                    vo.getClass().getName(), vo.getUuid());            
         } else if (VirtualMachine.State.isVmStopped(oldState, event, newState)) {
-            UsageEventUtils.saveUsageEvent(EventTypes.EVENT_VM_STOP, vo.getAccountId(), vo.getDataCenterId(),
vo.getId(), vo.getHostName());
+            UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_STOP, vo.getAccountId(),
vo.getDataCenterId(), vo.getId(), vo.getHostName(),
+                    vo.getClass().getName(), vo.getUuid());
             List<NicVO> nics = _nicDao.listByVmId(vo.getId());
             for (NicVO nic : nics) {
                 NetworkVO network = _networkDao.findById(nic.getNetworkId());
-                UsageEventUtils.saveUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE,
vo.getAccountId(), vo.getDataCenterId(), vo.getId(), null, network.getNetworkOfferingId(),
null, 0L);
+                UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE,
vo.getAccountId(), vo.getDataCenterId(),
+                        vo.getId(), Long.toString(nic.getId()),network.getNetworkOfferingId(),
null, 0L, vo.getClass().getName(), vo.getUuid());
             }
         } else if (VirtualMachine.State.isVmDestroyed(oldState, event, newState)) {
-            UsageEventUtils.saveUsageEvent(EventTypes.EVENT_VM_DESTROY, vo.getAccountId(),
vo.getDataCenterId(), vo.getId(), vo.getHostName(), vo.getServiceOfferingId(),
-                    vo.getTemplateId(), vo.getHypervisorType().toString());
+            UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_DESTROY, vo.getAccountId(),
vo.getDataCenterId(), vo.getId(),
+                    vo.getHostName(), vo.getServiceOfferingId(),vo.getTemplateId(), vo.getHypervisorType().toString(),
+                    vo.getClass().getName(), vo.getUuid());
         } 
         return true;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5118e9e2/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
index 2ecece2..b613917 100755
--- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -78,6 +78,8 @@ import com.cloud.deploy.DeploymentPlanner;
 import com.cloud.deploy.DeploymentPlanner.ExcludeList;
 import com.cloud.deploy.DeploymentPlanningManager;
 import com.cloud.domain.dao.DomainDao;
+import com.cloud.event.EventTypes;
+import com.cloud.event.UsageEventUtils;
 import com.cloud.exception.AffinityConflictException;
 import com.cloud.exception.AgentUnavailableException;
 import com.cloud.exception.ConcurrentOperationException;
@@ -2751,6 +2753,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
                 result = vmGuru.plugNic(network, nicTO, vmTO, context, dest);
                 if (result) {
                     s_logger.debug("Nic is plugged successfully for vm " + vm + " in network
" + network + ". Vm  is a part of network now");
+                    long isDefault = (nic.isDefaultNic()) ? 1 : 0;
+                    // insert nic's Id into DB as resource_name
+                    UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN,
vmVO.getAccountId(),
+                            vmVO.getDataCenterId(), vmVO.getId(), Long.toString(nic.getId()),
nic.getNetworkId(),
+                            null, isDefault, VirtualMachine.class.getName(), vmVO.getUuid());
                    
                     return nic;
                 } else {
                     s_logger.warn("Failed to plug nic to the vm " + vm + " in network " +
network);
@@ -2814,6 +2821,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
             boolean result = vmGuru.unplugNic(network, nicTO, vmTO, context, dest);
             if (result) {
                 s_logger.debug("Nic is unplugged successfully for vm " + vm + " in network
" + network );
+                long isDefault = (nic.isDefaultNic()) ? 1 : 0;
+                UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE,
vm.getAccountId(), vm.getDataCenterId(),
+                        vm.getId(), Long.toString(nic.getId()), network.getNetworkOfferingId(),
null, 
+                        isDefault, VirtualMachine.class.getName(), vm.getUuid());
             } else {
                 s_logger.warn("Failed to unplug nic for the vm " + vm + " from network "
+ network);
                 return false;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5118e9e2/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql
index 14aa2eb..93a685f 100644
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@ -774,4 +774,6 @@ CREATE VIEW `cloud`.`account_view` AS
             left join
         `cloud`.`async_job` ON async_job.instance_id = account.id
             and async_job.instance_type = 'Account'
-            and async_job.job_status = 0;
\ No newline at end of file
+            and async_job.job_status = 0;
+
+alter table `cloud_usage`.`usage_network_offering` add column nic_id bigint(20) unsigned
NOT NULL;             
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5118e9e2/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 85ea60b..16fe67b 100644
--- a/usage/src/com/cloud/usage/UsageManagerImpl.java
+++ b/usage/src/com/cloud/usage/UsageManagerImpl.java
@@ -78,7 +78,6 @@ import com.cloud.utils.db.Filter;
 import com.cloud.utils.db.GlobalLock;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.Transaction;
-import com.cloud.utils.exception.CloudRuntimeException;
 
 @Component
 @Local(value={UsageManager.class})
@@ -1298,6 +1297,12 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager,
Runna
 
         long vmId = event.getResourceId();
         long networkOfferingId = event.getOfferingId();
+        long nicId = 0;
+        try{
+            nicId = Long.parseLong(event.getResourceName());
+        }catch (Exception e) {
+            s_logger.warn("failed to get nic id from resource name, resource name is: " +
event.getResourceName());
+        }
 
         if (EventTypes.EVENT_NETWORK_OFFERING_CREATE.equals(event.getType()) || EventTypes.EVENT_NETWORK_OFFERING_ASSIGN.equals(event.getType()))
{
             if (s_logger.isDebugEnabled()) {
@@ -1306,12 +1311,13 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager,
Runna
             zoneId = event.getZoneId();
             Account acct = m_accountDao.findByIdIncludingRemoved(event.getAccountId());
             boolean isDefault = (event.getSize() == 1) ? true : false ;
-            UsageNetworkOfferingVO networkOffering = new UsageNetworkOfferingVO(zoneId, event.getAccountId(),
acct.getDomainId(), vmId, networkOfferingId, isDefault, event.getCreateDate(), null);
+            UsageNetworkOfferingVO networkOffering = new UsageNetworkOfferingVO(zoneId, event.getAccountId(),
acct.getDomainId(), vmId, networkOfferingId, nicId, isDefault, event.getCreateDate(), null);
             m_usageNetworkOfferingDao.persist(networkOffering);
         } else if (EventTypes.EVENT_NETWORK_OFFERING_DELETE.equals(event.getType()) || EventTypes.EVENT_NETWORK_OFFERING_REMOVE.equals(event.getType()))
{
             SearchCriteria<UsageNetworkOfferingVO> sc = m_usageNetworkOfferingDao.createSearchCriteria();
             sc.addAnd("accountId", SearchCriteria.Op.EQ, event.getAccountId());
             sc.addAnd("vmInstanceId", SearchCriteria.Op.EQ, vmId);
+            sc.addAnd("nicId", SearchCriteria.Op.EQ, nicId);
             sc.addAnd("networkOfferingId", SearchCriteria.Op.EQ, networkOfferingId);
             sc.addAnd("deleted", SearchCriteria.Op.NULL);
             List<UsageNetworkOfferingVO> noVOs = m_usageNetworkOfferingDao.search(sc,
null);


Mime
View raw message