Beispiel #1
0
        /// <summary>
        /// Creates a pool with a start task which installs ImageMagick onto each VM.
        /// </summary>
        private static void CreatePool()
        {
            using (IPoolManager pm = config.Client.OpenPoolManager())
            {
                Console.WriteLine("Creating pool: {0}", config.PoolName);
                //Create a pool -- note that OSFamily 3 is Windows Server 2012.  You can learn more about os families and versions at:
                //http://msdn.microsoft.com/en-us/library/azure/ee924680.aspx
                ICloudPool pool = pm.CreatePool(config.PoolName, targetDedicated: 3, vmSize: "small", osFamily: "3");

                //Create a start task for the pool (which installs ImageMagick).  The start task is run on each
                //VM when they first join the pool.  In this case it is used as a setup step to place the ImageMagick exe onto the VM.
                IStartTask startTask = new StartTask();
                startTask.RunElevated = true;
                startTask.CommandLine = ImageMagickCmdLine;

                //Set up the resource files for the start task (requires the image magick exe)
                List <IResourceFile> resFiles = new List <IResourceFile>();

                ResourceFile file = new ResourceFile(config.ImageMagickExeSAS, "ImageMagick.exe");
                resFiles.Add(file);

                startTask.ResourceFiles  = resFiles;
                startTask.WaitForSuccess = true;

                pool.StartTask = startTask;
                pool.Commit(); //Commit the pool -- this actually creates it on the Batch service.
            }
        }
        /// <summary>
        /// Creates a pool.
        /// </summary>
        /// <param name="poolName"></param>
        /// <param name="vmSize"></param>
        /// <param name="targetDedicated"></param>
        /// <param name="autoScaleFormula"></param>
        /// <param name="communicationEnabled"></param>
        /// <param name="osFamily"></param>
        /// <param name="osVersion"></param>
        /// <param name="maxTasksPerVM"></param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        public async Task CreatePoolAsync(
            string poolName,
            string vmSize,
            int?targetDedicated,
            string autoScaleFormula,
            bool communicationEnabled,
            string osFamily,
            string osVersion,
            int maxTasksPerVM,
            TimeSpan?timeout)
        {
            using (IPoolManager poolManager = this.Client.OpenPoolManager())
            {
                ICloudPool unboundPool = poolManager.CreatePool(
                    poolName,
                    osFamily: osFamily,
                    vmSize: vmSize,
                    targetDedicated: targetDedicated);

                unboundPool.TargetOSVersion = osVersion;
                unboundPool.Communication   = communicationEnabled;
                unboundPool.ResizeTimeout   = timeout;
                unboundPool.MaxTasksPerVM   = maxTasksPerVM;

                if (!string.IsNullOrEmpty(autoScaleFormula))
                {
                    unboundPool.AutoScaleEnabled = true;
                    unboundPool.AutoScaleFormula = autoScaleFormula;
                }

                await unboundPool.CommitAsync();
            }
        }
        /// <summary>
        /// Create a pool model from the pool cache entity
        /// </summary>
        public PoolModel(ICloudPool pool)
        {
            this.Pool            = pool;
            this.LastUpdatedTime = DateTime.UtcNow;
            this.Tvms            = new List <TvmModel>();

            this.TvmCollection = CollectionViewSource.GetDefaultView(this.Tvms);
            this.UpdateTvmView();
        }
        /// <summary>
        /// Builds a PSCloudPool for testing
        /// </summary>
        public static PSCloudPool CreatePSCloudPool()
        {
            BatchAccountContext context = CreateBatchContextWithKeys();

            using (IPoolManager poolManager = context.BatchOMClient.OpenPoolManager())
            {
                ICloudPool pool = poolManager.CreatePool("testPool");
                return(new PSCloudPool(pool));
            }
        }
