Skip to content

Commit c528e71

Browse files
committed
CLOUDSTACK-4390, CLOUDSTACK-4358: Enable full-clone deployment by default for VMware. Apply keep-alive kick for all outstanding vCenter sessions
1 parent b4a7d20 commit c528e71

5 files changed

Lines changed: 75 additions & 25 deletions

File tree

‎plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareContextFactory.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ public static VmwareContext create(String vCenterAddress, String vCenterUserName
6767
context.registerStockObject("serviceconsole", s_vmwareMgr.getServiceConsolePortGroupName());
6868
context.registerStockObject("manageportgroup", s_vmwareMgr.getManagementPortGroupName());
6969

70+
context.setPoolInfo(s_pool, VmwareContextPool.composePoolKey(vCenterAddress, vCenterUserName));
71+
s_pool.registerOutstandingContext(context);
72+
7073
return context;
7174
}
7275

@@ -76,8 +79,6 @@ public static VmwareContext getContext(String vCenterAddress, String vCenterUser
7679
context = create(vCenterAddress, vCenterUserName, vCenterPassword);
7780

7881
if(context != null) {
79-
context.setPoolInfo(s_pool, VmwareContextPool.composePoolKey(vCenterAddress, vCenterUserName));
80-
8182
context.registerStockObject(VmwareManager.CONTEXT_STOCK_NAME, s_vmwareMgr);
8283

8384
context.registerStockObject("serviceconsole", s_vmwareMgr.getServiceConsolePortGroupName());

‎plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageContextFactory.java‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
// under the License.
1717
package com.cloud.storage.resource;
1818

19-
import java.util.HashMap;
20-
import java.util.Iterator;
21-
import java.util.Map;
22-
2319
import com.cloud.hypervisor.vmware.util.VmwareClient;
2420
import com.cloud.hypervisor.vmware.util.VmwareContext;
2521
import com.cloud.hypervisor.vmware.util.VmwareContextPool;
@@ -44,6 +40,10 @@ public static VmwareContext create(String vCenterAddress, String vCenterUserName
4440
vimClient.connect(serviceUrl, vCenterUserName, vCenterPassword);
4541
VmwareContext context = new VmwareContext(vimClient, vCenterAddress);
4642
assert(context != null);
43+
44+
context.setPoolInfo(s_pool, VmwareContextPool.composePoolKey(vCenterAddress, vCenterUserName));
45+
s_pool.registerOutstandingContext(context);
46+
4747
return context;
4848
}
4949

@@ -54,8 +54,6 @@ public static VmwareContext getContext(String vCenterAddress, String vCenterUser
5454
}
5555

5656
if(context != null) {
57-
context.setPoolInfo(s_pool, VmwareContextPool.composePoolKey(vCenterAddress, vCenterUserName));
58-
5957
context.registerStockObject("username", vCenterUserName);
6058
context.registerStockObject("password", vCenterPassword);
6159
}

‎server/src/com/cloud/configuration/Config.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public enum Config {
282282
VmwareUseNexusVSwitch("Network", ManagementServer.class, Boolean.class, "vmware.use.nexus.vswitch", "false", "Enable/Disable Cisco Nexus 1000v vSwitch in VMware environment", null),
283283
VmwareUseDVSwitch("Network", ManagementServer.class, Boolean.class, "vmware.use.dvswitch", "false", "Enable/Disable Nexus/Vmware dvSwitch in VMware environment", null),
284284
VmwarePortsPerDVPortGroup("Network", ManagementServer.class, Integer.class, "vmware.ports.per.dvportgroup", "256", "Default number of ports per Vmware dvPortGroup in VMware environment", null),
285-
VmwareCreateFullClone("Advanced", ManagementServer.class, Boolean.class, "vmware.create.full.clone", "false", "If set to true, creates guest VMs as full clones on ESX", null),
285+
VmwareCreateFullClone("Advanced", ManagementServer.class, Boolean.class, "vmware.create.full.clone", "true", "If set to true, creates guest VMs as full clones on ESX", null),
286286
VmwareServiceConsole("Advanced", ManagementServer.class, String.class, "vmware.service.console", "Service Console", "Specify the service console network name(for ESX hosts)", null),
287287
VmwareManagementPortGroup("Advanced", ManagementServer.class, String.class, "vmware.management.portgroup", "Management Network", "Specify the management network name(for ESXi hosts)", null),
288288
VmwareAdditionalVncPortRangeStart("Advanced", ManagementServer.class, Integer.class, "vmware.additional.vnc.portrange.start", "50000", "Start port number of additional VNC port range", null),

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,11 @@ public void close() {
624624
} catch(Exception e) {
625625
s_logger.warn("Unexpected exception: ", e);
626626
}
627+
628+
if(_pool != null) {
629+
_pool.unregisterOutstandingContext(this);
630+
}
631+
627632
unregisterOutstandingContext();
628633
}
629634

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

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public class VmwareContextPool {
3131
private static final long DEFAULT_CHECK_INTERVAL = 10000;
3232
private static final int DEFAULT_IDLE_QUEUE_LENGTH = 128;
3333

34+
private List<VmwareContext> _outstandingRegistry = new ArrayList<VmwareContext>();
35+
3436
private Map<String, List<VmwareContext>> _pool;
3537
private int _maxIdleQueueLength = DEFAULT_IDLE_QUEUE_LENGTH;
3638
private long _idleCheckIntervalMs = DEFAULT_CHECK_INTERVAL;
@@ -54,9 +56,23 @@ public VmwareContextPool(int maxIdleQueueLength, long idleCheckIntervalMs) {
5456
_timer.scheduleAtFixedRate(getTimerTask(), _idleCheckIntervalMs, _idleCheckIntervalMs);
5557
}
5658

59+
public void registerOutstandingContext(VmwareContext context) {
60+
assert(context != null);
61+
synchronized(this) {
62+
_outstandingRegistry.add(context);
63+
}
64+
}
65+
66+
public void unregisterOutstandingContext(VmwareContext context) {
67+
assert(context != null);
68+
synchronized(this) {
69+
_outstandingRegistry.remove(context);
70+
}
71+
}
72+
5773
public VmwareContext getContext(String vCenterAddress, String vCenterUserName) {
5874
String poolKey = composePoolKey(vCenterAddress, vCenterUserName);
59-
synchronized(_pool) {
75+
synchronized(this) {
6076
List<VmwareContext> l = _pool.get(poolKey);
6177
if(l == null)
6278
return null;
@@ -78,7 +94,7 @@ public VmwareContext getContext(String vCenterAddress, String vCenterUserName) {
7894
public void returnContext(VmwareContext context) {
7995
assert(context.getPool() == this);
8096
assert(context.getPoolKey() != null);
81-
synchronized(_pool) {
97+
synchronized(this) {
8298
List<VmwareContext> l = _pool.get(context.getPoolKey());
8399
if(l == null) {
84100
l = new ArrayList<VmwareContext>();
@@ -100,8 +116,23 @@ public void returnContext(VmwareContext context) {
100116
}
101117
}
102118

119+
private TimerTask getTimerTask() {
120+
return new TimerTask() {
121+
@Override
122+
public void run() {
123+
try {
124+
// doIdleCheck();
125+
126+
doKeepAlive();
127+
} catch (Throwable e) {
128+
s_logger.error("Unexpected exception", e);
129+
}
130+
}
131+
};
132+
}
133+
103134
private void getIdleCheckContexts(List<VmwareContext> l, int batchSize) {
104-
synchronized(_pool) {
135+
synchronized(this) {
105136
for(Map.Entry<String, List<VmwareContext>> entry : _pool.entrySet()) {
106137
if(entry.getValue() != null) {
107138
int count = 0;
@@ -116,19 +147,6 @@ private void getIdleCheckContexts(List<VmwareContext> l, int batchSize) {
116147
}
117148
}
118149

119-
private TimerTask getTimerTask() {
120-
return new TimerTask() {
121-
@Override
122-
public void run() {
123-
try {
124-
doIdleCheck();
125-
} catch (Throwable e) {
126-
s_logger.error("Unexpected exception", e);
127-
}
128-
}
129-
};
130-
}
131-
132150
private void doIdleCheck() {
133151
List<VmwareContext> l = new ArrayList<VmwareContext>();
134152
int batchSize = (int)(_idleCheckIntervalMs / 1000); // calculate batch size at 1 request/sec rate
@@ -148,6 +166,34 @@ private void doIdleCheck() {
148166
}
149167
}
150168

169+
private void getKeepAliveCheckContexts(List<VmwareContext> l, int batchSize) {
170+
synchronized(this) {
171+
int size = Math.min(_outstandingRegistry.size(), batchSize);
172+
while(size > 0) {
173+
VmwareContext context = _outstandingRegistry.remove(0);
174+
l.add(context);
175+
176+
_outstandingRegistry.add(context);
177+
size--;
178+
}
179+
}
180+
}
181+
182+
private void doKeepAlive() {
183+
List<VmwareContext> l = new ArrayList<VmwareContext>();
184+
int batchSize = (int)(_idleCheckIntervalMs / 1000); // calculate batch size at 1 request/sec rate
185+
getKeepAliveCheckContexts(l, batchSize);
186+
187+
for(VmwareContext context : l) {
188+
try {
189+
context.idleCheck();
190+
} catch(Throwable e) {
191+
s_logger.warn("Exception caught during VmwareContext idle check, close and discard the context", e);
192+
context.close();
193+
}
194+
}
195+
}
196+
151197
public static String composePoolKey(String vCenterAddress, String vCenterUserName) {
152198
assert(vCenterUserName != null);
153199
assert(vCenterAddress != null);

0 commit comments

Comments
 (0)