Beispiel #1
0
        public static void StopCache(string cacheId, string serverName, bool isGracefulShutdown)
        {
            ICacheServer cs           = null;
            CacheService cacheService = new NCacheRPCService(null);

            try
            {
                cacheService.ServerName = serverName;
                cs = cacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                if (cs != null)
                {
                    cs.StopCache(cacheId);
                }
            }
            catch (Exception ex)
            {
                if (cs != null)
                {
                    cs.Dispose();
                    cs = null;
                }
                throw new ManagementException(ex.Message);
            }
            finally
            {
                if (cs != null)
                {
                    cs.Dispose();
                }
                cacheService.Dispose();
            }
        }
Beispiel #2
0
        public static void StopCache(string cacheId)
        {
            ICacheServer      cs           = null;
            CacheService      cacheService = new NCacheRPCService(null);
            CacheServerConfig config       = null;

            try
            {
                cacheService.ServerName = Environment.MachineName;
                cs = cacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                if (cs != null)
                {
                    config = cs.GetCacheConfiguration(cacheId);
                    if (!config.InProc)
                    {
                        cs.StopCache(cacheId);
                    }
                    else
                    {
                        throw new ManagementException("Inproc caches cannot be stopped explicitly.");
                    }
                }
            }
            finally
            {
                if (cs != null)
                {
                    cs.Dispose();
                }
                cacheService.Dispose();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Creates and returns an instance of NCache.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="timeout"></param>
        /// <returns>A reference to <see cref="Cache"/> object.</returns>
        private static Cache ConnectCacheInstance(CacheConfig data, TimeSpan timeout)
        {
            CacheService ncache;

            ncache = new NCacheRPCService(data.ServerName, (int)data.Port);

            try
            {
                ncache.UseTcp     = data.UseTcp;
                ncache.ServerName = data.ServerName;
                ncache.Port       = data.Port;
                if (ncache.ServerName == null ||
                    ncache.ServerName.Length < 1 ||
                    ncache.ServerName.CompareTo(".") == 0 ||
                    ncache.ServerName.CompareTo("localhost") == 0)
                {
                    ncache.ServerName = Environment.MachineName;
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                ncache.Dispose();
            }
            return(null);
        }
Beispiel #4
0
        /// <summary>
        /// Sets the application level parameters to those specified at the command line.
        /// </summary>
        /// <param name="args">array of command line parameters</param>
        public bool ValidateParameters()
        {
            if (Name != null && Name.Length > 0)
            {
                CachesList = new ArrayList();
                CachesList.AddRange(Name);
            }
            NCache            = new NCacheRPCService("");
            NCache.ServerName = Server;
            if (String.IsNullOrEmpty(NCache.ServerName))
            {
                NCache.ServerName = System.Environment.MachineName;
            }
            NCache.Port = Port;
            if (NCache.Port == -1)
            {
                NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
            }
            if (CachesList.Count == 0)
            {
                OutputProvider.WriteErrorLine("Error: cache name not specified.");
            }
            if (CachesList.Count > 1)
            {
                _partId = string.Empty;
            }

            ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME);
            return(true);
        }
Beispiel #5
0
        /// <summary>
        /// initilaise
        /// </summary>
        protected virtual void Initialize()
        {
            CacheService cacheService = null;

            if (RuntimeContext.CurrentContext == RtContextValue.JVCACHE)
            {
                cacheService = new JvCacheRPCService(_address, _port);
                cacheService.OnGetSecurityCredentials += new EventHandler <CredentialsEventArgs>(OnGetSecurityCredentials);
            }
            else
            {
                cacheService = new NCacheRPCService(_address, _port);
            }

            try
            {
                _server = cacheService.GetCacheServer(TimeSpan.FromSeconds(7));
            }
            catch (SshAuthenticationException)
            {
                throw new Exception("Could not authenticate on server. Incorrect Username or Password.");
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                cacheService.Dispose();
            }
        }
Beispiel #6
0
        private static bool ValidateNCacheService()
        {
            ICacheServer cacheServer;

            try
            {
                if (cParam.UpdateServerConfig)
                {
                    //Validate Service on Server(s)
                    foreach (string node in currentServerNodes)
                    {
                        NCache.ServerName = node;
                        cacheServer       = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                    }
                }
                //Validate Service on Client
                NCacheRPCService nCache = new NCacheRPCService("");
                nCache.ServerName = cParam.ClientNode; //clientNode;
                cacheServer       = nCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                return(true);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error: {0}", ex.Message);
                return(false);
            }
        }
Beispiel #7
0
        private bool IsUnderStateTransfer(string cacheId, CacheServerConfig settings)
        {
            bool isUnderStateTransfer = false;

            if (settings != null && settings.Cluster != null && settings.Cluster.Nodes != null)
            {
                foreach (var Node in settings.Cluster.Nodes)
                {
                    ICacheServer cacheserver = null;
                    try
                    {
                        //Try connecting to each node
                        NCacheRPCService nCacheRPCService = new NCacheRPCService(Node.Key.NodeName);
                        cacheserver          = nCacheRPCService.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                        isUnderStateTransfer = cacheserver.IsUnderStateTransfer(cacheId);
                        if (isUnderStateTransfer)
                        {
                            return(isUnderStateTransfer);
                        }
                    }
                    catch
                    {
                    }
                }
            }
            return(isUnderStateTransfer);
        }
Beispiel #8
0
        /// <summary>
        /// Creates and returns an instance of NCache.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="timeout"></param>
        /// <returns>A reference to <see cref="Cache"/> object.</returns>
        private static Alachisoft.NCache.Caching.Cache ConnectCacheInstance(CacheConfig data, TimeSpan timeout, bool autoStart)
        {
            CacheService ncache;

            if (RuntimeContext.CurrentContext == RtContextValue.JVCACHE)
            {
                ncache = new JvCacheRPCService(data.ServerName, (int)data.Port);
            }
            else
            {
                ncache = new NCacheRPCService(data.ServerName, (int)data.Port);
            }
            try
            {
                ncache.UseTcp     = data.UseTcp;
                ncache.ServerName = data.ServerName;
                ncache.Port       = data.Port;
                if (ncache.ServerName == null ||
                    ncache.ServerName.Length < 1 ||
                    ncache.ServerName.CompareTo(".") == 0 ||
                    ncache.ServerName.CompareTo("localhost") == 0)
                {
                    ncache.ServerName = Environment.MachineName;
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                ncache.Dispose();
            }
            return(null);
        }
Beispiel #9
0
        public static void StartCache(string cacheId)
        {
            CacheService cacheService = new NCacheRPCService(null);
            ICacheServer cs           = null;

            try
            {
                cacheService.ServerName = Environment.MachineName;
                cs = cacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                if (cs != null)
                {
                    cs.StartCache(cacheId);
                }
            }


            catch (Exception ex)
            {
                throw new ManagementException(ex.Message);
            }
            finally
            {
                if (cs != null)
                {
                    cs.Dispose();
                }
                cacheService.Dispose();
            }
        }
Beispiel #10
0
        private NodeStatus GetCacheStatistics(NCacheRPCService nCacheRPCService)
        {
            ICacheServer cacheServer = nCacheRPCService.GetCacheServer(new TimeSpan(0, 0, 0, 30));
            NodeStatus   nodeInfo    = new NodeStatus();

            nodeInfo.isRegistered = true;

            if (cacheServer.GetCacheConfiguration(CacheName) == null)
            {
                nodeInfo.isRegistered = false;
                return(nodeInfo);
            }
            var config = cacheServer.GetCacheConfiguration(CacheName);

            if (config.CacheType.Contains("local"))
            {
                nodeInfo.Topology = Topology.LOCAL;
            }
            else
            {
                if (config.Cluster.Topology.Contains("partitioned-replicas"))
                {
                    nodeInfo.Topology = Topology.POR;
                }
                else
                {
                    nodeInfo.Topology = Topology.OTHER;
                }
            }
            return(nodeInfo);
        }
        public static void StartCache(string cacheId, string serverName, int port, string userId, string password)
        {
            ICacheServer cs = null;

            CacheService      cacheService = new NCacheRPCService(null);
            CacheServerConfig config       = null;

            try
            {
                cacheService.ServerName = serverName;
                cacheService.Port       = port;
                cs = cacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                if (cs != null)
                {
                    config = cs.GetCacheConfiguration(cacheId);
                    if (config != null)
                    {
                        if (!config.InProc)
                        {
                            cs.StartCache(cacheId);
                        }
                    }
                    else
                    {
                        throw new ManagementException("Unable to Start Cache. Specified cache is not registered.");
                    }
                }
            }

            catch (SecurityException ex)
            {
                if (cs != null)
                {
                    cs.Dispose();
                    cs = null;
                }
                throw ex;
            }

            catch (Exception ex)
            {
                if (cs != null)
                {
                    cs.Dispose();
                    cs = null;
                }
                throw new ManagementException(ex.Message);
            }
            finally
            {
                if (cs != null)
                {
                    cs.Dispose();
                }
                cacheService.Dispose();
            }
        }
Beispiel #12
0
        public void VerifyLicense()
        {
            ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME);
            string            ipAddress = "this machine";
            ServerLicenseInfo serverLicenseInfo;

            try
            {
                if (string.IsNullOrEmpty(Server))
                {
                    serverLicenseInfo = new ServerLicenseInfo();
                }
                else
                {
                    NCache            = new NCacheRPCService("");
                    NCache.Port       = Port;
                    NCache.ServerName = Server;
                    ipAddress         = Server;
                    ICacheServer nCacheServer = null;
                    nCacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                    if (nCacheServer != null)
                    {
                        serverLicenseInfo = nCacheServer.GetServerLicenseInfo();
                    }
                    else
                    {
                        serverLicenseInfo = new ServerLicenseInfo();
                    }
                }

                OutputProvider.WriteLine("This product is registered to ");
                OutputProvider.WriteLine("User:        "******"Email:       " + serverLicenseInfo._email);
                OutputProvider.WriteLine("Company:     " + serverLicenseInfo._companyName);
                OutputProvider.WriteLine("Edition:     " + "NCache OpenSource ");

                if (LicenseManager.LicenseMode(null) == LicenseManager.LicenseType.UnRegistered)
                {
                    OutputProvider.WriteLine("\nThe machine does not have a valid registration information. Please register this machine with a FREE installation key.You can get free installation key from http://www.alachisoft.com/activate/RequestKey.php?Edition=NC-OSS-50-4x&Version=5.0&Source=Register-NCache");

                    OutputProvider.WriteLine("\nIf you are using this machine as NCache client, then you don't need to register NCache on this machine. Only cache server machines are required to be registered");
                }
                else
                {
                    OutputProvider.WriteLine("");
                    OutputProvider.WriteLine("Licensed to use FREE of cost. Use As-is without support.");
                }
            }
            catch (Exception ex)
            {
                OutputProvider.WriteLine(ex.ToString());
                return;
            }

            OutputProvider.WriteLine("\n");
        }
Beispiel #13
0
        public static bool VerifyClusterConfigurations(Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig
                                                       , string cacheName)
        {
            if (serverConfig == null)
            {
                throw new Exception("Specified cache is not registered on the given server");
            }
            double           configVersion     = -1;
            double           deploymentVersion = -1;
            string           configId          = "dummyconfig";
            NCacheRPCService NCache            = new NCacheRPCService("");

            if (serverConfig.CacheSettings.CacheType == "clustered-cache")
            {
                foreach (Address node in serverConfig.CacheDeployment.Servers.GetAllConfiguredNodes())
                {
                    NCache.ServerName = node.IpAddress.ToString();

                    ICacheServer         cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                    ConfigurationVersion config      = cacheServer.GetConfigurationVersion(cacheName);
                    if (configId.Equals(configId))
                    {
                        configId = config.ConfigID;
                    }

                    else if (!configId.Equals(config.ConfigID, StringComparison.InvariantCultureIgnoreCase))
                    {
                        throw new VersionException("same name cache is already registered on node : " + node.IpAddress, 0);
                    }

                    if (configVersion == -1)
                    {
                        configVersion = config.ConfigVersion;
                    }
                    else if (configVersion != config.ConfigVersion)
                    {
                        throw new VersionException("There is a configuration mismatch for caches : " + cacheName, 0);
                    }

                    if (deploymentVersion == -1)
                    {
                        deploymentVersion = config.DeploymentVersion;
                    }
                    else if (deploymentVersion != config.DeploymentVersion)
                    {
                        throw new Exception("Deployment version is not same on all nodes");
                    }

                    cacheServer.Dispose();
                }
            }
            return(true);
        }
Beispiel #14
0
        /// <summary>
        /// initilaise
        /// </summary>
        protected virtual void Initialize()
        {
            CacheService cacheService = null;

            cacheService = new NCacheRPCService(_address, _port);
            try
            {
                _server = cacheService.GetCacheServer(TimeSpan.FromSeconds(7));
            }
            finally
            {
                cacheService.Dispose();
            }
        }
        public static void StopCache(string cacheId, string serverName, int port, string userId, string password)
        {
            ICacheServer cs = null;

            CacheService cacheService = new NCacheRPCService(null);

            try
            {
                cacheService.ServerName = serverName;
                cacheService.Port       = port;
                cs = cacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                if (cs != null)
                {
                    cs.StopCache(cacheId);
                }
            }

            catch (SecurityException ex)
            {
                if (cs != null)
                {
                    cs.Dispose();
                    cs = null;
                }
                throw ex;
            }


            catch (Exception ex)
            {
                if (cs != null)
                {
                    cs.Dispose();
                    cs = null;
                }
                throw new ManagementException(ex.Message);
            }
            finally
            {
                if (cs != null)
                {
                    cs.Dispose();
                }
                cacheService.Dispose();
            }
        }
Beispiel #16
0
        public void VerifyLicense()
        {
            ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME);
            string            ipAddress = "this machine";
            ServerLicenseInfo serverLicenseInfo;

            try
            {
                if (string.IsNullOrEmpty(Server))
                {
                    serverLicenseInfo = new ServerLicenseInfo();
                }
                else
                {
                    NCache            = new NCacheRPCService("");
                    NCache.Port       = Port;
                    NCache.ServerName = Server;
                    ipAddress         = Server;
                    ICacheServer nCacheServer = null;
                    nCacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                    if (nCacheServer != null)
                    {
                        serverLicenseInfo = nCacheServer.GetServerLicenseInfo();
                    }
                    else
                    {
                        serverLicenseInfo = new ServerLicenseInfo();
                    }
                }
                OutputProvider.WriteLine("This product is registered to ");
                OutputProvider.WriteLine("User:        "******"Email:       " + serverLicenseInfo._email);
                OutputProvider.WriteLine("Company:     " + serverLicenseInfo._companyName);
                OutputProvider.WriteLine("Edition:     " + "NCache OpenSource ");

                OutputProvider.WriteLine("");
                OutputProvider.WriteLine("Licensed to use FREE of cost. Use As-is without support.");
            }
            catch (Exception ex)
            {
                OutputProvider.WriteLine(ex.ToString());
                return;
            }

            OutputProvider.WriteLine("\n");
        }
Beispiel #17
0
 private static void UpdateServerMappings(MappingConfiguration.Dom.MappingConfiguration mappingConfiguration, string[] nodes)
 {
     if (nodes != null && mappingConfiguration != null)
     {
         foreach (string node in nodes)
         {
             try
             {
                 NCacheRPCService NCache      = new NCacheRPCService(node);
                 ICacheServer     cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                 cacheServer.UpdateServerMappingConfig(mappingConfiguration);
                 cacheServer.Dispose();
             }
             catch (Exception ex)
             {
             }
         }
     }
 }
Beispiel #18
0
        private static MappingConfiguration.Dom.MappingConfiguration GetServerMappings(string[] nodes)
        {
            if (nodes != null)
            {
                List <Mapping> managementIPMapping = new List <Mapping>();
                List <Mapping> clientIPMapping     = new List <Mapping>();
                foreach (string node in nodes)
                {
                    try
                    {
                        NCacheRPCService NCache      = new NCacheRPCService(node);
                        ICacheServer     cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                        Hashtable serverIPMapping = cacheServer.GetServerMappingForConfig();
                        if (serverIPMapping.Contains("management-ip-mapping"))
                        {
                            managementIPMapping.Add((Mapping)serverIPMapping["management-ip-mapping"]);
                        }
                        if (serverIPMapping.Contains("client-ip-mapping"))
                        {
                            clientIPMapping.Add((Mapping)serverIPMapping["client-ip-mapping"]);
                        }
                        cacheServer.Dispose();
                    }
                    catch (Exception ex)
                    {
                    }
                }
                if (managementIPMapping.Count == 0 && clientIPMapping.Count == 0)
                {
                    return(null);
                }
                MappingConfiguration.Dom.MappingConfiguration mappingConfiguration = new MappingConfiguration.Dom.MappingConfiguration();
                mappingConfiguration.ManagementIPMapping = new ServerMapping(managementIPMapping.ToArray());
                mappingConfiguration.ClientIPMapping     = new ServerMapping(clientIPMapping.ToArray());

                return(mappingConfiguration);
            }
            return(null);
        }
Beispiel #19
0
 public static void ConveyCommandToAllRunningCacheHost(ConfiguredCacheInfo[] cacheHostprocesses, string Action, string server, IOutputConsole OutputProvider)
 {
     foreach (ConfiguredCacheInfo cacheHost in cacheHostprocesses)
     {
         NCacheRPCService nCache = new NCacheRPCService("");
         nCache.Port       = cacheHost.ManagementPort;
         nCache.ServerName = server;
         if (nCache.Port > 0)
         {
             ICacheServer hostService = nCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
             if (Action.ToLower().Equals("start"))
             {
                 OutputProvider.WriteLine("Starting monitoring on server {0}:{1}.", nCache.ServerName, nCache.Port);
                 hostService.StartMonitoringActivity();
             }
             else if (Action.ToLower().Equals("stop"))
             {
                 OutputProvider.WriteLine("Stop monitoring on server {0}:{1}.", nCache.ServerName, nCache.Port);
                 hostService.StopMonitoringActivity();
             }
             hostService.PublishActivity();
         }
     }
 }
Beispiel #20
0
        /// <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();
                }
            }
        }
