Exemple #1
0
        public object Clone()
        {
            CacheConfiguration configuration = new CacheConfiguration();

            configuration.BindIp       = _bindIp;
            configuration._cacheId     = _cacheId;
            configuration._loadBalance = _loadBalance;
            configuration.Servers      = Servers != null?Servers.Clone() as CacheServer[] : null;

            configuration._serverRuntimeContext = _serverRuntimeContext;
            configuration._serverMapping        = _serverMapping != null?_serverMapping.Clone() as ServerMapping : null;

            configuration._enableClientLogs       = _enableClientLogs;
            configuration._logLevel               = _logLevel;
            configuration._enableServerPriorities = _enableServerPriorities;
            return(configuration);
        }
Exemple #2
0
        public object Clone()
        {
            CacheConfiguration configuration = new CacheConfiguration();

            configuration.BindIp                    = _bindIp;
            configuration._cacheId                  = _cacheId;
            configuration._clientCacheId            = _clientCacheId;
            configuration._clientCacheSyncMode      = _clientCacheSyncMode;
            configuration._defaultReadThruProvider  = _defaultReadThruProvider;
            configuration._defaultWriteThruProvider = _defaultWriteThruProvider;
            configuration._loadBalance              = _loadBalance;

            configuration.Servers = Servers != null?Servers.Clone() as CacheServer[] : null;

            configuration._serverRuntimeContext = _serverRuntimeContext;
            configuration._serverMapping        = _serverMapping != null?_serverMapping.Clone() as ServerMapping : null;

            configuration._enableClientLogs = _enableClientLogs;
            configuration._logLevel         = _logLevel;
            return(configuration);
        }
Exemple #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);
            }
        }
        public static void UpdateServerNodes(string cacheId, string[] servers, ref string xml,  bool loadBalance)
        {
            LoadXml();

            cacheId = cacheId.ToLower();
            CacheConfiguration cacheConfiguration = null;

            if (_configuration != null && _configuration.CacheConfigurationsMap != null)
            {
                if (!_configuration.CacheConfigurationsMap.TryGetValue(cacheId, out cacheConfiguration))
                {
                    cacheConfiguration = new CacheConfiguration();
                    cacheConfiguration.CacheId = cacheId;

                    _configuration.CacheConfigurationsMap.Add(cacheId, cacheConfiguration);
                }
            }

            cacheConfiguration.ServersPriorityList.Clear();

            for (int i = 0; i < servers.Length; i++)
            {
                Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer server = new Alachisoft.NCache.Management.ClientConfiguration.Dom.CacheServer();
                server.ServerName = servers[i];
                server.Priority = i;
                cacheConfiguration.ServersPriorityList[i] = server;
            }

            
            cacheConfiguration.LoadBalance = loadBalance;

            SaveConfiguration();
            
            xml = string.Empty;
        }
        public static void UpdateServerNodes(string cacheId, Alachisoft.NCache.Management.ClientConfiguration.CacheServerList serversPriorityList, RtContextValue serverRuntimeContext)
        {
            LoadXml();

            if (_configuration != null)
            {
                if (_configuration.CacheConfigurationsMap == null)
                    _configuration.CacheConfigurationsMap = new Dictionary<string, CacheConfiguration>();

                cacheId = cacheId.ToLower();
                CacheConfiguration cacheConfiguration = null;

                if (!_configuration.CacheConfigurationsMap.TryGetValue(cacheId, out cacheConfiguration))
                {
                    cacheConfiguration = new CacheConfiguration();
                    cacheConfiguration.CacheId = cacheId;
                    cacheConfiguration.BindIp = bindIp;
                    cacheConfiguration.ServerRuntimeContext = serverRuntimeContext;
                    _configuration.CacheConfigurationsMap.Add(cacheId, cacheConfiguration);
                }

               

                cacheConfiguration.ServersPriorityList = serversPriorityList.ServersList;
            }

            SaveConfiguration();
        }
        public static void AddCache(string cacheId, CacheServerConfig config)
        {
            LoadXml();

            if (_configuration != null)
            {
                if (_configuration.CacheConfigurationsMap == null)
                    _configuration.CacheConfigurationsMap = new Dictionary<string, CacheConfiguration>();

                if (!_configuration.CacheConfigurationsMap.ContainsKey(cacheId.ToLower()))
                {
                    CacheConfiguration cacheConfiguration = new CacheConfiguration();
                    cacheConfiguration.CacheId = cacheId;

                    if (config.Cluster != null && config.Cluster.Nodes != null)
                    {
                        if (config.Cluster.Nodes.Count != 1)
                        {
                            // Extract server names from config
                            string[] serverList = new string[config.Cluster.NodeIdentities.Count];
                            for (int i = 0; i < serverList.Length; i++)
                            {
                                serverList[i] = config.Cluster.NodeIdentities[i].NodeName;
                            }

                            // Sort priority list i.e. local node at top
                            string[] copyServerList = new string[serverList.Length];
                            for (int i = 0; i < serverList.Length; i++)
                            {
                                if (serverList[i] == cacheConfiguration.BindIp)
                                {
                                    copyServerList[0] = serverList[i];
                                    cacheConfiguration.AddServer(cacheConfiguration.BindIp, 0);
                                }
                                else if (String.IsNullOrEmpty(copyServerList[0]))
                                {
                                    copyServerList[i + 1] = serverList[i];
                                    cacheConfiguration.AddServer(serverList[i], i + 1);
                                }
                                else
                                {
                                    copyServerList[i] = serverList[i];
                                    cacheConfiguration.AddServer(serverList[i], i);
                                }
                            }
                        }
                        else
                            cacheConfiguration.AddServer(config.Cluster.NodeIdentities[0].NodeName, 0);
                    }
                    else
                    {
                        cacheConfiguration.AddLocalServer();
                    }
                   
                    _configuration.CacheConfigurationsMap[cacheId.ToLower()] = cacheConfiguration;
                }
            }

            SaveConfiguration();
        }
        public static void AddCache(string cacheId, RtContextValue serverRuntimeContext)
        {
            LoadXml();

            if (_configuration != null)
            {
                if (_configuration.CacheConfigurationsMap == null)
                    _configuration.CacheConfigurationsMap = new Dictionary<string, CacheConfiguration>();

                if (!_configuration.CacheConfigurationsMap.ContainsKey(cacheId.ToLower()))
                {
                    CacheConfiguration cacheConfiguration = new CacheConfiguration();
                    cacheConfiguration.CacheId = cacheId;
                    cacheConfiguration.ServerRuntimeContext = serverRuntimeContext;
                    cacheConfiguration.AddLocalServer();
                    _configuration.CacheConfigurationsMap[cacheId.ToLower()] = cacheConfiguration;
                }
            }

            SaveConfiguration();
        }
 public object Clone()
 {
     CacheConfiguration configuration = new CacheConfiguration();
     configuration.BindIp = _bindIp;
     configuration._cacheId = _cacheId;
     configuration._loadBalance = _loadBalance;
     configuration.Servers = Servers != null ? Servers.Clone() as CacheServer[] : null;
     configuration._serverRuntimeContext = _serverRuntimeContext;
     configuration._serverMapping = _serverMapping != null ? _serverMapping.Clone() as ServerMapping : null;
     configuration._enableClientLogs = _enableClientLogs;
     configuration._logLevel = _logLevel;
     configuration._enableServerPriorities = _enableServerPriorities;
     return configuration;
 }