Esempio n. 1
0
        public static void Run(string[] args)
        {
            try
            {
                object param = new ClearCacheToolParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                cParam = (ClearCacheToolParam)param;
                if (cParam.IsUsage)
                {
                    AssemblyUsage.PrintUsage();
                    AssemblyUsage.PrintLogo(cParam.IsLogo);
                    return;
                }

                if (!ValidateParameters())
                {
                    return;
                }
                ClearCache(cParam.S_cacheId, cParam.S_forceClear, cParam.S_clearJsCss);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error: " + ex.Message);
                Console.Error.WriteLine();
                Console.Error.WriteLine(ex.ToString());
            }
        }
Esempio n. 2
0
        static public void Run(string[] args)
        {
            try
            {
                object param = new VerifyNCacheLicenceParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                cParam = (VerifyNCacheLicenceParam)param;

                if (!cParam.Logo)
                {
                    AssemblyUsage.PrintLogo(cParam.IsLogo);
                }
                if (cParam.IsUsage)
                {
                    AssemblyUsage.PrintUsage();
                    return;
                }


                PrintUserInfo();
                Console.WriteLine();

                Console.WriteLine("Edition Installed: NCache 4.6 OpenSouce Edition.\n");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return;
            }
        }
Esempio n. 3
0
        /// <summary>
        ///     The main entry point for the tool.
        /// </summary>
        public static void Run(string[] args)
        {
            try
            {
                object param = new StressTestToolParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                cParam = (StressTestToolParam)param;
                if (cParam.IsUsage)
                {
                    AssemblyUsage.PrintLogo(cParam.IsLogo);
                    AssemblyUsage.PrintUsage();
                    return;
                }

                if (!ApplyParameters(args))
                {
                    return;
                }
                //if (!ValidateParameters()) return;


                Console.WriteLine("cacheId = {0}, total-loop-count = {1}, test-case-iterations = {2}, testCaseIterationDelay = {3}, gets-per-iteration = {4}, updates-per-iteration = {5}, data-size = {6}, expiration = {7}, thread-count = {8}, reporting-interval = {9}.", cParam.CacheId, cParam.TotalLoopCount, cParam.TestCaseIterations, cParam.TestCaseIterationDelay, cParam.GetsPerIteration, cParam.UpdatesPerIteration, cParam.DataSize, cParam.Expiration, cParam.ThreadCount, cParam.ReportingInterval);
                Console.WriteLine("-------------------------------------------------------------------\n");
                Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Normal;

                var threadTest = new ThreadTest(cParam.CacheId, cParam.TotalLoopCount, cParam.TestCaseIterations, cParam.TestCaseIterationDelay, cParam.GetsPerIteration, cParam.UpdatesPerIteration, cParam.DataSize, cParam.Expiration, cParam.ThreadCount, cParam.ReportingInterval, cParam.IsLogo);
                threadTest.Test();
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error: " + e.Message);
                Console.Error.WriteLine();
                Console.Error.WriteLine(e.ToString());
            }
        }
Esempio n. 4
0
        public static void Run(string[] args)
        {
            try
            {
                object param = new AddtestDataToolParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                cParam = (AddtestDataToolParam)param;
                if (cParam.IsUsage)
                {
                    AssemblyUsage.PrintLogo(cParam.IsLogo);
                    AssemblyUsage.PrintUsage();
                    return;
                }

                if (!ValidateParameters())
                {
                    return;
                }

                AddTestData(cParam.S_cacheId, cParam.S_itemCount, cParam.S_dataSize, cParam.S_AbsoluteExpiration);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error: " + e.Message);
                Console.Error.WriteLine();
                Console.Error.WriteLine(e.ToString());
            }
        }
