Skip to content

Commit 9f84eb2

Browse files
committed
CLOUDSTACK-3568: finalize logging in the refactored code on new vCenter API management facility
1 parent 4520a01 commit 9f84eb2

2 files changed

Lines changed: 37 additions & 9 deletions

File tree

‎vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContext.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public class VmwareContext {
6868

6969
private VmwareContextPool _pool;
7070
private String _poolKey;
71+
72+
private static volatile int s_outstandingCount = 0;
7173

7274
static {
7375
try {
@@ -87,6 +89,8 @@ public VmwareContext(VmwareClient client, String address) {
8789

8890
_vimClient = client;
8991
_serverAddress = address;
92+
93+
registerOutstandingContext();
9094
}
9195

9296
public void registerStockObject(String name, Object obj) {
@@ -154,6 +158,18 @@ public String getPoolKey() {
154158
public void idleCheck() throws Exception {
155159
getRootFolder();
156160
}
161+
162+
public static int getOutstandingContextCount() {
163+
return s_outstandingCount;
164+
}
165+
166+
public static void registerOutstandingContext() {
167+
s_outstandingCount++;
168+
}
169+
170+
public static void unregisterOutstandingContext() {
171+
s_outstandingCount--;
172+
}
157173

158174
public ManagedObjectReference getHostMorByPath(String inventoryPath) throws Exception {
159175
assert(inventoryPath != null);
@@ -614,6 +630,7 @@ public void close() {
614630
} catch(Exception e) {
615631
s_logger.warn("Unexpected exception: ", e);
616632
}
633+
unregisterOutstandingContext();
617634
}
618635

619636
public static class TrustAllManager implements javax.net.ssl.TrustManager, javax.net.ssl.X509TrustManager {

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,17 @@ public VmwareContext getContext(String vCenterAddress, String vCenterUserName) {
6363

6464
if(l.size() > 0) {
6565
if(s_logger.isTraceEnabled())
66-
s_logger.trace("Return a VmwareContext from the pool.");
66+
s_logger.trace("Return a VmwareContext from the idle pool: " + poolKey + ". current pool size: " + l.size() + ", outstanding count: " + VmwareContext.getOutstandingContextCount());
6767

6868
VmwareContext context = l.remove(0);
6969
context.setPoolInfo(this, poolKey);
7070
return context;
7171
}
7272

73-
if(s_logger.isInfoEnabled())
74-
s_logger.info("No VmwareContext is available from the idle pool, create a new one");
73+
if(s_logger.isTraceEnabled())
74+
s_logger.trace("No VmwareContext is available from the idle pool: " + poolKey + ", create a new one and current outstanding count is: " + VmwareContext.getOutstandingContextCount());
75+
76+
// TODO, we need to control the maximum number of outstanding VmwareContext object in the future
7577
return null;
7678
}
7779
}
@@ -89,21 +91,27 @@ public void returnContext(VmwareContext context) {
8991
if(l.size() < _maxIdleQueueLength) {
9092
context.clearStockObjects();
9193
l.add(context);
94+
95+
if(s_logger.isTraceEnabled())
96+
s_logger.trace("Recycle VmwareContext into idle pool: " + context.getPoolKey() + ", current idle pool size: "
97+
+ l.size() + ", outstanding count: " + VmwareContext.getOutstandingContextCount());
9298
} else {
93-
if(s_logger.isInfoEnabled())
94-
s_logger.info("VmwareContextPool queue exceeds limits, queue size: " + l.size());
99+
if(s_logger.isTraceEnabled())
100+
s_logger.trace("VmwareContextPool queue exceeds limits, queue size: " + l.size());
95101
context.close();
96102
}
97103
}
98104
}
99105

100106
private void getIdleCheckContexts(List<VmwareContext> l, int batchSize) {
101107
synchronized(_pool) {
102-
for(List<VmwareContext> entryList : _pool.values()) {
103-
if(entryList != null) {
108+
for(Map.Entry<String, List<VmwareContext>> entry : _pool.entrySet()) {
109+
if(entry.getValue() != null) {
104110
int count = 0;
105-
while(entryList.size() > 0 && count < batchSize) {
106-
l.add(entryList.remove(0));
111+
while(entry.getValue().size() > 0 && count < batchSize) {
112+
VmwareContext context = entry.getValue().remove(0);
113+
context.setPoolInfo(this, entry.getKey());
114+
l.add(context);
107115
count++;
108116
}
109117
}
@@ -132,6 +140,9 @@ private void doIdleCheck() {
132140
for(VmwareContext context : l) {
133141
try {
134142
context.idleCheck();
143+
144+
if(s_logger.isTraceEnabled())
145+
s_logger.trace("Recyle context after idle check");
135146
returnContext(context);
136147
} catch(Throwable e) {
137148
s_logger.warn("Exception caught during VmwareContext idle check, close and discard the context", e);

0 commit comments

Comments
 (0)