示例#1
0
        protected override void ProcessRecord()
        {
            RemoteConfigurationManager rcm = ConfigurationConnection.Current;

            rcm.MoveCollection(true, _databaseName, _collectionName, NewShard);
            WriteObject("Data Transfer has started. You can monitor the progress through Perfmon Counters.");
        }
        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);
        }
示例#3
0
        protected override void BeginProcessing()
        {
            RemoteConfigurationManager remoteSession = new RemoteConfigurationManager();

            remoteSession.Initilize(MiscUtil.CLUSTERED, Server, Port, new ClientConfigurationFormatter(), ConfigurationConnection.Current.ClientCredential);
            IList <IUser> loginList   = remoteSession.GetLogins();
            string        currentUser = ConfigurationConnection.Current.ClientCredential.UserName;

            if (!string.IsNullOrEmpty(ConfigurationConnection.Current.ClientCredential.UserName) && !UserExist(loginList, ConfigurationConnection.Current.ClientCredential.UserName))
            {
                try
                {
                    SafeTokenHandle tokenHandle;
                    bool            isLogon = SSPIUtility.LogonUser(Username, Password, out tokenHandle);
                    if (isLogon)
                    {
                        using (WindowsIdentity.Impersonate(tokenHandle.DangerousGetHandle()))
                        {
                            remoteSession = new RemoteConfigurationManager();
                            remoteSession.Initilize(MiscUtil.CLUSTERED, Server, Port, new ClientConfigurationFormatter(), ConfigurationConnection.Current.ClientCredential);
                            IUser user;
                            user = new User(currentUser);

                            try
                            {
                                if (remoteSession.CreateUser(user))
                                {
                                    remoteSession.Grant(true, new ResourceId()
                                    {
                                        Name = Alachisoft.NosDB.Common.MiscUtil.NOSDB_CLUSTER_SERVER, ResourceType = Alachisoft.NosDB.Common.Security.Impl.Enums.ResourceType.System
                                    }, user.Username, ServerRole.sysadmin.ToString());
                                }
                            }
                            catch (SecurityException exc)
                            {
                                if (exc.ErrorCode.Equals(ErrorCodes.Security.USER_ALREADY_EXIST))
                                {
                                    remoteSession.Grant(true, new ResourceId()
                                    {
                                        Name = Alachisoft.NosDB.Common.MiscUtil.NOSDB_CLUSTER_SERVER, ResourceType = Alachisoft.NosDB.Common.Security.Impl.Enums.ResourceType.System
                                    }, user.Username, ServerRole.sysadmin.ToString());
                                }
                            }
                        }
                        tokenHandle.Release();
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
示例#4
0
        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.");
                }
            }
        }
示例#5
0
 public static void StartShard(ManagementInfo managementInfo)
 {
     try
     {
         RemoteConfigurationManager remoteConfigurationManager = InitializeRemoteConfigurationManager(managementInfo);
         remoteConfigurationManager.StartShard(managementInfo.ShardName);
     }
     catch (ManagementException)
     {
         throw;
     }
     catch (Exception exception)
     {
         throw new ManagementException(exception.Message, exception);
     }
 }
示例#6
0
 public static void MoveCollection(ManagementInfo managementInfo)
 {
     try
     {
         RemoteConfigurationManager remoteConfigurationManager = InitializeRemoteConfigurationManager(managementInfo);
         remoteConfigurationManager.MoveCollection(true, managementInfo.DatabaseName,
                                                   managementInfo.CollectionName, managementInfo.ShardName);
     }
     catch (ManagementException)
     {
         throw;
     }
     catch (Exception exception)
     {
         throw new ManagementException(exception.Message, exception);
     }
 }
示例#7
0
        private static RemoteConfigurationManager InitializeRemoteConfigurationManager(ManagementInfo managementInfo)
        {
            if (managementInfo.ConfigServerIp == null)
            {
                managementInfo.ConfigServerIp = NetworkUtil.GetLocalIPAddress().ToString();
            }

            if (managementInfo.ConfigServerPort == 0)
            {
                managementInfo.ConfigServerPort = NetworkUtil.DEFAULT_CS_HOST_PORT;
            }

            IClientAuthenticationCredential clientAuthenticationCredential = new SSPIClientAuthenticationCredential();

            var remoteConfigurationManager = new RemoteConfigurationManager();

            remoteConfigurationManager.Initilize(MiscUtil.CLUSTERED, managementInfo.ConfigServerIp, managementInfo.ConfigServerPort, new ConfigurationChannelFormatter(), clientAuthenticationCredential);

            return(remoteConfigurationManager);
        }
示例#8
0
        public static void StopNode(ManagementInfo managementInfo)
        {
            try
            {
                RemoteConfigurationManager remoteConfigurationManager = InitializeRemoteConfigurationManager(managementInfo);

                var serverNode = new ServerNode {
                    Name = managementInfo.ServerName
                };

                remoteConfigurationManager.StopNode(managementInfo.ShardName, serverNode);
            }
            catch (ManagementException)
            {
                throw;
            }
            catch (Exception exception)
            {
                throw new ManagementException(exception.Message, exception);
            }
        }
示例#9
0
        private static void VerifyPrimeryNode()
        {
            if (_configClusterInfo == null)
            {
                throw new Exception("Kindly connect database cluster to continue");
            }
            if (ConfigCluster.Name.Equals(MiscUtil.CLUSTERED) || ConfigCluster.Name.Equals("standalone", StringComparison.InvariantCultureIgnoreCase))
            {
                if (activeRcm != null)
                {
                    if (ConfigCluster.Name.Equals("standalone", StringComparison.InvariantCultureIgnoreCase))
                    {
                        return;
                    }

                    try
                    {
                        if (activeRcm.VerifyConfigurationClusterPrimery(_configClusterInfo.Name))
                        {
                            return;
                        }
                    }
                    catch
                    {
                    }
                }
                if (activeRcm == null)
                {
                    activeRcm = new RemoteConfigurationManager();
                }
                try
                {
                    if (!activeRcm.IsInitialised)
                    {
                        var configServer = ConfigCluster.Servers.Nodes.First(p => p.Value.Priority == 1);
                        ActiveConfigServerIp = configServer.Value.Name;
                        activeRcm.Initilize(ConfigCluster.Name, configServer.Value.Name, _configClusterInfo.Port, new ConfigurationChannelFormatter(), new SSPIClientAuthenticationCredential());
                    }
                    if (activeRcm.VerifyConfigurationClusterPrimery(_configClusterInfo.Name))
                    {
                        return;
                    }
                    activeRcm.Dispose();
                }
                catch
                {
                    try
                    {
                        var configServer = ConfigCluster.Servers.Nodes.First(p => p.Value.Priority == 2);
                        ActiveConfigServerIp = configServer.Value.Name;
                        activeRcm.Initilize(ConfigCluster.Name, configServer.Value.Name, _configClusterInfo.Port, new ConfigurationChannelFormatter(), new SSPIClientAuthenticationCredential());
                        if (activeRcm.VerifyConfigurationClusterPrimery(_configClusterInfo.Name))
                        {
                            return;
                        }
                        activeRcm.Dispose();
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            throw new Exception("Cann't connect to any of the servers in database cluster ");
        }