Updated Branches:
  refs/heads/4.2-forward 4ba68e3b3 -> 4c6ec5f3c

CLOUDSTACK-4464,CLOUDSTACK-4529: use property collector to collect all 
information in one round, we have a few other places that need to do it the 
same way


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

Branch: refs/heads/4.2-forward
Commit: 4c6ec5f3c63cb486566d9260e77d2f21c79d9c07
Parents: 4ba68e3
Author: Kelven Yang <kelv...@gmail.com>
Authored: Tue Aug 27 17:37:39 2013 -0700
Committer: Kelven Yang <kelv...@gmail.com>
Committed: Tue Aug 27 17:37:53 2013 -0700

----------------------------------------------------------------------
 .../vmware/resource/VmwareResource.java         | 53 ++++++++++++++------
 .../cloud/hypervisor/vmware/mo/ClusterMO.java   | 31 ++++++------
 .../com/cloud/hypervisor/vmware/mo/HostMO.java  | 15 ++++--
 .../vmware/mo/HypervisorHostHelper.java         | 18 +++----
 4 files changed, 74 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4c6ec5f3/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
----------------------------------------------------------------------
diff --git 
a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
 
b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
index 63d0482..fd88c7e 100755
--- 
a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ 
b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@ -277,6 +277,7 @@ import com.vmware.vim25.AboutInfo;
 import com.vmware.vim25.BoolPolicy;
 import com.vmware.vim25.ClusterDasConfigInfo;
 import com.vmware.vim25.ComputeResourceSummary;
+import com.vmware.vim25.CustomFieldStringValue;
 import com.vmware.vim25.DVPortConfigInfo;
 import com.vmware.vim25.DVPortConfigSpec;
 import com.vmware.vim25.DatastoreSummary;
