예제 #1
0
        /// <summary>
        /// Open an existing DataClient with the specified ID, job ID and job secret
        /// </summary>
        /// <param name="hpcContext">The <see cref="IHpcContext"/> instance.</param>
        /// <param name="dataClientId">ID of the DataClient to be opened</param>
        /// <param name="jobId">Job ID</param>
        /// <param name="jobSecret">Job Secret</param>
        /// <returns>DataClient instance that provides read/write access to the specified DataClient</returns>
        internal static DataClient Open(string dataClientId, int jobId, string jobSecret)
        {
            var context = HpcContext.GetOrAdd(EndpointsConnectionString.LoadFromEnvVarsOrWindowsRegistry(), CancellationToken.None, true);

            Utility.ValidateDataClientId(dataClientId);
            DataClientInfo info = OpenBySecretInternal(context, dataClientId, jobId, jobSecret);

            return(new DataClient(context.ResolveSessionLauncherNodeAsync().GetAwaiter().GetResult(), dataClientId, info.PrimaryDataPath, true, TransportScheme.NetTcp, null, null));
        }
예제 #2
0
        public ClusterInfo()
        {
            Contract             = new ClusterInfoContract();
            Contract.ClusterName = HpcContext.Get().GetClusterNameAsync().GetAwaiter().GetResult();
            Guid id = HpcContext.Get().GetClusterIdAsync().GetAwaiter().GetResult();

            Contract.ClusterId       = id == Guid.Empty ? null : id.ToString().ToLowerInvariant();
            Contract.NetworkTopology = HpcContext.Get().Registry.GetValueAsync <string>(HpcConstants.HpcFullKeyName, HpcConstants.NetworkTopology, HpcContext.Get().CancellationToken).GetAwaiter().GetResult();
            Contract.AzureStorageConnectionString = HpcContext.Get().Registry.GetValueAsync <string>(HpcConstants.HpcSecurityRegKey, HpcConstants.AzureStorageConnectionString, HpcContext.Get().CancellationToken).GetAwaiter().GetResult();
            Monitor();
        }
        /// <summary>
        /// Initializes a new instance of the HpcSchedulerAdapterInternalClient class
        /// </summary>
        /// <param name="headNode">indicating the headnode</param>
        public HpcSchedulerAdapterInternalClient(string headNode)
            : base(
                BindingHelper.HardCodedInternalSchedulerDelegationBinding,
                SoaHelper.CreateInternalCertEndpointAddress(
                    new Uri(SoaHelper.GetSchedulerDelegationInternalAddress(headNode)),
                    HpcContext.GetOrAdd(headNode, CancellationToken.None).GetSSLThumbprint().GetAwaiter().GetResult()))
        {
            // use certificate for cluster internal authentication
            string thunbprint = HpcContext.GetOrAdd(headNode, CancellationToken.None).GetSSLThumbprint().GetAwaiter().GetResult();

            this.ClientCredentials.UseInternalAuthentication(thunbprint);
            this.InnerChannel.OperationTimeout = OperationTimeout;
        }
예제 #4
0
        /// <summary>
        /// This method closes the session async with the given ID
        /// </summary>
        /// <param name="headNode">Headnode name</param>
        /// <param name="sessionId">The ID of the session to be closed</param>
        /// <param name="binding">indicting the binding</param>
        /// <param name="isAadUser">If the session is belong to a AAD user</param>
        /// <param name="token">The cancellation token.</param>
        public static async Task CloseSessionAsync(string headNode, int sessionId, Binding binding, bool isAadUser, CancellationToken token)
        {
            Utility.ThrowIfEmpty(headNode, "headNode");

            SessionLauncherClient client = null;
            BrokerLauncherClient  broker = null;

            string headNodeMachine = await HpcContext.GetOrAdd(headNode, token).ResolveSessionLauncherNodeAsync().ConfigureAwait(false);

            try
            {
                client = new SessionLauncherClient(headNodeMachine, binding, isAadUser);
                client.InnerChannel.OperationTimeout = GetTimeout(DateTime.MaxValue);
                //TODO: need to change the endpoint prefix for https
                SessionInfo info = null;
                if (binding is NetTcpBinding)
                {
                    info = Utility.BuildSessionInfoFromDataContract(await client.GetInfoV5Async(SessionLauncherClient.EndpointPrefix, sessionId).ConfigureAwait(false));
                }
#if !net40
                else if (binding is BasicHttpBinding || binding is NetHttpBinding || binding is NetHttpsBinding)
                {
                    info = Utility.BuildSessionInfoFromDataContract(await client.GetInfoV5Async(SessionLauncherClient.HttpsEndpointPrefix, sessionId).ConfigureAwait(false));
                }
#endif
                broker = new BrokerLauncherClient(info, binding, new Uri(info.BrokerLauncherEpr));
                broker.InnerChannel.OperationTimeout = GetTimeout(DateTime.MaxValue);
                broker.Close(sessionId);
            }
            catch (FaultException <SessionFault> e)
            {
                throw Utility.TranslateFaultException(e);
            }
            finally
            {
                if (client != null)
                {
                    Utility.SafeCloseCommunicateObject(client);
                }

                if (broker != null)
                {
                    Utility.SafeCloseCommunicateObject(broker);
                }
            }
        }
