/// <summary>
        /// Start the monitor
        /// </summary>
        public async Task StartAsync()
        {
            TraceHelper.TraceEvent(this.sessionid, TraceEventType.Information, "[AzureBatchJobMonitor] Start Azure Batch job monitor.");
            this.cloudJob = await this.batchClient.JobOperations.GetJobAsync(AzureBatchSessionJobIdConverter.ConvertToAzureBatchJobId(this.sessionid));

            // Do we need this?
            if (this.cloudJob.State == JobState.Disabled)
            {
                ThrowHelper.ThrowSessionFault(SOAFaultCode.Session_ValidateJobFailed_JobCanceled, SR.SessionLauncher_ValidateJobFailed_JobCanceled, this.sessionid.ToString());
            }

            try
            {
                await Task.Run(async() => await this.QueryJobChangeAsync());
            }
            catch (Exception e)
            {
                TraceHelper.TraceEvent(this.sessionid, TraceEventType.Warning, "[AzureBatchJobMonitor] Exception thrown when trigger querying job info task: {0}", e);
            }
        }
        public async Task <bool> UpdateBrokerInfoAsync(string sessionId, Dictionary <string, object> properties)
        {
            try
            {
                using (var batchClient = AzureBatchConfiguration.GetBatchClient())
                {
                    TraceHelper.TraceEvent(sessionId, TraceEventType.Information, "[AzureBatchSchedulerDelegation] UpdateBrokerInfo...");
                    StringBuilder sb = new System.Text.StringBuilder();
                    foreach (KeyValuePair <string, object> property in properties)
                    {
                        sb.AppendLine($"Property = {property.Key}\tValue = {property.Value}");
                    }

                    TraceHelper.TraceEvent(sessionId, TraceEventType.Verbose, "[AzureBatchSchedulerDelegation] Properties detail:\n{0}", sb.ToString());

                    var sessionJob = await batchClient.JobOperations.GetJobAsync(AzureBatchSessionJobIdConverter.ConvertToAzureBatchJobId(sessionId)).ConfigureAwait(false);

                    await this.UpdateSoaRelatedPropertiesAsync(sessionJob, properties).ConfigureAwait(false);
                }

                return(true);
            }
            catch (BatchException ex)
            {
                if (ex.RequestInformation != null && ex.RequestInformation.HttpStatusCode != null)
                {
                    if (ex.RequestInformation.HttpStatusCode == HttpStatusCode.NotFound)
                    {
                        TraceHelper.TraceEvent(sessionId, TraceEventType.Warning, "[AzureBatchSchedulerDelegation] Can't update job properties because it can't be found in AzureBatch.");
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                TraceHelper.TraceEvent(TraceEventType.Error, ex.ToString());
            }

            return(false);
        }
Example #3
0
        /// <summary>
        /// Start the monitor
        /// </summary>
        public async Task <CloudJob> StartAsync(System.ServiceModel.OperationContext context)
        {
            TraceHelper.TraceEvent(this.sessionid, TraceEventType.Information, "[AzureBatchJobMonitorEntry] Start monitor Entry.");
            this.currentState = Telepathy.Session.Data.JobState.Queued;
            this.context      = context.GetCallbackChannel <ISchedulerNotify>();
            this.cloudJob     = await this.batchClient.JobOperations.GetJobAsync(AzureBatchSessionJobIdConverter.ConvertToAzureBatchJobId(this.sessionid));

            if (this.cloudJob.State == JobState.Disabled)
            {
                ThrowHelper.ThrowSessionFault(SOAFaultCode.Session_ValidateJobFailed_JobCanceled, SR.SessionLauncher_ValidateJobFailed_JobCanceled, this.sessionid.ToString());
            }

            if (this.cloudJob.Metadata != null)
            {
                MetadataItem maxUnitsItem = this.cloudJob.Metadata.FirstOrDefault(item => item.Name == "MaxUnits");
                if (maxUnitsItem != null)
                {
                    if (Int32.TryParse(maxUnitsItem.Value, out int result))
                    {
                        this.maxUnits = result;
                    }
                }
            }

            // monitor batch job state
            this.batchJobMonitor = new AzureBatchJobMonitor(this.sessionid, this.JobMonitor_OnReportJobState);
            try
            {
                Task.Run(() => this.StartMonitorAsync());
            }
            catch (Exception e)
            {
                TraceHelper.TraceEvent(this.sessionid, TraceEventType.Warning, "[AzureBatchJobMonitorEntry] Exception thrown when start Azure Batch Job Monitor: {0}", e);
            }

            return(this.cloudJob);
        }