Beispiel #1
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.
            }
        }
Beispiel #2
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);
        }
Beispiel #3
0
 public void Dispose()
 {
     if (this.client != null)
     {
         Utility.SafeCloseCommunicateObject(this.client);
         this.client = null;
     }
 }
Beispiel #4
0
        /// <summary>
        /// Fetch service registration path
        /// </summary>
        /// <param name="serviceName">indicating the service name</param>
        /// <param name="serviceVersion">indicating the server version</param>
        /// <returns>returns tha path of the service registration file</returns>
        private async Task <string> FetchServiceRegistrationPath(string serviceName, Version serviceVersion)
        {
            string centralPath = null;

            if (this.isDebugModeEnabled)
            {
                // Fetch central path directly from environment if debug mode is enabled
                centralPath = Environment.GetEnvironmentVariable(Constant.RegistryPathEnv);
            }
            else
            {
                // Fetch central path from session launcher via GetSOAConfiguration on the other hand
                SessionLauncherClient client = new SessionLauncherClient(await Utility.GetSessionLauncherAsync(this.startInfo, this.binding).ConfigureAwait(false), this.binding, this.startInfo.IsAadOrLocalUser);
                try
                {
                    centralPath = await client.GetSOAConfigurationAsync(Constant.RegistryPathEnv).ConfigureAwait(false);
                }
                catch (Exception e)
                {
                    SessionBase.TraceSource.TraceEvent(TraceEventType.Error, 0, "[InprocBrokerAdapter] Failed to get service registration path via session launcher service: {0}", e);
                }
                finally
                {
                    Utility.SafeCloseCommunicateObject(client);
                }
            }

            if (centralPath == null)
            {
                ThrowHelper.ThrowSessionFault(SOAFaultCode.ServiceRegistrationPathEnvironmentMissing, SR.ServiceRegistrationPathEnvironmentMissing);
            }

            // setup the service registery helper
            ServiceRegistrationRepo serviceRegistration = new ServiceRegistrationRepo(centralPath, null);
            string serviceRegistrationPath = serviceRegistration.GetServiceRegistrationPath(serviceName, serviceVersion);

            if (serviceRegistrationPath == null)
            {
                throw new FileNotFoundException("Registration file is not found", serviceName);
            }
            return(serviceRegistrationPath);
        }
Beispiel #5
0
        public GeneralResourceProvider(SessionAttachInfo info, Binding binding)
        {
            this.sessionNode = info.Headnode;
            this.binding     = binding;
            if ((info.TransportScheme & TransportScheme.NetTcp) == TransportScheme.NetTcp)
            {
                this.endpointPrefix = SessionLauncherClient.EndpointPrefix;
            }
            else if ((info.TransportScheme & TransportScheme.Http) == TransportScheme.Http || (info.TransportScheme & TransportScheme.NetHttp) == TransportScheme.NetHttp)
            {
                this.endpointPrefix = SessionLauncherClient.HttpsEndpointPrefix;
            }
            else if ((info.TransportScheme & TransportScheme.Custom) == TransportScheme.Custom)
            {
                this.endpointPrefix = SessionLauncherClient.EndpointPrefix;
            }
            else if ((info.TransportScheme & TransportScheme.AzureStorage) == TransportScheme.AzureStorage)
            {
                this.endpointPrefix = "az.table";
            }

            this.client = new SessionLauncherClient(info, binding);
        }
Beispiel #6
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);
            }
        }
Beispiel #7
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);
                 *  }
                 *
                 * }
                 */
            }
        }