예제 #5
0
        private void Monitor()
        {
            HpcContext.Get().Registry.MonitorRegistryKeyAsync <string>(
                HpcConstants.HpcFullKeyName,
                HpcConstants.NetworkTopology,
                TimeSpan.FromSeconds(30),
                (o, e) => {
                if (e.ValueChangeType == RegistryValueChangedArgs <string> .ChangeType.Created || e.ValueChangeType == RegistryValueChangedArgs <string> .ChangeType.Modified)
                {
                    this.Contract.NetworkTopology = e.NewValue;
                    TraceHelper.TraceEvent(TraceEventType.Information, "[SessionLauncher] ClusterInfo Registry NetworkTopology is created or updated: {0}", e.NewValue);
                }
            },
                HpcContext.Get().CancellationToken);

            HpcContext.Get().Registry.MonitorRegistryKeyAsync <string>(
                HpcConstants.HpcSecurityRegKey,
                HpcConstants.AzureStorageConnectionString,
                TimeSpan.FromSeconds(30),
                (o, e) => {
                if (e.ValueChangeType == RegistryValueChangedArgs <string> .ChangeType.Created || e.ValueChangeType == RegistryValueChangedArgs <string> .ChangeType.Modified)
                {
                    this.Contract.AzureStorageConnectionString = e.NewValue;
                    TraceHelper.TraceEvent(TraceEventType.Information, "[SessionLauncher] ClusterInfo Registry AzureStorageConnectionString is created or updated: ***");
                    OnAzureStorageConnectionStringOrClusterIdUpdated?.Invoke(o, e);
                }
            },
                HpcContext.Get().CancellationToken);

            HpcContext.Get().Registry.MonitorRegistryKeyAsync <Guid>(
                HpcConstants.HpcFullKeyName,
                HpcConstants.ClusterIdRegVal,
                TimeSpan.FromSeconds(30),
                (o, e) => {
                if (e.ValueChangeType == RegistryValueChangedArgs <Guid> .ChangeType.Created || e.ValueChangeType == RegistryValueChangedArgs <Guid> .ChangeType.Modified)
                {
                    this.Contract.ClusterId = e.NewValue.ToString().ToLowerInvariant();
                    TraceHelper.TraceEvent(TraceEventType.Information, "[SessionLauncher] ClusterInfo Registry ClusterId is created or updated: {0}", e.NewValue);
                    OnAzureStorageConnectionStringOrClusterIdUpdated?.Invoke(o, e);
                }
            },
                HpcContext.Get().CancellationToken);
        }
