Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the LauncherHostService class
        /// This will be called when run in debug mode
        /// </summary>
        /// <param name="launcherChoose">launcher choose</param>
        //internal LauncherHostService(bool console)
        //{
        //    InitializeComponent();

        //    this.OpenService();
        //}

        public void StopService(bool isNtService = false)
        {
            try
            {
                // DataService instance is created by session launcher. To make sure data service exit gracefully, close DataService before closing session launcher.
                if (this.dataServiceHost != null)
                {
                    this.dataServiceHost.Faulted -= DataServiceHostFaultHandler;
                    this.dataServiceHost.Close();
                    this.dataServiceHost = null;

                    TraceHelper.TraceEvent(TraceEventType.Verbose, "SOA data service endpoint closed");
                }

                if (this.launcherHost != null)
                {
                    this.launcherHost.Close();
                }
                this.launcherHost = null;
                TraceHelper.TraceEvent(TraceEventType.Verbose, "Session launcher endpoint closed");

                this.delegationHost?.Close();
                this.delegationHost = null;
                TraceHelper.TraceEvent(TraceEventType.Verbose, "Scheduler delegation service closed");

#if HPCPACK
                // session launcher host has been closed, remember to close the data service instance
                if (this.dataService != null)
                {
                    this.dataService.Close();
                    this.dataService = null;
                    TraceHelper.TraceEvent(TraceEventType.Verbose, "Data service instance closed");
                }
#endif

                if (!isNtService)
                {
                    // only need to get cleaned in SF serivce
                    if (this.schedulerDelegation is IDisposable disposable)
                    {
                        disposable.Dispose();
                        TraceHelper.TraceEvent(TraceEventType.Verbose, "Scheduler delegation closed");
                    }
                    this.schedulerDelegation = null;

                    if (this.sessionLauncher != null)
                    {
                        this.sessionLauncher.Close();
                        TraceHelper.TraceEvent(TraceEventType.Verbose, "Session launcher closed");
                    }
                    this.sessionLauncher = null;

                    TraceHelper.IsDiagTraceEnabled = null;
                    SoaDiagTraceHelper.IsDiagTraceEnabledInternal = null;

                    if (this.brokerNodesManager is IDisposable d)
                    {
                        d.Dispose();
                    }
                    this.brokerNodesManager = null;
                }
            }
            catch (Exception e)
            {
                TraceHelper.TraceEvent(TraceEventType.Error, "Failed to close the service host - {0}", e);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Open the session launcher service
        /// </summary>
        public async Task OpenService()
        {
            try
            {
                // If running on Azure, monitor HAController service and terminate this service
                //  if HAController dies. Note that SCM service dependency monitoring does not provide
                //  this
                if (SoaHelper.IsOnAzure())
                {
                    ServiceControllerHelpers.MonitorHAControllerStopAsync(HpcServiceNames.HpcSession);
                    TraceHelper.TraceEvent(TraceEventType.Information, "Azure HAController service monitoring enabled");
                }

                if (SessionLauncherRuntimeConfiguration.SchedulerType == SchedulerType.HpcPack)
                {
#if HPCPACK
                    this.brokerNodesManager  = new BrokerNodesManager();
                    this.sessionLauncher     = SessionLauncherFactory.CreateHpcPackSessionLauncher(SoaHelper.GetSchedulerName(), false, this.brokerNodesManager);
                    this.schedulerDelegation = new HpcSchedulerDelegation(this.sessionLauncher, this.brokerNodesManager);
#endif
                }
                else if (SessionLauncherRuntimeConfiguration.SchedulerType == SchedulerType.AzureBatch)
                {
                    var instance = SessionLauncherFactory.CreateAzureBatchSessionLauncher();
                    this.sessionLauncher     = instance;
                    this.schedulerDelegation = new AzureBatchSchedulerDelegation(instance);
                }
                else if (SessionLauncherRuntimeConfiguration.SchedulerType == SchedulerType.Local)
                {
                    var instance = SessionLauncherFactory.CreateLocalSessionLauncher();
                    this.sessionLauncher     = instance;
                    this.schedulerDelegation = new LocalSchedulerDelegation(instance);
                }

                TraceHelper.IsDiagTraceEnabled = _ => true;
#if HPCPACK
                // Bug 18448: Need to enable traces only for those who have enabled trace
                if (this.schedulerDelegation is IHpcSchedulerAdapterInternal hpcAdapterInternal)
                {
                    SoaDiagTraceHelper.IsDiagTraceEnabledInternal = hpcAdapterInternal.IsDiagTraceEnabled;
                    TraceHelper.IsDiagTraceEnabled = SoaDiagTraceHelper.IsDiagTraceEnabled;
                }
#endif

                // start session launcher service
                this.StartSessionLauncherService();

                if (SessionLauncherRuntimeConfiguration.SchedulerType == SchedulerType.HpcPack ||
                    SessionLauncherRuntimeConfiguration.SchedulerType == SchedulerType.Local ||
                    SessionLauncherRuntimeConfiguration.SchedulerType == SchedulerType.AzureBatch)
                {
                    // start scheduler delegation service
                    this.StartSchedulerDelegationService();
                }

#if HPCPACK
                // start data service
                if (!SoaHelper.IsOnAzure() && this.sessionLauncher is HpcPackSessionLauncher hpcSessionLauncher)
                {
                    this.dataService = hpcSessionLauncher.GetDataService();
                    this.StartDataWcfService();
                    this.StartDataRestService(this.dataService);
                }
#endif
            }
            catch (Exception e)
            {
                TraceHelper.TraceEvent(TraceEventType.Critical, "Failed to open the service host - {0}", e);
                throw;
            }

            await Task.CompletedTask;
        }