Example #1
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);
        }
Example #2
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.
            }
        }
Example #3
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));
        }
Example #4
0
        /// <summary>
        /// Fail a service job with the reason
        /// </summary>
        /// <param name="jobid">the job id</param>
        /// <param name="reason">the reason string</param>
        public async Task FailJob(string jobid, string reason)
        {
            RetryManager retry = SoaHelper.GetDefaultExponentialRetryManager();

            await RetryHelper <object> .InvokeOperationAsync(
                async() =>
            {
                await this.schedulerClient.Value.FailJobAsync(jobid, reason);
                return(null);
            },
                async (e, r) =>
            {
                TraceHelper.TraceEvent(jobid, System.Diagnostics.TraceEventType.Error, "[SchedulerHelper] Exception throwed while failing job: {0}\nRetryCount = {1}", e, r.RetryCount);
                await this.RenewSchedulerAdapterClientAsync();
            },
                retry);
        }
Example #5
0
        /// <summary>
        /// Gets cluster info
        /// </summary>
        /// <param name="keys">indicating the keys</param>
        /// <returns>returns the values</returns>
        public async Task <ClusterInfoContract> GetClusterInfoAsync()
        {
            RetryManager retry = SoaHelper.GetDefaultExponentialRetryManager();

            return(await RetryHelper <ClusterInfoContract> .InvokeOperationAsync(
                       async() =>
            {
                using (BrokerIdentity identity = new BrokerIdentity())
                {
                    identity.Impersonate();
                    return await this.sessionLauncherClient.Value.GetClusterInfoAsync();
                }
            },
                       async (e, r) =>
            {
                TraceHelper.TraceEvent(TraceEventType.Warning, "[SchedulerHelper] Failed to get cluster info, Retry:{0}, Error:{1}", r.RetryCount, e);
                await this.RenewSessionLauncherClientAsync();
            },
                       retry));
        }
Example #6
0
 /// <summary>
 /// Query task info
 /// </summary>
 private async Task StartMonitorAsync()
 {
     try
     {
         TraceHelper.TraceEvent(this.sessionid, TraceEventType.Verbose, "[AzureBatchJobMonitorEntry] Start Azure Batch Job Monitor.");
         // RetryManager mgr = new RetryManager(new ExponentialRandomBackoffRetryTimer(1 * 1000, 10 * 1000));
         // await mgr.InvokeWithRetryAsync(() => await batchJobMonitor.StartAsync(), ex => true);
         RetryManager retry = SoaHelper.GetDefaultExponentialRetryManager();
         await RetryHelper <Task> .InvokeOperationAsync(
             async() =>
         {
             await this.batchJobMonitor.StartAsync();
             return(null);
         },
             async (e, r) => await Task.FromResult <object>(new Func <object>(() => { TraceHelper.TraceEvent(this.sessionid, TraceEventType.Warning, "[AzureBatchJobMonitorEntry] Exception thrown when trigger start Azure Batch Job Monitor: {0} ", e, r.RetryCount); return(null); }).Invoke()),
             retry);
     }
     catch (Exception e)
     {
         TraceHelper.TraceEvent(this.sessionid, TraceEventType.Warning, "[AzureBatchJobMonitorEntry] Exception thrown when trigger start Azure Batch Job Monitor: {0}", e);
     }
 }
Example #7
0
        /// <summary>
        /// Update broker info
        /// </summary>
        /// <param name="sessionId">indicating the session id</param>
        /// <param name="properties">indicating the key value pairs to be updated</param>
        private async Task UpdateBrokerInfoInternalAsync(string sessionId, Dictionary <string, object> properties)
        {
            RetryManager retry = SoaHelper.GetDefaultExponentialRetryManager();

            await RetryHelper <object> .InvokeOperationAsync(
                async() =>
            {
                if (await this.schedulerClient.Value.UpdateBrokerInfoAsync(sessionId, properties).ConfigureAwait(false))
                {
                    return(null);
                }
                else
                {
                    throw new InvalidOperationException("Can not update the properties in the scheduler database for EPRs");
                }
            },
                async (e, r) =>
            {
                TraceHelper.TraceEvent(sessionId, TraceEventType.Error, "[BrokerLauncher.SchedulerHelper] UpdateBrokerInfo failed: Exception = {0}\nRetryCount = {1}", e, r.RetryCount);
                await this.RenewSchedulerAdapterClientAsync().ConfigureAwait(false);
            },
                retry).ConfigureAwait(false);
        }
