예제 #1
0
        public static void StopCache(string cacheId, string serverName, bool isGracefulShutdown)
        {
            ICacheServer cs           = null;
            CacheService cacheService = new NCacheRPCService(null);

            try
            {
                cacheService.ServerName = serverName;
                cs = cacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                if (cs != null)
                {
                    cs.StopCache(cacheId);
                }
            }
            catch (Exception ex)
            {
                if (cs != null)
                {
                    cs.Dispose();
                    cs = null;
                }
                throw new ManagementException(ex.Message);
            }
            finally
            {
                if (cs != null)
                {
                    cs.Dispose();
                }
                cacheService.Dispose();
            }
        }
예제 #2
0
        public static void StartCache(string cacheId, string serverName, int port, string userId, string password)
        {
            ICacheServer cs = null;

            CacheService      cacheService = new NCacheRPCService(null);
            CacheServerConfig config       = null;

            try
            {
                cacheService.ServerName = serverName;
                cacheService.Port       = port;
                cs = cacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                if (cs != null)
                {
                    config = cs.GetCacheConfiguration(cacheId);
                    if (config != null)
                    {
                        if (!config.InProc)
                        {
                            cs.StartCache(cacheId);
                        }
                    }
                    else
                    {
                        throw new ManagementException("Unable to Start Cache. Specified cache is not registered.");
                    }
                }
            }

            catch (SecurityException ex)
            {
                if (cs != null)
                {
                    cs.Dispose();
                    cs = null;
                }
                throw ex;
            }

            catch (Exception ex)
            {
                if (cs != null)
                {
                    cs.Dispose();
                    cs = null;
                }
                throw new ManagementException(ex.Message);
            }
            finally
            {
                if (cs != null)
                {
                    cs.Dispose();
                }
                cacheService.Dispose();
            }
        }
예제 #3
0
        public static void StopCache(string cacheId)
        {
            ICacheServer      cs           = null;
            CacheService      cacheService = new NCacheRPCService(null);
            CacheServerConfig config       = null;

            try
            {
                cacheService.ServerName = Environment.MachineName;
                cs = cacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                if (cs != null)
                {
                    config = cs.GetCacheConfiguration(cacheId);
                    if (!config.InProc)
                    {
                        cs.StopCache(cacheId);
                    }
                    else
                    {
                        throw new ManagementException("Inproc caches cannot be stopped explicitly.");
                    }
                }
            }
            finally
            {
                if (cs != null)
                {
                    cs.Dispose();
                }
                cacheService.Dispose();
            }
        }
예제 #4
0
        public static void StartCache(string cacheId)
        {
            CacheService cacheService = new NCacheRPCService(null);
            ICacheServer cs           = null;

            try
            {
                cacheService.ServerName = Environment.MachineName;
                cs = cacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                if (cs != null)
                {
                    cs.StartCache(cacheId);
                }
            }


            catch (Exception ex)
            {
                throw new ManagementException(ex.Message);
            }
            finally
            {
                if (cs != null)
                {
                    cs.Dispose();
                }
                cacheService.Dispose();
            }
        }
예제 #5
0
        public void RegisterCache(Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig, int port, string cacheId, bool isHotApply, bool isOverwrite, string server)
        {
            if (port != -1)
            {
                NCache.Port = port;
            }

            if (port == -1)
            {
                NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
            }
            if (server != null && server != string.Empty)
            {
                NCache.ServerName = server;
            }

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

            if (cacheServer != null)
            {
                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));
                            cacheServer.RegisterCache(cacheId, serverConfig, "", isOverwrite, isHotApply);
                        }
                        catch (Exception ex)
                        {
                            Console.Error.WriteLine("Failed to Configure Backing Source on '{0}'. ", NCache.ServerName);
                            Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);
                        }
                        finally
                        {
                            cacheServer.Dispose();
                        }
                    }
                }
                else
                {
                    try
                    {
                        cacheServer.RegisterCache(cacheId, serverConfig, "", isOverwrite, isHotApply);
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine("Failed to Configure Backing Source on '{0}'. ", NCache.ServerName);
                        Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);
                    }
                    finally
                    {
                        cacheServer.Dispose();
                    }
                }
            }
        }
예제 #6
0
        public static void StopCache(string cacheId, string serverName, int port, string userId, string password)
        {
            ICacheServer cs = null;

            CacheService cacheService = new NCacheRPCService(null);

            try
            {
                cacheService.ServerName = serverName;
                cacheService.Port       = port;
                cs = cacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                if (cs != null)
                {
                    cs.StopCache(cacheId);
                }
            }

            catch (SecurityException ex)
            {
                if (cs != null)
                {
                    cs.Dispose();
                    cs = null;
                }
                throw ex;
            }


            catch (Exception ex)
            {
                if (cs != null)
                {
                    cs.Dispose();
                    cs = null;
                }
                throw new ManagementException(ex.Message);
            }
            finally
            {
                if (cs != null)
                {
                    cs.Dispose();
                }
                cacheService.Dispose();
            }
        }
