static public void Run(string[] args) { try { object param = new RemoveNodeParam(); CommandLineArgumentParser.CommandLineParser(ref param, args); cParam = (RemoveNodeParam)param; if (cParam.IsUsage) { AssemblyUsage.PrintLogo(cParam.IsLogo); AssemblyUsage.PrintUsage(); return; } if (!ValidateParameters()) { return; } if (cParam.Port != -1) { ncacheService.Port = cParam.Port; } if (cParam.Port == -1) { ncacheService.Port = ncacheService.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort; } if (cParam.Server != null || cParam.Server != string.Empty) { ncacheService.ServerName = cParam.Server; } else { cParam.Server = ncacheService.ServerName; } ICacheServer m = ncacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30)); if (m != null) { try { IPAddress address; if (!IPAddress.TryParse(ncacheService.ServerName, out address)) { string clusterIp = m.GetClusterIP(); if (clusterIp != null && clusterIp != string.Empty) { ncacheService.ServerName = clusterIp; } } CacheStatusOnServerContainer isClustered = m.IsClusteredCache(cParam.CacheId); CacheStatusOnServer result = isClustered.cacheStatus; if (result == CacheStatusOnServer.Unregistered) { throw new Exception("The requested cache is not registered on the specified server."); } else if (result == CacheStatusOnServer.LocalCache) { throw new Exception("RemoveNode Tool can be used with clustered caches only."); } Console.WriteLine("Removing '{0}' from the cache '{1}'.", ncacheService.ServerName.ToLower(), cParam.CacheId); NewCacheRegisterationInfo info = m.GetNewUpdatedCacheConfiguration(cParam.CacheId, null, ncacheService.ServerName, false); //.GetNewUpdatedCacheConfiguration(cParam.CacheId, null, NCache.ServerName, false); m.UnregisterCache(cParam.CacheId, string.Empty, true); foreach (string serverName in info.AffectedNodes) { ncacheService.ServerName = serverName; m = ncacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30)); m.RegisterCache(cParam.CacheId, info.UpdatedCacheConfig, null, true, false); } //Remove from client.ncconf Dictionary <string, Dictionary <int, Management.ClientConfiguration.Dom.CacheServer> > serversPriorityList = new Dictionary <string, Dictionary <int, Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer> >(); try { ArrayList clusterNodes = info.UpdatedCacheConfig.CacheDeployment.Servers.NodesList; ToolServerOperations.ClientConfigUtil _clientConfigUtil = new ToolServerOperations.ClientConfigUtil(); foreach (Alachisoft.NCache.Config.NewDom.ServerNode nodei in clusterNodes) { serversPriorityList.Add(nodei.IP, _clientConfigUtil.GetPrioritizedServerListForClient(nodei.IP, cParam.CacheId, clusterNodes)); } foreach (Alachisoft.NCache.Config.NewDom.ServerNode node in clusterNodes) { ncacheService.ServerName = node.IP; ICacheServer _cacheServer = ncacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30)); Management.ClientConfiguration.CacheServerList _cacheServerList = new Management.ClientConfiguration.CacheServerList(serversPriorityList[node.IP]); _cacheServer.UpdateClientServersList(cParam.CacheId, _cacheServerList, RtContextValue.NCACHE.ToString()); } serversPriorityList.Clear(); List <ClientNode> clusterClientNodes = info.UpdatedCacheConfig.CacheDeployment.ClientNodes.NodesList; foreach (Alachisoft.NCache.Config.Dom.ClientNode nodei in clusterClientNodes) { serversPriorityList.Add(nodei.Name, _clientConfigUtil.GetPrioritizedServerListForClient(nodei.Name, cParam.CacheId, clusterNodes)); } foreach (Alachisoft.NCache.Config.Dom.ClientNode node in clusterClientNodes) { ncacheService.ServerName = node.Name; ICacheServer _cacheServer = ncacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30)); Management.ClientConfiguration.CacheServerList _cacheServerList = new Management.ClientConfiguration.CacheServerList(serversPriorityList[node.Name]); _cacheServer.UpdateClientServersList(cParam.CacheId, _cacheServerList, node.RuntimeContextString); } } catch (Exception e) { } } catch (Exception e) { Console.Error.WriteLine("Failed to remove '{0}' from '{1}'. Error: {2} ", ncacheService.ServerName.ToLower(), cParam.CacheId, e.Message); } } } catch (Exception e) { Console.Error.WriteLine("Error : {0}", e.Message); } finally { if (ncacheService != null) { ncacheService.Dispose(); } } }
static public void Run(string[] args) { try { object param = new RemoveCacheParam(); CommandLineArgumentParser.CommandLineParser(ref param, args); cParam = (RemoveCacheParam)param; if (cParam.IsUsage) { AssemblyUsage.PrintLogo(cParam.IsLogo); AssemblyUsage.PrintUsage(); return; } if (!ValidateParameters()) { return; } if (cParam.Port != -1) { NCache.Port = cParam.Port; } if (cParam.Port == -1) { NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort; } if (cParam.Server != null || cParam.Server != string.Empty) { NCache.ServerName = cParam.Server; } cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); Console.WriteLine("\nRemoving cache '{0}' on server {1}:{2}.", cParam.CacheId, cacheServer.GetBindIP(), NCache.Port); if (cacheServer != null) { string getBindIp = string.Empty; try { Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = cacheServer.GetNewConfiguration(cParam.CacheId); if (serverConfig == null) { throw new Exception("Specified cache does not exist."); } if (serverConfig.CacheSettings.CacheType == "clustered-cache") { foreach (Address node in serverConfig.CacheDeployment.Servers.GetAllConfiguredNodes()) { try { NCache.ServerName = node.IpAddress.ToString(); cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); cacheServer.UnregisterCache(cParam.CacheId, null, false); Console.WriteLine("Cache '{0}' successfully removed from server {1}:{2}.\n", cParam.CacheId, NCache.ServerName, NCache.Port); } catch (Exception ex) { Console.Error.WriteLine("Error: Failed to Rmove Cache '{0}' from server '{1}:{2}'. ", cParam.CacheId, NCache.ServerName, NCache.Port); Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message); LogEvent(ex.Message); } finally { cacheServer.Dispose(); } } } else { try { getBindIp = cacheServer.GetBindIP(); cacheServer.UnregisterCache(cParam.CacheId, null, false); Console.WriteLine("Cache '{0}' successfully removed from server {1}:{2}.\n", cParam.CacheId, getBindIp, NCache.Port); } catch (Exception e) { throw e; } } } catch (Exception ex) { Console.Error.WriteLine("Error: Failed to Rmove Cache '{0}' from server '{1}:{2}'. ", cParam.CacheId, cacheServer.GetBindIP(), NCache.Port); Console.Error.WriteLine(ex.Message); LogEvent(ex.Message); } } } catch (Exception e) { Console.Error.WriteLine("Error: {0}", e.Message); Console.Error.WriteLine(); Console.Error.WriteLine(e.ToString()); } finally { NCache.Dispose(); } }
public static void Run(string[] args) { try { object param = new RemoveCacheParam(); CommandLineArgumentParser.CommandLineParser(ref param, args); cParam = (RemoveCacheParam)param; if (cParam.IsUsage) { AssemblyUsage.PrintLogo(cParam.IsLogo); AssemblyUsage.PrintUsage(); return; } if (!ValidateParameters()) return; if (cParam.Port != -1) { NCache.Port = cParam.Port; } if (cParam.Port == -1) NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort; if (cParam.Server != null || cParam.Server != string.Empty) { NCache.ServerName = cParam.Server; } cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); Console.WriteLine("\nRemoving cache '{0}' on server {1}:{2}.", cParam.CacheId, cacheServer.GetBindIP(), NCache.Port); if (cacheServer != null) { string getBindIp = string.Empty; try { Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = cacheServer.GetNewConfiguration(cParam.CacheId); if (serverConfig == null) { throw new Exception("Specified cache does not exist."); } if (serverConfig.CacheSettings.CacheType == "clustered-cache") { foreach (Address node in serverConfig.CacheDeployment.Servers.GetAllConfiguredNodes()) { try { NCache.ServerName = node.IpAddress.ToString(); cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); cacheServer.UnregisterCache(cParam.CacheId, null, false); Console.WriteLine("Cache '{0}' successfully removed from server {1}:{2}.\n", cParam.CacheId, NCache.ServerName, NCache.Port); } catch (Exception ex) { Console.Error.WriteLine("Error: Failed to Rmove Cache '{0}' from server '{1}:{2}'. ", cParam.CacheId, NCache.ServerName, NCache.Port); Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message); LogEvent(ex.Message); } finally { cacheServer.Dispose(); } } } else { try { getBindIp = cacheServer.GetBindIP(); cacheServer.UnregisterCache(cParam.CacheId, null, false); Console.WriteLine("Cache '{0}' successfully removed from server {1}:{2}.\n", cParam.CacheId, getBindIp, NCache.Port); } catch (Exception e) { throw e; } } } catch (Exception ex) { Console.Error.WriteLine("Error: Failed to Rmove Cache '{0}' from server '{1}:{2}'. ", cParam.CacheId, cacheServer.GetBindIP(), NCache.Port); Console.Error.WriteLine(ex.Message); LogEvent(ex.Message); } } } catch (Exception e) { Console.Error.WriteLine("Error: {0}", e.Message); Console.Error.WriteLine(); Console.Error.WriteLine(e.ToString()); } finally { NCache.Dispose(); } }