Example #8
0
        public async Task <SessionAllocateInfoContract> AllocateResource(SessionStartInfo startInfo, bool durable, TimeSpan timeout)
        {
            SessionAllocateInfoContract sessionAllocateInfo = new SessionAllocateInfoContract();

            this.client.InnerChannel.OperationTimeout = timeout;

            RetryManager retry = SoaHelper.GetDefaultExponentialRetryManager();

            SessionBase.TraceSource.TraceEvent(TraceEventType.Verbose, 0, "[Session:Unknown] Allocating resource... IsDurable = {0}, is LocalUser = {1}", durable, startInfo.LocalUser);
            DateTime startTime = DateTime.Now;

            if (durable)
            {
                sessionAllocateInfo = await RetryHelper <SessionAllocateInfoContract> .InvokeOperationAsync(
                    async() => await this.client.AllocateDurableAsync(startInfo.Data, this.endpointPrefix).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(startInfo, this.binding);
                        this.client.InnerChannel.OperationTimeout = remainingTime;
                    }
                    else
                    {
                        r.MaxRetryCount = 0;
                    }
                    return(Task.CompletedTask);
                },
                    retry).ConfigureAwait(false);
            }
            else
            {
                sessionAllocateInfo = await RetryHelper <SessionAllocateInfoContract> .InvokeOperationAsync(
                    async() => await this.client.AllocateAsync(startInfo.Data, this.endpointPrefix).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(startInfo, this.binding);
                        this.client.InnerChannel.OperationTimeout = remainingTime;
                    }
                    else
                    {
                        r.MaxRetryCount = 0;
                    }
                    return(Task.CompletedTask);
                },
                    retry).ConfigureAwait(false);
            }

            SessionBase.TraceSource.TraceEvent(TraceEventType.Verbose, 0, "[Session:{0}] Successfully allocated resource. Eprs = {1}", sessionAllocateInfo.Id, sessionAllocateInfo.BrokerLauncherEpr == null ? string.Empty : string.Join(",", sessionAllocateInfo.BrokerLauncherEpr));

            if (sessionAllocateInfo.ServiceVersion != null)
            {
                try
                {
                    startInfo.Data.ServiceVersion = sessionAllocateInfo.ServiceVersion;
                }
                catch
                {
                    throw new SessionException(SR.InvalidServiceVersionReturned);
                }
            }

            if (startInfo.UseSessionPool)
            {
                return(sessionAllocateInfo);
            }
            else
            {
                if (!startInfo.UseInprocessBroker && (sessionAllocateInfo.BrokerLauncherEpr == null || sessionAllocateInfo.BrokerLauncherEpr.Length == 0))
                {
                    throw new SessionException(SR.NoBrokerNodeFound);
                }

                return(sessionAllocateInfo);
            }
        }
