Пример #1
0
        protected override void BeginProcessing()
        {
            if (string.IsNullOrEmpty(Server))
            {
                Server = ProviderUtil.GetLocalAddress();
            }
            const string exceptionString = "Invalid context, to Add-Shard you must be in \n NoSDB:\\databasecluster\\Shards \n ";

            SessionState s1 = SessionState;

            string[] pathChunks = ProviderUtil.SplitPath(s1.Path.CurrentLocation.Path, s1.Drive.Current);

            if (!(s1.Drive.Current is NosDBPSDriveInfo))
            {
                throw new Exception(exceptionString);
            }

            if (ConfigurationConnection.ConfigCluster == null)
            {
                throw new Exception(ProviderUtil.CONFIG_NOT_CONNECTED_EXCEPTION);
            }

            NodeDetail thisNode;

            new NoSDbDetail(pathChunks, s1.Drive.Current).TryGetNodeDetail(out thisNode);

            if (!thisNode.NodeType.Equals(PathType.Shards))
            {
                throw new Exception(exceptionString);
            }
        }
Пример #2
0
        protected override void BeginProcessing()
        {
            string exceptionString =
                "Invalid context, to Move-Collection you must be in \n NoSDB:\\databasecluster\\Databases\\[DatabaseName]\\[CollectionName] \n ";
            NodeDetail   thisNode;
            SessionState sessionState = SessionState;

            string[] pathChunks = ProviderUtil.SplitPath(sessionState.Path.CurrentLocation.Path, sessionState.Drive.Current);

            if (!(sessionState.Drive.Current is NosDBPSDriveInfo))
            {
                throw new Exception(exceptionString);
            }

            if (!new NoSDbDetail(pathChunks, sessionState.Drive.Current).TryGetNodeDetail(out thisNode))
            {
                throw new Exception("Unable to Get Node Details :" + sessionState.Drive.Current);
            }

            if (!thisNode.NodeType.Equals(PathType.Collection))
            {
                throw new Exception(exceptionString);
            }

            _collectionName = thisNode.NodeName;
            _databaseName   = ((CollectionValueDetail)thisNode).Database;
        }
Пример #3
0
        protected override void BeginProcessing()
        {
            NodeDetail   thisNode = null;
            SessionState s1       = this.SessionState;

            string[] pathChunks = ProviderUtil.SplitPath(s1.Path.CurrentLocation.Path, (PSDriveInfo)s1.Drive.Current);
            if (s1.Drive.Current is NosDBPSDriveInfo)
            {
                if (ConfigurationConnection.ConfigCluster == null)
                {
                    throw new Exception(ProviderUtil.CONFIG_NOT_CONNECTED_EXCEPTION);
                }
                if (new NoSDbDetail(pathChunks, (PSDriveInfo)s1.Drive.Current).TryGetNodeDetail(out thisNode))
                {
                }

                if (thisNode.NodeType.Equals(PathType.Shards))
                {
                }
                else
                {
                    throw new System.Exception("invalid Context, to Remove-Shard you must be in \n NoSDB:\\databasecluster\\Shards \n ");
                }
            }

            else
            {
                throw new System.Exception("invalid Context, to Remove-Shard you must be in \n NoSDB:\\databasecluster\\Shards \n ");
            }
        }
Пример #4
0
        protected override void BeginProcessing()
        {
            SessionState s1 = SessionState;

            string[] pathChunks = ProviderUtil.SplitPath(s1.Path.CurrentLocation.Path, s1.Drive.Current);
            if (s1.Drive.Current is NosDBPSDriveInfo)
            {
                if (ConfigurationConnection.ConfigCluster == null)
                {
                    throw new Exception(ProviderUtil.CONFIG_NOT_CONNECTED_EXCEPTION);
                }
                NodeDetail thisNode;
                if (new NoSDbDetail(pathChunks, s1.Drive.Current).TryGetNodeDetail(out thisNode))
                {
                }
                if (thisNode.NodeType.Equals(PathType.Collection))
                {
                    _databaseName   = ((CollectionValueDetail)thisNode).Database;
                    _collectionName = thisNode.NodeName;
                    switch (Format.ToLower())
                    {
                    case "json":
                        _dataType = EXIMDataType.JSON;
                        break;

                    case "csv":
                        _dataType = EXIMDataType.CSV;
                        break;
                    }
                }
                else
                {
                    throw new Exception("You must be in NosDB:\\databasecluster\\databases\\database\\collections\\collection> for Export-Data.");
                }
            }
            else
            {
                throw new Exception("You must be in NosDB:\\databasecluster\\databases\\database\\collections\\collection> for Export-Data.");
            }
        }
