Example #1
0
        private void CheckConnection(AgentConnectionType connectionType)
        {
            switch (connectionType)
            {
            case AgentConnectionType.Generic:
                if (!_hasGenericConnection)
                {
                    throw new InvalidOperationException($"SetConnection {AgentConnectionType.Generic}");
                }
                break;

            case AgentConnectionType.JobRequest:
                if (!_hasRequestConnection)
                {
                    throw new InvalidOperationException($"SetConnection {AgentConnectionType.JobRequest}");
                }
                break;

            case AgentConnectionType.MessageQueue:
                if (!_hasMessageConnection)
                {
                    throw new InvalidOperationException($"SetConnection {AgentConnectionType.MessageQueue}");
                }
                break;

            default:
                throw new NotSupportedException(connectionType.ToString());
            }
        }
Example #2
0
        public async Task RefreshConnectionAsync(AgentConnectionType connectionType, TimeSpan timeout)
        {
            Trace.Info($"Refresh {connectionType} VssConnection to get on a different AFD node.");
            switch (connectionType)
            {
            case AgentConnectionType.MessageQueue:
                _hasMessageConnection = false;
                _messageConnection    = await EstablishVssConnection(_messageConnection.Uri, _messageConnection.Credentials, timeout);

                _messageTaskAgentClient = _messageConnection.GetClient <TaskAgentHttpClient>();
                _hasMessageConnection   = true;
                break;

            case AgentConnectionType.JobRequest:
                _hasRequestConnection = false;
                _requestConnection    = await EstablishVssConnection(_requestConnection.Uri, _requestConnection.Credentials, timeout);

                _requestTaskAgentClient = _requestConnection.GetClient <TaskAgentHttpClient>();
                _hasRequestConnection   = true;
                break;

            case AgentConnectionType.Generic:
                _hasGenericConnection = false;
                _genericConnection    = await EstablishVssConnection(_genericConnection.Uri, _genericConnection.Credentials, timeout);

                _genericTaskAgentClient = _genericConnection.GetClient <TaskAgentHttpClient>();
                _hasGenericConnection   = true;
                break;

            default:
                throw new NotSupportedException(connectionType.ToString());
            }
        }
Example #3
0
        public void SetConnectionTimeout(AgentConnectionType connectionType, TimeSpan timeout)
        {
            Trace.Info($"Set {connectionType} VssConnection's timeout to {timeout.TotalSeconds} seconds.");
            switch (connectionType)
            {
            case AgentConnectionType.JobRequest:
                _requestConnection.Settings.SendTimeout = timeout;
                break;

            case AgentConnectionType.MessageQueue:
                _messageConnection.Settings.SendTimeout = timeout;
                break;

            case AgentConnectionType.Generic:
                _genericConnection.Settings.SendTimeout = timeout;
                break;

            default:
                throw new NotSupportedException(connectionType.ToString());
            }
        }
Example #4
0
        public void SetConnectionTimeout(AgentConnectionType connectionType, TimeSpan timeout)
        {
            Trace.Info($"Set {connectionType} VssConnection's timeout to {timeout.TotalSeconds} seconds.");
            switch (connectionType)
            {
            case AgentConnectionType.JobRequest:
                _requestConnection.Settings.SendTimeout = timeout;
                break;

            case AgentConnectionType.MessageQueue:
                _messageConnection.Settings.SendTimeout = timeout;
                break;

            case AgentConnectionType.Generic:
                _genericConnection.Settings.SendTimeout = timeout;
                break;

            default:
                Trace.Error($"Unexpected connection type: {connectionType}.");
                break;
            }
        }
Example #5
0
        // Refresh connection is best effort. it should never throw exception
        public async Task RefreshConnectionAsync(AgentConnectionType connectionType, TimeSpan timeout)
        {
            Trace.Info($"Refresh {connectionType} VssConnection to get on a different AFD node.");
            VssConnection newConnection = null;

            switch (connectionType)
            {
            case AgentConnectionType.MessageQueue:
                try
                {
                    _hasMessageConnection = false;
                    newConnection         = await EstablishVssConnection(_messageConnection.Uri, _messageConnection.Credentials, timeout);

                    var client = newConnection.GetClient <TaskAgentHttpClient>();
                    _messageConnection      = newConnection;
                    _messageTaskAgentClient = client;
                }
                catch (SocketException ex)
                {
                    ExceptionsUtil.HandleSocketException(ex, _requestConnection.Uri.ToString(), Trace.Error);
                    newConnection?.Dispose();
                }
                catch (Exception ex)
                {
                    Trace.Error($"Catch exception during reset {connectionType} connection.");
                    Trace.Error(ex);
                    newConnection?.Dispose();
                }
                finally
                {
                    _hasMessageConnection = true;
                }
                break;

            case AgentConnectionType.JobRequest:
                try
                {
                    _hasRequestConnection = false;
                    newConnection         = await EstablishVssConnection(_requestConnection.Uri, _requestConnection.Credentials, timeout);

                    var client = newConnection.GetClient <TaskAgentHttpClient>();
                    _requestConnection      = newConnection;
                    _requestTaskAgentClient = client;
                }
                catch (SocketException ex)
                {
                    ExceptionsUtil.HandleSocketException(ex, _requestConnection.Uri.ToString(), Trace.Error);
                    newConnection?.Dispose();
                }
                catch (Exception ex)
                {
                    Trace.Error($"Catch exception during reset {connectionType} connection.");
                    Trace.Error(ex);
                    newConnection?.Dispose();
                }
                finally
                {
                    _hasRequestConnection = true;
                }
                break;

            case AgentConnectionType.Generic:
                try
                {
                    _hasGenericConnection = false;
                    newConnection         = await EstablishVssConnection(_genericConnection.Uri, _genericConnection.Credentials, timeout);

                    var client = newConnection.GetClient <TaskAgentHttpClient>();
                    _genericConnection      = newConnection;
                    _genericTaskAgentClient = client;
                }
                catch (SocketException ex)
                {
                    ExceptionsUtil.HandleSocketException(ex, _requestConnection.Uri.ToString(), Trace.Error);
                    newConnection?.Dispose();
                }
                catch (Exception ex)
                {
                    Trace.Error($"Catch exception during reset {connectionType} connection.");
                    Trace.Error(ex);
                    newConnection?.Dispose();
                }
                finally
                {
                    _hasGenericConnection = true;
                }
                break;

            default:
                Trace.Error($"Unexpected connection type: {connectionType}.");
                break;
            }
        }