public void NewBatchTaskParametersGetPassedToRequestTest(string commandline)
        {
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;

            cmdlet.Id    = "testTask";
            cmdlet.JobId = "testJob";
            cmdlet.AffinityInformation = new PSAffinityInformation("affinityValue");
            cmdlet.DisplayName         = "display name";
            cmdlet.Constraints         = new PSTaskConstraints(TimeSpan.FromHours(1), TimeSpan.FromDays(2), 5);
            cmdlet.CommandLine         = commandline;
            cmdlet.EnvironmentSettings = new Dictionary <string, string>();
            cmdlet.EnvironmentSettings.Add("env1", "value1");
            cmdlet.MultiInstanceSettings = new PSMultiInstanceSettings("cmd /c echo coordinating", 3)
            {
                CommonResourceFiles = new List <PSResourceFile>()
                {
                    new PSResourceFile(ResourceFile.FromUrl("https://some.blob", "myFile.txt"))
                }
            };
            cmdlet.ResourceFiles = new PSResourceFile[]
            {
                new PSResourceFile(ResourceFile.FromUrl("anotherFile.txt", "https://another.blob"))
            };

            TaskAddParameter requestParameters = null;

            // Store the request parameters
            RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <
                TaskAddParameter,
                TaskAddOptions,
                AzureOperationHeaderResponse <TaskAddHeaders> >(requestAction: (r) =>
            {
                requestParameters = r.Parameters;
            });

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

            // Verify the request parameters match the cmdlet parameters
            Assert.Equal(cmdlet.AffinityInformation.AffinityId, requestParameters.AffinityInfo.AffinityId);
            Assert.Equal(cmdlet.DisplayName, requestParameters.DisplayName);
            Assert.Equal(cmdlet.Constraints.RetentionTime, requestParameters.Constraints.RetentionTime);
            Assert.Equal(cmdlet.Constraints.MaxTaskRetryCount, requestParameters.Constraints.MaxTaskRetryCount);
            Assert.Equal(cmdlet.Constraints.MaxWallClockTime, requestParameters.Constraints.MaxWallClockTime);
            Assert.Equal(cmdlet.CommandLine, requestParameters.CommandLine);
            Assert.Equal(cmdlet.EnvironmentSettings.Count, requestParameters.EnvironmentSettings.Count);
            Assert.Equal(cmdlet.EnvironmentSettings["env1"], requestParameters.EnvironmentSettings[0].Value);
            Assert.Equal(cmdlet.MultiInstanceSettings.NumberOfInstances, requestParameters.MultiInstanceSettings.NumberOfInstances);
            Assert.Equal(cmdlet.MultiInstanceSettings.CoordinationCommandLine, requestParameters.MultiInstanceSettings.CoordinationCommandLine);
            Assert.Equal(cmdlet.MultiInstanceSettings.CommonResourceFiles.Count, requestParameters.MultiInstanceSettings.CommonResourceFiles.Count);
            Assert.Equal(cmdlet.MultiInstanceSettings.CommonResourceFiles[0].HttpUrl, requestParameters.MultiInstanceSettings.CommonResourceFiles[0].HttpUrl);
            Assert.Equal(cmdlet.MultiInstanceSettings.CommonResourceFiles[0].FilePath, requestParameters.MultiInstanceSettings.CommonResourceFiles[0].FilePath);
            Assert.Equal(cmdlet.ResourceFiles.Length, requestParameters.ResourceFiles.Count);
            Assert.Equal(cmdlet.ResourceFiles.Single().HttpUrl, requestParameters.ResourceFiles.Single().HttpUrl);
        }
Ejemplo n.º 2
0
 internal PSResourceFile(Microsoft.Azure.Batch.ResourceFile omObject)
 {
     if ((omObject == null))
     {
         throw new System.ArgumentNullException("omObject");
     }
     this.omObject = omObject;
 }
Ejemplo n.º 3
0
 internal PSResourceFile(Microsoft.Azure.Batch.ResourceFile omObject)
 {
     if ((omObject == null))
     {
         throw new System.ArgumentNullException("omObject");
     }
     this.omObject = omObject;
 }