예제 #7
0
        public static bool VerifyClusterConfigurations(Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig
                                                       , string cacheName)
        {
            if (serverConfig == null)
            {
                throw new Exception("Specified cache is not registered on the given server");
            }
            double           configVersion     = -1;
            double           deploymentVersion = -1;
            string           configId          = "dummyconfig";
            NCacheRPCService NCache            = new NCacheRPCService("");

            if (serverConfig.CacheSettings.CacheType == "clustered-cache")
            {
                foreach (Address node in serverConfig.CacheDeployment.Servers.GetAllConfiguredNodes())
                {
                    NCache.ServerName = node.IpAddress.ToString();

                    ICacheServer         cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                    ConfigurationVersion config      = cacheServer.GetConfigurationVersion(cacheName);
                    if (configId.Equals(configId))
                    {
                        configId = config.ConfigID;
                    }

                    else if (!configId.Equals(config.ConfigID, StringComparison.InvariantCultureIgnoreCase))
                    {
                        throw new VersionException("same name cache is already registered on node : " + node.IpAddress, 0);
                    }

                    if (configVersion == -1)
                    {
                        configVersion = config.ConfigVersion;
                    }
                    else if (configVersion != config.ConfigVersion)
                    {
                        throw new VersionException("There is a configuration mismatch for caches : " + cacheName, 0);
                    }

                    if (deploymentVersion == -1)
                    {
                        deploymentVersion = config.DeploymentVersion;
                    }
                    else if (deploymentVersion != config.DeploymentVersion)
                    {
                        throw new Exception("Deployment version is not same on all nodes");
                    }

                    cacheServer.Dispose();
                }
            }
            return(true);
        }
예제 #8
0
 private static void UpdateServerMappings(MappingConfiguration.Dom.MappingConfiguration mappingConfiguration, string[] nodes)
 {
     if (nodes != null && mappingConfiguration != null)
     {
         foreach (string node in nodes)
         {
             try
             {
                 NCacheRPCService NCache      = new NCacheRPCService(node);
                 ICacheServer     cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                 cacheServer.UpdateServerMappingConfig(mappingConfiguration);
                 cacheServer.Dispose();
             }
             catch (Exception ex)
             {
             }
         }
     }
 }
예제 #9
0
        private static MappingConfiguration.Dom.MappingConfiguration GetServerMappings(string[] nodes)
        {
            if (nodes != null)
            {
                List <Mapping> managementIPMapping = new List <Mapping>();
                List <Mapping> clientIPMapping     = new List <Mapping>();
                foreach (string node in nodes)
                {
                    try
                    {
                        NCacheRPCService NCache      = new NCacheRPCService(node);
                        ICacheServer     cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                        Hashtable serverIPMapping = cacheServer.GetServerMappingForConfig();
                        if (serverIPMapping.Contains("management-ip-mapping"))
                        {
                            managementIPMapping.Add((Mapping)serverIPMapping["management-ip-mapping"]);
                        }
                        if (serverIPMapping.Contains("client-ip-mapping"))
                        {
                            clientIPMapping.Add((Mapping)serverIPMapping["client-ip-mapping"]);
                        }
                        cacheServer.Dispose();
                    }
                    catch (Exception ex)
                    {
                    }
                }
                if (managementIPMapping.Count == 0 && clientIPMapping.Count == 0)
                {
                    return(null);
                }
                MappingConfiguration.Dom.MappingConfiguration mappingConfiguration = new MappingConfiguration.Dom.MappingConfiguration();
                mappingConfiguration.ManagementIPMapping = new ServerMapping(managementIPMapping.ToArray());
                mappingConfiguration.ClientIPMapping     = new ServerMapping(clientIPMapping.ToArray());

                return(mappingConfiguration);
            }
            return(null);
        }