Пример #5
0
        protected override void BeginProcessing()
        {
            string       exceptionString = "invalid Context, to Stop-Shard you must be in \n NoSDB:\\databasecluster\\Shards \n ";
            NodeDetail   thisNode        = null;
            SessionState s1 = this.SessionState;

            string[] pathChunks = ProviderUtil.SplitPath(s1.Path.CurrentLocation.Path, (PSDriveInfo)s1.Drive.Current);
            if (s1.Drive.Current is NosDBPSDriveInfo)
            {
                if (ConfigurationConnection.ConfigCluster == null)
                {
                    throw new Exception(ProviderUtil.CONFIG_NOT_CONNECTED_EXCEPTION);
                }
                if (new NoSDbDetail(pathChunks, (PSDriveInfo)s1.Drive.Current).TryGetNodeDetail(out thisNode))
                {
                }

                if (thisNode.NodeType.Equals(PathType.Shards))
                {
                    if (string.IsNullOrEmpty(Name))
                    {
                        throw new Exception("Specify value for parameter Name or try to stop shard from:\nNoSDB:\\databasecluster\\Shards\\shard. ");
                    }
                }
                else if (thisNode.NodeType.Equals(PathType.Shard))
                {
                    Name = thisNode.NodeName;
                }
                else
                {
                    throw new System.Exception(exceptionString);
                }
            }

            else
            {
                throw new System.Exception(exceptionString);
            }
        }
Пример #6
0
        protected override void BeginProcessing()
        {
            NodeDetail   thisNode = null;
            SessionState s1       = this.SessionState;

            string[] pathChunks = ProviderUtil.SplitPath(s1.Path.CurrentLocation.Path, (PSDriveInfo)s1.Drive.Current);
            if (s1.Drive.Current is NosDBPSDriveInfo)
            {
                if (ConfigurationConnection.ConfigCluster == null)
                {
                    throw new Exception(ProviderUtil.CONFIG_NOT_CONNECTED_EXCEPTION);
                }

                if (!Path.EndsWith("\\"))
                {
                    Path = Path + "\\";
                }
                //Path = Path + ProviderUtil.CONFIGURATION_DUMP_FILE_NAME;
                if (ConfigurationConnection.ConfigCluster.Name.Equals(MiscUtil.CLUSTERED))
                {
                    ConfigurationConnection.UpdateClusterConfiguration();
                }
                object[] configs = new object[2];
                configs[0] = ConfigurationConnection.ConfigCluster;
                configs[1] = ConfigurationConnection.ClusterConfiguration;


                string configurationStr = JsonConvert.SerializeObject(configs,
                                                                      Newtonsoft.Json.Formatting.Indented);

                WriteConfigurationToFile(configurationStr, ConfigurationConnection.ClusterConfiguration.DisplayName);
            }
            else
            {
                throw new Exception(ProviderUtil.CONFIG_NOT_CONNECTED_EXCEPTION);
            }
        }