Ejemplo n.º 4
0
 public PSResourceFile(string blobSource, string filePath)
 {
     this.omObject = new Microsoft.Azure.Batch.ResourceFile(blobSource, filePath);
 }
Ejemplo n.º 5
0
 public PSResourceFile(string blobSource, string filePath)
 {
     this.omObject = new Microsoft.Azure.Batch.ResourceFile(blobSource, filePath);
 }
Ejemplo n.º 6
0
 public PropertyContainer(Models.CloudTask protocolObject) : base(BindingState.Bound)
 {
     this.AffinityInformationProperty = this.CreatePropertyAccessor(
         UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.AffinityInfo, o => new AffinityInformation(o).Freeze()),
         nameof(AffinityInformation),
         BindingAccess.Read);
     this.ApplicationPackageReferencesProperty = this.CreatePropertyAccessor(
         ApplicationPackageReference.ConvertFromProtocolCollectionAndFreeze(protocolObject.ApplicationPackageReferences),
         nameof(ApplicationPackageReferences),
         BindingAccess.Read);
     this.AuthenticationTokenSettingsProperty = this.CreatePropertyAccessor(
         UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.AuthenticationTokenSettings, o => new AuthenticationTokenSettings(o).Freeze()),
         nameof(AuthenticationTokenSettings),
         BindingAccess.Read);
     this.CommandLineProperty = this.CreatePropertyAccessor(
         protocolObject.CommandLine,
         nameof(CommandLine),
         BindingAccess.Read);
     this.ComputeNodeInformationProperty = this.CreatePropertyAccessor(
         UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.NodeInfo, o => new ComputeNodeInformation(o).Freeze()),
         nameof(ComputeNodeInformation),
         BindingAccess.Read);
     this.ConstraintsProperty = this.CreatePropertyAccessor(
         UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.Constraints, o => new TaskConstraints(o)),
         nameof(Constraints),
         BindingAccess.Read | BindingAccess.Write);
     this.ContainerSettingsProperty = this.CreatePropertyAccessor(
         UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.ContainerSettings, o => new TaskContainerSettings(o).Freeze()),
         nameof(ContainerSettings),
         BindingAccess.Read);
     this.CreationTimeProperty = this.CreatePropertyAccessor(
         protocolObject.CreationTime,
         nameof(CreationTime),
         BindingAccess.Read);
     this.DependsOnProperty = this.CreatePropertyAccessor(
         UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.DependsOn, o => new TaskDependencies(o).Freeze()),
         nameof(DependsOn),
         BindingAccess.Read);
     this.DisplayNameProperty = this.CreatePropertyAccessor(
         protocolObject.DisplayName,
         nameof(DisplayName),
         BindingAccess.Read);
     this.EnvironmentSettingsProperty = this.CreatePropertyAccessor(
         EnvironmentSetting.ConvertFromProtocolCollectionAndFreeze(protocolObject.EnvironmentSettings),
         nameof(EnvironmentSettings),
         BindingAccess.Read);
     this.ETagProperty = this.CreatePropertyAccessor(
         protocolObject.ETag,
         nameof(ETag),
         BindingAccess.Read);
     this.ExecutionInformationProperty = this.CreatePropertyAccessor(
         UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.ExecutionInfo, o => new TaskExecutionInformation(o).Freeze()),
         nameof(ExecutionInformation),
         BindingAccess.Read);
     this.ExitConditionsProperty = this.CreatePropertyAccessor(
         UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.ExitConditions, o => new ExitConditions(o).Freeze()),
         nameof(ExitConditions),
         BindingAccess.Read);
     this.FilesToStageProperty = this.CreatePropertyAccessor <IList <IFileStagingProvider> >(
         nameof(FilesToStage),
         BindingAccess.None);
     this.IdProperty = this.CreatePropertyAccessor(
         protocolObject.Id,
         nameof(Id),
         BindingAccess.Read);
     this.LastModifiedProperty = this.CreatePropertyAccessor(
         protocolObject.LastModified,
         nameof(LastModified),
         BindingAccess.Read);
     this.MultiInstanceSettingsProperty = this.CreatePropertyAccessor(
         UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.MultiInstanceSettings, o => new MultiInstanceSettings(o).Freeze()),
         nameof(MultiInstanceSettings),
         BindingAccess.Read);
     this.OutputFilesProperty = this.CreatePropertyAccessor(
         OutputFile.ConvertFromProtocolCollectionAndFreeze(protocolObject.OutputFiles),
         nameof(OutputFiles),
         BindingAccess.Read);
     this.PreviousStateProperty = this.CreatePropertyAccessor(
         UtilitiesInternal.MapNullableEnum <Models.TaskState, Common.TaskState>(protocolObject.PreviousState),
         nameof(PreviousState),
         BindingAccess.Read);
     this.PreviousStateTransitionTimeProperty = this.CreatePropertyAccessor(
         protocolObject.PreviousStateTransitionTime,
         nameof(PreviousStateTransitionTime),
         BindingAccess.Read);
     this.RequiredSlotsProperty = this.CreatePropertyAccessor(
         protocolObject.RequiredSlots,
         nameof(RequiredSlots),
         BindingAccess.Read);
     this.ResourceFilesProperty = this.CreatePropertyAccessor(
         ResourceFile.ConvertFromProtocolCollectionAndFreeze(protocolObject.ResourceFiles),
         nameof(ResourceFiles),
         BindingAccess.Read);
     this.StateProperty = this.CreatePropertyAccessor(
         UtilitiesInternal.MapNullableEnum <Models.TaskState, Common.TaskState>(protocolObject.State),
         nameof(State),
         BindingAccess.Read);
     this.StateTransitionTimeProperty = this.CreatePropertyAccessor(
         protocolObject.StateTransitionTime,
         nameof(StateTransitionTime),
         BindingAccess.Read);
     this.StatisticsProperty = this.CreatePropertyAccessor(
         UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.Stats, o => new TaskStatistics(o).Freeze()),
         nameof(Statistics),
         BindingAccess.Read);
     this.UrlProperty = this.CreatePropertyAccessor(
         protocolObject.Url,
         nameof(Url),
         BindingAccess.Read);
     this.UserIdentityProperty = this.CreatePropertyAccessor(
         UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.UserIdentity, o => new UserIdentity(o).Freeze()),
         nameof(UserIdentity),
         BindingAccess.Read);
 }