예제 #10
0
        private static CacheServerConfig GetCacheConfigThroughClientConfig(string cacheName, int port, Runtime.CacheManagement.CacheContext context)
        {
            CacheServerConfig cacheServerConfig = null;

            ClientConfiguration.Dom.CacheServer[] serverNodes = null;
            ICacheServer cacheServer = null;

            CacheService cacheService = GetCacheService(context);

            if (port != 0)
            {
                cacheService.Port = port;
            }

            try
            {
                //Get Server Info from Client.nconf for specified cacheName
                ClientConfiguration.Dom.ClientConfiguration clientConfiguration = ClientConfiguration.ClientConfigManager.GetClientConfiguration(cacheName);
                if (clientConfiguration != null)
                {
                    Dictionary <string, CacheConfiguration> cacheConfigurationMap = clientConfiguration.CacheConfigurationsMap;
                    CacheConfiguration cacheClientConfiguration = null;

                    try
                    {
                        cacheClientConfiguration = cacheConfigurationMap[cacheName];
                    }
                    catch (System.Collections.Generic.KeyNotFoundException ex)
                    {
                    }

                    if (cacheClientConfiguration == null)
                    {
                        throw new ManagementException("cache not found in " + config);
                    }

                    serverNodes = cacheClientConfiguration.Servers;

                    foreach (ClientConfiguration.Dom.CacheServer node in serverNodes)
                    {
                        try
                        {
                            cacheService.ServerName = node.ServerName;
                            cacheServer             = cacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                            if (cacheServer != null)
                            {
                                cacheServerConfig = cacheServer.GetCacheConfiguration(cacheName);
                                //dispose the server
                                cacheServer.Dispose();
                                cacheServer = null;

                                if (cacheServerConfig != null)
                                {
                                    break;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
                else
                {
                    throw new ManagementException("error while fetching info from " + config);
                }
            }
            finally
            {
                if (cacheServer != null)
                {
                    cacheServer.Dispose();
                }
                if (cacheService != null)
                {
                    cacheService.Dispose();
                }
            }
            return(cacheServerConfig);
        }
예제 #11
0
        public void GetCacheConfiguration()
        {
            string       failedNodes = string.Empty;
            ICacheServer cacheServer = null;

            try
            {
                if (!ValidateParameters())
                {
                    return;
                }

                string _filename = null;
                string _path     = null;
                if (Path != null && Path != string.Empty)
                {
                    if (!System.IO.Path.HasExtension(Path))
                    {
                        _filename = Name + ".ncconf";
                        Path      = Path + System.IO.Path.DirectorySeparatorChar + _filename;
                    }
                }
                else
                {
                    //Path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                    Path      = System.IO.Path.Combine(AppUtil.InstallDir, @"bin" + System.IO.Path.DirectorySeparatorChar + "tools");
                    _filename = Name + ".ncconf";
                    Path      = Path + System.IO.Path.DirectorySeparatorChar + _filename;
                }

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

                if (Port != -1)
                {
                    NCache.Port = Port;
                }
                try
                {
                    cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                }
                catch (Exception e)
                {
                    OutputProvider.WriteErrorLine("Error: NCache service could not be contacted on server.");
                    return;
                }

                if (cacheServer != null)
                {
                    Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = cacheServer.GetNewConfiguration(Name);
                    if (serverConfig == null)
                    {
                        throw new Exception("Specified cache is not registered on the given server.");
                    }
                    serverConfig.CacheDeployment = null;
                    OutputProvider.WriteLine("Creating configuration for cache '{0}' registered on server '{1}:{2}'.", Name, 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());
                    OutputProvider.WriteLine("Cache configuration saved successfully at " + Path + ".");
                }
            }
            catch (Exception e)
            {
                OutputProvider.WriteErrorLine("Error : {0}", e.Message);
            }
            finally
            {
                NCache.Dispose();
                if (cacheServer != null)
                {
                    cacheServer.Dispose();
                }
            }
        }
예제 #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();
            }
        }
예제 #13
0
        public void RegisterCache(Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig, int port, string cacheId, bool isHotApply, bool isOverwrite, string server)
        {
            if (port != -1)
            {
                NCache.Port = port;
            }

            if (port == -1) NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
            if (server != null && server != string.Empty)
            {
                NCache.ServerName = server;
            }

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

            if (cacheServer != null)
            {

                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));
                            cacheServer.RegisterCache(cacheId, serverConfig, "", isOverwrite, isHotApply);
                        }
                        catch (Exception ex)
                        {
                            Console.Error.WriteLine("Failed to Configure Backing Source on '{0}'. ", NCache.ServerName);
                            Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);

                        }
                        finally
                        {
                            cacheServer.Dispose();
                        }
                    }
                }
                else
                {
                    try
                    {
                        cacheServer.RegisterCache(cacheId, serverConfig, "", isOverwrite, isHotApply);
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine("Failed to Configure Backing Source on '{0}'. ", NCache.ServerName);
                        Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);

                    }
                    finally
                    {
                        cacheServer.Dispose();
                    }
                }
            }
        }
예제 #14
0
파일: Main.cs 프로젝트: rvrn22/NCache
        /// <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();
            }
        }
