mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-3568: finalize logging in the refactored code on new vCenter API management facility
This commit is contained in:
parent
4520a01777
commit
9f84eb2f1f
|
|
@ -68,6 +68,8 @@ public class VmwareContext {
|
|||
|
||||
private VmwareContextPool _pool;
|
||||
private String _poolKey;
|
||||
|
||||
private static volatile int s_outstandingCount = 0;
|
||||
|
||||
static {
|
||||
try {
|
||||
|
|
@ -87,6 +89,8 @@ public class VmwareContext {
|
|||
|
||||
_vimClient = client;
|
||||
_serverAddress = address;
|
||||
|
||||
registerOutstandingContext();
|
||||
}
|
||||
|
||||
public void registerStockObject(String name, Object obj) {
|
||||
|
|
@ -154,6 +158,18 @@ public class VmwareContext {
|
|||
public void idleCheck() throws Exception {
|
||||
getRootFolder();
|
||||
}
|
||||
|
||||
public static int getOutstandingContextCount() {
|
||||
return s_outstandingCount;
|
||||
}
|
||||
|
||||
public static void registerOutstandingContext() {
|
||||
s_outstandingCount++;
|
||||
}
|
||||
|
||||
public static void unregisterOutstandingContext() {
|
||||
s_outstandingCount--;
|
||||
}
|
||||
|
||||
public ManagedObjectReference getHostMorByPath(String inventoryPath) throws Exception {
|
||||
assert(inventoryPath != null);
|
||||
|
|
@ -614,6 +630,7 @@ public class VmwareContext {
|
|||
} catch(Exception e) {
|
||||
s_logger.warn("Unexpected exception: ", e);
|
||||
}
|
||||
unregisterOutstandingContext();
|
||||
}
|
||||
|
||||
public static class TrustAllManager implements javax.net.ssl.TrustManager, javax.net.ssl.X509TrustManager {
|
||||
|
|
|
|||
|
|
@ -63,15 +63,17 @@ public class VmwareContextPool {
|
|||
|
||||
if(l.size() > 0) {
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("Return a VmwareContext from the pool.");
|
||||
s_logger.trace("Return a VmwareContext from the idle pool: " + poolKey + ". current pool size: " + l.size() + ", outstanding count: " + VmwareContext.getOutstandingContextCount());
|
||||
|
||||
VmwareContext context = l.remove(0);
|
||||
context.setPoolInfo(this, poolKey);
|
||||
return context;
|
||||
}
|
||||
|
||||
if(s_logger.isInfoEnabled())
|
||||
s_logger.info("No VmwareContext is available from the idle pool, create a new one");
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("No VmwareContext is available from the idle pool: " + poolKey + ", create a new one and current outstanding count is: " + VmwareContext.getOutstandingContextCount());
|
||||
|
||||
// TODO, we need to control the maximum number of outstanding VmwareContext object in the future
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -89,9 +91,13 @@ public class VmwareContextPool {
|
|||
if(l.size() < _maxIdleQueueLength) {
|
||||
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: " + VmwareContext.getOutstandingContextCount());
|
||||
} else {
|
||||
if(s_logger.isInfoEnabled())
|
||||
s_logger.info("VmwareContextPool queue exceeds limits, queue size: " + l.size());
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("VmwareContextPool queue exceeds limits, queue size: " + l.size());
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -99,11 +105,13 @@ public class VmwareContextPool {
|
|||
|
||||
private void getIdleCheckContexts(List<VmwareContext> l, int batchSize) {
|
||||
synchronized(_pool) {
|
||||
for(List<VmwareContext> entryList : _pool.values()) {
|
||||
if(entryList != null) {
|
||||
for(Map.Entry<String, List<VmwareContext>> entry : _pool.entrySet()) {
|
||||
if(entry.getValue() != null) {
|
||||
int count = 0;
|
||||
while(entryList.size() > 0 && count < batchSize) {
|
||||
l.add(entryList.remove(0));
|
||||
while(entry.getValue().size() > 0 && count < batchSize) {
|
||||
VmwareContext context = entry.getValue().remove(0);
|
||||
context.setPoolInfo(this, entry.getKey());
|
||||
l.add(context);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
|
@ -132,6 +140,9 @@ public class VmwareContextPool {
|
|||
for(VmwareContext context : l) {
|
||||
try {
|
||||
context.idleCheck();
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("Recyle context after idle check");
|
||||
returnContext(context);
|
||||
} catch(Throwable e) {
|
||||
s_logger.warn("Exception caught during VmwareContext idle check, close and discard the context", e);
|
||||
|
|
|
|||
Loading…
Reference in New Issue