Skip to content

Commit 9866c64

Browse files
committed
CLOUDSTACK-7260: Management server not responding after some time for
Vmware due to Oom (cannot create native thread).
1 parent b9d834e commit 9866c64

2 files changed

Lines changed: 61 additions & 49 deletions

File tree

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3847,18 +3847,22 @@ public IAgentControl getAgentControl() {
38473847

38483848
@Override
38493849
public PingCommand getCurrentStatus(long id) {
3850-
gcAndKillHungWorkerVMs();
3851-
VmwareContext context = getServiceContext();
3852-
VmwareHypervisorHost hyperHost = getHyperHost(context);
38533850
try {
3854-
if (!hyperHost.isHyperHostConnected()) {
3851+
gcAndKillHungWorkerVMs();
3852+
VmwareContext context = getServiceContext();
3853+
VmwareHypervisorHost hyperHost = getHyperHost(context);
3854+
try {
3855+
if (!hyperHost.isHyperHostConnected()) {
3856+
return null;
3857+
}
3858+
} catch (Exception e) {
3859+
s_logger.error("Unexpected exception", e);
38553860
return null;
38563861
}
3857-
} catch (Exception e) {
3858-
s_logger.error("Unexpected exception", e);
3859-
return null;
3862+
return new PingRoutingCommand(getType(), id, syncHostVmStates());
3863+
} finally {
3864+
recycleServiceContext();
38603865
}
3861-
return new PingRoutingCommand(getType(), id, syncHostVmStates());
38623866
}
38633867

38643868
private void gcAndKillHungWorkerVMs() {
@@ -3926,8 +3930,6 @@ private void gcAndKillHungWorkerVMs() {
39263930
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
39273931
invalidateServiceContext();
39283932
}
3929-
} finally {
3930-
recycleServiceContext();
39313933
}
39323934
}
39333935

@@ -4661,37 +4663,32 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
46614663
_guestTrafficInfo = (VmwareTrafficLabel)params.get("guestTrafficInfo");
46624664
_publicTrafficInfo = (VmwareTrafficLabel)params.get("publicTrafficInfo");
46634665
VmwareContext context = getServiceContext();
4666+
VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
4667+
if (mgr == null) {
4668+
throw new ConfigurationException("Invalid vmwareContext: vmwareMgr stock object is not set or cleared.");
4669+
}
4670+
mgr.setupResourceStartupParams(params);
46644671

4665-
// TODO ??? this is an invalid usage pattern. need to fix the reference to VolumeManagerImp here at resource file
4666-
// volMgr = ComponentContext.inject(VolumeManagerImpl.class);
4667-
try {
4668-
VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
4669-
mgr.setupResourceStartupParams(params);
4672+
CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(context, context.getServiceContent().getCustomFieldsManager());
4673+
cfmMo.ensureCustomFieldDef("Datastore", CustomFieldConstants.CLOUD_UUID);
4674+
if (_publicTrafficInfo != null && _publicTrafficInfo.getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch || _guestTrafficInfo != null &&
4675+
_guestTrafficInfo.getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch) {
4676+
cfmMo.ensureCustomFieldDef("DistributedVirtualPortgroup", CustomFieldConstants.CLOUD_GC_DVP);
4677+
}
4678+
cfmMo.ensureCustomFieldDef("Network", CustomFieldConstants.CLOUD_GC);
4679+
cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_UUID);
4680+
cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_NIC_MASK);
4681+
cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
4682+
cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_WORKER);
4683+
cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_WORKER_TAG);
46704684

4671-
CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(context, context.getServiceContent().getCustomFieldsManager());
4672-
cfmMo.ensureCustomFieldDef("Datastore", CustomFieldConstants.CLOUD_UUID);
4673-
if (_publicTrafficInfo != null && _publicTrafficInfo.getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch || _guestTrafficInfo != null &&
4674-
_guestTrafficInfo.getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch) {
4675-
cfmMo.ensureCustomFieldDef("DistributedVirtualPortgroup", CustomFieldConstants.CLOUD_GC_DVP);
4676-
}
4677-
cfmMo.ensureCustomFieldDef("Network", CustomFieldConstants.CLOUD_GC);
4678-
cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_UUID);
4679-
cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_NIC_MASK);
4680-
cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
4681-
cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_WORKER);
4682-
cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_WORKER_TAG);
4683-
4684-
VmwareHypervisorHost hostMo = this.getHyperHost(context);
4685-
_hostName = hostMo.getHyperHostName();
4686-
4687-
if (_guestTrafficInfo.getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch ||
4688-
_publicTrafficInfo.getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch) {
4689-
_privateNetworkVSwitchName = mgr.getPrivateVSwitchName(Long.parseLong(_dcId), HypervisorType.VMware);
4690-
_vsmCredentials = mgr.getNexusVSMCredentialsByClusterId(Long.parseLong(_cluster));
4691-
}
4685+
VmwareHypervisorHost hostMo = this.getHyperHost(context);
4686+
_hostName = hostMo.getHyperHostName();
46924687