예제 #15
0
        private void ConveyToRegisteredNodes()
        {
            byte[] userId = null;
            byte[] paswd  = null;
            if (UserId != string.Empty && Password != string.Empty)
            {
                userId = EncryptionUtil.Encrypt(UserId);
                paswd  = EncryptionUtil.Encrypt(Password);
            }


            string pId = "";
            NewCacheRegisterationInfo info = cacheServer.GetNewUpdatedCacheConfiguration(CacheName.ToLower(), pId, CacheServer, true);
            // Now update the cache configurations on all the servers where the cache
            //is registered...
            IPAddress address;
            string    clusterIp;
            bool      reregister = false;

            config.ConfigVersion++;
            foreach (string serverName in info.AffectedNodes)
            {
                if (info.AffectedPartitions.Count > 0)
                {
                    foreach (string partId in info.AffectedPartitions)
                    {
                        try
                        {
                            NCache            = new NCacheRPCService(serverName);
                            NCache.ServerName = serverName;
                            if (!IPAddress.TryParse(NCache.ServerName, out address))
                            {
                                clusterIp = cacheServer.GetClusterIP();
                                if (clusterIp != null && clusterIp != string.Empty)
                                {
                                    NCache.ServerName = clusterIp;
                                }
                            }
                            reregister  = true;
                            cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                            cacheServer.ConfigureBridgeToCache(config, userId, paswd, true);
                            cacheServer.HotApplyBridgeReplicator(CacheName, false);
                        }
                        catch (Exception ex)
                        {
                            OutputProvider.WriteErrorLine("Failed to Create Cache on '{0}'. ", NCache.ServerName);
                            OutputProvider.WriteErrorLine("Error Detail: '{0}'. ", ex.Message);
                        }
                        finally
                        {
                            cacheServer.Dispose();
                        }
                    }
                }
                else
                {
                    try
                    {
                        NCache.ServerName = serverName;
                        if (!IPAddress.TryParse(NCache.ServerName, out address))
                        {
                            clusterIp = cacheServer.GetClusterIP();
                            if (clusterIp != null && clusterIp != string.Empty)
                            {
                                NCache.ServerName = clusterIp;
                            }
                        }
                        reregister  = true;
                        cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                        cacheServer.ConfigureBridgeToCache(config, userId, paswd, true);
                        cacheServer.HotApplyBridgeReplicator(CacheName, false);
                    }
                    catch (Exception ex)
                    {
                        OutputProvider.WriteErrorLine("Failed to Create Cache on '{0}'. ", NCache.ServerName);
                        OutputProvider.WriteErrorLine("Error Detail: '{0}'. ", ex.Message);


                        NCache.Dispose();
                        return;
                    }
                    finally
                    {
                        cacheServer.Dispose();
                    }
                }
            }

            /*
             *
             * byte[] userId = null;
             * byte[] paswd = null;
             * if (UserId != string.Empty && Password != string.Empty)
             * {
             *  userId = EncryptionUtil.Encrypt(UserId);
             *  paswd = EncryptionUtil.Encrypt(Password);
             * }
             * Alachisoft.NCache.Bridging.Configuration.BridgeConfiguration bridgeConfig = _bridgeServer.GetBridgeConfiguration(BridgeId);
             * List<TargetCacheCofiguration> previouslyAddedCaches = bridgeConfig.TargetCacheConfigList;
             * char[] separater = { ',' };
             * foreach (TargetCacheCofiguration pCache in previouslyAddedCaches)
             * {
             *  if (pCache.CacheID.ToLower().Equals(CacheId.ToLower()))
             *  {
             *      //if exists than remove
             *      foreach (string server in pCache.Servers.Split(separater).ToList())
             *      {
             *          NCacheRPCService nNCache = new NCacheRPCService(server);
             *          cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
             *          cacheServer.ConfigureBridgeToCache(config, userId, paswd, true);
             *          cacheServer.HotApplyBridgeReplicator(CacheId, false);
             *
             *      }
             *  }
             *
             * }
             * */
        }