Esempio n. 5
0
            /// <summary>
            /// The main entry point for the tool.
            /// </summary>
            public static void Run(string[] args)
            {
                try
                {
                    object param = new StopCacheToolParam();
                    CommandLineArgumentParser.CommandLineParser(ref param, args);
                    cParam = (StopCacheToolParam)param;
                    if (cParam.IsUsage)
                    {
                        AssemblyUsage.PrintLogo(cParam.IsLogo);
                        AssemblyUsage.PrintUsage();
                        return;
                    }

                    if (!ApplyParameters(args))
                    {
                        return;
                    }

                    ICacheServer m         = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                    string       getBindIp = string.Empty;
                    if (m != null)
                    {
                        foreach (string cache in s_cacheId)
                        {
                            try
                            {
                                getBindIp = m.GetBindIP();
                                Console.WriteLine("\nStopping cache '{0}' on server {1}:{2}.", cache, getBindIp,
                                                  NCache.Port);

                                m.StopCache(cache);
                                Console.WriteLine("'{0}' successfully stopped on server {1}:{2}.\n", cache, getBindIp,
                                                  NCache.Port);
                            }

                            catch (Exception e)
                            {
                                Console.Error.WriteLine("Failed to stop '{0}'. Error: {1} ", cache, e.Message);
                                Console.Error.WriteLine();
                                Console.Error.WriteLine(e.ToString());
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine("Error : {0}", e.Message);

                    Console.Error.WriteLine();
                    Console.Error.WriteLine(e.ToString());
                }
                finally
                {
                    NCache.Dispose();
                }
            }
        static public Hashtable DiscoverCachesViaWMI()
        {
            ServiceController sc = new ServiceController("Winmgmt");

            runningcaches = new Hashtable();
            if (sc.Status == ServiceControllerStatus.Running)
            {
                try
                {
                    foreach (Process process in processes)
                    {
                        string   cmdLine = GetCommandLine(process);
                        string[] tmp     = cmdLine.Split(' ');
                        if (tmp != null && tmp.Length > 0)
                        {
                            object param = new CacheHostParam();
                            CommandLineArgumentParser.CommandLineParser(ref param, tmp);
                            CacheHostParam cParam    = (CacheHostParam)param;
                            CacheHostInfo  cacheInfo = null;
                            if (!runningcaches.ContainsKey(cParam.CacheName.ToLower()))
                            {
                                cacheInfo                = new CacheHostInfo();
                                cacheInfo.ProcessId      = process.Id;
                                cacheInfo.ManagementPort = cParam.ManagementPort;
                                runningcaches.Add(cParam.CacheName.ToLower(), cacheInfo);
                            }
                            else
                            {
                                cacheInfo                = runningcaches[cParam.CacheName.ToLower()] as CacheHostInfo;
                                cacheInfo.ProcessId      = process.Id;
                                cacheInfo.ManagementPort = cParam.ManagementPort;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    return(null);
                }
                return(runningcaches);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// The main entry point for the tool.
        /// </summary>
        static public void Run(string[] args)
        {
            try
            {
                object param = new AddNodeParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                cParam         = (AddNodeParam)param;
                cParam.CacheId = cParam.CacheId.ToLower();
                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;
                }


                try
                {
                    if (cParam.ExistingServer != null || cParam.ExistingServer != string.Empty)
                    {
                        NCache.ServerName = cParam.ExistingServer;
                    }
                    IPAddress address;
                    string    clusterIp;

                    ICacheServer m = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                    if (!IPAddress.TryParse(cParam.NewServer, out address))
                    {
                        clusterIp = m.GetClusterIP();
                        if (clusterIp != null && clusterIp != string.Empty)
                        {
                            cParam.NewServer = clusterIp;
                        }
                    }

                    NCache.ServerName = cParam.ExistingServer;
                    m = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                    if (!IPAddress.TryParse(cParam.ExistingServer, out address))
                    {
                        clusterIp = m.GetClusterIP();
                        if (clusterIp != null && clusterIp != string.Empty)
                        {
                            cParam.ExistingServer = clusterIp;
                        }
                    }
                    CacheStatusOnServerContainer isClustered = m.IsClusteredCache(cParam.CacheId.ToLower());
                    CacheStatusOnServer          result      = isClustered.cacheStatus;

                    if (result == CacheStatusOnServer.Unregistered)
                    {
                        throw new Exception("The requested cache is not registered on the source node.");
                    }
                    else if (result == CacheStatusOnServer.LocalCache)
                    {
                        throw new Exception("The AddNode Tool can be used with clustered caches only");
                    }

                    Console.WriteLine("Adding node '{0}' to cache '{1}'.", cParam.NewServer, cParam.CacheId);

                    NewCacheRegisterationInfo info = m.GetNewUpdatedCacheConfiguration(cParam.CacheId, _partId, cParam.NewServer, true);

                    //muds:
                    //first of all try to register the cache on the destination server.
                    try
                    {
                        NCache.ServerName = cParam.NewServer;
                        m = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                        if (!IPAddress.TryParse(cParam.NewServer, out address))
                        {
                            clusterIp = m.GetClusterIP();
                            if (clusterIp != null && clusterIp != string.Empty)
                            {
                                cParam.NewServer = clusterIp;
                            }
                        }

                        m.RegisterCache(cParam.CacheId, info.UpdatedCacheConfig, _partId, true, false);
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine("Failed to Create Cache on '{0}'. ", NCache.ServerName);
                        Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);

                        LogEvent(ex.Message);
                        NCache.Dispose();
                        return;
                    }
                    finally
                    {
                        m.Dispose();
                    }
                    //muds:
                    // Now update the cache configurations on all the servers where the cache
                    //is registered.
                    foreach (string serverName in info.AffectedNodes)
                    {
                        if (info.AffectedPartitions.Count > 0)
                        {
                            foreach (string partId in info.AffectedPartitions)
                            {
                                try
                                {
                                    NCache.ServerName = serverName;
                                    if (!IPAddress.TryParse(NCache.ServerName, out address))
                                    {
                                        clusterIp = m.GetClusterIP();
                                        if (clusterIp != null && clusterIp != string.Empty)
                                        {
                                            NCache.ServerName = clusterIp;
                                        }
                                    }
                                    reregister = true;
                                    m          = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                                    m.RegisterCache(cParam.CacheId, info.UpdatedCacheConfig, _partId, true, false);
                                }
                                catch (Exception ex)
                                {
                                    Console.Error.WriteLine("Failed to Create Cache on '{0}'. ", NCache.ServerName);
                                    Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);

                                    LogEvent(ex.Message);
                                }
                                finally
                                {
                                    m.Dispose();
                                }
                            }
                        }
                        else
                        {
                            try
                            {
                                NCache.ServerName = serverName;
                                if (!IPAddress.TryParse(NCache.ServerName, out address))
                                {
                                    clusterIp = m.GetClusterIP();
                                    if (clusterIp != null && clusterIp != string.Empty)
                                    {
                                        NCache.ServerName = clusterIp;
                                    }
                                }
                                reregister = true;
                                m          = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                                m.RegisterCache(cParam.CacheId, info.UpdatedCacheConfig, _partId, true, false);
                            }
                            catch (Exception ex)
                            {
                                Console.Error.WriteLine("Failed to Create Cache on '{0}'. ", NCache.ServerName);
                                Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);

                                LogEvent(ex.Message);
                                NCache.Dispose();
                                return;
                            }
                            finally
                            {
                                m.Dispose();
                            }
                        }
                    }
                    List <string> serversToUpdate = new List <string>();
                    foreach (Config.NewDom.ServerNode node in info.UpdatedCacheConfig.CacheDeployment.Servers.ServerNodeList)
                    {
                        serversToUpdate.Add(node.IP);
                    }
                    Management.Management.Util.ManagementWorkFlow.UpdateServerMappingConfig(serversToUpdate.ToArray());
                    //Add in client.ncconf
                    Dictionary <string, Dictionary <int, Management.ClientConfiguration.Dom.CacheServer> > serversPriorityList = new Dictionary <string, Dictionary <int, Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer> >();
                    ToolServerOperations.ClientConfigUtil _clientConfigUtil = new ToolServerOperations.ClientConfigUtil();
                    try
                    {
                        ArrayList clusterNodes = info.UpdatedCacheConfig.CacheDeployment.Servers.NodesList;

                        foreach (Alachisoft.NCache.Config.NewDom.ServerNode nodei in clusterNodes)
                        {
                            serversPriorityList.Add(nodei.IP, _clientConfigUtil.GetPrioritizedServerListForClient(nodei.IP, cParam.CacheId, clusterNodes));
                        }

                        Alachisoft.NCache.Config.NewDom.ServerNode nodeForClientList = new Config.NewDom.ServerNode();   //Hack: priority list requires a serverIP and client Ip cant be used hence!!
                        foreach (Alachisoft.NCache.Config.NewDom.ServerNode node in clusterNodes)
                        {
                            NCache.ServerName = node.IP;
                            ICacheServer _cacheServer = NCache.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());
                            nodeForClientList = node;
                        }


                        List <Alachisoft.NCache.Config.Dom.ClientNode> clientNodeList = info.UpdatedCacheConfig.CacheDeployment.ClientNodes.NodesList;
                        foreach (Alachisoft.NCache.Config.Dom.ClientNode node in clientNodeList)
                        {
                            NCache.ServerName = node.Name;
                            ICacheServer _cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                            Management.ClientConfiguration.CacheServerList _cacheServerList = new Management.ClientConfiguration.CacheServerList(serversPriorityList[nodeForClientList.IP]);
                            _cacheServer.UpdateClientServersList(cParam.CacheId, _cacheServerList, RtContextValue.NCACHE.ToString());
                        }
                    }
                    catch (Exception e)
                    {
                    }

                    Console.WriteLine("'{0}' successfully added to cache '{1}'.\n", cParam.NewServer,
                                      cParam.CacheId);
                }

                catch (ConfigurationException e)
                {
                    Console.Error.WriteLine("Failed to add '{0}' to '{1}'. Error: {2} ", NCache.ServerName.ToLower(), cParam.CacheId, e.Message);
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine("Failed to add '{0}' to '{1}'. Error: {2} ", NCache.ServerName.ToLower(), cParam.CacheId, e.Message);
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error : {0}", e.Message);
            }
            finally
            {
                NCache.Dispose();
            }
        }
Esempio n. 8
0
        /// <summary>
        /// The main entry point for the tool.
        /// </summary>ju
        static public void Run(string[] args)
        {
            bool successful = true;

            System.Reflection.Assembly           asm          = null;
            Alachisoft.NCache.Config.Dom.Class[] queryClasses = null;
            string failedNodes = string.Empty;
            string serverName  = string.Empty;

            try
            {
                object param = new ConfigureQueryIndexParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                cParam = (ConfigureQueryIndexParam)param;
                if (cParam.IsUsage)
                {
                    AssemblyUsage.PrintLogo(cParam.IsLogo);
                    AssemblyUsage.PrintUsage();
                    return;
                }
                if (!ValidateParameters())
                {
                    successful = false;
                    return;
                }
                if (cParam.Port == -1)
                {
                    NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                }
                if (cParam.Server != null && cParam.Server != string.Empty)
                {
                    NCache.ServerName = cParam.Server;
                }
                if (cParam.Port != -1)
                {
                    NCache.Port = cParam.Port;
                }

                cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                string extension = ".dll";
                if (cacheServer != null)
                {
                    serverName = cacheServer.GetClusterIP();
                    if (cacheServer.IsRunning(cParam.CacheId))
                    {
                        throw new Exception(cParam.CacheId + " is Running on " + serverName +
                                            "\nStop the cache first and try again.");
                    }

                    Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig =
                        cacheServer.GetNewConfiguration(cParam.CacheId);

                    if (serverConfig == null)
                    {
                        throw new Exception("Specified cache is not registered on the given server.");
                    }

                    try
                    {
                        asm = System.Reflection.Assembly.LoadFrom(cParam.AsmPath);

                        extension = Path.GetExtension(asm.FullName);
                    }
                    catch (Exception e)
                    {
                        string message = string.Format("Could not load assembly \"" + cParam.AsmPath + "\". {0}",
                                                       e.Message);
                        Console.Error.WriteLine("Error : {0}", message);
                        LogEvent(e.Message);
                        successful = false;
                        return;
                    }

                    if (asm == null)
                    {
                        throw new Exception("Could not load specified Assembly");
                    }

                    System.Type type = asm.GetType(cParam.Class, true);


                    if (serverConfig.CacheSettings.QueryIndices == null)
                    {
                        serverConfig.CacheSettings.QueryIndices         = new Alachisoft.NCache.Config.Dom.QueryIndex();
                        serverConfig.CacheSettings.QueryIndices.Classes = queryClasses;
                    }

                    queryClasses = serverConfig.CacheSettings.QueryIndices.Classes;

                    serverConfig.CacheSettings.QueryIndices.Classes = GetSourceClass(GetClass(queryClasses, asm));

                    if (serverConfig.CacheSettings.CacheType == "clustered-cache")
                    {
                        foreach (Address node in serverConfig.CacheDeployment.Servers.GetAllConfiguredNodes())
                        {
                            NCache.ServerName = node.IpAddress.ToString();
                            try
                            {
                                cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                                if (cacheServer.IsRunning(cParam.CacheId))
                                {
                                    throw new Exception(cParam.CacheId + " is Running on " + serverName +
                                                        "\nStop the cache first.");
                                }

                                Console.WriteLine("Adding query indexes on node '{0}' to cache '{1}'.", serverName, cParam.CacheId);
                                cacheServer.RegisterCache(cParam.CacheId, serverConfig, "", true,
                                                          cParam.IsHotApply);
                            }
                            catch (Exception ex)
                            {
                                Console.Error.WriteLine("Failed to Add Query Index on '{0}'. ", serverName);
                                Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);
                                failedNodes = failedNodes + "/n" + node.IpAddress.ToString();
                                LogEvent(ex.Message);
                                successful = false;
                            }
                            finally
                            {
                                cacheServer.Dispose();
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            Console.WriteLine("Adding query indexes on node '{0}' to cache '{1}'.", serverName, cParam.CacheId);
                            cacheServer.RegisterCache(cParam.CacheId, serverConfig, "", true, cParam.IsHotApply);
                        }
                        catch (Exception ex)
                        {
                            Console.Error.WriteLine("Failed to Add Query Index on '{0}'. ", NCache.ServerName);
                            Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);
                            LogEvent(ex.Message);
                            successful = false;
                        }
                        finally
                        {
                            cacheServer.Dispose();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error : {0}", e.Message);
                LogEvent(e.Message);
                successful = false;
            }
            finally
            {
                NCache.Dispose();
                if (successful && !cParam.IsUsage)
                {
                    Console.WriteLine("Query indexes successfully added.");
                }
            }
        }
Esempio n. 9
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();
                }
            }
        }
Esempio n. 10
0
            public static void Run(string[] args)
            {
                try
                {
                    object param = new DumpCacheParam();
                    CommandLineArgumentParser.CommandLineParser(ref param, args);
                    cParam = (DumpCacheParam)param;

                    if (cParam.IsUsage)
                    {
                        AssemblyUsage.PrintLogo(cParam.IsLogo);
                        AssemblyUsage.PrintUsage();
                        return;
                    }
                    if (!ValidateParameters())
                    {
                        return;
                    }

                    Cache cache = Factory.InitializeCache(cParam.CacheId);
                    cache.ExceptionsEnabled = true;

                    System.Console.WriteLine("Cache count: {0}.", cache.Count);
                    IDictionaryEnumerator keys = (IDictionaryEnumerator)cache.GetEnumerator();

                    if (keys != null)
                    {
                        long index       = 0;
                        bool checkFilter = (cParam.KeyFilter != "");
                        cParam.KeyFilter = cParam.KeyFilter.Trim();
                        while (keys.MoveNext())
                        {
                            if ((cParam.KeyCount > 0) && (index >= cParam.KeyCount))
                            {
                                break;
                            }

                            if (checkFilter == true)
                            {
                                string tmpKey = (string)keys.Key;

                                if (tmpKey.Contains(cParam.KeyFilter) == true)
                                {
                                    System.Console.WriteLine(tmpKey);
                                }
                            }
                            else
                            {
                                System.Console.WriteLine(keys.Key);
                            }
                            index++;
                        } //end while
                    }     //end if
                    cache.Dispose();
                }         //end try block
                catch (Exception e)
                {
                    Console.Error.WriteLine("Error: " + e.Message);
                    Console.Error.WriteLine();
                    Console.Error.WriteLine(e.ToString());
                }
            }
Esempio n. 11
0
        /// <summary>
        ///     The main entry point for the tool.
        /// </summary>
        public static void Run(string[] args)
        {
            var failedNodes = string.Empty;

            NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
            CacheServerConfig[] caches       = null;
            ICacheServer        cacheServer  = null;
            CacheServerConfig   _cacheConfig = null;

            try
            {
                object param = new ConfigureCacheParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                ccParam = (ConfigureCacheParam)param;

                if (ccParam.IsUsage)
                {
                    AssemblyUsage.PrintLogo(ccParam.IsLogo);
                    AssemblyUsage.PrintUsage();
                    return;
                }

                if (!ValidateParameters())
                {
                    return;
                }

                if (ccParam.Port != -1)
                {
                    NCache.Port = ccParam.Port;
                }

                if (ccParam.Port == -1)
                {
                    NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                }

                if (ccParam.Path != null && ccParam.Path != string.Empty)
                {
                    if (Path.HasExtension(ccParam.Path))
                    {
                        var extension = Path.GetExtension(ccParam.Path);

                        if (!extension.Equals(".ncconf") && !extension.Equals(".xml"))
                        {
                            throw new Exception("Incorrect file format. Only .ncconf and .xml are supported.");
                        }
                    }
                    else
                    {
                        throw new Exception("Incorrect configuration file path specified.");
                    }

                    var builder = new ConfigurationBuilder(ccParam.Path);
                    builder.RegisterRootConfigurationObject(typeof(CacheServerConfig));
                    builder.ReadConfiguration();

                    if (builder.Configuration != null)
                    {
                        caches = new CacheServerConfig[builder.Configuration.Length];
                        builder.Configuration.CopyTo(caches, 0);
                    }
                    else
                    {
                        throw new Exception("Configuration cannot be loaded.");
                    }
                    var validator          = new ConfigurationValidator();
                    var _isConfigValidated = validator.ValidateConfiguration(caches);

                    _cacheConfig = caches[0];

                    if (_cacheConfig.CacheSettings.Name == null)
                    {
                        _cacheConfig.CacheSettings.Name = ccParam.CacheId;
                    }

                    if (_cacheConfig.CacheSettings.Storage == null || _cacheConfig.CacheSettings.Storage.Size == -1)
                    {
                        throw new Exception("Cache size is not specified.");
                    }

                    if (_cacheConfig.CacheSettings.EvictionPolicy == null)
                    {
                        _cacheConfig.CacheSettings.EvictionPolicy                 = new EvictionPolicy();
                        _cacheConfig.CacheSettings.EvictionPolicy.Policy          = "priority";
                        _cacheConfig.CacheSettings.EvictionPolicy.DefaultPriority = "normal";
                        _cacheConfig.CacheSettings.EvictionPolicy.EvictionRatio   = 5;
                        _cacheConfig.CacheSettings.EvictionPolicy.Enabled         = true;
                    }

                    if (_cacheConfig.CacheSettings.Cleanup == null)
                    {
                        _cacheConfig.CacheSettings.Cleanup          = new Cleanup();
                        _cacheConfig.CacheSettings.Cleanup.Interval = 15;
                    }

                    if (_cacheConfig.CacheSettings.Log == null)
                    {
                        _cacheConfig.CacheSettings.Log = new Log();
                    }

                    if (_cacheConfig.CacheSettings.PerfCounters == null)
                    {
                        _cacheConfig.CacheSettings.PerfCounters         = new PerfCounters();
                        _cacheConfig.CacheSettings.PerfCounters.Enabled = true;
                    }

                    if (_cacheConfig.CacheSettings.CacheType == "clustered-cache")
                    {
                        if (_cacheConfig.CacheSettings.CacheTopology.ClusterSettings == null)
                        {
                            throw new Exception("Cluster settings not specified for the cluster cache.");
                        }

                        if (_cacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel == null)
                        {
                            throw new Exception("Cluster channel related settings not specified for cluster cache.");
                        }

                        if (_cacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel.TcpPort == -1)
                        {
                            throw new Exception("Cluster port not specified for cluster cache.");
                        }
                    }
                }
                else
                {
                    _SimpleCacheConfig.CacheSettings                                = new CacheServerConfigSetting();
                    _SimpleCacheConfig.CacheSettings.Name                           = ccParam.CacheId;
                    _SimpleCacheConfig.CacheSettings.Storage                        = new Storage();
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy                 = new EvictionPolicy();
                    _SimpleCacheConfig.CacheSettings.Cleanup                        = new Cleanup();
                    _SimpleCacheConfig.CacheSettings.Log                            = new Log();
                    _SimpleCacheConfig.CacheSettings.PerfCounters                   = new PerfCounters();
                    _SimpleCacheConfig.CacheSettings.PerfCounters.Enabled           = true;
                    _SimpleCacheConfig.CacheSettings.Storage.Type                   = "heap";
                    _SimpleCacheConfig.CacheSettings.Storage.Size                   = ccParam.CacheSize;
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy.Policy          = "priority";
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy.DefaultPriority = "normal";
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy.EvictionRatio   = 5;
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy.Enabled         = false;
                    _SimpleCacheConfig.CacheSettings.Cleanup.Interval               = 15;
                    _SimpleCacheConfig.CacheSettings.CacheTopology                  = new CacheTopology();

                    if (string.IsNullOrEmpty(ccParam.Topology))
                    {
                        _SimpleCacheConfig.CacheSettings.CacheTopology.Topology = "Local";
                    }
                    else
                    {
                        _SimpleCacheConfig.CacheSettings.CacheTopology.Topology = ccParam.Topology;
                    }

                    if (ccParam.IsInProc && _SimpleCacheConfig.CacheSettings.CacheTopology.Topology.Equals("local-cache"))
                    {
                        _SimpleCacheConfig.CacheSettings.InProc = true;
                    }


                    if (_SimpleCacheConfig.CacheSettings.CacheType == "clustered-cache")
                    {
                        _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings         = new Cluster();
                        _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel = new Channel();

                        _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel.TcpPort  = ccParam.ClusterPort;
                        _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings.StatsRepInterval = 600;
                        if (_SimpleCacheConfig.CacheSettings.CacheTopology.Topology == "partitioned-replica")
                        {
                            _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel.PortRange = 2;
                        }
                    }

                    if (ccParam.EvictionPolicy != null && ccParam.EvictionPolicy != string.Empty)
                    {
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.Policy  = ccParam.EvictionPolicy;
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.Enabled = true;
                    }

                    if (ccParam.Ratio != -1)
                    {
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.EvictionRatio = ccParam.Ratio;
                    }

                    if (ccParam.CleanupInterval != -1)
                    {
                        _SimpleCacheConfig.CacheSettings.Cleanup.Interval = ccParam.CleanupInterval;
                    }

                    if (ccParam.DefaultPriority != null && ccParam.DefaultPriority != string.Empty)
                    {
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.DefaultPriority = ccParam.DefaultPriority;
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.Enabled         = true;
                    }
                    _cacheConfig = _SimpleCacheConfig;
                }
                try
                {
                    _cacheConfig.CacheSettings.Name = ccParam.CacheId;

                    if (_cacheConfig.CacheSettings.CacheType == "clustered-cache")
                    {
                        if (_cacheConfig.CacheDeployment == null)
                        {
                            _cacheConfig.CacheDeployment         = new CacheDeployment();
                            _cacheConfig.CacheDeployment.Servers = new ServersNodes();
                        }
                        _cacheConfig.CacheDeployment.Servers.NodesList = GetServers(ccParam.Server);
                    }

                    var serverList  = new Dictionary <int, CacheServer>();
                    var serverCount = 0;
                    foreach (ServerNode node in GetServers(ccParam.Server))
                    {
                        var tempServer = new CacheServer();
                        tempServer.ServerName = node.IP;
                        serverList.Add(serverCount, tempServer);
                        serverCount++;
                    }
                    var servers         = new CacheServerList(serverList);
                    var serversToUpdate = new List <string>();
                    foreach (ServerNode node in GetServers(ccParam.Server))
                    {
                        NCache.ServerName = node.IP;

                        Console.WriteLine(AppendBlankLine("\nCreating cache") + " '{0}' on server '{1}' ", _cacheConfig.CacheSettings.Name, NCache.ServerName);
                        try
                        {
                            cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                            if (cacheServer != null)
                            {
                                var serverConfig = cacheServer.GetNewConfiguration(_cacheConfig.CacheSettings.Name);

                                if (serverConfig != null)
                                {
                                    throw new Exception("Specified cache already exists.");
                                }

                                if (serverConfig != null && ccParam.IsOverWrite)
                                {
                                    NCache.ServerName = node.IP;

                                    if (serverConfig.CacheDeployment != null)
                                    {
                                        if (serverConfig.CacheDeployment.ClientNodes != null)
                                        {
                                            _cacheConfig.CacheDeployment.ClientNodes = serverConfig.CacheDeployment.ClientNodes;
                                        }
                                    }
                                }

                                cacheServer.RegisterCache(_cacheConfig.CacheSettings.Name, _cacheConfig, "", ccParam.IsOverWrite, ccParam.IsHotApply);
                                cacheServer.UpdateClientServersList(_cacheConfig.CacheSettings.Name, servers, "NCACHE");
                                serversToUpdate.Add(node.IP);

                                Console.WriteLine("Cache '{0}' successfully created on server {1}:{2} .", _cacheConfig.CacheSettings.Name, NCache.ServerName, NCache.Port);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                    ManagementWorkFlow.UpdateServerMappingConfig(serversToUpdate.ToArray());
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    if (cacheServer != null)
                    {
                        cacheServer.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(AppendBlankLine("Failed") + " to create cache on server '{0}'. ", ccParam.Server);
                Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);
                LogEvent(ex.Message);
            }
            finally
            {
                NCache.Dispose();
            }
        }
Esempio n. 12
0
        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();
            }
        }
Esempio n. 13
0
        static public void Run(string[] args)
        {
            try
            {
                object param = new RemoveClientNodeParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                cParam = (RemoveClientNodeParam)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));

                config = cacheServer.GetNewConfiguration(cParam.CacheId);
                string getClusterIp = cacheServer.GetClusterIP();
                if (config == null)
                {
                    Console.Error.WriteLine("Error: The cache doesnot exist.");
                    return;
                }
                if (config.CacheSettings.CacheType == "clustered-cache")
                {
                    Console.WriteLine("Removing client node '{0}' from cache '{1}' on server '{2}:{3}'.",
                                      cParam.ClientNode, cParam.CacheId, getClusterIp, 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 (UpdateConfigs())
                {
                    Console.WriteLine("Client node '{0}' successfully removed from cache '{1}' on server {2}:{3}.",
                                      cParam.ClientNode, cParam.CacheId, getClusterIp, NCache.Port);
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error: {0}", ex.Message);
            }
            finally
            {
                if (cacheServer != null)
                {
                    cacheServer.Dispose();
                }
            }
        }
Esempio n. 14
0
        public static bool populateValues(string[] args)
        {
            bool   isValid      = false;
            String errorMessage = "";

            try
            {
                if (args != null && args.Length > 0)
                {
                    object param = new CacheHostParam();
                    CommandLineArgumentParser.CommandLineParser(ref param, args);
                    CacheHostParam cParam = (CacheHostParam)param;
                    if (cParam.Debug)
                    {
                        while (!Debugger.IsAttached)
                        {
                            Thread.Sleep(500);
                        }
                    }
                    if (cParam.IsUsage)
                    {
                        AssemblyUsage.PrintLogo(cParam.IsLogo);
                        AssemblyUsage.PrintUsage();
                        return(false);
                    }

                    if (!String.IsNullOrEmpty(cParam.CacheName))
                    {
                        cacheName = cParam.CacheName;
                        isValid   = true;
                    }
                    else
                    {
                        if (File.Exists(cParam.CacheConfigPath))
                        {
                            try
                            {
                                if (isCacheExist(cParam.CacheConfigPath))
                                {
                                    String cName = getCacheName(cParam.CacheConfigPath);
                                    if (!String.IsNullOrEmpty(cName))
                                    {
                                        cacheName = cName;
                                        isValid   = true;
                                    }
                                    else
                                    {
                                        errorMessage = "Provided config.conf is not valid cache configurations.";
                                        isValid      = false;
                                        ErrorCode    = 1;
                                    }
                                }
                                else
                                {
                                    errorMessage = "Multiple cache configurations provided in config.conf.";
                                    isValid      = false;
                                    ErrorCode    = 2;
                                }
                            }
                            catch (Exception ex)
                            {
                                errorMessage = ex.Message;
                                isValid      = false;
                            }
                        }
                        else
                        {
                            errorMessage = "Cache configuration [config.conf] path is not provided or File does not exist.";
                            isValid      = false;
                            ErrorCode    = 3;
                        }
                    }

                    throwError(errorMessage, isValid);

                    if (cParam.ManagementPort != -1 && cParam.ManagementPort != 0)
                    {
                        managementPort = cParam.ManagementPort;
                        isValid        = true;
                    }
                    throwError(errorMessage, isValid);
                }
                else
                {
                    errorMessage = "Arguments not specified";
                    isValid      = false;
                    throwError(errorMessage, isValid);
                }
            }
            catch (Exception ex)
            {
                throwError(ex.ToString(), false);
            }
            return(true);
        }
Esempio n. 15
0
        /// <summary>
        /// The main entry point for the tool.
        /// </summary>
        static public void Run(string[] args)
        {
            string       failedNodes = string.Empty;
            ICacheServer cacheServer = null;

            try
            {
                object param = new GetCacheConfigurationParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                ccParam = (GetCacheConfigurationParam)param;

                if (ccParam.IsUsage)
                {
                    AssemblyUsage.PrintLogo(ccParam.IsLogo);
                    AssemblyUsage.PrintUsage();
                    return;
                }

                if (!ValidateParameters())
                {
                    return;
                }

                string _filename = null;
                string _path     = null;
                if (ccParam.Path != null && ccParam.Path != string.Empty)
                {
                    if (!Path.HasExtension(ccParam.Path))
                    {
                        _filename    = ccParam.CacheId + ".ncconf";
                        ccParam.Path = ccParam.Path + "\\" + _filename;
                    }
                }
                else
                {
                    ccParam.Path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
                    _filename    = ccParam.CacheId + ".ncconf";
                    ccParam.Path = ccParam.Path + "\\" + _filename;
                }

                if (ccParam.Port == -1)
                {
                    NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                }
                if (!string.IsNullOrEmpty(ccParam.Server))
                {
                    NCache.ServerName = ccParam.Server;
                }
                else
                {
                    NCache.ServerName = System.Environment.MachineName;
                }

                if (ccParam.Port != -1)
                {
                    NCache.Port = ccParam.Port;
                }

                cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                if (cacheServer != null)
                {
                    Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = cacheServer.GetNewConfiguration(ccParam.CacheId);

                    if (serverConfig == null)
                    {
                        throw new Exception("Specified cache is not registered on given server.");
                    }

                    serverConfig.CacheDeployment = null;

                    Console.WriteLine("Creating configuration for cache '{0}' registered on server '{1}:{2}'.", ccParam.CacheId, NCache.ServerName, NCache.Port);

                    StringBuilder xml = new StringBuilder();
                    List <Alachisoft.NCache.Config.NewDom.CacheServerConfig> configurations = new List <Alachisoft.NCache.Config.NewDom.CacheServerConfig>();
                    configurations.Add(serverConfig);
                    ConfigurationBuilder builder = new ConfigurationBuilder(configurations.ToArray());
                    builder.RegisterRootConfigurationObject(typeof(Alachisoft.NCache.Config.NewDom.CacheServerConfig));
                    xml.Append(builder.GetXmlString());
                    WriteXmlToFile(xml.ToString());

                    Console.WriteLine("Cache configuration saved successfully at " + ccParam.Path + ".");
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error : {0}", e.Message);
            }
            finally
            {
                NCache.Dispose();
                if (cacheServer != null)
                {
                    cacheServer.Dispose();
                }
            }
        }
Esempio n. 16
0
        /// <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);
            }
        }
Esempio n. 17
0
        /// <summary>
        /// The main entry point for the tool.
        /// </summary>
        static public void Run(string[] args)
        {
            NCache = new NCacheRPCService("");
            string cacheIp = string.Empty;

            try
            {
                object param = new StartCacheToolParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                cParam = (StartCacheToolParam)param;
                if (cParam.IsUsage)
                {
                    AssemblyUsage.PrintLogo(cParam.IsLogo);
                    AssemblyUsage.PrintUsage();
                    return;
                }

                if (!ApplyParameters(args))
                {
                    return;
                }
                ICacheServer      m      = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                CacheServerConfig config = null;
                cacheIp = m.GetClusterIP();
                if (m != null)
                {
                    foreach (string cache in s_cacheId)
                    {
                        try
                        {
                            config = m.GetCacheConfiguration((string)cache);
                            if (config != null && config.InProc)
                            {
                                throw new Exception("InProc caches cannot be started explicitly.");
                            }

                            Console.WriteLine("\nStarting cache '{0}' on server {1}:{2}.", cache, cacheIp, NCache.Port);
                            m.StartCache(cache, string.Empty);

                            Console.WriteLine("'{0}' successfully started on server {1}:{2}.\n", cache, cacheIp,
                                              NCache.Port);
                        }

                        catch (Exception e)
                        {
                            Console.Error.WriteLine("Failed to start '{0}' on server {1}.", cache,
                                                    cacheIp);
                            Console.Error.WriteLine();
                            Console.Error.WriteLine(e.ToString() + "\n");
                        }
                    }
                }
            }
            catch (ManagementException ex)
            {
                Console.Error.WriteLine("Error : {0}", "NCache service could not be contacted on server.");
                Console.Error.WriteLine();
                Console.Error.WriteLine(ex.ToString());
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error : {0}", e.Message);
                Console.Error.WriteLine();
                Console.Error.WriteLine(e.ToString());
            }
            finally
            {
                NCache.Dispose();
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Sets the application level parameters to those specified at the command line.
        /// </summary>
        /// <param name="args">array of command line parameters</param>


        /// <summary>
        /// The main entry point for the tool.
        /// </summary>
        static public void Run(string[] args)
        {
            object param = new ListCachesParam();

            CommandLineArgumentParser.CommandLineParser(ref param, args);
            cParam = (ListCachesParam)param;
            AssemblyUsage.PrintLogo(cParam.IsLogo);



            if (cParam.IsUsage)
            {
                AssemblyUsage.PrintUsage();
                return;
            }

            if (!cParam.Detail && string.IsNullOrEmpty(cParam.Server) && args.Length != 0 && cParam.Port == -1 && cParam.IsUsage)
            {
                AssemblyUsage.PrintUsage();
                return;
            }


            if (cParam.Port != -1)
            {
                NCache.Port = cParam.Port;
            }
            if (cParam.Server != null && !cParam.Server.Equals(""))
            {
                NCache.ServerName = cParam.Server;
            }

            string getBindIp = string.Empty;



            try
            {
                ICacheServer m = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                getBindIp = m.GetBindIP();
                Console.WriteLine("Listing registered caches on server {0}:{1}\n", getBindIp, NCache.Port);

                if (m != null)
                {
                    Alachisoft.NCache.Common.Monitoring.ConfiguredCacheInfo[] caches = m.GetAllConfiguredCaches();
                    Alachisoft.NCache.Common.Monitoring.ConfiguredCacheInfo[] partitionedReplicaCaches = m.GetConfiguredPartitionedReplicaCaches();// PartitionedReplicaCaches;

                    if (caches.Length > 0 || partitionedReplicaCaches.Length > 0)
                    {
                        if (!cParam.Detail)
                        {
                            Console.WriteLine("{0,-25} {1,-35} {2,-15}", "Cache-Name", "Scheme", "Status");
                            Console.WriteLine("{0,-25} {1,-35} {2,-15}", "----------", "------", "------");
                        }

                        if (caches.Length > 0)
                        {
                            for (int i = 0; i < caches.Length; i++)
                            {
                                Alachisoft.NCache.Common.Monitoring.ConfiguredCacheInfo cacheInfo = caches[i];
                                if (!cParam.Detail)
                                {
                                    PrintCacheInfo(m.GetCacheStatistics2(cacheInfo.CacheId), cacheInfo.CacheId, cacheInfo.IsRunning);
                                }
                                else
                                {
                                    PrintDetailedCacheInfo(m.GetCacheStatistics2(cacheInfo.CacheId), null, cParam.PrintConf, cParam.XmlSyntax, cacheInfo.IsRunning, cacheInfo.CacheId, cacheInfo.CachePropString);
                                }
                            }
                        }

                        if (partitionedReplicaCaches.Length > 0)
                        {
                            IEnumerator ide = partitionedReplicaCaches.GetEnumerator();
                            while (ide.MoveNext())
                            {
                                Hashtable cacheTbl = ide.Current as Hashtable;
                                if (cacheTbl != null)
                                {
                                    IDictionaryEnumerator e = cacheTbl.GetEnumerator();
                                    while (e.MoveNext())
                                    {
                                        string partId = e.Key as string;
                                        Cache  cache  = (Cache)e.Value;
                                        if (!detailed)
                                        {
                                            PrintCacheInfo(cache, partId);
                                        }
                                        else
                                        {
                                            PrintDetailedCacheInfo(cache, partId, printConf, xmlSyntax);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("There are no registered caches on {0}", NCache.ServerName);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error: {0}", e.Message);
                Console.Error.WriteLine();
                Console.Error.WriteLine(e.ToString());
            }
            finally
            {
                NCache.Dispose();
            }
        }
Esempio n. 19
0
        /// <summary>
        /// The main entry point for the tool.
        /// </summary>ju
        static public void Run(string[] args)
        {
            System.Reflection.Assembly           asm          = null;
            Alachisoft.NCache.Config.Dom.Class[] queryClasses = null;
            string failedNodes = string.Empty;
            bool   sucessful   = false;
            string serverName  = string.Empty;

            try
            {
                object param = new RemoveQueryIndexParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                cParam = (RemoveQueryIndexParam)param;
                if (cParam.IsUsage)
                {
                    AssemblyUsage.PrintLogo(cParam.IsLogo);
                    AssemblyUsage.PrintUsage();
                    return;
                }
                if (!ValidateParameters())
                {
                    return;
                }
                if (cParam.Port == -1)
                {
                    NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                }
                if (cParam.Server != null && cParam.Server != string.Empty)
                {
                    NCache.ServerName = cParam.Server;
                }
                if (cParam.Port != -1)
                {
                    NCache.Port = cParam.Port;
                }

                cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));


                if (cacheServer != null)
                {
                    Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = cacheServer.GetNewConfiguration(cParam.CacheId);
                    serverName = cacheServer.GetClusterIP();
                    if (cacheServer.IsRunning(cParam.CacheId))
                    {
                        throw new Exception(cParam.CacheId + " is Running on " + serverName + "Stop the cache first.");
                    }



                    if (serverConfig == null)
                    {
                        throw new Exception("Specified cache is not registered on given server.");
                    }


                    Console.WriteLine("Removing query indexes on node '{0}' from cache '{1}'.",
                                      serverName, cParam.CacheId);
                    if (serverConfig.CacheSettings.QueryIndices != null)
                    {
                        if (serverConfig.CacheSettings.QueryIndices.Classes != null)
                        {
                            queryClasses = serverConfig.CacheSettings.QueryIndices.Classes;
                        }
                        else
                        {
                            return;
                        }

                        if (queryClasses != null)
                        {
                            serverConfig.CacheSettings.QueryIndices.Classes = GetSourceClass(GetClass(queryClasses));
                            if (serverConfig.CacheSettings.QueryIndices.Classes != null)
                            {
                                for (int i = 0; i < serverConfig.CacheSettings.QueryIndices.Classes.Length; i++)
                                {
                                    if (serverConfig.CacheSettings.QueryIndices.Classes[i].AttributesTable.Count < 1)
                                    {
                                        serverConfig.CacheSettings.QueryIndices.Classes[i] = null;
                                    }
                                }
                                bool NoClasses = true;
                                foreach (Class cls in serverConfig.CacheSettings.QueryIndices.Classes)
                                {
                                    if (cls != null)
                                    {
                                        NoClasses = false;
                                        break;
                                    }
                                }
                                if (NoClasses)
                                {
                                    serverConfig.CacheSettings.QueryIndices = null;
                                }
                            }
                            else
                            {
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("No such Query Index class found. ");
                        return;
                    }
                    if (serverConfig.CacheSettings.CacheType == "clustered-cache")
                    {
                        foreach (Address node in serverConfig.CacheDeployment.Servers.GetAllConfiguredNodes())
                        {
                            NCache.ServerName = node.IpAddress.ToString();
                            try
                            {
                                cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                                if (cacheServer.IsRunning(cParam.CacheId))
                                {
                                    throw new Exception(cParam.CacheId + " is Running on " + serverName + "Stop the cache first.");
                                }
                                cacheServer.RegisterCache(cParam.CacheId, serverConfig, "", true, cParam.IsHotApply);
                            }
                            catch (Exception ex)
                            {
                                Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);
                                failedNodes = failedNodes + "/n" + node.IpAddress.ToString();
                                LogEvent(ex.Message);
                                sucessful = false;
                            }
                            finally
                            {
                                cacheServer.Dispose();
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            cacheServer.RegisterCache(cParam.CacheId, serverConfig, "", true, cParam.IsHotApply);
                        }
                        catch (Exception ex)
                        {
                            Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);
                            LogEvent(ex.Message);
                            sucessful = false;
                        }
                        finally
                        {
                            cacheServer.Dispose();
                        }
                    }
                }
                sucessful = true;
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Failed to Remove Query Index on node '{0}'. ", serverName);
                Console.Error.WriteLine("Error : {0}", e.Message);
                LogEvent(e.Message);
                sucessful = false;
            }
            finally
            {
                NCache.Dispose();
                if (sucessful && !cParam.IsUsage)
                {
                    Console.WriteLine("Query indexes successfully removed.");
                }
            }
        }
Esempio n. 20
0
        public void InitializeCommandLinePrameters(string[] args)
        {
            object parameters = this;

            CommandLineArgumentParser.CommandLineParser(ref parameters, args);
        }
Esempio n. 21
0
        /// <summary>
        /// Sets the application level parameters to those specified at the command line.
        /// </summary>
        /// <param name="args">array of command line parameters</param>


        /// <summary>
        /// The main entry point for the tool.
        /// </summary>
        static public void Run(string[] args)
        {
            object param = new ListCachesParam();

            CommandLineArgumentParser.CommandLineParser(ref param, args);
            cParam = (ListCachesParam)param;
            AssemblyUsage.PrintLogo(cParam.IsLogo);



            if (cParam.IsUsage)
            {
                AssemblyUsage.PrintUsage();
                return;
            }

            if (!cParam.Detail && string.IsNullOrEmpty(cParam.Server) && args.Length != 0 && cParam.Port == -1 && cParam.IsUsage)
            {
                AssemblyUsage.PrintUsage();
                return;
            }


            if (cParam.Port != -1)
            {
                NCache.Port = cParam.Port;
            }
            if (cParam.Server != null && !cParam.Server.Equals(""))
            {
                NCache.ServerName = cParam.Server;
            }

            string getBindIp = string.Empty;



            try
            {
                ICacheServer m = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                getBindIp = m.GetBindIP();
                Console.WriteLine("Listing registered caches on server {0}:{1}\n", getBindIp, NCache.Port);

                if (m != null)
                {
                    Alachisoft.NCache.Common.Monitoring.ConfiguredCacheInfo[] caches = m.GetAllConfiguredCaches();

                    if (caches.Length > 0)
                    {
                        if (!cParam.Detail)
                        {
                            Console.WriteLine("{0,-25} {1,-35} {2,-15}", "Cache-Name", "Scheme", "Status");
                            Console.WriteLine("{0,-25} {1,-35} {2,-15}", "----------", "------", "------");
                        }

                        if (caches.Length > 0)
                        {
                            for (int i = 0; i < caches.Length; i++)
                            {
                                Alachisoft.NCache.Common.Monitoring.ConfiguredCacheInfo cacheInfo = caches[i];
                                if (!cParam.Detail)
                                {
                                    PrintCacheInfo(cacheInfo.Topology.ToString(), cacheInfo.CacheId, cacheInfo.IsRunning, cacheInfo.ProcessID);
                                }
                                else
                                {
                                    PrintDetailedCacheInfo(m.GetCacheStatistics2(cacheInfo.CacheId), cacheInfo.Topology.ToString(), null, cacheInfo.IsRunning, cacheInfo.CacheId, cacheInfo.CachePropString, cacheInfo.ProcessID.ToString());
                                }
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("There are no registered caches on {0}", NCache.ServerName);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error: {0}", e.Message);
                Console.Error.WriteLine();
                Console.Error.WriteLine(e.ToString());
            }
            finally
            {
                NCache.Dispose();
            }
        }