diff --git a/server/src/com/cloud/cluster/ClusterServiceServletAdapter.java b/server/src/com/cloud/cluster/ClusterServiceServletAdapter.java index 7b14c177986..813cc123a80 100644 --- a/server/src/com/cloud/cluster/ClusterServiceServletAdapter.java +++ b/server/src/com/cloud/cluster/ClusterServiceServletAdapter.java @@ -51,7 +51,14 @@ public class ClusterServiceServletAdapter implements ClusterServiceAdapter { private int _clusterServicePort = DEFAULT_SERVICE_PORT; @Override - public ClusterService getPeerService(String strPeer) throws RemoteException { + 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; @@ -61,6 +68,12 @@ public class ClusterServiceServletAdapter implements ClusterServiceAdapter { @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); @@ -86,33 +99,10 @@ public class ClusterServiceServletAdapter implements ClusterServiceAdapter { public boolean configure(String name, Map params) throws ConfigurationException { _name = name; - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - - manager = locator.getManager(ClusterManager.class); - if(manager == null) - throw new ConfigurationException("Unable to get " + ClusterManager.class.getName()); - - _mshostDao = locator.getDao(ManagementServerHostDao.class); - if(_mshostDao == null) - throw new ConfigurationException("Unable to get " + ManagementServerHostDao.class.getName()); - - 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); - + init(); return true; - } - + } + @Override public String getName() { return _name; @@ -130,5 +120,34 @@ public class ClusterServiceServletAdapter implements ClusterServiceAdapter { if(_servletContainer != null) _servletContainer.stop(); return true; - } + } + + private void init() throws ConfigurationException { + if(_mshostDao != null) + return; + + ComponentLocator locator = ComponentLocator.getCurrentLocator(); + + manager = locator.getManager(ClusterManager.class); + if(manager == null) + throw new ConfigurationException("Unable to get " + ClusterManager.class.getName()); + + _mshostDao = locator.getDao(ManagementServerHostDao.class); + if(_mshostDao == null) + throw new ConfigurationException("Unable to get " + ManagementServerHostDao.class.getName()); + + 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); + } }