Пример #7
0
        protected override void BeginProcessing()
        {
            ConfigurationConnection.UpdateClusterConfiguration();
            List <string> shards = new List <string>(ConfigurationConnection.ClusterConfiguration.Deployment.Shards.Keys);

            if (shards == null || shards.Count == 0)
            {
                throw new Exception("No shard exist");
            }
            if (string.IsNullOrEmpty(Shard))
            {
                Shard = shards[0];
            }
            else if (!shards.Contains(Shard))
            {
                throw new Exception("Specified shard doesn't exist");
            }
            _collectionName = GetCollectionName(Shard);

            string[] paramArray = null;


            NodeDetail   thisNode = null;
            SessionState s1       = this.SessionState;

            string[] pathChunks = ProviderUtil.SplitPath(s1.Path.CurrentLocation.Path, (PSDriveInfo)s1.Drive.Current);

            if (s1.Drive.Current is NosDBPSDriveInfo)
            {
                if (ConfigurationConnection.ConfigCluster == null)
                {
                    throw new Exception(ProviderUtil.CONFIG_NOT_CONNECTED_EXCEPTION);
                }
                //NodeDetail thisNode;
                if (new NoSDbDetail(pathChunks, s1.Drive.Current).TryGetNodeDetail(out thisNode))
                {
                    if (thisNode.NodeType.Equals(PathType.Database))
                    {
                        if (_drop)
                        {
                            _databaseName     = thisNode.NodeName;
                            _connectionString = ProviderUtil.GetConnectionString(_databaseName);
                            _database         = Alachisoft.NosDB.Client.NosDB.InitializeDatabase(_connectionString);
                            ConfigurationConnection.UpdateClusterConfiguration();
                            if (((DatabaseConfiguration)thisNode.Configuration).Storage.Collections.ContainsCollection(
                                    _collectionName))
                            {
                                String query = "DROP COLLECTION $" + _collectionName + "$ {\"Database\":\"" +
                                               thisNode.NodeName + "\"}";
                                _database.ExecuteNonQuery(query);

                                Thread.Sleep(5000);
                                ConfigurationConnection.UpdateClusterConfiguration();
                            }
                        }
                        else
                        {
                            _databaseName     = thisNode.NodeName;
                            _connectionString = ProviderUtil.GetConnectionString(_databaseName);
                            _database         = Alachisoft.NosDB.Client.NosDB.InitializeDatabase(_connectionString);
                            ConfigurationConnection.UpdateClusterConfiguration();
                            pathChunks = ProviderUtil.SplitPath(s1.Path.CurrentLocation.Path,
                                                                (PSDriveInfo)s1.Drive.Current);
                            new NoSDbDetail(pathChunks, s1.Drive.Current).TryGetNodeDetail(out thisNode);

                            if (!((DatabaseConfiguration)thisNode.Configuration).Storage.Collections.ContainsCollection(
                                    _collectionName))
                            {
                                String query = "CREATE COLLECTION $" + _collectionName + "$ {\"Database\":\"" +
                                               thisNode.NodeName + "\", \"Shard\": \"" + Shard + "\"}";

                                try
                                {
                                    _database.ExecuteNonQuery(query);
                                }
                                catch (Exception e)
                                {
                                    if (!e.Message.Contains("Collection with name: " + _collectionName + " already exists"))
                                    {
                                        throw e;
                                    }
                                }
                                do
                                {
                                    Thread.Sleep(2000);
                                    ConfigurationConnection.UpdateClusterConfiguration();
                                    pathChunks = ProviderUtil.SplitPath(s1.Path.CurrentLocation.Path,
                                                                        (PSDriveInfo)s1.Drive.Current);
                                    new NoSDbDetail(pathChunks, s1.Drive.Current).TryGetNodeDetail(out thisNode);
                                } while (
                                    !((DatabaseConfiguration)thisNode.Configuration).Storage.Collections
                                    .ContainsCollection(
                                        _collectionName));
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("You must be in NosDB:\\databasecluster\\databases\\database> for Test-Stress.");
                    }
                }
            }
            else
            {
                throw new Exception("You must be in NosDB:\\databasecluster\\databases\\database> for Test-Stress.");
            }
        }
Пример #8
0
        protected override void BeginProcessing()
        {
            if (Query.Equals(string.Empty) && InputFile.Equals(string.Empty))
            {
                throw new Exception("Invoke the command with argument Query|InputFile");
            }
            if (Query != string.Empty && InputFile != string.Empty)
            {
                throw new Exception("The Query and the InputFile options are mutually exclusive");
            }
            string       dbName   = string.Empty;
            NodeDetail   thisNode = null;
            SessionState s1       = this.SessionState;

            string[] pathChunks = ProviderUtil.SplitPath(s1.Path.CurrentLocation.Path, (PSDriveInfo)s1.Drive.Current);
            if (s1.Drive.Current is NosDBPSDriveInfo)
            {
                if (ConfigurationConnection.ConfigCluster == null)
                {
                    throw new Exception(ProviderUtil.CONFIG_NOT_CONNECTED_EXCEPTION);
                }
                new NoSDbDetail(pathChunks, (PSDriveInfo)s1.Drive.Current).TryGetNodeDetail(out thisNode);

                if (thisNode is IDatabaseContext)
                {
                    dbName           = ((IDatabaseContext)thisNode).DatabaseName;
                    _databaseContext = true;
                }
                else
                {
                    dbName = "$sysdb";
                }
                //conString = "nosdb://" + ConfigurationConnection.Current.ConfigServerIP + ":" +
                //            ConfigurationConnection.Current.Port + "/" +
                //            ConfigurationConnection.ClusterConfiguration.Name + "/" + dbName;
                bool localInstance;
                if (ConfigurationConnection.ClusterConfiguration.Name.Equals("local",
                                                                             StringComparison.InvariantCultureIgnoreCase))
                {
                    localInstance = true;
                }
                else
                {
                    localInstance = false;
                }
                conString = ProviderUtil.GetConnectionString(dbName);
                //conString = "Data Source=" + ConfigurationConnection.Current.ConfigServerIP + ";" + "Port=" +
                //            ConfigurationConnection.Current.Port + ";" + "Database=" + dbName + ";" + "Local Instance="+localInstance+";";
            }

            if (InputFile != string.Empty)
            {
                if (!File.Exists(InputFile))
                {
                    throw new Exception("Input file does't exist");
                }
                string text = File.ReadAllText(InputFile);
                text     = text.Replace("\r\n", "");
                queryArr = text.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            }
        }