public void CreateAndUpdateCommitmentPlan() { const string TagKey = "tag1"; const string TagValue = "value1"; this.RunAMLCommitmentPlanTestScenario((commitmentPlanName, resourceGroupName, resourcesClient, amlPlansClient) => { try { // Create and validate the AML commitment plan resource CommitmentPlan inputCommitmentPlan = new CommitmentPlan(CommitmentPlanTests.DefaultLocation, sku: new ResourceSku(1, CommitmentPlanTests.TestSkuName, CommitmentPlanTests.TestSkuTier)); CommitmentPlan outputCommitmentPlan = amlPlansClient.CommitmentPlans.CreateOrUpdateWithHttpMessagesAsync(inputCommitmentPlan, resourceGroupName, commitmentPlanName).Result.Body; CommitmentPlanTests.ValidateCommitmentPlanResource(amlPlansClient.SubscriptionId, resourceGroupName, commitmentPlanName, outputCommitmentPlan); // Update the commitment plan outputCommitmentPlan.Tags[TagKey] = TagValue; outputCommitmentPlan = amlPlansClient.CommitmentPlans.CreateOrUpdateWithHttpMessagesAsync(outputCommitmentPlan, resourceGroupName, commitmentPlanName).Result.Body; // Validate the change Assert.Equal(1, outputCommitmentPlan.Tags.Count); Assert.Equal(TagValue, outputCommitmentPlan.Tags[TagKey]); } finally { // Remove the commitment plan BaseScenarioTests.DisposeOfTestResource(() => amlPlansClient.CommitmentPlans.RemoveWithHttpMessagesAsync(resourceGroupName, commitmentPlanName)); } }); }
protected override void RunCmdlet() { // If this is a simple get commitment plan by name operation, resolve it as such if (!string.IsNullOrWhiteSpace(this.ResourceGroupName) && !string.IsNullOrWhiteSpace(this.Name)) { CommitmentPlan commitmentPlan = this.CommitmentPlansClient.GetAzureMlCommitmentPlan(this.ResourceGroupName, this.Name); this.WriteObject(commitmentPlan); } else { IPage <CommitmentPlan> commitmentPlans; if (!string.IsNullOrWhiteSpace(this.ResourceGroupName)) { commitmentPlans = this.CommitmentPlansClient.ListAzureMlCommitmentPlansInResourceGroupAsync( this.ResourceGroupName, null, this.CancellationToken).Result; } else { commitmentPlans = this.CommitmentPlansClient.ListAzureMlCommitmentPlansAsync( null, this.CancellationToken).Result; } foreach (var commitmentPlan in commitmentPlans) { this.WriteObject(commitmentPlan, true); } } }
public CommitmentPlan CreateOrUpdateAzureMlCommitmentPlan( string resourceGroupName, string location, string commitmentPlanName, ResourceSku commitmentPlanSku) { CommitmentPlan commitmentPlan = new CommitmentPlan { Location = location, Sku = commitmentPlanSku }; return(this.apiClient.CommitmentPlans.CreateOrUpdate( commitmentPlan, resourceGroupName, commitmentPlanName)); }
public CommitmentPlan CreateOrUpdateAzureMlCommitmentPlan( string resourceGroupName, string location, string commitmentPlanName, ResourceSku commitmentPlanSku) { CommitmentPlan commitmentPlan = new CommitmentPlan { Location = location, Sku = commitmentPlanSku }; return this.apiClient.CommitmentPlans.CreateOrUpdate( commitmentPlan, resourceGroupName, commitmentPlanName); }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); RunCmdLet(() => { var commitmentPlan = new CommitmentPlan() { Properties = Properties }; var createAccountResponse = CognitiveServicesClient.CommitmentPlans.CreateOrUpdate( ResourceGroupName, AccountName, Name, commitmentPlan); WriteObject(createAccountResponse); }); }
protected override void RunCmdlet() { this.ConfirmAction( this.Force.IsPresent, Resources.NewServiceWarning.FormatInvariant(this.Name), "Creating the new commitment plan", this.Name, () => { int skuCapacity = this.SkuCapacity == 0 ? 1 : this.SkuCapacity; ResourceSku sku = new ResourceSku(skuCapacity, this.SkuName, this.SkuTier); CommitmentPlan newCommitmentPlan = this.CommitmentPlansClient.CreateOrUpdateAzureMlCommitmentPlan( this.ResourceGroupName, this.Location, this.Name, sku); this.WriteObject(newCommitmentPlan); }); }
public void CreateGetRemoveCommitmentPlan() { this.RunAMLCommitmentPlanTestScenario((commitmentPlanName, resourceGroupName, resourcesClient, amlPlansClient) => { bool planWasRemoved = false; try { //Validate expected NO-OP behavior on deleting a nonexistent plan amlPlansClient.CommitmentPlans.RemoveWithHttpMessagesAsync(resourceGroupName, commitmentPlanName); // Create and validate the AML commitment plan resource CommitmentPlan inputCommitmentPlan = new CommitmentPlan(CommitmentPlanTests.DefaultLocation, sku: new ResourceSku(1, CommitmentPlanTests.TestSkuName, CommitmentPlanTests.TestSkuTier)); CommitmentPlan outputCommitmentPlan = amlPlansClient.CommitmentPlans.CreateOrUpdateWithHttpMessagesAsync(inputCommitmentPlan, resourceGroupName, commitmentPlanName).Result.Body; CommitmentPlanTests.ValidateCommitmentPlanResource(amlPlansClient.SubscriptionId, resourceGroupName, commitmentPlanName, outputCommitmentPlan); // Retrieve the AML commitment plan after creation var retrievedPlan = amlPlansClient.CommitmentPlans.Get(resourceGroupName, commitmentPlanName); CommitmentPlanTests.ValidateCommitmentPlanResource(amlPlansClient.SubscriptionId, resourceGroupName, commitmentPlanName, retrievedPlan); // Remove the commitment plan amlPlansClient.CommitmentPlans.RemoveWithHttpMessagesAsync(resourceGroupName, commitmentPlanName).Wait(); planWasRemoved = true; //Validate that the expected not found exception is thrown after deletion when trying to access the commitment plan var expectedCloudException = Assert.Throws <CloudException>(() => amlPlansClient.CommitmentPlans.Get(resourceGroupName, commitmentPlanName)); Assert.NotNull(expectedCloudException.Body); Assert.Equal("ResourceNotFound", expectedCloudException.Body.Code); } finally { // Remove the commitment plan if (!planWasRemoved) { BaseScenarioTests.DisposeOfTestResource(() => amlPlansClient.CommitmentPlans.RemoveWithHttpMessagesAsync(resourceGroupName, commitmentPlanName)); } } }); }
/// <summary> /// Creates a new Azure ML commitment plan resource or updates an existing one. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='createOrUpdatePayload'> /// The payload to create or update the Azure ML commitment plan. /// </param> /// <param name='resourceGroupName'> /// The resource group name. /// </param> /// <param name='commitmentPlanName'> /// The Azure ML commitment plan name. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async System.Threading.Tasks.Task <CommitmentPlan> CreateOrUpdateAsync(this ICommitmentPlansOperations operations, CommitmentPlan createOrUpdatePayload, string resourceGroupName, string commitmentPlanName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(createOrUpdatePayload, resourceGroupName, commitmentPlanName, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Creates a new Azure ML commitment plan resource or updates an existing one. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='createOrUpdatePayload'> /// The payload to create or update the Azure ML commitment plan. /// </param> /// <param name='resourceGroupName'> /// The resource group name. /// </param> /// <param name='commitmentPlanName'> /// The Azure ML commitment plan name. /// </param> public static CommitmentPlan CreateOrUpdate(this ICommitmentPlansOperations operations, CommitmentPlan createOrUpdatePayload, string resourceGroupName, string commitmentPlanName) { return(System.Threading.Tasks.Task.Factory.StartNew(s => ((ICommitmentPlansOperations)s).CreateOrUpdateAsync(createOrUpdatePayload, resourceGroupName, commitmentPlanName), operations, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskCreationOptions.None, System.Threading.Tasks.TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
private static void ValidateCommitmentPlanResource(string subscriptionId, string resourceGroupName, string commitmentPlanName, CommitmentPlan commitmentPlan) { // Validate basic ARM resource fields Assert.NotNull(commitmentPlan); string expectedResourceId = string.Format(CultureInfo.InvariantCulture, CommitmentPlanTests.ResourceIdFormat, subscriptionId, resourceGroupName, commitmentPlanName); Assert.Equal(expectedResourceId, commitmentPlan.Id); Assert.Equal(CommitmentPlanTests.DefaultLocation, commitmentPlan.Location); Assert.Equal("Microsoft.MachineLearning/commitmentPlans", commitmentPlan.Type); Assert.NotNull(commitmentPlan.Sku); Assert.Equal(CommitmentPlanTests.TestSkuName, commitmentPlan.Sku.Name); Assert.Equal(CommitmentPlanTests.TestSkuTier, commitmentPlan.Sku.Tier); // Validate specific AML commitment plan properties Assert.NotNull(commitmentPlan.Properties); Assert.NotEmpty(commitmentPlan.Properties.IncludedQuantities); Assert.NotNull(commitmentPlan.Properties.MaxAssociationLimit); Assert.True(commitmentPlan.Properties.MaxAssociationLimit.Value.CompareTo(1) > 0); Assert.NotNull(commitmentPlan.Properties.MaxCapacityLimit); Assert.True(commitmentPlan.Properties.MaxCapacityLimit.Value.CompareTo(1) > 0); Assert.NotNull(commitmentPlan.Properties.MinCapacityLimit); Assert.True(commitmentPlan.Properties.MinCapacityLimit.Value.CompareTo(1) == 0); }
public void CreateAndListCommitmentPlans() { this.RunAMLCommitmentPlanTestScenario((commitmentPlanName, resourceGroupName, resourcesClient, amlPlansClient) => { string plan1Name = TestUtilities.GenerateName(CommitmentPlanTests.TestPlanNamePrefix); string plan2Name = TestUtilities.GenerateName(CommitmentPlanTests.TestPlanNamePrefix); string plan3Name = TestUtilities.GenerateName(CommitmentPlanTests.TestPlanNamePrefix); string resourceGroup1Name = TestUtilities.GenerateName(CommitmentPlanTests.TestResourceGroupNamePrefix); string resourceGroup2Name = TestUtilities.GenerateName(CommitmentPlanTests.TestResourceGroupNamePrefix); try { ResourceSku sku = new ResourceSku(1, CommitmentPlanTests.TestSkuName, CommitmentPlanTests.TestSkuTier); CommitmentPlan inputCommitmentPlan = new CommitmentPlan(CommitmentPlanTests.DefaultLocation, sku: sku); // Create two commitment plans in the first resource group resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroup1Name, new ResourceGroup { Location = CommitmentPlanTests.DefaultLocation }); CommitmentPlan outputCommitmentPlan1 = amlPlansClient.CommitmentPlans.CreateOrUpdateWithHttpMessagesAsync(inputCommitmentPlan, resourceGroup1Name, plan1Name).Result.Body; CommitmentPlanTests.ValidateCommitmentPlanResource(amlPlansClient.SubscriptionId, resourceGroup1Name, plan1Name, outputCommitmentPlan1); CommitmentPlan outputCommitmentPlan2 = amlPlansClient.CommitmentPlans.CreateOrUpdateWithHttpMessagesAsync(inputCommitmentPlan, resourceGroup1Name, plan2Name).Result.Body; CommitmentPlanTests.ValidateCommitmentPlanResource(amlPlansClient.SubscriptionId, resourceGroup1Name, plan2Name, outputCommitmentPlan2); // Create one commitment plan in the second resource group resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroup2Name, new ResourceGroup { Location = CommitmentPlanTests.DefaultLocation }); CommitmentPlan outputCommitmentPlan3 = amlPlansClient.CommitmentPlans.CreateOrUpdateWithHttpMessagesAsync(inputCommitmentPlan, resourceGroup2Name, plan3Name).Result.Body; CommitmentPlanTests.ValidateCommitmentPlanResource(amlPlansClient.SubscriptionId, resourceGroup2Name, plan3Name, outputCommitmentPlan3); // Get plans from first resource group and validate var plansInGroup1 = amlPlansClient.CommitmentPlans.ListInResourceGroup(resourceGroup1Name); Assert.NotNull(plansInGroup1); Assert.Equal(2, plansInGroup1.Count()); string expectedResourceId1 = string.Format(CultureInfo.InvariantCulture, CommitmentPlanTests.ResourceIdFormat, amlPlansClient.SubscriptionId, resourceGroup1Name, plan1Name); Assert.Contains(plansInGroup1, plan => string.Equals(plan.Id, expectedResourceId1, StringComparison.OrdinalIgnoreCase)); string expectedResourceId2 = string.Format(CultureInfo.InvariantCulture, CommitmentPlanTests.ResourceIdFormat, amlPlansClient.SubscriptionId, resourceGroup1Name, plan2Name); Assert.Contains(plansInGroup1, plan => string.Equals(plan.Id, expectedResourceId2, StringComparison.OrdinalIgnoreCase)); // Get plans from second resource group and validate var plansInGroup2 = amlPlansClient.CommitmentPlans.ListInResourceGroup(resourceGroup2Name); Assert.NotNull(plansInGroup2); Assert.Single(plansInGroup2); string expectedResourceId3 = string.Format(CultureInfo.InvariantCulture, CommitmentPlanTests.ResourceIdFormat, amlPlansClient.SubscriptionId, resourceGroup2Name, plan3Name); Assert.Contains(plansInGroup2, plan => string.Equals(plan.Id, expectedResourceId3, StringComparison.OrdinalIgnoreCase)); } finally { // Delete plans and resource groups BaseScenarioTests.DisposeOfTestResource(() => amlPlansClient.CommitmentPlans.RemoveWithHttpMessagesAsync(resourceGroup1Name, plan1Name)); BaseScenarioTests.DisposeOfTestResource(() => amlPlansClient.CommitmentPlans.RemoveWithHttpMessagesAsync(resourceGroup1Name, plan2Name)); BaseScenarioTests.DisposeOfTestResource(() => resourcesClient.ResourceGroups.Delete(resourceGroup1Name)); BaseScenarioTests.DisposeOfTestResource(() => amlPlansClient.CommitmentPlans.RemoveWithHttpMessagesAsync(resourceGroup2Name, plan3Name)); BaseScenarioTests.DisposeOfTestResource(() => resourcesClient.ResourceGroups.Delete(resourceGroup2Name)); } }); }
/// <summary> /// Update the state of specified commitmentPlans associated with the Cognitive /// Services account. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. The name is case insensitive. /// </param> /// <param name='accountName'> /// The name of Cognitive Services account. /// </param> /// <param name='commitmentPlanName'> /// The name of the commitmentPlan associated with the Cognitive Services /// Account /// </param> /// <param name='commitmentPlan'> /// The commitmentPlan properties. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <CommitmentPlan> CreateOrUpdateAsync(this ICommitmentPlansOperations operations, string resourceGroupName, string accountName, string commitmentPlanName, CommitmentPlan commitmentPlan, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, accountName, commitmentPlanName, commitmentPlan, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Update the state of specified commitmentPlans associated with the Cognitive /// Services account. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. The name is case insensitive. /// </param> /// <param name='accountName'> /// The name of Cognitive Services account. /// </param> /// <param name='commitmentPlanName'> /// The name of the commitmentPlan associated with the Cognitive Services /// Account /// </param> /// <param name='commitmentPlan'> /// The commitmentPlan properties. /// </param> public static CommitmentPlan CreateOrUpdate(this ICommitmentPlansOperations operations, string resourceGroupName, string accountName, string commitmentPlanName, CommitmentPlan commitmentPlan) { return(operations.CreateOrUpdateAsync(resourceGroupName, accountName, commitmentPlanName, commitmentPlan).GetAwaiter().GetResult()); }