コード例 #1
0
        /// <summary>
        /// Gets the id of the compute node that the specified task completed on. Returns null if the task isn't complete.
        /// </summary>
        public static string GetTaskComputeNodeId(BatchController controller, BatchAccountContext context, string jobId, string taskId)
        {
            BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient);

            ListTaskOptions options = new ListTaskOptions(context, jobId, null)
            {
                TaskId = taskId
            };
            PSCloudTask task = client.ListTasks(options).First();

            return(task.ComputeNodeInformation == null ? null : task.ComputeNodeInformation.ComputeNodeId);
        }
コード例 #2
0
        public void NewBatchTaskCollectionParametersTest()
        {
            string commandLine = "cmd /c dir /s";

            // Setup cmdlet without the required parameters
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;

            Assert.Throws <ArgumentNullException>(() => cmdlet.ExecuteCmdlet());

            cmdlet.JobId = "job-collection";

            Assert.Throws <ArgumentNullException>(() => cmdlet.ExecuteCmdlet());

            string[]    taskIds   = new[] { "simple1", "simple2" };
            PSCloudTask expected1 = new PSCloudTask(taskIds[0], commandLine);
            PSCloudTask expected2 = new PSCloudTask(taskIds[1], commandLine);

            cmdlet.Tasks = new PSCloudTask[] { expected1, expected2 };

            IList <TaskAddParameter> requestCollection = null;

            Action <BatchRequest <
                        IList <TaskAddParameter>,
                        TaskAddCollectionOptions,
                        AzureOperationResponse <TaskAddCollectionResult, TaskAddCollectionHeaders> > > extractCollection =
                (request) =>
            {
                requestCollection = request.Parameters;
            };

            // Don't go to the service on an Add Task Collection call
            AzureOperationResponse <TaskAddCollectionResult, TaskAddCollectionHeaders> response =
                BatchTestHelpers.CreateTaskCollectionResponse(cmdlet.Tasks);

            RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor(responseToUse: response, requestAction: extractCollection);

            cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>()
            {
                interceptor
            };

            // Verify no exceptions when required parameters are set
            cmdlet.ExecuteCmdlet();

            Assert.Equal(2, requestCollection.Count);
            foreach (var task in requestCollection)
            {
                Assert.Contains(task.Id, taskIds);
            }
        }
コード例 #3
0
        /// <summary>
        /// Syncs the collections on a PSCloudTask with its wrapped OM object
        /// </summary>
        internal static void CloudTaskSyncCollections(PSCloudTask task)
        {
            if (task != null)
            {
                task.omObject.EnvironmentSettings = CreateSyncedDict(
                    task.EnvironmentSettings,
                    ConvertEnvironmentSetting);

                task.omObject.ResourceFiles = CreateSyncedList(task.ResourceFiles, ConvertResourceFile);
                task.omObject.OutputFiles   = CreateSyncedList(task.OutputFiles, ps => ps.omObject);
                task.omObject.ApplicationPackageReferences = CreateSyncedList(task.ApplicationPackageReferences, ps => ps.omObject);
                ExitConditionsSyncCollections(task.ExitConditions);

                MultiInstanceSettingsSyncCollections(task.MultiInstanceSettings);
            }
        }
コード例 #4
0
        /// <summary>
        /// Syncs the collections on a PSCloudTask with its wrapped OM object
        /// </summary>
        internal static void CloudTaskSyncCollections(PSCloudTask task)
        {
            if (task != null)
            {
                task.omObject.EnvironmentSettings = CreateSyncedList(task.EnvironmentSettings,
                                                                     (e) =>
                {
                    EnvironmentSetting envSetting = new EnvironmentSetting(e.Name, e.Value);
                    return(envSetting);
                });

                task.omObject.ResourceFiles = CreateSyncedList(task.ResourceFiles,
                                                               (r) =>
                {
                    ResourceFile resourceFile = new ResourceFile(r.BlobSource, r.FilePath);
                    return(resourceFile);
                });

                MultiInstanceSettingsSyncCollections(task.MultiInstanceSettings);
            }
        }