mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
bug 10677: add client side time out to cluster servlet interface
This commit is contained in:
parent
a2de0f60d5
commit
b9f00ccbab
@ -73,11 +73,17 @@ public class ClusterServiceServletHttpHandler implements HttpRequestHandler {
|
||||
}
|
||||
|
||||
} catch(Throwable e) {
|
||||
if(s_logger.isTraceEnabled()) {
|
||||
s_logger.trace("Unexpected exception " + e.toString());
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Exception " + e.toString());
|
||||
}
|
||||
|
||||
try {
|
||||
writeResponse(response, HttpStatus.SC_INTERNAL_SERVER_ERROR, null);
|
||||
} catch(Throwable e2) {
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Exception " + e2.toString());
|
||||
}
|
||||
}
|
||||
|
||||
writeResponse(response, HttpStatus.SC_INTERNAL_SERVER_ERROR, null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -160,9 +166,15 @@ public class ClusterServiceServletHttpHandler implements HttpRequestHandler {
|
||||
s_logger.error("Unexpected exception when processing cluster service request : ", e);
|
||||
}
|
||||
|
||||
if(responseContent != null) {
|
||||
if(responseContent != null) {
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("Write reponse with HTTP OK " + responseContent);
|
||||
|
||||
writeResponse(response, HttpStatus.SC_OK, responseContent);
|
||||
} else {
|
||||
} else {
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("Write reponse with HTTP Bad request");
|
||||
|
||||
writeResponse(response, HttpStatus.SC_BAD_REQUEST, null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,16 +25,17 @@ import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.httpclient.HttpException;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.commons.httpclient.methods.PostMethod;
|
||||
import org.apache.commons.httpclient.params.HttpClientParams;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.serializer.GsonHelper;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class ClusterServiceServletImpl implements ClusterService {
|
||||
private static final long serialVersionUID = 4574025200012566153L;
|
||||
|
||||
private static final long serialVersionUID = 4574025200012566153L;
|
||||
private static final Logger s_logger = Logger.getLogger(ClusterServiceServletImpl.class);
|
||||
|
||||
private static int HTTP_DATA_TIMEOUT = 60000;
|
||||
|
||||
private String serviceUrl;
|
||||
|
||||
private final Gson gson;
|
||||
@ -55,7 +56,7 @@ public class ClusterServiceServletImpl implements ClusterService {
|
||||
s_logger.debug("Post (sync-call) " + gsonPackage + " to " + serviceUrl + " for agent " + agentId + " from " + callingPeer);
|
||||
}
|
||||
|
||||
HttpClient client = new HttpClient();
|
||||
HttpClient client = getHttpClient();
|
||||
PostMethod method = new PostMethod(serviceUrl);
|
||||
|
||||
method.addParameter("method", Integer.toString(RemoteMethodConstants.METHOD_EXECUTE));
|
||||
@ -64,8 +65,8 @@ public class ClusterServiceServletImpl implements ClusterService {
|
||||
method.addParameter("stopOnError", stopOnError ? "1" : "0");
|
||||
|
||||
return executePostMethod(client, method);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public long executeAsync(String callingPeer, long agentId, String gsonPackage, boolean stopOnError) throws RemoteException {
|
||||
|
||||
@ -73,7 +74,7 @@ public class ClusterServiceServletImpl implements ClusterService {
|
||||
s_logger.debug("Post (Async-call) " + gsonPackage + " to " + serviceUrl + " for agent " + agentId + " from " + callingPeer);
|
||||
}
|
||||
|
||||
HttpClient client = new HttpClient();
|
||||
HttpClient client = getHttpClient();
|
||||
PostMethod method = new PostMethod(serviceUrl);
|
||||
|
||||
method.addParameter("method", Integer.toString(RemoteMethodConstants.METHOD_EXECUTE_ASYNC));
|
||||
@ -103,7 +104,7 @@ public class ClusterServiceServletImpl implements ClusterService {
|
||||
+ ", excutingPeer: " + executingPeer
|
||||
+ ", seq: " + seq + ", gsonPackage: " + gsonPackage);
|
||||
}
|
||||
HttpClient client = new HttpClient();
|
||||
HttpClient client = getHttpClient();
|
||||
PostMethod method = new PostMethod(serviceUrl);
|
||||
|
||||
method.addParameter("method", Integer.toString(RemoteMethodConstants.METHOD_ASYNC_RESULT));
|
||||
@ -132,7 +133,7 @@ public class ClusterServiceServletImpl implements ClusterService {
|
||||
s_logger.debug("Ping at " + serviceUrl);
|
||||
}
|
||||
|
||||
HttpClient client = new HttpClient();
|
||||
HttpClient client = getHttpClient();
|
||||
PostMethod method = new PostMethod(serviceUrl);
|
||||
|
||||
method.addParameter("method", Integer.toString(RemoteMethodConstants.METHOD_PING));
|
||||
@ -170,7 +171,16 @@ public class ClusterServiceServletImpl implements ClusterService {
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private HttpClient getHttpClient() {
|
||||
HttpClient client = new HttpClient();
|
||||
HttpClientParams clientParams = new HttpClientParams();
|
||||
clientParams.setSoTimeout(HTTP_DATA_TIMEOUT);
|
||||
client.setParams(clientParams);
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
// for test purpose only
|
||||
public static void main(String[] args) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user