Пример #1
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);
        }
Пример #2
0
        /// <summary>
        /// Callback when Azure Batch Monitor report jon state
        /// </summary>
        private async void JobMonitor_OnReportJobState(Telepathy.Session.Data.JobState state, List <TaskInfo> stateChangedTaskList, bool shouldExit)
        {
            if (state != this.currentState)
            {
                lock (this.changeJobStateLock)
                {
                    if (state != this.currentState)
                    {
                        this.currentState = state;
                        if (this.context != null)
                        {
                            try
                            {
                                TraceHelper.TraceEvent(this.sessionid, TraceEventType.Information, "[AzureBatchJobMonitorEntry] Job state change event triggered, new state received from AzureBatchJobMonitor: {0}", state);
                                ISchedulerNotify proxy = this.context;
                                proxy.JobStateChanged(state);
                            }
                            catch (System.ObjectDisposedException e)
                            {
                                TraceHelper.TraceEvent(this.sessionid, TraceEventType.Error, "[AzureBatchJobMonitorEntry] Callback channel is disposed: {0}, lose connection to broker.", e);
                                this.context = null;
                            }
                            catch (CommunicationException e)
                            {
                                // Channel is aborted, set the context to null
                                TraceHelper.TraceEvent(this.sessionid, TraceEventType.Error, "[AzureBatchJobMonitorEntry] Callback channel is aborted: {0}", e);
                                this.context = null;
                            }
                            catch (Exception e)
                            {
                                TraceHelper.TraceEvent(this.sessionid, TraceEventType.Error, "[AzureBatchJobMonitorEntry] Failed to trigger job state change event: {0}", e);
                            }
                        }
                    }
                }
            }

            if (stateChangedTaskList != null)
            {
                if (this.context != null)
                {
                    try
                    {
                        ISchedulerNotify proxy = this.context;
                        await proxy.TaskStateChanged(stateChangedTaskList);

                        TraceHelper.TraceEvent(this.sessionid, TraceEventType.Information, "[AzureBatchJobMonitorEntry] Task state change event triggered.");
                    }
                    catch (System.ObjectDisposedException e)
                    {
                        TraceHelper.TraceEvent(this.sessionid, TraceEventType.Error, "[AzureBatchJobMonitorEntry] Callback channel is disposed: {0}, lose connection to broker", e);
                        this.context = null;
                    }
                    catch (CommunicationException e)
                    {
                        // Channel is aborted, set the context to null
                        TraceHelper.TraceEvent(this.sessionid, TraceEventType.Error, "[AzureBatchJobMonitorEntry] Callback channel is aborted: {0}", e);
                        this.context = null;
                    }
                    catch (Exception e)
                    {
                        TraceHelper.TraceEvent(this.sessionid, TraceEventType.Error, "[AzureBatchJobMonitorEntry] Failed to trigger task state change event: {0}", e);
                    }
                }
            }

            if (shouldExit)
            {
                if (this.Exit != null)
                {
                    TraceHelper.TraceEvent(this.sessionid, TraceEventType.Information, "[AzureBatchJobMonitorEntry] Exit AzureBatchJobMonitor Entry");
                    this.Exit(this, EventArgs.Empty);
                }
            }
        }