Ejemplo n.º 7
0
 public PropertyContainer(Models.JobManagerTask protocolObject) : base(BindingState.Bound)
 {
     this.AllowLowPriorityNodeProperty = this.CreatePropertyAccessor(
         protocolObject.AllowLowPriorityNode,
         nameof(AllowLowPriorityNode),
         BindingAccess.Read | BindingAccess.Write);
     this.ApplicationPackageReferencesProperty = this.CreatePropertyAccessor(
         ApplicationPackageReference.ConvertFromProtocolCollection(protocolObject.ApplicationPackageReferences),
         nameof(ApplicationPackageReferences),
         BindingAccess.Read | BindingAccess.Write);
     this.AuthenticationTokenSettingsProperty = this.CreatePropertyAccessor(
         UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.AuthenticationTokenSettings, o => new AuthenticationTokenSettings(o)),
         nameof(AuthenticationTokenSettings),
         BindingAccess.Read | BindingAccess.Write);
     this.CommandLineProperty = this.CreatePropertyAccessor(
         protocolObject.CommandLine,
         nameof(CommandLine),
         BindingAccess.Read | BindingAccess.Write);
     this.ConstraintsProperty = this.CreatePropertyAccessor(
         UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.Constraints, o => new TaskConstraints(o)),
         nameof(Constraints),
         BindingAccess.Read | BindingAccess.Write);
     this.ContainerSettingsProperty = this.CreatePropertyAccessor(
         UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.ContainerSettings, o => new TaskContainerSettings(o).Freeze()),
         nameof(ContainerSettings),
         BindingAccess.Read);
     this.DisplayNameProperty = this.CreatePropertyAccessor(
         protocolObject.DisplayName,
         nameof(DisplayName),
         BindingAccess.Read | BindingAccess.Write);
     this.EnvironmentSettingsProperty = this.CreatePropertyAccessor(
         EnvironmentSetting.ConvertFromProtocolCollection(protocolObject.EnvironmentSettings),
         nameof(EnvironmentSettings),
         BindingAccess.Read | BindingAccess.Write);
     this.IdProperty = this.CreatePropertyAccessor(
         protocolObject.Id,
         nameof(Id),
         BindingAccess.Read | BindingAccess.Write);
     this.KillJobOnCompletionProperty = this.CreatePropertyAccessor(
         protocolObject.KillJobOnCompletion,
         nameof(KillJobOnCompletion),
         BindingAccess.Read | BindingAccess.Write);
     this.OutputFilesProperty = this.CreatePropertyAccessor(
         OutputFile.ConvertFromProtocolCollection(protocolObject.OutputFiles),
         nameof(OutputFiles),
         BindingAccess.Read | BindingAccess.Write);
     this.RequiredSlotsProperty = this.CreatePropertyAccessor(
         protocolObject.RequiredSlots,
         nameof(RequiredSlots),
         BindingAccess.Read);
     this.ResourceFilesProperty = this.CreatePropertyAccessor(
         ResourceFile.ConvertFromProtocolCollection(protocolObject.ResourceFiles),
         nameof(ResourceFiles),
         BindingAccess.Read | BindingAccess.Write);
     this.RunExclusiveProperty = this.CreatePropertyAccessor(
         protocolObject.RunExclusive,
         nameof(RunExclusive),
         BindingAccess.Read | BindingAccess.Write);
     this.UserIdentityProperty = this.CreatePropertyAccessor(
         UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.UserIdentity, o => new UserIdentity(o)),
         nameof(UserIdentity),
         BindingAccess.Read | BindingAccess.Write);
 }
        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());

            const string pattern      = @"**\*.txt";
            const string containerUrl = "containerUrl";
            const string path         = "path";
            const OutputFileUploadCondition uploadCondition = OutputFileUploadCondition.TaskCompletion;

            string[]      taskIds = new[] { "simple1", "simple2" };
            PSCloudTask[] tasks   = taskIds.Select(
                id => new PSCloudTask(id, commandLine)
            {
                ResourceFiles = new[]
                {
                    new PSResourceFile(ResourceFile.FromUrl("anotherFile.txt", "https://another.blob"))
                },
                OutputFiles = new[]
                {
                    new PSOutputFile(
                        pattern,
                        new PSOutputFileDestination(new PSOutputFileBlobContainerDestination(containerUrl, path)),
                        new PSOutputFileUploadOptions(uploadCondition))
                },
                ApplicationPackageReferences = new[]
                {
                    new PSApplicationPackageReference
                    {
                        ApplicationId = "1",
                        Version       = "foo"
                    }
                },
                ExitConditions = new PSExitConditions()
                {
                    ExitCodeRanges = new List <PSExitCodeRangeMapping>
                    {
                        new PSExitCodeRangeMapping(
                            5,
                            10,
                            new PSExitOptions
                        {
                            DependencyAction = Azure.Batch.Common.DependencyAction.Block
                        })
                    },
                    ExitCodes = new List <PSExitCodeMapping>
                    {
                        new PSExitCodeMapping(
                            11,
                            new PSExitOptions
                        {
                            DependencyAction = Azure.Batch.Common.DependencyAction.Block
                        })
                    },
                    Default = new PSExitOptions
                    {
                        DependencyAction = Azure.Batch.Common.DependencyAction.Satisfy
                    }
                }
            }).ToArray();

            cmdlet.Tasks = tasks;

            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);
                Assert.NotNull(task.ResourceFiles);
                Assert.NotEmpty(task.ResourceFiles);
                Assert.NotNull(task.OutputFiles);
                Assert.NotEmpty(task.OutputFiles);
                Assert.NotNull(task.ApplicationPackageReferences);
                Assert.NotEmpty(task.ApplicationPackageReferences);

                Assert.NotNull(task.ExitConditions.ExitCodeRanges);
                Assert.NotEmpty(task.ExitConditions.ExitCodeRanges);
                Assert.NotNull(task.ExitConditions.ExitCodes);
                Assert.NotEmpty(task.ExitConditions.ExitCodes);
                Assert.NotNull(task.ExitConditions.DefaultProperty);
            }
        }