Beispiel #5
0
 /// <summary>
 /// Creates a test Pool for use in Scenario tests.
 /// TODO: Replace with new Pool client method when it exists.
 /// </summary>
 public static void CreateTestPool(BatchAccountContext context, string poolName)
 {
     if (HttpMockServer.Mode == HttpRecorderMode.Record)
     {
         using (IPoolManager poolManager = context.BatchOMClient.OpenPoolManager())
         {
             ICloudPool pool = poolManager.CreatePool(poolName, "4", "small", 3);
             pool.Commit();
         }
     }
 }
        /// <summary>
        /// Lists the pools matching the specified filter options
        /// </summary>
        /// <param name="options">The options to use when querying for pools</param>
        /// <returns>The pools matching the specified filter options</returns>
        public IEnumerable <PSCloudPool> ListPools(ListPoolOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            // Get the single pool matching the specified name
            if (!string.IsNullOrWhiteSpace(options.PoolName))
            {
                WriteVerbose(string.Format(Resources.GBP_GetByName, options.PoolName));
                using (IPoolManager poolManager = options.Context.BatchOMClient.OpenPoolManager())
                {
                    ICloudPool  pool   = poolManager.GetPool(options.PoolName, additionalBehaviors: options.AdditionalBehaviors);
                    PSCloudPool psPool = new PSCloudPool(pool);
                    return(new PSCloudPool[] { psPool });
                }
            }
            // List pools using the specified filter
            else
            {
                ODATADetailLevel odata            = null;
                string           verboseLogString = null;
                if (!string.IsNullOrEmpty(options.Filter))
                {
                    verboseLogString = Resources.GBP_GetByOData;
                    odata            = new ODATADetailLevel(filterClause: options.Filter);
                }
                else
                {
                    verboseLogString = Resources.GBP_NoFilter;
                }
                WriteVerbose(verboseLogString);

                using (IPoolManager poolManager = options.Context.BatchOMClient.OpenPoolManager())
                {
                    IEnumerableAsyncExtended <ICloudPool> pools           = poolManager.ListPools(odata, options.AdditionalBehaviors);
                    Func <ICloudPool, PSCloudPool>        mappingFunction = p => { return(new PSCloudPool(p)); };
                    return(PSAsyncEnumerable <PSCloudPool, ICloudPool> .CreateWithMaxCount(
                               pools, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount))));
                }
            }
        }
        private static void CreatePoolIfNotExist(IBatchClient client, string poolName)
        {
            // All Pool and VM operation starts from PoolManager
            using (IPoolManager pm = client.OpenPoolManager())
            {
                // go through all the pools and see if it already exists
                bool found = false;
                foreach (ICloudPool p in pm.ListPools())
                {
                    // pools are uniquely identified by their name
                    if (string.Equals(p.Name, poolName))
                    {
                        Console.WriteLine("Using existing pool {0}", poolName);
                        found = true;

                        if (!p.ListVMs().Any <IVM>())
                        {
                            Console.WriteLine("There are no VMs in this pool. No tasks will be run until at least one VM has been added via resizing.");
                            Console.WriteLine("Resizing pool to add 3 VMs. This might take a while...");
                            p.Resize(3);
                        }

                        break;
                    }
                }

                if (!found)
                {
                    Console.WriteLine("Creating pool: {0}", poolName);
                    // if pool not found, call CreatePool
                    //You can learn more about os families and versions at:
                    //http://msdn.microsoft.com/en-us/library/azure/ee924680.aspx
                    ICloudPool pool = pm.CreatePool(poolName, targetDedicated: 3, vmSize: "small", osFamily: "3");
                    pool.Commit();
                }
            }
        }
 public HeatMapModel(ICloudPool pool)
 {
     this.Pool = pool;
     this.vms  = new List <IVM>();
 }
