Exemple #1
0
        private void Initialize(string address, IChannelFormatter channelFormatter)
        {
            TraceProvider traceProvider = EnableTracing ? new TraceProvider() : null;

            //    ManagementHost.RegisterCompactTypes();
            if (string.IsNullOrEmpty(address))
            {
                address = NetworkUtil.GetLocalIPAddress().ToString();
            }
            //binding IP is null for ConfigClient
            _channel = new DualChannel(address, _port, null, _sessionType, traceProvider, channelFormatter);
            //_channel.RegisterRequestHandler(this);


            //RTD: whats the purpose of this?
            try
            {
                if (_channel.Connect(true))
                {
                    //string _sessionType = ((int)sessionType).ToString();
                    //_channel.SendMessage(_sessionType, true);
                }
            }
            catch (ChannelException ex)
            {
                //if (LoggerManager.Instance.CONDBLogger != null && LoggerManager.Instance.CONDBLogger.IsErrorEnabled)
                //    LoggerManager.Instance.CONDBLogger.Error("Error: OutprocConfigClient.Init()", ex.ToString());
                throw;
            }
        }
Exemple #2
0
        public bool OnSessionEstablished(Session session)
        {
            if (session == null || session.SessionType != SessionTypes.Management || session.Connection == null || _managementServer == null)
            {
                return(false);
            }
            try
            {
                IDualChannel channel;
                IPAddress    localAddress = DnsCache.Resolve(Environment.MachineName);
                channel = new DualChannel(session.Connection, session.IP.ToString(), session.RemotePort, localAddress.ToString(), session.SessionType, _traceProvider, _channelFormatter);

                switch (session.SessionType)
                {
                case SessionTypes.Management:
                    ManagementSession managementSession = (ManagementSession)_managementServer.OpenManagementSession(new UserCredentials());
                    channel.RegisterRequestHandler(managementSession);
                    managementSession.Channel = channel;
                    if (channel.Connect(true))
                    {
                        _sessionChannnelMap.Add(managementSession, channel);
                    }
                    return(true);
                }
            }
            catch (Exception ex)
            {
                if (LoggerManager.Instance.ServerLogger != null && LoggerManager.Instance.ServerLogger.IsErrorEnabled)
                {
                    LoggerManager.Instance.ServerLogger.Error("MgtSessionListener.OnSessionEstablished", "Error", ex);
                }
            }
            return(false);
        }
Exemple #3
0
        private void FormChannelConnection(Server server)
        {
            if (server.Address.Equals(context.LocalAddress))
            {
                try
                {
                    IDualChannel channel = new LocalChannel(context.LocalAddress, this);
                    lock (_shardChannels)
                    {
                        _shardChannels[server] = channel;
                    }
                }
                catch (Exception e)
                {
                    if (LoggerManager.Instance.ShardLogger != null && LoggerManager.Instance.ShardLogger.IsErrorEnabled)
                    {
                        LoggerManager.Instance.ShardLogger.Error("LocalShard.FormChannel()", "Local node: " + e.ToString());
                    }
                }
            }
            else
            {
                DualChannel channel = new DualChannel(server.Address.IpAddress.ToString(), server.Address.Port, context.LocalAddress.IpAddress.ToString(), SessionTypes.Shard, _traceProvider, _channelFormatter);
                try
                {
                    if (channel.Connect(false))
                    {
                        SessionInfo sessionInfo = new SessionInfo();
                        sessionInfo.Cluster = this.context.ClusterName;
                        sessionInfo.Shard   = this.context.LocalShardName;

                        channel.SendMessage(sessionInfo, true);

                        IDualChannel acceptedChannel = _resolveDispute.GetValidChannel(_resolveDispute.SetConnectInfo(channel, ConnectInfo.ConnectStatus.CONNECT_FIRST_TIME), _shardChannels);
                        lock (_shardChannels)
                        {
                            _shardChannels[server] = acceptedChannel;
                        }

                        _shardChannels[server].RegisterRequestHandler(this);
                        _shardChannels[server].StartReceiverThread();
                    }
                }
                catch (ChannelException ex)
                {
                    if (LoggerManager.Instance.ShardLogger != null && LoggerManager.Instance.ShardLogger.IsErrorEnabled)
                    {
                        LoggerManager.Instance.ShardLogger.Error("LocalShard.Start()", "Local shard: " + Name + ": Connection with " + server.Address + " failed to establish. " + ex);
                    }
                }
            }
        }
        public void Connect(string peerIP, int peerPort /*, string bindingIP*/)
        {
            try
            {
                _channel = new DualChannel(peerIP, peerPort, null, SessionTypes.Management, new TraceProvider(), new ConfigurationChannelFormatter());
                _channel.Connect(true);

                Initialize();
            }
            catch (ChannelException ex)
            {
                //RTD: Replace shardLogger with the respective module logger name
                if (LoggerManager.Instance.ShardLogger != null && LoggerManager.Instance.ShardLogger.IsErrorEnabled)
                {
                    LoggerManager.Instance.ShardLogger.Error("Error: RemoteMgmtSession.Connect()", ex.ToString());
                }
                throw ex;
            }
        }
