public static HpcPackSessionLauncher CreateHpcPackSessionLauncher(string headNode, bool runningLocal, BrokerNodesManager brokerNodesManager) =>
 new HpcPackSessionLauncher(headNode, runningLocal, brokerNodesManager);
Exemple #2
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);
            }
        }
Exemple #3
0
        public override async Task <SessionInfoContract> GetInfoAsync(string endpointPrefix, string sessionId)
        {
            SessionInfoContract sessionInfo = null;

            this.CheckAccess();

            ParamCheckUtility.ThrowIfNullOrEmpty(endpointPrefix, "endpointPrefix");

            TraceHelper.TraceEvent(
                sessionId,
                TraceEventType.Information,
                "[SessionLauncher] .GetInfo: headnode={0}, endpointPrefix={1}, sessionId={2}",
                Environment.MachineName,
                endpointPrefix,
                sessionId);

            if (!IsEndpointPrefixSupported(endpointPrefix))
            {
                TraceHelper.TraceEvent(sessionId, TraceEventType.Error, "[SessionLauncher] .GetInfo: {0} is not a supported endpoint prefix.", endpointPrefix);

                ThrowHelper.ThrowSessionFault(SOAFaultCode.InvalidArgument, SR.SessionLauncher_EndpointNotSupported, endpointPrefix);
            }

            try
            {
                using (var batchClient = AzureBatchConfiguration.GetBatchClient())
                {
                    var jobId = AzureBatchSessionJobIdConverter.ConvertToAzureBatchJobId(sessionId);

                    var sessionJob = await batchClient.JobOperations.GetJobAsync(jobId).ConfigureAwait(false);

                    if (sessionJob == null)
                    {
                        throw new InvalidOperationException($"[{nameof(AzureBatchSessionLauncher)}] .{nameof(this.GetInfoAsync)} Failed to get batch job for session {sessionId}");
                    }

                    TraceHelper.TraceEvent(
                        sessionId,
                        TraceEventType.Information,
                        $"[{nameof(AzureBatchSessionLauncher)}] .{nameof(this.GetInfoAsync)}: try to get the job properties(Secure, TransportScheme, BrokerEpr, BrokerNode, ControllerEpr, ResponseEpr) for the job, jobid={sessionId}.");

                    sessionInfo    = new SessionInfoContract();
                    sessionInfo.Id = AzureBatchSessionJobIdConverter.ConvertToSessionId(sessionJob.Id);

                    // TODO: sessionInfo.JobState
                    var metadata = sessionJob.Metadata;
                    if (metadata != null)
                    {
                        string brokerNodeString = null;

                        foreach (var pair in metadata)
                        {
                            if (pair.Name.Equals(BrokerSettingsConstants.Secure, StringComparison.OrdinalIgnoreCase))
                            {
                                string secureString = pair.Value;
                                Debug.Assert(secureString != null, "BrokerSettingsConstants.Secure value should be a string.");
                                bool secure;
                                if (bool.TryParse(secureString, out secure))
                                {
                                    sessionInfo.Secure = secure;
                                    TraceHelper.TraceEvent(sessionId, TraceEventType.Information, "[SessionLauncher] .GetInfo: get the job secure property, Secure={0}.", secure);
                                }
                                else
                                {
                                    TraceHelper.TraceEvent(sessionId, TraceEventType.Error, "Illegal secure value[{0}] for job's " + BrokerSettingsConstants.Secure + " property", secureString);
                                }
                            }
                            else if (pair.Name.Equals(BrokerSettingsConstants.TransportScheme, StringComparison.OrdinalIgnoreCase))
                            {
                                string schemeString = pair.Value;
                                Debug.Assert(schemeString != null, "BrokerSettingsConstants.TransportScheme value should be a string.");

                                int scheme;
                                if (int.TryParse(schemeString, out scheme))
                                {
                                    sessionInfo.TransportScheme = (TransportScheme)scheme;
                                    TraceHelper.TraceEvent(
                                        sessionId,
                                        TraceEventType.Information,
                                        "[SessionLauncher] .GetInfo: get the job TransportScheme property, TransportScheme={0}.",
                                        sessionInfo.TransportScheme);
                                }
                                else
                                {
                                    TraceHelper.TraceEvent(
                                        sessionId,
                                        TraceEventType.Error,
                                        "Illegal transport scheme value[{0}] for job's " + BrokerSettingsConstants.TransportScheme + " property",
                                        schemeString);
                                }
                            }
                            else if (pair.Name.Equals(BrokerSettingsConstants.BrokerNode, StringComparison.OrdinalIgnoreCase))
                            {
                                brokerNodeString = pair.Value;
                                Debug.Assert(brokerNodeString != null, "BrokerSettingsConstants.BrokerNode value should be a string.");

                                TraceHelper.TraceEvent(
                                    sessionId,
                                    TraceEventType.Information,
                                    "[SessionLauncher] .GetInfo: get the job BrokerLauncherEpr property, BrokerLauncherEpr={0}.",
                                    sessionInfo.BrokerLauncherEpr);
                            }
                            else if (pair.Name.Equals(BrokerSettingsConstants.Durable, StringComparison.OrdinalIgnoreCase))
                            {
                                string durableString = pair.Value;
                                Debug.Assert(durableString != null, "BrokerSettingsConstants.Durable value should be a string.");

                                bool durable;
                                if (bool.TryParse(durableString, out durable))
                                {
                                    sessionInfo.Durable = durable;
                                    TraceHelper.TraceEvent(sessionId, TraceEventType.Information, "[SessionLauncher] .GetInfo: get the job Durable property, Durable={0}.", sessionInfo.Durable);
                                }
                                else
                                {
                                    TraceHelper.TraceEvent(sessionId, TraceEventType.Error, "Illegal secure value[{0}] for job's " + BrokerSettingsConstants.Durable + " property", durableString);
                                }
                            }
                            else if (pair.Name.Equals(BrokerSettingsConstants.ServiceVersion, StringComparison.OrdinalIgnoreCase))
                            {
                                if (pair.Value != null)
                                {
                                    try
                                    {
                                        sessionInfo.ServiceVersion = new Version(pair.Value);
                                        TraceHelper.TraceEvent(
                                            sessionId,
                                            TraceEventType.Information,
                                            "[SessionLauncher] .GetInfo: get the job ServiceVersion property, ServiceVersion={0}.",
                                            (sessionInfo.ServiceVersion != null) ? sessionInfo.ServiceVersion.ToString() : string.Empty);
                                    }
                                    catch (Exception e)
                                    {
                                        TraceHelper.TraceEvent(
                                            sessionId,
                                            TraceEventType.Error,
                                            "Illegal secure value[{0}] for job's " + BrokerSettingsConstants.ServiceVersion + " property. Exception = {1}",
                                            pair.Value,
                                            e);
                                    }
                                }
                            }
                        }

                        if (!string.IsNullOrEmpty(brokerNodeString))
                        {
                            if (brokerNodeString != Constant.InprocessBrokerNode)
                            {
                                sessionInfo.BrokerLauncherEpr = BrokerNodesManager.GenerateBrokerLauncherEpr(endpointPrefix, brokerNodeString, sessionInfo.TransportScheme);
                            }
                        }
                        else
                        {
                            sessionInfo.UseInprocessBroker = true;
                        }

                        TraceHelper.TraceEvent(
                            sessionId,
                            TraceEventType.Information,
                            "[SessionLauncher] .GetInfo: get the job BrokerLauncherEpr property, BrokerLauncherEpr={0}.",
                            sessionInfo.BrokerLauncherEpr);
                    }
                }
            }
            catch (Exception e)
            {
                TraceHelper.TraceEvent(sessionId, TraceEventType.Error, "[SessionLauncher] .GetInfo: Failed to get all properties from job[{0}], Exception:{1}", sessionId, e);

                ThrowHelper.ThrowSessionFault(SOAFaultCode.GetJobPropertyFailure, SR.SessionLauncher_FailToGetJobProperty, e.ToString());
            }

            if (sessionInfo.SessionOwner == null)
            {
                sessionInfo.SessionOwner = "Everyone";
            }

            if (sessionInfo.SessionACL == null)
            {
                sessionInfo.SessionACL = new string[0];
            }

            if (sessionInfo.JobState == 0)
            {
                // TODO: apply job state converting
                sessionInfo.JobState = JobState.Running;
            }

            TraceHelper.TraceEvent(
                sessionId,
                TraceEventType.Information,
                "[SessionLauncher] .GetInfo: return the sessionInfo, BrokerEpr={0}, BrokerLauncherEpr={1}, ControllerEpr={2}, Id={3}, JobState={4}, ResponseEpr={5}, Secure={6}, TransportScheme={7}, sessionOwner={8}, sessionACL={9}",
                sessionInfo.BrokerEpr,
                sessionInfo.BrokerLauncherEpr,
                sessionInfo.ControllerEpr,
                sessionInfo.Id,
                sessionInfo.JobState,
                sessionInfo.ResponseEpr,
                sessionInfo.Secure,
                sessionInfo.TransportScheme,
                sessionInfo.SessionOwner ?? "null",
                sessionInfo.SessionACL?.Length.ToString() ?? "null");
            return(sessionInfo);
        }
Exemple #4
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;
        }