コード例 #1
0
        /// <summary>
        /// Ask broker to initialize
        /// </summary>
        /// <param name="startInfo">indicating the start info</param>
        /// <param name="brokerInfo">indicating the broker info</param>
        /// <returns>returns broker initialization result</returns>
        public BrokerInitializationResult Initialize(SessionStartInfoContract startInfo, BrokerStartInfo brokerInfo)
        {
            ParamCheckUtility.ThrowIfNull(startInfo, "startInfo");
            ParamCheckUtility.ThrowIfNull(brokerInfo, "brokerInfo");

            // Concurrent mode is set to single so no need to lock here
            if (this.entry != null)
            {
                ThrowHelper.ThrowSessionFault(SOAFaultCode.Broker_AlreadyInitialized, SR.AlreadyInitialized);
            }

            // Notice: We get the session Id here and expect to change the
            // cosmos log file name to include session id. But cosmos log has a
            // limitation that it is a static class without close method, and
            // it can't be initialized twice. HpcTraceListener is just a wrapper
            // for that static class. So creating a new HpcTraceListener can not
            // workaround this issue.
            TraceHelper.TraceInfo(
                brokerInfo.SessionId,
                "[BrokerManagementService].Initialize: Broker worker initializes for session {0}",
                brokerInfo.SessionId);

            // Set the configuration indicating enable/disable diag trace
            SoaDiagTraceHelper.SetDiagTraceEnabledFlag(brokerInfo.SessionId, brokerInfo.EnableDiagTrace);
            TraceHelper.IsDiagTraceEnabled = SoaDiagTraceHelper.IsDiagTraceEnabled;

            Environment.SetEnvironmentVariable(SessionIdEnv, brokerInfo.SessionId.ToString(), EnvironmentVariableTarget.Process);

#if HPCPACK
            // create the session id mapping file
            foreach (TraceListener listener in TraceHelper.RuntimeTrace.CosmosTrace.Listeners)
            {
                if (listener is HpcTraceListener)
                {
                    HpcTraceListener hpcListener = listener as HpcTraceListener;
                    if (hpcListener.IsPerSessionLogging)
                    {
                        string logIdFileName = string.Format("{0}_{1}", HpcTraceListener.LogFileBaseName, brokerInfo.SessionId);
                        string logIdFilePath = Path.Combine(HpcTraceListener.LogDir, logIdFileName);
                        try
                        {
                            using (FileStream file = File.Open(logIdFilePath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.None))
                            {
                            }
                        }
                        catch (Exception e)
                        {
                            TraceHelper.TraceError(brokerInfo.SessionId,
                                                   "[BrokerManagementService].Initialize: Create log session Id match file failed with Exception {0}",
                                                   e.ToString());
                        }
                    }
                }
            }
#endif

            this.entry = new BrokerEntry(brokerInfo.SessionId);
            this.entry.BrokerFinished += new EventHandler(this.Entry_BrokerFinished);
            return(this.entry.Run(startInfo, brokerInfo));
        }
コード例 #2
0
        public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            ParamCheckUtility.ThrowIfNull(info, "info");

            info.AddValue(BrokerQueueItem.MessageVersionTag, SerializeMessageVersion(this.Message.Version));

            MemoryStream msgStream = null;

            try
            {
                msgStream = new MemoryStream();
                using (XmlDictionaryWriter writer = XmlDictionaryWriter.CreateBinaryWriter(msgStream))
                {
                    var msgStreamTemp = msgStream;
                    msgStream = null;
                    this.Message.WriteMessage(writer);
                    writer.Flush();
                    info.AddValue(BrokerQueueItem.MessageTag, msgStreamTemp.ToArray());
                }
            }
            finally
            {
                if (msgStream != null)
                {
                    msgStream.Dispose();
                }
            }

            BrokerQueueItem.SerializeObject(info, this.asyncState, BrokerQueueItem.AsyncStateTag);
            BrokerQueueItem.SerializeObject(info, this.persistGuid, BrokerQueueItem.PersistIdTag);
        }
コード例 #3
0
        /// <summary>
        ///   <para />
        /// </summary>
        /// <param name="clientId">
        ///   <para />
        /// </param>
        /// <param name="session">
        ///   <para />
        /// </param>
        protected BrokerClientBase(string clientId, SessionBase session)
        {
            if (string.IsNullOrEmpty(clientId))
            {
                if (session.Info is SessionInfo)
                {
                    this.clientId = String.Empty;
                }
                else
                {
                    this.clientId = DefaultClientIdForRestService;
                }
            }
            else
            {
                this.clientId = clientId;
            }

            ParamCheckUtility.ThrowIfNotMatchRegex(ParamCheckUtility.ClientIdValid, this.clientId, "clientId", SR.InvalidClientId);

            // Associate BrokerClient with session
            session.AddBrokerClient(this.clientId, this);

            this.session = session;
        }
コード例 #4
0
        /// <summary>
        /// For Java to pull the responses
        /// </summary>
        /// <param name="action">indicating the action</param>
        /// <param name="position">indicating the position</param>
        /// <param name="count">indicating the count</param>
        /// <param name="clientId">indicating the client id</param>
        /// <returns>returns the responses messages</returns>
        public BrokerResponseMessages PullResponses(string action, GetResponsePosition position, int count, string clientId)
        {
            try
            {
                ParamCheckUtility.ThrowIfOutofRange(count <= 0, "count");
                ParamCheckUtility.ThrowIfNull(clientId, "clientId");
                ParamCheckUtility.ThrowIfTooLong(clientId.Length, "clientId", Constant.MaxClientIdLength, SR.ClientIdTooLong);
                ParamCheckUtility.ThrowIfNotMatchRegex(ParamCheckUtility.ClientIdValid, clientId, "clientId", SR.InvalidClientId);

                BrokerTracing.TraceEvent(System.Diagnostics.TraceEventType.Information, 0, "[BrokerController] PullResponses: Action = {0}, Position = {1}, Count = {2}", action, position, count);
                this.ThrowIfDisposed();
                this.CheckAuth();

                #region Debug Failure Test
                SimulateFailure.FailOperation(1);
                #endregion

                return(this.GetClient(clientId).PullResponses(action, position, count, GetMessageVersion()));
            }
            catch (Exception e)
            {
                BrokerTracing.TraceEvent(System.Diagnostics.TraceEventType.Error, 0, "[BrokerController] PullResponses Failed: {0}", e);
                throw TranslateException(e);
            }
        }
コード例 #5
0
 /// <summary>
 /// remove the broker queue from the cached list.
 /// </summary>
 /// <param name="clientId">the client id.</param>
 internal void RemovePersistQueueByClient(string clientId)
 {
     ParamCheckUtility.ThrowIfNull(clientId, "clientId");
     BrokerTracing.TraceInfo("[BrokerQueueFactory] .RemovePersistQueueByClient: ClientId:{0}", clientId);
     lock (this.clientBrokerQueueDic)
     {
         if (this.clientBrokerQueueDic.ContainsKey(clientId))
         {
             this.clientBrokerQueueDic.Remove(clientId);
         }
     }
 }
コード例 #6
0
        public void GetRequestAsync(BrokerQueueCallback requestCallback, object state)
        {
            ParamCheckUtility.ThrowIfNull(requestCallback, "requestCallback");
            bool isCallbackHandled = false;

            if (this.requestCacheQueue.Count > 0)
            {
                BrokerQueueItem request = null;

                if (!this.requestCacheQueue.TryDequeue(out request))
                {
                    BrokerTracing.TraceInfo("[BrokerQueueDispatcher] .GetRequestAsync: All cached requests are dispatched.");
                }

                if (request != null)
                {
                    try
                    {
#if DEBUG
                        BrokerTracing.TraceVerbose("[BrokerQueueDispatcher] .GetRequestAsync: handle request callback from cache queue. request id={0}", GetMessageId(request));
#endif

                        this.RegisterReemit(request);

                        isCallbackHandled = true;
                        requestCallback(request, state);
                    }
                    catch (Exception e)
                    {
                        this.requestCacheQueue.Enqueue(request);

                        // request callback raise exception.
                        BrokerTracing.TraceWarning("[BrokerQueueDispatcher] .GetRequestAsync: The request callback raise exception. Exception: {0}", e);
                    }
                }
            }

            if (this.requestCacheQueue.Count <= this.watermarkerForTriggerPrefetch)
            {
                BrokerTracing.TraceVerbose("[BrokerQueueDispatcher] .GetRequestAsync (perf): Trigger prefetch because the count of cached items is below threshold. state={0}", (int)state);
                this.TriggerPrefetch();
            }

            if (!isCallbackHandled)
            {
                this.requestCallbackQueue.Enqueue(new BrokerQueueCallbackItem(requestCallback, state));

                // in case the last request come in the cache queue right before the request callback enqueue.
                this.HandlePendingRequestCallback();
            }
        }
