/// <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)); }
/// <summary> /// cleanup the stale session data. /// </summary> /// <param name="state">the state object.</param> private async void CleanStaleSessionData(object state) { TraceHelper.TraceEvent(TraceEventType.Verbose, "[BrokerManager] CleanStaleSessionData: begin."); try { await BrokerEntry.CleanupStaleSessionData( async delegate(string jobId) { return(await this.schedulerHelper.IsJobPurged(jobId)); }, (await this.schedulerHelper.GetClusterInfoAsync()).AzureStorageConnectionString); } catch (Exception e) { TraceHelper.TraceEvent(TraceEventType.Error, "[BrokerManager] Failed to cleanup stale session data: {0}", e.ToString()); } TraceHelper.TraceEvent(TraceEventType.Verbose, "[BrokerManager] CleanStaleSessionData: end."); }