cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ni...@apache.org
Subject git commit: updated refs/heads/4.4 to 4723fbb
Date Tue, 18 Mar 2014 20:59:49 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/4.4 df3a2083d -> 4723fbb83


CLOUDSTACK-6247: Usage Events - hide them when display flag is off in the context of "Ability
to have better control over first class objects in CS" feature
Work done for network offering.


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

Branch: refs/heads/4.4
Commit: 4723fbb83f9c0e26eef7306ee02e71b24c01f83c
Parents: df3a208
Author: Nitin Mehta <nitin.mehta@citrix.com>
Authored: Tue Mar 18 13:54:25 2014 -0700
Committer: Nitin Mehta <nitin.mehta@citrix.com>
Committed: Tue Mar 18 13:54:25 2014 -0700

----------------------------------------------------------------------
 api/src/com/cloud/vm/VirtualMachine.java        |  2 +
 .../com/cloud/vm/VirtualMachineManagerImpl.java |  4 +-
 .../schema/src/com/cloud/vm/VMInstanceVO.java   |  6 +++
 .../engine/cloud/entity/api/db/VMEntityVO.java  | 12 ++++++
 .../com/cloud/network/NetworkServiceImpl.java   |  4 +-
 server/src/com/cloud/vm/UserVmManagerImpl.java  | 43 ++++++++++++++++----
 .../src/com/cloud/vm/UserVmStateListener.java   |  2 +-
 7 files changed, 61 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4723fbb8/api/src/com/cloud/vm/VirtualMachine.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/vm/VirtualMachine.java b/api/src/com/cloud/vm/VirtualMachine.java
index 72cbb25..e7cfd64 100755
--- a/api/src/com/cloud/vm/VirtualMachine.java
+++ b/api/src/com/cloud/vm/VirtualMachine.java
@@ -321,4 +321,6 @@ public interface VirtualMachine extends RunningOn, ControlledEntity, Identity,
I
 
     long getUpdated();
 
+    boolean isDisplay();
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4723fbb8/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
index 0a6e83d..a31172c 100755
--- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -3422,7 +3422,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
                     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()), network.getNetworkOfferingId(), null,
isDefault, VirtualMachine.class.getName(), vmVO.getUuid());
+                            Long.toString(nic.getId()), network.getNetworkOfferingId(), null,
isDefault, VirtualMachine.class.getName(), vmVO.getUuid(), vm.isDisplay());
                     return nic;
                 } else {
                     s_logger.warn("Failed to plug nic to the vm " + vm + " in network " +
network);
@@ -3537,7 +3537,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
                 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());
+                        Long.toString(nic.getId()), network.getNetworkOfferingId(), null,
isDefault, VirtualMachine.class.getName(), vm.getUuid(), vm.isDisplay());
             } 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/4723fbb8/engine/schema/src/com/cloud/vm/VMInstanceVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/VMInstanceVO.java b/engine/schema/src/com/cloud/vm/VMInstanceVO.java
index c7206d0..9ebade1 100644
--- a/engine/schema/src/com/cloud/vm/VMInstanceVO.java
+++ b/engine/schema/src/com/cloud/vm/VMInstanceVO.java
@@ -384,10 +384,16 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State,
Vi
         return haEnabled;
     }
 
+    //FIXME - Remove this and use isDisplay() instead
     public boolean isDisplayVm() {
         return displayVm;
     }
 
+    @Override
+    public boolean isDisplay() {
+        return displayVm;
+    }
+
     public void setDisplayVm(boolean displayVm) {
         this.displayVm = displayVm;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4723fbb8/engine/schema/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java
b/engine/schema/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java
index ced2f22..b20cae3 100644
--- a/engine/schema/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java
+++ b/engine/schema/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java
@@ -173,6 +173,9 @@ public class VMEntityVO implements VirtualMachine, FiniteStateObject<State,
Virt
     @Column(name = "disk_offering_id")
     protected Long diskOfferingId;
 
+    @Column(name = "display_vm", updatable = true, nullable = false)
+    protected boolean display = true;
+
     @Transient
     private VMReservationVO vmReservation;
 
@@ -539,4 +542,13 @@ public class VMEntityVO implements VirtualMachine, FiniteStateObject<State,
Virt
     public Class<?> getEntityType() {
         return VirtualMachine.class;
     }
+
+    @Override
+    public boolean isDisplay() {
+        return display;
+    }
+
+    public void setDisplay(boolean display) {
+        this.display = display;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4723fbb8/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 e255976..b804b07 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -2277,9 +2277,9 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
                     long isDefault = (nic.isDefaultNic()) ? 1 : 0;
                     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());
+                                    oldNetworkOfferingId, null, isDefault, VirtualMachine.class.getName(),
vm.getUuid(), vm.isDisplay());
                             UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN,
vm.getAccountId(), vm.getDataCenterId(), vm.getId(), nicIdString,
-                                    networkOfferingId, null, isDefault, VirtualMachine.class.getName(),
vm.getUuid());
+                                    networkOfferingId, null, isDefault, VirtualMachine.class.getName(),
vm.getUuid(), vm.isDisplay());
                 }
                     }
                 });

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4723fbb8/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 bca0d29..b4888a8 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -1188,13 +1188,13 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
             String nicIdString = Long.toString(nic.getId());
             long newNetworkOfferingId = network.getNetworkOfferingId();
             UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vmInstance.getAccountId(),
vmInstance.getDataCenterId(), vmInstance.getId(),
-                    oldNicIdString, oldNetworkOfferingId, null, 1L, VirtualMachine.class.getName(),
vmInstance.getUuid());
+                    oldNicIdString, oldNetworkOfferingId, null, 1L, VirtualMachine.class.getName(),
vmInstance.getUuid(), vmInstance.isDisplay());
             UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vmInstance.getAccountId(),
