Example #1
0
        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();
                }
            }
        }
Example #2
0
        public static 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();
            }
        }