public bool ValidateParameters() { try { if (CacheName == String.Empty || CacheName == null) { OutputProvider.WriteErrorLine("Error: Cache name not specified."); return(false); } } catch (Exception ex) { OutputProvider.WriteLine("Exception occured while parsing input parameters. Please verify all given parameters are in correct format."); OutputProvider.WriteLine(ex.Message); return(false); } ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); return(true); }
public bool ValidateParameters() { //validate BridgeID if (string.IsNullOrEmpty(BridgeId)) { OutputProvider.WriteErrorLine("Error: BridgeID not specified."); return(false); } //validate Active Node if (string.IsNullOrEmpty(ActiveNode)) { OutputProvider.WriteErrorLine("Error: Bridge Active Node not specified."); return(false); } ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); return(true); }
/// <summary> /// Validate all parameters in property string. /// </summary> public bool ValidateParameters() { if (string.IsNullOrEmpty(Class)) { OutputProvider.WriteErrorLine("\nError: Class name not specified."); return(false); } if (string.IsNullOrEmpty(AssemblyPath)) { OutputProvider.WriteErrorLine("\nError: Assembly path not specified."); return(false); } if (!OutputFile.Equals(string.Empty) && !(Path.GetExtension(OutputFile).Equals(".txt") || Path.GetExtension(OutputFile).Equals(".xml"))) { OutputProvider.WriteErrorLine("\nError: Extension for the file specified is not valid."); return(false); } ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); return(true); }
public void TestLaunchTool() { Mount mount = new Mount() { AppId = 440000, IsRequired = true }; Assume.That(mount.MountPath, Is.Not.Null.Or.Empty); Process process = null; Assert.That(() => { process = ToolsUtil.LaunchTool(mount.BinDirectory, "hammer"); Assert.That(process.HasExited, Is.False); }, Throws.Nothing); process.Kill(true); Assert.That(process.HasExited, Is.True); }
public bool ValidateParameters() { if ((!ReadThru) && (!WriteThru)) { OutputProvider.WriteErrorLine("Error: ReadThru/WriteThru not specified."); return(false); } if (!string.IsNullOrEmpty(OutputFile)) { string path = Path.GetExtension(OutputFile); if (!(path.Contains(".txt") || path.Contains(".xml"))) { OutputProvider.WriteErrorLine("Invalid file. Please specify path of .xml or .txt file."); return(false); } } ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); return(true); }
public bool ValidateParameters() { _bridgeService.Port = Port; _bridgeService.ServerName = BridgeServer; if (Port == -1) { _bridgeService.Port = _bridgeService.UseTcp ? BridgeConfigurationManager.NCacheTcpPort : BridgeConfigurationManager.NCacheHttpPort; } if (string.IsNullOrEmpty(BridgeId)) { OutputProvider.WriteErrorLine("Error: Bridge-id not specified."); return(false); } if (string.IsNullOrEmpty(CacheName)) { OutputProvider.WriteErrorLine("Error: Cache-id not specified."); return(false); } bool multipleServers = false; if (CacheServer != null || CacheServer != string.Empty) { _serverList = CacheServer.Split(','); if (_serverList.Length > 1 || (_serverList[0].Contains(":"))) { multipleServers = true; } } VerifyCacheServer(multipleServers); ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); return(true); }
public bool ValidateParameters() { if (string.IsNullOrEmpty(CacheName)) { OutputProvider.WriteErrorLine("Error: Cache name not specified."); return(false); } if (string.IsNullOrEmpty(FilePath)) { OutputProvider.WriteErrorLine("Error: File path not specified."); return(false); } if (string.IsNullOrEmpty(Name)) { OutputProvider.WriteErrorLine("Error: Provider name not specified."); return(false); } ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); return(true); }
public bool ValidateParameters() { try { NCache.Port = Port; } catch (FormatException) { } catch (OverflowException) { } if (Port > 1) { NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort; } bool validAction = false; if (!string.IsNullOrEmpty(Action)) { if (Action.ToLower() == "start") { validAction = true; } if (Action.ToLower() == "stop") { validAction = true; } } if (IsUsage || !validAction) { return(false); } ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); return(true); }
public void StartTasks() { try { Thread[] threads = new Thread[_threadCount]; CacheConnectionOptions parameters = new CacheConnectionOptions(); parameters = ToolsUtil.AddServersInCacheConnectionOptions(_servers, parameters); _cache = CacheManager.GetCache(_cacheId, parameters); string pid = System.Diagnostics.Process.GetCurrentProcess().Id.ToString(); for (int threadIndex = 0; threadIndex < _threadCount; threadIndex++) { StressThreadTask threadTask = new StressThreadTask(_cache, _totalLoopCount, _testCaseIterations, _testCaseIterationDelay, _getsPerIteration, _updatesPerIteration, _dataSize, _expiration, _threadCount, _reportingInterval, threadIndex, _outputProvider, _adapter); _tasks.Add(threadTask); threadTask.Start(); } _adapter.Listen(); } catch (Exception) { throw; } }
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> public void RemoveBridgeCache() { try { _bridgeService = new NCBridgeRPCService(BridgeServer); _bridgeServer = _bridgeService.GetBridgeServer(TimeSpan.FromSeconds(30)); NCacheRPCService nService = new NCacheRPCService(CacheServer); cacheServer = nService.GetCacheServer(new TimeSpan(0, 0, 0, 30)); if (!ValidateParameters()) { return; } //********************************** config = cacheServer.GetCacheConfiguration(CacheName); if (config == null) { OutputProvider.WriteErrorLine("Error : The cache'{0}' does not exist on server {1}:{2} .", CacheName, NCache.ServerName, NCache.Port); return; } { //OutputProvider.WriteErrorLine("Error : The Bidge {0} is running on {1} , please stop Bridge and try again .", BridgeId, NCache.ServerName); //return; } if (config.CacheType.ToLower().Equals("local-cache")) { OutputProvider.WriteLine("Local Cache cannot be added as a bridge cache"); return; } //cacheServer = GetCacheServers(config.Cluster.GetAllConfiguredNodes()); if (_bridgeServer != null) { try { OutputProvider.WriteLine("Removing Cache To Bridge '{0}' on {1}:{2}.", BridgeId, _bridgeService.ServerName, _bridgeService.Port); Alachisoft.NCache.Bridging.Configuration.BridgeConfiguration bridgeConfig = _bridgeServer.GetBridgeConfiguration(BridgeId); ToolsUtil.VerifyBridgeConfigurations(bridgeConfig, BridgeId); if (bridgeConfig == null) { OutputProvider.WriteErrorLine("No Bridge with Bridge ID '{0} exists' on Server {1}:{2}.", BridgeId, _bridgeService.ServerName, _bridgeService.Port); return; } TargetCacheCofiguration targtCacheConfig = new TargetCacheCofiguration(); targtCacheConfig.CacheID = CacheName; targtCacheConfig.Servers = cacheServer.GetHostName(); targtCacheConfig.IsConnected = true; { if (!VerifyBridgeMasterCache(BridgeId, false, bridgeConfig)) { targtCacheConfig.IsMaster = true; } targtCacheConfig.Status = BridgeCacheStateParam.Active.ToString(); } List <TargetCacheCofiguration> previouslyAddedCaches = bridgeConfig.TargetCacheConfigList; int removedCacheIndex = -1; if (previouslyAddedCaches.Count >= 1) { int iteration = 0; //checking validations regarding bridge foreach (TargetCacheCofiguration pCache in previouslyAddedCaches) { //if exists than remove if (pCache.CacheID.ToLower().Equals(CacheName.ToLower())) { if (pCache.CacheAlias.ToLower().Equals(Alias.ToLower()) || string.IsNullOrEmpty(Alias)) { removedCacheIndex = iteration; if (pCache.IsMaster) { OutputProvider.WriteErrorLine("Failed to Remove Cache to bridge '{0}'. Error: Master cache cannot be removed ", BridgeId); return; } } } if (pCache.Status.Equals("passive")) { OutputProvider.WriteErrorLine("Failed to Remove Cache to bridge '{0}'. Error: No both bridge caches can be passive ", BridgeId); return; } iteration++; } } else { OutputProvider.WriteErrorLine("Failed to Remove Cache There is currently no Cache Added in Bridge {0} ", BridgeId); return; } // if (removedCacheIndex >= 0) { bridgeConfig.TargetCacheConfigList.RemoveAt(removedCacheIndex); } else { OutputProvider.WriteErrorLine("Bridge Cache Does not exists with name{0} in Bridge '{1}'", CacheName, BridgeId); return; } //Adding Bridge to config.ncconf BridgeConfig bridgeConf = config.Bridge; config.Bridge = null; byte[] userId = null; byte[] paswd = null; if (UserId != string.Empty && Password != string.Empty) { userId = EncryptionUtil.Encrypt(UserId); paswd = EncryptionUtil.Encrypt(Password); } //writing to config.ncconf config.ConfigVersion++; cacheServer.ConfigureBridgeToCache(config, userId, paswd, true); cacheServer.HotApplyBridgeReplicator(CacheName, false); ConveyToRegisteredNodes(); char[] separater = { ',' }; // write in all bridge nodes bridge.nconnf file bool write = false; foreach (string bridgeIp in bridgeConfig.BridgeNodes.Split(separater).ToList()) { try{ _bridgeService = new NCBridgeRPCService(bridgeIp); _bridgeServer = _bridgeService.GetBridgeServer(TimeSpan.FromSeconds(30)); _bridgeServer.RegisterBridge(bridgeConfig, true, true); write = true; OutputProvider.WriteLine("Removed Bridge Cache {0} From Bridge {1}", CacheName, BridgeId); } catch (Exception e) { OutputProvider.WriteErrorLine("Removing Bridge Cache {0} From Bridge Server{1} Gives Error: {2}", bridgeConf, bridgeIp, e.Message); } } } catch (SecurityException e) { OutputProvider.WriteErrorLine("Failed to Remove Cache to bridge '{0}'. Error: {1} ", BridgeId, e.Message); } catch (Exception e) { OutputProvider.WriteErrorLine("Failed to Remove Cache to bridge '{0}'. Error: {1} ", BridgeId, e.Message); } } } catch (Exception e) { OutputProvider.WriteErrorLine("Error: {0}", e.Message); } finally { if (_bridgeService != null) { _bridgeService.Dispose(); } if (NCache != null) { NCache.Dispose(); } } }
public void CloseUIByPath(string path, CloseType closeType = CloseType.DESTORY) { string uiName = ToolsUtil.getUINameForPath(path); CloseUI(uiName, closeType); }
/// <summary> /// The main entry point for the tool. /// </summary> public void SetBridgeCacheMode() { try { _bridgeService = new NCBridgeRPCService(BridgeServer); _bridgeServer = _bridgeService.GetBridgeServer(TimeSpan.FromSeconds(30)); NCacheRPCService nService = new NCacheRPCService(CacheServer); cacheServer = nService.GetCacheServer(new TimeSpan(0, 0, 0, 30)); if (!ValidateParameters()) { return; } //********************************** config = cacheServer.GetCacheConfiguration(CacheName); if (config == null) { OutputProvider.WriteErrorLine("Error : The cache'{0}' does not exist on server {1}:{2} .", CacheName, NCache.ServerName, NCache.Port); return; } if (config.CacheType.ToLower().Equals("local-cache")) { OutputProvider.WriteLine("Local Cache cannot be Set as a bridge cache"); return; } //cacheServer = GetCacheServers(config.Cluster.GetAllConfiguredNodes()); bool isNotMaster = false; int passiveCount = 0; TargetCacheCofiguration targtCacheConfig = null; if (_bridgeServer != null) { try { OutputProvider.WriteLine("Setting Cache Mode To Bridge '{0}' on {1}:{2}.", BridgeId, _bridgeService.ServerName, _bridgeService.Port); Alachisoft.NCache.Bridging.Configuration.BridgeConfiguration bridgeConfig = _bridgeServer.GetBridgeConfiguration(BridgeId); ToolsUtil.VerifyBridgeConfigurations(bridgeConfig, BridgeId); List <TargetCacheCofiguration> previouslyAddedCaches = bridgeConfig.TargetCacheConfigList; if (previouslyAddedCaches.Count >= 1) { //checking validations regarding bridge foreach (TargetCacheCofiguration pCache in previouslyAddedCaches) { if (pCache.CacheID.ToLower().Equals(CacheName.ToLower())) { isNotMaster = !pCache.IsMaster; targtCacheConfig = pCache; } if (pCache.Status.Equals("passive")) { passiveCount++; } } } else { OutputProvider.WriteErrorLine("No Cache Exists in Bridge {0}", BridgeId); } if (passiveCount >= 1 && State.Equals(BridgeCacheStateParam.Passive)) { OutputProvider.WriteErrorLine("There is already a Passive cache in Bridge", BridgeId); return; } if (!isNotMaster) { OutputProvider.WriteErrorLine("Bridge Cache '{0}' is a master Node,please change masterNode first", CacheName); return; } if (targtCacheConfig.Status.Equals(State.ToString())) { OutputProvider.WriteErrorLine("Bridge Cache '{0}' is already {1}", CacheName, State.ToString()); return; } // //Adding Bridge to config.ncconf BridgeConfig bridgeConf = config.Bridge; bridgeConf.Status = State.ToString(); config.Bridge = bridgeConf; WriteToClientConf(); WriteToBridgeConf(bridgeConfig, targtCacheConfig); OutputProvider.WriteLine("Cache '{0}' mode set to {1}", BridgeId, State.ToString()); } catch (SecurityException e) { OutputProvider.WriteErrorLine("Failed to Add Cache to bridge '{0}'. Error: {1} ", BridgeId, e.Message); } catch (Exception e) { OutputProvider.WriteErrorLine("Failed to Add Cache to bridge '{0}'. Error: {1} ", BridgeId, e.Message); } } } catch (Exception e) { OutputProvider.WriteErrorLine("Error: {0}", e.Message); } finally { if (_bridgeService != null) { _bridgeService.Dispose(); } if (NCache != null) { NCache.Dispose(); } } }
public void CacheServerStatistics() { ArrayList servers = null; bool isPOR = false; bool isRegistered = true; List <ICacheServer> cacheServers = new List <ICacheServer>(); if (!ValidateParameters()) { return; } if (Servers != null && !Servers.Equals("")) { servers = GetServers(Servers); } else { servers = new ArrayList(); NCacheRPCService nCache = new NCacheRPCService(""); servers.Add(nCache.ServerName); } foreach (var server in servers) { NCacheRPCService nCache = new NCacheRPCService(server.ToString()); try { ICacheServer cacheServer = nCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); serverList.Add(cacheServer.GetBindIP()); NodeStatus status = GetCacheStatistics(nCache); if (status.isRegistered == false) { throw new Exception("The specified cache is not registered on server " + server); } isPOR = status.Topology == Topology.POR; cacheServers.Add(cacheServer); //array of it ICacheServer } catch (Exception ex) { if (ex.Message.Contains("The specified cache is not registered")) { OutputProvider.WriteErrorLine(ex.Message); isRegistered = false; } else if (ex.Message.ToUpper().Contains("service".ToUpper())) { OutputProvider.WriteErrorLine("NCache Service could not be contacted on server " + server); isRegistered = false; } } } if (isRegistered) { _mainCounters = GetAllCounters(false); if (isPOR) { _replicaCounters = GetAllCounters(true); } if (!(Format.Equals("csv", StringComparison.OrdinalIgnoreCase) || Format.Equals("tabular", StringComparison.OrdinalIgnoreCase))) { throw new ArgumentException("Invalid Format type"); } if (Continuous && MaxSamples > 0) { throw new Exception("The Continuous parameter and the MaxSamples parameter cannot be used in the same command."); } if (Continuous && Format.Equals("csv", StringComparison.OrdinalIgnoreCase)) { FetchAndDisplayContinousulyCSV(cacheServers, isPOR); } else if (Continuous && Format.Equals("tabular", StringComparison.OrdinalIgnoreCase)) { ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); FetchAndDisplayContinousuly(cacheServers, isPOR); } else if (MaxSamples > 0) { if (Format.Equals("tabular", StringComparison.OrdinalIgnoreCase)) { ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); FetchAndDisplayMax(cacheServers, isPOR); } else if (Format.Equals("csv", StringComparison.OrdinalIgnoreCase)) { FetchAndDisplayMaxCSV(cacheServers, isPOR); } } if (!Continuous && MaxSamples == 0) { try { SortedDictionary <string, string[]> CountList = FetchCounters(cacheServers, isPOR); if (Format.Equals("csv", StringComparison.OrdinalIgnoreCase)) { DisplayinCSVFormat(CountList, isPOR); } else if (Format.Equals("tabular", StringComparison.OrdinalIgnoreCase)) { ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); DisplayTimeStamp(); DisplayCounters(CountList, isPOR); } } catch (ArgumentOutOfRangeException ex) { OutputProvider.WriteErrorLine(ex); } catch (Exception ex) { OutputProvider.WriteErrorLine(ex); } } } OutputProvider.WriteLine("\n"); }
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"); } } }
public void AddBridgeNode() { try { _bridgeService = new NCBridgeRPCService(Server); if (!ValidateParameters()) { return; } _bridgeServer = _bridgeService.GetBridgeServer(TimeSpan.FromSeconds(30)); BridgeConfiguration bconfig = _bridgeServer.GetBridgeConfiguration(BridgeId); ToolsUtil.VerifyBridgeConfigurations(bconfig, BridgeId); byte[] userId = null; byte[] paswd = null; if (UserId != string.Empty && Password != string.Empty) { userId = EncryptionUtil.Encrypt(UserId); paswd = EncryptionUtil.Encrypt(Password); } if (bconfig != null && bconfig.NumberOfBridgeNodes >= 2) { OutputProvider.WriteErrorLine("You cannot add more than 2 nodes in a Bridge"); return; } if (!bconfig.GetBridgeNodeList().Contains(NewBridgeNode)) { if (bconfig.GetBridgeNodeList().Count != 0) { bconfig.DeploymentVersion++; bconfig.BridgeNodes = bconfig.BridgeNodes + "," + NewBridgeNode; _bridgeServer.RegisterBridge(bconfig, true, false); //for registering bridge on newly added node NCBridgeRPCService _bridgeNewService = new NCBridgeRPCService(NewBridgeNode); IBridgeServer _bridgeNewServer = _bridgeNewService.GetBridgeServer(TimeSpan.FromSeconds(30)); _bridgeNewServer.RegisterBridge(bconfig, true, false); OutputProvider.WriteLine(NewBridgeNode + " added to " + BridgeId); } else { bconfig.BridgeNodes = NewBridgeNode; bconfig.BridgeActive = NewBridgeNode; NCBridgeRPCService _bridgeNewService = new NCBridgeRPCService(NewBridgeNode); IBridgeServer _bridgeNewServer = _bridgeNewService.GetBridgeServer(TimeSpan.FromSeconds(30)); _bridgeNewServer.RegisterBridge(bconfig, true, false); OutputProvider.WriteLine(NewBridgeNode + " added to " + BridgeId); } //updating target cache config if (bconfig.TargetCacheConfigList != null) { foreach (TargetCacheCofiguration targetCacheConfig in bconfig.TargetCacheConfigList) { try { if (targetCacheConfig != null) { foreach (string server in targetCacheConfig.Servers.Split(',')) { NCacheRPCService NCache = new NCacheRPCService(server);; ICacheServer cacheServer = null; cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); string cacheID = targetCacheConfig.CacheID.ToString(); CacheServerConfig serverConfig = cacheServer.GetCacheConfiguration(cacheID); if (serverConfig.Bridge != null) { serverConfig.Bridge.Servers = bconfig.BridgeNodes; } serverConfig.ConfigVersion++; cacheServer.ConfigureBridgeToCache(serverConfig, userId, paswd, false); } } } catch (Exception e) { OutputProvider.WriteErrorLine(e.Message); return; } } } } else { OutputProvider.WriteErrorLine("Error: Node already exists in bridge"); return; } } catch (Exception e) { OutputProvider.WriteErrorLine("Error: Bridge not registered on server.\n"); OutputProvider.WriteErrorLine(e.Message); } }
/// <summary> /// The main entry point for the tool. /// </summary> public void AddBridgeCache() { try { if (!ValidateParameters()) { return; } _bridgeService = new NCBridgeRPCService(BridgeServer); if (Port == -1) { _bridgeService.Port = _bridgeService.UseTcp ? BridgeConfigurationManager.NCacheTcpPort : BridgeConfigurationManager.NCacheHttpPort; } else { _bridgeService.Port = Port; } if (!string.IsNullOrEmpty(BridgeServer)) { _bridgeService.ServerName = BridgeServer; } _bridgeServer = _bridgeService.GetBridgeServer(TimeSpan.FromSeconds(30)); NCacheRPCService nService = new NCacheRPCService(CacheServer); cacheServer = nService.GetCacheServer(new TimeSpan(0, 0, 0, 30)); //********************************** config = cacheServer.GetCacheConfiguration(CacheName); if (config == null) { OutputProvider.WriteErrorLine("Error : The cache'{0}' does not exist on server {1}:{2} .", CacheName, NCache.ServerName, NCache.Port); return; } if (config.CacheType.ToLower().Equals("local-cache")) { OutputProvider.WriteLine("Local Cache cannot be added as a bridge cache"); return; } //cacheServer = GetCacheServers(config.Cluster.GetAllConfiguredNodes()); if (_bridgeServer != null) { try { OutputProvider.WriteLine("Adding Cache To Bridge '{0}' on {1}:{2}.", BridgeId, _bridgeService.ServerName, _bridgeService.Port); Alachisoft.NCache.Bridging.Configuration.BridgeConfiguration bridgeConfig = _bridgeServer.GetBridgeConfiguration(BridgeId); if (bridgeConfig == null) { OutputProvider.WriteErrorLine("No Bridge with Bridge ID '{0} exists' on Server {1}:{2}.", BridgeId, _bridgeService.ServerName, _bridgeService.Port); return; } TargetCacheCofiguration targtCacheConfig = new TargetCacheCofiguration(); targtCacheConfig.CacheID = CacheName; targtCacheConfig.CacheAlias = Alias; // set the Alias, null if name is different. Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = cacheServer.GetNewConfiguration(CacheName); string servers = String.Empty; foreach (Address node in serverConfig.CacheDeployment.Servers.GetAllConfiguredNodes()) { servers += node.IpAddress + ","; } servers = servers.Remove(servers.Length - 1); targtCacheConfig.Servers = servers; targtCacheConfig.IsConnected = true; if (State.Equals(BridgeCacheStateParam.Active)) { if (!VerifyBridgeMasterCache(BridgeId, false, bridgeConfig)) { targtCacheConfig.IsMaster = true; } targtCacheConfig.Status = BridgeCacheStateParam.Active.ToString(); } else { targtCacheConfig.Status = BridgeCacheStateParam.Passive.ToString(); } ToolsUtil.VerifyBridgeConfigurations(bridgeConfig, BridgeId); List <TargetCacheCofiguration> previouslyAddedCaches = bridgeConfig.TargetCacheConfigList; if (previouslyAddedCaches.Count <= 1) { //checking validations regarding bridge foreach (TargetCacheCofiguration pCache in previouslyAddedCaches) { if (pCache.CacheID.ToLower().Equals(targtCacheConfig.CacheID.ToLower())) { OutputProvider.WriteErrorLine("Failed to Add Cache to bridge '{0}'. Error:No Same Cache Can be Added Twice ", BridgeId); return; } if (pCache.Status.Equals("passive")) { OutputProvider.WriteErrorLine("Failed to Add Cache to bridge '{0}'. Error:No both bridge caches can be passive ", BridgeId); return; } } } else { OutputProvider.WriteErrorLine("Failed to Add Cache to bridge '{0}'. Error:No More than 2 caches can be add at a time ", BridgeId); return; } // //Adding Bridge to config.ncconf BridgeConfig bridgeConf = new BridgeConfig(); bridgeConf.CacheAlias = Alias; bridgeConf.Id = BridgeId; if (config != null) { bridgeConf.Servers = bridgeConfig.BridgeNodes; bridgeConf.Port = bridgeConfig.BridgePort; bridgeConf.Status = State.ToString(); } config.Bridge = bridgeConf; byte[] userId = null; byte[] paswd = null; if (UserId != string.Empty && Password != string.Empty) { userId = EncryptionUtil.Encrypt(UserId); paswd = EncryptionUtil.Encrypt(Password); } //writing to config.ncconf config.ConfigVersion++; cacheServer.ConfigureBridgeToCache(config, userId, paswd, true); cacheServer.HotApplyBridgeReplicator(CacheName, false); Alachisoft.NCache.Config.NewDom.CacheServerConfig nConfig = cacheServer.GetNewConfiguration(CacheName); foreach (Address node in nConfig.CacheDeployment.Servers.GetAllConfiguredNodes()) { NCache.ServerName = node.IpAddress.ToString(); ICacheServer server = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); server.ConfigureBridgeToCache(config, userId, paswd, true); server.HotApplyBridgeReplicator(CacheName, false); } ConveyToRegisteredNodes(); char [] separater = { ',' }; bridgeConfig.TargetCacheConfigList.Add(targtCacheConfig); // write in all bridge nodes bridge.nconnf file bridgeConfig.DeploymentVersion++; foreach (string bridgeIp in bridgeConfig.BridgeNodes.Split(separater).ToList()) { _bridgeService = new NCBridgeRPCService(bridgeIp); _bridgeServer = _bridgeService.GetBridgeServer(TimeSpan.FromSeconds(30)); _bridgeServer.RegisterBridge(bridgeConfig, true, true); } OutputProvider.WriteLine("{0} successfully added to BridgeID {1}", CacheName, BridgeId); } catch (SecurityException e) { OutputProvider.WriteErrorLine("Failed to Add Cache to bridge '{0}'. Error: {1} ", BridgeId, e.Message); } catch (Exception e) { OutputProvider.WriteErrorLine("Failed to Add Cache to bridge '{0}'. Error: {1} ", BridgeId, e.Message); } } } catch (Exception e) { OutputProvider.WriteErrorLine("Error: {0}", e.Message); } finally { if (_bridgeService != null) { _bridgeService.Dispose(); } if (NCache != null) { NCache.Dispose(); } } }
public void ListCaches() { ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); OutputProvider.WriteLine("Licensed to use FREE of cost. Use As-is without support.\n"); if (Port != -1) { NCache.Port = Port; } if (Server != null && !Server.Equals("")) { NCache.ServerName = Server; } string getBindIp = string.Empty; try { ICacheServer cacheServer = null; 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; } getBindIp = cacheServer.GetBindIP(); OutputProvider.WriteLine("Listing registered caches on server {0}:{1}\n", getBindIp, NCache.Port); if (cacheServer != null) { Alachisoft.NCache.Common.Monitoring.ConfiguredCacheInfo[] caches = cacheServer.GetAllConfiguredCaches(); if (caches.Length > 0) { if (!Detail) { OutputProvider.WriteLine("{0,-25} {1,-35} {2,-15}", "Cache-Name", "Topology", "Status(PID)"); OutputProvider.WriteLine("{0,-25} {1,-35} {2,-15}", "----------", "--------", "-----------"); } if (caches.Length > 0) { for (int i = 0; i < caches.Length; i++) { Alachisoft.NCache.Common.Monitoring.ConfiguredCacheInfo cacheInfo = caches[i]; if (!Detail) { PrintCacheInfo(cacheInfo.Topology.ToString(), cacheInfo.CacheId, cacheInfo.IsRunning, cacheInfo.ProcessID); } else { try { PrintDetailedCacheInfo(cacheServer.GetCacheStatistics2(cacheInfo.CacheId), cacheInfo.Topology.ToString(), null, cacheInfo.IsRunning, cacheInfo.CacheId, cacheInfo.CachePropString, cacheInfo.ProcessID.ToString()); } catch (Exception e) { if (e.Message != null && e.Message.Contains("No connection could be made because the target machine actively refused it")) { PrintDetailedCacheInfo(null, cacheInfo.Topology.ToString(), null, false, cacheInfo.CacheId, cacheInfo.CachePropString, "0"); } else { OutputProvider.WriteErrorLine("Error: {0}", e.Message); OutputProvider.WriteErrorLine(e.ToString()); } } } } } } else { OutputProvider.WriteLine("There are no registered caches on {0}", NCache.ServerName); } } } catch (Exception e) { OutputProvider.WriteErrorLine("Error: {0}", e.Message); OutputProvider.WriteErrorLine(e.ToString()); } finally { NCache.Dispose(); } OutputProvider.WriteLine((Detail)?"": Environment.NewLine); }
public void VerifyCacheServer(bool multipleServers) { int index = 0; string server = ""; tryNextServer: if (multipleServers) { string[] serverAddress = _serverList[index].Split(':'); if (serverAddress.Length == 2) { if (!ToolsUtil.IsValidIP(serverAddress[0])) { OutputProvider.WriteErrorLine("Error: Invalid Server IP."); throw new Exception("Invalid IP :" + serverAddress[0]); } NCache.ServerName = serverAddress[0]; try { NCache.Port = Convert.ToInt32(serverAddress[1]); } catch (Exception) { throw new Exception("Invalid Port :" + serverAddress[1] + "specified for server : " + serverAddress[0] + "."); } } else if (serverAddress.Length == 1) { if (!ToolsUtil.IsValidIP(serverAddress[0])) { OutputProvider.WriteErrorLine("Error: Invalid Server IP."); throw new Exception("Invalid Server IP :" + serverAddress[0] + "."); } NCache.ServerName = serverAddress[0]; NCache.Port = Port; if (Port == -1) { NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort; } } else { throw new Exception("Invalid server Address specified, kindly specify as [IPAdress] or [IPAdress]:[Port]."); } } else { if (Port != -1) { NCache.Port = Port; } if (CacheServer != null || CacheServer != string.Empty) { NCache.ServerName = CacheServer; } if (Port == -1) { NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort; } } try { server = NCache.ServerName; cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); } catch (Exception ex) { if (multipleServers) { if (index < _serverList.Length - 1) { OutputProvider.WriteErrorLine("Failed to connect to server : " + NCache.ServerName + ":" + NCache.Port + " \nTrying next server."); index++; goto tryNextServer; } } throw ex; } }
private void LaunchGame() { string binDir = _currentProfile.Mod.Mount.BinDirectory; string executableName = _currentProfile.Mod.ExecutableName; string gameRootPath = _currentProfile.Mod.Mount.MountPath; if (OperatingSystem.IsWindows()) { executableName += ".exe"; } else if (OperatingSystem.IsLinux()) { executableName += ".sh"; } string binPath = Path.Combine(binDir, executableName); // See if the binary is in bin folder if (!File.Exists(binPath)) { // Not in a chaos game. Try to find it in game root. binPath = Path.Combine(gameRootPath, executableName); if (!File.Exists(binPath)) { var dialog = new NotificationDialog($"Unable to find game binary '{binPath}'"); dialog.ShowDialog(this); return; } } var args = $"{_currentProfile.Mod.LaunchArguments} -game {_currentProfile.Mod.Mount.PrimarySearchPath}"; if (!string.IsNullOrWhiteSpace(_currentProfile.AdditionalMount.MountPath)) { args += $" -mountmod \"{Path.Combine(_currentProfile.AdditionalMount.MountPath, _currentProfile.AdditionalMount.PrimarySearchPath)}\""; } if (ToolsModeCheckBox.IsChecked != null && ToolsModeCheckBox.IsChecked.Value && !args.Contains("-tools")) { args += " -tools"; } if (LegacyUiCheckBox.IsChecked != null && LegacyUiCheckBox.IsChecked.Value && !args.Contains("-legacyui")) { args += " -legacyui"; } if (GraphicsApiCheckBox.IsChecked != null && GraphicsApiCheckBox.IsChecked.Value && !args.Contains("-shaderapi")) { args += " -shaderapi shaderapidx11"; } if (ConsoleCheckBox.IsChecked != null && ConsoleCheckBox.IsChecked.Value && !args.Contains("-console")) { args += " -console"; } if (DeveloperCheckBox.IsChecked != null && DeveloperCheckBox.IsChecked.Value && !args.Contains("-dev")) { args += " -dev"; } try { ToolsUtil.LaunchTool(binDir, executableName, args, false, gameRootPath); } catch (ToolsLaunchException e) { var dialog = new NotificationDialog(e.Message); dialog.ShowDialog(this); } Close(); }
/// <summary> /// The main entry point for the tool. /// </summary> public void SetBridgeCacheConnection() { try { _bridgeService = new NCBridgeRPCService(BridgeServer); _bridgeServer = _bridgeService.GetBridgeServer(TimeSpan.FromSeconds(30)); if (!ValidateParameters()) { return; } //********************************** //cacheServer = GetCacheServers(config.Cluster.GetAllConfiguredNodes()); bool isNotMaster = false; int passiveCount = 0; bool cacheExists = false; TargetCacheCofiguration targtCacheConfig = null; if (_bridgeServer != null) { try { OutputProvider.WriteLine("Setting Cache '{0}' Connection To Bridge '{1}' on {2}:{3}.", CacheName, BridgeId, _bridgeService.ServerName, _bridgeService.Port); Alachisoft.NCache.Bridging.Configuration.BridgeConfiguration bridgeConfig = _bridgeServer.GetBridgeConfiguration(BridgeId); ToolsUtil.VerifyBridgeConfigurations(bridgeConfig, BridgeId); List <TargetCacheCofiguration> previouslyAddedCaches = bridgeConfig.TargetCacheConfigList; if (previouslyAddedCaches.Count >= 1) { //checking validations regarding bridge foreach (TargetCacheCofiguration pCache in previouslyAddedCaches) { if (pCache.CacheID.ToLower().Equals(CacheName.ToLower())) { cacheExists = true; isNotMaster = !pCache.IsMaster; targtCacheConfig = pCache; } if (pCache.Status.Equals("passive")) { passiveCount++; } } } else { OutputProvider.WriteErrorLine("No Cache Exists in Bridge {0}", BridgeId); return; } if (previouslyAddedCaches.Count == 2 && !isNotMaster && cacheExists && Connection.ToString().ToLower().Equals("disconnect")) { OutputProvider.WriteErrorLine("Master Cache '{0}'cannot be disconnected,please change the master cache First", CacheName); return; } if (!cacheExists) { OutputProvider.WriteErrorLine("No Cache Exists in Bridge {0} with CacheId {1}", BridgeId, CacheName); } WriteToBridgeConf(bridgeConfig, targtCacheConfig); OutputProvider.WriteLine("Bridge Connection for Bridge {0} set to {1} Successfully!", BridgeId, Connection.ToString()); } catch (SecurityException e) { OutputProvider.WriteErrorLine("Failed to Set Cache Connection Status to bridge '{0}'. Error: {1} ", BridgeId, e.Message); } catch (Exception e) { OutputProvider.WriteErrorLine("Failed to Set Cache Connection Status to bridge '{0}'. Error: {1} ", BridgeId, e.Message); } } } catch (Exception e) { OutputProvider.WriteErrorLine("Error: {0}", e.Message); } finally { if (_bridgeService != null) { _bridgeService.Dispose(); } } }
protected void CacheClientStatistics() { ArrayList clients = null; List <ICacheServer> cacheServers = new List <ICacheServer>(); bool isServiceRunning = true; if (!ValidateParameters()) { return; } if (Clients != null && !Clients.Equals("")) { clients = GetClients(Clients); } else { clients = new ArrayList(); NCacheRPCService nCache = new NCacheRPCService(""); clients.Add(nCache.ServerName); } foreach (var client in clients) { NCacheRPCService nCache = new NCacheRPCService(client.ToString()); try { ICacheServer cacheServer = nCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); //NodeStatus status = GetCacheStatistics(_nCache); ClientList.Add(cacheServer.GetBindIP()); cacheServers.Add(cacheServer); } catch (Exception ex) { if (ex.Message.ToUpper().Contains("service".ToUpper())) { OutputProvider.WriteErrorLine("NCache Service could not be contacted on server " + client); isServiceRunning = false; } else { cacheServers.Add(null); } } } if (!(Format.Equals("csv", StringComparison.OrdinalIgnoreCase) || Format.Equals("tabular", StringComparison.OrdinalIgnoreCase))) { throw new ArgumentException("Invalid Format type"); } if (Continuous && MaxSamples > 0) { throw new Exception("The Continuous parameter and the MaxSamples parameter cannot be used in the same command."); } _perfmonCounters = CreateCounterList(); if (Continuous && Format.Equals("csv", StringComparison.OrdinalIgnoreCase)) { FetchAndDisplayContinousulyCSV(cacheServers); } else if (Continuous && Format.Equals("tabular", StringComparison.OrdinalIgnoreCase)) { Util.ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); FetchAndDisplayContinousuly(cacheServers); } else if (MaxSamples > 0) { if (Format.Equals("tabular", StringComparison.OrdinalIgnoreCase)) { ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); FetchAndDisplayMax(cacheServers); } else if (Format.Equals("csv", StringComparison.OrdinalIgnoreCase)) { FetchAndDisplayMaxCSV(cacheServers); } } if (!Continuous && MaxSamples == 0) { if (isServiceRunning) { try { SortedDictionary <string, string[]> CountList = FetchCounters(cacheServers); if (Format.Equals("csv", StringComparison.OrdinalIgnoreCase)) { DisplayinCSVFormat(CountList); } else if (Format.Equals("tabular", StringComparison.OrdinalIgnoreCase)) { Util.ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME); DisplayTimeStamp(); DisplayCounters(CountList); } } catch (ArgumentOutOfRangeException ex) { OutputProvider.WriteErrorLine(ex); } catch (Exception ex) { OutputProvider.WriteErrorLine(ex); } } } }
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 void RemoveBridgeNode() { try { _bridgeService = new NCBridgeRPCService(Server); if (!ValidateParameters()) { return; } _bridgeServer = _bridgeService.GetBridgeServer(TimeSpan.FromSeconds(30)); BridgeConfiguration bridgeConfig = _bridgeServer.GetBridgeConfiguration(BridgeId); if (!ToolsUtil.VerifyBridgeConfigurations(bridgeConfig, BridgeId)) { OutputProvider.WriteErrorLine("Error: Configuration mismatch."); return; } byte[] userId = null; byte[] paswd = null; if (UserId != string.Empty && Password != string.Empty) { userId = EncryptionUtil.Encrypt(UserId); paswd = EncryptionUtil.Encrypt(Password); } if (DeleteBridgeNode == Server) { _bridgeServer.UnRegisterBridge(BridgeId); } else { NCBridgeRPCService _removeBridgeService = new NCBridgeRPCService(DeleteBridgeNode); IBridgeServer _removeServer = _removeBridgeService.GetBridgeServer(TimeSpan.FromSeconds(30)); _removeServer.UnRegisterBridge(BridgeId); } if (bridgeConfig != null) { if (bridgeConfig.GetBridgeNodeList().Count == 1) { bridgeConfig.BridgeNodes = ""; } else if (bridgeConfig.BridgeNodes.Contains(DeleteBridgeNode + ",")) { bridgeConfig.BridgeNodes = bridgeConfig.BridgeNodes.Replace(DeleteBridgeNode + ",", ""); } else { bridgeConfig.BridgeNodes = bridgeConfig.BridgeNodes.Replace("," + DeleteBridgeNode, ""); } if (bridgeConfig.GetBridgeNodeList().Count == 0) { bridgeConfig.BridgeActive = string.Empty; } else { bridgeConfig.BridgeActive = bridgeConfig.BridgeNodes; } bridgeConfig.DeploymentVersion++; if (bridgeConfig.GetBridgeNodeList().Count > 0 && !string.IsNullOrEmpty(bridgeConfig.BridgeNodes)) { NCBridgeRPCService _bridge = new NCBridgeRPCService(bridgeConfig.BridgeActive); IBridgeServer _server = _bridge.GetBridgeServer(TimeSpan.FromSeconds(30)); _server.RegisterBridge(bridgeConfig, true, false); } //updating target cache config if (bridgeConfig.TargetCacheConfigList != null) { foreach (TargetCacheCofiguration targetCacheConfig in bridgeConfig.TargetCacheConfigList) { try { if (targetCacheConfig != null) { foreach (string server in targetCacheConfig.Servers.Split(',')) { NCacheRPCService NCache = new NCacheRPCService(server);; ICacheServer cacheServer = null; cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30)); string cacheID = targetCacheConfig.CacheID.ToString(); CacheServerConfig serverConfig = cacheServer.GetCacheConfiguration(cacheID); if (serverConfig.Bridge != null) { serverConfig.Bridge.Servers = bridgeConfig.BridgeNodes; } serverConfig.ConfigVersion++; cacheServer.ConfigureBridgeToCache(serverConfig, userId, paswd, false); } } } catch (Exception ex) { OutputProvider.WriteErrorLine(ex.Message); return; } } } } OutputProvider.WriteLine("Bridge node" + DeleteBridgeNode.ToString() + " removed successfully from Bridge " + BridgeId); } catch (Exception e) { OutputProvider.WriteErrorLine("Bridge not registered on server.\n"); OutputProvider.WriteErrorLine(e.Message); return; } }