/// <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); }
/// <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); * } * * } */ } }