コード例 #7
0
        /// <summary>
        /// Initializes a new instance of the BrokerNodeItem class.
        /// </summary>
        /// <param name="name">the node name.</param>
        /// <param name="domainName">the node domain name.</param>
        /// <param name="state">the node state.</param>
        /// <param name="reachable">a value indicating whether the node is reachable.</param>
        public BrokerNodeItem(string name, string domainName, bool reachable)
        {
            ParamCheckUtility.ThrowIfNullOrEmpty(name, "name");

            // Make sure the name is saved in upper case so it can be easily looked up later
            this.nameField = name.ToUpper();

            if (!string.IsNullOrEmpty(domainName))
            {
                this.domainNameField = domainName.ToUpper();
            }

            this.isReachableField = reachable;
        }
コード例 #8
0
 /// <summary>
 /// cleanup the stale persisted data for the sessions that related jobs are purged by the scheduler.
 /// </summary>
 /// <param name="persistName">the persist name.</param>
 /// <param name="isStaleSessionCallback">the calback function to judge whether a session is stale.</param>
 public static async Task CleanupStalePersistedData(string persistName, IsStaleSessionCallback isStaleSessionCallback, string connectString)
 {
     ParamCheckUtility.ThrowIfNull(isStaleSessionCallback, "isStaleSessionCallback");
     if (!string.IsNullOrEmpty(persistName))
     {
         if (persistName.Trim().Equals("AzureQueue", StringComparison.OrdinalIgnoreCase))
         {
             BrokerTracing.TraceInfo(
                 "[BrokerQueueFactory] .CleanupStalePersistedData: cleaning up stale data in AzureQueue");
             await AzureQueuePersist
             .CleanupStaleMessageQueue(isStaleSessionCallback, connectString);
         }
         else
         {
             throw new ArgumentOutOfRangeException("persistName",
                                                   persistName + ", which persistence is not supported.");
         }
     }
 }
コード例 #9
0
        /// <summary>
        /// Send requests
        /// </summary>
        /// <param name="message">indicating the message</param>
        void IBrokerFrontend.SendRequest(Message message)
        {
            string clientId = FrontEndBase.GetClientId(message, String.Empty);

            try
            {
                ParamCheckUtility.ThrowIfNull(clientId, "clientId");
                ParamCheckUtility.ThrowIfTooLong(clientId.Length, "clientId", Constant.MaxClientIdLength, SR.ClientIdTooLong);
                ParamCheckUtility.ThrowIfNotMatchRegex(ParamCheckUtility.ClientIdValid, clientId, "clientId", SR.InvalidClientId);

                this.observer.IncomingRequest();
                this.GetClient(clientId).RequestReceived(DummyRequestContext.GetInstance(MessageVersion.Default), message, null);
            }
            catch (Exception e)
            {
                BrokerTracing.TraceEvent(System.Diagnostics.TraceEventType.Error, 0, "[BrokerController] SendRequest {1} Failed: {0}", e, clientId);
                throw TranslateException(e);
            }
        }
コード例 #10
0
ファイル: BrokerLauncher.cs プロジェクト: umialpha/Telepathy
        /// <summary>
        /// Create a session
        /// </summary>
        /// <param name="info">session start info</param>
        /// <param name="sessionId">session id</param>
        /// <returns>returns broker initialization result</returns>
        public BrokerInitializationResult Create(SessionStartInfoContract info, string sessionId)
        {
            if ((!this.AllowNewSession) || (!this.IsOnline && String.IsNullOrEmpty(info.DiagnosticBrokerNode)))
            {
                ThrowHelper.ThrowSessionFault(SOAFaultCode.Broker_BrokerIsOffline, SR.BrokerIsOffline);
            }

            // Handle invalid input parameters
            try
            {
                ParamCheckUtility.ThrowIfNull(info, "info");
                if (!BrokerLauncherEnvironment.Standalone)
                {
                    this.CheckAccess(sessionId);
                }

                TraceHelper.TraceEvent(sessionId, System.Diagnostics.TraceEventType.Information, "[BrokerLauncher] Create: SessionId = {0}", sessionId);
                //TODO: make it async
                BrokerInitializationResult returnValue = this.brokerManager.CreateNewBrokerDomain(info, sessionId, false).GetAwaiter().GetResult();

                #region Debug Failure Test
                SimulateFailure.FailOperation(1);
                #endregion

                TraceHelper.RuntimeTrace.LogSessionCreated(sessionId);
                TraceHelper.TraceEvent(sessionId, System.Diagnostics.TraceEventType.Information, "[BrokerLauncher] Create Broker {0} Succeeded.", sessionId);
                return(returnValue);
            }
            catch (Exception e)
            {
                TraceHelper.RuntimeTrace.LogFailedToCreateSession(sessionId);

                // Bug 10614: Throw a proper exception when the broker node is being taken offline
                if ((!this.AllowNewSession) || (!this.IsOnline && String.IsNullOrEmpty(info.DiagnosticBrokerNode)))
                {
                    ThrowHelper.ThrowSessionFault(SOAFaultCode.Broker_BrokerIsOffline, SR.BrokerIsOffline);
                }

                TraceHelper.TraceEvent(sessionId, System.Diagnostics.TraceEventType.Error, "[BrokerLauncher] Create Broker {0} failed: {1}", sessionId, e.ToString());
                throw ExceptionHelper.ConvertExceptionToFaultException(e);
            }
        }
コード例 #11
0
        /// <summary>
        /// Purge a client
        /// </summary>
        /// <param name="clientId">indicating the client id</param>
        public void Purge(string clientId)
        {
            try
            {
                ParamCheckUtility.ThrowIfNull(clientId, "clientId");
                ParamCheckUtility.ThrowIfTooLong(clientId.Length, "clientId", Constant.MaxClientIdLength, SR.ClientIdTooLong);
                ParamCheckUtility.ThrowIfNotMatchRegex(ParamCheckUtility.ClientIdValid, clientId, "clientId", SR.InvalidClientId);

                BrokerTracing.TraceEvent(System.Diagnostics.TraceEventType.Information, 0, "[BrokerController] Purge Client {0}", clientId);
                this.ThrowIfDisposed();
                this.CheckAuth();
                this.clientManager.PurgeClient(clientId, GetUserName()).GetAwaiter().GetResult();
                BrokerTracing.TraceEvent(System.Diagnostics.TraceEventType.Information, 0, "[BrokerController] Purge Client {0} Succeeded.", clientId);
            }
            catch (Exception e)
            {
                BrokerTracing.TraceEvent(System.Diagnostics.TraceEventType.Error, 0, "[BrokerController] Purge Client {1} Failed: {0}", e, clientId);
                throw TranslateException(e);
            }
        }
コード例 #12
0
        /// <summary>
        /// Gets number of requests that have been committed into specified client
        /// </summary>
        /// <param name="clientId">client id</param>
        /// <returns>number of committed requests in the client with specified client id</returns>
        public int GetRequestsCount(string clientId)
        {
            try
            {
                ParamCheckUtility.ThrowIfNull(clientId, "clientId");
                ParamCheckUtility.ThrowIfTooLong(clientId.Length, "clientId", Constant.MaxClientIdLength, SR.ClientIdTooLong);
                ParamCheckUtility.ThrowIfNotMatchRegex(ParamCheckUtility.ClientIdValid, clientId, "clientId", SR.InvalidClientId);

                BrokerTracing.TraceInfo("[BrokerController] Get requests count for Client {0}", clientId);

                this.ThrowIfDisposed();
                this.CheckAuth();

                return(this.GetClient(clientId).RequestsCount);
            }
            catch (Exception e)
            {
                BrokerTracing.TraceError("[BrokerController] Get requests for Client {1} Failed: {0}", e, clientId);
                throw TranslateException(e);
            }
        }
