/// <summary> /// The main entry point for the tool. /// </summary> static public void Run(string[] args) { try { object param = new AddClientNodeParam(); CommandLineArgumentParser.CommandLineParser(ref param, args); cParam = (AddClientNodeParam)param; if (cParam.IsUsage) { AssemblyUsage.PrintLogo(cParam.IsLogo); AssemblyUsage.PrintUsage(); return; } if (!ValidateParameters()) { return; } bool multipleServers = false; if (cParam.Server != null || cParam.Server != string.Empty) { _serverList = cParam.Server.Split(','); if (_serverList.Length > 1 || (_serverList[0].Contains(":"))) { multipleServers = true; } } tryNextServer: if (multipleServers) { string[] serverAddress = _serverList[index].Split(':'); if (serverAddress.Length == 2) { if (!IsValidIP(serverAddress[0])) { Console.Error.WriteLine("Error: Invalid Server IP."); return; } NCache.ServerName = serverAddress[0]; try { NCache.Port = Convert.ToInt32(serverAddress[1]); } catch (Exception) { throw new Exception("Invalid Port :" + serverAddress[1] + " specified for server : " + serverAddress[0] + "."); } } else if (serverAddress.Length == 1) { if (!IsValidIP(serverAddress[0])) { Console.Error.WriteLine("Error: Invalid Server IP."); return; } NCache.ServerName = serverAddress[0]; NCache.Port = cParam.Port; if (cParam.Port == -1) { NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort; } } else { throw new Exception("Invalid server Address specified, kindly specify as [IPAdress] or [IPAdress]:[Port]."); } } else { if (cParam.Port != -1) { NCache.Port = cParam.Port; } if (cParam.Server != null || cParam.Server != string.Empty) { NCache.ServerName = cParam.Server; } if (cParam.Port == -1) { NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort; } } try { _server = NCache.ServerName; cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); } catch (Exception ex) { if (multipleServers) { if (index < _serverList.Length - 1) { Console.Error.WriteLine("Failed to connect to server : " + NCache.ServerName + ":" + NCache.Port + " \nTrying next server."); index++; goto tryNextServer; } } throw ex; } config = cacheServer.GetNewConfiguration(cParam.CacheId); //for getting server mappings if (cParam.AcquireServerMapping) { Alachisoft.NCache.Management.MappingConfiguration.Dom.MappingConfiguration mapping = cacheServer.GetServerMappingForClient(); if (mapping != null) { _clientIPMapping = mapping.ClientIPMapping; foreach (Mapping mappingServer in mapping.ManagementIPMapping.MappingServers) { if (mappingServer != null) { _managementIPMapping.Add(mappingServer.PrivateIP, mappingServer); } } } } if (config == null) { Console.Error.WriteLine("Error : The cache'{0}' does not exist on server {1}:{2} .", cParam.CacheId, NCache.ServerName, NCache.Port); return; } if (config.CacheSettings.CacheType == "clustered-cache") { Console.WriteLine("Adding client node '{0}' to cache '{1}' on server {2}:{3}.", cParam.ClientNode, cParam.CacheId, NCache.ServerName, NCache.Port); foreach (Address node in config.CacheDeployment.Servers.GetAllConfiguredNodes()) { currentServerNodes.Add(node.IpAddress.ToString()); } } else { Console.Error.WriteLine("Error: Client nodes cannot be added to local caches"); return; } if (config.CacheDeployment.ClientNodes != null) { foreach (ClientNode clientNode in config.CacheDeployment.ClientNodes.NodesList) { if (cParam.ClientNode.Equals(clientNode.Name)) { Console.Error.WriteLine("Error: " + clientNode.Name + " already part of \"" + cParam.CacheId + "\""); return; } currentClientNodes.Add(clientNode.Name); } } UpdateConfigs(); } catch (Exception ex) { Console.Error.WriteLine("Error: {0}", ex.Message); } }
/// <summary> /// The main entry point for the tool. /// </summary> public static void Run(string[] args) { try { object param = new AddClientNodeParam(); CommandLineArgumentParser.CommandLineParser(ref param, args); cParam = (AddClientNodeParam)param; if (cParam.IsUsage) { AssemblyUsage.PrintLogo(cParam.IsLogo); AssemblyUsage.PrintUsage(); return; } if (!ValidateParameters()) return; bool multipleServers = false; if (cParam.Server != null || cParam.Server != string.Empty) { _serverList = cParam.Server.Split(','); if (_serverList.Length > 1 || (_serverList[0].Contains(":"))) { multipleServers = true; } } tryNextServer: if (multipleServers) { string[] serverAddress = _serverList[index].Split(':'); if (serverAddress.Length == 2) { if (!IsValidIP(serverAddress[0])) { Console.Error.WriteLine("Error: Invalid Server IP."); return; } NCache.ServerName = serverAddress[0]; try { NCache.Port = Convert.ToInt32(serverAddress[1]); } catch (Exception) { throw new Exception("Invalid Port :" + serverAddress[1] + " specified for server : " + serverAddress[0] + "."); } } else if (serverAddress.Length == 1) { if (!IsValidIP(serverAddress[0])) { Console.Error.WriteLine("Error: Invalid Server IP."); return; } NCache.ServerName = serverAddress[0]; NCache.Port = cParam.Port; if (cParam.Port == -1) NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort; } else { throw new Exception("Invalid server Address specified, kindly specify as [IPAdress] or [IPAdress]:[Port]."); } } else { if (cParam.Port != -1) { NCache.Port = cParam.Port; } if (cParam.Server != null || cParam.Server != string.Empty) { NCache.ServerName = cParam.Server; } if (cParam.Port == -1) NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort; } try { _server = NCache.ServerName; cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); } catch (Exception ex) { if (multipleServers) { if (index < _serverList.Length - 1) { Console.Error.WriteLine("Failed to connect to server : " + NCache.ServerName + ":"+NCache.Port+" \nTrying next server."); index++; goto tryNextServer; } } throw ex; } config = cacheServer.GetNewConfiguration(cParam.CacheId); //for getting server mappings if (cParam.AcquireServerMapping) { Alachisoft.NCache.Management.MappingConfiguration.Dom.MappingConfiguration mapping=cacheServer.GetServerMappingForClient(); if (mapping != null) { _clientIPMapping = mapping.ClientIPMapping; foreach (Mapping mappingServer in mapping.ManagementIPMapping.MappingServers) { if (mappingServer != null) { _managementIPMapping.Add(mappingServer.PrivateIP, mappingServer); } } } } if (config == null) { Console.Error.WriteLine("Error : The cache'{0}' does not exist on server {1}:{2} .", cParam.CacheId, NCache.ServerName, NCache.Port); return; } if (config.CacheSettings.CacheType == "clustered-cache") { Console.WriteLine("Adding client node '{0}' to cache '{1}' on server {2}:{3}.", cParam.ClientNode, cParam.CacheId, NCache.ServerName, NCache.Port); foreach (Address node in config.CacheDeployment.Servers.GetAllConfiguredNodes()) { currentServerNodes.Add(node.IpAddress.ToString()); } } else { Console.Error.WriteLine("Error: Client nodes cannot be added to local caches"); return; } if (config.CacheDeployment.ClientNodes != null) { foreach (ClientNode clientNode in config.CacheDeployment.ClientNodes.NodesList) { if (cParam.ClientNode.Equals(clientNode.Name)) { Console.Error.WriteLine("Error: " + clientNode.Name + " already part of \"" + cParam.CacheId + "\""); return; } currentClientNodes.Add(clientNode.Name); } } UpdateConfigs(); } catch (Exception ex) { Console.Error.WriteLine("Error: {0}", ex.Message); } }