mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
bug 13225: setup firewall rules for all ESX/ESXi hosts under a cluster as worker VM may be created at any host available, also add connect retry when work with vCenter and ESX/ESXi hosts
This commit is contained in:
parent
03653b936e
commit
1056afbbcf
@ -4,6 +4,8 @@
|
||||
|
||||
package com.cloud.storage.resource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
@ -26,6 +28,7 @@ import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostNetworkSummary;
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.cloud.hypervisor.vmware.util.VmwareHelper;
|
||||
import com.cloud.serializer.GsonHelper;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.google.gson.Gson;
|
||||
import com.vmware.vim25.ManagedObjectReference;
|
||||
|
||||
@ -210,9 +213,19 @@ public class VmwareSecondaryStorageResourceHandler implements SecondaryStorageRe
|
||||
HostMO hostMo = new HostMO(context, morHyperHost);
|
||||
|
||||
try {
|
||||
VmwareHypervisorHostNetworkSummary netSummary = hostMo.getHyperHostNetworkSummary(
|
||||
hostMo.getHostType() == VmwareHostType.ESXi ? cmd.getContextParam("manageportgroup") : cmd.getContextParam("serviceconsole"));
|
||||
_resource.ensureOutgoingRuleForAddress(netSummary.getHostIp());
|
||||
|
||||
ManagedObjectReference mor = hostMo.getHyperHostCluster();
|
||||
ClusterMO clusterMo = new ClusterMO(hostMo.getContext(), mor);
|
||||
List<Pair<ManagedObjectReference, String>> hostsInCluster = clusterMo.getClusterHosts();
|
||||
for(Pair<ManagedObjectReference, String> hostPair : hostsInCluster) {
|
||||
HostMO hostIteratorMo = new HostMO(hostMo.getContext(), hostPair.first());
|
||||
|
||||
VmwareHypervisorHostNetworkSummary netSummary = hostIteratorMo.getHyperHostNetworkSummary(
|
||||
hostIteratorMo.getHostType() == VmwareHostType.ESXi ? cmd.getContextParam("manageportgroup") : cmd.getContextParam("serviceconsole"));
|
||||
_resource.ensureOutgoingRuleForAddress(netSummary.getHostIp());
|
||||
|
||||
s_logger.info("Setup firewall rule for host: " + netSummary.getHostIp());
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
s_logger.warn("Unable to retrive host network information due to exception " + e.toString() + ", host: " + hostTokens[0] + "-" + hostTokens[1]);
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.ConnectException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
@ -47,12 +48,16 @@ import com.vmware.vim25.VimPortType;
|
||||
|
||||
public class VmwareContext {
|
||||
private static final Logger s_logger = Logger.getLogger(VmwareContext.class);
|
||||
|
||||
|
||||
private static int MAX_CONNECT_RETRY = 5;
|
||||
private static int CONNECT_RETRY_INTERVAL = 1000;
|
||||
|
||||
private ExtendedAppUtil _appUtil;
|
||||
private String _serverAddress;
|
||||
|
||||
private Map<String, Object> _stockMap = new HashMap<String, Object>();
|
||||
private int _CHUNKSIZE = 1*1024*1024; // 1M
|
||||
private int _CHUNKSIZE = 1*1024*1024; // 1M
|
||||
|
||||
|
||||
static {
|
||||
try {
|
||||
@ -328,7 +333,7 @@ public class VmwareContext {
|
||||
conn.setRequestProperty("Connection", "Keep-Alive");
|
||||
conn.setRequestProperty("Content-Type", "application/x-vnd.vmware-streamVmdk");
|
||||
conn.setRequestProperty("Content-Length", Long.toString(new File(localFileName).length()));
|
||||
conn.connect();
|
||||
connectWithRetry(conn);
|
||||
|
||||
BufferedOutputStream bos = null;
|
||||
BufferedInputStream is = null;
|
||||
@ -367,8 +372,8 @@ public class VmwareContext {
|
||||
conn.setRequestProperty(org.apache.axis.transport.http.HTTPConstants.HEADER_COOKIE, cookieString);
|
||||
conn.setDoInput(true);
|
||||
conn.setDoOutput(true);
|
||||
conn.setAllowUserInteraction(true);
|
||||
conn.connect();
|
||||
conn.setAllowUserInteraction(true);
|
||||
connectWithRetry(conn);
|
||||
|
||||
long bytesWritten = 0;
|
||||
InputStream in = null;
|
||||
@ -387,8 +392,6 @@ public class VmwareContext {
|
||||
if(progressUpdater != null)
|
||||
progressUpdater.action(new Long(totalBytesDownloaded));
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
s_logger.error("Unexpected exception ", e);
|
||||
} finally {
|
||||
if(in != null)
|
||||
in.close();
|
||||
@ -533,7 +536,7 @@ public class VmwareContext {
|
||||
conn.setAllowUserInteraction(true);
|
||||
conn.setRequestProperty(org.apache.axis.transport.http.HTTPConstants.HEADER_COOKIE, cookieString);
|
||||
conn.setRequestMethod(httpMethod);
|
||||
conn.connect();
|
||||
connectWithRetry(conn);
|
||||
return conn;
|
||||
}
|
||||
|
||||
@ -556,6 +559,27 @@ public class VmwareContext {
|
||||
org.apache.axis.MessageContext msgContext = callObj.getMessageContext();
|
||||
String cookieString = (String)msgContext.getProperty(org.apache.axis.transport.http.HTTPConstants.HEADER_COOKIE);
|
||||
return cookieString;
|
||||
}
|
||||
|
||||
private static void connectWithRetry(HttpURLConnection conn) throws Exception {
|
||||
boolean connected = false;
|
||||
for(int i = 0; i < MAX_CONNECT_RETRY && !connected; i++) {
|
||||
try {
|
||||
conn.connect();
|
||||
connected = true;
|
||||
s_logger.info("Connected, conn: " + conn.toString() + ", retry: " + i);
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Unable to connect, conn: " + conn.toString() + ", message: " + e.toString() + ", retry: " + i);
|
||||
|
||||
try {
|
||||
Thread.sleep(CONNECT_RETRY_INTERVAL);
|
||||
} catch(InterruptedException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!connected)
|
||||
throw new Exception("Unable to connect to " + conn.toString());
|
||||
}
|
||||
|
||||
public void close() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user