vmInstance.getDataCenterId(), vmInstance.getId(), nicIdString,
-                    newNetworkOfferingId, null, 1L, VirtualMachine.class.getName(), vmInstance.getUuid());
+                    newNetworkOfferingId, null, 1L, VirtualMachine.class.getName(), vmInstance.getUuid(),
vmInstance.isDisplay());
             UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vmInstance.getAccountId(),
vmInstance.getDataCenterId(), vmInstance.getId(), nicIdString,
-                    newNetworkOfferingId, null, 0L, VirtualMachine.class.getName(), vmInstance.getUuid());
+                    newNetworkOfferingId, null, 0L, VirtualMachine.class.getName(), vmInstance.getUuid(),
vmInstance.isDisplay());
             UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vmInstance.getAccountId(),
vmInstance.getDataCenterId(), vmInstance.getId(),
-                    oldNicIdString, oldNetworkOfferingId, null, 0L, VirtualMachine.class.getName(),
vmInstance.getUuid());
+                    oldNicIdString, oldNetworkOfferingId, null, 0L, VirtualMachine.class.getName(),
vmInstance.getUuid(), vmInstance.isDisplay());
             return _vmDao.findById(vmInstance.getId());
         }
 
@@ -1866,6 +1866,15 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
         return updateVirtualMachine(id, displayName, group, ha, isDisplayVm, osTypeId, userData,
isDynamicallyScalable, cmd.getHttpMethod(), cmd.getCustomId(), hostName);
     }
 
+    private void usage(VirtualMachine vm){
+        List<NicVO> nics = _nicDao.listByVmId(vm.getId());
+        for (NicVO nic : nics) {
+            NetworkVO network = _networkDao.findById(nic.getNetworkId());
+            UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vm.getAccountId(),
vm.getDataCenterId(), vm.getId(),
+                    Long.toString(nic.getId()), network.getNetworkOfferingId(), null, 0L,
vm.getClass().getName(), vm.getUuid(), vm.isDisplay());
+        }
+    }
+
     private void saveUsageEvent(UserVmVO vm) {
 
         // If vm not destroyed
@@ -1874,23 +1883,43 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
             if(vm.isDisplayVm()){
                 //1. Allocated VM Usage Event
                 generateUsageEvent(vm, true, EventTypes.EVENT_VM_CREATE);
-                //2. Running VM Usage Event
+
                 if(vm.getState() == State.Running || vm.getState() == State.Stopping){
+                    //2. Running VM Usage Event
                     generateUsageEvent(vm, true, EventTypes.EVENT_VM_START);
+
+                    // 3. Network offering usage
+                    generateNetworkUsageForVm(vm, true, EventTypes.EVENT_NETWORK_OFFERING_ASSIGN);
                 }
 
             }else {
                 //1. Allocated VM Usage Event
                 generateUsageEvent(vm, true, EventTypes.EVENT_VM_DESTROY);
-                //2. Running VM Usage Event
+
                 if(vm.getState() == State.Running || vm.getState() == State.Stopping){
+                    //2. Running VM Usage Event
                     generateUsageEvent(vm, true, EventTypes.EVENT_VM_STOP);
+
+                    // 3. Network offering usage
+                    generateNetworkUsageForVm(vm, true, EventTypes.EVENT_NETWORK_OFFERING_REMOVE);
                 }
             }
         }
 
     }
 
+    private void generateNetworkUsageForVm(VirtualMachine vm, boolean isDisplay, String eventType){
+
+        List<NicVO> nics = _nicDao.listByVmId(vm.getId());
+        for (NicVO nic : nics) {
+            NetworkVO network = _networkDao.findById(nic.getNetworkId());
+            long isDefault = (nic.isDefaultNic()) ? 1 : 0;
+            UsageEventUtils.publishUsageEvent(eventType, vm.getAccountId(), vm.getDataCenterId(),
vm.getId(),
+                    Long.toString(nic.getId()), network.getNetworkOfferingId(), null, isDefault,
vm.getClass().getName(), vm.getUuid(), isDisplay);
+        }
+
+    }
+
     @Override
     public UserVm updateVirtualMachine(long id, String displayName, String group, Boolean
ha, Boolean isDisplayVmEnabled, Long osTypeId, String userData,
             Boolean isDynamicallyScalable, HTTPMethod httpMethod, String customId, String
hostName) throws ResourceUnavailableException, InsufficientCapacityException {
@@ -3175,7 +3204,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
             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(), Long.toString(nic.getId()),
-                    network.getNetworkOfferingId(), null, isDefault, VirtualMachine.class.getName(),
vm.getUuid());
+                    network.getNetworkOfferingId(), null, isDefault, VirtualMachine.class.getName(),
vm.getUuid(), vm.isDisplay());
             if (network.getTrafficType() == TrafficType.Guest) {
                 originalIp = nic.getIp4Address();
                 guestNic = nic;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4723fbb8/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 af5f882..202391f 100644
--- a/server/src/com/cloud/vm/UserVmStateListener.java
+++ b/server/src/com/cloud/vm/UserVmStateListener.java
@@ -93,7 +93,7 @@ public class UserVmStateListener implements StateListener<State, VirtualMachine.
             for (NicVO nic : nics) {
                 NetworkVO network = _networkDao.findById(nic.getNetworkId());
                 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());
+                    Long.toString(nic.getId()), network.getNetworkOfferingId(), null, 0L,
vo.getClass().getName(), vo.getUuid(), vo.isDisplay());
             }
         } else if (VirtualMachine.State.isVmDestroyed(oldState, event, newState)) {
             generateUsageEvent(vo.getServiceOfferingId(), vo, EventTypes.EVENT_VM_DESTROY);


Mime
View raw message