Beispiel #9
0
        /// <summary>
        /// Creates a new Pool
        /// </summary>
        /// <param name="parameters">The parameters to use when creating the Pool</param>
        public void CreatePool(NewPoolParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            if (string.IsNullOrWhiteSpace(parameters.PoolName))
            {
                throw new ArgumentNullException("PoolName");
            }

            using (IPoolManager poolManager = parameters.Context.BatchOMClient.OpenPoolManager())
            {
                ICloudPool pool = poolManager.CreatePool(poolName: parameters.PoolName, osFamily: parameters.OSFamily);
                pool.ResizeTimeout = parameters.ResizeTimeout;
                pool.MaxTasksPerVM = parameters.MaxTasksPerVM;
                pool.Communication = parameters.Communication;

                if (!string.IsNullOrEmpty(parameters.VMSize))
                {
                    // Don't override OM default if unspecified
                    pool.VMSize = parameters.VMSize;
                }

                if (!string.IsNullOrEmpty(parameters.AutoScaleFormula))
                {
                    pool.AutoScaleEnabled = true;
                    pool.AutoScaleFormula = parameters.AutoScaleFormula;
                    // Clear OM default to avoid server errors
                    pool.TargetDedicated = null;
                }
                else if (parameters.TargetDedicated.HasValue)
                {
                    // Don't override OM default if unspecified
                    pool.TargetDedicated = parameters.TargetDedicated;
                }

                if (parameters.SchedulingPolicy != null)
                {
                    pool.SchedulingPolicy = parameters.SchedulingPolicy.omObject;
                }

                if (parameters.StartTask != null)
                {
                    Utils.Utils.StartTaskSyncCollections(parameters.StartTask);
                    pool.StartTask = parameters.StartTask.omObject;
                }

                if (parameters.Metadata != null)
                {
                    pool.Metadata = new List <IMetadataItem>();
                    foreach (DictionaryEntry m in parameters.Metadata)
                    {
                        pool.Metadata.Add(new MetadataItem(m.Key.ToString(), m.Value.ToString()));
                    }
                }

                if (parameters.CertificateReferences != null)
                {
                    pool.CertificateReferences = new List <ICertificateReference>();
                    foreach (PSCertificateReference c in parameters.CertificateReferences)
                    {
                        pool.CertificateReferences.Add(c.omObject);
                    }
                }

                WriteVerbose(string.Format(Resources.NBP_CreatingPool, parameters.PoolName));
                pool.Commit(parameters.AdditionalBehaviors);
            }
        }
Beispiel #10
0
 public ShowHeatMapMessage(ICloudPool pool)
 {
     this.Pool = pool;
 }
