Repository: cloudstack Updated Branches: refs/heads/master b9d834e83 -> 9866c648e
CLOUDSTACK-7260: Management server not responding after some time for Vmware due to Oom (cannot create native thread). Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/9866c648 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9866c648 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9866c648 Branch: refs/heads/master Commit: 9866c648eb5e6ce6ded1b6dcadbb77240fe0e683 Parents: b9d834e Author: Min Chen <min.c...@citrix.com> Authored: Tue Aug 5 17:26:10 2014 -0700 Committer: Min Chen <min.c...@citrix.com> Committed: Tue Aug 5 17:36:53 2014 -0700 ---------------------------------------------------------------------- .../vmware/resource/VmwareResource.java | 98 +++++++++++--------- .../vmware/util/VmwareContextPool.java | 12 +-- 2 files changed, 61 insertions(+), 49 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9866c648/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 8a2488d..60007e3 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 @@ -3847,18 +3847,22 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa @Override public PingCommand getCurrentStatus(long id) { - gcAndKillHungWorkerVMs(); - VmwareContext context = getServiceContext(); - VmwareHypervisorHost hyperHost = getHyperHost(context); try { - if (!hyperHost.isHyperHostConnected()) { + gcAndKillHungWorkerVMs(); + VmwareContext context = getServiceContext(); + VmwareHypervisorHost hyperHost = getHyperHost(context); + try { + if (!hyperHost.isHyperHostConnected()) { + return null; + } + } catch (Exception e) { + s_logger.error("Unexpected exception", e); return null; } - } catch (Exception e) { - s_logger.error("Unexpected exception", e); - return null; + return new PingRoutingCommand(getType(), id, syncHostVmStates()); + } finally { + recycleServiceContext(); } - return new PingRoutingCommand(getType(), id, syncHostVmStates()); } private void gcAndKillHungWorkerVMs() { @@ -3926,8 +3930,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context"); invalidateServiceContext(); } - } finally { - recycleServiceContext(); } } @@ -4661,37 +4663,32 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa _guestTrafficInfo = (VmwareTrafficLabel)params.get("guestTrafficInfo"); _publicTrafficInfo = (VmwareTrafficLabel)params.get("publicTrafficInfo"); VmwareContext context = getServiceContext(); + VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME); + if (mgr == null) { + throw new ConfigurationException("Invalid vmwareContext: vmwareMgr stock object is not set or cleared."); + } + mgr.setupResourceStartupParams(params); - // TODO ??? this is an invalid usage pattern. need to fix the reference to VolumeManagerImp here at resource file - // volMgr = ComponentContext.inject(VolumeManagerImpl.class); - try { - VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME); - mgr.setupResourceStartupParams(params); + CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(context, context.getServiceContent().getCustomFieldsManager()); + cfmMo.ensureCustomFieldDef("Datastore", CustomFieldConstants.CLOUD_UUID); + if (_publicTrafficInfo != null && _publicTrafficInfo.getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch || _guestTrafficInfo != null && + _guestTrafficInfo.getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch) { + cfmMo.ensureCustomFieldDef("DistributedVirtualPortgroup", CustomFieldConstants.CLOUD_GC_DVP); + } + cfmMo.ensureCustomFieldDef("Network", CustomFieldConstants.CLOUD_GC); + cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_UUID); + cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_NIC_MASK); + cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME); + cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_WORKER); + cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_WORKER_TAG); - CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(context, context.getServiceContent().getCustomFieldsManager()); - cfmMo.ensureCustomFieldDef("Datastore", CustomFieldConstants.CLOUD_UUID); - if (_publicTrafficInfo != null && _publicTrafficInfo.getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch || _guestTrafficInfo != null && - _guestTrafficInfo.getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch) { - cfmMo.ensureCustomFieldDef("DistributedVirtualPortgroup", CustomFieldConstants.CLOUD_GC_DVP); - } - cfmMo.ensureCustomFieldDef("Network", CustomFieldConstants.CLOUD_GC); - cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_UUID); - cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_NIC_MASK); - cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME); - cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_WORKER); - cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_WORKER_TAG); - - VmwareHypervisorHost hostMo = this.getHyperHost(context); - _hostName = hostMo.getHyperHostName(); - - if (_guestTrafficInfo.getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch || - _publicTrafficInfo.getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch) { - _privateNetworkVSwitchName = mgr.getPrivateVSwitchName(Long.parseLong(_dcId), HypervisorType.VMware); - _vsmCredentials = mgr.getNexusVSMCredentialsByClusterId(Long.parseLong(_cluster)); - } + VmwareHypervisorHost hostMo = this.getHyperHost(context); + _hostName = hostMo.getHyperHostName(); - } catch (Exception e) { - s_logger.error("Unexpected Exception ", e); + if (_guestTrafficInfo.getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch || + _publicTrafficInfo.getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch) { + _privateNetworkVSwitchName = mgr.getPrivateVSwitchName(Long.parseLong(_dcId), HypervisorType.VMware); + _vsmCredentials = mgr.getNexusVSMCredentialsByClusterId(Long.parseLong(_cluster)); } if (_privateNetworkVSwitchName == null) { @@ -4724,15 +4721,15 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa _publicTrafficInfo.getVirtualSwitchType() + " : " + _publicTrafficInfo.getVirtualSwitchName() + ", guest traffic over " + _guestTrafficInfo.getVirtualSwitchType() + " : " + _guestTrafficInfo.getVirtualSwitchName()); - value = params.get("vmware.create.full.clone").toString(); - if (value != null && value.equalsIgnoreCase("true")) { + Boolean boolObj = (Boolean)params.get("vmware.create.full.clone"); + if (boolObj != null && boolObj.booleanValue()) { _fullCloneFlag = true; } else { _fullCloneFlag = false; } - value = params.get("vm.instancename.flag").toString(); - if (value != null && value.equalsIgnoreCase("true")) { + boolObj = (Boolean)params.get("vm.instancename.flag"); + if (boolObj != null && boolObj.booleanValue()) { _instanceNameFlag = true; } else { _instanceNameFlag = false; @@ -4740,7 +4737,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa value = (String)params.get("scripts.timeout"); int timeout = NumbersUtil.parseInt(value, 1440) * 1000; - VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME); _storageProcessor = new VmwareStorageProcessor((VmwareHostService)this, _fullCloneFlag, (VmwareStorageMount)mgr, timeout, this, _shutdownWaitMs, null); storageHandler = new VmwareStorageSubsystemCommandHandler(_storageProcessor); @@ -4748,7 +4744,14 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa if (!_vrResource.configure(name, params)) { throw new ConfigurationException("Unable to configure VirtualRoutingResource"); } + + if (s_logger.isTraceEnabled()) { + s_logger.trace("Successfully configured VmwareResource."); + } return true; + } catch (Exception e) { + s_logger.error("Unexpected Exception ", e); + throw new ConfigurationException("Failed to configure VmwareResource due to unexpect exception."); } finally { recycleServiceContext(); } @@ -4787,6 +4790,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa 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"); + } return context; } else { s_logger.info("Validation of the context failed, dispose and use a new one"); @@ -4814,10 +4820,16 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa private static void recycleServiceContext() { VmwareContext context = s_serviceContext.get(); + if (s_logger.isTraceEnabled()) { + s_logger.trace("Reset threadlocal context to null"); + } s_serviceContext.set(null); if (context != null) { assert (context.getPool() != null); + if (s_logger.isTraceEnabled()) { + s_logger.trace("Recycling threadlocal context to pool"); + } context.getPool().returnContext(context); } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9866c648/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContextPool.java ---------------------------------------------------------------------- diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContextPool.java b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContextPool.java index c97c01f..e28c974 100644 --- a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContextPool.java +++ b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContextPool.java @@ -83,8 +83,8 @@ public class VmwareContextPool { VmwareContext context = l.remove(0); context.setPoolInfo(this, poolKey); - if (s_logger.isTraceEnabled()) - s_logger.trace("Return a VmwareContext from the idle pool: " + poolKey + ". current pool size: " + l.size() + ", outstanding count: " + + if (s_logger.isInfoEnabled()) + s_logger.info("Return a VmwareContext from the idle pool: " + poolKey + ". current pool size: " + l.size() + ", outstanding count: " + VmwareContext.getOutstandingContextCount()); return context; } @@ -108,12 +108,12 @@ public class VmwareContextPool { context.clearStockObjects(); l.add(context); - if (s_logger.isTraceEnabled()) - s_logger.trace("Recycle VmwareContext into idle pool: " + context.getPoolKey() + ", current idle pool size: " + l.size() + ", outstanding count: " + + if (s_logger.isInfoEnabled()) + s_logger.info("Recycle VmwareContext into idle pool: " + context.getPoolKey() + ", current idle pool size: " + l.size() + ", outstanding count: " + VmwareContext.getOutstandingContextCount()); } else { - if (s_logger.isTraceEnabled()) - s_logger.trace("VmwareContextPool queue exceeds limits, queue size: " + l.size()); + if (s_logger.isInfoEnabled()) + s_logger.info("VmwareContextPool queue exceeds limits, queue size: " + l.size()); context.close(); } }