Example #9
0
        /// <summary>
        /// Build broker start information
        /// </summary>
        /// <param name="serviceName">indicating service name</param>
        /// <param name="serviceVersion">indicating service version</param>
        /// <param name="sessionId">indicating session id</param>
        /// <param name="durable">indicating whether the session is durable</param>
        /// <param name="attached">indicating whether the session is raised up by attaching</param>
        private async Task BuildBrokerStartInfo(string serviceName, Version serviceVersion, string sessionId, bool durable, bool attached)
        {
            this.brokerInfo          = new BrokerStartInfo();
            this.brokerInfo.Headnode = this.startInfo.Headnode;

            // Secure will be set to false and the following two settings are ignored
            this.brokerInfo.JobOwnerSID       = null;
            this.brokerInfo.JobTemplateACL    = null;
            this.brokerInfo.PersistVersion    = BrokerVersion.DefaultPersistVersion;
            this.brokerInfo.SessionId         = sessionId;
            this.brokerInfo.Attached          = attached;
            this.brokerInfo.Durable           = durable;
            this.brokerInfo.NetworkPrefix     = Constant.EnterpriseNetwork;
            this.brokerInfo.ConfigurationFile = await this.FetchServiceRegistrationPath(serviceName, serviceVersion).ConfigureAwait(false);

            // Bug 14892: Fetch AutoShrinkEnabled property from scheduler (via session launcher)
            if (!this.isDebugModeEnabled)
            {
                SessionLauncherClient client = new SessionLauncherClient(await Utility.GetSessionLauncherAsync(this.startInfo, this.binding).ConfigureAwait(false), this.binding, this.startInfo.IsAadOrLocalUser);

                try
                {
                    this.brokerInfo.AutomaticShrinkEnabled = await RetryHelper <bool> .InvokeOperationAsync(
                        async() => Convert.ToBoolean(await client.GetSOAConfigurationAsync(Constant.AutomaticShrinkEnabled).ConfigureAwait(false)),
                        async (e, count) =>
                    {
                        SessionBase.TraceSource.TraceEvent(TraceEventType.Warning, 0, "[InprocBrokerAdapter] Failed to get AutomaticShrinkEnabled property via session launcher service: {0}\nRetryCount = {1}", e, count);
                        Utility.SafeCloseCommunicateObject(client);
                        client = new SessionLauncherClient(await Utility.GetSessionLauncherAsync(this.startInfo, this.binding).ConfigureAwait(false), this.binding, this.startInfo.IsAadOrLocalUser);
                    },
                        SoaHelper.GetDefaultExponentialRetryManager()).ConfigureAwait(false);
                }
                catch (Exception e)
                {
                    SessionBase.TraceSource.TraceEvent(TraceEventType.Error, 0, "[InprocBrokerAdapter] Failed to get AutomaticShrinkEnabled property via session launcher service: {0}", e);
                }
                finally
                {
                    Utility.SafeCloseCommunicateObject(client);
                }

                this.brokerInfo.EnableDiagTrace = false; // TODO: retrieve this from session

                // SchedulerAdapterInternalClient schedulerAdapterClient = new SchedulerAdapterInternalClient(await this.startInfo.ResolveHeadnodeMachineAsync().ConfigureAwait(false));

                /*
                 * ISchedulerAdapter schedulerAdapterClient = SessionServiceContainer.SchedulerAdapterInstance;
                 * try
                 * {
                 *  this.brokerInfo.EnableDiagTrace = await RetryHelper<bool>.InvokeOperationAsync(
                 *      async () => await
                 #if net40
                 *      TaskEx.Run(
                 #else
                 *      Task.Run(
                 #endif
                 *          () => schedulerAdapterClient.IsDiagTraceEnabled(sessionId)).ConfigureAwait(false),
                 *      async (e, count) =>
                 *      {
                 *          SessionBase.TraceSource.TraceEvent(TraceEventType.Warning, 0, "[InprocBrokerAdapter] Failed to get IsDiagTraceEnabled property via session launcher service: {0}\nRetryCount = {1}", e, count);
                 *          var communicateObj = schedulerAdapterClient as ICommunicationObject;
                 *          if (communicateObj != null)
                 *          {
                 *              Utility.SafeCloseCommunicateObject(communicateObj);
                 *          }
                 *
                 *          //schedulerAdapterClient = new SchedulerAdapterInternalClient(await this.startInfo.ResolveHeadnodeMachineAsync().ConfigureAwait(false));
                 *          schedulerAdapterClient = SessionServiceContainer.SchedulerAdapterInstance;
                 *      },
                 *      SoaHelper.GetDefaultExponentialRetryManager()).ConfigureAwait(false);
                 * }
                 * catch (Exception e)
                 * {
                 *  SessionBase.TraceSource.TraceEvent(TraceEventType.Error, 0, "[InprocBrokerAdapter] Failed to get IsDiagTraceEnabled property via session launcher service: {0}", e);
                 * }
                 * finally
                 * {
                 *  var communicateObj = schedulerAdapterClient as ICommunicationObject;
                 *  if (communicateObj != null)
                 *  {
                 *      Utility.SafeCloseCommunicateObject(communicateObj);
                 *  }
                 *
                 * }
                 */
            }
        }