Beispiel #11
0
        public static void JobMain(string[] args)
        {
            //Load the configuration
            TopNWordsConfiguration configuration = TopNWordsConfiguration.LoadConfigurationFromAppConfig();

            StagingStorageAccount stagingStorageAccount = new StagingStorageAccount(
                configuration.StorageAccountName,
                configuration.StorageAccountKey,
                configuration.StorageAccountBlobEndpoint);

            IBatchClient client           = BatchClient.Connect(configuration.BatchServiceUrl, new BatchCredentials(configuration.BatchAccountName, configuration.BatchAccountKey));
            string       stagingContainer = null;

            //Create a pool (if user hasn't provided one)
            if (configuration.ShouldCreatePool)
            {
                using (IPoolManager pm = client.OpenPoolManager())
                {
                    //OSFamily 4 == OS 2012 R2
                    //You can learn more about os families and versions at:
                    //http://msdn.microsoft.com/en-us/library/azure/ee924680.aspx
                    ICloudPool pool = pm.CreatePool(configuration.PoolName, targetDedicated: configuration.PoolSize, osFamily: "4", vmSize: "small");
                    Console.WriteLine("Adding pool {0}", configuration.PoolName);
                    pool.Commit();
                }
            }

            try
            {
                using (IWorkItemManager wm = client.OpenWorkItemManager())
                {
                    IToolbox toolbox = client.OpenToolbox();

                    //Use the TaskSubmissionHelper to help us create a WorkItem and add tasks to it.
                    ITaskSubmissionHelper taskSubmissionHelper = toolbox.CreateTaskSubmissionHelper(wm, configuration.PoolName);
                    taskSubmissionHelper.WorkItemName = configuration.WorkItemName;

                    FileToStage topNWordExe = new FileToStage(TopNWordsExeName, stagingStorageAccount);
                    FileToStage storageDll  = new FileToStage(StorageClientDllName, stagingStorageAccount);

                    string bookFileUri = UploadBookFileToCloudBlob(configuration, configuration.BookFileName);
                    Console.WriteLine("{0} uploaded to cloud", configuration.BookFileName);

                    for (int i = 1; i <= configuration.NumberOfTasks; i++)
                    {
                        ICloudTask task = new CloudTask("task_no_" + i, String.Format("{0} --Task {1} {2} {3} {4}",
                                                                                      TopNWordsExeName,
                                                                                      bookFileUri,
                                                                                      configuration.NumberOfTopWords,
                                                                                      configuration.StorageAccountName,
                                                                                      configuration.StorageAccountKey));

                        //This is the list of files to stage to a container -- for each TaskSubmissionHelper one container is created and
                        //files all resolve to Azure Blobs by their name (so two tasks with the same named file will create just 1 blob in
                        //the TaskSubmissionHelper's container).
                        task.FilesToStage = new List <IFileStagingProvider>
                        {
                            topNWordExe,
                            storageDll
                        };

                        taskSubmissionHelper.AddTask(task);
                    }

                    //Commit all the tasks to the Batch Service.
                    IJobCommitUnboundArtifacts artifacts = taskSubmissionHelper.Commit() as IJobCommitUnboundArtifacts;

                    foreach (var fileStagingArtifact in artifacts.FileStagingArtifacts)
                    {
                        SequentialFileStagingArtifact stagingArtifact = fileStagingArtifact.Value as SequentialFileStagingArtifact;
                        if (stagingArtifact != null)
                        {
                            stagingContainer = stagingArtifact.BlobContainerCreated;
                            Console.WriteLine("Uploaded files to container: {0} -- you will be charged for their storage unless you delete them.",
                                              stagingArtifact.BlobContainerCreated);
                        }
                    }

                    //Get the job to monitor status.
                    ICloudJob job = wm.GetJob(artifacts.WorkItemName, artifacts.JobName);

                    Console.Write("Waiting for tasks to complete ...");
                    // Wait 1 minute for all tasks to reach the completed state
                    client.OpenToolbox().CreateTaskStateMonitor().WaitAll(job.ListTasks(), TaskState.Completed, TimeSpan.FromMinutes(20));
                    Console.WriteLine("Done.");

                    foreach (ICloudTask task in job.ListTasks())
                    {
                        Console.WriteLine("Task " + task.Name + " says:\n" + task.GetTaskFile(Constants.StandardOutFileName).ReadAsString());
                        Console.WriteLine(task.GetTaskFile(Constants.StandardErrorFileName).ReadAsString());
                    }
                }
            }
            finally
            {
                //Delete the pool that we created
                if (configuration.ShouldCreatePool)
                {
                    using (IPoolManager pm = client.OpenPoolManager())
                    {
                        Console.WriteLine("Deleting pool: {0}", configuration.PoolName);
                        pm.DeletePool(configuration.PoolName);
                    }
                }

                //Delete the workitem that we created
                if (configuration.ShouldDeleteWorkItem)
                {
                    using (IWorkItemManager wm = client.OpenWorkItemManager())
                    {
                        Console.WriteLine("Deleting work item: {0}", configuration.WorkItemName);
                        wm.DeleteWorkItem(configuration.WorkItemName);
                    }
                }

                //Delete the containers we created
                if (configuration.ShouldDeleteContainer)
                {
                    DeleteContainers(configuration, stagingContainer);
                }
            }
        }
 public ShowHeatMapMessage(ICloudPool pool)
 {
     this.Pool = pool;
 }