コード例 #13
0
        /// <summary>
        /// Initializes a new instance of the PersistMessage class for deserialization.
        /// </summary>
        /// <param name="info">the serializaion info.</param>
        /// <param name="context">the serialization context.</param>
        protected BrokerQueueItem(SerializationInfo info, StreamingContext context)
        {
            ParamCheckUtility.ThrowIfNull(info, "info");

            MessageVersion version = DeserializeMessageVersion(info.GetInt32(MessageVersionTag));

            using (XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader((byte[])info.GetValue(BrokerQueueItem.MessageTag, typeof(byte[])), BrokerEntry.ReaderQuotas))
            {
                using (Message messageTmp = Message.CreateMessage(reader, BrokerEntry.MaxMessageSize, version))
                {
                    this.buffer = messageTmp.CreateBufferedCopy(BrokerEntry.MaxMessageSize);
                }
            }

            int deserializeFlags = 0;

            foreach (SerializationEntry entry in info)
            {
                switch (entry.Name)
                {
                case BrokerQueueItem.AsyncStateTag:
                    this.asyncState   = BrokerQueueItem.DeserializeObject(entry);
                    deserializeFlags |= 1;
                    break;

                case BrokerQueueItem.PersistIdTag:
                    this.persistGuid  = (Guid)BrokerQueueItem.DeserializeObject(entry);
                    deserializeFlags |= 2;
                    break;
                }

                if (deserializeFlags == 3)
                {
                    break;
                }
            }

            this.context    = BrokerQueueItem.DummyRequestContextField;
            this.asyncToken = new BrokerQueueAsyncToken(this.persistGuid, this.asyncState, null, 0);
        }
コード例 #14
0
        /// <summary>
        /// Initializes a new instance of the BrokerQueueFactory class,
        /// </summary>
        /// <param name="persistName">tye persist name.</param>
        /// <param name="sharedData">indicating the shared data</param>
        public BrokerQueueFactory(string persistName, SharedData sharedData)
        {
            if (persistName == null)
            {
                persistName = string.Empty;
            }

            ParamCheckUtility.ThrowIfOutofRange(!string.IsNullOrEmpty(persistName) && !string.Equals("AzureQueue", persistName, StringComparison.OrdinalIgnoreCase), "persistName");
            this.thisLockObj           = new object();
            this.sessionId             = sharedData.BrokerInfo.SessionId;
            this.persistName           = persistName;
            this.sharedData            = sharedData;
            this.clientBrokerQueueDic  = new Dictionary <string, BrokerQueue>(StringComparer.OrdinalIgnoreCase);
            this.brokerQueueDispatcher = new BrokerQueueDispatcher(this.sessionId, !string.IsNullOrEmpty(persistName), sharedData);
#if MSMQ
            if (!string.IsNullOrEmpty(sharedData.BrokerInfo.AadUserSid) && !string.IsNullOrEmpty(sharedData.BrokerInfo.AadUserName))
            {
                BrokerTracing.TraceInfo($"[BrokerQueueFactory] .Ctor: Add AAD SID mapping from broker start info: {sharedData.BrokerInfo.AadUserSid}, {sharedData.BrokerInfo.AadUserName}.");
                MSMQ.MSMQPersist.SetAadSidEntry(sharedData.BrokerInfo.AadUserSid, sharedData.BrokerInfo.AadUserName);
            }
#endif
        }
コード例 #15
0
        /// <summary>
        /// Gets broker client status
        /// </summary>
        /// <param name="clientId">indicating the client id</param>
        /// <returns>returns the broker client status</returns>
        public BrokerClientStatus GetBrokerClientStatus(string clientId)
        {
            try
            {
                ParamCheckUtility.ThrowIfNull(clientId, "clientId");
                ParamCheckUtility.ThrowIfTooLong(clientId.Length, "clientId", Constant.MaxClientIdLength, SR.ClientIdTooLong);
                ParamCheckUtility.ThrowIfNotMatchRegex(ParamCheckUtility.ClientIdValid, clientId, "clientId", SR.InvalidClientId);

                BrokerTracing.TraceEvent(System.Diagnostics.TraceEventType.Information, 0, "[BrokerController] Get broker client status for Client {0}", clientId);

                this.ThrowIfDisposed();
                this.CheckAuth();

                BrokerClientState state = this.GetClient(clientId).State;
                return(BrokerClient.MapToBrokerClientStatus(state));
            }
            catch (Exception e)
            {
                BrokerTracing.TraceEvent(System.Diagnostics.TraceEventType.Error, 0, "[BrokerController] Get broker client status for Client {1} Failed: {0}", e, clientId);
                throw TranslateException(e);
            }
        }
コード例 #16
0
        /// <summary>
        /// Get responses from client
        /// </summary>
        /// <param name="action">indicating the action</param>
        /// <param name="clientData">indicating the client data</param>
        /// <param name="resetToBegin">indicating the position</param>
        /// <param name="count">indicating the count</param>
        /// <param name="clientId">indicating the client id</param>
        public void GetResponses(string action, string clientData, GetResponsePosition resetToBegin, int count, string clientId)
        {
            try
            {
                BrokerTracing.TraceVerbose("[BrokerController] GetResponses is called for Client {0}.", clientId);

                ParamCheckUtility.ThrowIfOutofRange(count <= 0 && count != -1, "count");
                ParamCheckUtility.ThrowIfNull(clientId, "clientId");
                ParamCheckUtility.ThrowIfTooLong(clientId.Length, "clientId", Constant.MaxClientIdLength, SR.ClientIdTooLong);
                ParamCheckUtility.ThrowIfNotMatchRegex(ParamCheckUtility.ClientIdValid, clientId, "clientId", SR.InvalidClientId);

                BrokerTracing.TraceEvent(System.Diagnostics.TraceEventType.Information, 0, "[BrokerController] GetResponses for Client {2}, Count = {0}, Position = {1}", count, resetToBegin, clientId);

                this.ThrowIfDisposed();
                this.CheckAuth();

                // Try to get callback instance for inprocess broker
                IResponseServiceCallback callbackInstance = this.callbackInstance;

                // If callback instance is null, get callback instance from operation context
                if (callbackInstance == null)
                {
                    callbackInstance = OperationContext.Current.GetCallbackChannel <IResponseServiceCallback>();
                }

                this.GetClient(clientId).GetResponses(action, clientData, resetToBegin, count, callbackInstance, GetMessageVersion());

                #region Debug Failure Test
                SimulateFailure.FailOperation(1);
                #endregion

                BrokerTracing.TraceEvent(System.Diagnostics.TraceEventType.Information, 0, "[BrokerController] GetResponses for Client {0} Succeeded.", clientId);
            }
            catch (Exception e)
            {
                BrokerTracing.TraceEvent(System.Diagnostics.TraceEventType.Error, 0, "[BrokerController] GetResponses for Client {1} Failed: {0}", e, clientId);
                throw TranslateException(e);
            }
        }
