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 cdd0c29c9fe..11163e90d6f 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 @@ -89,7 +89,7 @@ public class VmwareContextFactory { } else { // Validate current context and verify if vCenter session timeout value of the context matches the timeout value set by Admin if (!context.validate() || (context.getVimClient().getVcenterSessionTimeout() != s_vmwareMgr.getVcenterSessionTimeout())) { - s_logger.info("Validation of the context faild. dispose and create a new one"); + s_logger.info("Validation of the context failed, dispose and create a new one"); context.close(); context = create(vCenterAddress, vCenterUserName, vCenterPassword); } 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 4aa6f27991a..8b252763e78 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 @@ -6896,10 +6896,16 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa @Override public VmwareContext getServiceContext(Command cmd) { - if (s_serviceContext.get() != null) - return s_serviceContext.get(); - VmwareContext context = null; + if(s_serviceContext.get() != null) { + context = s_serviceContext.get(); + if (context.validate()) { + return context; + } else { + s_logger.info("Validation of the context failed, dispose and use a new one"); + invalidateServiceContext(context); + } + } try { context = VmwareContextFactory.getContext(_vCenterAddress, _username, _password); s_serviceContext.set(context); diff --git a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java index c91d7b6f2cd..7e08aeceac9 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java +++ b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java @@ -214,18 +214,23 @@ public class VmwareSecondaryStorageResourceHandler implements SecondaryStorageRe _resource.ensureOutgoingRuleForAddress(vCenterAddress); VmwareContext context = currentContext.get(); - if (context == null) { + if (context != null) { + if(!context.validate()) { + invalidateServiceContext(context); + context = null; + } else { + context.registerStockObject("serviceconsole", cmd.getContextParam("serviceconsole")); + context.registerStockObject("manageportgroup", cmd.getContextParam("manageportgroup")); + context.registerStockObject("noderuninfo", cmd.getContextParam("noderuninfo")); + } + } + if(context == null) { s_logger.info("Open new VmwareContext. vCenter: " + vCenterAddress + ", user: " + username + ", password: " + - StringUtils.getMaskedPasswordForDisplay(password)); + StringUtils.getMaskedPasswordForDisplay(password)); VmwareSecondaryStorageContextFactory.setVcenterSessionTimeout(vCenterSessionTimeout); context = VmwareSecondaryStorageContextFactory.getContext(vCenterAddress, username, password); } - if (context != null) { - context.registerStockObject("serviceconsole", cmd.getContextParam("serviceconsole")); - context.registerStockObject("manageportgroup", cmd.getContextParam("manageportgroup")); - context.registerStockObject("noderuninfo", cmd.getContextParam("noderuninfo")); - } currentContext.set(context); return context; } catch (Exception e) { 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 4c3ff55ae4d..eaa205ebba3 100755 --- a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContext.java +++ b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContext.java @@ -37,6 +37,7 @@ import java.util.Map; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLSession; +import javax.xml.ws.soap.SOAPFaultException; import org.apache.log4j.Logger; @@ -638,16 +639,18 @@ public class VmwareContext { public void close() { clearStockObjects(); try { + s_logger.info("Disconnecting VMware session"); _vimClient.disconnect(); + } catch(SOAPFaultException sfe) { + s_logger.debug("Tried to disconnect a session that is no longer valid"); } catch (Exception e) { s_logger.warn("Unexpected exception: ", e); + } finally { + if (_pool != null) { + _pool.unregisterOutstandingContext(this); + } + unregisterOutstandingContext(); } - - if (_pool != null) { - _pool.unregisterOutstandingContext(this); - } - - unregisterOutstandingContext(); } public static class TrustAllManager implements javax.net.ssl.TrustManager, javax.net.ssl.X509TrustManager {