Beispiel #21
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 #22
0
        private static CacheServerList GetSeversPriorityList()
        {
            Dictionary <int, Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer> serversPriorityList = new Dictionary <int, Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer>();

            Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer server = new Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer();
            if (config != null)
            {
                List <Address> hosts = config.CacheDeployment.Servers.GetAllConfiguredNodes();
                Alachisoft.NCache.Management.ICacheServer cs;
                NCacheRPCService cache = new NCacheRPCService("");
                int priority           = 0;
                int port = -1;
                foreach (Address addr in hosts)
                {
                    try
                    {
                        string address = addr.IpAddress.ToString();
                        if (_managementIPMapping != null)
                        {
                            if (_managementIPMapping.ContainsKey(address))
                            {
                                Mapping endPoint = _managementIPMapping[address];
                                address = endPoint.PublicIP;
                                port    = endPoint.PublicPort;
                            }
                        }
                        server = new Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer();
                        string tempClientServerName = "";
                        cache.ServerName = address;
                        if (port != -1)
                        {
                            cache.Port = port;
                        }
                        cs = cache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                        Management.Management.BindedIpMap bindedIps = cs.BindedIp();

                        if (bindedIps.Map.Contains(Alachisoft.NCache.Management.CacheServer.Channel.SocketServer))
                        {
                            tempClientServerName = bindedIps.Map[Alachisoft.NCache.Management.CacheServer.Channel.SocketServer].ToString();
                        }

                        if (!string.IsNullOrEmpty(tempClientServerName))
                        {
                            server.ServerName = tempClientServerName;
                        }
                        else
                        {
                            server.ServerName = addr.IpAddress.ToString();
                        }

                        server.Priority = priority;

                        serversPriorityList.Add(priority, server);
                        priority++;
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine("Error while adding server :" + cache.ServerName + ":" + cache.Port + "\nException : " + ex.Message);
                    }
                }
            }

            if (serversPriorityList.Count < 1)
            {
                server.ServerName = _server;
                server.Priority   = 0;
                serversPriorityList.Add(0, server);
            }

            return(new CacheServerList(serversPriorityList));
        }
