You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ah...@apache.org on 2013/07/26 05:11:05 UTC
[2/8] Moved ClusterManager into it's own package. Removed the agent
load balancing code.
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9aaa378b/server/src/com/cloud/cluster/ClusterServiceServletAdapter.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/cluster/ClusterServiceServletAdapter.java b/server/src/com/cloud/cluster/ClusterServiceServletAdapter.java
deleted file mode 100644
index 04026d30..0000000
--- a/server/src/com/cloud/cluster/ClusterServiceServletAdapter.java
+++ /dev/null
@@ -1,148 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.cluster;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.rmi.RemoteException;
-import java.util.Map;
-import java.util.Properties;
-
-import javax.ejb.Local;
-import javax.inject.Inject;
-import javax.naming.ConfigurationException;
-
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
-import com.cloud.cluster.dao.ManagementServerHostDao;
-import com.cloud.configuration.Config;
-import com.cloud.configuration.dao.ConfigurationDao;
-import com.cloud.utils.NumbersUtil;
-import com.cloud.utils.PropertiesUtil;
-import com.cloud.utils.component.AdapterBase;
-
-@Component
-@Local(value={ClusterServiceAdapter.class})
-public class ClusterServiceServletAdapter extends AdapterBase implements ClusterServiceAdapter {
-
- private static final Logger s_logger = Logger.getLogger(ClusterServiceServletAdapter.class);
- private static final int DEFAULT_SERVICE_PORT = 9090;
- private static final int DEFAULT_REQUEST_TIMEOUT = 300; // 300 seconds
-
- @Inject private ClusterManager _manager;
-
- @Inject private ManagementServerHostDao _mshostDao;
-
- @Inject private ConfigurationDao _configDao;
-
- private ClusterServiceServletContainer _servletContainer;
-
- private int _clusterServicePort = DEFAULT_SERVICE_PORT;
-
- private int _clusterRequestTimeoutSeconds = DEFAULT_REQUEST_TIMEOUT;
-
- @Override
- public ClusterService getPeerService(String strPeer) throws RemoteException {
- try {
- init();
- } catch (ConfigurationException e) {
- s_logger.error("Unable to init ClusterServiceServletAdapter");
- throw new RemoteException("Unable to init ClusterServiceServletAdapter");
- }
-
- String serviceUrl = getServiceEndpointName(strPeer);
- if(serviceUrl == null)
- return null;
-
- return new ClusterServiceServletImpl(serviceUrl, _clusterRequestTimeoutSeconds);
- }
-
- @Override
- public String getServiceEndpointName(String strPeer) {
- try {
- init();
- } catch (ConfigurationException e) {
- s_logger.error("Unable to init ClusterServiceServletAdapter");
- return null;
- }
-
- long msid = Long.parseLong(strPeer);
-
- ManagementServerHostVO mshost = _mshostDao.findByMsid(msid);
- if(mshost == null)
- return null;
-
- return composeEndpointName(mshost.getServiceIP(), mshost.getServicePort());
- }
-
- @Override
- public int getServicePort() {
- return _clusterServicePort;
- }
-
- private String composeEndpointName(String nodeIP, int port) {
- StringBuffer sb = new StringBuffer();
- sb.append("http://").append(nodeIP).append(":").append(port).append("/clusterservice");
- return sb.toString();
- }
-
- @Override
- public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
- init();
- return true;
- }
-
- @Override
- public boolean start() {
- _servletContainer = new ClusterServiceServletContainer();
- _servletContainer.start(new ClusterServiceServletHttpHandler(_manager), _clusterServicePort);
- return true;
- }
-
- @Override
- public boolean stop() {
- if(_servletContainer != null)
- _servletContainer.stop();
- return true;
- }
-
- private void init() throws ConfigurationException {
- if(_mshostDao != null)
- return;
-
- String value = _configDao.getValue(Config.ClusterMessageTimeOutSeconds.key());
- _clusterRequestTimeoutSeconds = NumbersUtil.parseInt(value, DEFAULT_REQUEST_TIMEOUT);
- s_logger.info("Configure cluster request time out. timeout: " + _clusterRequestTimeoutSeconds + " seconds");
-
- File dbPropsFile = PropertiesUtil.findConfigFile("db.properties");
- Properties dbProps = new Properties();
- try {
- dbProps.load(new FileInputStream(dbPropsFile));
- } catch (FileNotFoundException e) {
- throw new ConfigurationException("Unable to find db.properties");
- } catch (IOException e) {
- throw new ConfigurationException("Unable to load db.properties content");
- }
-
- _clusterServicePort = NumbersUtil.parseInt(dbProps.getProperty("cluster.servlet.port"), DEFAULT_SERVICE_PORT);
- if(s_logger.isInfoEnabled())
- s_logger.info("Cluster servlet port : " + _clusterServicePort);
- }
-}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9aaa378b/server/src/com/cloud/cluster/ClusterServiceServletContainer.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/cluster/ClusterServiceServletContainer.java b/server/src/com/cloud/cluster/ClusterServiceServletContainer.java
deleted file mode 100644
index def3e17..0000000
--- a/server/src/com/cloud/cluster/ClusterServiceServletContainer.java
+++ /dev/null
@@ -1,179 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.cluster;
-
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-import org.apache.http.ConnectionClosedException;
-import org.apache.http.HttpException;
-import org.apache.http.impl.DefaultConnectionReuseStrategy;
-import org.apache.http.impl.DefaultHttpResponseFactory;
-import org.apache.http.impl.DefaultHttpServerConnection;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.CoreConnectionPNames;
-import org.apache.http.params.CoreProtocolPNames;
-import org.apache.http.params.HttpParams;
-import org.apache.http.protocol.BasicHttpContext;
-import org.apache.http.protocol.BasicHttpProcessor;
-import org.apache.http.protocol.HttpContext;
-import org.apache.http.protocol.HttpRequestHandler;
-import org.apache.http.protocol.HttpRequestHandlerRegistry;
-import org.apache.http.protocol.HttpService;
-import org.apache.http.protocol.ResponseConnControl;
-import org.apache.http.protocol.ResponseContent;
-import org.apache.http.protocol.ResponseDate;
-import org.apache.http.protocol.ResponseServer;
-import org.apache.log4j.Logger;
-
-import com.cloud.utils.concurrency.NamedThreadFactory;
-
-public class ClusterServiceServletContainer {
- private static final Logger s_logger = Logger.getLogger(ClusterServiceServletContainer.class);
-
- private ListenerThread listenerThread;
-
- public ClusterServiceServletContainer() {
- }
-
- public boolean start(HttpRequestHandler requestHandler, int port) {
-
- listenerThread = new ListenerThread(requestHandler, port);
- listenerThread.start();
-
- return true;
- }
-
- public void stop() {
- if(listenerThread != null) {
- listenerThread.stopRunning();
- }
- }
-
- static class ListenerThread extends Thread {
- private HttpService _httpService = null;
- private volatile ServerSocket _serverSocket = null;
- private HttpParams _params = null;
- private ExecutorService _executor;
-
- public ListenerThread(HttpRequestHandler requestHandler, int port) {
- _executor = Executors.newCachedThreadPool(new NamedThreadFactory("Cluster-Listener"));
-
- try {
- _serverSocket = new ServerSocket(port);
- } catch (IOException ioex) {
- s_logger.error("error initializing cluster service servlet container", ioex);
- return;
- }
-
- _params = new BasicHttpParams();
- _params
- .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
- .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
- .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
- .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
- .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");
-
- // Set up the HTTP protocol processor
- BasicHttpProcessor httpproc = new BasicHttpProcessor();
- httpproc.addInterceptor(new ResponseDate());
- httpproc.addInterceptor(new ResponseServer());
- httpproc.addInterceptor(new ResponseContent());
- httpproc.addInterceptor(new ResponseConnControl());
-
- // Set up request handlers
- HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
- reqistry.register("/clusterservice", requestHandler);
-
- // Set up the HTTP service
- _httpService = new HttpService(httpproc, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory());
- _httpService.setParams(_params);
- _httpService.setHandlerResolver(reqistry);
- }
-
- public void stopRunning() {
- if(_serverSocket != null) {
- try {
- _serverSocket.close();
- } catch (IOException e) {
- }
- _serverSocket = null;
- }
- }
-
- public void run() {
- if(s_logger.isInfoEnabled())
- s_logger.info("Cluster service servlet container listening on port " + _serverSocket.getLocalPort());
-
- while (_serverSocket != null) {
- try {
- // Set up HTTP connection
- Socket socket = _serverSocket.accept();
- final DefaultHttpServerConnection conn = new DefaultHttpServerConnection();
- conn.bind(socket, _params);
-
- _executor.execute(new Runnable() {
- public void run() {
- HttpContext context = new BasicHttpContext(null);
- try {
- while(!Thread.interrupted() && conn.isOpen()) {
- if(s_logger.isTraceEnabled())
- s_logger.trace("dispatching cluster request from " + conn.getRemoteAddress().toString());
-
- _httpService.handleRequest(conn, context);
-
- if(s_logger.isTraceEnabled())
- s_logger.trace("Cluster request from " + conn.getRemoteAddress().toString() + " is processed");
- }
- } catch (ConnectionClosedException ex) {
- // client close and read time out exceptions are expected
- // when KEEP-AVLIE is enabled
- s_logger.trace("Client closed connection", ex);
- } catch (IOException ex) {
- s_logger.trace("I/O error", ex);
- } catch (HttpException ex) {
- s_logger.error("Unrecoverable HTTP protocol violation", ex);
- } finally {
- try {
- conn.shutdown();
- } catch (IOException ignore) {
- s_logger.error("unexpected exception", ignore);
- }
- }
- }
- });
-
- } catch (Throwable e) {
- s_logger.error("Unexpected exception ", e);
-
- // back off to avoid spinning if the exception condition keeps coming back
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e1) {
- }
- }
- }
-
- _executor.shutdown();
- if(s_logger.isInfoEnabled())
- s_logger.info("Cluster service servlet container shutdown");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9aaa378b/server/src/com/cloud/cluster/ClusterServiceServletHttpHandler.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/cluster/ClusterServiceServletHttpHandler.java b/server/src/com/cloud/cluster/ClusterServiceServletHttpHandler.java
deleted file mode 100755
index 2d77ce0..0000000
--- a/server/src/com/cloud/cluster/ClusterServiceServletHttpHandler.java
+++ /dev/null
@@ -1,192 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.cluster;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.net.URLDecoder;
-
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.http.HttpEntityEnclosingRequest;
-import org.apache.http.HttpException;
-import org.apache.http.HttpRequest;
-import org.apache.http.HttpResponse;
-import org.apache.http.entity.BasicHttpEntity;
-import org.apache.http.protocol.HttpContext;
-import org.apache.http.protocol.HttpRequestHandler;
-import org.apache.http.util.EntityUtils;
-import org.apache.log4j.Logger;
-
-public class ClusterServiceServletHttpHandler implements HttpRequestHandler {
- private static final Logger s_logger = Logger.getLogger(ClusterServiceServletHttpHandler.class);
-
- private final ClusterManager manager;
-
- public ClusterServiceServletHttpHandler(ClusterManager manager) {
- this.manager = manager;
- }
-
- @Override
- public void handle(HttpRequest request, HttpResponse response, HttpContext context)
- throws HttpException, IOException {
-
- try {
- if(s_logger.isTraceEnabled()) {
- s_logger.trace("Start Handling cluster HTTP request");
- }
-
- parseRequest(request);
- handleRequest(request, response);
-
- if(s_logger.isTraceEnabled()) {
- s_logger.trace("Handle cluster HTTP request done");
- }
-
- } catch(Throwable e) {
- 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());
- }
- }
- }
- }
-
- @SuppressWarnings("deprecation")
- private void parseRequest(HttpRequest request) throws IOException {
- if(request instanceof HttpEntityEnclosingRequest) {
- HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest)request;
-
- String body = EntityUtils.toString(entityRequest.getEntity());
- if(body != null) {
- String[] paramArray = body.split("&");
- if(paramArray != null) {
- for (String paramEntry : paramArray) {
- String[] paramValue = paramEntry.split("=");
- if (paramValue.length != 2) {
- continue;
- }
-
- String name = URLDecoder.decode(paramValue[0]);
- String value = URLDecoder.decode(paramValue[1]);
-
- if(s_logger.isTraceEnabled()) {
- s_logger.trace("Parsed request parameter " + name + "=" + value);
- }
- request.getParams().setParameter(name, value);
- }
- }
- }
- }
- }
-
- private void writeResponse(HttpResponse response, int statusCode, String content) {
- if(content == null) {
- content = "";
- }
- response.setStatusCode(statusCode);
- BasicHttpEntity body = new BasicHttpEntity();
- body.setContentType("text/html; charset=UTF-8");
-
- byte[] bodyData = content.getBytes();
- body.setContent(new ByteArrayInputStream(bodyData));
- body.setContentLength(bodyData.length);
- response.setEntity(body);
- }
-
- protected void handleRequest(HttpRequest req, HttpResponse response) {
- String method = (String)req.getParams().getParameter("method");
-
- int nMethod = RemoteMethodConstants.METHOD_UNKNOWN;
- String responseContent = null;
- try {
- if(method != null) {
- nMethod = Integer.parseInt(method);
- }
-
- switch(nMethod) {
- case RemoteMethodConstants.METHOD_DELIVER_PDU :
- responseContent = handleDeliverPduMethodCall(req);
- break;
-
- case RemoteMethodConstants.METHOD_PING :
- responseContent = handlePingMethodCall(req);
- break;
-
- case RemoteMethodConstants.METHOD_UNKNOWN :
- default :
- assert(false);
- s_logger.error("unrecognized method " + nMethod);
- break;
- }
- } catch(Throwable e) {
- s_logger.error("Unexpected exception when processing cluster service request : ", e);
- }
-
- if(responseContent != null) {
- if(s_logger.isTraceEnabled())
- s_logger.trace("Write reponse with HTTP OK " + responseContent);
-
- writeResponse(response, HttpStatus.SC_OK, responseContent);
- } else {
- if(s_logger.isTraceEnabled())
- s_logger.trace("Write reponse with HTTP Bad request");
-
- writeResponse(response, HttpStatus.SC_BAD_REQUEST, null);
- }
- }
-
- private String handleDeliverPduMethodCall(HttpRequest req) {
-
- String pduSeq = (String)req.getParams().getParameter("pduSeq");
- String pduAckSeq = (String)req.getParams().getParameter("pduAckSeq");
- String sourcePeer = (String)req.getParams().getParameter("sourcePeer");
- String destPeer = (String)req.getParams().getParameter("destPeer");
- String agentId = (String)req.getParams().getParameter("agentId");
- String gsonPackage = (String)req.getParams().getParameter("gsonPackage");
- String stopOnError = (String)req.getParams().getParameter("stopOnError");
- String pduType = (String)req.getParams().getParameter("pduType");
-
- ClusterServicePdu pdu = new ClusterServicePdu();
- pdu.setSourcePeer(sourcePeer);
- pdu.setDestPeer(destPeer);
- pdu.setAgentId(Long.parseLong(agentId));
- pdu.setSequenceId(Long.parseLong(pduSeq));
- pdu.setAckSequenceId(Long.parseLong(pduAckSeq));
- pdu.setJsonPackage(gsonPackage);
- pdu.setStopOnError("1".equals(stopOnError));
- pdu.setPduType(Integer.parseInt(pduType));
-
- manager.OnReceiveClusterServicePdu(pdu);
- return "true";
- }
-
- private String handlePingMethodCall(HttpRequest req) {
- String callingPeer = (String)req.getParams().getParameter("callingPeer");
-
- if(s_logger.isDebugEnabled()) {
- s_logger.debug("Handle ping request from " + callingPeer);
- }
-
- return "true";
- }
-}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9aaa378b/server/src/com/cloud/cluster/ClusterServiceServletImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/cluster/ClusterServiceServletImpl.java b/server/src/com/cloud/cluster/ClusterServiceServletImpl.java
deleted file mode 100644
index 3270315..0000000
--- a/server/src/com/cloud/cluster/ClusterServiceServletImpl.java
+++ /dev/null
@@ -1,146 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.cluster;
-
-import java.io.IOException;
-import java.rmi.RemoteException;
-
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.params.HttpClientParams;
-import org.apache.log4j.Logger;
-
-public class ClusterServiceServletImpl implements ClusterService {
- private static final long serialVersionUID = 4574025200012566153L;
- private static final Logger s_logger = Logger.getLogger(ClusterServiceServletImpl.class);
-
- private String _serviceUrl;
-
- private int _requestTimeoutSeconds;
- protected static HttpClient s_client = null;
-
- public ClusterServiceServletImpl() {
- }
-
- public ClusterServiceServletImpl(String serviceUrl, int requestTimeoutSeconds) {
- s_logger.info("Setup cluster service servlet. service url: " + serviceUrl + ", request timeout: " + requestTimeoutSeconds + " seconds");
-
- this._serviceUrl = serviceUrl;
- this._requestTimeoutSeconds = requestTimeoutSeconds;
- }
-
- @Override
- public String execute(ClusterServicePdu pdu) throws RemoteException {
-
- HttpClient client = getHttpClient();
- PostMethod method = new PostMethod(_serviceUrl);
-
- method.addParameter("method", Integer.toString(RemoteMethodConstants.METHOD_DELIVER_PDU));
- method.addParameter("sourcePeer", pdu.getSourcePeer());
- method.addParameter("destPeer", pdu.getDestPeer());
- method.addParameter("pduSeq", Long.toString(pdu.getSequenceId()));
- method.addParameter("pduAckSeq", Long.toString(pdu.getAckSequenceId()));
- method.addParameter("agentId", Long.toString(pdu.getAgentId()));
- method.addParameter("gsonPackage", pdu.getJsonPackage());
- method.addParameter("stopOnError", pdu.isStopOnError() ? "1" : "0");
- method.addParameter("pduType", Integer.toString(pdu.getPduType()));
-
- return executePostMethod(client, method);
- }
-
- @Override
- public boolean ping(String callingPeer) throws RemoteException {
- if(s_logger.isDebugEnabled()) {
- s_logger.debug("Ping at " + _serviceUrl);
- }
-
- HttpClient client = getHttpClient();
- PostMethod method = new PostMethod(_serviceUrl);
-
- method.addParameter("method", Integer.toString(RemoteMethodConstants.METHOD_PING));
- method.addParameter("callingPeer", callingPeer);
-
- String returnVal = executePostMethod(client, method);
- if("true".equalsIgnoreCase(returnVal)) {
- return true;
- }
- return false;
- }
-
- private String executePostMethod(HttpClient client, PostMethod method) {
- int response = 0;
- String result = null;
- try {
- long startTick = System.currentTimeMillis();
- response = client.executeMethod(method);
- if(response == HttpStatus.SC_OK) {
- result = method.getResponseBodyAsString();
- if(s_logger.isDebugEnabled()) {
- s_logger.debug("POST " + _serviceUrl + " response :" + result + ", responding time: "
- + (System.currentTimeMillis() - startTick) + " ms");
- }
- } else {
- s_logger.error("Invalid response code : " + response + ", from : "
- + _serviceUrl + ", method : " + method.getParameter("method")
- + " responding time: " + (System.currentTimeMillis() - startTick));
- }
- } catch (HttpException e) {
- s_logger.error("HttpException from : " + _serviceUrl + ", method : " + method.getParameter("method"));
- } catch (IOException e) {
- s_logger.error("IOException from : " + _serviceUrl + ", method : " + method.getParameter("method"));
- } catch(Throwable e) {
- s_logger.error("Exception from : " + _serviceUrl + ", method : " + method.getParameter("method") + ", exception :", e);
- } finally {
- method.releaseConnection();
- }
-
- return result;
- }
-
- private HttpClient getHttpClient() {
-
- if(s_client == null) {
- MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
- mgr.getParams().setDefaultMaxConnectionsPerHost(4);
-
- // TODO make it configurable
- mgr.getParams().setMaxTotalConnections(1000);
-
- s_client = new HttpClient(mgr);
- HttpClientParams clientParams = new HttpClientParams();
- clientParams.setSoTimeout(_requestTimeoutSeconds * 1000);
-
- s_client.setParams(clientParams);
- }
- return s_client;
- }
-
- // for test purpose only
- public static void main(String[] args) {
-/*
- ClusterServiceServletImpl service = new ClusterServiceServletImpl("http://localhost:9090/clusterservice", 300);
- try {
- String result = service.execute("test", 1, "{ p1:v1, p2:v2 }", true);
- System.out.println(result);
- } catch (RemoteException e) {
- }
-*/
- }
-}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9aaa378b/server/src/com/cloud/cluster/DummyClusterManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/cluster/DummyClusterManagerImpl.java b/server/src/com/cloud/cluster/DummyClusterManagerImpl.java
deleted file mode 100755
index 12972b9..0000000
--- a/server/src/com/cloud/cluster/DummyClusterManagerImpl.java
+++ /dev/null
@@ -1,179 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.cluster;
-
-import java.util.Map;
-
-import javax.ejb.Local;
-import javax.naming.ConfigurationException;
-
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
-import com.cloud.agent.api.Answer;
-import com.cloud.agent.api.Command;
-import com.cloud.exception.AgentUnavailableException;
-import com.cloud.exception.OperationTimedoutException;
-import com.cloud.host.Status.Event;
-import com.cloud.utils.component.ManagerBase;
-import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.utils.net.MacAddress;
-
-@Local(value={ClusterManager.class})
-public class DummyClusterManagerImpl extends ManagerBase implements ClusterManager {
- private static final Logger s_logger = Logger.getLogger(DummyClusterManagerImpl.class);
-
- protected long _id = MacAddress.getMacAddress().toLong();
- protected long _runId = System.currentTimeMillis();
-
- private final String _clusterNodeIP = "127.0.0.1";
-
- @Override
- public void OnReceiveClusterServicePdu(ClusterServicePdu pdu) {
- throw new CloudRuntimeException("Unsupported feature");
- }
-
- @Override
- public void executeAsync(String strPeer, long agentId, Command [] cmds, boolean stopOnError) {
- throw new CloudRuntimeException("Unsupported feature");
- }
-
- @Override
- public Answer[] execute(String strPeer, long agentId, Command [] cmds, boolean stopOnError) {
- throw new CloudRuntimeException("Unsupported feature");
- }
-
- @Override
- public Answer[] sendToAgent(Long hostId, Command [] cmds, boolean stopOnError)
- throws AgentUnavailableException, OperationTimedoutException {
- throw new CloudRuntimeException("Unsupported feature");
- }
-
-/*
- @Override
- public long sendToAgent(Long hostId, Command[] cmds, boolean stopOnError, Listener listener) throws AgentUnavailableException {
- throw new CloudRuntimeException("Unsupported feature");
- }
-*/
- @Override
- public boolean executeAgentUserRequest(long agentId, Event event) throws AgentUnavailableException {
- throw new CloudRuntimeException("Unsupported feature");
- }
-
- @Override
- public Boolean propagateAgentEvent(long agentId, Event event) throws AgentUnavailableException {
- throw new CloudRuntimeException("Unsupported feature");
- }
-
- @Override
- public int getHeartbeatThreshold() {
- return ClusterManager.DEFAULT_HEARTBEAT_INTERVAL;
- }
-
- @Override
- public long getManagementNodeId() {
- return _id;
- }
-
- @Override
- public long getCurrentRunId() {
- return _runId;
- }
-
- @Override
- public ManagementServerHostVO getPeer(String str) {
- return null;
- }
-
- @Override
- public String getSelfPeerName() {
- return Long.toString(_id);
- }
-
- @Override
- public String getSelfNodeIP() {
- return _clusterNodeIP;
- }
-
- @Override
- public boolean isManagementNodeAlive(long msid) {
- return true;
- }
-
- @Override
- public boolean pingManagementNode(long msid) {
- return false;
- }
-
- @Override
- public String getPeerName(long agentHostId) {
- throw new CloudRuntimeException("Unsupported feature");
- }
-
- @Override
- public void registerListener(ClusterManagerListener listener) {
- }
-
- @Override
- public void unregisterListener(ClusterManagerListener listener) {
- }
-
- @Override
- public boolean configure(String name, Map<String, Object> params)
- throws ConfigurationException {
- return true;
- }
-
- @Override
- public void broadcast(long hostId, Command[] cmds) {
- }
-
- @Override
- public boolean start() {
- if(s_logger.isInfoEnabled())
- s_logger.info("Starting cluster manager, msid : " + _id);
-
- return true;
- }
-
- @Override
- public boolean stop() {
- return true;
- }
-
- @Override
- public boolean rebalanceAgent(long agentId, Event event, long currentOwnerId, long futureOwnerId) throws AgentUnavailableException, OperationTimedoutException {
- return false;
- }
-
- @Override
- public boolean isAgentRebalanceEnabled() {
- return false;
- }
-
- @Override
- public Boolean propagateResourceEvent(long agentId, com.cloud.resource.ResourceState.Event event) throws AgentUnavailableException {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public boolean executeResourceUserRequest(long hostId, com.cloud.resource.ResourceState.Event event) throws AgentUnavailableException {
- // TODO Auto-generated method stub
- return false;
- }
-}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9aaa378b/server/src/com/cloud/cluster/LockMasterListener.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/cluster/LockMasterListener.java b/server/src/com/cloud/cluster/LockMasterListener.java
deleted file mode 100644
index cc10e2c..0000000
--- a/server/src/com/cloud/cluster/LockMasterListener.java
+++ /dev/null
@@ -1,49 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.cluster;
-
-import java.util.List;
-
-import com.cloud.utils.db.Merovingian2;
-
-/**
- * when a management server is down.
- *
- */
-public class LockMasterListener implements ClusterManagerListener {
- Merovingian2 _lockMaster;
-
- public LockMasterListener(long msId) {
- _lockMaster = Merovingian2.createLockMaster(msId);
- }
-
- @Override
- public void onManagementNodeJoined(List<ManagementServerHostVO> nodeList, long selfNodeId) {
- }
-
- @Override
- public void onManagementNodeLeft(List<ManagementServerHostVO> nodeList, long selfNodeId) {
- for (ManagementServerHostVO node : nodeList) {
- _lockMaster.cleanupForServer(node.getMsid());
- }
- }
-
- @Override
- public void onManagementNodeIsolated() {
- }
-
-}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9aaa378b/server/src/com/cloud/cluster/RemoteMethodConstants.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/cluster/RemoteMethodConstants.java b/server/src/com/cloud/cluster/RemoteMethodConstants.java
deleted file mode 100644
index 1174bd3..0000000
--- a/server/src/com/cloud/cluster/RemoteMethodConstants.java
+++ /dev/null
@@ -1,23 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.cluster;
-
-public interface RemoteMethodConstants {
- public static final int METHOD_UNKNOWN = 0;
- public static final int METHOD_PING = 4;
- public static final int METHOD_DELIVER_PDU = 5;
-}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9aaa378b/server/src/com/cloud/server/LockMasterListener.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/LockMasterListener.java b/server/src/com/cloud/server/LockMasterListener.java
new file mode 100644
index 0000000..ee9c9a9
--- /dev/null
+++ b/server/src/com/cloud/server/LockMasterListener.java
@@ -0,0 +1,51 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.server;
+
+import java.util.List;
+
+import com.cloud.cluster.ClusterManagerListener;
+import com.cloud.cluster.ManagementServerHostVO;
+import com.cloud.utils.db.Merovingian2;
+
+/**
+ * when a management server is down.
+ *
+ */
+public class LockMasterListener implements ClusterManagerListener {
+ Merovingian2 _lockMaster;
+
+ public LockMasterListener(long msId) {
+ _lockMaster = Merovingian2.createLockMaster(msId);
+ }
+
+ @Override
+ public void onManagementNodeJoined(List<ManagementServerHostVO> nodeList, long selfNodeId) {
+ }
+
+ @Override
+ public void onManagementNodeLeft(List<ManagementServerHostVO> nodeList, long selfNodeId) {
+ for (ManagementServerHostVO node : nodeList) {
+ _lockMaster.cleanupForServer(node.getMsid());
+ }
+ }
+
+ @Override
+ public void onManagementNodeIsolated() {
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9aaa378b/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java
index 77c77e1..d96536e 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -427,6 +427,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
+import org.apache.cloudstack.utils.identity.ManagementServerNode;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.GetVncPortAnswer;
@@ -825,6 +826,8 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
public boolean start() {
s_logger.info("Startup CloudStack management server...");
+ _clusterMgr.registerListener(new LockMasterListener(ManagementServerNode.getManagementServerId()));
+
enableAdminUser("password");
return true;
}