Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
        public void AddBridge()
        {
            try
            {
                if (!ValidateParameters())
                {
                    return;
                }

                _bridgeService = new NCBridgeRPCService(ActiveNode);

                _bridgeService.ServerName = ActiveNode;

                if (Port == -1)
                {
                    _bridgeService.Port = _bridgeService.UseTcp ? BridgeConfigurationManager.NCacheTcpPort : BridgeConfigurationManager.NCacheHttpPort;
                }
                else
                {
                    _bridgeService.Port = Port;
                }

                _bridgeServer = _bridgeService.GetBridgeServer(TimeSpan.FromSeconds(30));



                BridgeConfiguration bridgeConfig = _bridgeServer.GetBridgeConfiguration(BridgeId);
                if (bridgeConfig != null)
                {
                    OutputProvider.WriteErrorLine("Error: Bridge with specified Bridge Id already exists.");
                    return;
                }

                else
                {
                    bridgeConfig          = new BridgeConfiguration();
                    bridgeConfig.ConfigID = Guid.NewGuid().ToString();
                }


                bridgeConfig.ID = BridgeId;

                bridgeConfig.ReplicatorVirtualQueueSize      = ReplicatorQueueSize;
                bridgeConfig.QueueConfig.Size                = MaxQueueSize;
                bridgeConfig.QueueConfig.OptimizationEnabled = QueueOptimized;
                bridgeConfig.BridgeActive = ActiveNode;
                bridgeConfig.BridgeNodes  = ActiveNode;



                if (!string.IsNullOrEmpty(PassiveNode))
                {
                    bridgeConfig.BridgeNodes = bridgeConfig.BridgeNodes + "," + PassiveNode;
                    //specify port for bridge
                    if (BridgePort != -1)
                    {
                        if (IsBridgePortAvailable(bridgeConfig, BridgePort))
                        {
                            bridgeConfig.BridgePort = BridgePort;
                        }

                        else
                        {
                            OutputProvider.WriteErrorLine("Error: Specified bridge port is not available.");
                            return;
                        }
                    }

                    else
                    {
                        bridgeConfig.BridgePort = NextAvailableBridgePort(bridgeConfig);
                    }

                    try
                    {
                        NCBridgeRPCService _bridgePassiveNodeService = new NCBridgeRPCService(PassiveNode);
                        IBridgeServer      _bridgePassiveServer      = _bridgePassiveNodeService.GetBridgeServer(TimeSpan.FromSeconds(30));
                        _bridgePassiveServer.RegisterBridge(bridgeConfig, false, false);
                    }
                    catch (Exception ee)
                    {
                        OutputProvider.WriteErrorLine("Error: Bridge could not be added on passive node.");
                        return;
                    }
                }

                else
                {
                    //specify port for bridge
                    if (BridgePort != -1)
                    {
                        if (IsBridgePortAvailable(bridgeConfig, BridgePort))
                        {
                            bridgeConfig.BridgePort = BridgePort;
                        }

                        else
                        {
                            OutputProvider.WriteErrorLine("Error: Specified bridge port is not available.");
                            return;
                        }
                    }

                    else
                    {
                        bridgeConfig.BridgePort = NextAvailableBridgePort(bridgeConfig);
                    }
                }

                try
                {
                    _bridgeServer.RegisterBridge(bridgeConfig, false, false);
                    OutputProvider.WriteLine("Bridge succesfully added.");
                }
                catch (Exception e)
                {
                    OutputProvider.WriteErrorLine("Error: Bridge could not be added.");
                    return;
                }
            }
            catch (Exception ex)
            {
                OutputProvider.WriteErrorLine("Error: " + ex.Message);
            }
        }
Beispiel #3
0
        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;
            }
        }
Beispiel #4
0
        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;
            }
        }