cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kelv...@apache.org
Subject [3/3] git commit: updated refs/heads/master to f3c917d
Date Fri, 27 Sep 2013 23:07:32 GMT
CLOUDSTACK-4734: Validate and Fail-over to another VmwareContext object when it is from the
pool


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

Branch: refs/heads/master
Commit: f3c917db05bb6bfa964ccb4d7572f86c99124fce
Parents: 08c3b65
Author: Kelven Yang <kelveny@gmail.com>
Authored: Fri Sep 27 15:11:07 2013 -0700
Committer: Kelven Yang <kelveny@gmail.com>
Committed: Fri Sep 27 15:57:56 2013 -0700

----------------------------------------------------------------------
 .../vmware/resource/VmwareContextFactory.java   |  9 +++-
 .../VmwareSecondaryStorageContextFactory.java   | 10 ++++
 .../hypervisor/vmware/mo/DatacenterMO.java      |  8 ++-
 .../hypervisor/vmware/util/VmwareClient.java    | 51 +++++++++++++++++---
 .../hypervisor/vmware/util/VmwareContext.java   |  4 ++
 5 files changed, 71 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f3c917db/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareContextFactory.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareContextFactory.java
b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareContextFactory.java
index ed607e1..3079998 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareContextFactory.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareContextFactory.java
@@ -80,8 +80,15 @@ public class VmwareContextFactory {
 	
 	public static VmwareContext getContext(String vCenterAddress, String vCenterUserName, String
vCenterPassword) throws Exception {
 		VmwareContext context = s_pool.getContext(vCenterAddress, vCenterUserName);
-		if(context == null)
+		if(context == null) {
 			context = create(vCenterAddress, vCenterUserName, vCenterPassword);
+		} else {
+			if(!context.validate()) {
+				s_logger.info("Validation of the context faild. dispose and create a new one");
+				context.close();
+				context = create(vCenterAddress, vCenterUserName, vCenterPassword);
+			}
+		}
 		
 		if(context != null) {
 			context.registerStockObject(VmwareManager.CONTEXT_STOCK_NAME, s_vmwareMgr);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f3c917db/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageContextFactory.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageContextFactory.java
b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageContextFactory.java
index 5365e58..253d6fd 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageContextFactory.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageContextFactory.java
@@ -16,11 +16,15 @@
 // under the License.
 package com.cloud.storage.resource;
 
+import org.apache.log4j.Logger;
+
 import com.cloud.hypervisor.vmware.util.VmwareClient;
 import com.cloud.hypervisor.vmware.util.VmwareContext;
 import com.cloud.hypervisor.vmware.util.VmwareContextPool;
 
 public class VmwareSecondaryStorageContextFactory {
+    private static final Logger s_logger = Logger.getLogger(VmwareSecondaryStorageContextFactory.class);
+    
 	private static volatile int s_seq = 1;
 
 	private static VmwareContextPool s_pool;
@@ -51,6 +55,12 @@ public class VmwareSecondaryStorageContextFactory {
 		VmwareContext context = s_pool.getContext(vCenterAddress, vCenterUserName);
 		if(context == null) {
 			context = create(vCenterAddress, vCenterUserName, vCenterPassword);
+		} else {
+			if(!context.validate()) {
+				s_logger.info("Validation of the context faild. dispose and create a new one");
+				context.close();
+				context = create(vCenterAddress, vCenterUserName, vCenterPassword);
+			}
 		}
 		
 		if(context != null) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f3c917db/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java
index 1844b6a..03ba2b7 100755
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java
@@ -20,6 +20,8 @@ package com.cloud.hypervisor.vmware.mo;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.log4j.Logger;
+
 import com.cloud.hypervisor.vmware.util.VmwareContext;
 import com.cloud.utils.Pair;
 import com.vmware.vim25.CustomFieldStringValue;
@@ -37,6 +39,7 @@ import com.vmware.vim25.VirtualEthernetCardDistributedVirtualPortBackingInfo;
 import java.util.Arrays;
 
 public class DatacenterMO extends BaseMO {
+    private static final Logger s_logger = Logger.getLogger(DatacenterMO.class);
 
 	public DatacenterMO(VmwareContext context, ManagedObjectReference morDc) {
 		super(context, morDc);
@@ -50,7 +53,9 @@ public class DatacenterMO extends BaseMO {
 		super(context, null);
 
 		_mor = _context.getVimClient().getDecendentMoRef(_context.getRootFolder(), "Datacenter",
dcName);
-		assert(_mor != null);
+		if(_mor == null) {
+			s_logger.error("Unable to locate DC " + dcName);
+		}
 	}
 
 	@Override
@@ -61,7 +66,6 @@ public class DatacenterMO extends BaseMO {
 	public void registerTemplate(ManagedObjectReference morHost, String datastoreName,
 		String templateName, String templateFileName) throws Exception {
 
-
 		ManagedObjectReference morFolder = (ManagedObjectReference)_context.getVimClient().getDynamicProperty(
 			_mor, "vmFolder");
 		assert(morFolder != null);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f3c917db/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareClient.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareClient.java b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareClient.java
index d4e4256..b20217a 100644
--- a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareClient.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareClient.java
@@ -107,7 +107,6 @@ public class VmwareClient {
     }
 
     private ManagedObjectReference SVC_INST_REF = new ManagedObjectReference();
-    private ManagedObjectReference propCollectorRef;
     private static VimService vimService;
     private VimPortType vimPort;
     private String serviceCookie;
@@ -151,8 +150,6 @@ public class VmwareClient {
 
         vimPort.login(serviceContent.getSessionManager(), userName, password, null);
         isConnected = true;
-
-        propCollectorRef = serviceContent.getPropertyCollector();
     }
 
     /**
@@ -197,7 +194,7 @@ public class VmwareClient {
      * @return Service property collector
      */
     public ManagedObjectReference getPropCol() {
-        return propCollectorRef;
+        return getServiceContent().getPropertyCollector();
     }
 
     /**
@@ -207,6 +204,43 @@ public class VmwareClient {
         return getServiceContent().getRootFolder();
     }
 
+	public boolean validate() {
+		//
+		// There is no official API to validate an open vCenter API session. This is hacking way
to tell if
+		// an open vCenter API session is still valid for making calls.
+		//
+		// It will give false result if there really does not exist data-center in the inventory,
however, I consider
+		// this really is not possible in production deployment
+		//
+		
+        // Create PropertySpecs
+        PropertySpec pSpec = new PropertySpec();
+        pSpec.setType("Datacenter");
+        pSpec.setAll(false);
+        pSpec.getPathSet().add("name");
+
+        ObjectSpec oSpec = new ObjectSpec();
+        oSpec.setObj(getRootFolder());
+        oSpec.setSkip(false);
+        oSpec.getSelectSet().addAll(constructCompleteTraversalSpec());
+
+        PropertyFilterSpec spec = new PropertyFilterSpec();
+        spec.getPropSet().add(pSpec);
+        spec.getObjectSet().add(oSpec);
+        List<PropertyFilterSpec> specArr = new ArrayList<PropertyFilterSpec>();
+        specArr.add(spec);
+
+        try {
+        	List<ObjectContent> ocary = vimPort.retrieveProperties(getPropCol(), specArr);
+        	if(ocary != null && ocary.size() > 0)
+        		return true;
+        } catch(Exception e) {
+        	return false;
+        }
+        
+        return false;
+	}
+    
     /**
      * Get the property value of a managed object.
      *
@@ -266,7 +300,7 @@ public class VmwareClient {
         List<PropertyFilterSpec> specArr = new ArrayList<PropertyFilterSpec>();
         specArr.add(spec);
 
-        return vimPort.retrieveProperties(propCollectorRef, specArr);
+        return vimPort.retrieveProperties(getPropCol(), specArr);    
     }
 
     /**
@@ -334,7 +368,8 @@ public class VmwareClient {
         pSpec.setType(objmor.getType());
         spec.getPropSet().add(pSpec);
 
-        ManagedObjectReference filterSpecRef = vimPort.createFilter(propCollectorRef, spec,
true);
+        ManagedObjectReference propertyCollector = this.getPropCol();
+        ManagedObjectReference filterSpecRef = vimPort.createFilter(propertyCollector, spec,
true);
 
         boolean reached = false;
 
@@ -343,7 +378,7 @@ public class VmwareClient {
         List<ObjectUpdate> objupary = null;
         List<PropertyChange> propchgary = null;
         while (!reached) {
-            updateset = vimPort.waitForUpdates(propCollectorRef, version);
+            updateset = vimPort.waitForUpdates(propertyCollector, version);
             if (updateset == null || updateset.getFilterSet() == null) {
                 continue;
             }
@@ -546,7 +581,7 @@ public class VmwareClient {
         List<PropertyFilterSpec> specArr = new ArrayList<PropertyFilterSpec>();
         specArr.add(spec);
 
-        List<ObjectContent> ocary = vimPort.retrieveProperties(propCollectorRef, specArr);
+        List<ObjectContent> ocary = vimPort.retrieveProperties(getPropCol(), specArr);
 
         if (ocary == null || ocary.size() == 0) {
             return null;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f3c917db/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContext.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContext.java b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContext.java
index 6c3dab7..c499576 100755
--- a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContext.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContext.java
@@ -102,6 +102,10 @@ public class VmwareContext {
 		if(s_logger.isInfoEnabled())
 			s_logger.info("New VmwareContext object, current outstanding count: " + getOutstandingContextCount());
 	}
+	
+	public boolean validate() {
+		return _vimClient.validate();
+	}
 
 	public void registerStockObject(String name, Object obj) {
 		synchronized(_stockMap) {


Mime
View raw message