Exemple #5
0
        public Boolean OnSessionEstablished(Session session)
        {
            Server       server      = new Server(new Common.Net.Address(session.IP.ToString(), session.LocalPort), Status.Initializing);
            IDualChannel channel     = new DualChannel(session.Connection, session.IP.ToString(), this.context.LocalAddress.Port, context.LocalAddress.ToString(), SessionTypes.Shard, _traceProvider, _channelFormatter);
            bool         isConnected = false;

            try
            {
                isConnected = channel.Connect(false);
            }
            catch (ChannelException e)
            {
                if (LoggerManager.Instance.ShardLogger != null && LoggerManager.Instance.ShardLogger.IsErrorEnabled)
                {
                    LoggerManager.Instance.ShardLogger.Error("Error: Localshard.OnSessionEstd()", e.ToString());
                }
            }
            if (isConnected)
            {
                ConnectInfo.ConnectStatus status = ConnectInfo.ConnectStatus.CONNECT_FIRST_TIME;
                if (_shardChannels.ContainsKey(server))
                {
                    status = ConnectInfo.ConnectStatus.RECONNECTING;
                }

                IDualChannel acceptedChannel = _resolveDispute.GetValidChannel(_resolveDispute.SetConnectInfo(channel, status), _shardChannels);

                lock (_shardChannels)
                {
                    _shardChannels[server] = acceptedChannel;
                }

                _shardChannels[server].RegisterRequestHandler(this);
                _shardChannels[server].StartReceiverThread();

                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #6
0
        public bool OnSessionEstablished(Session session)
        {
            if (session == null || session.SessionType != SessionTypes.Monitoring || session.Connection == null)
            {
                return(false);
            }
            IDualChannel _channel;
            IPAddress    _localAddress = DnsCache.Resolve(Environment.MachineName);

            _channel = new DualChannel(session.Connection, session.IP.ToString(), session.RemotePort, _localAddress.ToString(), session.SessionType, null, _channelFormatter);

            switch (session.SessionType)
            {
            case SessionTypes.Monitoring:
            {
                MonitorServer monitorServerSession = new MonitorServer(_clientSessionManager, _nodeContext, new UserCredentials());
                _channel.RegisterRequestHandler(monitorServerSession);
                monitorServerSession.Channel = _channel;
                try
                {
                    if (_channel.Connect(true))
                    {
                        _sessionChannnelMap.Add(monitorServerSession, _channel);
                    }
                }
                catch (ChannelException ex)
                {
                    //RTD: Replace shardLogger with the respective module logger name
                    if (LoggerManager.Instance.ShardLogger != null && LoggerManager.Instance.ShardLogger.IsErrorEnabled)
                    {
                        LoggerManager.Instance.ShardLogger.Error("Error: MonitorSessionListener.OnSessionEstd()", ex.ToString());
                    }
                }
                return(true);
            }
            }
            return(false);
        }
Exemple #7
0
        public bool OnSessionEstablished(Session session)
        {
            if (session == null || session.Connection == null)
            {
                return(false);
            }
            IDualChannel _channel;

            IPAddress _localAddress = DnsCache.Resolve(Environment.MachineName);

            _channel = new DualChannel(session.Connection, session.IP.ToString(), session.RemotePort, _localAddress.ToString(), session.SessionType, _traceProvider, _channelFormatter);

            try
            {
                switch (session.SessionType)
                {
                case SessionTypes.Management:
                case SessionTypes.Client:
                {
                    ConfigurationSession cfgsession = (ConfigurationSession)this.ConfigServer.OpenConfigurationSession(new SSPIClientAuthenticationCredential());        //new ConfigurationSession(this.ConfigServer, new UserCredentials());
                    _channel.RegisterRequestHandler(cfgsession);
                    if (session.SessionType == SessionTypes.Client)
                    {
                        cfgsession.Channel = _channel;
                    }
                    else
                    {
                        cfgsession.NodeChannel = _channel;
                    }

                    cfgsession.Parent = this;
                    if (_channel.Connect(true))
                    {
                        _sessionChannnelMap.Add(cfgsession, _channel);
                    }
                    return(true);
                }

                case SessionTypes.Shard:
                {
                    return(false);
                }

                case SessionTypes.Monitoring:
                {
                    ConfigrationMonitorSession cfgMonitorsession = new ConfigrationMonitorSession(
                        this.ConfigServer, new UserCredentials());
                    _channel.RegisterRequestHandler(cfgMonitorsession);
                    cfgMonitorsession.Channel = _channel;

                    if (_channel.Connect(true))
                    {
                    }
                    return(true);
                }
                }
            }
            catch (ChannelException ex)
            {
                if (LoggerManager.Instance.CONDBLogger != null && LoggerManager.Instance.CONDBLogger.IsErrorEnabled)
                {
                    LoggerManager.Instance.CONDBLogger.Error("Error: SessionMgr.OnSessionEstd()", ex.ToString());
                }
            }
            return(false);
        }
Exemple #8
0
        public void ChannelDisconnected(IRequestResponseChannel channel, string reason)
        {
            if (_channelDisconnctedListener != null)
            {
                _channelDisconnctedListener.ChannelDisconnected(channel, reason);
            }

            if (!_autoReconnect)
            {
                return;
            }

            int  retries   = 3;
            bool connected = false;

            if (channel != null)
            {
                while (0 < retries--)
                {
                    try
                    {
                        lock (_mutex)
                        {
                            if (_channel.RetryConnect())
                            {
                                IServerAuthenticationCredential serverAuthCred = _session.Authenticate(credentials);
                                if (serverAuthCred != null && serverAuthCred.IsAuthenticated)
                                {
                                    _session.Channel.IsAuthenticated = serverAuthCred.IsAuthenticated;
                                    _session.SessionId = serverAuthCred.SessionId;
                                }
                                connected = true;

                                break;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (retries == 2)
                        {
                            Thread.Sleep(30000);
                        }
                        else if (retries == 1)
                        {
                            Thread.Sleep(60000);
                        }
                    }
                }

                if (!connected)
                {
                    retries = 3;
                    TraceProvider traceProvider = EnableTracing ? new TraceProvider() : null;
                    if (_secondConfiguratioServer != null)
                    {
                        string disconnectedServer = channel.PeerAddress.ip;
                        string failOverServer     = null;

                        if (string.Compare(disconnectedServer, _firstConfiguratioServer, true) == 0)
                        {
                            failOverServer = _secondConfiguratioServer;
                        }
                        else
                        {
                            failOverServer = _firstConfiguratioServer;
                        }

                        _channel = new DualChannel(failOverServer, _port, null, SessionTypes.Management, traceProvider,
                                                   _channelFormatter);

                        while (0 < retries--)
                        {
                            try
                            {
                                if (_channel.Connect(true))
                                {
                                    _session.Channel = _channel;
                                    //
                                    //Connection re-established and needs to be authenticated
                                    IServerAuthenticationCredential serverAuthCred = _session.Authenticate(credentials);
                                    if (serverAuthCred != null && serverAuthCred.IsAuthenticated)
                                    {
                                        _session.Channel.IsAuthenticated = serverAuthCred.IsAuthenticated;
                                        _session.SessionId = serverAuthCred.SessionId;
                                    }
                                    break;
                                }
                            }
                            catch (ChannelException ex)
                            {
                                if (LoggerManager.Instance.CONDBLogger != null && LoggerManager.Instance.CONDBLogger.IsErrorEnabled)
                                {
                                    LoggerManager.Instance.CONDBLogger.Error("Error: OutProcConfigClient.ChannelDisconnected()", ex.ToString());
                                }
                            }
                        }
                    }
                }
            }
        }
 public OutProcShardConfigurationSession(string cluster, string shard, ServerNode server, UserCredentials credentials, DualChannel channel)
 {
     _channel = channel;
     //_shardSession = new InProcConfigurationClient().OpenShardConfigurationSession(cluster, shard, server, credentials);
 }