Package com.dotcms.cluster.bean

Examples of com.dotcms.cluster.bean.Server


  }

  public void setClusterNode(Map<String, String> properties) throws Exception {
      String httpPort=null, transportTCPPort, bindAddr, initData;
      ServerAPI serverAPI = APILocator.getServerAPI();
      Server currentServer=null;
     
        if(Config.getBooleanProperty("CLUSTER_AUTOWIRE",true)) {

      String serverId = ConfigUtils.getServerId();
      //This line is added because when someone add a license the node is already up and working and reset the existing port
      shutDownNode();
      currentServer = serverAPI.getServer(serverId);

      String storedBindAddr = (UtilMethods.isSet(currentServer.getHost()) && !currentServer.getHost().equals("localhost"))
          ?currentServer.getHost():currentServer.getIpAddress();

      bindAddr = properties!=null && UtilMethods.isSet(properties.get("BIND_ADDRESS")) ? properties.get("BIND_ADDRESS")
          :Config.getStringProperty("es.network.host", storedBindAddr);

      currentServer.setHost(Config.getStringProperty("es.network.host", null));

      if(properties!=null && UtilMethods.isSet(properties.get("ES_TRANSPORT_TCP_PORT"))){
        transportTCPPort = getNextAvailableESPort(serverId,bindAddr,properties.get("ES_TRANSPORT_TCP_PORT"));
      } else if(UtilMethods.isSet(currentServer.getEsTransportTcpPort())){
        transportTCPPort = getNextAvailableESPort(serverId,bindAddr,currentServer.getEsTransportTcpPort().toString());
      }else{
        transportTCPPort = getNextAvailableESPort(serverId, bindAddr, null);
      }

      if(Config.getBooleanProperty("es.http.enabled", false)) {
        httpPort = properties!=null &&   UtilMethods.isSet(properties.get("ES_HTTP_PORT")) ? properties.get("ES_HTTP_PORT")
            :UtilMethods.isSet(currentServer.getEsHttpPort()) ? currentServer.getEsHttpPort().toString()
            :ClusterFactory.getNextAvailablePort(serverId, ServerPort.ES_HTTP_PORT);

        currentServer.setEsHttpPort(Integer.parseInt(httpPort));
      }     

      List<String> myself = new ArrayList<String>();
      myself.add(currentServer.getServerId());

      List<Server> aliveServers = serverAPI.getAliveServers(myself);

      currentServer.setEsTransportTcpPort(Integer.parseInt(transportTCPPort));

      aliveServers.add(currentServer);

      StringBuilder initialHosts = new StringBuilder();

      int i=0;
      for (Server server : aliveServers) {
        if(i>0) {
          initialHosts.append(",");
        }

        if(UtilMethods.isSet(server.getHost()) && !server.getHost().equals("localhost")) {
          initialHosts.append(server.getHost()).append(":").append(server.getEsTransportTcpPort());
        } else {
          initialHosts.append(server.getIpAddress()).append(":").append(server.getEsTransportTcpPort());
        }

        i++;
      }

      if(initialHosts.length()==0) {
        if(bindAddr.equals("localhost")) {
          initialHosts.append(currentServer.getIpAddress()).append(":").append(transportTCPPort);
        } else {
          initialHosts.append(bindAddr).append(":").append(transportTCPPort);
        }
      }

      initData=initialHosts.toString();
     
      try {
                serverAPI.updateServer(currentServer);
            } catch (DotDataException e) {
                Logger.error(this, "Error trying to update server. Server Id: " + currentServer.getServerId());
            }
        }
        else {
            httpPort = Config.getStringProperty("es.http.port", "9200");
            transportTCPPort = Config.getStringProperty("es.transport.tcp.port", null);
View Full Code Here


        JSONObject jsonNode = new JSONObject();
        ServerAPI serverAPI = APILocator.getServerAPI();

        String serverId = serverAPI.readServerId();
        Server server = serverAPI.getServer(serverId);
        String cachePort = ClusterFactory.getNextAvailablePort(serverId, ServerPort.CACHE_PORT);
        String esPort = ClusterFactory.getNextAvailablePort(serverId, ServerPort.ES_TRANSPORT_TCP_PORT);

        jsonNode.put("BIND_ADDRESS", server!=null&&UtilMethods.isSet(server.getIpAddress())?server.getIpAddress():"");
        jsonNode.put("CACHE_BINDPORT", server!=null&&UtilMethods.isSet(server.getCachePort())?server.getCachePort():cachePort);
        jsonNode.put("ES_TRANSPORT_TCP_PORT", server!=null&&UtilMethods.isSet(server.getEsTransportTcpPort())?server.getEsTransportTcpPort():esPort);

        return responseResource.response( jsonNode.toString() );

    }
View Full Code Here

TOP

Related Classes of com.dotcms.cluster.bean.Server

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.