예제 #16
0
파일: Program.cs 프로젝트: rvrn22/NCache
        /// <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.");
                }
            }
        }
        private void AddLuceneQueryIndexDefaults()
        {
            if (!ValidateParameters())
            {
                return;
            }
            bool        successful = true;
            AssemblyDef asm        = null;

            //ArrayList cc = new ArrayList();
            Alachisoft.NCache.Config.Dom.Class[] queryClasses = null;
            string failedNodes = string.Empty;
            string serverName  = string.Empty;

            try
            {
                if (Port == -1)
                {
                    NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                }
                if (Server != null && Server != string.Empty)
                {
                    NCache.ServerName = Server;
                }
                if (Port != -1)
                {
                    NCache.Port = Port;
                }
                try
                {
                    cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                }
                catch (Exception e)
                {
                    OutputProvider.WriteErrorLine("Error: NCache service could not be contacted on server.");
                    return;
                }

                ToolsUtil.VerifyClusterConfigurations(cacheServer.GetNewConfiguration(CacheName), CacheName);


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

                    serverConfig = cacheServer.GetNewConfiguration(CacheName);
                    //ConfiguredCacheInfo[] configuredCaches = cacheServer.GetAllConfiguredCaches();

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

                    //if (! Unregister)
                    //{
                    try
                    {
                        asm = AssemblyDef.LoadFrom(AssemblyPath);

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

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

                    TypeDef type = asm.GetType(Class);


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


                    byte[] userId = null;
                    byte[] paswd  = null;
                    if (UserId != string.Empty && Password != string.Empty)
                    {
                        userId = EncryptionUtil.Encrypt(UserId);
                        paswd  = EncryptionUtil.Encrypt(Password);
                    }
                    serverConfig.ConfigVersion++;
                    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(CacheName))
                                {
                                    throw new Exception(CacheName + " is Running on " + serverName +
                                                        "\nStop the cache first and try again.");
                                }

                                OutputProvider.WriteLine("Adding query indexes on node '{0}' to cache '{1}'.", node.IpAddress, CacheName);
                                cacheServer.RegisterCache(CacheName, serverConfig, "", true, userId, paswd, false);
                            }
                            catch (Exception ex)
                            {
                                OutputProvider.WriteErrorLine("Failed to Add Query Index on '{0}'. ", serverName);
                                OutputProvider.WriteErrorLine("Error Detail: '{0}'. ", ex.Message);
                                failedNodes = failedNodes + "/n" + node.IpAddress.ToString();
                                successful  = false;
                            }
                            finally
                            {
                                cacheServer.Dispose();
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            OutputProvider.WriteLine("Adding query indexes on node '{0}' to cache '{1}'.", serverName, CacheName);
                            cacheServer.RegisterCache(CacheName, serverConfig, "", true, userId, paswd, false);
                        }
                        catch (Exception ex)
                        {
                            OutputProvider.WriteErrorLine("Failed to Add Query Index on '{0}'. ", serverName);
                            OutputProvider.WriteErrorLine("Error Detail: '{0}'. ", ex.Message);
                            successful = false;
                        }
                        finally
                        {
                            cacheServer.Dispose();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                OutputProvider.WriteErrorLine("Error : {0}", e.Message);
                successful = false;
            }
            finally
            {
                NCache.Dispose();
                if (successful && !IsUsage)
                {
                    OutputProvider.WriteLine("Query indexes successfully added.");
                }
            }
        }
예제 #18
0
        public static Dictionary <string, TopicStats> GetTopicStat(string cacheName, string initialNodeName, Runtime.CacheManagement.CacheContext context, int port)
        {
            CacheService cacheService = GetCacheService(context);

            if (port != 0)
            {
                cacheService.Port = port;
            }
            string            startingNode      = initialNodeName;
            CacheServerConfig cacheServerConfig = null;
            ICacheServer      cacheServer       = null;



            try
            {
                if (initialNodeName.Equals(string.Empty))
                {
                    cacheServerConfig = GetCacheConfigThroughClientConfig(cacheName, port, context);
                    if (cacheServerConfig == null)
                    {
                        throw new ManagementException("cache with name " + cacheName + " not found in " + config);
                    }
                }
                else
                {
                    cacheService.ServerName = initialNodeName;
                    cacheServer             = cacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                    if (cacheServer == null)
                    {
                        throw new ManagementException("provided initial node not available");
                    }

                    cacheServerConfig = cacheServer.GetCacheConfiguration(cacheName);
                    if (cacheServerConfig == null)
                    {
                        throw new ManagementException("cache with name " + cacheName + " not registered on specified node");
                    }
                }

                //For Local Cache
                if (cacheServerConfig.CacheType.Equals(LOCALCACHE, StringComparison.OrdinalIgnoreCase))
                {
                    if (cacheServerConfig.InProc)
                    {
                        throw new ArgumentException("API is not supported for Local Inproc Cache");
                    }

                    cacheService.ServerName = Environment.MachineName;
                    cacheServer             = cacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                    if (cacheServer != null && cacheServer.IsRunning(cacheName))
                    {
                        return(cacheServer.GetTopicStats(cacheServerConfig.Name));
                    }
                }
                //For Clustered Cache
                else
                {
                    Dictionary <string, TopicStats> topicWiseStat = new Dictionary <string, TopicStats>();
                    ArrayList initialHost = InitialHostList(cacheServerConfig.Cluster.Channel.InitialHosts);
                    foreach (object host in initialHost)
                    {
                        try
                        {
                            cacheService.ServerName = (string)host;
                            cacheServer             = cacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                            if (cacheServer.IsRunning(cacheName))
                            {
                                Dictionary <string, TopicStats> NodeWisetopicStat = cacheServer.GetTopicStats(cacheServerConfig.Name);
                                if (NodeWisetopicStat != null)
                                {
                                    foreach (var item in NodeWisetopicStat)
                                    {
                                        if (!topicWiseStat.ContainsKey(item.Key))
                                        {
                                            item.Value.TopicName = item.Key;
                                            topicWiseStat.Add(item.Key, ((TopicStats)item.Value.Clone()));
                                        }
                                        else
                                        {
                                            TopicStats topicStat = topicWiseStat[item.Key];
                                            topicStat.CurrentMessageCount += item.Value.CurrentMessageCount;
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                        }
                    }
                    return(topicWiseStat);
                }
            }
            catch (Exception ex)
            {
                throw new ManagementException(ex.Message);
            }
            finally
            {
                if (cacheServer != null)
                {
                    cacheServer.Dispose();
                }
                cacheService.Dispose();
            }
            return(null);
        }
예제 #19
0
파일: Main.cs 프로젝트: rvrn22/NCache
        /// <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();
            }
        }
예제 #20
0
        /// <summary>
        /// The main entry point for the tool.
        /// </summary>ju
        public static 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.");
            }
        }
