public bool IsRunningCache(string server, int port, string cacheId) { ArrayList runningCaches = new ArrayList(); bool isRunning = false; 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) { isRunning = cacheServer.IsRunning(cacheId); } return(isRunning); }
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"); } } }
public bool IsRunningCache(string server, int port, string cacheId) { ArrayList runningCaches = new ArrayList(); bool isRunning = false; 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) { isRunning = cacheServer.IsRunning(cacheId); } return isRunning; }
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."); } } }
/// <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."); } } }
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); }
/// <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."); } } }
/// <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."); } } }
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"); } } }
/// <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."); } }