}
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);