CLOUDSTACK-7260: Management server not responding after some time for

Vmware due to Oom (cannot create native thread).
This commit is contained in:
Min Chen 2014-08-05 17:26:10 -07:00
parent b9d834e838
commit 9866c648eb
2 changed files with 61 additions and 49 deletions

View File

@ -3847,6 +3847,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
@Override
public PingCommand getCurrentStatus(long id) {
try {
gcAndKillHungWorkerVMs();
VmwareContext context = getServiceContext();
VmwareHypervisorHost hyperHost = getHyperHost(context);
@ -3859,6 +3860,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
return null;
}
return new PingRoutingCommand(getType(), id, syncHostVmStates());
} finally {
recycleServiceContext();
}
}
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,11 +4663,10 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
_guestTrafficInfo = (VmwareTrafficLabel)params.get("guestTrafficInfo");
_publicTrafficInfo = (VmwareTrafficLabel)params.get("publicTrafficInfo");
VmwareContext context = getServiceContext();
// 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);
if (mgr == null) {
throw new ConfigurationException("Invalid vmwareContext: vmwareMgr stock object is not set or cleared.");
}
mgr.setupResourceStartupParams(params);
CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(context, context.getServiceContent().getCustomFieldsManager());
@ -4690,10 +4691,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
_vsmCredentials = mgr.getNexusVSMCredentialsByClusterId(Long.parseLong(_cluster));
}
} catch (Exception e) {
s_logger.error("Unexpected Exception ", e);
}
if (_privateNetworkVSwitchName == null) {
_privateNetworkVSwitchName = (String)params.get("private.network.vswitch.name");
}
@ -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);
}
}

View File

@ -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();
}
}