コード例 #17
0
        /// <summary>
        /// Indicate the end of requeusts
        /// </summary>
        /// <param name="count">indicating the number of the messages</param>
        /// <param name="timeoutMs">indicating the timeout in MS</param>
        /// <param name="clientId">indicating the client id</param>
        public void EndRequests(int count, string clientId, int batchId, int timeoutThrottlingMs, int timeoutEOMMs)
        {
            ParamCheckUtility.ThrowIfOutofRange(count < 0, "count");
            ParamCheckUtility.ThrowIfOutofRange(timeoutThrottlingMs <= 0 && timeoutThrottlingMs != Timeout.Infinite, "timeoutThrottlingMs");
            ParamCheckUtility.ThrowIfOutofRange(timeoutEOMMs <= 0 && timeoutEOMMs != Timeout.Infinite, "timeoutEOMMs");
            ParamCheckUtility.ThrowIfNull(clientId, "clientId");
            ParamCheckUtility.ThrowIfTooLong(clientId.Length, "clientId", Constant.MaxClientIdLength, SR.ClientIdTooLong);
            ParamCheckUtility.ThrowIfNotMatchRegex(ParamCheckUtility.ClientIdValid, clientId, "clientId", SR.InvalidClientId);

            this.ThrowIfDisposed();
            this.CheckAuth();

            BrokerTracing.TraceEvent(System.Diagnostics.TraceEventType.Information, 0, "[BrokerController] Receive EOM for Client {0}, Count = {1}", clientId, count);
            try
            {
                #region Debug Failure Test
                SimulateFailure.FailOperation(1);
                #endregion

                BrokerClient brokerClient = this.GetClient(clientId);
                FrontEndBase frontendBase = brokerClient.GetDuplexFrontEnd();

                WaitOnThrottling(frontendBase, timeoutThrottlingMs);

                // Then handle the EOM which waits until all requests are stored. Use user specified EndRequests timeout for this
                brokerClient.EndOfMessage(count, batchId, timeoutEOMMs);

                #region Debug Failure Test
                SimulateFailure.FailOperation(2);
                #endregion
            }
            catch (Exception e)
            {
                BrokerTracing.TraceError("[BrokerController] EOM failed for client {0}: {1}", clientId, e);
                throw TranslateException(e);
            }
        }
コード例 #18
0
        /// <summary>
        /// AsyncCallback for ReceiveRequest
        /// </summary>
        /// <param name="ar">async result</param>
        private void ReceiveRequest(IAsyncResult ar)
        {
            ChannelClientState state  = (ChannelClientState)ar.AsyncState;
            BrokerClient       client = state.Client;
            Message            request;

            try
            {
                request = this.azureQueueProxy.EndReceiveRequest(ar);
            }
            catch (TimeoutException)
            {
                BrokerTracing.TraceEvent(TraceEventType.Information, 0, "[AzureQueueFrontEnd] Receive Request timed out");
                if (!ar.CompletedSynchronously)
                {
                    this.TryToBeginReceiveMessagesWithThrottling(state);
                }

                return;
            }
            catch (CommunicationException ce)
            {
                BrokerTracing.TraceEvent(TraceEventType.Information, 0, "[AzureQueueFrontEnd] Exception while receiving requests: {0}", ce.Message);

                // Retry receiving requests
                if (!ar.CompletedSynchronously)
                {
                    this.TryToBeginReceiveMessagesWithThrottling(state);
                }

                return;
            }

            #region Debug Failure Test
            SimulateFailure.FailOperation(1);
            #endregion


            // Try to get the client id and the user name
            string userName = GetUserName(request);
            string clientId = GetClientId(request, string.Empty);

            try
            {
                ParamCheckUtility.ThrowIfTooLong(clientId.Length, "clientId", Constant.MaxClientIdLength, SR.ClientIdTooLong);
                ParamCheckUtility.ThrowIfNotMatchRegex(ParamCheckUtility.ClientIdValid, clientId, "clientId", SR.InvalidClientId);
            }
            catch (ArgumentException)
            {
                BrokerTracing.EtwTrace.LogFrontEndRequestRejectedClientIdInvalid(this.SessionId, clientId, Utility.GetMessageIdFromMessage(request));
                return;
            }

            if (client == null || client.State == BrokerClientState.Disconnected || !client.ClientId.Equals(clientId, StringComparison.InvariantCultureIgnoreCase))
            {
                try
                {
                    client = this.ClientManager.GetClient(clientId, userName);
                    client.SingletonInstanceConnected();
                }
                catch (FaultException <SessionFault> e)
                {
                    if (e.Detail.Code == (int)SOAFaultCode.AccessDenied_BrokerQueue)
                    {
                        BrokerTracing.EtwTrace.LogFrontEndRequestRejectedAuthenticationError(this.SessionId, clientId, Utility.GetMessageIdFromMessage(request), userName);
                        return;
                    }
                    else
                    {
                        BrokerTracing.EtwTrace.LogFrontEndRequestRejectedGeneralError(this.SessionId, clientId, Utility.GetMessageIdFromMessage(request), e.ToString());
                        throw;
                    }
                }
                catch (BrokerQueueException e)
                {
                    BrokerTracing.EtwTrace.LogFrontEndRequestRejectedGeneralError(this.SessionId, clientId, Utility.GetMessageIdFromMessage(request), e.ToString());
                    return;
                }
                catch (Exception e)
                {
                    BrokerTracing.EtwTrace.LogFrontEndRequestRejectedGeneralError(this.SessionId, clientId, Utility.GetMessageIdFromMessage(request), e.ToString());
                    throw;
                }

                state.Client = client;
            }

            // Receive new requests
            if (!ar.CompletedSynchronously)
            {
                this.TryToBeginReceiveMessagesWithThrottling(state);
            }

            // Try to get the user info header
            bool userDataFlag = GetUserInfoHeader(request);

            // Create request context
            RequestContextBase requestContext;
            //Message that needs not to reply
            requestContext = DummyRequestContext.GetInstance(request.Version);

            // Bug 15195: Remove security header for https
            TryRemoveSecurityHeaderForHttps(request);

            // Send request to the broker client
            client.RequestReceived(requestContext, request, null);
        }