Beispiel #23
0
        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");
        }
Beispiel #24
0
        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);
                    }
                }
            }
        }
Beispiel #25
0
        private static void UpdateConfigs()
        {
            try
            {
                if (ValidateNCacheService())
                {
                    if (cParam.UpdateServerConfig)
                    {
                        if (config != null)
                        {
                            if (config.CacheDeployment.ClientNodes == null)
                            {
                                config.CacheDeployment.ClientNodes = new ClientNodes();
                            }

                            if (config.CacheDeployment.ClientNodes.NodesList == null)
                            {
                                config.CacheDeployment.ClientNodes.NodesList = new List <ClientNode>();
                            }
                        }

                        ClientNode clientNod = new ClientNode();
                        clientNod.Name = cParam.ClientNode;

                        if (config != null)
                        {
                            config.CacheDeployment.ClientNodes.NodesList.Add(clientNod);
                        }


                        foreach (string node in currentServerNodes)
                        {
                            NCache.ServerName = node;
                            cacheServer       = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                            cacheServer.ApplyCacheConfiguration(cParam.CacheId, config, false);
                        }
                        string oldClientNode             = null;
                        ClientConfiguration clientConfig = null;
                        if (currentClientNodes.Count > 0)
                        {
                            oldClientNode     = currentClientNodes[0];
                            NCache.ServerName = oldClientNode;
                            cacheServer       = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                            clientConfig      = cacheServer.GetClientConfiguration(cParam.CacheId);
                        }
                    }

                    NCacheRPCService nCache = new NCacheRPCService("");
                    nCache.ServerName = cParam.ClientNode; //clientNode;
                    cacheServer       = nCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                    string xml = string.Empty;
                    cacheServer.UpdateClientServersList(cParam.CacheId, GetSeversPriorityList(), "0");
                    ClientConfiguration clientConfiguration = cacheServer.GetClientConfiguration(cParam.CacheId);
                    CacheConfiguration  cacheConfig         = new CacheConfiguration();
                    cacheConfig = clientConfiguration.CacheConfigurationsMap[cParam.CacheId.ToLower()];
                    //if flag of get mapping is true
                    if (cParam.AcquireServerMapping && _clientIPMapping != null)
                    {
                        if (cacheConfig.ServerMapping == null)
                        {
                            cacheConfig.ServerMapping = new ServerMapping();
                        }
                        cacheConfig.ServerMapping = new ServerMapping(Management.Management.Util.ManagementWorkFlow.GetUpdatedMappingList(cacheConfig.ServerMapping.MappingServers, _clientIPMapping.MappingServers));
                    }

                    clientConfiguration.CacheConfigurationsMap.Remove(cParam.CacheId);
                    clientConfiguration.CacheConfigurationsMap.Add(cParam.CacheId, cacheConfig);
                    if (config != null)
                    {
                        if (config.CacheDeployment.Servers.NodeIdentities != null && config.CacheDeployment.Servers.NodeIdentities.Count != 0)
                        {
                            cacheConfig.ServersPriorityList.Clear();

                            foreach (NodeIdentity identity in config.CacheDeployment.Servers.NodeIdentities)
                            {
                                Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer server = new Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer();
                                server.ServerName = identity.NodeName;
                                server.Priority   = identity.NodePriority;
                                cacheConfig.ServersPriorityList[identity.NodePriority - 1] = server;
                            }
                        }
                    }
                    cacheServer.UpdateClientConfiguration(cParam.CacheId, clientConfiguration);

                    Console.WriteLine("{0}' successfully added as client node to cache '{1}' on server {2}:{3}.",
                                      cParam.ClientNode, cParam.CacheId, NCache.ServerName, NCache.Port);
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error: {0}", ex.Message);
            }
        }
Beispiel #26
0
        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);
             *
             *      }
             *  }
             *
             * }
             * */
        }
Beispiel #27
0
        /// <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();
                }
            }
        }
Beispiel #28
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 #29
0
        /// <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();
            }
        }
Beispiel #30
0
        /// <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();
                }
            }
        }