Skip to content

Commit 950672e

Browse files
committed
CLOUDSTACK-4288: Fix the way that VmwareClient is using vSphere 5.1 SDK which caused huge memory footprint
1 parent 6abc3da commit 950672e

7 files changed

Lines changed: 306 additions & 282 deletions

File tree

‎engine/api/src/org/apache/cloudstack/storage/command/CopyCommand.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public CopyCommand(DataTO srcData, DataTO destData, int timeout, boolean execute
3737
this.destTO = destData;
3838
this.setWait(timeout);
3939
this.executeInSequence = executeInSequence; // default is to run in parallel, so false here
40+
/*
4041
// special handling for vmware parallel vm deployment bug https://issues.apache.org/jira/browse/CLOUDSTACK-3568
4142
if (srcTO instanceof TemplateObjectTO && destTO instanceof VolumeObjectTO) {
4243
// create a volume wrapper vm from a template on primary storage
@@ -47,7 +48,7 @@ public CopyCommand(DataTO srcData, DataTO destData, int timeout, boolean execute
4748
this.executeInSequence = true;
4849
}
4950
}
50-
51+
*/
5152
}
5253

5354
public DataTO getDestTO() {

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

Lines changed: 258 additions & 245 deletions
Large diffs are not rendered by default.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class VmwareSecondaryStorageResourceHandler implements SecondaryStorageRe
5959
private final Gson _gson;
6060
private final StorageSubsystemCommandHandler storageSubsystemHandler;
6161

62-
private ThreadLocal<VmwareContext> currentContext = new ThreadLocal<VmwareContext>();
62+
private static ThreadLocal<VmwareContext> currentContext = new ThreadLocal<VmwareContext>();
6363

6464
/*
6565
* private Map<String, HostMO> _activeHosts = new HashMap<String, HostMO>();

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ public void checkClientTrusted(java.security.cert.X509Certificate[] certs, Strin
7979
return;
8080
}
8181
}
82+
83+
static {
84+
try {
85+
trustAllHttpsCertificates();
86+
HostnameVerifier hv = new HostnameVerifier() {
87+
@Override
88+
public boolean verify(String urlHostName, SSLSession session) {
89+
return true;
90+
}
91+
};
92+
HttpsURLConnection.setDefaultHostnameVerifier(hv);
93+
94+
vimService = new VimService();
95+
} catch (Exception e) {
96+
}
97+
}
8298

8399
private static void trustAllHttpsCertificates() throws Exception {
84100
// Create a trust manager that does not validate certificate chains:
@@ -95,7 +111,7 @@ private static void trustAllHttpsCertificates() throws Exception {
95111
private ManagedObjectReference SVC_INST_REF = new ManagedObjectReference();
96112
private ManagedObjectReference propCollectorRef;
97113
private ManagedObjectReference rootRef;
98-
private VimService vimService;
114+
private static VimService vimService;
99115
private VimPortType vimPort;
100116
private ServiceContent serviceContent;
101117
private String serviceCookie;
@@ -104,7 +120,6 @@ private static void trustAllHttpsCertificates() throws Exception {
104120
private boolean isConnected = false;
105121

106122
public VmwareClient(String name) {
107-
108123
}
109124

110125
/**
@@ -114,20 +129,9 @@ public VmwareClient(String name) {
114129
* the exception
115130
*/
116131
public void connect(String url, String userName, String password) throws Exception {
117-
118-
HostnameVerifier hv = new HostnameVerifier() {
119-
@Override
120-
public boolean verify(String urlHostName, SSLSession session) {
121-
return true;
122-
}
123-
};
124-
trustAllHttpsCertificates();
125-
HttpsURLConnection.setDefaultHostnameVerifier(hv);
126-
127132
SVC_INST_REF.setType(SVC_INST_NAME);
128133
SVC_INST_REF.setValue(SVC_INST_NAME);
129134

130-
vimService = new VimService();
131135
vimPort = vimService.getVimPort();
132136
Map<String, Object> ctxt = ((BindingProvider) vimPort).getRequestContext();
133137

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ public class VmwareContext {
7979
javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext.getInstance("SSL");
8080
sc.init(null, trustAllCerts, null);
8181
javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
82+
83+
HostnameVerifier hv = new HostnameVerifier() {
84+
@Override
85+
public boolean verify(String urlHostName, SSLSession session) {
86+
return true;
87+
}
88+
};
89+
HttpsURLConnection.setDefaultHostnameVerifier(hv);
8290
} catch (Exception e) {
8391
s_logger.error("Unexpected exception ", e);
8492
}
@@ -91,6 +99,8 @@ public VmwareContext(VmwareClient client, String address) {
9199
_serverAddress = address;
92100

93101
registerOutstandingContext();
102+
if(s_logger.isInfoEnabled())
103+
s_logger.info("New VmwareContext object, current outstanding count: " + getOutstandingContextCount());
94104
}
95105

96106
public void registerStockObject(String name, Object obj) {
@@ -569,14 +579,6 @@ public HttpURLConnection getHTTPConnection(String urlString, String httpMethod)
569579
s_logger.error("No cookie is found in vmware web service request context!");
570580
throw new Exception("No cookie is found in vmware web service request context!");
571581
}
572-
HostnameVerifier hv = new HostnameVerifier() {
573-
@Override
574-
public boolean verify(String urlHostName, SSLSession session) {
575-
return true;
576-
}
577-
};
578-
579-
HttpsURLConnection.setDefaultHostnameVerifier(hv);
580582
URL url = new URL(urlString);
581583
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
582584

@@ -590,14 +592,6 @@ public boolean verify(String urlHostName, SSLSession session) {
590592
}
591593

592594
public HttpURLConnection getRawHTTPConnection(String urlString) throws Exception {
593-
HostnameVerifier hv = new HostnameVerifier() {
594-
@Override
595-
public boolean verify(String urlHostName, SSLSession session) {
596-
return true;
597-
}
598-
};
599-
600-
HttpsURLConnection.setDefaultHostnameVerifier(hv);
601595
URL url = new URL(urlString);
602596
return (HttpURLConnection)url.openConnection();
603597
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,14 @@ public VmwareContext getContext(String vCenterAddress, String vCenterUserName) {
6262
return null;
6363

6464
if(l.size() > 0) {
65-
if(s_logger.isTraceEnabled())
66-
s_logger.trace("Return a VmwareContext from the idle pool: " + poolKey + ". current pool size: " + l.size() + ", outstanding count: " + VmwareContext.getOutstandingContextCount());
67-
6865
VmwareContext context = l.remove(0);
6966
context.setPoolInfo(this, poolKey);
67+
68+
if(s_logger.isTraceEnabled())
69+
s_logger.trace("Return a VmwareContext from the idle pool: " + poolKey + ". current pool size: " + l.size() + ", outstanding count: " + VmwareContext.getOutstandingContextCount());
7070
return context;
7171
}
7272

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-
7673
// TODO, we need to control the maximum number of outstanding VmwareContext object in the future
7774
return null;
7875
}

‎vmware-base/test/com/cloud/hypervisor/vmware/mo/TestVmwareContextFactory.java‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,20 @@
2121

2222
import com.cloud.hypervisor.vmware.util.VmwareClient;
2323
import com.cloud.hypervisor.vmware.util.VmwareContext;
24+
import com.cloud.hypervisor.vmware.util.VmwareContextPool;
2425
import com.cloud.utils.StringUtils;
2526

2627
public class TestVmwareContextFactory {
2728

2829
private static final Logger s_logger = Logger.getLogger(TestVmwareContextFactory.class);
2930

3031
private static volatile int s_seq = 1;
32+
private static VmwareContextPool s_pool;
3133

3234
static {
3335
// skip certificate check
3436
System.setProperty("axis.socketSecureFactory", "org.apache.axis.components.net.SunFakeTrustSocketFactory");
37+
s_pool = new VmwareContextPool();
3538
}
3639

3740
public static VmwareContext create(String vCenterAddress, String vCenterUserName, String vCenterPassword) throws Exception {
@@ -50,4 +53,16 @@ public static VmwareContext create(String vCenterAddress, String vCenterUserName
5053
VmwareContext context = new VmwareContext(vimClient, vCenterAddress);
5154
return context;
5255
}
56+
57+
public static VmwareContext getContext(String vCenterAddress, String vCenterUserName, String vCenterPassword) throws Exception {
58+
VmwareContext context = s_pool.getContext(vCenterAddress, vCenterUserName);
59+
if(context == null)
60+
context = create(vCenterAddress, vCenterUserName, vCenterPassword);
61+
62+
if(context != null) {
63+
context.setPoolInfo(s_pool, VmwareContextPool.composePoolKey(vCenterAddress, vCenterUserName));
64+
}
65+
66+
return context;
67+
}
5368
}

0 commit comments

Comments
 (0)