void StartCacheOnServer() { OutputProvider.WriteLine("Licensed to use FREE of cost. Use As-is without support.\n"); string cacheIp = string.Empty; try { ICacheServer cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); CacheServerConfig config = null; if (cacheServer != null) { cacheIp = cacheServer.GetClusterIP(); foreach (string cache in CachesList) { try { config = cacheServer.GetCacheConfiguration(cache); if (config != null && config.InProc) { throw new Exception("InProc caches cannot be started explicitly."); } OutputProvider.WriteLine("Starting cache '{0}' on server {1}:{2}.", cache, cacheIp, NCache.Port); cacheServer.StartCache(cache, _partId); OutputProvider.WriteLine("'{0}' successfully started on server {1}:{2}.\n", cache, cacheIp, NCache.Port); } catch (Exception e) { OutputProvider.WriteErrorLine("Failed to start '{0}' on server {1}.", cache, cacheIp); OutputProvider.WriteErrorLine(e.ToString() + "\n"); } } } } catch (ManagementException ex) { OutputProvider.WriteErrorLine("Error : {0}", "NCache service could not be contacted on server"); OutputProvider.WriteErrorLine(ex.ToString()); } catch (Exception e) { OutputProvider.WriteErrorLine("Error : {0}", e.Message); OutputProvider.WriteErrorLine(e.ToString()); } finally { NCache.Dispose(); } }
/// <summary> /// Constructor /// </summary> /// <param name="address"></param> /// <param name="port"></param> public CacheServiceClient(string address, int port) { _address = address; _port = port; Initialize(); _bindIpAddress = _server.GetBindIP(); _clusterIpAddress = _server.GetClusterIP(); }
/// <summary> /// Constructor /// </summary> /// <param name="address"></param> /// <param name="port"></param> public CacheServiceClient(string address, int port, Action <CredentialsEventArgs> getCredentialsAction) { _address = address; _port = port; _getCacheCredentials = getCredentialsAction; Initialize(); _bindIpAddress = _server.GetBindIP(); _clusterIpAddress = _server.GetClusterIP(); }
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"); } } }
/// <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(); } }
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); * * } * } * * } * */ }
public void StopCache() { try { if (!ValidateParameters()) { return; } ICacheServer m = null; try { m = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); } catch (Exception e) { OutputProvider.WriteErrorLine("Error: NCache service could not be contacted on server."); } string getBindIp = string.Empty; CacheServerConfig config = null; if (m != null) { foreach (string cache in CachesList) { try { config = m.GetCacheConfiguration(cache); if (config != null && config.InProc) { throw new Exception("InProc caches cannot be stopped explicitly."); } getBindIp = m.GetClusterIP(); OutputProvider.WriteLine("Stopping cache '{0}' on server {1}:{2}.", cache, getBindIp, NCache.Port); m.StopCache(cache, _partId); m.StopCache(cache, string.Empty); OutputProvider.WriteLine("'{0}' successfully stopped on server {1}:{2}.\n", cache, getBindIp, NCache.Port); } catch (System.Security.SecurityException e) { OutputProvider.WriteErrorLine("Failed to stop '{0}'. Error: {1} ", cache, e.Message); OutputProvider.WriteErrorLine(e.ToString()); OutputProvider.WriteLine(Environment.NewLine); } catch (Exception e) { OutputProvider.WriteErrorLine("Failed to stop '{0}'.", cache); OutputProvider.WriteErrorLine("Error: " + e.ToString()); OutputProvider.WriteLine(Environment.NewLine); } } } } catch (Exception e) { OutputProvider.WriteErrorLine("Error : {0}", e.Message); OutputProvider.WriteErrorLine(e.ToString()); OutputProvider.WriteLine(Environment.NewLine); } finally { NCache.Dispose(); } }
/// <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."); } } }
static public void Run(string[] args) { try { object param = new RemoveNodeParam(); CommandLineArgumentParser.CommandLineParser(ref param, args); cParam = (RemoveNodeParam)param; if (cParam.IsUsage) { AssemblyUsage.PrintLogo(cParam.IsLogo); AssemblyUsage.PrintUsage(); return; } if (!ValidateParameters()) { return; } if (cParam.Port != -1) { ncacheService.Port = cParam.Port; } if (cParam.Port == -1) { ncacheService.Port = ncacheService.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort; } if (cParam.Server != null || cParam.Server != string.Empty) { ncacheService.ServerName = cParam.Server; } else { cParam.Server = ncacheService.ServerName; } ICacheServer m = ncacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30)); if (m != null) { try { IPAddress address; if (!IPAddress.TryParse(ncacheService.ServerName, out address)) { string clusterIp = m.GetClusterIP(); if (clusterIp != null && clusterIp != string.Empty) { ncacheService.ServerName = clusterIp; } } CacheStatusOnServerContainer isClustered = m.IsClusteredCache(cParam.CacheId); CacheStatusOnServer result = isClustered.cacheStatus; if (result == CacheStatusOnServer.Unregistered) { throw new Exception("The requested cache is not registered on the specified server."); } else if (result == CacheStatusOnServer.LocalCache) { throw new Exception("RemoveNode Tool can be used with clustered caches only."); } Console.WriteLine("Removing '{0}' from the cache '{1}'.", ncacheService.ServerName.ToLower(), cParam.CacheId); NewCacheRegisterationInfo info = m.GetNewUpdatedCacheConfiguration(cParam.CacheId, null, ncacheService.ServerName, false); //.GetNewUpdatedCacheConfiguration(cParam.CacheId, null, NCache.ServerName, false); m.UnregisterCache(cParam.CacheId, string.Empty, true); foreach (string serverName in info.AffectedNodes) { ncacheService.ServerName = serverName; m = ncacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30)); m.RegisterCache(cParam.CacheId, info.UpdatedCacheConfig, null, true, false); } //Remove from client.ncconf Dictionary <string, Dictionary <int, Management.ClientConfiguration.Dom.CacheServer> > serversPriorityList = new Dictionary <string, Dictionary <int, Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer> >(); try { ArrayList clusterNodes = info.UpdatedCacheConfig.CacheDeployment.Servers.NodesList; ToolServerOperations.ClientConfigUtil _clientConfigUtil = new ToolServerOperations.ClientConfigUtil(); foreach (Alachisoft.NCache.Config.NewDom.ServerNode nodei in clusterNodes) { serversPriorityList.Add(nodei.IP, _clientConfigUtil.GetPrioritizedServerListForClient(nodei.IP, cParam.CacheId, clusterNodes)); } foreach (Alachisoft.NCache.Config.NewDom.ServerNode node in clusterNodes) { ncacheService.ServerName = node.IP; ICacheServer _cacheServer = ncacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30)); Management.ClientConfiguration.CacheServerList _cacheServerList = new Management.ClientConfiguration.CacheServerList(serversPriorityList[node.IP]); _cacheServer.UpdateClientServersList(cParam.CacheId, _cacheServerList, RtContextValue.NCACHE.ToString()); } serversPriorityList.Clear(); List <ClientNode> clusterClientNodes = info.UpdatedCacheConfig.CacheDeployment.ClientNodes.NodesList; foreach (Alachisoft.NCache.Config.Dom.ClientNode nodei in clusterClientNodes) { serversPriorityList.Add(nodei.Name, _clientConfigUtil.GetPrioritizedServerListForClient(nodei.Name, cParam.CacheId, clusterNodes)); } foreach (Alachisoft.NCache.Config.Dom.ClientNode node in clusterClientNodes) { ncacheService.ServerName = node.Name; ICacheServer _cacheServer = ncacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30)); Management.ClientConfiguration.CacheServerList _cacheServerList = new Management.ClientConfiguration.CacheServerList(serversPriorityList[node.Name]); _cacheServer.UpdateClientServersList(cParam.CacheId, _cacheServerList, node.RuntimeContextString); } } catch (Exception e) { } } catch (Exception e) { Console.Error.WriteLine("Failed to remove '{0}' from '{1}'. Error: {2} ", ncacheService.ServerName.ToLower(), cParam.CacheId, e.Message); } } } catch (Exception e) { Console.Error.WriteLine("Error : {0}", e.Message); } finally { if (ncacheService != null) { ncacheService.Dispose(); } } }
/// <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."); } } }
/// <summary> /// The main entry point for the tool. /// </summary> static public void Run(string[] args) { NCache = new NCacheRPCService(""); string cacheIp = string.Empty; try { object param = new StartCacheToolParam(); CommandLineArgumentParser.CommandLineParser(ref param, args); cParam = (StartCacheToolParam)param; if (cParam.IsUsage) { AssemblyUsage.PrintLogo(cParam.IsLogo); AssemblyUsage.PrintUsage(); return; } if (!ApplyParameters(args)) { return; } ICacheServer m = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); CacheServerConfig config = null; cacheIp = m.GetClusterIP(); if (m != null) { foreach (string cache in s_cacheId) { try { config = m.GetCacheConfiguration((string)cache); if (config != null && config.InProc) { throw new Exception("InProc caches cannot be started explicitly."); } Console.WriteLine("\nStarting cache '{0}' on server {1}:{2}.", cache, cacheIp, NCache.Port); m.StartCache(cache, string.Empty); Console.WriteLine("'{0}' successfully started on server {1}:{2}.\n", cache, cacheIp, NCache.Port); } catch (Exception e) { Console.Error.WriteLine("Failed to start '{0}' on server {1}.", cache, cacheIp); Console.Error.WriteLine(); Console.Error.WriteLine(e.ToString() + "\n"); } } } } catch (ManagementException ex) { Console.Error.WriteLine("Error : {0}", "NCache service could not be contacted on server."); Console.Error.WriteLine(); Console.Error.WriteLine(ex.ToString()); } catch (Exception e) { Console.Error.WriteLine("Error : {0}", e.Message); Console.Error.WriteLine(); Console.Error.WriteLine(e.ToString()); } finally { NCache.Dispose(); } }
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."); } }