コード例 #19
0
ファイル: SessionLauncher.cs プロジェクト: scovetta/Telepathy
        /// <summary>
        /// Allocate a new durable or non-durable session
        /// </summary>
        /// <param name="startInfo">session start info</param>
        /// <param name="durable">whether session should be durable</param>
        /// <param name="endpointPrefix">the endpoint prefix, net.tcp:// or https:// </param>
        /// <returns>the Broker Launcher EPRs, sorted by the preference.</returns>
        protected virtual async Task <SessionAllocateInfoContract> AllocateInternalAsync(SessionStartInfoContract startInfo, string endpointPrefix, bool durable)
        {
            TraceHelper.TraceEvent(TraceEventType.Verbose, "[SessionLauncher] Begin: AllocateInternalAsync");
            SessionAllocateInfoContract sessionAllocateInfo = new SessionAllocateInfoContract();

            ParamCheckUtility.ThrowIfNull(startInfo, "startInfo");
            ParamCheckUtility.ThrowIfNullOrEmpty(startInfo.ServiceName, "startInfo.ServiceName");
            ParamCheckUtility.ThrowIfNullOrEmpty(endpointPrefix, "endpointPrefix");

#if HPCPACK
            // check client api version, 4.3 or older client is not supported by 4.4 server for the broken changes
            if (startInfo.ClientVersion == null || startInfo.ClientVersion < new Version(4, 4))
            {
                TraceHelper.TraceEvent(TraceEventType.Error,
                                       "[SessionLauncher] .AllocateInternalAsync: ClientVersion {0} does not match ServerVersion {1}.", startInfo.ClientVersion, ServerVersion);

                ThrowHelper.ThrowSessionFault(SOAFaultCode.ClientServerVersionMismatch,
                                              SR.SessionLauncher_ClientServerVersionMismatch,
                                              startInfo.ClientVersion == null ? "NULL" : startInfo.ClientVersion.ToString(),
                                              ServerVersion.ToString());
            }
#endif

            // Init service version to the service version passed in
            if (startInfo.ServiceVersion != null)
            {
                sessionAllocateInfo.ServiceVersion = startInfo.ServiceVersion;
                TraceHelper.TraceEvent(TraceEventType.Verbose, "[SessionLauncher] .AllocateInternalAsync: Original service version is {0}", sessionAllocateInfo.ServiceVersion);
            }
            else
            {
                sessionAllocateInfo.ServiceVersion = null;
                TraceHelper.TraceEvent(TraceEventType.Verbose, "[SessionLauncher] .AllocateInternalAsync: Original service version is null.");
            }

            string callId = Guid.NewGuid().ToString();
            this.CheckAccess();

            SecureString securePassword = CreateSecureString(startInfo.Password);
            startInfo.Password = null;

            // BUG 4522 : Use CCP_SCHEDULER when referencing service registration file share so HA HN virtual name is used when needed
            //var reliableRegistry = new ReliableRegistry(this.fabricClient.PropertyManager);
            //string defaultServiceRegistrationServerName = await reliableRegistry.GetValueAsync<string>(HpcConstants.HpcFullKeyName, HpcConstants.FileShareServerRegVal, this.token);

            //if (String.IsNullOrEmpty(defaultServiceRegistrationServerName))
            //{
            //    defaultServiceRegistrationServerName = "localhost";
            //}

            // the reg repo path is from scheduler environments, defaultServiceRegistrationServerName is actually not used

            string serviceConfigFile;
            ServiceRegistrationRepo serviceRegistration = this.GetRegistrationRepo(callId);
            serviceConfigFile = serviceRegistration.GetServiceRegistrationPath(startInfo.ServiceName, startInfo.ServiceVersion);

            // If the serviceConfigFile wasnt found and serviceversion isnt specified, try getitng the service config based on the service's latest version
            if (string.IsNullOrEmpty(serviceConfigFile) && (startInfo.ServiceVersion == null))
            {
                TraceHelper.TraceEvent(TraceEventType.Verbose, "[SessionLauncher] .AllocateInternalAsync: Try to find out versioned service.");

                // Get service version in ServiceRegistrationRepo
                Version dynamicServiceVersion = serviceRegistration.GetServiceVersionInternal(startInfo.ServiceName, false);

                if (dynamicServiceVersion != null)
                {
                    TraceHelper.TraceEvent(TraceEventType.Verbose, "[SessionLauncher] .AllocateInternalAsync: Selected dynamicServiceVersion is {0}.", dynamicServiceVersion.ToString());
                }

                serviceConfigFile = serviceRegistration.GetServiceRegistrationPath(startInfo.ServiceName, dynamicServiceVersion);

                // If a config file is found, update the serviceVersion that is returned to client and stored in recovery info
                if (!string.IsNullOrEmpty(serviceConfigFile))
                {
                    TraceHelper.TraceEvent(TraceEventType.Verbose, "[SessionLauncher] .AllocateInternalAsync: serviceConfigFile is {0}.", serviceConfigFile);

                    startInfo.ServiceVersion = dynamicServiceVersion;

                    if (dynamicServiceVersion != null)
                    {
                        sessionAllocateInfo.ServiceVersion = dynamicServiceVersion;
                    }
                }
            }

            string serviceName = ServiceRegistrationRepo.GetServiceRegistrationFileName(startInfo.ServiceName, startInfo.ServiceVersion);
            TraceHelper.TraceEvent(TraceEventType.Verbose, "[SessionLauncher] .AllocateInternalAsync: Service name = {0}, Configuration file = {1}", serviceName, serviceConfigFile);

            // If the service is not found and user code doesn't specify
            // version, we will use the latest version.
            if (string.IsNullOrEmpty(serviceConfigFile))
            {
                if (startInfo.ServiceVersion != null)
                {
                    ThrowHelper.ThrowSessionFault(SOAFaultCode.ServiceVersion_NotFound, SR.SessionLauncher_ServiceVersionNotFound, startInfo.ServiceName, startInfo.ServiceVersion.ToString());
                }
                else
                {
                    ThrowHelper.ThrowSessionFault(SOAFaultCode.Service_NotFound, SR.SessionLauncher_ServiceNotFound, startInfo.ServiceName);
                }
            }

            ExeConfigurationFileMap map = new ExeConfigurationFileMap();
            map.ExeConfigFilename = serviceConfigFile;

            ServiceRegistration  registration         = null;
            BrokerConfigurations brokerConfigurations = null;
            string hostpath         = null;
            string traceSwitchValue = null;

            try
            {
                Configuration config = null;

                RetryManager.RetryOnceAsync(
                    () => config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None),
                    TimeSpan.FromSeconds(1),
                    ex => ex is ConfigurationErrorsException).GetAwaiter().GetResult();

                Debug.Assert(config != null, "Configuration is not opened properly.");
                registration         = ServiceRegistration.GetSectionGroup(config);
                brokerConfigurations = BrokerConfigurations.GetSectionGroup(config);

                if (registration != null && registration.Host != null && registration.Host.Path != null)
                {
                    hostpath = registration.Host.Path;
                }
                else
                {
                    // x86 or x64
                    hostpath = registration.Service.Architecture == ServiceArch.X86 ? TaskCommandLine32 : TaskCommandLine64;
                }

                traceSwitchValue = registration.Service.SoaDiagTraceLevel;

                // TODO: should deprecate the previous settings
                if (string.IsNullOrEmpty(traceSwitchValue))
                {
                    traceSwitchValue = ConfigurationHelper.GetTraceSwitchValue(config);
                }
            }
            catch (ConfigurationErrorsException e)
            {
                ThrowHelper.ThrowSessionFault(SOAFaultCode.ConfigFile_Invalid, SR.SessionLauncher_ConfigFileInvalid, e.ToString());
            }
            catch (Exception ex)
            {
                TraceHelper.TraceEvent(TraceEventType.Error, ex.ToString());
                throw;
            }

            // after figuring out the service and version, and the session pool size, we check if the service pool already has the instance.
            sessionAllocateInfo.Id          = "0";
            sessionAllocateInfo.SessionInfo = null;
            if (startInfo.UseSessionPool)
            {
                if (this.TryGetSessionAllocateInfoFromPooled(endpointPrefix, durable, sessionAllocateInfo, serviceConfigFile, registration, out var allocateInternal))
                {
                    return(allocateInternal);
                }
            }

            // for sessions to add in session pool
            try
            {
                var sessionAllocateInfoContract = await this.CreateAndSubmitSessionJob(
                    startInfo,
                    endpointPrefix,
                    durable,
                    callId,
                    securePassword,
                    registration,
                    sessionAllocateInfo,
                    traceSwitchValue,
                    serviceName,
                    brokerConfigurations,
                    hostpath);

                if (sessionAllocateInfoContract != null)
                {
                    return(sessionAllocateInfoContract);
                }
            }
            finally
            {
                // Add the submitted job to the session pool.
                if (startInfo.UseSessionPool)
                {
                    this.AddSessionToPool(Path.GetFileNameWithoutExtension(serviceConfigFile), durable, sessionAllocateInfo.Id, registration.Service.MaxSessionPoolSize);
                }
            }

            return(null);
        }