4693-
} catch (Exception e) {
4694-
s_logger.error("Unexpected Exception ", e);
4688+
if (_guestTrafficInfo.getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch ||
4689+
_publicTrafficInfo.getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch) {
4690+
_privateNetworkVSwitchName = mgr.getPrivateVSwitchName(Long.parseLong(_dcId), HypervisorType.VMware);
4691+
_vsmCredentials = mgr.getNexusVSMCredentialsByClusterId(Long.parseLong(_cluster));
46954692
}
46964693

46974694
if (_privateNetworkVSwitchName == null) {
@@ -4724,31 +4721,37 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
47244721
_publicTrafficInfo.getVirtualSwitchType() + " : " + _publicTrafficInfo.getVirtualSwitchName() + ", guest traffic over " +
47254722
_guestTrafficInfo.getVirtualSwitchType() + " : " + _guestTrafficInfo.getVirtualSwitchName());
47264723

4727-
value = params.get("vmware.create.full.clone").toString();
4728-
if (value != null && value.equalsIgnoreCase("true")) {
4724+
Boolean boolObj = (Boolean)params.get("vmware.create.full.clone");
4725+
if (boolObj != null && boolObj.booleanValue()) {
47294726
_fullCloneFlag = true;
47304727
} else {
47314728
_fullCloneFlag = false;
47324729
}
47334730

4734-
value = params.get("vm.instancename.flag").toString();
4735-
if (value != null && value.equalsIgnoreCase("true")) {
4731+
boolObj = (Boolean)params.get("vm.instancename.flag");
4732+
if (boolObj != null && boolObj.booleanValue()) {
47364733
_instanceNameFlag = true;
47374734
} else {
47384735
_instanceNameFlag = false;
47394736
}
47404737

47414738
value = (String)params.get("scripts.timeout");
47424739
int timeout = NumbersUtil.parseInt(value, 1440) * 1000;
4743-
VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
47444740
_storageProcessor = new VmwareStorageProcessor((VmwareHostService)this, _fullCloneFlag, (VmwareStorageMount)mgr, timeout, this, _shutdownWaitMs, null);
47454741
storageHandler = new VmwareStorageSubsystemCommandHandler(_storageProcessor);
47464742

47474743
_vrResource = new VirtualRoutingResource(this);
47484744
if (!_vrResource.configure(name, params)) {
47494745
throw new ConfigurationException("Unable to configure VirtualRoutingResource");
47504746
}
4747+
4748+
if (s_logger.isTraceEnabled()) {
4749+
s_logger.trace("Successfully configured VmwareResource.");
4750+
}
47514751
return true;
4752+
} catch (Exception e) {
4753+
s_logger.error("Unexpected Exception ", e);
4754+
throw new ConfigurationException("Failed to configure VmwareResource due to unexpect exception.");
47524755
} finally {
47534756
recycleServiceContext();
47544757
}
@@ -4787,6 +4790,9 @@ public VmwareContext getServiceContext(Command cmd) {
47874790
if(s_serviceContext.get() != null) {
47884791
context = s_serviceContext.get();
47894792
if (context.validate()) {
4793+
if (s_logger.isTraceEnabled()) {
4794+
s_logger.trace("ThreadLocal context is still valid, just reuse");
4795+
}
47904796
return context;
47914797
} else {
47924798
s_logger.info("Validation of the context failed, dispose and use a new one");
@@ -4814,10 +4820,16 @@ public void invalidateServiceContext(VmwareContext context) {
48144820

48154821
private static void recycleServiceContext() {
48164822
VmwareContext context = s_serviceContext.get();
4823+
if (s_logger.isTraceEnabled()) {
4824+
s_logger.trace("Reset threadlocal context to null");
4825+
}
48174826
s_serviceContext.set(null);
48184827

48194828
if (context != null) {
48204829
assert (context.getPool() != null);
4830+
if (s_logger.isTraceEnabled()) {
4831+
s_logger.trace("Recycling threadlocal context to pool");
4832+
}
48214833
context.getPool().returnContext(context);
48224834
}
48234835
}

vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContextPool.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ public VmwareContext getContext(String vCenterAddress, String vCenterUserName) {
8383
VmwareContext context = l.remove(0);
8484
context.setPoolInfo(this, poolKey);
8585

86-
if (s_logger.isTraceEnabled())
87-
s_logger.trace("Return a VmwareContext from the idle pool: " + poolKey + ". current pool size: " + l.size() + ", outstanding count: " +
86+
if (s_logger.isInfoEnabled())
87+
s_logger.info("Return a VmwareContext from the idle pool: " + poolKey + ". current pool size: " + l.size() + ", outstanding count: " +
8888
VmwareContext.getOutstandingContextCount());
8989
return context;
9090
}
@@ -108,12 +108,12 @@ public void returnContext(VmwareContext context) {
108108
context.clearStockObjects();
109109
l.add(context);
110110

111-
if (s_logger.isTraceEnabled())
112-
s_logger.trace("Recycle VmwareContext into idle pool: " + context.getPoolKey() + ", current idle pool size: " + l.size() + ", outstanding count: " +
111+
if (s_logger.isInfoEnabled())
112+
s_logger.info("Recycle VmwareContext into idle pool: " + context.getPoolKey() + ", current idle pool size: " + l.size() + ", outstanding count: " +
113113
VmwareContext.getOutstandingContextCount());
114114
} else {
115-
if (s_logger.isTraceEnabled())
116-
s_logger.trace("VmwareContextPool queue exceeds limits, queue size: " + l.size());
115+
if (s_logger.isInfoEnabled())
116+
s_logger.info("VmwareContextPool queue exceeds limits, queue size: " + l.size());
117117
context.close();
118118
}
119119
}

0 commit comments

Comments
 (0)