public object Clone()
        {
            ClientConfiguration configuration = new ClientConfiguration();
            configuration.CacheConfigurations = CacheConfigurations != null ? CacheConfigurations.Clone() as CacheConfiguration[] : null;
            configuration._nodeConfig = _nodeConfig != null ? _nodeConfig.Clone() as NodeConfiguration : null;
            configuration.BindIp = _bindIp;

            return configuration;
        }
Example #2
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);
            }
        }
Example #3
0
        private static CacheServerConfig GetCacheConfigThroughClientConfig(string cacheName, int port, Runtime.CacheManagement.CacheContext context)
        {
            CacheServerConfig cacheServerConfig = null;

            ClientConfiguration.Dom.CacheServer[] serverNodes = null;
            ICacheServer cacheServer = null;

            CacheService cacheService = GetCacheService(context);

            if (port != 0)
            {
                cacheService.Port = port;
            }

            try
            {
                //Get Server Info from Client.nconf for specified cacheName
                ClientConfiguration.Dom.ClientConfiguration clientConfiguration = ClientConfiguration.ClientConfigManager.GetClientConfiguration(cacheName);
                if (clientConfiguration != null)
                {
                    Dictionary <string, CacheConfiguration> cacheConfigurationMap = clientConfiguration.CacheConfigurationsMap;
                    CacheConfiguration cacheClientConfiguration = null;

                    try
                    {
                        cacheClientConfiguration = cacheConfigurationMap[cacheName];
                    }
                    catch (System.Collections.Generic.KeyNotFoundException ex)
                    {
                    }

                    if (cacheClientConfiguration == null)
                    {
                        throw new ManagementException("cache not found in " + config);
                    }

                    serverNodes = cacheClientConfiguration.Servers;

                    foreach (ClientConfiguration.Dom.CacheServer node in serverNodes)
                    {
                        try
                        {
                            cacheService.ServerName = node.ServerName;
                            cacheServer             = cacheService.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                            if (cacheServer != null)
                            {
                                cacheServerConfig = cacheServer.GetCacheConfiguration(cacheName);
                                //dispose the server
                                cacheServer.Dispose();
                                cacheServer = null;

                                if (cacheServerConfig != null)
                                {
                                    break;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
                else
                {
                    throw new ManagementException("error while fetching info from " + config);
                }
            }
            finally
            {
                if (cacheServer != null)
                {
                    cacheServer.Dispose();
                }
                if (cacheService != null)
                {
                    cacheService.Dispose();
                }
            }
            return(cacheServerConfig);
        }
        public static void UpdateCacheConfiguration(string cacheId, ClientConfiguration.Dom.ClientConfiguration configuration)
        {
            LoadXml();

            if (_configuration == null)
                _configuration = new Alachisoft.NCache.Management.ClientConfiguration.Dom.ClientConfiguration();

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

            cacheId = cacheId.ToLower();
            _configuration.NodeConfiguration = configuration.NodeConfiguration.Clone() as NodeConfiguration;
            CacheConfiguration cacheConfiguration = null;
            if (configuration.CacheConfigurationsMap.TryGetValue(cacheId, out cacheConfiguration))
            {
                
                cacheConfiguration.BindIp = configuration.BindIp;
                _configuration.CacheConfigurationsMap[cacheId] = cacheConfiguration.Clone() as CacheConfiguration;
            }

            SaveConfiguration();
        }