protected override void ProcessRecord() { var sConfiguration = new ShardConfiguration { Port = Port, Name = Shard, NodeHeartbeatInterval = HeartBeat, }; var serverNodes = new Dictionary <string, ServerNode>(); var sNode = new ServerNode { Name = Server.Split('[', ']')[0] }; int priority = 1; if (Server.Contains('[')) { string priorityString = Server.Split('[', ']')[1]; int.TryParse(priorityString, out priority); priority = priority > 3 ? 3 : priority; } sNode.Priority = priority < 1 ? 1 : priority; serverNodes.Add(sNode.Name, sNode); sConfiguration.Servers = new ServerNodes(); if (serverNodes.Count > 0) { sConfiguration.Servers.Nodes = serverNodes; } ClusterConfiguration config = new ClusterConfiguration { Name = Common.MiscUtil.CLUSTERED, DisplayName = Name, Deployment = new DeploymentConfiguration() }; config.Deployment.AddShard(sConfiguration); var current = new RemoteConfigurationManager(); current.CreateCluster(config, new SSPIClientAuthenticationCredential()); if (current.VerifyConfigurationCluster()) { ConfigurationConnection.ConfigCluster = current.GetConfigurationClusterConfiguration(); ConfigurationConnection.ClusterConfiguration = current.GetDatabaseClusterConfig(true); ConfigurationConnection.Current = current; ConfigurationConnection.UpdateDatabaseClusterInfo(); } SessionState.Path.SetLocation(ProviderUtil.DRIVE_ROOT + ":\\" + ConfigurationConnection.ClusterConfiguration.DisplayName); }
protected override void BeginProcessing() { if (string.IsNullOrEmpty(Server)) { Server = ProviderUtil.GetLocalAddress(); } var rcm = new RemoteConfigurationManager(); rcm.Initilize(StandAlone?MiscUtil.LOCAL:MiscUtil.CLUSTERED, Server, Port, new ConfigurationChannelFormatter(), new SSPIClientAuthenticationCredential()); if (!_standAlone) { if (rcm.VerifyConfigurationCluster()) { ConfigurationConnection.ConfigCluster = rcm.GetConfigurationClusterConfiguration(); ConfigurationConnection.ClusterConfiguration = rcm.GetDatabaseClusterConfig(true); ConfigurationConnection.Current = rcm; ConfigurationConnection.UpdateDatabaseClusterInfo(); } else { throw new Exception("Database cluster does not exist on the specified server."); } } else { var localConfig = rcm.GetDatabaseClusterConfig(false); if (localConfig != null) { var configCluster = new ConfigServerConfiguration { Name = MiscUtil.STAND_ALONE, Port = Port, Servers = new ServerNodes() }; configCluster.Servers.AddNode(new ServerNode { Name = Server, Priority = 1 }); ConfigurationConnection.ConfigCluster = configCluster; ConfigurationConnection.ClusterConfiguration = localConfig; ConfigurationConnection.Current = rcm; ConfigurationConnection.UpdateClusterConfiguration(); ConfigurationConnection.UpdateDatabaseClusterInfo(); } else { throw new Exception("Standalone database does not exist on the specified server."); } } }
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); } }
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."); } }