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); } }
public void RemoveBridge() { try { if (!ValidateParameters()) { return; } _bridgeService = new NCBridgeRPCService(Server); if (Port == -1) { _bridgeService.Port = _bridgeService.UseTcp ? BridgeConfigurationManager.NCacheTcpPort : BridgeConfigurationManager.NCacheHttpPort; } else { _bridgeService.Port = Port; } _bridgeService.ServerName = Server; _bridgeServer = _bridgeService.GetBridgeServer(TimeSpan.FromSeconds(30)); BridgeConfiguration bridgeConfig = _bridgeServer.GetBridgeConfiguration(BridgeId); byte[] userId = null; byte[] paswd = null; if (UserId != string.Empty && Password != string.Empty) { userId = EncryptionUtil.Encrypt(UserId); paswd = EncryptionUtil.Encrypt(Password); } if (bridgeConfig.GetBridgeNodeList().Count == 2) { _bridgeServer.UnRegisterBridge(BridgeId); if (bridgeConfig.BridgeNodes.Contains(_bridgeServer + ",")) { bridgeConfig.BridgeNodes = bridgeConfig.BridgeNodes.Replace(_bridgeServer + ",", ""); } else { bridgeConfig.BridgeNodes = bridgeConfig.BridgeNodes.Replace("," + _bridgeServer, ""); } bridgeConfig.BridgeActive = bridgeConfig.BridgeNodes; NCBridgeRPCService _bridge = new NCBridgeRPCService(bridgeConfig.BridgeActive); IBridgeServer _server = _bridge.GetBridgeServer(TimeSpan.FromSeconds(30)); _server.UnRegisterBridge(BridgeId); } else { _bridgeServer.UnRegisterBridge(BridgeId); } bridgeConfig.BridgeNodes = ""; //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 = null; } serverConfig.ConfigVersion++; cacheServer.ConfigureBridgeToCache(serverConfig, userId, paswd, false); } } } catch (Exception ex) { OutputProvider.WriteErrorLine(ex.Message); return; } } } OutputProvider.WriteLine("Bridge removed."); } catch (Exception e) { OutputProvider.WriteErrorLine("Bridge not registered on server.\n"); OutputProvider.WriteErrorLine("Error: " + e.Message); return; } }
private bool IsBridgePortAvailable(BridgeConfiguration bconfig, int newBridgePort) { ArrayList nodes = bconfig.GetBridgeNodeList(); string serverName = ""; Hashtable bridgeProps = new Hashtable(); NCBridgeRPCService sw; bool isAvailable = true; try { for (int i = 0; i < nodes.Count; i++) { serverName = nodes[i].ToString(); sw = new NCBridgeRPCService(serverName); IBridgeServer server = sw.GetBridgeServer(TimeSpan.FromSeconds(30)); BridgeConfiguration[] configs = server.GetAllBridgesConfiguration(); Hashtable bridgeList = new Hashtable(); if (configs != null) { for (int j = 0; j < configs.Length; j++) { bridgeList.Add(configs[j].ID.ToLower(), configs[j]); } } bridgeProps = bridgeList; if (bridgeProps != null) { IDictionaryEnumerator ide = bridgeProps.GetEnumerator(); while (ide.MoveNext()) { try { string bridgeName = ide.Key as string; BridgeConfiguration bridgeConfig = new BridgeConfiguration(); if (ide.Value is BridgeConfiguration) { bridgeConfig = (BridgeConfiguration)ide.Value; } if (bridgeConfig != null && bridgeConfig.BridgePort == newBridgePort) { isAvailable = false; break; } } catch (Exception e) { OutputProvider.WriteErrorLine("Error: " + e.Message); } } } } } catch (Exception ex) { OutputProvider.WriteErrorLine("Error: Failed to fetch bridge port info from " + serverName + "\n\nError: " + ex.Message); } return(isAvailable); }
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; } }