Exemplo n.º 1
0
        /// <summary>
        /// Create request queue for specified Azure service.
        /// </summary>
        /// <param name="azureServiceName">azure service name</param>
        public void CreateRequestStorage(string azureServiceName)
        {
            this.requestStorage.GetOrAdd(
                azureServiceName,
                (key) =>
            {
                string requestStorageName = SoaHelper.GetRequestStorageName(this.clusterId.ToString(), key);

                BrokerTracing.TraceVerbose(
                    "[AzureQueueManager].CreateRequestStorage: Try to create the request storage {0} for Azure service {1}",
                    requestStorageName,
                    key);

                this.CreateStorageClient(RetryPolicyForRequestStorage);

                CloudQueue queue = this.queueClient.GetQueueReference(requestStorageName);

                AzureQueueManager.CreateQueueWithRetry(queue);

                CloudBlobContainer container = this.blobClient.GetContainerReference(requestStorageName);

                AzureQueueManager.CreateContainerWithRetry(container);

                if (Interlocked.CompareExchange(ref this.requestQueueExist, 1, 0) == 0)
                {
                    BrokerTracing.EtwTrace.LogQueueCreatedOrExist(this.sessionId, requestStorageName);
                }

                return(new Tuple <CloudQueue, CloudBlobContainer>(queue, container));
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets SOA configurations
        /// </summary>
        /// <param name="keys">indicating the keys</param>
        /// <returns>returns the values</returns>
        public async Task <Dictionary <string, string> > GetSOAConfigurations(List <string> keys)
        {
            RetryManager retry = SoaHelper.GetDefaultExponentialRetryManager();

            return(await RetryHelper <Dictionary <string, string> > .InvokeOperationAsync(
                       async() =>
            {
                using (BrokerIdentity identity = new BrokerIdentity())
                {
                    identity.Impersonate();
                    return await this.sessionLauncherClient.Value.GetSOAConfigurationsAsync(keys);
                }
            },
                       async (e, r) =>
            {
                TraceHelper.TraceEvent(
                    TraceEventType.Warning,
                    "[SchedulerHelper] Failed to get SOA configuration, Key:{0}, Retry:{1}, Error:{2}",
                    string.Join(",", keys),
                    r.RetryCount,
                    e);
                await this.RenewSessionLauncherClientAsync();
            },
                       retry));
        }
Exemplo n.º 3
0
 private bool SetClientCredential(ClientCredentials clientCredentials)
 {
     if (this.schedulerOnIaaS || this.info.UseWindowsClientCredential)
     {
         string domainName;
         string userName;
         SoaHelper.ParseDomainUser(this.info.Username, out domainName, out userName);
         clientCredentials.Windows.ClientCredential.Domain   = domainName;
         clientCredentials.Windows.ClientCredential.UserName = userName;
         clientCredentials.Windows.ClientCredential.Password = this.info.InternalPassword;
         return(true);
     }
     else if ((this.scheme & TransportScheme.NetHttp) == TransportScheme.NetHttp)
     {
         clientCredentials.UserName.UserName = this.info.Username;
         clientCredentials.UserName.Password = this.info.InternalPassword;
         return(true);
     }
     else if (this.info.LocalUser)
     {
         clientCredentials.UseInternalAuthenticationAsync().GetAwaiter().GetResult();
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Get data service binding
        /// </summary>
        /// <returns>data service binding</returns>
        private static Binding GetBinding(string headNode)
        {
            Binding binding;

            if (SoaHelper.IsOnAzure())
            {
                // Azure CN doesn't join domain. so secure binding cannot be used to authenticate non-system users
                // TODO: use secure binding and enhance security mechanism
                binding = BindingHelper.HardCodedUnsecureDataServiceNetTcpBinding;
                // At client side, SendTimeout is used to initialize OperationTimeout. It governs
                // the whole interaction for sending a message (including receiving a reply message).
                // ReceiveTimeout is actually not used.
                binding.SendTimeout    = TimeSpan.FromMinutes(Constant.DataProxyOperationTimeoutInMinutes);
                binding.ReceiveTimeout = TimeSpan.FromMinutes(Constant.DataProxyOperationTimeoutInMinutes);
            }
            else if (SoaHelper.IsSchedulerOnIaaS(headNode))
            {
                binding = BindingHelper.HardCodedDataServiceHttpsBinding;
            }
            else
            {
                binding = BindingHelper.HardCodedDataServiceNetTcpBinding;
            }

            return(binding);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the BrokerLauncherClient class.
 /// </summary>
 /// <param name="uri">The broker launcher EPR</param>
 /// <param name="info">The sesion info</param>
 /// <param name="binding">indicting the binding</param>
 public BrokerLauncherClient(Uri uri, SessionInfoBase info, Binding binding)
     : this(info, binding, uri)
 {
     if (info.UseAad)
     {
     }
     else if ((info.TransportScheme & TransportScheme.NetTcp) == TransportScheme.NetTcp)
     {
         SessionInfo sessionInfo = info as SessionInfo;
         if (SoaHelper.IsSchedulerOnIaaS(info.Headnode) || (sessionInfo != null && sessionInfo.UseWindowsClientCredential))
         {
             string domainName;
             string userName;
             SoaHelper.ParseDomainUser(info.Username, out domainName, out userName);
             this.ClientCredentials.Windows.ClientCredential.Domain   = domainName;
             this.ClientCredentials.Windows.ClientCredential.UserName = userName;
             this.ClientCredentials.Windows.ClientCredential.Password = info.InternalPassword;
         }
     }
     else if ((info.TransportScheme & TransportScheme.Http) == TransportScheme.Http || (info.TransportScheme & TransportScheme.NetHttp) == TransportScheme.NetHttp)
     {
         this.ClientCredentials.UserName.UserName = info.Username;
         this.ClientCredentials.UserName.Password = info.InternalPassword;
     }
 }
Exemplo n.º 6
0
        public async Task FreeResource(SessionStartInfo startInfo, string sessionId)
        {
            try
            {
                if (!sessionId.Equals("0"))
                {
                    RetryManager retry = SoaHelper.GetDefaultExponentialRetryManager();

                    await RetryHelper <object> .InvokeOperationAsync(
                        async() =>
                    {
                        await this.client.TerminateAsync(sessionId).ConfigureAwait(false);
                        return(null);
                    },
                        (e, r) =>
                    {
                        if (e is EndpointNotFoundException)
                        {
                            Utility.SafeCloseCommunicateObject(this.client);
                            this.client = new SessionLauncherClient(startInfo, this.binding);
                        }
                        else
                        {
                            r.MaxRetryCount = 0;
                        }
                        return(Task.CompletedTask);
                    },
                        retry).ConfigureAwait(false);
                }
            }
            catch
            {
                // if terminate the session failed, then do nothing here.
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Get data service binding
        /// </summary>
        /// <returns>data service binding</returns>
        private static Binding GetBinding(Uri uri)
        {
            Binding binding;

            if (uri.Scheme.Equals(BindingHelper.HttpsScheme, StringComparison.OrdinalIgnoreCase))
            {
                binding = BindingHelper.HardCodedDataServiceHttpsBinding;
            }
            else if (uri.Scheme.Equals(BindingHelper.NetTcpScheme))
            {
                if (SoaHelper.IsOnAzure())
                {
                    // Azure CN doesn't join domain. so secure binding cannot be used to authenticate non-system users
                    // TODO: use secure binding and enhance security mechanism
                    binding = BindingHelper.HardCodedUnsecureDataServiceNetTcpBinding;
                    // At client side, SendTimeout is used to initialize OperationTimeout. It governs
                    // the whole interaction for sending a message (including receiving a reply message).
                    // ReceiveTimeout is actually not used.
                    binding.SendTimeout    = TimeSpan.FromMinutes(Constant.DataProxyOperationTimeoutInMinutes);
                    binding.ReceiveTimeout = TimeSpan.FromMinutes(Constant.DataProxyOperationTimeoutInMinutes);
                }
                else
                {
                    binding = BindingHelper.HardCodedDataServiceNetTcpBinding;
                }
            }
            else
            {
                throw new NotImplementedException(string.Format("[DataServiceAgent] Not supported Uri scheme: {0}", uri));
            }

            return(binding);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the BrokerNodeAuthManager class.
        /// </summary>
        /// <param name="jobId">job id of the soa session</param>
        internal BrokerNodeAuthManager(string jobId)
        {
            this.jobId = jobId;

            if (SoaHelper.IsCurrentUserLocal() || WindowsIdentity.GetCurrent().IsSystem)
            {
                this.enable = false;
                RuntimeTraceHelper.TraceEvent(this.jobId, TraceEventType.Information, "[HpcServiceHost]: BrokerNodeAuthManager is disabled in non-domain joined compute node.");
            }
            else
            {
                this.enable      = true;
                this.allowedUser = WindowsIdentity.GetCurrent();

                // If this environment does not exist, the jobOwnerUserName will remain null.
                // Thus the comparision will always fail so that HpcServiceHost will not authenticate job owner.
                this.jobOwnerUserName = Environment.GetEnvironmentVariable(Constant.JobOwnerNameEnvVar, EnvironmentVariableTarget.Process);

                RuntimeTraceHelper.TraceEvent(
                    this.jobId,
                    TraceEventType.Information,
                    "[HpcServiceHost]: BrokerNodeAuthManager initialized. AllowerUser = {0}, JobOwner = {1}",
                    this.allowedUser.Name,
                    this.jobOwnerUserName);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the HpcSchedulerAdapterClient class
        /// </summary>
        /// <param name="headnode">indicating the headnode</param>
        /// <param name="instanceContext">indicating the instance context</param>
        public HpcSchedulerAdapterClient(string headnode, string certThrumbprint, InstanceContext instanceContext)
            : base(
                instanceContext,
                BindingHelper.HardCodedInternalSchedulerDelegationBinding,
                SoaHelper.CreateInternalCertEndpointAddress(new Uri(SoaHelper.GetSchedulerDelegationAddress(headnode)), certThrumbprint))
        {
            BrokerTracing.TraceVerbose("[HpcSchedulerAdapterClient] In constructor");
            this.ClientCredentials.UseInternalAuthentication(certThrumbprint);
            if (BrokerIdentity.IsHAMode)
            {
                // Bug 10301 : Explicitly open channel when impersonating the resource group's account if running on failover cluster so identity flows correctly when
                //      calling HpcSession.
                //  NOTE: The patch we got from the WCF team (KB981001) only works when the caller is on a threadpool thread.
                //  NOTE: Channel must be opened before setting OperationTimeout
                using (BrokerIdentity identity = new BrokerIdentity())
                {
                    identity.Impersonate();
                    this.Open();
                }
            }

            this.InnerChannel.OperationTimeout = SchedulerAdapterTimeout;

            foreach (OperationDescription op in this.Endpoint.Contract.Operations)
            {
                DataContractSerializerOperationBehavior dataContractBehavior = op.Behaviors.Find <DataContractSerializerOperationBehavior>() as DataContractSerializerOperationBehavior;
                if (dataContractBehavior != null)
                {
                    dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue;
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the BrokerManager class
        /// </summary>
        public BrokerManager(bool needRecover, ITelepathyContext context)
        {
            TraceHelper.TraceEvent(TraceEventType.Verbose, "[BrokerManager] Constructor: needRecover={0}", needRecover);
            this.headnode = SoaHelper.GetSchedulerName();

            this.context = context;

            this.brokerDic = new Dictionary <string, BrokerInfo>();

            this.staleSessionCleanupTimer = new Timer(this.CleanStaleSessionData, null, Timeout.Infinite, Timeout.Infinite);
#if HPCPACK
            if (!SoaHelper.IsOnAzure())
            {
                // TODO: on azure, about the MSMQ. Don't use the MSMQ in the Azure cluster.
                this.updateQueueLengthTimer = new Timer(this.CallbackToUpdateMSMQLength, null, Timeout.Infinite, Timeout.Infinite);
            }
#endif

            this.pool = new BrokerProcessPool();

            // TODO: enable recovery in Telepathy
#if HPCPACK
            if (needRecover && !BrokerLauncherEnvironment.Standalone)
            {
                this.ts = new CancellationTokenSource();
                CancellationToken ct = ts.Token;
                this.RecoverTask = Task.Run(async() => await this.RecoverThreadProc(ct), ct);
            }
#endif
        }
Exemplo n.º 11
0
        /// <summary>
        /// Apply session id to the uri
        /// </summary>
        /// <param name="baseUri">indicate the base uri</param>
        /// <param name="sessionId">indicate the session id</param>
        /// <param name="postfix">indicate the postfix</param>
        /// <param name="needFqdn">indicate if need FQDN</param>
        /// <returns>uri with session id</returns>
        private static Uri ApplySessionId(Uri baseUri, string sessionId, string postfix, bool needFqdn)
        {
            UriBuilder builder = new UriBuilder(baseUri);

            if (baseUri.IsLoopback)
            {
#if PaaS
                if (SoaHelper.IsOnAzure())
                {
                    builder.Host = AzureRoleHelper.GetLocalMachineAddress();
                }
                else
#endif
                {
                    if (needFqdn)
                    {
                        string domainName = IPGlobalProperties.GetIPGlobalProperties().DomainName;
                        builder.Host = string.Format("{0}.{1}", Environment.MachineName, domainName);
                    }
                    else
                    {
                        builder.Host = Environment.MachineName;
                    }
                }
            }

            return(new Uri(builder.Uri, String.Format(CultureInfo.InvariantCulture, "{0}/{1}", sessionId, postfix)));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Save the credential at local Windows Vault, if
        /// (1) scheduler is on Azure (credential is needed by session service to run as that user)
        /// (2) debug mode (no scheduler)
        /// (3) scheduler version is before 3.1 (scheduler side credential cache is not supported before 3.1)
        /// </summary>
        /// <param name="info">it contians credential and targeted scheduler</param>
        /// <param name="binding">indicating the binding</param>
        public static void SaveCrendential(SessionStartInfo info, Binding binding)
        {
            if (info.SavePassword && info.InternalPassword != null)
            {
                Debug.Assert(!String.IsNullOrEmpty(info.Headnode), "The headnode can't be null or empty.");

                bool saveToLocal = false;

                if (SoaHelper.IsSchedulerOnAzure(info.Headnode) || SoaHelper.IsSchedulerOnIaaS(info.Headnode))
                {
                    saveToLocal = true;
                }
                else if (info.DebugModeEnabled)
                {
                    saveToLocal = true;
                }

                if (saveToLocal)
                {
                    SaveCrendential(info.Headnode, info.Username, info.InternalPassword);
                    SessionBase.TraceSource.TraceInformation("Cached credential is saved to local Windows Vault.");
                }
                else
                {
                    // the password is already sent to session service, which saves it to the scheduler.
                    SessionBase.TraceSource.TraceInformation("Cached credential is expected to be saved to the scheduler by session service.");
                }
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Build broker authorization
        /// </summary>
        /// <param name="sharedData">indicating the shared data</param>
        /// <param name="monitor">indicating the service job monitor</param>
        /// <returns>returns the broker autorization instance</returns>
        private static BrokerAuthorization BuildBrokerAuthorization(SharedData sharedData)
        {
            // No authorization for inprocess session
            if (sharedData.StartInfo.UseInprocessBroker)
            {
                return(null);
            }

            if (sharedData.StartInfo.Secure)
            {
                if (SoaHelper.IsOnAzure())
                {
                    return(null);
                }

                if (sharedData.StartInfo.ShareSession)
                {
                    // TODO: Feature: share session
                    throw new NotImplementedException();
                    // return new BrokerAuthorization(sharedData.BrokerInfo.JobTemplateACL, (int)JobTemplateRights.SubmitJob, (int)JobTemplateRights.Generic_Read, (int)JobTemplateRights.Generic_Write, (int)JobTemplateRights.Generic_Execute, (int)JobTemplateRights.Generic_All);
                }
                else
                {
                    return(new BrokerAuthorization(new SecurityIdentifier(sharedData.BrokerInfo.JobOwnerSID)));
                }
            }
            else
            {
                // No authorization for nonsecure session
                return(null);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Generate endpoint address by scheme from epr list
        /// </summary>
        /// <param name="eprList">indicating the epr list</param>
        /// <param name="scheme">indicating the scheme</param>
        /// <returns>endpoint address</returns>
        private static EndpointAddress GenerateEndpointAddress(string[] eprList, TransportScheme scheme, bool secure, bool internalChannel)
        {
            int    index = (int)Math.Log((int)scheme, 2);
            string epr   = eprList[index];

            return(SoaHelper.CreateEndpointAddress(new Uri(epr), secure, internalChannel));
        }
Exemplo n.º 15
0
        /// <summary>
        /// Initializes a new instance of the HpcSchedulerAdapterInternalClient class
        /// </summary>
        /// <param name="headNodeMachine">indicating the headnode</param>
        public HpcSchedulerAdapterInternalClient(string headNodeMachine, string certThumbprint)
            : base(
                BindingHelper.HardCodedInternalSchedulerDelegationBinding,
                SoaHelper.CreateInternalCertEndpointAddress(new Uri(SoaHelper.GetSchedulerDelegationInternalAddress(headNodeMachine)), certThumbprint))
        {
#if BrokerLauncher
            BrokerTracing.TraceVerbose("[HpcSchedulerAdapterInternalClient] In constructor");
#endif
            // use certificate for cluster internal authentication
            this.ClientCredentials.UseInternalAuthentication(certThumbprint);

            if (BrokerIdentity.IsHAMode)
            {
                // Bug 10301 : Explicitly open channel when impersonating the resource group's account if running on failover cluster so identity flows correctly when
                //      calling HpcSession.
                //  NOTE: The patch we got from the WCF team (KB981001) only works when the caller is on a threadpool thread.
                //  NOTE: Channel must be opened before setting OperationTimeout
                using (BrokerIdentity identity = new BrokerIdentity())
                {
                    identity.Impersonate();
                    this.Open();
                }
            }

            this.InnerChannel.OperationTimeout = OperationTimeout;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Process a collection of queue messages.
        /// </summary>
        /// <param name="messages">collection of the queue messages</param>
        private void ProcessMessages(IEnumerable <CloudQueueMessage> messages)
        {
            BrokerTracing.TraceInfo(SoaHelper.CreateTraceMessage("Proxy", "ProcessMessages", string.Format("Process {0} messages.", messages.Count <CloudQueueMessage>())));

            messages.AsParallel <CloudQueueMessage>()
            .ForAll <CloudQueueMessage>(
                (requestQueueMessage) =>
            {
                Message request = null;

                try
                {
                    BrokerTracing.TraceInfo(string.Format("SOA broker proxy perf1 - {0}", DateTime.UtcNow.TimeOfDay.TotalSeconds));

                    request = this.requestStorageClients.First().GetWcfMessageFromQueueMessage(requestQueueMessage);

                    this.requestMessageQueue.Add(request);

                    // this.requestMessageQueue.Enqueue(request);
                    UniqueId messageId = SoaHelper.GetMessageId(request);

                    BrokerTracing.TraceInfo(SoaHelper.CreateTraceMessage("Proxy", "Request received inqueue", string.Empty, messageId, "Request message in queue"));
                }
                catch (Exception e)
                {
                    BrokerTracing.TraceError(SoaHelper.CreateTraceMessage("Proxy", "ProcessMessages", string.Format("Error occurs {0}", e)));
                }
            });

            this.semaphoreForWorker.Release();
        }
Exemplo n.º 17
0
        /// <summary>
        /// Set the trace level according to the env var
        /// </summary>
        public static void SetTraceSwitchLevel()
        {
            SourceLevels level = Utility.GetTraceSwitchLevel();

            ServiceContext.Logger.Switch.Level = level;

            if (level != SourceLevels.Off)
            {
                RuntimeTraceHelper.IsDiagTraceEnabled = x => true;

                RuntimeTraceHelper.TraceEvent(
                    TraceEventType.Information,
                    SoaHelper.CreateTraceMessage(
                        "Utility",
                        "SetTraceSwitchLevel",
                        "Add the SoaDiagTraceListener."));

                ServiceContext.Logger.Listeners.Add(new SoaDiagTraceListener(Utility.GetJobId()));
            }
            else
            {
                RuntimeTraceHelper.TraceEvent(
                    TraceEventType.Information,
                    SoaHelper.CreateTraceMessage(
                        "Utility",
                        "SetTraceSwitchLevel",
                        "SoaDiagTrace is disabled."));
            }
        }
Exemplo n.º 18
0
        public async Task <SessionInfo> GetResourceInfo(SessionAttachInfo attachInfo, TimeSpan timeout)
        {
            this.client.InnerChannel.OperationTimeout = timeout;
            RetryManager retry = SoaHelper.GetDefaultExponentialRetryManager();

            SessionInfo info;
            DateTime    startTime = DateTime.Now;

            if (attachInfo.TransportScheme == TransportScheme.Http)
            {
                info = Utility.BuildSessionInfoFromDataContract(
                    await RetryHelper <SessionInfoContract> .InvokeOperationAsync(
                        async() => await this.client.GetInfoAsync(SessionLauncherClient.HttpsEndpointPrefix, attachInfo.SessionId).ConfigureAwait(false),
                        (e, r) =>
                {
                    var remainingTime = GetRemainingTime(timeout, startTime);
                    if ((e is EndpointNotFoundException || (e is CommunicationException && !(e is FaultException <SessionFault>))) && remainingTime > TimeSpan.Zero)
                    {
                        Utility.SafeCloseCommunicateObject(this.client);
                        this.client = new SessionLauncherClient(attachInfo, this.binding);
                        this.client.InnerChannel.OperationTimeout = remainingTime;
                    }
                    else
                    {
                        r.MaxRetryCount = 0;
                    }

                    return(Task.CompletedTask);
                },
                        retry)
                    .ConfigureAwait(false));
            }
            else
            {
                info = Utility.BuildSessionInfoFromDataContract(
                    await RetryHelper <SessionInfoContract> .InvokeOperationAsync(
                        async() => await this.client.GetInfoAsync(SessionLauncherClient.EndpointPrefix, attachInfo.SessionId).ConfigureAwait(false),
                        (e, r) =>
                {
                    var remainingTime = GetRemainingTime(timeout, startTime);

                    if ((e is EndpointNotFoundException || (e is CommunicationException && !(e is FaultException <SessionFault>))) && remainingTime > TimeSpan.Zero)
                    {
                        Utility.SafeCloseCommunicateObject(this.client);
                        this.client = new SessionLauncherClient(attachInfo, this.binding);
                        this.client.InnerChannel.OperationTimeout = remainingTime;
                    }
                    else
                    {
                        r.MaxRetryCount = 0;
                    }

                    return(Task.CompletedTask);
                },
                        retry)
                    .ConfigureAwait(false));
            }

            return(info);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Get requests from the local cache and spawn a thread to process
        /// them.
        /// </summary>
        /// <remarks>
        /// Can add throttling logic in the method, but now no need, because
        /// broker proxy doesn't hit limit of CPU, Memory or Network.
        /// </remarks>
        private void MessageProcessor()
        {
            try
            {
                while (true)
                {
                    this.semaphoreForResponse.WaitOne();

                    IEnumerable <CloudQueueMessage> messages;

                    if (this.responseCache.TryDequeue(out messages))
                    {
                        this.semaphoreForWorker.WaitOne();

                        ThreadPool.QueueUserWorkItem((s) => { this.ProcessMessages(messages); });
                    }
                }
            }
            catch (Exception e)
            {
                SessionBase.TraceSource.TraceInformation(
                    SoaHelper.CreateTraceMessage(
                        "Proxy",
                        "MessageProcessor",
                        string.Format("Error occurs, {0}", e)));
            }
        }
Exemplo n.º 20
0
            /// <summary>
            /// Start the timer.
            /// </summary>
            private void TriggerTimer()
            {
                if (this.stop)
                {
                    lock (this.timerStopLock)
                    {
                        if (this.stop)
                        {
                            this.timerStopped = true;
                            BrokerTracing.TraceInfo(
                                SoaHelper.CreateTraceMessage(
                                    "MessageSender.Worker",
                                    "TriggerTimer",
                                    "Worker stops."));
                            return;
                        }
                        else
                        {
                            this.timerStopped = false;
                        }
                    }
                }

                try
                {
                    BrokerTracing.TraceInfo(
                        SoaHelper.CreateTraceMessage(
                            "MessageSender.Worker",
                            "TriggerTimer",
                            "Timer triggered with sleep time {0}.", this.sleepPeriod));

                    this.timer.Change(this.sleepPeriod, Timeout.Infinite);

                    if (this.sleepPeriod == 0)
                    {
                        this.sleepPeriod = MinSleepTime;
                    }
                    else
                    {
                        this.sleepPeriod *= 2;

                        if (this.sleepPeriod > MaxSleepTime)
                        {
                            this.sleepPeriod = MaxSleepTime;
                        }
                    }
                }
                catch (NullReferenceException)
                {
                    TraceUtils.TraceWarning(
                        "MessageSender.Worker",
                        "TriggerTimer",
                        "NullReferenceException occurs when timer is being disposed.");
                }
                catch (Exception e)
                {
                    TraceUtils.TraceError("MessageSender.Worker", "TriggerTimer", "Error occurs, {0}", e);
                }
            }
Exemplo n.º 21
0
 /// <summary>
 /// Initializes a new instance of the SessionLauncherClient class.
 /// </summary>
 /// <param name="uri">the session launcher EPR</param>
 /// <param name="binding">indicating the binding</param>
 public SessionLauncherClient(Uri uri, Binding binding, bool useInternalChannel)
     : base(binding ?? GetBinding(useInternalChannel), GetEndpoint(uri, useInternalChannel))
 {
     if (!SoaHelper.IsOnAzure())
     {
         this.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
     }
 }
Exemplo n.º 22
0
 /// <summary>
 /// cleanup the stake session data.
 /// </summary>
 /// <param name="isStaleSessionCallback">the callback to judge whether </param>
 public static async Task CleanupStaleSessionData(IsStaleSessionCallback isStaleSessionCallback, string connectString)
 {
     if (!SoaHelper.IsOnAzure())
     {
         // TODO: on azure, about MSMQ
         await BrokerQueueFactory.CleanupStalePersistedData("azurequeue", isStaleSessionCallback, connectString);
     }
 }
Exemplo n.º 23
0
        /// <summary>
        /// Process a collection of queue messages.
        /// </summary>
        /// <param name="messages">collection of the queue messages</param>
        private void ProcessMessages(IEnumerable <CloudQueueMessage> messages)
        {
            SessionBase.TraceSource.TraceInformation(
                SoaHelper.CreateTraceMessage(
                    "Proxy",
                    "ProcessMessages",
                    string.Format("Process {0} messages.", messages.Count <CloudQueueMessage>())));

            messages.AsParallel <CloudQueueMessage>().ForAll <CloudQueueMessage>(
                (responseQueueMessage) =>
            {
                Message response = null;

                try
                {
                    SessionBase.TraceSource.TraceInformation(
                        string.Format("SOA broker proxy perf1 - {0}", DateTime.UtcNow.TimeOfDay.TotalSeconds));

                    response = this.responseStorageClient.GetWcfMessageFromQueueMessage(responseQueueMessage);

                    var qkey = Tuple.Create(SoaHelper.GetClientDataHeaderFromMessage(response));

                    if (!this.responseMessageQueues.ContainsKey(qkey))
                    {
                        lock (this.responseMessageQueues)
                        {
                            if (!this.responseMessageQueues.ContainsKey(qkey))
                            {
                                this.responseMessageQueues.Add(qkey, new ConcurrentQueue <Message>());
                            }
                        }
                    }

                    this.responseMessageQueues[qkey].Enqueue(response);

                    UniqueId messageId = SoaHelper.GetMessageId(response);

                    SessionBase.TraceSource.TraceInformation(
                        SoaHelper.CreateTraceMessage(
                            "Proxy",
                            "Response received inqueue",
                            string.Empty,
                            messageId,
                            "Response message in queue"));

                    // do not delete the message from the queue here, depends on the long invisable timeout and hourly cleanup
                    // this.responseStorageClient.DeleteMessageAsync(responseQueueMessage, messageId);
                }
                catch (Exception e)
                {
                    SessionBase.TraceSource.TraceInformation(
                        SoaHelper.CreateTraceMessage(
                            "Proxy", "ProcessMessages", string.Format("Error occurs {0}", e)));
                }
            });

            this.semaphoreForWorker.Release();
        }
Exemplo n.º 24
0
 /// <summary>
 /// Initializes a new instance of the DataServiceAgent class
 /// </summary>
 /// <param name="uri">data service uri</param>
 public DataServiceAgent(Uri uri) :
     base(GetBinding(uri), GetEndpoint(uri))
 {
     // For common data on Azure, none secure binding is used
     if (!SoaHelper.IsOnAzure())
     {
         this.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
     }
 }
Exemplo n.º 25
0
        internal static string GenerateBrokerLauncherAadEpr(string endpointPrefix, string machineName)
        {
            if (endpointPrefix.Equals(NettcpPrefix, StringComparison.InvariantCultureIgnoreCase))
            {
                return(SoaHelper.GetBrokerLauncherAadAddress(machineName));
            }

            throw new ArgumentException("AAD only support net.tcp");
        }
        /// <summary>
        /// Check access for incoming call
        /// </summary>
        /// <param name="operationContext">indicating the operation context</param>
        /// <returns>returns if incoming user is system</returns>
        protected override bool CheckAccessCore(OperationContext operationContext)
        {
            if (SoaHelper.IsOnAzure())
            {
                return(true);
            }

            // Bug 6152: Only allow system account to use this service
            return(operationContext.ServiceSecurityContext.WindowsIdentity.IsSystem);
        }
Exemplo n.º 27
0
        protected override bool CheckAccessCore(OperationContext operationContext)
        {
            if (SoaHelper.IsOnAzure())
            {
                // Skip it in the Azure cluster.
                return(true);
            }

            return(ServiceSecurityContext.Current.WindowsIdentity.User == this.allowedUser);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Creates a new client
        /// </summary>
        private BrokerManagementServiceClient CreateClient()
        {
            BrokerManagementServiceClient client =
                new BrokerManagementServiceClient(
                    BindingHelper.HardCodedBrokerManagementServiceBinding,
                    new EndpointAddress(SoaHelper.GetBrokerManagementServiceAddress(this.brokerProcess.Id)));

            client.InnerChannel.OperationTimeout = operationTimeoutForBrokerManagementService;
            return(client);
        }
Exemplo n.º 29
0
        public static Guid GetMessageIdFromMessage(Message message)
        {
            Guid     guid = Guid.Empty;
            UniqueId id   = SoaHelper.GetMessageId(message);

            if (id != null)
            {
                id.TryGetGuid(out guid);
            }
            return(guid);
        }
Exemplo n.º 30
0
 /// <summary>
 /// Get the endpoint Uri for session launcher
 /// </summary>
 /// <param name="headnode">the headnode name</param>
 /// <param name="binding">indicating the binding</param>
 /// <param name="useInternalChannel">If connect to Session Launcher via internal channel</param>
 /// <returns>the SessionLauncher EPR</returns>
 public static Uri GetSessionLauncher(string headnode, Binding binding, bool useInternalChannel)
 {
     if (LocalSession.LocalBroker)
     {
         return(new Uri(SessionLauncherNetPipeAddress));
     }
     else
     {
         return(new Uri((useInternalChannel || SoaHelper.IsCurrentUserLocal()) ? SoaHelper.GetSessionLauncherInternalAddress(headnode, binding) : SoaHelper.GetSessionLauncherAddress(headnode, binding)));
     }
 }