예제 #21
0
        private void AddLuceneStopWords()
        {
            if (!ValidateParameters())
            {
                return;
            }

            System.IO.FileInfo fInfo = null;
            Alachisoft.NCache.Config.Dom.LuceneDeployment[] prov = null;
            string       failedNodes = string.Empty;
            string       serverName  = string.Empty;
            ICacheServer cacheServer = null;
            bool         successFull = true;

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

                if (Port == -1)
                {
                    NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                }
                if (Server != null && Server != string.Empty)
                {
                    NCache.ServerName = Server;
                }

                try
                {
                    cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                }
                catch (Exception e)
                {
                    successFull = false;
                    OutputProvider.WriteErrorLine("Error: NCache service could not be contacted on server.");
                    return;
                }

                if (cacheServer != null)
                {
                    serverName = cacheServer.GetClusterIP();
                    if (cacheServer.IsRunning(CacheName))
                    {
                        successFull = false;
                        throw new Exception(CacheName + " is Running on " + cacheServer.GetClusterIP() + "\nStop the cache first and try again.");
                    }
                    Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = cacheServer.GetNewConfiguration(CacheName);


                    if (serverConfig == null)
                    {
                        successFull = false;
                        throw new Exception("Specified cache is not registered on the given server.");
                    }
                    ToolsUtil.VerifyClusterConfigurations(serverConfig, CacheName);
                    try
                    {
                        fInfo = new System.IO.FileInfo(FilePath);
                    }
                    catch (Exception e)
                    {
                        successFull = false;
                        string message = string.Format("Could not load file \"" + FilePath + "\". {0}", e.Message);
                        OutputProvider.WriteErrorLine("Error: {0}", message);
                        return;
                    }

                    if (serverConfig.CacheSettings.LuceneSettings == null)
                    {
                        serverConfig.CacheSettings.LuceneSettings = new Alachisoft.NCache.Config.Dom.LuceneSettings();
                    }

                    if (fInfo.Extension != ".txt")
                    {
                        successFull = false;
                        string message = string.Format("\"" + FilePath + "\" is not a Text file. {0}");
                        OutputProvider.WriteErrorLine("Error: {0}", message);
                        return;
                    }

                    if (serverConfig.CacheSettings.LuceneSettings.StopWordFiles == null)
                    {
                        serverConfig.CacheSettings.LuceneSettings.StopWordFiles = new StopWords();
                    }

                    if (serverConfig.CacheSettings.LuceneSettings.StopWordFiles.Providers != null)
                    {
                        prov = serverConfig.CacheSettings.LuceneSettings.StopWordFiles.Providers;
                    }

                    serverConfig.CacheSettings.LuceneSettings.StopWordFiles.Providers = GetStopWords(GetProvider(prov, fInfo));

                    byte[] userId = null;
                    byte[] paswd  = null;
                    if (UserId != string.Empty && Password != string.Empty)
                    {
                        userId = EncryptionUtil.Encrypt(UserId);
                        paswd  = EncryptionUtil.Encrypt(Password);
                    }
                    serverConfig.ConfigVersion++;
                    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(CacheName))
                                {
                                    throw new Exception(CacheName + " is Running on " + serverName +
                                                        "\nStop the cache first and try again.");
                                }

                                OutputProvider.WriteLine("Adding Lucene Stop Words file on node '{0}' to cache '{1}'.", node.IpAddress, CacheName);
                                cacheServer.RegisterCache(CacheName, serverConfig, "", true, userId, paswd, false);
                            }
                            catch (Exception ex)
                            {
                                OutputProvider.WriteErrorLine("Failed to Add Lucene Stop Words file on '{0}'. ", serverName);
                                OutputProvider.WriteErrorLine("Error Detail: '{0}'. ", ex.Message);
                                failedNodes = failedNodes + "/n" + node.IpAddress.ToString();
                                successFull = false;
                            }
                            finally
                            {
                                cacheServer.Dispose();
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            OutputProvider.WriteLine("Adding Lucene Stop Words file on node '{0}' to cache '{1}'.", serverName, CacheName);
                            cacheServer.RegisterCache(CacheName, serverConfig, "", true, userId, paswd, false);
                        }
                        catch (Exception ex)
                        {
                            OutputProvider.WriteErrorLine("Failed to Add Lucene Stop Words file on '{0}'. ", serverName);
                            OutputProvider.WriteErrorLine("Error Detail: '{0}'. ", ex.Message);
                            successFull = false;
                        }
                        finally
                        {
                            NCache.Dispose();
                            if (successFull && !IsUsage)
                            {
                                OutputProvider.WriteLine("Stop words file successfully added");
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                successFull = false;
                throw;
            }
            finally
            {
                NCache.Dispose();
                if (successFull && !IsUsage)
                {
                    OutputProvider.WriteLine("Stop words file successfully added");
                }
            }
        }