コード例 #20
0
        public override async Task <SessionInfoContract> GetInfoAsync(string endpointPrefix, string sessionId)
        {
            SessionInfoContract sessionInfo = null;

            this.CheckAccess();

            ParamCheckUtility.ThrowIfNullOrEmpty(endpointPrefix, "endpointPrefix");

            TraceHelper.TraceEvent(
                sessionId,
                TraceEventType.Information,
                "[SessionLauncher] .GetInfo: headnode={0}, endpointPrefix={1}, sessionId={2}",
                Environment.MachineName,
                endpointPrefix,
                sessionId);

            if (!IsEndpointPrefixSupported(endpointPrefix))
            {
                TraceHelper.TraceEvent(sessionId, TraceEventType.Error, "[SessionLauncher] .GetInfo: {0} is not a supported endpoint prefix.", endpointPrefix);

                ThrowHelper.ThrowSessionFault(SOAFaultCode.InvalidArgument, SR.SessionLauncher_EndpointNotSupported, endpointPrefix);
            }

            try
            {
                using (var batchClient = AzureBatchConfiguration.GetBatchClient())
                {
                    var jobId = AzureBatchSessionJobIdConverter.ConvertToAzureBatchJobId(sessionId);

                    var sessionJob = await batchClient.JobOperations.GetJobAsync(jobId).ConfigureAwait(false);

                    if (sessionJob == null)
                    {
                        throw new InvalidOperationException($"[{nameof(AzureBatchSessionLauncher)}] .{nameof(this.GetInfoAsync)} Failed to get batch job for session {sessionId}");
                    }

                    TraceHelper.TraceEvent(
                        sessionId,
                        TraceEventType.Information,
                        $"[{nameof(AzureBatchSessionLauncher)}] .{nameof(this.GetInfoAsync)}: try to get the job properties(Secure, TransportScheme, BrokerEpr, BrokerNode, ControllerEpr, ResponseEpr) for the job, jobid={sessionId}.");

                    sessionInfo    = new SessionInfoContract();
                    sessionInfo.Id = AzureBatchSessionJobIdConverter.ConvertToSessionId(sessionJob.Id);

                    // TODO: sessionInfo.JobState
                    var metadata = sessionJob.Metadata;
                    if (metadata != null)
                    {
                        string brokerNodeString = null;

                        foreach (var pair in metadata)
                        {
                            if (pair.Name.Equals(BrokerSettingsConstants.Secure, StringComparison.OrdinalIgnoreCase))
                            {
                                string secureString = pair.Value;
                                Debug.Assert(secureString != null, "BrokerSettingsConstants.Secure value should be a string.");
                                bool secure;
                                if (bool.TryParse(secureString, out secure))
                                {
                                    sessionInfo.Secure = secure;
                                    TraceHelper.TraceEvent(sessionId, TraceEventType.Information, "[SessionLauncher] .GetInfo: get the job secure property, Secure={0}.", secure);
                                }
                                else
                                {
                                    TraceHelper.TraceEvent(sessionId, TraceEventType.Error, "Illegal secure value[{0}] for job's " + BrokerSettingsConstants.Secure + " property", secureString);
                                }
                            }
                            else if (pair.Name.Equals(BrokerSettingsConstants.TransportScheme, StringComparison.OrdinalIgnoreCase))
                            {
                                string schemeString = pair.Value;
                                Debug.Assert(schemeString != null, "BrokerSettingsConstants.TransportScheme value should be a string.");

                                int scheme;
                                if (int.TryParse(schemeString, out scheme))
                                {
                                    sessionInfo.TransportScheme = (TransportScheme)scheme;
                                    TraceHelper.TraceEvent(
                                        sessionId,
                                        TraceEventType.Information,
                                        "[SessionLauncher] .GetInfo: get the job TransportScheme property, TransportScheme={0}.",
                                        sessionInfo.TransportScheme);
                                }
                                else
                                {
                                    TraceHelper.TraceEvent(
                                        sessionId,
                                        TraceEventType.Error,
                                        "Illegal transport scheme value[{0}] for job's " + BrokerSettingsConstants.TransportScheme + " property",
                                        schemeString);
                                }
                            }
                            else if (pair.Name.Equals(BrokerSettingsConstants.BrokerNode, StringComparison.OrdinalIgnoreCase))
                            {
                                brokerNodeString = pair.Value;
                                Debug.Assert(brokerNodeString != null, "BrokerSettingsConstants.BrokerNode value should be a string.");

                                TraceHelper.TraceEvent(
                                    sessionId,
                                    TraceEventType.Information,
                                    "[SessionLauncher] .GetInfo: get the job BrokerLauncherEpr property, BrokerLauncherEpr={0}.",
                                    sessionInfo.BrokerLauncherEpr);
                            }
                            else if (pair.Name.Equals(BrokerSettingsConstants.Durable, StringComparison.OrdinalIgnoreCase))
                            {
                                string durableString = pair.Value;
                                Debug.Assert(durableString != null, "BrokerSettingsConstants.Durable value should be a string.");

                                bool durable;
                                if (bool.TryParse(durableString, out durable))
                                {
                                    sessionInfo.Durable = durable;
                                    TraceHelper.TraceEvent(sessionId, TraceEventType.Information, "[SessionLauncher] .GetInfo: get the job Durable property, Durable={0}.", sessionInfo.Durable);
                                }
                                else
                                {
                                    TraceHelper.TraceEvent(sessionId, TraceEventType.Error, "Illegal secure value[{0}] for job's " + BrokerSettingsConstants.Durable + " property", durableString);
                                }
                            }
                            else if (pair.Name.Equals(BrokerSettingsConstants.ServiceVersion, StringComparison.OrdinalIgnoreCase))
                            {
                                if (pair.Value != null)
                                {
                                    try
                                    {
                                        sessionInfo.ServiceVersion = new Version(pair.Value);
                                        TraceHelper.TraceEvent(
                                            sessionId,
                                            TraceEventType.Information,
                                            "[SessionLauncher] .GetInfo: get the job ServiceVersion property, ServiceVersion={0}.",
                                            (sessionInfo.ServiceVersion != null) ? sessionInfo.ServiceVersion.ToString() : string.Empty);
                                    }
                                    catch (Exception e)
                                    {
                                        TraceHelper.TraceEvent(
                                            sessionId,
                                            TraceEventType.Error,
                                            "Illegal secure value[{0}] for job's " + BrokerSettingsConstants.ServiceVersion + " property. Exception = {1}",
                                            pair.Value,
                                            e);
                                    }
                                }
                            }
                        }

                        if (!string.IsNullOrEmpty(brokerNodeString))
                        {
                            if (brokerNodeString != Constant.InprocessBrokerNode)
                            {
                                sessionInfo.BrokerLauncherEpr = BrokerNodesManager.GenerateBrokerLauncherEpr(endpointPrefix, brokerNodeString, sessionInfo.TransportScheme);
                            }
                        }
                        else
                        {
                            sessionInfo.UseInprocessBroker = true;
                        }

                        TraceHelper.TraceEvent(
                            sessionId,
                            TraceEventType.Information,
                            "[SessionLauncher] .GetInfo: get the job BrokerLauncherEpr property, BrokerLauncherEpr={0}.",
                            sessionInfo.BrokerLauncherEpr);
                    }
                }
            }
            catch (Exception e)
            {
                TraceHelper.TraceEvent(sessionId, TraceEventType.Error, "[SessionLauncher] .GetInfo: Failed to get all properties from job[{0}], Exception:{1}", sessionId, e);

                ThrowHelper.ThrowSessionFault(SOAFaultCode.GetJobPropertyFailure, SR.SessionLauncher_FailToGetJobProperty, e.ToString());
            }

            if (sessionInfo.SessionOwner == null)
            {
                sessionInfo.SessionOwner = "Everyone";
            }

            if (sessionInfo.SessionACL == null)
            {
                sessionInfo.SessionACL = new string[0];
            }

            if (sessionInfo.JobState == 0)
            {
                // TODO: apply job state converting
                sessionInfo.JobState = JobState.Running;
            }

            TraceHelper.TraceEvent(
                sessionId,
                TraceEventType.Information,
                "[SessionLauncher] .GetInfo: return the sessionInfo, BrokerEpr={0}, BrokerLauncherEpr={1}, ControllerEpr={2}, Id={3}, JobState={4}, ResponseEpr={5}, Secure={6}, TransportScheme={7}, sessionOwner={8}, sessionACL={9}",
                sessionInfo.BrokerEpr,
                sessionInfo.BrokerLauncherEpr,
                sessionInfo.ControllerEpr,
                sessionInfo.Id,
                sessionInfo.JobState,
                sessionInfo.ResponseEpr,
                sessionInfo.Secure,
                sessionInfo.TransportScheme,
                sessionInfo.SessionOwner ?? "null",
                sessionInfo.SessionACL?.Length.ToString() ?? "null");
            return(sessionInfo);
        }
