Ejemplo n.º 1
0
        /// <summary>
        /// Runs the reducer task.
        /// </summary>
        public async Task RunAsync()
        {
            //Set up the Batch Service credentials used to authenticate with the Batch Service.
            BatchCredentials credentials = new BatchCredentials(
                this.configurationSettings.BatchAccountName,
                this.configurationSettings.BatchAccountKey);

            using (IBatchClient batchClient = BatchClient.Connect(this.configurationSettings.BatchServiceUrl, credentials))
            {
                using (IWorkItemManager workItemManager = batchClient.OpenWorkItemManager())
                {
                    //Gather each Mapper tasks output and write it to standard out.
                    for (int i = 0; i < this.configurationSettings.NumberOfMapperTasks; i++)
                    {
                        string mapperTaskName = Helpers.GetMapperTaskName(i);

                        //Download the standard out from each mapper task.
                        ITaskFile taskFile = await workItemManager.GetTaskFileAsync(
                            this.workItemName,
                            this.jobName,
                            mapperTaskName,
                            Microsoft.Azure.Batch.Constants.StandardOutFileName);

                        string taskFileString = await taskFile.ReadAsStringAsync();

                        Console.WriteLine(taskFileString);

                        Console.WriteLine();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Downloads a Task file using the specified options.
        /// </summary>
        /// <param name="options">The download options</param>
        public void DownloadTaskFile(DownloadTaskFileOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            if ((string.IsNullOrWhiteSpace(options.WorkItemName) || string.IsNullOrWhiteSpace(options.JobName) || string.IsNullOrWhiteSpace(options.TaskName) ||
                 string.IsNullOrWhiteSpace(options.TaskFileName)) && options.TaskFile == null)
            {
                throw new ArgumentNullException(Resources.GBTFC_NoTaskFileSpecified);
            }

            ITaskFile taskFile = null;

            if (options.TaskFile == null)
            {
                using (IWorkItemManager wiManager = options.Context.BatchOMClient.OpenWorkItemManager())
                {
                    taskFile = wiManager.GetTaskFile(options.WorkItemName, options.JobName, options.TaskName, options.TaskFileName, options.AdditionalBehaviors);
                }
            }
            else
            {
                taskFile = options.TaskFile.omObject;
            }

            string path = null;
            // The task file object's name is a relative path that includes directories.
            string fileName = Path.GetFileName(taskFile.Name);

            if (string.IsNullOrWhiteSpace(options.DestinationPath))
            {
                // If no destination is specified, just save the file to the local directory
                path = fileName;
            }
            else
            {
                path = Path.Combine(options.DestinationPath, fileName);
            }

            WriteVerbose(string.Format(Resources.GBTFC_Downloading, taskFile.Name, path));
            if (options.Stream != null)
            {
                // Used for testing.
                // Don't dispose supplied Stream
                taskFile.CopyToStream(options.Stream, options.AdditionalBehaviors);
            }
            else
            {
                using (FileStream fs = new FileStream(path, FileMode.Create))
                {
                    taskFile.CopyToStream(fs, options.AdditionalBehaviors);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Lists the Task files matching the specified filter options
        /// </summary>
        /// <param name="options">The options to use when querying for Task files</param>
        /// <returns>The Task files matching the specified filter options</returns>
        public IEnumerable <PSTaskFile> ListTaskFiles(ListTaskFileOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            if ((string.IsNullOrWhiteSpace(options.WorkItemName) || string.IsNullOrWhiteSpace(options.JobName) || string.IsNullOrWhiteSpace(options.TaskName)) &&
                options.Task == null)
            {
                throw new ArgumentNullException(Resources.GBTF_NoTaskSpecified);
            }

            // Get the single Task file matching the specified name
            if (!string.IsNullOrEmpty(options.TaskFileName))
            {
                WriteVerbose(string.Format(Resources.GBTF_GetByName, options.TaskFileName, options.TaskName));
                using (IWorkItemManager wiManager = options.Context.BatchOMClient.OpenWorkItemManager())
                {
                    ITaskFile  taskFile   = wiManager.GetTaskFile(options.WorkItemName, options.JobName, options.TaskName, options.TaskFileName, options.AdditionalBehaviors);
                    PSTaskFile psTaskFile = new PSTaskFile(taskFile);
                    return(new PSTaskFile[] { psTaskFile });
                }
            }
            // List Task files using the specified filter
            else
            {
                string           tName = options.Task == null ? options.TaskName : options.Task.Name;
                ODATADetailLevel odata = null;
                if (!string.IsNullOrEmpty(options.Filter))
                {
                    WriteVerbose(string.Format(Resources.GBTF_GetByOData, tName));
                    odata = new ODATADetailLevel(filterClause: options.Filter);
                }
                else
                {
                    WriteVerbose(string.Format(Resources.GBTF_NoFilter, tName));
                }

                IEnumerableAsyncExtended <ITaskFile> taskFiles = null;
                if (options.Task != null)
                {
                    taskFiles = options.Task.omObject.ListTaskFiles(options.Recursive, odata, options.AdditionalBehaviors);
                }
                else
                {
                    using (IWorkItemManager wiManager = options.Context.BatchOMClient.OpenWorkItemManager())
                    {
                        taskFiles = wiManager.ListTaskFiles(options.WorkItemName, options.JobName, options.TaskName, options.Recursive, odata, options.AdditionalBehaviors);
                    }
                }
                Func <ITaskFile, PSTaskFile> mappingFunction = f => { return(new PSTaskFile(f)); };
                return(PSAsyncEnumerable <PSTaskFile, ITaskFile> .CreateWithMaxCount(
                           taskFiles, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount))));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Lists the vm files matching the specified filter options
        /// </summary>
        /// <param name="options">The options to use when querying for vm files</param>
        /// <returns>The vm files matching the specified filter options</returns>
        public IEnumerable <PSVMFile> ListVMFiles(ListVMFileOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            // Get the single vm file matching the specified name
            if (!string.IsNullOrEmpty(options.VMFileName))
            {
                WriteVerbose(string.Format(Resources.GBVMF_GetByName, options.VMFileName, options.VMName));
                using (IPoolManager poolManager = options.Context.BatchOMClient.OpenPoolManager())
                {
                    ITaskFile vmFile   = poolManager.GetVMFile(options.PoolName, options.VMName, options.VMFileName, options.AdditionalBehaviors);
                    PSVMFile  psVMFile = new PSVMFile(vmFile);
                    return(new PSVMFile[] { psVMFile });
                }
            }
            // List vm files using the specified filter
            else
            {
                string           vmName           = options.VM == null ? options.VMName : options.VM.Name;
                ODATADetailLevel odata            = null;
                string           verboseLogString = null;
                if (!string.IsNullOrEmpty(options.Filter))
                {
                    verboseLogString = string.Format(Resources.GBVMF_GetByOData, vmName);
                    odata            = new ODATADetailLevel(filterClause: options.Filter);
                }
                else
                {
                    verboseLogString = string.Format(Resources.GBVMF_NoFilter, vmName);
                }
                WriteVerbose(verboseLogString);

                IEnumerableAsyncExtended <ITaskFile> vmFiles = null;
                if (options.VM != null)
                {
                    vmFiles = options.VM.omObject.ListVMFiles(options.Recursive, odata, options.AdditionalBehaviors);
                }
                else
                {
                    using (IPoolManager poolManager = options.Context.BatchOMClient.OpenPoolManager())
                    {
                        vmFiles = poolManager.ListVMFiles(options.PoolName, options.VMName, options.Recursive, odata, options.AdditionalBehaviors);
                    }
                }
                Func <ITaskFile, PSVMFile> mappingFunction = f => { return(new PSVMFile(f)); };
                return(PSAsyncEnumerable <PSVMFile, ITaskFile> .CreateWithMaxCount(
                           vmFiles, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount))));
            }
        }
Ejemplo n.º 5
0
 // Downloads the file represented by an ITaskFile instance to the specified path
 private void DownloadITaskFile(ITaskFile file, string destinationPath, string loggingFileType, Stream stream = null, IEnumerable <BatchClientBehavior> additionalBehaviors = null)
 {
     if (stream != null)
     {
         // Don't dispose supplied Stream
         file.CopyToStream(stream, additionalBehaviors);
     }
     else
     {
         WriteVerbose(string.Format(Resources.Downloading, loggingFileType, file.Name, destinationPath));
         using (FileStream fs = new FileStream(destinationPath, FileMode.Create))
         {
             file.CopyToStream(fs, additionalBehaviors);
         }
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Downloads a task file using the specified options.
        /// </summary>
        /// <param name="options">The download options</param>
        public void DownloadTaskFile(DownloadTaskFileOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            ITaskFile taskFile = null;

            if (options.TaskFile == null)
            {
                using (IWorkItemManager wiManager = options.Context.BatchOMClient.OpenWorkItemManager())
                {
                    taskFile = wiManager.GetTaskFile(options.WorkItemName, options.JobName, options.TaskName, options.TaskFileName, options.AdditionalBehaviors);
                }
            }
            else
            {
                taskFile = options.TaskFile.omObject;
            }

            DownloadITaskFile(taskFile, options.DestinationPath, "task", options.Stream, options.AdditionalBehaviors);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Downloads a vm file using the specified options.
        /// </summary>
        /// <param name="options">The download options</param>
        public void DownloadVMFile(DownloadVMFileOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            ITaskFile vmFile = null;

            if (options.VMFile == null)
            {
                using (IPoolManager poolManager = options.Context.BatchOMClient.OpenPoolManager())
                {
                    vmFile = poolManager.GetVMFile(options.PoolName, options.VMName, options.VMFileName, options.AdditionalBehaviors);
                }
            }
            else
            {
                vmFile = options.VMFile.omObject;
            }

            DownloadITaskFile(vmFile, options.DestinationPath, "vm", options.Stream, options.AdditionalBehaviors);
        }
Ejemplo n.º 8
0
 public AddTaskCommandHandler(ITaskFile taskFile)
 {
     _taskFile = taskFile;
 }
Ejemplo n.º 9
0
 public DeleteTaskCommandHandler(ITaskFile taskFile, ITaskConfiguration config)
 {
     _taskFile = taskFile;
     _config   = config;
 }
Ejemplo n.º 10
0
 public DeprioritizeCommandHandler(ITaskFile taskFile, ITaskConfiguration config)
 {
     _taskFile = taskFile;
     _config   = config;
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Downloads the contents of the specific file on the VM.
        /// </summary>
        /// <param name="filePath">The path to the file.</param>
        /// <param name="destinationStream">The destination stream.</param>
        /// <returns></returns>
        private async System.Threading.Tasks.Task DownloadVMFile(string filePath, Stream destinationStream)
        {
            ITaskFile file = await this.VM.GetVMFileAsync(filePath);

            await file.CopyToStreamAsync(destinationStream);
        }
Ejemplo n.º 12
0
 public TaskQueryHandler(ITaskFile taskFile, ITaskConfiguration config)
 {
     _taskFile = taskFile;
     _config   = config;
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Checks for a tasks success or failure, and optionally dumps the output of the task.  In the case that the task hit a scheduler or execution error,
        /// dumps that information as well.
        /// </summary>
        /// <param name="boundTask">The task.</param>
        /// <param name="dumpStandardOutOnTaskSuccess">True to log the standard output file of the task even if it succeeded.  False to not log anything if the task succeeded.</param>
        public static async Task CheckForTaskSuccessAsync(ICloudTask boundTask, bool dumpStandardOutOnTaskSuccess)
        {
            if (boundTask.State == TaskState.Completed)
            {
                //Check to see if the task has execution information metadata.
                if (boundTask.ExecutionInformation != null)
                {
                    //Dump the task scheduling error if there was one.
                    if (boundTask.ExecutionInformation.SchedulingError != null)
                    {
                        TaskSchedulingError schedulingError = boundTask.ExecutionInformation.SchedulingError;
                        Console.WriteLine("Task {0} hit scheduling error.", boundTask.Name);
                        Console.WriteLine("SchedulingError Code: {0}", schedulingError.Code);
                        Console.WriteLine("SchedulingError Message: {0}", schedulingError.Message);
                        Console.WriteLine("SchedulingError Category: {0}", schedulingError.Category);
                        Console.WriteLine("SchedulingError Details:");

                        foreach (NameValuePair detail in schedulingError.Details)
                        {
                            Console.WriteLine("{0} : {1}", detail.Name, detail.Value);
                        }

                        throw new TextSearchException(string.Format("Task {0} failed with a scheduling error", boundTask.Name));
                    }

                    //Read the content of the output files if the task exited.
                    if (boundTask.ExecutionInformation.ExitCode.HasValue)
                    {
                        Console.WriteLine("Task {0} exit code: {1}", boundTask.Name, boundTask.ExecutionInformation.ExitCode);

                        if (dumpStandardOutOnTaskSuccess && boundTask.ExecutionInformation.ExitCode.Value == 0 || boundTask.ExecutionInformation.ExitCode.Value != 0)
                        {
                            //Dump the standard out file of the task.
                            ITaskFile taskStandardOut = await boundTask.GetTaskFileAsync(
                                Microsoft.Azure.Batch.Constants.StandardOutFileName);

                            Console.WriteLine("Task {0} StdOut:", boundTask.Name);
                            Console.WriteLine("----------------------------------------");
                            string stdOutString = await taskStandardOut.ReadAsStringAsync();

                            Console.WriteLine(stdOutString);
                        }

                        //Check for nonzero exit code and dump standard error if there was a nonzero exit code.
                        if (boundTask.ExecutionInformation.ExitCode.Value != 0)
                        {
                            ITaskFile taskErrorFile = await boundTask.GetTaskFileAsync(
                                Microsoft.Azure.Batch.Constants.StandardErrorFileName);

                            Console.WriteLine("Task {0} StdErr:", boundTask.Name);
                            Console.WriteLine("----------------------------------------");
                            string stdErrString = await taskErrorFile.ReadAsStringAsync();

                            Console.WriteLine(stdErrString);

                            throw new TextSearchException(string.Format("Task {0} failed with a nonzero exit code", boundTask.Name));
                        }
                    }
                }
                else
                {
                    throw new TextSearchException(string.Format("Task {0} is not completed yet.  Current state: {1}", boundTask.Name, boundTask.State));
                }
            }
        }
Ejemplo n.º 14
0
 public AddPriorityCommandHandler(ITaskFile taskFile, ITaskConfiguration config)
 {
     _taskFile = taskFile;
     _config   = config;
 }
Ejemplo n.º 15
0
 public ArchiveTasksCommandHandler(ITaskFile taskFile, ITaskConfiguration config)
 {
     _taskFile = taskFile;
     _config   = config;
 }
Ejemplo n.º 16
0
 // Downloads the file represented by an ITaskFile instance to the specified path
 private void DownloadITaskFile(ITaskFile file, string destinationPath, string loggingFileType, Stream stream = null, IEnumerable<BatchClientBehavior> additionalBehaviors = null)
 {
     if (stream != null)
     {
         // Don't dispose supplied Stream
         file.CopyToStream(stream, additionalBehaviors);
     }
     else
     {
         WriteVerbose(string.Format(Resources.Downloading, loggingFileType, file.Name, destinationPath));
         using (FileStream fs = new FileStream(destinationPath, FileMode.Create))
         {
             file.CopyToStream(fs, additionalBehaviors);
         }
     }
 }