Beispiel #1
0
        /// <summary>
        /// Loads and returns all cache configurations from the configuration file.
        /// </summary>
        static public CacheServerConfig[] GetConfiguredCaches()
        {
            if (FileName.Length == 0)
            {
                throw new ManagementException("Can not locate cache configuration file. Installation might be corrupt.");
            }
            try
            {
                ConfigurationBuilder builder = new ConfigurationBuilder(FileName);
                builder.RegisterRootConfigurationObject(typeof(Alachisoft.NCache.Config.NewDom.CacheServerConfig));
                builder.ReadConfiguration();
                Alachisoft.NCache.Config.NewDom.CacheServerConfig[] newCaches = new Alachisoft.NCache.Config.NewDom.CacheServerConfig[builder.Configuration.Length];
                builder.Configuration.CopyTo(newCaches, 0);

                return(convertToOldDom(newCaches));
            }
            catch (ManagementException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new ManagementException(e.Message, e);
            }
        }
Beispiel #2
0
        public void RegisterCache(Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig, int port, string cacheId, bool isHotApply, bool isOverwrite, string server)
        {
            if (port != -1)
            {
                NCache.Port = port;
            }

            if (port == -1)
            {
                NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
            }
            if (server != null && server != string.Empty)
            {
                NCache.ServerName = server;
            }

            cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

            if (cacheServer != null)
            {
                if (serverConfig.CacheSettings.CacheType == "clustered-cache")
                {
                    foreach (Address node in serverConfig.CacheDeployment.Servers.GetAllConfiguredNodes())
                    {
                        NCache.ServerName = node.IpAddress.ToString();
                        try
                        {
                            cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                            cacheServer.RegisterCache(cacheId, serverConfig, "", isOverwrite, isHotApply);
                        }
                        catch (Exception ex)
                        {
                            Console.Error.WriteLine("Failed to Configure Backing Source on '{0}'. ", NCache.ServerName);
                            Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);
                        }
                        finally
                        {
                            cacheServer.Dispose();
                        }
                    }
                }
                else
                {
                    try
                    {
                        cacheServer.RegisterCache(cacheId, serverConfig, "", isOverwrite, isHotApply);
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine("Failed to Configure Backing Source on '{0}'. ", NCache.ServerName);
                        Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);
                    }
                    finally
                    {
                        cacheServer.Dispose();
                    }
                }
            }
        }
Beispiel #3
0
        private static CacheServerConfig[] LoadConfig(string fileName)
        {
            ConfigurationBuilder builder = new ConfigurationBuilder(fileName);

            builder.RegisterRootConfigurationObject(typeof(Alachisoft.NCache.Config.NewDom.CacheServerConfig));
            builder.ReadConfiguration();
            Alachisoft.NCache.Config.NewDom.CacheServerConfig[] newCaches = new Alachisoft.NCache.Config.NewDom.CacheServerConfig[builder.Configuration.Length];
            builder.Configuration.CopyTo(newCaches, 0);

            return(convertToOldDom(newCaches));
        }
Beispiel #4
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);
        }
        /// <summary>
        /// Register cache
        /// </summary>
        /// <param name="cacheId"></param>
        /// <param name="props"></param>
        /// <param name="overwrite"></param>
        /// <exception cref="ArgumentNullException">cacheId is a null reference (Nothing in Visual Basic).</exception>
        ///

        public bool RegisterCache(string cacheId, Alachisoft.NCache.Config.NewDom.CacheServerConfig config, string partId, bool overwrite, bool hotApply)

        {
            //overload 2
            ManagementCommand command = GetManagementCommand(ManagementUtil.MethodName.RegisterCache, 2);

            command.Parameters.AddParameter(cacheId);
            command.Parameters.AddParameter(config);
            command.Parameters.AddParameter(partId);
            command.Parameters.AddParameter(overwrite);
            command.Parameters.AddParameter(hotApply);

            return((bool)ExecuteCommandOnCacehServer(command));
        }
        private static List <Alachisoft.NCache.Config.NewDom.CacheServerConfig> convertToNewDom(List <CacheServerConfig> oldCacheConfigsList)
        {
            List <Alachisoft.NCache.Config.NewDom.CacheServerConfig> newCacheConfigsList = new List <Alachisoft.NCache.Config.NewDom.CacheServerConfig>();
            IEnumerator itr = oldCacheConfigsList.GetEnumerator();

            while (itr.MoveNext())
            {
                Alachisoft.NCache.Config.Dom.CacheServerConfig tempOldCacheConfig = (Alachisoft.NCache.Config.Dom.CacheServerConfig)itr.Current;
                try
                {
                    Alachisoft.NCache.Config.NewDom.CacheServerConfig tempNewCacheConfig = Alachisoft.NCache.Config.NewDom.DomHelper.convertToNewDom(tempOldCacheConfig);
                    newCacheConfigsList.Add(tempNewCacheConfig);
                }
                catch (Exception)
                {
                }
            }
            return(newCacheConfigsList);
        }