コード例 #21
0
        /// <summary>
        /// AsyncCallback for ReceiveRequest
        /// </summary>
        /// <param name="ar">async result</param>
        private void ReceiveRequest(IAsyncResult ar)
        {
            ChannelClientState state = (ChannelClientState)ar.AsyncState;
            T              channel   = (T)state.Channel;
            BrokerClient   client    = state.Client;
            RequestContext request;

            try
            {
                request = channel.EndReceiveRequest(ar);
            }
            catch (TimeoutException)
            {
                BrokerTracing.TraceEvent(TraceEventType.Information, 0, "[RequestReplyFrontEnd] Receive Request timed out");
                if (!ar.CompletedSynchronously)
                {
                    this.TryToBeginReceiveMessagesWithThrottling(state);
                }

                return;
            }
            catch (CommunicationException ce)
            {
                BrokerTracing.TraceEvent(TraceEventType.Information, 0, "[RequestReplyFrontEnd] Exception while receiving requests: {0}", ce.Message);

                // Retry receiving requests
                if (!ar.CompletedSynchronously)
                {
                    this.TryToBeginReceiveMessagesWithThrottling(state);
                }

                return;
            }

            #region Debug Failure Test
            SimulateFailure.FailOperation(1);
            #endregion

            // After channel timed out, the request will be null if you call channel.ReceiveRequest()
            // Need to end the channel at this time
            if (request == null)
            {
                // Indicate that the channel should be closed
                // Close the channel
                lock (channel)
                {
                    if (channel.State == CommunicationState.Opened)
                    {
                        try
                        {
                            channel.Close();
                        }
                        catch (CommunicationException ce)
                        {
                            BrokerTracing.TraceEvent(TraceEventType.Warning, 0, "[RequestReplyFrontEnd] Exception throwed while close the channel: {0}", ce);
                            channel.Abort();
                        }
                    }
                }

                return;
            }

            // Try to get the client id and the user name
            string callerSID;
            string userName = this.GetUserName(request.RequestMessage, out callerSID);
            string clientId = GetClientId(request.RequestMessage, callerSID);

            try
            {
                ParamCheckUtility.ThrowIfTooLong(clientId.Length, "clientId", Constant.MaxClientIdLength, SR.ClientIdTooLong);
                ParamCheckUtility.ThrowIfNotMatchRegex(ParamCheckUtility.ClientIdValid, clientId, "clientId", SR.InvalidClientId);
            }
            catch (ArgumentException)
            {
                BrokerTracing.EtwTrace.LogFrontEndRequestRejectedClientIdInvalid(this.SessionId, clientId, Utility.GetMessageIdFromMessage(request.RequestMessage));
                RequestContextBase requestContextToReject = new RequestReplyRequestContext(request, this.Observer);
                requestContextToReject.BeginReply(FrontEndFaultMessage.GenerateFaultMessage(request.RequestMessage, request.RequestMessage.Headers.MessageVersion, SOAFaultCode.Broker_InvalidClientIdOrTooLong, SR.InvalidClientIdOrTooLong), this.ReplySentCallback, requestContextToReject);
                return;
            }

            if (client == null || client.State == BrokerClientState.Disconnected || String.Compare(clientId, client.ClientId, StringComparison.OrdinalIgnoreCase) != 0)
            {
                try
                {
                    client = this.ClientManager.GetClient(clientId, userName);
                    client.SingletonInstanceConnected();
                }
                catch (FaultException <SessionFault> e)
                {
                    if (e.Detail.Code == (int)SOAFaultCode.AccessDenied_BrokerQueue)
                    {
                        BrokerTracing.EtwTrace.LogFrontEndRequestRejectedAuthenticationError(this.SessionId, clientId, Utility.GetMessageIdFromMessage(request.RequestMessage), userName);
                        RequestContextBase requestContextToReject = new RequestReplyRequestContext(request, this.Observer);
                        requestContextToReject.BeginReply(FrontEndFaultMessage.GenerateFaultMessage(request.RequestMessage, request.RequestMessage.Headers.MessageVersion, SOAFaultCode.Broker_UserNameNotMatch, SR.UserNameNotMatch, userName, clientId), this.ReplySentCallback, requestContextToReject);
                        return;
                    }
                    else
                    {
                        BrokerTracing.EtwTrace.LogFrontEndRequestRejectedGeneralError(this.SessionId, clientId, Utility.GetMessageIdFromMessage(request.RequestMessage), e.ToString());
                        throw;
                    }
                }
                catch (BrokerQueueException e)
                {
                    BrokerTracing.EtwTrace.LogFrontEndRequestRejectedGeneralError(this.SessionId, clientId, Utility.GetMessageIdFromMessage(request.RequestMessage), e.ToString());
                    RequestContextBase requestContextToReject = new RequestReplyRequestContext(request, this.Observer);
                    requestContextToReject.BeginReply(FrontEndFaultMessage.TranslateBrokerQueueExceptionToFaultMessage(e, request.RequestMessage), this.ReplySentCallback, requestContextToReject);
                    return;
                }
                catch (Exception e)
                {
                    BrokerTracing.EtwTrace.LogFrontEndRequestRejectedGeneralError(this.SessionId, clientId, Utility.GetMessageIdFromMessage(request.RequestMessage), e.ToString());
                    throw;
                }

                state.Client = client;
            }

            // Receive new requests
            if (!ar.CompletedSynchronously)
            {
                this.TryToBeginReceiveMessagesWithThrottling(state);
            }

            // Try to get the user info header
            bool userDataFlag = GetUserInfoHeader(request.RequestMessage);

            // Create request context
            RequestContextBase requestContext;
            if (userDataFlag)
            {
                // Message that needs not to reply
                requestContext = DummyRequestContext.GetInstance(request.RequestMessage.Version);

                // Reply the message to the client immediately if user data is found for request/reply MEP (basic http binding)
                try
                {
                    request.BeginReply(Message.CreateMessage(request.RequestMessage.Headers.MessageVersion, request.RequestMessage.Headers.Action + "Response"), this.ReplySent, request);
                }
                catch (Exception e)
                {
                    BrokerTracing.TraceEvent(TraceEventType.Error, 0, "[RequestReplyFrontEnd] Exception throwed while trying to reply dummy message to client: {0}", e);
                }
            }
            else
            {
                requestContext = new RequestReplyRequestContext(request, this.Observer, client);
            }

            // Check auth
            if (!this.CheckAuth(requestContext, request.RequestMessage))
            {
                return;
            }

            // Bug 15195: Remove security header for https
            TryRemoveSecurityHeaderForHttps(request.RequestMessage);

            // Send request to the broker client
            client.RequestReceived(requestContext, request.RequestMessage, null);
        }
コード例 #22
0
 /// <summary>
 /// Validate data client id
 /// </summary>
 /// <param name="dataClientId">data client id</param>
 public static void ValidateDataClientId(string dataClientId)
 {
     Microsoft.Hpc.Scheduler.Session.Internal.Utility.ThrowIfNullOrEmpty(dataClientId, "dataClientId");
     ParamCheckUtility.ThrowIfTooLong(dataClientId.Length, "dataClientId", Internal.Constant.MaxDataClientIdLength, SR.DataClientIdTooLong, Internal.Constant.MaxDataClientIdLength);
     ParamCheckUtility.ThrowIfNotMatchRegex(ParamCheckUtility.DataClientIdValid, dataClientId, "dataClientId", SR.DataClientIdInvalid);
 }
コード例 #23
0
 /// <summary>
 /// Initializes a new instance of the BrokerQueueCallbackItem class.
 /// </summary>
 /// <param name="brokerQueueCallback">the response/request callback.</param>
 /// <param name="state">the state object for the callback.</param>
 public BrokerQueueCallbackItem(BrokerQueueCallback brokerQueueCallback, object state)
 {
     ParamCheckUtility.ThrowIfNull(brokerQueueCallback, "brokerQueueCallback");
     this.brokerQueueCallbackField = brokerQueueCallback;
     this.callbackStateField       = state;
 }