예제 #22
0
        /// <summary>
        /// The main entry point for the tool.
        /// </summary>ju
        public static 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.");
                }
            }
        }
예제 #23
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.");
                }
            }
        }
예제 #24
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();
                }
            }
        }
예제 #25
0
        private void AddLuceneAnalyzer()
        {
            if (!ValidateParameters())
            {
                return;
            }

            System.Reflection.Assembly asm = null;
            Alachisoft.NCache.Config.Dom.LuceneDeployment[] prov = null;
            string       failedNodes = string.Empty;
            string       serverName  = string.Empty;
            ICacheServer cacheServer = null;
            bool         successFull = true;

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

                if (Port == -1)
                {
                    NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                }
                if (Server != null && Server != string.Empty)
                {
                    NCache.ServerName = Server;
                }

                try
                {
                    cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                }
                catch (Exception e)
                {
                    successFull = false;
                    OutputProvider.WriteErrorLine("Error: NCache service could not be contacted on server.");
                    return;
                }

                if (cacheServer != null)
                {
                    serverName = cacheServer.GetClusterIP();
                    if (cacheServer.IsRunning(CacheName))
                    {
                        successFull = false;
                        throw new Exception(CacheName + " is Running on " + cacheServer.GetClusterIP() + "\nStop the cache first and try again.");
                    }
                    Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = cacheServer.GetNewConfiguration(CacheName);


                    if (serverConfig == null)
                    {
                        successFull = false;
                        throw new Exception("Specified cache is not registered on the given server.");
                    }
                    ToolsUtil.VerifyClusterConfigurations(serverConfig, CacheName);
                    try
                    {
                        asm = System.Reflection.Assembly.LoadFrom(AssemblyPath);
                    }
                    catch (Exception e)
                    {
                        successFull = false;
                        string message = string.Format("Could not load assembly \"" + AssemblyPath + "\". {0}", e.Message);
                        OutputProvider.WriteErrorLine("Error: {0}", message);
                        return;
                    }

                    if (asm == null)
                    {
                        successFull = false;
                        throw new Exception("Could not load specified assembly.");
                    }

                    if (serverConfig.CacheSettings.LuceneSettings == null)
                    {
                        serverConfig.CacheSettings.LuceneSettings = new Alachisoft.NCache.Config.Dom.LuceneSettings();
                    }

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

                    if (!type.IsSubclassOf(typeof(Analyzer)))
                    {
                        successFull = false;
                        OutputProvider.WriteErrorLine("Error: Specified class does not implement Analyzer.");
                        return;
                    }
                    else
                    {
                        if (serverConfig.CacheSettings.LuceneSettings.Analyzers == null)
                        {
                            serverConfig.CacheSettings.LuceneSettings.Analyzers           = new Analyzers();
                            serverConfig.CacheSettings.LuceneSettings.Analyzers.Providers = prov;
                        }
                        prov = serverConfig.CacheSettings.LuceneSettings.Analyzers.Providers;
                        serverConfig.CacheSettings.LuceneSettings.Analyzers.Providers = GetAnalyzers(GetProvider(prov, asm));
                    }

                    byte[] userId = null;
                    byte[] paswd  = null;
                    if (UserId != string.Empty && Password != string.Empty)
                    {
                        userId = EncryptionUtil.Encrypt(UserId);
                        paswd  = EncryptionUtil.Encrypt(Password);
                    }
                    serverConfig.ConfigVersion++;
                    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(CacheName))
                                {
                                    throw new Exception(CacheName + " is Running on " + serverName +
                                                        "\nStop the cache first and try again.");
                                }

                                OutputProvider.WriteLine("Adding Analyzer on node '{0}' to cache '{1}'.", node.IpAddress, CacheName);
                                cacheServer.RegisterCache(CacheName, serverConfig, "", true, userId, paswd, false);
                            }
                            catch (Exception ex)
                            {
                                OutputProvider.WriteErrorLine("Failed to Lucene Analyzer on node '{0}'. ", serverName);
                                OutputProvider.WriteErrorLine("Error Detail: '{0}'. ", ex.Message);
                                failedNodes = failedNodes + "/n" + node.IpAddress.ToString();
                                successFull = false;
                            }
                            finally
                            {
                                cacheServer.Dispose();
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            OutputProvider.WriteLine("Adding Analyzer on node '{0}' to cache '{1}'.", serverName, CacheName);
                            cacheServer.RegisterCache(CacheName, serverConfig, "", true, userId, paswd, false);
                        }
                        catch (Exception ex)
                        {
                            OutputProvider.WriteErrorLine("Failed to Lucene Analyzer on node '{0}'. ", serverName);
                            OutputProvider.WriteErrorLine("Error Detail: '{0}'. ", ex.Message);
                            successFull = false;
                        }
                        finally
                        {
                            NCache.Dispose();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                successFull = false;
                OutputProvider.WriteErrorLine("Failed to Lucene Analyzer on node '{0}'. ", NCache.ServerName);
                OutputProvider.WriteErrorLine("Error : {0}", e.Message);
            }
            finally
            {
                NCache.Dispose();
                if (successFull && !IsUsage)
                {
                    OutputProvider.WriteLine("Analyzer successfully added");
                }
            }
        }
