From e338cdd1ed5ca370ca24b5e715131d91bd24675a Mon Sep 17 00:00:00 2001 From: Likitha Shetty Date: Tue, 23 Sep 2014 13:32:06 +0530 Subject: [PATCH] BUG-ID: CLOUDSTACK-7652. [VMware] 'SOAPFaultException: The object has already been deleted or has not been completely created' exceptions. If CCP thread local context which is used to handle connections to a vCenter is being re-used, validate that the context corresponds to the right vCenter API session. (cherry picked from commit 6b069703666c33636a545e7093eccf04efff88e7) --- .../vmware/resource/VmwareResource.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) 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 489cf434c4f..226a884bc45 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 @@ -239,6 +239,7 @@ import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost; import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostNetworkSummary; import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostResourceSummary; import com.cloud.hypervisor.vmware.util.VmwareContext; +import com.cloud.hypervisor.vmware.util.VmwareContextPool; import com.cloud.hypervisor.vmware.util.VmwareHelper; import com.cloud.network.Networks; import com.cloud.network.Networks.BroadcastDomainType; @@ -4794,14 +4795,21 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa VmwareContext context = null; if(s_serviceContext.get() != null) { context = s_serviceContext.get(); - if (context.validate()) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("ThreadLocal context is still valid, just reuse"); + String poolKey = VmwareContextPool.composePoolKey(_vCenterAddress, _username); + // Before re-using the thread local context, ensure it corresponds to the right vCenter API session and that it is valid to make calls. + if(context.getPoolKey().equals(poolKey)) { + if (context.validate()) { + if (s_logger.isTraceEnabled()) { + s_logger.trace("ThreadLocal context is still valid, just reuse"); + } + return context; + } else { + s_logger.info("Validation of the context failed, dispose and use a new one"); + invalidateServiceContext(context); } - return context; } else { - s_logger.info("Validation of the context failed, dispose and use a new one"); - invalidateServiceContext(context); + // Exisitng ThreadLocal context corresponds to a different vCenter API session. Why has it not been recycled? + s_logger.warn("ThreadLocal VMware context: " + poolKey + " doesn't correspond to the right vCenter. Expected VMware context: " + context.getPoolKey()); } } try {