Пример #1
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();
     }
 }
Пример #2
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;
     }
 }
Пример #3
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);
            }
        }
Пример #4
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);
        }
Пример #5
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;
        }
Пример #6
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)
             {
             }
         }
     }
 }
Пример #7
0
        /// <summary>
        /// The main entry point for the tool.
        /// </summary>
        public static 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();
            }
        }