예제 #6
0
        /// <summary>
        /// This method will only be internally called by session launcher,
        /// before the job is submitted. It combines the user's job properties and the
        /// items set in the service start info. The job properties will override the start info items.
        /// </summary>
        /// <param name="startInfo">the session start info</param>
        /// <param name="schedulerJob">service job</param>
        /// <param name="traceLevel">diag trace level</param>
        internal static void MakeJobProperties(SessionStartInfoContract startInfo, ISchedulerJob schedulerJob, string traceLevel)
        {
            Debug.Assert(startInfo != null,
                         "The session startInfo cannot be null.");

            Debug.Assert(!string.IsNullOrEmpty(startInfo.ServiceName),
                         "The service name in the session start info cannnot be null or empty.");

            schedulerJob.ServiceName = startInfo.ServiceName;
            schedulerJob.SetEnvironmentVariable("CCP_SERVICENAME", startInfo.ServiceName);
            if (startInfo.CanPreempt.HasValue)
            {
                schedulerJob.CanPreempt = startInfo.CanPreempt.Value;
            }

            if (!string.IsNullOrEmpty(startInfo.JobTemplate))
            {
                schedulerJob.SetJobTemplate(startInfo.JobTemplate);
            }

            if (startInfo.Priority.HasValue)
            {
                schedulerJob.Priority = (JobPriority)startInfo.Priority.Value;
            }

            if (startInfo.ExtendedPriority.HasValue)
            {
                schedulerJob.ExpandedPriority = startInfo.ExtendedPriority.Value;
            }

            schedulerJob.Progress = 0;

            // For max units
            if (startInfo.MaxUnits != null)
            {
                schedulerJob.MaximumNumberOfCores         =
                    schedulerJob.MaximumNumberOfSockets   =
                        schedulerJob.MaximumNumberOfNodes = startInfo.MaxUnits.Value;

                schedulerJob.AutoCalculateMax = false;
            }

            // For min units
            if (startInfo.MinUnits != null)
            {
                schedulerJob.MinimumNumberOfCores         =
                    schedulerJob.MinimumNumberOfSockets   =
                        schedulerJob.MinimumNumberOfNodes = startInfo.MinUnits.Value;

                schedulerJob.AutoCalculateMin = false;
            }

            // Should set UnitType after above resource count update
            if (startInfo.ResourceUnitType != null)
            {
                schedulerJob.UnitType = (JobUnitType)startInfo.ResourceUnitType.Value;
            }

            schedulerJob.Name = string.IsNullOrEmpty(startInfo.ServiceJobName) ?
                                string.Format("{0} - WCF service", startInfo.ServiceName) :
                                startInfo.ServiceJobName;

            if (!string.IsNullOrEmpty(startInfo.ServiceJobProject))
            {
                schedulerJob.Project = startInfo.ServiceJobProject;
            }

            if (!string.IsNullOrEmpty(startInfo.NodeGroupsStr))
            {
                string[] nodes = startInfo.NodeGroupsStr.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string node in nodes)
                {
                    schedulerJob.NodeGroups.Add(node);
                }
            }

            if (!string.IsNullOrEmpty(startInfo.RequestedNodesStr))
            {
                schedulerJob.RequestedNodes = new StringCollection(startInfo.RequestedNodesStr.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries));
            }

            if (startInfo.Runtime >= 0)
            {
                schedulerJob.Runtime = startInfo.Runtime;
            }

            // start adding the broker settings.
            schedulerJob.SetCustomProperty(BrokerSettingsConstants.ShareSession, startInfo.ShareSession.ToString());
            schedulerJob.SetCustomProperty(BrokerSettingsConstants.UseAad, startInfo.UseAad.ToString());
            schedulerJob.SetCustomProperty(BrokerSettingsConstants.Secure, startInfo.Secure.ToString());
            schedulerJob.SetCustomProperty(BrokerSettingsConstants.TransportScheme, ((int)startInfo.TransportScheme).ToString());
            schedulerJob.SetCustomProperty(BrokerSettingsConstants.UseAzureQueue, (startInfo.UseAzureQueue == true).ToString());
            schedulerJob.SetCustomProperty(BrokerSettingsConstants.LocalUser, (startInfo.LocalUser == true).ToString());

            var context   = HpcContext.Get();
            var principal = Thread.CurrentPrincipal;

            if (principal.IsHpcAadPrincipal(context))
            {
                string identity = principal.GenerateSecurityIdentifierFromAadPrincipal(context).Value + ";" + principal.Identity.Name;
                schedulerJob.SetCustomProperty(BrokerSettingsConstants.AadUserIdentity, identity);
            }

            // Save ServiceVersion if set
            if (startInfo.ServiceVersion != null)
            {
                schedulerJob.SetCustomProperty(BrokerSettingsConstants.ServiceVersion, startInfo.ServiceVersion.ToString());
            }

            string[] customPropNames = new string[]
            {
                BrokerSettingsConstants.AllocationGrowLoadRatioThreshold,
                BrokerSettingsConstants.AllocationShrinkLoadRatioThreshold,
                BrokerSettingsConstants.ClientIdleTimeout,
                BrokerSettingsConstants.SessionIdleTimeout,
                BrokerSettingsConstants.MessagesThrottleStartThreshold,
                BrokerSettingsConstants.MessagesThrottleStopThreshold,
                BrokerSettingsConstants.ClientConnectionTimeout,
                BrokerSettingsConstants.ServiceConfigMaxMessageSize,
                BrokerSettingsConstants.ServiceConfigOperationTimeout,
                BrokerSettingsConstants.DispatcherCapacityInGrowShrink
            };

            int?[] intNullableValues = new int?[]
            {
                startInfo.AllocationGrowLoadRatioThreshold,
                startInfo.AllocationShrinkLoadRatioThreshold,
                startInfo.ClientIdleTimeout,
                startInfo.SessionIdleTimeout,
                startInfo.MessagesThrottleStartThreshold,
                startInfo.MessagesThrottleStopThreshold,
                startInfo.ClientConnectionTimeout,
                startInfo.MaxMessageSize,
                startInfo.ServiceOperationTimeout,
                startInfo.DispatcherCapacityInGrowShrink
            };

            Debug.Assert(intNullableValues.Length == customPropNames.Length);

            for (int i = 0; i < customPropNames.Length; i++)
            {
                if (intNullableValues[i].HasValue)
                {
                    schedulerJob.SetCustomProperty(customPropNames[i], intNullableValues[i].Value.ToString());
                }
            }

            // add soa diag settings
            schedulerJob.SetCustomProperty(BrokerSettingsConstants.SoaDiagTraceLevel, traceLevel);
            schedulerJob.SetCustomProperty(BrokerSettingsConstants.SoaDiagTraceCleanup, Boolean.FalseString);
        }