@@ -5799,10 +5800,16 @@ public class VmwareResource implements 
StoragePoolResource, ServerResource, Vmwa
        
                        if(_recycleHungWorker) {
                            s_logger.info("Scan hung worker VM to recycle");
+                           
+                               int key = 
((HostMO)hyperHost).getCustomFieldKey("VirtualMachine", 
CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
+                               if(key == 0) {
+                                       s_logger.warn("Custom field " + 
CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!");
+                               }
+                               String instanceNameCustomField = "value[" + key 
+ "]";
        
                            // GC worker that has been running for too long
                            ObjectContent[] ocs = 
hyperHost.getVmPropertiesOnHyperHost(
-                                   new String[] {"name", "config.template", 
"runtime.powerState", "runtime.bootTime"});
+                                   new String[] {"name", "config.template", 
"runtime.powerState", "runtime.bootTime", instanceNameCustomField });
                            if(ocs != null) {
                                for(ObjectContent oc : ocs) {
                                    List<DynamicProperty> props = 
oc.getPropSet();
@@ -5816,6 +5823,10 @@ public class VmwareResource implements 
StoragePoolResource, ServerResource, Vmwa
                                        for(DynamicProperty prop : props) {
                                            if (prop.getName().equals("name"))
                                                vmName = 
prop.getVal().toString();
+                                           else 
if(prop.getName().startsWith("value[")) {
+                                                       if(prop.getVal() != 
null)
+                                                               internalName = 
((CustomFieldStringValue)prop.getVal()).getValue();
+                                               } 
                                            else 
if(prop.getName().equals("config.template"))
                                                template = 
(Boolean)prop.getVal();
                                            else 
if(prop.getName().equals("runtime.powerState"))
@@ -5825,15 +5836,13 @@ public class VmwareResource implements 
StoragePoolResource, ServerResource, Vmwa
                                        }
        
                                        VirtualMachineMO vmMo = new 
VirtualMachineMO(hyperHost.getContext(), oc.getObj());
-                                       // Check if vmMo has the custom 
property CLOUD_VM_INTERNAL_NAME set.
-                                       internalName =  
vmMo.getCustomFieldValue(CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
-       
                                        String name = null;
                                        if (internalName != null) {
                                            name = internalName;
                                        } else {
                                            name = vmName;
                                        }
+                                       
                                        if(!template && 
name.matches("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}")) {
                                            boolean recycle = false;
        
@@ -6274,9 +6283,16 @@ public class VmwareResource implements 
StoragePoolResource, ServerResource, Vmwa
 
     private HashMap<String, State> getVmStates() throws Exception {
         VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
+        
+               int key = 
((HostMO)hyperHost).getCustomFieldKey("VirtualMachine", 
CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
+               if(key == 0) {
+                       s_logger.warn("Custom field " + 
CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!");
+               }
+               String instanceNameCustomField = "value[" + key + "]";
+        
         // CLOUD_VM_INTERNAL_NAME stores the internal CS generated vm name. 
This was earlier stored in name. Now, name can be either the hostname or
         // the internal CS name, but the custom field CLOUD_VM_INTERNAL_NAME 
always stores the internal CS name.
-        ObjectContent[] ocs = hyperHost.getVmPropertiesOnHyperHost(new 
String[] { "name", "runtime.powerState", "config.template" });
+        ObjectContent[] ocs = hyperHost.getVmPropertiesOnHyperHost(new 
String[] { "name", "runtime.powerState", "config.template", 
instanceNameCustomField });
 
         HashMap<String, State> newStates = new HashMap<String, State>();
         if (ocs != null && ocs.length > 0) {
@@ -6297,13 +6313,15 @@ public class VmwareResource implements 
StoragePoolResource, ServerResource, Vmwa
                             powerState = (VirtualMachinePowerState) 
objProp.getVal();
                         } else if (objProp.getName().equals("name")) {
                             name = (String) objProp.getVal();
-                        } else {
+                        } else 
if(objProp.getName().contains(instanceNameCustomField)) {
+                                       if(objProp.getVal() != null)
+                                               VMInternalCSName = 
((CustomFieldStringValue)objProp.getVal()).getValue();
+                               }
+                        else {
                             assert (false);
                         }
                     }
-                    VirtualMachineMO vmMo = new 
VirtualMachineMO(hyperHost.getContext(), oc.getObj());
-                    // Check if vmMo has the custom property 
CLOUD_VM_INTERNAL_NAME set.
-                    VMInternalCSName =  
vmMo.getCustomFieldValue(CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
+                    
                     if (VMInternalCSName != null)
                         name = VMInternalCSName;
 
@@ -6335,8 +6353,14 @@ public class VmwareResource implements 
StoragePoolResource, ServerResource, Vmwa
                 }
             }
         }
+        
+               int key = 
((HostMO)hyperHost).getCustomFieldKey("VirtualMachine", 
CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
+               if(key == 0) {
+                       s_logger.warn("Custom field " + 
CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!");
+               }
+               String instanceNameCustomField = "value[" + key + "]";
 
-        ObjectContent[] ocs = hyperHost.getVmPropertiesOnHyperHost(new 
String[] {"name", "summary.config.numCpu", 
"summary.quickStats.overallCpuUsage"});
+        ObjectContent[] ocs = hyperHost.getVmPropertiesOnHyperHost(new 
String[] {"name", "summary.config.numCpu", 
"summary.quickStats.overallCpuUsage", instanceNameCustomField});
         if (ocs != null && ocs.length > 0) {
             for (ObjectContent oc : ocs) {
                 List<DynamicProperty> objProps = oc.getPropSet();
@@ -6349,16 +6373,17 @@ public class VmwareResource implements 
StoragePoolResource, ServerResource, Vmwa
                     for (DynamicProperty objProp : objProps) {
                         if (objProp.getName().equals("name")) {
                             vmNameOnVcenter = objProp.getVal().toString();
-                        } else if 
(objProp.getName().equals("summary.config.numCpu")) {
+                        } else 
if(objProp.getName().contains(instanceNameCustomField)) {
+                                       if(objProp.getVal() != null)
+                                               vmInternalCSName = 
((CustomFieldStringValue)objProp.getVal()).getValue();
+                               }
+                        else if 
(objProp.getName().equals("summary.config.numCpu")) {
                             numberCPUs = objProp.getVal().toString();
                         } else if 
(objProp.getName().equals("summary.quickStats.overallCpuUsage")) {
                             maxCpuUsage =  objProp.getVal().toString();
                         }
                     }
                     VirtualMachineMO vmMo = new 
VirtualMachineMO(hyperHost.getContext(), oc.getObj());
-                    // Check if vmMo has the custom property 
CLOUD_VM_INTERNAL_NAME set.
-                    vmInternalCSName =  
vmMo.getCustomFieldValue(CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
-
                     if (vmInternalCSName != null) {
                         name = vmInternalCSName;
                     } else {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4c6ec5f3/vmware-base/src/com/cloud/hypervisor/vmware/mo/ClusterMO.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/ClusterMO.java 
b/vmware-base/src/com/cloud/hypervisor/vmware/mo/ClusterMO.java
index d1a4530..b91d9f4 100755
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/ClusterMO.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/ClusterMO.java
@@ -98,25 +98,28 @@ public class ClusterMO extends BaseMO implements 
VmwareHypervisorHost {
 
        @Override
        public VirtualMachineMO findVmOnHyperHost(String name) throws Exception 
{
-               ObjectContent[] ocs = getVmPropertiesOnHyperHost(new String[] { 
"name" });
-               return HypervisorHostHelper.findVmFromObjectContent(_context, 
ocs, name);
+               
+               int key = getCustomFieldKey("VirtualMachine", 
CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
+               if(key == 0) {
+                       s_logger.warn("Custom field " + 
CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!");
+               }
+               
+               String instanceNameCustomField = "value[" + key + "]";
+               ObjectContent[] ocs = getVmPropertiesOnHyperHost(new String[] { 
"name",  instanceNameCustomField });
+               return HypervisorHostHelper.findVmFromObjectContent(_context, 
ocs, name, instanceNameCustomField);
        }
 
        @Override
        public VirtualMachineMO findVmOnPeerHyperHost(String name) throws 
Exception {
-               ObjectContent[] ocs = getVmPropertiesOnHyperHost(new String[] { 
"name" });
-               if(ocs != null && ocs.length > 0) {
-                       for(ObjectContent oc : ocs) {
-                               List<DynamicProperty> props = oc.getPropSet();
-                               if(props != null) {
-                                       for(DynamicProperty prop : props) {
-                                               
if(prop.getVal().toString().equals(name))
-                                                       return new 
VirtualMachineMO(_context, oc.getObj());
-                                       }
-                               }
-                       }
+               int key = getCustomFieldKey("VirtualMachine", 
CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
+               if(key == 0) {
+                       s_logger.warn("Custom field " + 
CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!");
                }
-               return null;
+               
+               String instanceNameCustomField = "value[" + key + "]";
+               
+               ObjectContent[] ocs = getVmPropertiesOnHyperHost(new String[] { 
"name", instanceNameCustomField });
+               return HypervisorHostHelper.findVmFromObjectContent(_context, 
ocs, name, instanceNameCustomField);
        }
 
        @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4c6ec5f3/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java 
b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java
index 49a340c..c350aa5 100755
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java
@@ -510,9 +510,14 @@ public class HostMO extends BaseMO implements 
VmwareHypervisorHost {
 
         _vmCache.clear();
 
+               int key = getCustomFieldKey("VirtualMachine", 
CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
+               if(key == 0) {
+                       s_logger.warn("Custom field " + 
CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!");
+               }
+        
         // name is the name of the VM as it appears in vCenter. The 
CLOUD_VM_INTERNAL_NAME custom
         // field value contains the name of the VM as it is maintained 
internally by cloudstack (i-x-y).
-        ObjectContent[] ocs = getVmPropertiesOnHyperHost(new String[] { "name" 
});
+        ObjectContent[] ocs = getVmPropertiesOnHyperHost(new String[] { 
"name", "value[" + key + "]" });
         if(ocs != null && ocs.length > 0) {
             for(ObjectContent oc : ocs) {
                 List<DynamicProperty> props = oc.getPropSet();
@@ -522,11 +527,11 @@ public class HostMO extends BaseMO implements 
VmwareHypervisorHost {
                     for (DynamicProperty prop : props) {
                         if (prop.getName().equals("name")) {
                             vmVcenterName = prop.getVal().toString();
-                        }
+                        } else if(prop.getName().startsWith("value[")) {
+                                       if(prop.getVal() != null)
+                                               vmInternalCSName = 
((CustomFieldStringValue)prop.getVal()).getValue();
+                               }                        
                     }
-                    VirtualMachineMO vmMo = new VirtualMachineMO(_context, 
oc.getObj());
-                    // Check if vmMo has the custom property 
CLOUD_VM_INTERNAL_NAME set.
-                    vmInternalCSName =  
vmMo.getCustomFieldValue(CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
                     String vmName = null;
                     if (vmInternalCSName != null && 
isUserVMInternalCSName(vmInternalCSName)) {
                         vmName = vmInternalCSName;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4c6ec5f3/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java
----------------------------------------------------------------------
diff --git 
a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java 
b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java
index db4fe73..43c59fc 100755
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java
@@ -44,6 +44,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.net.NetUtils;
 import com.vmware.vim25.AlreadyExistsFaultMsg;
 import com.vmware.vim25.BoolPolicy;
+import com.vmware.vim25.CustomFieldStringValue;
 import com.vmware.vim25.DVPortSetting;
 import com.vmware.vim25.DVPortgroupConfigInfo;
 import com.vmware.vim25.DVPortgroupConfigSpec;
@@ -61,7 +62,6 @@ import com.vmware.vim25.HttpNfcLeaseState;
 import com.vmware.vim25.LongPolicy;
 import com.vmware.vim25.ManagedObjectReference;
 import com.vmware.vim25.ObjectContent;
-import com.vmware.vim25.OptionValue;
 import com.vmware.vim25.OvfCreateImportSpecParams;
 import com.vmware.vim25.OvfCreateImportSpecResult;
 import com.vmware.vim25.OvfFileItem;
@@ -90,8 +90,8 @@ public class HypervisorHostHelper {
     private static final String UNTAGGED_VLAN_NAME = "untagged";
 
     public static VirtualMachineMO findVmFromObjectContent(VmwareContext 
context,
-            ObjectContent[] ocs, String name) {
-
+            ObjectContent[] ocs, String name, String instanceNameCustomField) {
+       
         if(ocs != null && ocs.length > 0) {
             for(ObjectContent oc : ocs) {
                 String vmNameInvCenter = null;
@@ -101,16 +101,14 @@ public class HypervisorHostHelper {
                            for(DynamicProperty objProp : objProps) {
                                if(objProp.getName().equals("name")) {
                                    vmNameInvCenter = (String)objProp.getVal();
+                               } else 
if(objProp.getName().contains(instanceNameCustomField)) {
+                                       if(objProp.getVal() != null)
+                                               vmInternalCSName = 
((CustomFieldStringValue)objProp.getVal()).getValue();
                                }
-                               VirtualMachineMO vmMo = new 
VirtualMachineMO(context, oc.getObj());
-                           // Check if vmMo has the custom property 
CLOUD_VM_INTERNAL_NAME set.
-                               try {
-                                   vmInternalCSName =  
vmMo.getCustomFieldValue(CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
-                               } catch (Exception e) {
-                                   s_logger.error("Unable to retrieve custom 
field value for internal VM name");
-                               }
+                               
                         if ( (vmNameInvCenter != null && 
name.equalsIgnoreCase(vmNameInvCenter))
                                 || (vmInternalCSName != null && 
name.equalsIgnoreCase(vmInternalCSName)) ) {
+                               VirtualMachineMO vmMo = new 
VirtualMachineMO(context, oc.getObj());
                             return vmMo;
                         }
                     }

Reply via email to