예제 #26
0
파일: Main.cs 프로젝트: javithalion/NCache
        public static void Run(string[] args)
        {
            try
            {
                object param = new RemoveCacheParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                cParam = (RemoveCacheParam)param;
                if (cParam.IsUsage)
                {
                    AssemblyUsage.PrintLogo(cParam.IsLogo);
                    AssemblyUsage.PrintUsage();
                    return;
                }

                if (!ValidateParameters()) return;

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

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

                if (cParam.Server != null || cParam.Server != string.Empty)
                {
                    NCache.ServerName = cParam.Server;
                }

                cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                Console.WriteLine("\nRemoving cache '{0}' on server {1}:{2}.", cParam.CacheId,
                                            cacheServer.GetBindIP(), NCache.Port);
                if (cacheServer != null)
                {
                    string getBindIp = string.Empty;
                    try
                    {

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

                        if (serverConfig == null)
                        {
                            throw new Exception("Specified cache does not exist.");
                        }
                        if (serverConfig.CacheSettings.CacheType == "clustered-cache")
                        {

                            foreach (Address node in serverConfig.CacheDeployment.Servers.GetAllConfiguredNodes())
                            {
                                try
                                {
                                    NCache.ServerName = node.IpAddress.ToString();
                                    cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                                    cacheServer.UnregisterCache(cParam.CacheId, null, false);
                                    Console.WriteLine("Cache '{0}' successfully removed from server {1}:{2}.\n",
                                        cParam.CacheId, NCache.ServerName, NCache.Port);
                                }
                                catch (Exception ex)
                                {
                                    Console.Error.WriteLine("Error: Failed to Rmove Cache '{0}' from server '{1}:{2}'. ",
                                        cParam.CacheId, NCache.ServerName, NCache.Port);
                                    Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);

                                    LogEvent(ex.Message);
                                }
                                finally
                                {
                                    cacheServer.Dispose();
                                }
                            }
                        }
                        else
                        {
                            try
                            {
                                getBindIp = cacheServer.GetBindIP();
                                cacheServer.UnregisterCache(cParam.CacheId, null, false);
                                Console.WriteLine("Cache '{0}' successfully removed from server {1}:{2}.\n",
                                            cParam.CacheId, getBindIp, NCache.Port);
                            }
                            catch (Exception e)
                            {
                                throw e;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine("Error: Failed to Rmove Cache '{0}' from server '{1}:{2}'. ",
                                   cParam.CacheId, cacheServer.GetBindIP(), NCache.Port);
                        Console.Error.WriteLine(ex.Message);
                        LogEvent(ex.Message);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error: {0}", e.Message);
                Console.Error.WriteLine();
                Console.Error.WriteLine(e.ToString());
            }
            finally
            {
                NCache.Dispose();
            }
        }