Beispiel #7
0
        public static Alachisoft.NCache.Config.Dom.CacheServerConfig convertToOldDom(Alachisoft.NCache.Config.NewDom.CacheServerConfig newDom)
        {
            Alachisoft.NCache.Config.Dom.CacheServerConfig oldDom = null;
            try
            {
                if (newDom != null)
                {
                    oldDom = new Alachisoft.NCache.Config.Dom.CacheServerConfig();
                    if (newDom.CacheSettings != null)
                    {
                        oldDom.Name          = newDom.Name;
                        oldDom.InProc        = newDom.CacheSettings.InProc;
                        oldDom.ConfigVersion = newDom.ConfigVersion;
                        oldDom.ConfigID      = newDom.ConfigID;
                        oldDom.LastModified  = newDom.CacheSettings.LastModified;
                        oldDom.DataFormat    = newDom.CacheSettings.DataFormat;

                        if (newDom.CacheSettings.Log != null)
                        {
                            oldDom.Log = newDom.CacheSettings.Log;
                        }
                        else
                        {
                            oldDom.Log = new Alachisoft.NCache.Config.Dom.Log();
                        }

                        if (newDom.CacheSettings.PerfCounters != null)
                        {
                            oldDom.PerfCounters = newDom.CacheSettings.PerfCounters;
                        }
                        else
                        {
                            oldDom.PerfCounters = new Alachisoft.NCache.Config.Dom.PerfCounters();
                        }

                        if (newDom.CacheSettings.ClientDeathDetection != null)
                        {
                            oldDom.ClientDeathDetection = newDom.CacheSettings.ClientDeathDetection;
                        }
                        else
                        {
                            oldDom.ClientDeathDetection = new Alachisoft.NCache.Config.Dom.ClientDeathDetection();
                        }


                        if (newDom.CacheSettings.BackingSource != null)
                        {
                            oldDom.BackingSource = newDom.CacheSettings.BackingSource;
                        }



                        if (newDom.CacheSettings.Notifications != null)
                        {
                            oldDom.Notifications = newDom.CacheSettings.Notifications;
                        }
                        else
                        {
                            oldDom.Notifications = new Alachisoft.NCache.Config.Dom.Notifications();
                        }
                        if (newDom.CacheSettings.Cleanup != null)
                        {
                            oldDom.Cleanup = newDom.CacheSettings.Cleanup;
                        }
                        else
                        {
                            oldDom.Cleanup = new Alachisoft.NCache.Config.Dom.Cleanup();
                        }

                        if (newDom.CacheSettings.Storage != null)
                        {
                            oldDom.Storage = newDom.CacheSettings.Storage;
                        }
                        else
                        {
                            oldDom.Storage = new Alachisoft.NCache.Config.Dom.Storage();
                        }

                        if (newDom.CacheSettings.EvictionPolicy != null)
                        {
                            oldDom.EvictionPolicy = newDom.CacheSettings.EvictionPolicy;
                        }
                        else
                        {
                            oldDom.EvictionPolicy = new Alachisoft.NCache.Config.Dom.EvictionPolicy();
                        }

                        if (newDom.CacheSettings.SynchronizationStrategy != null)
                        {
                            oldDom.SynchronizationStrategy = newDom.CacheSettings.SynchronizationStrategy;
                        }


                        if (newDom.CacheSettings.CacheTopology != null)
                        {
                            oldDom.CacheType = newDom.CacheSettings.CacheType;
                        }

                        if (oldDom.CacheType.Equals("clustered-cache"))
                        {
                            if (newDom.CacheDeployment != null)
                            {
                                if (oldDom.Cluster == null)
                                {
                                    oldDom.Cluster = new Alachisoft.NCache.Config.Dom.Cluster();
                                }
                                string topology = newDom.CacheSettings.CacheTopology.Topology;

                                if (topology != null)
                                {
                                    topology = topology.ToLower();

                                    if (topology.Equals("replicated"))
                                    {
                                        topology = "replicated-server";
                                    }

                                    else if (topology.Equals("partitioned"))
                                    {
                                        topology = "partitioned-server";
                                    }

                                    else if (topology.Equals("partitioned-replica"))
                                    {
                                        topology = "partitioned-replicas-server";
                                    }

                                    else if (topology.Equals("mirrored"))
                                    {
                                        topology = "mirror-server";
                                    }

                                    else if (topology.Equals("local"))
                                    {
                                        topology = "local-cache";
                                    }

                                    else if (topology.Equals("client-cache"))
                                    {
                                        topology = "client-cache";
                                    }
                                }

                                oldDom.Cluster.Topology         = topology;
                                oldDom.Cluster.OpTimeout        = newDom.CacheSettings.CacheTopology.ClusterSettings.OpTimeout;
                                oldDom.Cluster.StatsRepInterval = newDom.CacheSettings.CacheTopology.ClusterSettings.StatsRepInterval;

                                if (oldDom.Cluster.Channel == null)
                                {
                                    oldDom.Cluster.Channel = new Alachisoft.NCache.Config.Dom.Channel();
                                }

                                oldDom.Cluster.Channel.TcpPort                 = newDom.CacheSettings.CacheTopology.ClusterSettings.Channel.TcpPort;
                                oldDom.Cluster.Channel.PortRange               = newDom.CacheSettings.CacheTopology.ClusterSettings.Channel.PortRange;
                                oldDom.Cluster.Channel.ConnectionRetries       = newDom.CacheSettings.CacheTopology.ClusterSettings.Channel.ConnectionRetries;
                                oldDom.Cluster.Channel.ConnectionRetryInterval = newDom.CacheSettings.CacheTopology.ClusterSettings.Channel.ConnectionRetryInterval;

                                if (newDom.CacheSettings.CacheTopology.ClusterSettings.ReplicationStrategy != null)
                                {
                                    oldDom.ReplicationStrategy = newDom.CacheSettings.CacheTopology.ClusterSettings.ReplicationStrategy;
                                }
                                else
                                {
                                    oldDom.ReplicationStrategy = new Alachisoft.NCache.Config.Dom.ReplicationStrategy();
                                }

                                oldDom.Cluster.Channel.InitialHosts = createInitialHosts(newDom.CacheDeployment.Servers.NodesList, newDom.CacheSettings.CacheTopology.ClusterSettings.Channel.TcpPort);
                                oldDom.Cluster.Channel.NumInitHosts = newDom.CacheDeployment.Servers.NodesList.Count;
                                oldDom.Cluster.ActiveMirrorNode     = newDom.CacheDeployment.Servers.ActiveMirrorNode;

                                if (newDom.CacheDeployment.ClientNodes != null)
                                {
                                    if (oldDom.ClientNodes == null)
                                    {
                                        oldDom.ClientNodes = new Alachisoft.NCache.Config.Dom.ClientNodes();
                                    }
                                    oldDom.ClientNodes = newDom.CacheDeployment.ClientNodes;
                                }
                                oldDom.DeploymentVersion = newDom.CacheDeployment.DeploymentVersion;
                            }
                        }

                        if (newDom.CacheSettings.Security != null)
                        {
                            oldDom.Security = newDom.CacheSettings.Security;
                        }
                        if (newDom.CacheSettings.AutoLoadBalancing != null)
                        {
                            oldDom.AutoLoadBalancing = newDom.CacheSettings.AutoLoadBalancing;
                        }

                        if (newDom.CacheSettings.ClientActivityNotification != null)
                        {
                            oldDom.ClientActivityNotification = newDom.CacheSettings.ClientActivityNotification;
                        }
                        oldDom.IsRunning    = newDom.IsRunning;
                        oldDom.IsRegistered = newDom.IsRegistered;
                        oldDom.IsExpired    = newDom.IsExpired;
                        oldDom.DataFormat   = newDom.CacheSettings.DataFormat;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("DomHelper.convertToOldDom" + ex.Message);
            }
            return(oldDom);
        }
Beispiel #8
0
        public static void Run(string[] args)
        {
            try
            {
                object param = new RemoveClientNodeParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                cParam = (RemoveClientNodeParam)param;
                if (cParam.IsUsage)
                {
                    AssemblyUsage.PrintLogo(cParam.IsLogo);
                    AssemblyUsage.PrintUsage();
                    return;
                }

                if (!ValidateParameters()) return;

                if (cParam.Port != -1)
                    NCache.Port = cParam.Port;

                if (cParam.Port == -1) NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;

                if (cParam.Server != null || cParam.Server != string.Empty)
                {
                    NCache.ServerName = cParam.Server;
                }

                cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                config = cacheServer.GetNewConfiguration(cParam.CacheId);
                string getClusterIp = cacheServer.GetClusterIP();
                if (config == null)
                {
                    Console.Error.WriteLine("Error: The cache doesnot exist.");
                    return;
                }
                if (config.CacheSettings.CacheType == "clustered-cache")
                {

                    Console.WriteLine("Removing client node '{0}' from cache '{1}' on server '{2}:{3}'.",
                            cParam.ClientNode, cParam.CacheId, getClusterIp, NCache.Port);
                    foreach (Address node in config.CacheDeployment.Servers.GetAllConfiguredNodes())
                    {
                        currentServerNodes.Add(node.IpAddress.ToString());
                    }
                }
                else
                {
                    Console.Error.WriteLine("Error: Client nodes cannot be removed from local caches");
                    return;
                }

                if (UpdateConfigs())
                {
                    Console.WriteLine("Client node '{0}' successfully removed from cache '{1}' on server {2}:{3}.",
                        cParam.ClientNode, cParam.CacheId, getClusterIp, NCache.Port);
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error: {0}", ex.Message);
            }
            finally
            {
                if(cacheServer!=null)
                cacheServer.Dispose();
            }
        }
Beispiel #9
0
 public void Deserialize(Runtime.Serialization.IO.CompactReader reader)
 {
     _updatedCacheConfig = (Alachisoft.NCache.Config.NewDom.CacheServerConfig)reader.ReadObject();
     _affectedNodesList  = (ArrayList)reader.ReadObject();
     _affectedPartitions = (ArrayList)reader.ReadObject();
 }
Beispiel #10
0
        /// <summary>
        /// The main entry point for the tool.
        /// </summary>
        static public void Run(string[] args)
        {
            string failedNodes = string.Empty;

            NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
            Alachisoft.NCache.Config.NewDom.CacheServerConfig[] caches = null;
            ICacheServer cacheServer = null;

            Alachisoft.NCache.Config.NewDom.CacheServerConfig _cacheConfig = null;

            try
            {
                object param = new ConfigureCacheParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                ccParam = (ConfigureCacheParam)param;

                if (ccParam.IsUsage)
                {
                    AssemblyUsage.PrintLogo(ccParam.IsLogo);
                    AssemblyUsage.PrintUsage();
                    return;
                }

                if (!ValidateParameters())
                {
                    return;
                }

                if (ccParam.Port != -1)
                {
                    NCache.Port = ccParam.Port;
                }

                if (ccParam.Port == -1)
                {
                    NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                }

                if (ccParam.Path != null && ccParam.Path != string.Empty)
                {
                    if (Path.HasExtension(ccParam.Path))
                    {
                        string extension = Path.GetExtension(ccParam.Path);

                        if (!extension.Equals(".ncconf") && !extension.Equals(".xml"))
                        {
                            throw new Exception("Incorrect file format. Only .ncconf and .xml are supported.");
                        }
                    }
                    else
                    {
                        throw new Exception("Incorrect configuration file path specified.");
                    }

                    ConfigurationBuilder builder = new ConfigurationBuilder(ccParam.Path);
                    builder.RegisterRootConfigurationObject(typeof(Alachisoft.NCache.Config.NewDom.CacheServerConfig));
                    builder.ReadConfiguration();

                    if (builder.Configuration != null)
                    {
                        caches = new Alachisoft.NCache.Config.NewDom.CacheServerConfig[builder.Configuration.Length];
                        builder.Configuration.CopyTo(caches, 0);
                    }
                    else
                    {
                        throw new Exception("Configuration cannot be loaded.");
                    }
                    ConfigurationValidator validator = new ConfigurationValidator();
                    bool _isConfigValidated          = validator.ValidateConfiguration(caches);

                    _cacheConfig = caches[0];

                    if (_cacheConfig.CacheSettings.Name == null)
                    {
                        _cacheConfig.CacheSettings.Name = ccParam.CacheId;
                    }

                    if (_cacheConfig.CacheSettings.Storage == null || _cacheConfig.CacheSettings.Storage.Size == -1)
                    {
                        throw new Exception("Cache size is not specified.");
                    }

                    if (_cacheConfig.CacheSettings.EvictionPolicy == null)
                    {
                        _cacheConfig.CacheSettings.EvictionPolicy                 = new EvictionPolicy();
                        _cacheConfig.CacheSettings.EvictionPolicy.Policy          = "priority";
                        _cacheConfig.CacheSettings.EvictionPolicy.DefaultPriority = "normal";
                        _cacheConfig.CacheSettings.EvictionPolicy.EvictionRatio   = 5;
                        _cacheConfig.CacheSettings.EvictionPolicy.Enabled         = true;
                    }

                    if (_cacheConfig.CacheSettings.Cleanup == null)
                    {
                        _cacheConfig.CacheSettings.Cleanup          = new Cleanup();
                        _cacheConfig.CacheSettings.Cleanup.Interval = 15;
                    }

                    if (_cacheConfig.CacheSettings.Log == null)
                    {
                        _cacheConfig.CacheSettings.Log = new Log();
                    }

                    if (_cacheConfig.CacheSettings.PerfCounters == null)
                    {
                        _cacheConfig.CacheSettings.PerfCounters         = new PerfCounters();
                        _cacheConfig.CacheSettings.PerfCounters.Enabled = true;
                    }

                    if (_cacheConfig.CacheSettings.CacheType == "clustered-cache")
                    {
                        if (_cacheConfig.CacheSettings.CacheTopology.ClusterSettings == null)
                        {
                            throw new Exception("Cluster settings not specified for the cluster cache.");
                        }

                        if (_cacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel == null)
                        {
                            throw new Exception("Cluster channel related settings not specified for cluster cache.");
                        }

                        if (_cacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel.TcpPort == -1)
                        {
                            throw new Exception("Cluster port not specified for cluster cache.");
                        }
                    }
                }
                else
                {
                    _SimpleCacheConfig.CacheSettings                                = new Alachisoft.NCache.Config.NewDom.CacheServerConfigSetting();
                    _SimpleCacheConfig.CacheSettings.Name                           = ccParam.CacheId;
                    _SimpleCacheConfig.CacheSettings.Storage                        = new Alachisoft.NCache.Config.Dom.Storage();
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy                 = new EvictionPolicy();
                    _SimpleCacheConfig.CacheSettings.Cleanup                        = new Cleanup();
                    _SimpleCacheConfig.CacheSettings.Log                            = new Log();
                    _SimpleCacheConfig.CacheSettings.PerfCounters                   = new PerfCounters();
                    _SimpleCacheConfig.CacheSettings.PerfCounters.Enabled           = true;
                    _SimpleCacheConfig.CacheSettings.Storage.Type                   = "heap";
                    _SimpleCacheConfig.CacheSettings.Storage.Size                   = ccParam.CacheSize;
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy.Policy          = "priority";
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy.DefaultPriority = "normal";
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy.EvictionRatio   = 5;
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy.Enabled         = false;
                    _SimpleCacheConfig.CacheSettings.Cleanup.Interval               = 15;
                    _SimpleCacheConfig.CacheSettings.CacheTopology                  = new Alachisoft.NCache.Config.NewDom.CacheTopology();

                    if (string.IsNullOrEmpty(ccParam.Topology))
                    {
                        _SimpleCacheConfig.CacheSettings.CacheTopology.Topology = "Local";
                    }
                    else
                    {
                        _SimpleCacheConfig.CacheSettings.CacheTopology.Topology = ccParam.Topology;
                    }

                    if (ccParam.IsInProc && _SimpleCacheConfig.CacheSettings.CacheTopology.Topology.Equals("local-cache"))
                    {
                        _SimpleCacheConfig.CacheSettings.InProc = true;
                    }


                    if (_SimpleCacheConfig.CacheSettings.CacheType == "clustered-cache")
                    {
                        _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings         = new Alachisoft.NCache.Config.NewDom.Cluster();
                        _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel = new Alachisoft.NCache.Config.NewDom.Channel();

                        _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel.TcpPort  = ccParam.ClusterPort;
                        _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings.StatsRepInterval = 600;
                        if (_SimpleCacheConfig.CacheSettings.CacheTopology.Topology == "partitioned-replica")
                        {
                            _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel.PortRange = 2;
                        }
                    }

                    if (ccParam.EvictionPolicy != null && ccParam.EvictionPolicy != string.Empty)
                    {
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.Policy  = ccParam.EvictionPolicy;
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.Enabled = true;
                    }

                    if (ccParam.Ratio != -1)
                    {
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.EvictionRatio = ccParam.Ratio;
                    }

                    if (ccParam.CleanupInterval != -1)
                    {
                        _SimpleCacheConfig.CacheSettings.Cleanup.Interval = ccParam.CleanupInterval;
                    }

                    if (ccParam.DefaultPriority != null && ccParam.DefaultPriority != string.Empty)
                    {
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.DefaultPriority = ccParam.DefaultPriority;
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.Enabled         = true;
                    }
                    _cacheConfig = _SimpleCacheConfig;
                }
                try
                {
                    _cacheConfig.CacheSettings.Name = ccParam.CacheId;

                    if (_cacheConfig.CacheSettings.CacheType == "clustered-cache")
                    {
                        if (_cacheConfig.CacheDeployment == null)
                        {
                            _cacheConfig.CacheDeployment         = new Alachisoft.NCache.Config.NewDom.CacheDeployment();
                            _cacheConfig.CacheDeployment.Servers = new Alachisoft.NCache.Config.NewDom.ServersNodes();
                        }
                        _cacheConfig.CacheDeployment.Servers.NodesList = GetServers(ccParam.Server);
                    }

                    Dictionary <int, Management.ClientConfiguration.Dom.CacheServer> serverList = new Dictionary <int, Management.ClientConfiguration.Dom.CacheServer>();
                    int serverCount = 0;
                    foreach (Alachisoft.NCache.Config.NewDom.ServerNode node in GetServers(ccParam.Server))
                    {
                        Management.ClientConfiguration.Dom.CacheServer tempServer = new Management.ClientConfiguration.Dom.CacheServer();
                        tempServer.ServerName = node.IP;
                        serverList.Add(serverCount, tempServer);
                        serverCount++;
                    }
                    Management.ClientConfiguration.CacheServerList servers = new Management.ClientConfiguration.CacheServerList(serverList);
                    List <string> serversToUpdate = new List <string>();
                    foreach (Alachisoft.NCache.Config.NewDom.ServerNode node in GetServers(ccParam.Server))
                    {
                        NCache.ServerName = node.IP;

                        Console.WriteLine(AppendBlankLine("\nCreating cache") + " '{0}' on server '{1}' ", _cacheConfig.CacheSettings.Name, NCache.ServerName);
                        try
                        {
                            cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                            if (cacheServer != null)
                            {
                                Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = cacheServer.GetNewConfiguration(_cacheConfig.CacheSettings.Name);

                                if (serverConfig != null)
                                {
                                    throw new Exception("Specified cache already exists.");
                                }

                                else if (serverConfig != null && ccParam.IsOverWrite)
                                {
                                    NCache.ServerName = node.IP;

                                    if (serverConfig.CacheDeployment != null)
                                    {
                                        if (serverConfig.CacheDeployment.ClientNodes != null)
                                        {
                                            _cacheConfig.CacheDeployment.ClientNodes = serverConfig.CacheDeployment.ClientNodes;
                                        }
                                    }
                                }

                                cacheServer.RegisterCache(_cacheConfig.CacheSettings.Name, _cacheConfig, "", ccParam.IsOverWrite, ccParam.IsHotApply);
                                cacheServer.UpdateClientServersList(_cacheConfig.CacheSettings.Name, servers, "NCACHE");
                                serversToUpdate.Add(node.IP);

                                Console.WriteLine("Cache '{0}' successfully created on server {1}:{2} .", _cacheConfig.CacheSettings.Name, NCache.ServerName, NCache.Port);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                    Management.Management.Util.ManagementWorkFlow.UpdateServerMappingConfig(serversToUpdate.ToArray());
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    if (cacheServer != null)
                    {
                        cacheServer.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(AppendBlankLine("Failed") + " to create cache on server '{0}'. ", ccParam.Server);
                Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);
                LogEvent(ex.Message);
            }
            finally
            {
                NCache.Dispose();
            }
        }
Beispiel #11
0
        /// <summary>
        /// The main entry point for the tool.
        /// </summary>
        public static void Run(string[] args)
        {
            string failedNodes = string.Empty;
            NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
            Alachisoft.NCache.Config.NewDom.CacheServerConfig[] caches = null;
            ICacheServer cacheServer = null;
            Alachisoft.NCache.Config.NewDom.CacheServerConfig _cacheConfig = null;

            try
            {
                object param = new ConfigureCacheParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                ccParam = (ConfigureCacheParam)param;

                if (ccParam.IsUsage)
                {
                    AssemblyUsage.PrintLogo(ccParam.IsLogo);
                    AssemblyUsage.PrintUsage();
                    return;
                }

                if (!ValidateParameters()) return;

                if (ccParam.Port != -1)
                {
                    NCache.Port = ccParam.Port;
                }

                if (ccParam.Port == -1) NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;

                if (ccParam.Path != null && ccParam.Path != string.Empty)
                {
                    if (Path.HasExtension(ccParam.Path))
                    {
                        string extension = Path.GetExtension(ccParam.Path);

                        if (!extension.Equals(".ncconf") && !extension.Equals(".xml"))
                        {
                            throw new Exception("Incorrect file format. Only .ncconf and .xml are supported.");
                        }
                    }
                    else
                        throw new Exception("Incorrect configuration file path specified.");

                    ConfigurationBuilder builder = new ConfigurationBuilder(ccParam.Path);
                    builder.RegisterRootConfigurationObject(typeof(Alachisoft.NCache.Config.NewDom.CacheServerConfig));
                    builder.ReadConfiguration();

                    if (builder.Configuration != null)
                    {
                        caches = new Alachisoft.NCache.Config.NewDom.CacheServerConfig[builder.Configuration.Length];
                        builder.Configuration.CopyTo(caches, 0);
                    }
                    else
                        throw new Exception("Configuration cannot be loaded.");
                    ConfigurationValidator validator = new ConfigurationValidator();
                    bool _isConfigValidated = validator.ValidateConfiguration(caches);

                    _cacheConfig = caches[0];

                    if (_cacheConfig.CacheSettings.Name == null)
                        _cacheConfig.CacheSettings.Name = ccParam.CacheId;

                    if (_cacheConfig.CacheSettings.Storage == null || _cacheConfig.CacheSettings.Storage.Size == -1)
                    {
                        throw new Exception("Cache size is not specified.");
                    }

                    if (_cacheConfig.CacheSettings.EvictionPolicy == null)
                    {
                        _cacheConfig.CacheSettings.EvictionPolicy = new EvictionPolicy();
                        _cacheConfig.CacheSettings.EvictionPolicy.Policy = "priority";
                        _cacheConfig.CacheSettings.EvictionPolicy.DefaultPriority = "normal";
                        _cacheConfig.CacheSettings.EvictionPolicy.EvictionRatio = 5;
                        _cacheConfig.CacheSettings.EvictionPolicy.Enabled = true;
                    }

                    if (_cacheConfig.CacheSettings.Cleanup == null)
                    {
                        _cacheConfig.CacheSettings.Cleanup = new Cleanup();
                        _cacheConfig.CacheSettings.Cleanup.Interval = 15;
                    }

                    if (_cacheConfig.CacheSettings.Log == null)
                    {
                        _cacheConfig.CacheSettings.Log = new Log();
                    }

                    if (_cacheConfig.CacheSettings.PerfCounters == null)
                    {
                        _cacheConfig.CacheSettings.PerfCounters = new PerfCounters();
                        _cacheConfig.CacheSettings.PerfCounters.Enabled = true;
                    }

                    if (_cacheConfig.CacheSettings.CacheType == "clustered-cache")
                    {
                        if (_cacheConfig.CacheSettings.CacheTopology.ClusterSettings == null)
                        {
                            throw new Exception("Cluster settings not specified for the cluster cache.");
                        }

                        if (_cacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel == null)
                        {
                            throw new Exception("Cluster channel related settings not specified for cluster cache.");
                        }

                        if (_cacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel.TcpPort == -1)
                        {
                            throw new Exception("Cluster port not specified for cluster cache.");
                        }
                    }
                }
                else
                {
                    _SimpleCacheConfig.CacheSettings = new Alachisoft.NCache.Config.NewDom.CacheServerConfigSetting();
                    _SimpleCacheConfig.CacheSettings.Name = ccParam.CacheId;
                    _SimpleCacheConfig.CacheSettings.Storage = new Alachisoft.NCache.Config.Dom.Storage();
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy = new EvictionPolicy();
                    _SimpleCacheConfig.CacheSettings.Cleanup = new Cleanup();
                    _SimpleCacheConfig.CacheSettings.Log = new Log();
                    _SimpleCacheConfig.CacheSettings.PerfCounters = new PerfCounters();
                    _SimpleCacheConfig.CacheSettings.PerfCounters.Enabled = true;
                    _SimpleCacheConfig.CacheSettings.Storage.Type = "heap";
                    _SimpleCacheConfig.CacheSettings.Storage.Size = ccParam.CacheSize;
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy.Policy = "priority";
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy.DefaultPriority = "normal";
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy.EvictionRatio = 5;
                    _SimpleCacheConfig.CacheSettings.EvictionPolicy.Enabled = false;
                    _SimpleCacheConfig.CacheSettings.Cleanup.Interval = 15;
                    _SimpleCacheConfig.CacheSettings.CacheTopology = new Alachisoft.NCache.Config.NewDom.CacheTopology();

                    if (string.IsNullOrEmpty(ccParam.Topology))
                    {
                        _SimpleCacheConfig.CacheSettings.CacheTopology.Topology = "Local";
                    }
                    else
                    {
                        _SimpleCacheConfig.CacheSettings.CacheTopology.Topology = ccParam.Topology;
                    }

                    if (ccParam.IsInProc && _SimpleCacheConfig.CacheSettings.CacheTopology.Topology.Equals("local-cache"))
                        _SimpleCacheConfig.CacheSettings.InProc = true;

                    if (_SimpleCacheConfig.CacheSettings.CacheType == "clustered-cache")
                    {
                        _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings = new Alachisoft.NCache.Config.NewDom.Cluster();
                        _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel = new Alachisoft.NCache.Config.NewDom.Channel();

                        _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel.TcpPort = ccParam.ClusterPort;
                        _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings.StatsRepInterval = 600;
                        if (_SimpleCacheConfig.CacheSettings.CacheTopology.Topology == "partitioned-replica")
                            _SimpleCacheConfig.CacheSettings.CacheTopology.ClusterSettings.Channel.PortRange = 2;

                    }

                    if (ccParam.EvictionPolicy != null && ccParam.EvictionPolicy != string.Empty)
                    {
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.Policy = ccParam.EvictionPolicy;
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.Enabled = true;
                    }

                    if (ccParam.Ratio != -1)
                    {
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.EvictionRatio = ccParam.Ratio;
                    }

                    if (ccParam.CleanupInterval != -1)
                    {
                        _SimpleCacheConfig.CacheSettings.Cleanup.Interval = ccParam.CleanupInterval;
                    }

                    if (ccParam.DefaultPriority != null && ccParam.DefaultPriority != string.Empty)
                    {
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.DefaultPriority = ccParam.DefaultPriority;
                        _SimpleCacheConfig.CacheSettings.EvictionPolicy.Enabled = true;
                    }
                    _cacheConfig = _SimpleCacheConfig;
                }
                try
                {
                    _cacheConfig.CacheSettings.Name = ccParam.CacheId;

                    if (_cacheConfig.CacheSettings.CacheType == "clustered-cache")
                    {
                        if (_cacheConfig.CacheDeployment == null)
                        {
                            _cacheConfig.CacheDeployment = new Alachisoft.NCache.Config.NewDom.CacheDeployment();
                            _cacheConfig.CacheDeployment.Servers = new Alachisoft.NCache.Config.NewDom.ServersNodes();

                        }
                        _cacheConfig.CacheDeployment.Servers.NodesList = GetServers(ccParam.Server);
                    }

                    Dictionary<int, Management.ClientConfiguration.Dom.CacheServer> serverList = new Dictionary<int, Management.ClientConfiguration.Dom.CacheServer>();
                    int serverCount = 0;
                    foreach (Alachisoft.NCache.Config.NewDom.ServerNode node in GetServers(ccParam.Server))
                    {
                        Management.ClientConfiguration.Dom.CacheServer tempServer = new Management.ClientConfiguration.Dom.CacheServer();
                        tempServer.ServerName = node.IP;
                        serverList.Add(serverCount, tempServer);
                        serverCount++;
                    }
                    Management.ClientConfiguration.CacheServerList servers = new Management.ClientConfiguration.CacheServerList(serverList);
                    List<string> serversToUpdate = new List<string>();
                    foreach (Alachisoft.NCache.Config.NewDom.ServerNode node in GetServers(ccParam.Server))
                    {
                        NCache.ServerName = node.IP;

                        Console.WriteLine(AppendBlankLine("\nCreating cache") + " '{0}' on server '{1}' ", _cacheConfig.CacheSettings.Name, NCache.ServerName);
                        try
                        {
                            cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                            if (cacheServer != null)
                            {
                                Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = cacheServer.GetNewConfiguration(_cacheConfig.CacheSettings.Name);

                                if (serverConfig != null)
                                {
                                    throw new Exception("Specified cache already exists.");

                                }

                                else if (serverConfig != null && ccParam.IsOverWrite)
                                {
                                    NCache.ServerName = node.IP;

                                    if (serverConfig.CacheDeployment != null)
                                    {
                                        if (serverConfig.CacheDeployment.ClientNodes != null)
                                            _cacheConfig.CacheDeployment.ClientNodes = serverConfig.CacheDeployment.ClientNodes;
                                    }

                                }

                                cacheServer.RegisterCache(_cacheConfig.CacheSettings.Name, _cacheConfig, "", ccParam.IsOverWrite, ccParam.IsHotApply);
                                cacheServer.UpdateClientServersList(_cacheConfig.CacheSettings.Name, servers, "NCACHE");
                                serversToUpdate.Add(node.IP);

                                Console.WriteLine("Cache '{0}' successfully created on server {1}:{2} .", _cacheConfig.CacheSettings.Name, NCache.ServerName, NCache.Port);
                            }

                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                    Management.Management.Util.ManagementWorkFlow.UpdateServerMappingConfig(serversToUpdate.ToArray());

                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    if (cacheServer != null)
                        cacheServer.Dispose();
                }

            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(AppendBlankLine("Failed") + " to create cache on server '{0}'. ", ccParam.Server);
                Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);
                LogEvent(ex.Message);
            }
            finally
            {
                NCache.Dispose();
            }
        }
Beispiel #12
0
        static public void Run(string[] args)
        {
            try
            {
                object param = new RemoveClientNodeParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                cParam = (RemoveClientNodeParam)param;
                if (cParam.IsUsage)
                {
                    AssemblyUsage.PrintLogo(cParam.IsLogo);
                    AssemblyUsage.PrintUsage();
                    return;
                }

                if (!ValidateParameters())
                {
                    return;
                }

                if (cParam.Port != -1)
                {
                    NCache.Port = cParam.Port;
                }

                if (cParam.Port == -1)
                {
                    NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                }


                if (cParam.Server != null || cParam.Server != string.Empty)
                {
                    NCache.ServerName = cParam.Server;
                }

                cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                config = cacheServer.GetNewConfiguration(cParam.CacheId);
                string getClusterIp = cacheServer.GetClusterIP();
                if (config == null)
                {
                    Console.Error.WriteLine("Error: The cache doesnot exist.");
                    return;
                }
                if (config.CacheSettings.CacheType == "clustered-cache")
                {
                    Console.WriteLine("Removing client node '{0}' from cache '{1}' on server '{2}:{3}'.",
                                      cParam.ClientNode, cParam.CacheId, getClusterIp, NCache.Port);
                    foreach (Address node in config.CacheDeployment.Servers.GetAllConfiguredNodes())
                    {
                        currentServerNodes.Add(node.IpAddress.ToString());
                    }
                }
                else
                {
                    Console.Error.WriteLine("Error: Client nodes cannot be added to local caches");
                    return;
                }

                if (UpdateConfigs())
                {
                    Console.WriteLine("Client node '{0}' successfully removed from cache '{1}' on server {2}:{3}.",
                                      cParam.ClientNode, cParam.CacheId, getClusterIp, NCache.Port);
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error: {0}", ex.Message);
            }
            finally
            {
                if (cacheServer != null)
                {
                    cacheServer.Dispose();
                }
            }
        }
Beispiel #13
0
        public static bool DeployAssembly(string server, int port, string path, string cacheId, string depAsmPath, LogErrors logError)
        {
            List <FileInfo> files    = new List <FileInfo>(); // List that will hold the files and subfiles in path
            string          fileName = null;

            byte[] asmData;
            string failedNodes = string.Empty;

            Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = null;

            try
            {
                if (port != -1)
                {
                    NCache.Port = port;
                }

                if (port == -1)
                {
                    NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                }
                if (server != null || server != string.Empty)
                {
                    NCache.ServerName = server;
                }


                cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                if (cacheServer != null)
                {
                    serverConfig = cacheServer.GetNewConfiguration(cacheId);

                    if (path != null && path != string.Empty)
                    {
                        if (Path.HasExtension(path))
                        {
                            FileInfo fi = new FileInfo(path);
                            files.Add(fi);
                        }
                        else
                        {
                            DirectoryInfo di = new DirectoryInfo(path);

                            try
                            {
                                foreach (FileInfo f in di.GetFiles("*"))
                                {
                                    if (Path.HasExtension(f.FullName))
                                    {
                                        files.Add(f);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                logError("Directory " + di.FullName + "could not be accessed.");
                                return(false);
                            }
                        }
                    }

                    if (depAsmPath != null && depAsmPath != string.Empty)
                    {
                        if (Path.HasExtension(depAsmPath))
                        {
                            FileInfo fi = new FileInfo(path);
                            files.Add(fi);
                        }
                        else
                        {
                            DirectoryInfo di = new DirectoryInfo(depAsmPath);

                            try
                            {
                                foreach (FileInfo f in di.GetFiles("*"))
                                {
                                    if (Path.HasExtension(f.FullName))
                                    {
                                        files.Add(f);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                logError("Directory " + di.FullName + "could not be accessed.");
                                return(false);
                            }
                        }
                    }

                    foreach (FileInfo f in files)
                    {
                        try
                        {
                            FileStream fs = new FileStream(f.FullName, FileMode.Open, FileAccess.Read);
                            asmData = new byte[fs.Length];
                            fs.Read(asmData, 0, asmData.Length);
                            fs.Flush();
                            fs.Close();
                            fileName = Path.GetFileName(f.FullName);


                            if (serverConfig.CacheSettings.CacheType == "clustered-cache")
                            {
                                foreach (Address node in serverConfig.CacheDeployment.Servers.GetAllConfiguredNodes())
                                {
                                    NCache.ServerName = node.IpAddress.ToString();
                                    try
                                    {
                                        cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                                        cacheServer.CopyAssemblies(cacheId, fileName, asmData);
                                    }
                                    catch (Exception ex)
                                    {
                                        logError("Failed to Deploy Assembly on " + NCache.ServerName);
                                        logError("Error Detail: " + ex.Message);
                                    }
                                }
                            }
                            else
                            {
                                cacheServer.CopyAssemblies(cacheId, fileName, asmData);
                            }
                        }
                        catch (Exception e)
                        {
                            string message = string.Format("Could not deploy assembly \"" + fileName + "\". {0}", e.Message);
                            logError("Error : " + message);
                            return(false);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                logError("Error : {0}" + e.Message);
            }
            finally
            {
                NCache.Dispose();
            }

            return(true);
        }
Beispiel #14
0
        /// <summary>
        /// The main entry point for the tool.
        /// </summary>
        static public void Run(string[] args)
        {
            string       failedNodes = string.Empty;
            ICacheServer cacheServer = null;

            try
            {
                object param = new GetCacheConfigurationParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                ccParam = (GetCacheConfigurationParam)param;

                if (ccParam.IsUsage)
                {
                    AssemblyUsage.PrintLogo(ccParam.IsLogo);
                    AssemblyUsage.PrintUsage();
                    return;
                }

                if (!ValidateParameters())
                {
                    return;
                }

                string _filename = null;
                string _path     = null;
                if (ccParam.Path != null && ccParam.Path != string.Empty)
                {
                    if (!Path.HasExtension(ccParam.Path))
                    {
                        _filename    = ccParam.CacheId + ".ncconf";
                        ccParam.Path = ccParam.Path + "\\" + _filename;
                    }
                }
                else
                {
                    ccParam.Path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
                    _filename    = ccParam.CacheId + ".ncconf";
                    ccParam.Path = ccParam.Path + "\\" + _filename;
                }

                if (ccParam.Port == -1)
                {
                    NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                }
                if (!string.IsNullOrEmpty(ccParam.Server))
                {
                    NCache.ServerName = ccParam.Server;
                }
                else
                {
                    NCache.ServerName = System.Environment.MachineName;
                }

                if (ccParam.Port != -1)
                {
                    NCache.Port = ccParam.Port;
                }

                cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                if (cacheServer != null)
                {
                    Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = cacheServer.GetNewConfiguration(ccParam.CacheId);

                    if (serverConfig == null)
                    {
                        throw new Exception("Specified cache is not registered on given server.");
                    }

                    serverConfig.CacheDeployment = null;

                    Console.WriteLine("Creating configuration for cache '{0}' registered on server '{1}:{2}'.", ccParam.CacheId, NCache.ServerName, NCache.Port);

                    StringBuilder xml = new StringBuilder();
                    List <Alachisoft.NCache.Config.NewDom.CacheServerConfig> configurations = new List <Alachisoft.NCache.Config.NewDom.CacheServerConfig>();
                    configurations.Add(serverConfig);
                    ConfigurationBuilder builder = new ConfigurationBuilder(configurations.ToArray());
                    builder.RegisterRootConfigurationObject(typeof(Alachisoft.NCache.Config.NewDom.CacheServerConfig));
                    xml.Append(builder.GetXmlString());
                    WriteXmlToFile(xml.ToString());

                    Console.WriteLine("Cache configuration saved successfully at " + ccParam.Path + ".");
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error : {0}", e.Message);
            }
            finally
            {
                NCache.Dispose();
                if (cacheServer != null)
                {
                    cacheServer.Dispose();
                }
            }
        }
Beispiel #15
0
        private void AddLuceneStopWords()
        {
            if (!ValidateParameters())
            {
                return;
            }

            System.IO.FileInfo fInfo = null;
            Alachisoft.NCache.Config.Dom.LuceneDeployment[] prov = null;
            string       failedNodes = string.Empty;
            string       serverName  = string.Empty;
            ICacheServer cacheServer = null;
            bool         successFull = true;

            try
            {
                if (Port != -1)
                {
                    NCache.Port = Port;
                }

                if (Port == -1)
                {
                    NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                }
                if (Server != null && Server != string.Empty)
                {
                    NCache.ServerName = Server;
                }

                try
                {
                    cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                }
                catch (Exception e)
                {
                    successFull = false;
                    OutputProvider.WriteErrorLine("Error: NCache service could not be contacted on server.");
                    return;
                }

                if (cacheServer != null)
                {
                    serverName = cacheServer.GetClusterIP();
                    if (cacheServer.IsRunning(CacheName))
                    {
                        successFull = false;
                        throw new Exception(CacheName + " is Running on " + cacheServer.GetClusterIP() + "\nStop the cache first and try again.");
                    }
                    Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = cacheServer.GetNewConfiguration(CacheName);


                    if (serverConfig == null)
                    {
                        successFull = false;
                        throw new Exception("Specified cache is not registered on the given server.");
                    }
                    ToolsUtil.VerifyClusterConfigurations(serverConfig, CacheName);
                    try
                    {
                        fInfo = new System.IO.FileInfo(FilePath);
                    }
                    catch (Exception e)
                    {
                        successFull = false;
                        string message = string.Format("Could not load file \"" + FilePath + "\". {0}", e.Message);
                        OutputProvider.WriteErrorLine("Error: {0}", message);
                        return;
                    }

                    if (serverConfig.CacheSettings.LuceneSettings == null)
                    {
                        serverConfig.CacheSettings.LuceneSettings = new Alachisoft.NCache.Config.Dom.LuceneSettings();
                    }

                    if (fInfo.Extension != ".txt")
                    {
                        successFull = false;
                        string message = string.Format("\"" + FilePath + "\" is not a Text file. {0}");
                        OutputProvider.WriteErrorLine("Error: {0}", message);
                        return;
                    }

                    if (serverConfig.CacheSettings.LuceneSettings.StopWordFiles == null)
                    {
                        serverConfig.CacheSettings.LuceneSettings.StopWordFiles = new StopWords();
                    }

                    if (serverConfig.CacheSettings.LuceneSettings.StopWordFiles.Providers != null)
                    {
                        prov = serverConfig.CacheSettings.LuceneSettings.StopWordFiles.Providers;
                    }

                    serverConfig.CacheSettings.LuceneSettings.StopWordFiles.Providers = GetStopWords(GetProvider(prov, fInfo));

                    byte[] userId = null;
                    byte[] paswd  = null;
                    if (UserId != string.Empty && Password != string.Empty)
                    {
                        userId = EncryptionUtil.Encrypt(UserId);
                        paswd  = EncryptionUtil.Encrypt(Password);
                    }
                    serverConfig.ConfigVersion++;
                    if (serverConfig.CacheSettings.CacheType == "clustered-cache")
                    {
                        foreach (Address node in serverConfig.CacheDeployment.Servers.GetAllConfiguredNodes())
                        {
                            NCache.ServerName = node.IpAddress.ToString();
                            try
                            {
                                cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                                if (cacheServer.IsRunning(CacheName))
                                {
                                    throw new Exception(CacheName + " is Running on " + serverName +
                                                        "\nStop the cache first and try again.");
                                }

                                OutputProvider.WriteLine("Adding Lucene Stop Words file on node '{0}' to cache '{1}'.", node.IpAddress, CacheName);
                                cacheServer.RegisterCache(CacheName, serverConfig, "", true, userId, paswd, false);
                            }
                            catch (Exception ex)
                            {
                                OutputProvider.WriteErrorLine("Failed to Add Lucene Stop Words file on '{0}'. ", serverName);
                                OutputProvider.WriteErrorLine("Error Detail: '{0}'. ", ex.Message);
                                failedNodes = failedNodes + "/n" + node.IpAddress.ToString();
                                successFull = false;
                            }
                            finally
                            {
                                cacheServer.Dispose();
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            OutputProvider.WriteLine("Adding Lucene Stop Words file on node '{0}' to cache '{1}'.", serverName, CacheName);
                            cacheServer.RegisterCache(CacheName, serverConfig, "", true, userId, paswd, false);
                        }
                        catch (Exception ex)
                        {
                            OutputProvider.WriteErrorLine("Failed to Add Lucene Stop Words file on '{0}'. ", serverName);
                            OutputProvider.WriteErrorLine("Error Detail: '{0}'. ", ex.Message);
                            successFull = false;
                        }
                        finally
                        {
                            NCache.Dispose();
                            if (successFull && !IsUsage)
                            {
                                OutputProvider.WriteLine("Stop words file successfully added");
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                successFull = false;
                throw;
            }
            finally
            {
                NCache.Dispose();
                if (successFull && !IsUsage)
                {
                    OutputProvider.WriteLine("Stop words file successfully added");
                }
            }
        }
Beispiel #16
0
        public static Alachisoft.NCache.Config.NewDom.CacheServerConfig convertToNewDom(Alachisoft.NCache.Config.Dom.CacheServerConfig oldDom)
        {
            Alachisoft.NCache.Config.NewDom.CacheServerConfig newDom = null;
            try
            {
                if (oldDom != null)
                {
                    newDom = new CacheServerConfig();

                    if (newDom.CacheSettings == null)
                    {
                        newDom.CacheSettings = new CacheServerConfigSetting();
                    }
                    newDom.Name = oldDom.Name;
                    newDom.CacheSettings.InProc = oldDom.InProc;

                    newDom.CacheSettings.DataFormat = oldDom.DataFormat;

                    if (oldDom.Log != null)
                    {
                        newDom.CacheSettings.Log = oldDom.Log;
                    }
                    else
                    {
                        newDom.CacheSettings.Log = new Alachisoft.NCache.Config.Dom.Log();
                    }

                    if (oldDom.PerfCounters != null)
                    {
                        newDom.CacheSettings.PerfCounters = oldDom.PerfCounters;
                    }
                    else
                    {
                        newDom.CacheSettings.PerfCounters = new Alachisoft.NCache.Config.Dom.PerfCounters();
                    }

                    if (oldDom.QueryIndices != null)
                    {
                        newDom.CacheSettings.QueryIndices = oldDom.QueryIndices;
                    }

                    if (oldDom.BackingSource != null)
                    {
                        newDom.CacheSettings.BackingSource = oldDom.BackingSource;
                    }


                    if (oldDom.Notifications != null)
                    {
                        newDom.CacheSettings.Notifications = oldDom.Notifications;
                    }
                    else
                    {
                        newDom.CacheSettings.Notifications = new Alachisoft.NCache.Config.Dom.Notifications();
                    }

                    if (oldDom.Cleanup != null)
                    {
                        newDom.CacheSettings.Cleanup = oldDom.Cleanup;
                    }
                    else
                    {
                        newDom.CacheSettings.Cleanup = new Alachisoft.NCache.Config.Dom.Cleanup();
                    }

                    if (oldDom.Storage != null)
                    {
                        newDom.CacheSettings.Storage = oldDom.Storage;
                    }
                    else
                    {
                        newDom.CacheSettings.Storage = new Alachisoft.NCache.Config.Dom.Storage();
                    }

                    if (oldDom.EvictionPolicy != null)
                    {
                        newDom.CacheSettings.EvictionPolicy = oldDom.EvictionPolicy;
                    }
                    else
                    {
                        newDom.CacheSettings.EvictionPolicy = oldDom.EvictionPolicy;
                    }

                    if (oldDom.ExpirationPolicy != null)
                    {
                        newDom.CacheSettings.ExpirationPolicy = oldDom.ExpirationPolicy;
                    }
                    else
                    {
                        newDom.CacheSettings.ExpirationPolicy = oldDom.ExpirationPolicy;
                    }

                    if (oldDom.TaskConfiguration != null)
                    {
                        newDom.CacheSettings.TaskConfiguration = oldDom.TaskConfiguration;
                    }
                    else
                    {
                        newDom.CacheSettings.TaskConfiguration = oldDom.TaskConfiguration;
                    }

                    if (newDom.CacheSettings.CacheTopology == null)
                    {
                        newDom.CacheSettings.CacheTopology = new CacheTopology();
                    }

                    if (oldDom.ClientActivityNotification != null)
                    {
                        newDom.CacheSettings.ClientActivityNotification = oldDom.ClientActivityNotification;
                    }

                    newDom.CacheSettings.CacheType = oldDom.CacheType;
                    if (oldDom.Cluster != null)
                    {
                        string topology = oldDom.Cluster.Topology;
                        if (topology != null)
                        {
                            topology = topology.ToLower();

                            if (topology.Equals("replicated-server"))
                            {
                                topology = "replicated";
                            }

                            else if (topology.Equals("partitioned-server"))
                            {
                                topology = "partitioned";
                            }



                            else if (topology.Equals("local-cache"))
                            {
                                topology = "local-cache";
                            }
                        }

                        newDom.CacheSettings.CacheTopology.Topology = topology;

                        if (oldDom.CacheType.Equals("clustered-cache"))
                        {
                            if (newDom.CacheDeployment == null)
                            {
                                newDom.CacheDeployment = new CacheDeployment();
                            }

                            if (newDom.CacheSettings.CacheTopology.ClusterSettings == null)
                            {
                                newDom.CacheSettings.CacheTopology.ClusterSettings = new Cluster();
                            }
                            newDom.CacheSettings.CacheTopology.ClusterSettings.OpTimeout        = oldDom.Cluster.OpTimeout;
                            newDom.CacheSettings.CacheTopology.ClusterSettings.StatsRepInterval = oldDom.Cluster.StatsRepInterval;
                            newDom.CacheSettings.CacheTopology.ClusterSettings.UseHeartbeat     = oldDom.Cluster.UseHeartbeat;

                            if (newDom.CacheSettings.CacheTopology.ClusterSettings.Channel == null)
                            {
                                newDom.CacheSettings.CacheTopology.ClusterSettings.Channel = new Channel();
                            }

                            if (oldDom.Cluster.Channel != null)
                            {
                                newDom.CacheSettings.CacheTopology.ClusterSettings.Channel.TcpPort                 = oldDom.Cluster.Channel.TcpPort;
                                newDom.CacheSettings.CacheTopology.ClusterSettings.Channel.PortRange               = oldDom.Cluster.Channel.PortRange;
                                newDom.CacheSettings.CacheTopology.ClusterSettings.Channel.ConnectionRetries       = oldDom.Cluster.Channel.ConnectionRetries;
                                newDom.CacheSettings.CacheTopology.ClusterSettings.Channel.ConnectionRetryInterval = oldDom.Cluster.Channel.ConnectionRetryInterval;
                            }
                            if (oldDom.ReplicationStrategy != null)
                            {
                                newDom.CacheSettings.CacheTopology.ClusterSettings.ReplicationStrategy = oldDom.ReplicationStrategy;
                            }
                            else
                            {
                                newDom.CacheSettings.CacheTopology.ClusterSettings.ReplicationStrategy = new Alachisoft.NCache.Config.Dom.ReplicationStrategy();
                            }

                            if (newDom.CacheDeployment.Servers == null)
                            {
                                newDom.CacheDeployment.Servers = new ServersNodes();
                            }

                            newDom.CacheDeployment.Servers.NodesList = createServers(oldDom.Cluster.Channel.InitialHosts, oldDom.Cluster.ActiveMirrorNode);

                            if (oldDom.ClientNodes != null)
                            {
                                if (newDom.CacheDeployment.ClientNodes == null)
                                {
                                    newDom.CacheDeployment.ClientNodes = new Alachisoft.NCache.Config.Dom.ClientNodes();
                                }
                                newDom.CacheDeployment.ClientNodes = oldDom.ClientNodes;
                            }
                        }
                    }
                    else
                    {
                        if (oldDom.CacheType != null)
                        {
                            if (oldDom.CacheType.Equals("local-cache"))
                            {
                                newDom.CacheSettings.CacheTopology.Topology = oldDom.CacheType;
                            }

                            newDom.CacheSettings.CacheTopology.ClusterSettings = null;
                        }
                    }

                    if (oldDom.SQLDependencyConfig != null)
                    {
                        newDom.CacheSettings.SQLDependencyConfig = oldDom.SQLDependencyConfig;
                    }

                    newDom.IsRunning    = oldDom.IsRunning;
                    newDom.IsRegistered = oldDom.IsRegistered;
                    newDom.IsExpired    = oldDom.IsExpired;
                }
            }
            catch
            (Exception ex)
            {
                throw new Exception("DomHelper.convertToNewDom" + ex.Message);
            }
            return(newDom);
        }
        /// <summary>
        /// Loads and returns all cache configurations from the configuration file.
        /// </summary>
        static public CacheServerConfig[] GetConfiguredCaches()
        {
            if (FileName.Length == 0)
            {
                throw new ManagementException("Can not locate cache configuration file. Installation might be corrupt.");
            }
            try
            {
                ConfigurationBuilder builder = new ConfigurationBuilder(FileName);
                builder.RegisterRootConfigurationObject(typeof(Alachisoft.NCache.Config.NewDom.CacheServerConfig));
                builder.ReadConfiguration();
                Alachisoft.NCache.Config.NewDom.CacheServerConfig[] newCaches = new Alachisoft.NCache.Config.NewDom.CacheServerConfig[builder.Configuration.Length];
                builder.Configuration.CopyTo(newCaches, 0);

                return convertToOldDom(newCaches);
            }
            catch (ManagementException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new ManagementException(e.Message, e);
            }
        }
        public void GetCacheConfiguration()
        {
            string       failedNodes = string.Empty;
            ICacheServer cacheServer = null;

            try
            {
                if (!ValidateParameters())
                {
                    return;
                }

                string _filename = null;
                string _path     = null;
                if (Path != null && Path != string.Empty)
                {
                    if (!System.IO.Path.HasExtension(Path))
                    {
                        _filename = Name + ".ncconf";
                        Path      = Path + System.IO.Path.DirectorySeparatorChar + _filename;
                    }
                }
                else
                {
                    //Path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                    Path      = System.IO.Path.Combine(AppUtil.InstallDir, @"bin" + System.IO.Path.DirectorySeparatorChar + "tools");
                    _filename = Name + ".ncconf";
                    Path      = Path + System.IO.Path.DirectorySeparatorChar + _filename;
                }

                if (Port == -1)
                {
                    NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                }
                if (!string.IsNullOrEmpty(Server))
                {
                    NCache.ServerName = Server;
                }
                else
                {
                    NCache.ServerName = System.Environment.MachineName;
                }

                if (Port != -1)
                {
                    NCache.Port = Port;
                }
                try
                {
                    cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                }
                catch (Exception e)
                {
                    OutputProvider.WriteErrorLine("Error: NCache service could not be contacted on server.");
                    return;
                }

                if (cacheServer != null)
                {
                    Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = cacheServer.GetNewConfiguration(Name);
                    if (serverConfig == null)
                    {
                        throw new Exception("Specified cache is not registered on the given server.");
                    }
                    serverConfig.CacheDeployment = null;
                    OutputProvider.WriteLine("Creating configuration for cache '{0}' registered on server '{1}:{2}'.", Name, NCache.ServerName, NCache.Port);
                    StringBuilder xml = new StringBuilder();
                    List <Alachisoft.NCache.Config.NewDom.CacheServerConfig> configurations = new List <Alachisoft.NCache.Config.NewDom.CacheServerConfig>();
                    configurations.Add(serverConfig);
                    ConfigurationBuilder builder = new ConfigurationBuilder(configurations.ToArray());
                    builder.RegisterRootConfigurationObject(typeof(Alachisoft.NCache.Config.NewDom.CacheServerConfig));
                    xml.Append(builder.GetXmlString());
                    WriteXmlToFile(xml.ToString());
                    OutputProvider.WriteLine("Cache configuration saved successfully at " + Path + ".");
                }
            }
            catch (Exception e)
            {
                OutputProvider.WriteErrorLine("Error : {0}", e.Message);
            }
            finally
            {
                NCache.Dispose();
                if (cacheServer != null)
                {
                    cacheServer.Dispose();
                }
            }
        }
Beispiel #19
0
        private static CacheServerConfig[] LoadConfig(string fileName)
        {
            ConfigurationBuilder builder = new ConfigurationBuilder(fileName);
            builder.RegisterRootConfigurationObject(typeof(Alachisoft.NCache.Config.NewDom.CacheServerConfig));
            builder.ReadConfiguration();
            Alachisoft.NCache.Config.NewDom.CacheServerConfig[] newCaches = new Alachisoft.NCache.Config.NewDom.CacheServerConfig[builder.Configuration.Length];
            builder.Configuration.CopyTo(newCaches, 0);

            return convertToOldDom(newCaches);
        }
Beispiel #20
0
        public static Alachisoft.NCache.Config.Dom.CacheServerConfig convertToOldDom(Alachisoft.NCache.Config.NewDom.CacheServerConfig newDom)
        {
            Alachisoft.NCache.Config.Dom.CacheServerConfig oldDom = null;
            try
            {
                if (newDom != null)
                {
                    oldDom = new Alachisoft.NCache.Config.Dom.CacheServerConfig();

                    if (newDom.CacheSettings != null)
                    {
                        oldDom.Name         = newDom.CacheSettings.Name;
                        oldDom.InProc       = newDom.CacheSettings.InProc;
                        oldDom.ConfigID     = newDom.ConfigID;
                        oldDom.LastModified = newDom.CacheSettings.LastModified;

                        if (newDom.CacheSettings.Log != null)
                        {
                            oldDom.Log = newDom.CacheSettings.Log;
                        }
                        else
                        {
                            oldDom.Log = new Alachisoft.NCache.Config.Dom.Log();
                        }

                        if (newDom.CacheSettings.PerfCounters != null)
                        {
                            oldDom.PerfCounters = newDom.CacheSettings.PerfCounters;
                        }
                        else
                        {
                            oldDom.PerfCounters = new Alachisoft.NCache.Config.Dom.PerfCounters();
                        }

                        if (newDom.CacheSettings.QueryIndices != null)
                        {
                            oldDom.QueryIndices = newDom.CacheSettings.QueryIndices;
                        }



                        if (newDom.CacheSettings.Cleanup != null)
                        {
                            oldDom.Cleanup = newDom.CacheSettings.Cleanup;
                        }
                        else
                        {
                            oldDom.Cleanup = new Alachisoft.NCache.Config.Dom.Cleanup();
                        }

                        if (newDom.CacheSettings.Storage != null)
                        {
                            oldDom.Storage = newDom.CacheSettings.Storage;
                        }
                        else
                        {
                            oldDom.Storage = new Alachisoft.NCache.Config.Dom.Storage();
                        }

                        if (newDom.CacheSettings.EvictionPolicy != null)
                        {
                            oldDom.EvictionPolicy = newDom.CacheSettings.EvictionPolicy;
                        }
                        else
                        {
                            oldDom.EvictionPolicy = new Alachisoft.NCache.Config.Dom.EvictionPolicy();
                        }

                        if (newDom.CacheSettings.CacheTopology != null)
                        {
                            oldDom.CacheType = newDom.CacheSettings.CacheType;
                        }

                        if (oldDom.CacheType.Equals("clustered-cache"))
                        {
                            if (newDom.CacheDeployment != null)
                            {
                                if (oldDom.Cluster == null)
                                {
                                    oldDom.Cluster = new Alachisoft.NCache.Config.Dom.Cluster();
                                }
                                string topology = newDom.CacheSettings.CacheTopology.Topology;
                                if (topology != null)
                                {
                                    topology = topology.ToLower();

                                    if (topology.Equals("partitioned"))
                                    {
                                        topology = "partitioned-server";
                                    }

                                    else if (topology.Equals("replicated"))
                                    {
                                        topology = "replicated-server";
                                    }
                                    else if (topology.Equals("local"))
                                    {
                                        topology = "local-cache";
                                    }
                                }

                                oldDom.Cluster.Topology         = topology;
                                oldDom.Cluster.OpTimeout        = newDom.CacheSettings.CacheTopology.ClusterSettings.OpTimeout;
                                oldDom.Cluster.StatsRepInterval = newDom.CacheSettings.CacheTopology.ClusterSettings.StatsRepInterval;
                                oldDom.Cluster.UseHeartbeat     = newDom.CacheSettings.CacheTopology.ClusterSettings.UseHeartbeat;

                                if (oldDom.Cluster.Channel == null)
                                {
                                    oldDom.Cluster.Channel = new Alachisoft.NCache.Config.Dom.Channel();
                                }

                                oldDom.Cluster.Channel.TcpPort                 = newDom.CacheSettings.CacheTopology.ClusterSettings.Channel.TcpPort;
                                oldDom.Cluster.Channel.PortRange               = newDom.CacheSettings.CacheTopology.ClusterSettings.Channel.PortRange;
                                oldDom.Cluster.Channel.ConnectionRetries       = newDom.CacheSettings.CacheTopology.ClusterSettings.Channel.ConnectionRetries;
                                oldDom.Cluster.Channel.ConnectionRetryInterval = newDom.CacheSettings.CacheTopology.ClusterSettings.Channel.ConnectionRetryInterval;
                                oldDom.Cluster.Channel.InitialHosts            = createInitialHosts(newDom.CacheDeployment.Servers.NodesList, newDom.CacheSettings.CacheTopology.ClusterSettings.Channel.TcpPort);
                                oldDom.Cluster.Channel.NumInitHosts            = newDom.CacheDeployment.Servers.NodesList.Count;

                                if (newDom.CacheDeployment.ClientNodes != null)
                                {
                                    if (oldDom.ClientNodes == null)
                                    {
                                        oldDom.ClientNodes = new Alachisoft.NCache.Config.Dom.ClientNodes();
                                    }

                                    oldDom.ClientNodes = newDom.CacheDeployment.ClientNodes;
                                }
                            }
                        }

                        if (newDom.CacheSettings.AutoLoadBalancing != null)
                        {
                            oldDom.AutoLoadBalancing = newDom.CacheSettings.AutoLoadBalancing;
                        }
                        oldDom.IsRunning    = newDom.IsRunning;
                        oldDom.IsRegistered = newDom.IsRegistered;
                        oldDom.IsExpired    = newDom.IsExpired;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("DomHelper.convertToOldDom" + ex.Message);
            }
            return(oldDom);
        }
        private void AddLuceneQueryIndexDefaults()
        {
            if (!ValidateParameters())
            {
                return;
            }
            bool        successful = true;
            AssemblyDef asm        = null;

            //ArrayList cc = new ArrayList();
            Alachisoft.NCache.Config.Dom.Class[] queryClasses = null;
            string failedNodes = string.Empty;
            string serverName  = string.Empty;

            try
            {
                if (Port == -1)
                {
                    NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                }
                if (Server != null && Server != string.Empty)
                {
                    NCache.ServerName = Server;
                }
                if (Port != -1)
                {
                    NCache.Port = Port;
                }
                try
                {
                    cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                }
                catch (Exception e)
                {
                    OutputProvider.WriteErrorLine("Error: NCache service could not be contacted on server.");
                    return;
                }

                ToolsUtil.VerifyClusterConfigurations(cacheServer.GetNewConfiguration(CacheName), CacheName);


                string extension = ".dll";
                if (cacheServer != null)
                {
                    serverName = cacheServer.GetClusterIP();
                    if (cacheServer.IsRunning(CacheName))
                    {
                        throw new Exception(CacheName + " is Running on " + serverName +
                                            "\nStop the cache first and try again.");
                    }

                    serverConfig = cacheServer.GetNewConfiguration(CacheName);
                    //ConfiguredCacheInfo[] configuredCaches = cacheServer.GetAllConfiguredCaches();

                    if (serverConfig == null)
                    {
                        throw new Exception("Specified cache is not registered on the given server.");
                    }

                    //if (! Unregister)
                    //{
                    try
                    {
                        asm = AssemblyDef.LoadFrom(AssemblyPath);

                        extension = Path.GetExtension(asm.FullName);
                    }
                    catch (Exception e)
                    {
                        string message = string.Format("Could not load assembly \"" + AssemblyPath + "\". {0}", e.Message);
                        OutputProvider.WriteErrorLine("Error : {0}", message);
                        successful = false;
                        return;
                    }

                    if (asm == null)
                    {
                        throw new Exception("Could not load specified Assembly");
                    }

                    TypeDef type = asm.GetType(Class);


                    if (serverConfig.CacheSettings.QueryIndices == null)
                    {
                        serverConfig.CacheSettings.QueryIndices         = new Alachisoft.NCache.Config.Dom.QueryIndex();
                        serverConfig.CacheSettings.QueryIndices.Classes = queryClasses;
                    }

                    queryClasses = serverConfig.CacheSettings.QueryIndices.Classes;

                    serverConfig.CacheSettings.QueryIndices.Classes = GetSourceClass(GetClass(queryClasses, asm));


                    byte[] userId = null;
                    byte[] paswd  = null;
                    if (UserId != string.Empty && Password != string.Empty)
                    {
                        userId = EncryptionUtil.Encrypt(UserId);
                        paswd  = EncryptionUtil.Encrypt(Password);
                    }
                    serverConfig.ConfigVersion++;
                    if (serverConfig.CacheSettings.CacheType == "clustered-cache")
                    {
                        foreach (Address node in serverConfig.CacheDeployment.Servers.GetAllConfiguredNodes())
                        {
                            NCache.ServerName = node.IpAddress.ToString();
                            try
                            {
                                cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                                if (cacheServer.IsRunning(CacheName))
                                {
                                    throw new Exception(CacheName + " is Running on " + serverName +
                                                        "\nStop the cache first and try again.");
                                }

                                OutputProvider.WriteLine("Adding query indexes on node '{0}' to cache '{1}'.", node.IpAddress, CacheName);
                                cacheServer.RegisterCache(CacheName, serverConfig, "", true, userId, paswd, false);
                            }
                            catch (Exception ex)
                            {
                                OutputProvider.WriteErrorLine("Failed to Add Query Index on '{0}'. ", serverName);
                                OutputProvider.WriteErrorLine("Error Detail: '{0}'. ", ex.Message);
                                failedNodes = failedNodes + "/n" + node.IpAddress.ToString();
                                successful  = false;
                            }
                            finally
                            {
                                cacheServer.Dispose();
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            OutputProvider.WriteLine("Adding query indexes on node '{0}' to cache '{1}'.", serverName, CacheName);
                            cacheServer.RegisterCache(CacheName, serverConfig, "", true, userId, paswd, false);
                        }
                        catch (Exception ex)
                        {
                            OutputProvider.WriteErrorLine("Failed to Add Query Index on '{0}'. ", serverName);
                            OutputProvider.WriteErrorLine("Error Detail: '{0}'. ", ex.Message);
                            successful = false;
                        }
                        finally
                        {
                            cacheServer.Dispose();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                OutputProvider.WriteErrorLine("Error : {0}", e.Message);
                successful = false;
            }
            finally
            {
                NCache.Dispose();
                if (successful && !IsUsage)
                {
                    OutputProvider.WriteLine("Query indexes successfully added.");
                }
            }
        }
Beispiel #22
0
        /// <summary>
        /// The main entry point for the tool.
        /// </summary>ju
        static public void Run(string[] args)
        {
            bool successful = true;

            System.Reflection.Assembly           asm          = null;
            Alachisoft.NCache.Config.Dom.Class[] queryClasses = null;
            string failedNodes = string.Empty;
            string serverName  = string.Empty;

            try
            {
                object param = new ConfigureQueryIndexParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                cParam = (ConfigureQueryIndexParam)param;
                if (cParam.IsUsage)
                {
                    AssemblyUsage.PrintLogo(cParam.IsLogo);
                    AssemblyUsage.PrintUsage();
                    return;
                }
                if (!ValidateParameters())
                {
                    successful = false;
                    return;
                }
                if (cParam.Port == -1)
                {
                    NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                }
                if (cParam.Server != null && cParam.Server != string.Empty)
                {
                    NCache.ServerName = cParam.Server;
                }
                if (cParam.Port != -1)
                {
                    NCache.Port = cParam.Port;
                }

                cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                string extension = ".dll";
                if (cacheServer != null)
                {
                    serverName = cacheServer.GetClusterIP();
                    if (cacheServer.IsRunning(cParam.CacheId))
                    {
                        throw new Exception(cParam.CacheId + " is Running on " + serverName +
                                            "\nStop the cache first and try again.");
                    }

                    Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig =
                        cacheServer.GetNewConfiguration(cParam.CacheId);

                    if (serverConfig == null)
                    {
                        throw new Exception("Specified cache is not registered on the given server.");
                    }

                    try
                    {
                        asm = System.Reflection.Assembly.LoadFrom(cParam.AsmPath);

                        extension = Path.GetExtension(asm.FullName);
                    }
                    catch (Exception e)
                    {
                        string message = string.Format("Could not load assembly \"" + cParam.AsmPath + "\". {0}",
                                                       e.Message);
                        Console.Error.WriteLine("Error : {0}", message);
                        LogEvent(e.Message);
                        successful = false;
                        return;
                    }

                    if (asm == null)
                    {
                        throw new Exception("Could not load specified Assembly");
                    }

                    System.Type type = asm.GetType(cParam.Class, true);


                    if (serverConfig.CacheSettings.QueryIndices == null)
                    {
                        serverConfig.CacheSettings.QueryIndices         = new Alachisoft.NCache.Config.Dom.QueryIndex();
                        serverConfig.CacheSettings.QueryIndices.Classes = queryClasses;
                    }

                    queryClasses = serverConfig.CacheSettings.QueryIndices.Classes;

                    serverConfig.CacheSettings.QueryIndices.Classes = GetSourceClass(GetClass(queryClasses, asm));

                    if (serverConfig.CacheSettings.CacheType == "clustered-cache")
                    {
                        foreach (Address node in serverConfig.CacheDeployment.Servers.GetAllConfiguredNodes())
                        {
                            NCache.ServerName = node.IpAddress.ToString();
                            try
                            {
                                cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                                if (cacheServer.IsRunning(cParam.CacheId))
                                {
                                    throw new Exception(cParam.CacheId + " is Running on " + serverName +
                                                        "\nStop the cache first.");
                                }

                                Console.WriteLine("Adding query indexes on node '{0}' to cache '{1}'.", serverName, cParam.CacheId);
                                cacheServer.RegisterCache(cParam.CacheId, serverConfig, "", true,
                                                          cParam.IsHotApply);
                            }
                            catch (Exception ex)
                            {
                                Console.Error.WriteLine("Failed to Add Query Index on '{0}'. ", serverName);
                                Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);
                                failedNodes = failedNodes + "/n" + node.IpAddress.ToString();
                                LogEvent(ex.Message);
                                successful = false;
                            }
                            finally
                            {
                                cacheServer.Dispose();
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            Console.WriteLine("Adding query indexes on node '{0}' to cache '{1}'.", serverName, cParam.CacheId);
                            cacheServer.RegisterCache(cParam.CacheId, serverConfig, "", true, cParam.IsHotApply);
                        }
                        catch (Exception ex)
                        {
                            Console.Error.WriteLine("Failed to Add Query Index on '{0}'. ", NCache.ServerName);
                            Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);
                            LogEvent(ex.Message);
                            successful = false;
                        }
                        finally
                        {
                            cacheServer.Dispose();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error : {0}", e.Message);
                LogEvent(e.Message);
                successful = false;
            }
            finally
            {
                NCache.Dispose();
                if (successful && !cParam.IsUsage)
                {
                    Console.WriteLine("Query indexes successfully added.");
                }
            }
        }
 public void Deserialize(Runtime.Serialization.IO.CompactReader reader)
 {
     _updatedCacheConfig = (Alachisoft.NCache.Config.NewDom.CacheServerConfig)reader.ReadObject();
     _affectedNodesList = (ArrayList)reader.ReadObject();
     _affectedPartitions = (ArrayList)reader.ReadObject();
 }
Beispiel #24
0
        /// <summary>
        /// The main entry point for the tool.
        /// </summary>
        static public void Run(string[] args)
        {
            try
            {
                object param = new AddClientNodeParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                cParam = (AddClientNodeParam)param;
                if (cParam.IsUsage)
                {
                    AssemblyUsage.PrintLogo(cParam.IsLogo);
                    AssemblyUsage.PrintUsage();
                    return;
                }

                if (!ValidateParameters())
                {
                    return;
                }
                bool multipleServers = false;
                if (cParam.Server != null || cParam.Server != string.Empty)
                {
                    _serverList = cParam.Server.Split(',');
                    if (_serverList.Length > 1 || (_serverList[0].Contains(":")))
                    {
                        multipleServers = true;
                    }
                }
tryNextServer:
                if (multipleServers)
                {
                    string[] serverAddress = _serverList[index].Split(':');
                    if (serverAddress.Length == 2)
                    {
                        if (!IsValidIP(serverAddress[0]))
                        {
                            Console.Error.WriteLine("Error: Invalid Server IP.");
                            return;
                        }
                        NCache.ServerName = serverAddress[0];
                        try
                        {
                            NCache.Port = Convert.ToInt32(serverAddress[1]);
                        }
                        catch (Exception)
                        {
                            throw new Exception("Invalid Port :" + serverAddress[1] + " specified for server : " + serverAddress[0] + ".");
                        }
                    }
                    else
                    if (serverAddress.Length == 1)
                    {
                        if (!IsValidIP(serverAddress[0]))
                        {
                            Console.Error.WriteLine("Error: Invalid Server IP.");
                            return;
                        }
                        NCache.ServerName = serverAddress[0];
                        NCache.Port       = cParam.Port;
                        if (cParam.Port == -1)
                        {
                            NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                        }
                    }
                    else
                    {
                        throw new Exception("Invalid server Address specified, kindly specify as [IPAdress] or [IPAdress]:[Port].");
                    }
                }
                else
                {
                    if (cParam.Port != -1)
                    {
                        NCache.Port = cParam.Port;
                    }
                    if (cParam.Server != null || cParam.Server != string.Empty)
                    {
                        NCache.ServerName = cParam.Server;
                    }
                    if (cParam.Port == -1)
                    {
                        NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                    }
                }


                try
                {
                    _server     = NCache.ServerName;
                    cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                }
                catch (Exception ex)
                {
                    if (multipleServers)
                    {
                        if (index < _serverList.Length - 1)
                        {
                            Console.Error.WriteLine("Failed to connect to server : " + NCache.ServerName + ":" + NCache.Port + " \nTrying next server.");
                            index++;
                            goto tryNextServer;
                        }
                    }
                    throw ex;
                }
                config = cacheServer.GetNewConfiguration(cParam.CacheId);
                //for getting server mappings
                if (cParam.AcquireServerMapping)
                {
                    Alachisoft.NCache.Management.MappingConfiguration.Dom.MappingConfiguration mapping = cacheServer.GetServerMappingForClient();
                    if (mapping != null)
                    {
                        _clientIPMapping = mapping.ClientIPMapping;
                        foreach (Mapping mappingServer in mapping.ManagementIPMapping.MappingServers)
                        {
                            if (mappingServer != null)
                            {
                                _managementIPMapping.Add(mappingServer.PrivateIP, mappingServer);
                            }
                        }
                    }
                }
                if (config == null)
                {
                    Console.Error.WriteLine("Error : The cache'{0}' does not exist on server {1}:{2} .", cParam.CacheId, NCache.ServerName, NCache.Port);
                    return;
                }
                if (config.CacheSettings.CacheType == "clustered-cache")
                {
                    Console.WriteLine("Adding client node '{0}' to cache '{1}' on server {2}:{3}.",
                                      cParam.ClientNode, cParam.CacheId, NCache.ServerName, NCache.Port);
                    foreach (Address node in config.CacheDeployment.Servers.GetAllConfiguredNodes())
                    {
                        currentServerNodes.Add(node.IpAddress.ToString());
                    }
                }
                else
                {
                    Console.Error.WriteLine("Error: Client nodes cannot be added to local caches");
                    return;
                }
                if (config.CacheDeployment.ClientNodes != null)
                {
                    foreach (ClientNode clientNode in config.CacheDeployment.ClientNodes.NodesList)
                    {
                        if (cParam.ClientNode.Equals(clientNode.Name))
                        {
                            Console.Error.WriteLine("Error: " + clientNode.Name + " already part of \"" + cParam.CacheId + "\"");
                            return;
                        }
                        currentClientNodes.Add(clientNode.Name);
                    }
                }

                UpdateConfigs();
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error: {0}", ex.Message);
            }
        }
Beispiel #25
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 #26
0
        static public void Run(string[] args)
        {
            try
            {
                object param = new RemoveCacheParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                cParam = (RemoveCacheParam)param;
                if (cParam.IsUsage)
                {
                    AssemblyUsage.PrintLogo(cParam.IsLogo);
                    AssemblyUsage.PrintUsage();
                    return;
                }

                if (!ValidateParameters())
                {
                    return;
                }

                if (cParam.Port != -1)
                {
                    NCache.Port = cParam.Port;
                }

                if (cParam.Port == -1)
                {
                    NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                }

                if (cParam.Server != null || cParam.Server != string.Empty)
                {
                    NCache.ServerName = cParam.Server;
                }


                cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                Console.WriteLine("\nRemoving cache '{0}' on server {1}:{2}.", cParam.CacheId,
                                  cacheServer.GetBindIP(), NCache.Port);
                if (cacheServer != null)
                {
                    string getBindIp = string.Empty;
                    try
                    {
                        Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = cacheServer.GetNewConfiguration(cParam.CacheId);

                        if (serverConfig == null)
                        {
                            throw new Exception("Specified cache does not exist.");
                        }
                        if (serverConfig.CacheSettings.CacheType == "clustered-cache")
                        {
                            foreach (Address node in serverConfig.CacheDeployment.Servers.GetAllConfiguredNodes())
                            {
                                try
                                {
                                    NCache.ServerName = node.IpAddress.ToString();
                                    cacheServer       = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                                    cacheServer.UnregisterCache(cParam.CacheId, null, false);
                                    Console.WriteLine("Cache '{0}' successfully removed from server {1}:{2}.\n",
                                                      cParam.CacheId, NCache.ServerName, NCache.Port);
                                }
                                catch (Exception ex)
                                {
                                    Console.Error.WriteLine("Error: Failed to Rmove Cache '{0}' from server '{1}:{2}'. ",
                                                            cParam.CacheId, NCache.ServerName, NCache.Port);
                                    Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);

                                    LogEvent(ex.Message);
                                }
                                finally
                                {
                                    cacheServer.Dispose();
                                }
                            }
                        }
                        else
                        {
                            try
                            {
                                getBindIp = cacheServer.GetBindIP();
                                cacheServer.UnregisterCache(cParam.CacheId, null, false);
                                Console.WriteLine("Cache '{0}' successfully removed from server {1}:{2}.\n",
                                                  cParam.CacheId, getBindIp, NCache.Port);
                            }
                            catch (Exception e)
                            {
                                throw e;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine("Error: Failed to Rmove Cache '{0}' from server '{1}:{2}'. ",
                                                cParam.CacheId, cacheServer.GetBindIP(), NCache.Port);
                        Console.Error.WriteLine(ex.Message);
                        LogEvent(ex.Message);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error: {0}", e.Message);
                Console.Error.WriteLine();
                Console.Error.WriteLine(e.ToString());
            }
            finally
            {
                NCache.Dispose();
            }
        }
Beispiel #27
0
        /// <summary>
        /// The main entry point for the tool.
        /// </summary>ju
        static public void Run(string[] args)
        {
            System.Reflection.Assembly           asm          = null;
            Alachisoft.NCache.Config.Dom.Class[] queryClasses = null;
            string failedNodes = string.Empty;
            bool   sucessful   = false;
            string serverName  = string.Empty;

            try
            {
                object param = new RemoveQueryIndexParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                cParam = (RemoveQueryIndexParam)param;
                if (cParam.IsUsage)
                {
                    AssemblyUsage.PrintLogo(cParam.IsLogo);
                    AssemblyUsage.PrintUsage();
                    return;
                }
                if (!ValidateParameters())
                {
                    return;
                }
                if (cParam.Port == -1)
                {
                    NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                }
                if (cParam.Server != null && cParam.Server != string.Empty)
                {
                    NCache.ServerName = cParam.Server;
                }
                if (cParam.Port != -1)
                {
                    NCache.Port = cParam.Port;
                }

                cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));


                if (cacheServer != null)
                {
                    Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = cacheServer.GetNewConfiguration(cParam.CacheId);
                    serverName = cacheServer.GetClusterIP();
                    if (cacheServer.IsRunning(cParam.CacheId))
                    {
                        throw new Exception(cParam.CacheId + " is Running on " + serverName + "Stop the cache first.");
                    }



                    if (serverConfig == null)
                    {
                        throw new Exception("Specified cache is not registered on given server.");
                    }


                    Console.WriteLine("Removing query indexes on node '{0}' from cache '{1}'.",
                                      serverName, cParam.CacheId);
                    if (serverConfig.CacheSettings.QueryIndices != null)
                    {
                        if (serverConfig.CacheSettings.QueryIndices.Classes != null)
                        {
                            queryClasses = serverConfig.CacheSettings.QueryIndices.Classes;
                        }
                        else
                        {
                            return;
                        }

                        if (queryClasses != null)
                        {
                            serverConfig.CacheSettings.QueryIndices.Classes = GetSourceClass(GetClass(queryClasses));
                            if (serverConfig.CacheSettings.QueryIndices.Classes != null)
                            {
                                for (int i = 0; i < serverConfig.CacheSettings.QueryIndices.Classes.Length; i++)
                                {
                                    if (serverConfig.CacheSettings.QueryIndices.Classes[i].AttributesTable.Count < 1)
                                    {
                                        serverConfig.CacheSettings.QueryIndices.Classes[i] = null;
                                    }
                                }
                                bool NoClasses = true;
                                foreach (Class cls in serverConfig.CacheSettings.QueryIndices.Classes)
                                {
                                    if (cls != null)
                                    {
                                        NoClasses = false;
                                        break;
                                    }
                                }
                                if (NoClasses)
                                {
                                    serverConfig.CacheSettings.QueryIndices = null;
                                }
                            }
                            else
                            {
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("No such Query Index class found. ");
                        return;
                    }
                    if (serverConfig.CacheSettings.CacheType == "clustered-cache")
                    {
                        foreach (Address node in serverConfig.CacheDeployment.Servers.GetAllConfiguredNodes())
                        {
                            NCache.ServerName = node.IpAddress.ToString();
                            try
                            {
                                cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                                if (cacheServer.IsRunning(cParam.CacheId))
                                {
                                    throw new Exception(cParam.CacheId + " is Running on " + serverName + "Stop the cache first.");
                                }
                                cacheServer.RegisterCache(cParam.CacheId, serverConfig, "", true, cParam.IsHotApply);
                            }
                            catch (Exception ex)
                            {
                                Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);
                                failedNodes = failedNodes + "/n" + node.IpAddress.ToString();
                                LogEvent(ex.Message);
                                sucessful = false;
                            }
                            finally
                            {
                                cacheServer.Dispose();
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            cacheServer.RegisterCache(cParam.CacheId, serverConfig, "", true, cParam.IsHotApply);
                        }
                        catch (Exception ex)
                        {
                            Console.Error.WriteLine("Error Detail: '{0}'. ", ex.Message);
                            LogEvent(ex.Message);
                            sucessful = false;
                        }
                        finally
                        {
                            cacheServer.Dispose();
                        }
                    }
                }
                sucessful = true;
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Failed to Remove Query Index on node '{0}'. ", serverName);
                Console.Error.WriteLine("Error : {0}", e.Message);
                LogEvent(e.Message);
                sucessful = false;
            }
            finally
            {
                NCache.Dispose();
                if (sucessful && !cParam.IsUsage)
                {
                    Console.WriteLine("Query indexes successfully removed.");
                }
            }
        }
 public NewCacheRegisterationInfo(Alachisoft.NCache.Config.NewDom.CacheServerConfig cacheConfig, ArrayList nodesList, ArrayList affectedPartitions)
 {
     _updatedCacheConfig = cacheConfig;
     _affectedNodesList = nodesList;
     _affectedPartitions = affectedPartitions;
 }
Beispiel #29
0
 public NewCacheRegisterationInfo(Alachisoft.NCache.Config.NewDom.CacheServerConfig cacheConfig, ArrayList nodesList, ArrayList affectedPartitions)
 {
     _updatedCacheConfig = cacheConfig;
     _affectedNodesList  = nodesList;
     _affectedPartitions = affectedPartitions;
 }
Beispiel #30
0
        private void AddLuceneAnalyzer()
        {
            if (!ValidateParameters())
            {
                return;
            }

            System.Reflection.Assembly asm = null;
            Alachisoft.NCache.Config.Dom.LuceneDeployment[] prov = null;
            string       failedNodes = string.Empty;
            string       serverName  = string.Empty;
            ICacheServer cacheServer = null;
            bool         successFull = true;

            try
            {
                if (Port != -1)
                {
                    NCache.Port = Port;
                }

                if (Port == -1)
                {
                    NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                }
                if (Server != null && Server != string.Empty)
                {
                    NCache.ServerName = Server;
                }

                try
                {
                    cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                }
                catch (Exception e)
                {
                    successFull = false;
                    OutputProvider.WriteErrorLine("Error: NCache service could not be contacted on server.");
                    return;
                }

                if (cacheServer != null)
                {
                    serverName = cacheServer.GetClusterIP();
                    if (cacheServer.IsRunning(CacheName))
                    {
                        successFull = false;
                        throw new Exception(CacheName + " is Running on " + cacheServer.GetClusterIP() + "\nStop the cache first and try again.");
                    }
                    Alachisoft.NCache.Config.NewDom.CacheServerConfig serverConfig = cacheServer.GetNewConfiguration(CacheName);


                    if (serverConfig == null)
                    {
                        successFull = false;
                        throw new Exception("Specified cache is not registered on the given server.");
                    }
                    ToolsUtil.VerifyClusterConfigurations(serverConfig, CacheName);
                    try
                    {
                        asm = System.Reflection.Assembly.LoadFrom(AssemblyPath);
                    }
                    catch (Exception e)
                    {
                        successFull = false;
                        string message = string.Format("Could not load assembly \"" + AssemblyPath + "\". {0}", e.Message);
                        OutputProvider.WriteErrorLine("Error: {0}", message);
                        return;
                    }

                    if (asm == null)
                    {
                        successFull = false;
                        throw new Exception("Could not load specified assembly.");
                    }

                    if (serverConfig.CacheSettings.LuceneSettings == null)
                    {
                        serverConfig.CacheSettings.LuceneSettings = new Alachisoft.NCache.Config.Dom.LuceneSettings();
                    }

                    System.Type type = asm.GetType(Class, true);

                    if (!type.IsSubclassOf(typeof(Analyzer)))
                    {
                        successFull = false;
                        OutputProvider.WriteErrorLine("Error: Specified class does not implement Analyzer.");
                        return;
                    }
                    else
                    {
                        if (serverConfig.CacheSettings.LuceneSettings.Analyzers == null)
                        {
                            serverConfig.CacheSettings.LuceneSettings.Analyzers           = new Analyzers();
                            serverConfig.CacheSettings.LuceneSettings.Analyzers.Providers = prov;
                        }
                        prov = serverConfig.CacheSettings.LuceneSettings.Analyzers.Providers;
                        serverConfig.CacheSettings.LuceneSettings.Analyzers.Providers = GetAnalyzers(GetProvider(prov, asm));
                    }

                    byte[] userId = null;
                    byte[] paswd  = null;
                    if (UserId != string.Empty && Password != string.Empty)
                    {
                        userId = EncryptionUtil.Encrypt(UserId);
                        paswd  = EncryptionUtil.Encrypt(Password);
                    }
                    serverConfig.ConfigVersion++;
                    if (serverConfig.CacheSettings.CacheType == "clustered-cache")
                    {
                        foreach (Address node in serverConfig.CacheDeployment.Servers.GetAllConfiguredNodes())
                        {
                            NCache.ServerName = node.IpAddress.ToString();
                            try
                            {
                                cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));

                                if (cacheServer.IsRunning(CacheName))
                                {
                                    throw new Exception(CacheName + " is Running on " + serverName +
                                                        "\nStop the cache first and try again.");
                                }

                                OutputProvider.WriteLine("Adding Analyzer on node '{0}' to cache '{1}'.", node.IpAddress, CacheName);
                                cacheServer.RegisterCache(CacheName, serverConfig, "", true, userId, paswd, false);
                            }
                            catch (Exception ex)
                            {
                                OutputProvider.WriteErrorLine("Failed to Lucene Analyzer on node '{0}'. ", serverName);
                                OutputProvider.WriteErrorLine("Error Detail: '{0}'. ", ex.Message);
                                failedNodes = failedNodes + "/n" + node.IpAddress.ToString();
                                successFull = false;
                            }
                            finally
                            {
                                cacheServer.Dispose();
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            OutputProvider.WriteLine("Adding Analyzer on node '{0}' to cache '{1}'.", serverName, CacheName);
                            cacheServer.RegisterCache(CacheName, serverConfig, "", true, userId, paswd, false);
                        }
                        catch (Exception ex)
                        {
                            OutputProvider.WriteErrorLine("Failed to Lucene Analyzer on node '{0}'. ", serverName);
                            OutputProvider.WriteErrorLine("Error Detail: '{0}'. ", ex.Message);
                            successFull = false;
                        }
                        finally
                        {
                            NCache.Dispose();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                successFull = false;
                OutputProvider.WriteErrorLine("Failed to Lucene Analyzer on node '{0}'. ", NCache.ServerName);
                OutputProvider.WriteErrorLine("Error : {0}", e.Message);
            }
            finally
            {
                NCache.Dispose();
                if (successFull && !IsUsage)
                {
                    OutputProvider.WriteLine("Analyzer successfully added");
                }
            }
        }
Beispiel #31
0
        /// <summary>
        /// The main entry point for the tool.
        /// </summary>
        public static void Run(string[] args)
        {
            try
            {
                object param = new AddClientNodeParam();
                CommandLineArgumentParser.CommandLineParser(ref param, args);
                cParam = (AddClientNodeParam)param;
                if (cParam.IsUsage)
                {
                    AssemblyUsage.PrintLogo(cParam.IsLogo);
                    AssemblyUsage.PrintUsage();
                    return;
                }

                if (!ValidateParameters()) return;
                bool multipleServers = false;
                if (cParam.Server != null || cParam.Server != string.Empty)
                {
                    _serverList = cParam.Server.Split(',');
                    if (_serverList.Length > 1 || (_serverList[0].Contains(":")))
                    {
                        multipleServers = true;
                    }

                }
                tryNextServer:
                if (multipleServers)
                {
                    string[] serverAddress = _serverList[index].Split(':');
                    if (serverAddress.Length == 2)
                    {
                        if (!IsValidIP(serverAddress[0]))
                        {
                            Console.Error.WriteLine("Error: Invalid Server IP.");
                            return;
                        }
                        NCache.ServerName = serverAddress[0];
                        try
                        {
                            NCache.Port = Convert.ToInt32(serverAddress[1]);
                        }
                        catch (Exception)
                        {
                            throw new Exception("Invalid Port :" + serverAddress[1] + " specified for server : " + serverAddress[0] + ".");
                        }

                    }
                    else
                        if (serverAddress.Length == 1)
                        {
                            if (!IsValidIP(serverAddress[0]))
                            {
                                Console.Error.WriteLine("Error: Invalid Server IP.");
                                return;
                            }
                            NCache.ServerName = serverAddress[0];
                            NCache.Port = cParam.Port;
                            if (cParam.Port == -1) NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;

                        }
                        else
                        {
                            throw new Exception("Invalid server Address specified, kindly specify as [IPAdress] or [IPAdress]:[Port].");
                        }
                }
                else
                {
                    if (cParam.Port != -1)
                    {
                        NCache.Port = cParam.Port;
                    }
                    if (cParam.Server != null || cParam.Server != string.Empty)
                    {
                        NCache.ServerName = cParam.Server;
                    }
                    if (cParam.Port == -1) NCache.Port = NCache.UseTcp ? CacheConfigManager.NCacheTcpPort : CacheConfigManager.HttpPort;
                }

                try
                {
                    _server = NCache.ServerName;
                    cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                }
                catch (Exception ex)
                {
                    if (multipleServers)
                    {
                        if (index  < _serverList.Length - 1)
                        {
                            Console.Error.WriteLine("Failed to connect to server : " + NCache.ServerName + ":"+NCache.Port+" \nTrying next server.");
                            index++;
                            goto tryNextServer;
                        }
                    }
                    throw ex;
                }
                config = cacheServer.GetNewConfiguration(cParam.CacheId);
                //for getting server mappings
                if (cParam.AcquireServerMapping)
                {
                    Alachisoft.NCache.Management.MappingConfiguration.Dom.MappingConfiguration mapping=cacheServer.GetServerMappingForClient();
                    if (mapping != null)
                    {
                        _clientIPMapping = mapping.ClientIPMapping;
                        foreach (Mapping mappingServer in mapping.ManagementIPMapping.MappingServers)
                        {
                            if (mappingServer != null)
                            {
                                _managementIPMapping.Add(mappingServer.PrivateIP, mappingServer);
                            }
                        }
                    }
                }
                if (config == null)
                {
                    Console.Error.WriteLine("Error : The cache'{0}' does not exist on server {1}:{2} .", cParam.CacheId, NCache.ServerName, NCache.Port);
                    return;
                }
                if (config.CacheSettings.CacheType == "clustered-cache")
                {
                    Console.WriteLine("Adding client node '{0}' to cache '{1}' on server {2}:{3}.",
                          cParam.ClientNode, cParam.CacheId, NCache.ServerName, NCache.Port);
                    foreach (Address node in config.CacheDeployment.Servers.GetAllConfiguredNodes())
                    {
                        currentServerNodes.Add(node.IpAddress.ToString());
                    }
                }
                else
                {
                    Console.Error.WriteLine("Error: Client nodes cannot be added to local caches");
                    return;
                }
                if (config.CacheDeployment.ClientNodes != null)
                {

                    foreach (ClientNode clientNode in config.CacheDeployment.ClientNodes.NodesList)
                    {

                        if (cParam.ClientNode.Equals(clientNode.Name))
                        {
                            Console.Error.WriteLine("Error: " + clientNode.Name + " already part of \"" + cParam.CacheId + "\"");
                            return;
                        }
                        currentClientNodes.Add(clientNode.Name);
                    }
                }

                UpdateConfigs();
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error: {0}", ex.Message);
            }
        }