コード例 #24
0
ファイル: DuplexFrontEnd.cs プロジェクト: umialpha/Telepathy
        /// <summary>
        /// AsyncCallback for ReceiveRequest
        /// </summary>
        /// <param name="ar">async result</param>
        private void ReceiveRequest(IAsyncResult ar)
        {
            ChannelClientState    state   = (ChannelClientState)ar.AsyncState;
            IDuplexSessionChannel channel = (IDuplexSessionChannel)state.Channel;
            BrokerClient          client  = state.Client;
            Message requestMessage;

            try
            {
                requestMessage = channel.EndReceive(ar);
            }
            catch (Exception ce)
            {
                BrokerTracing.TraceEvent(TraceEventType.Warning, 0, "[DuplexFrontEnd] Exception while receiving requests: {0}", ce);
                this.FrontendDisconnect(channel, client);

                lock (channel)
                {
                    if (channel.State == CommunicationState.Faulted)
                    {
                        BrokerTracing.TraceEvent(TraceEventType.Warning, 0, "[DuplexFrontEnd] Abort faulted channel.");
                        channel.Abort();
                        return;
                    }
                }

                // Retry receiving requests
                if (!ar.CompletedSynchronously)
                {
                    this.TryToBeginReceiveMessagesWithThrottling(state);
                }

                return;
            }

            #region Debug Failure Test
            SimulateFailure.FailOperation(1);
            #endregion

            // After channel timeout, the request will be null if you call channel.Receive()
            // Need to end the channel at this time
            if (requestMessage == null)
            {
                // Indicate that the channel should be closed
                // Close the channel
                lock (channel)
                {
                    if (channel.State == CommunicationState.Opened)
                    {
                        this.FrontendDisconnect(channel, client);
                        try
                        {
                            channel.Close();
                            BrokerTracing.TraceEvent(TraceEventType.Information, 0, "[DuplexFrontEnd] Channel closed");
                        }
                        catch (Exception ce)
                        {
                            BrokerTracing.TraceEvent(TraceEventType.Warning, 0, "[DuplexFrontEnd] Exception throwed while close the channel: {0}", ce);
                            channel.Abort();
                        }
                    }
                }

                return;
            }

            // Try to get the client id
            string callerSID;
            string userName = this.GetUserName(requestMessage, out callerSID);
            string clientId = GetClientId(requestMessage, callerSID);

            try
            {
                ParamCheckUtility.ThrowIfTooLong(clientId.Length, "clientId", Constant.MaxClientIdLength, SR.ClientIdTooLong);
                ParamCheckUtility.ThrowIfNotMatchRegex(ParamCheckUtility.ClientIdValid, clientId, "clientId", SR.InvalidClientId);
            }
            catch (ArgumentException)
            {
                BrokerTracing.EtwTrace.LogFrontEndRequestRejectedClientIdInvalid(this.SessionId, clientId, Utility.GetMessageIdFromMessage(requestMessage));
                RequestContextBase requestContextToReject = new DuplexRequestContext(requestMessage, this.binding, channel, this.Observer);
                requestContextToReject.BeginReply(FrontEndFaultMessage.GenerateFaultMessage(requestMessage, requestMessage.Headers.MessageVersion, SOAFaultCode.Broker_InvalidClientIdOrTooLong, SR.InvalidClientIdOrTooLong), this.ReplySentCallback, requestContextToReject);
                return;
            }

            if (client == null)
            {
                if (!this.TryGetClientByChannel(channel, clientId, userName, requestMessage, out client))
                {
                    return;
                }

                state.Client = client;
            }

            // Receive new requests
            if (!ar.CompletedSynchronously)
            {
                this.TryToBeginReceiveMessagesWithThrottling(state);
            }

            // Reject if client id does not match
            if (String.Compare(clientId, client.ClientId, StringComparison.OrdinalIgnoreCase) != 0)
            {
                BrokerTracing.EtwTrace.LogFrontEndRequestRejectedClientIdNotMatch(this.SessionId, clientId, Utility.GetMessageIdFromMessage(requestMessage));
                RequestContextBase requestContextToReject = new DuplexRequestContext(requestMessage, this.binding, channel, this.Observer);
                requestContextToReject.BeginReply(FrontEndFaultMessage.GenerateFaultMessage(requestMessage, requestMessage.Headers.MessageVersion, SOAFaultCode.Broker_ClientIdNotMatch, SR.ClientIdNotMatch), this.ReplySentCallback, requestContextToReject);
                return;
            }

            // Try to get the user info header
            bool userDataFlag = GetUserInfoHeader(requestMessage);

            // Create request context
            RequestContextBase requestContext;
            if (userDataFlag)
            {
                // Message that needs not to reply
                requestContext = DummyRequestContext.GetInstance(requestMessage.Version);
            }
            else
            {
                requestContext = new DuplexRequestContext(requestMessage, this.binding, channel, this.Observer, client);
            }

            // Check auth
            if (!this.CheckAuth(requestContext, requestMessage))
            {
                return;
            }

            // remove security header for websocket
            TryRemoveSecurityHeaderForHttps(requestMessage);

            // Send the request to the broker client
            Task.Run(() => client.RequestReceived(requestContext, requestMessage, null));
        }
コード例 #25
0
        public BrokerQueue GetPersistQueueByClient(string clientId, string userName, out bool isNewCreate)
        {
            BrokerTracing.TraceInfo($"[GetPersistQueueByClient] username:{userName}, sessionid:{this.sessionId}, client:{clientId}");
            isNewCreate = false;
            if (string.IsNullOrEmpty(clientId))
            {
                clientId = BrokerQueueFactory.defaultClientId;
            }

            BrokerQueue brokerQueue = null;

            lock (this.clientBrokerQueueDic)
            {
                this.clientBrokerQueueDic.TryGetValue(clientId, out brokerQueue);
            }

            if (brokerQueue == null)
            {
                lock (this.thisLockObj)
                {
                    lock (this.clientBrokerQueueDic)
                    {
                        this.clientBrokerQueueDic.TryGetValue(clientId, out brokerQueue);
                    }

                    if (brokerQueue == null)
                    {
                        ISessionPersist sessionPersist = null;
                        if (string.IsNullOrEmpty(this.persistName))
                        {
                            sessionPersist = new MemoryPersist(userName, this.sessionId, clientId);
                            brokerQueue    = new BrokerPersistQueue(
                                this.brokerQueueDispatcher,
                                this.persistName,
                                this.sessionId,
                                clientId,
                                sessionPersist,
                                1,    // no request cache
                                // no request cache
                                1,    // no response cache
                                // no response cache
                                0,    // no timeout
                                // no timeout
                                false,
                                // no in-memory cache
                                this.sharedData,
                                this);
                            this.brokerQueueDispatcher.AddBrokerQueue(brokerQueue, null);
                        }
                        else
                        {
                            ParamCheckUtility.ThrowIfNull(this.sharedData.BrokerInfo.AzureStorageConnectionString, "StorageConnectString");

                            sessionPersist = new AzureQueuePersist(userName, this.sessionId, clientId, this.sharedData.BrokerInfo.AzureStorageConnectionString);
                            isNewCreate    = sessionPersist.IsNewCreated;
                            brokerQueue    = new BrokerPersistQueue(
                                this.brokerQueueDispatcher,
                                this.persistName,
                                this.sessionId,
                                clientId,
                                sessionPersist,
                                BrokerQueueConstants.DefaultThresholdForRequestPersist,
                                BrokerQueueConstants.DefaultThresholdForResponsePersist,
                                BrokerQueueConstants.DefaultMessagesInCacheTimeout,
                                isNewCreate,  // need in-memory quick cache for newly-created durable queue
                                // need in-memory quick cache for newly-created durable queue
                                this.sharedData,
                                this);

                            //
                            // For an existing durable queue, if EndOfMessage is not received, or there are requests waiting to be processed,
                            // then schedule the broker queue for dispatching;
                            // for an newly created durable queue, it will be added to brokerQueueDispatcher when BrokerQueuePersist.Flush
                            // is called (with quick cache filled), so no need to call AddBrokerQueue here (bug #21453)
                            //
                            if (!isNewCreate && (!brokerQueue.EOMReceived || sessionPersist.RequestsCount > 0))
                            {
                                this.brokerQueueDispatcher.AddBrokerQueue(brokerQueue, null);
                            }
                        }

                        lock (this.clientBrokerQueueDic)
                        {
                            this.clientBrokerQueueDic.Add(clientId, brokerQueue);
                        }
                    }
                }
            }

            // Bug 6313: Check the user name
            ThrowIfUserNameDoesNotMatch(brokerQueue, userName);
            return(brokerQueue);
        }