public async Task SqlContainerCreateAndUpdate() { var container = await CreateSqlContainer(null); Assert.AreEqual(_containerName, container.Data.Resource.Id); // Seems bug in swagger definition //Assert.AreEqual(TestThroughput1, container.Data.Options.Throughput); bool ifExists = await SqlContainerCollection.ExistsAsync(_containerName); Assert.True(ifExists); // NOT WORKING API //ThroughputSettingsData throughtput = await container.GetMongoDBCollectionThroughputAsync(); SqlContainerResource container2 = await SqlContainerCollection.GetAsync(_containerName); Assert.AreEqual(_containerName, container2.Data.Resource.Id); //Assert.AreEqual(TestThroughput1, container2.Data.Options.Throughput); VerifySqlContainers(container, container2); // TODO: use original tags see defect: https://github.com/Azure/autorest.csharp/issues/1590 SqlContainerCreateUpdateData updateOptions = new SqlContainerCreateUpdateData(AzureLocation.WestUS, container.Data.Resource) { Options = new CreateUpdateOptions { Throughput = TestThroughput2 } }; container = (await SqlContainerCollection.CreateOrUpdateAsync(WaitUntil.Completed, _containerName, updateOptions)).Value; Assert.AreEqual(_containerName, container.Data.Resource.Id); container2 = await SqlContainerCollection.GetAsync(_containerName); VerifySqlContainers(container, container2); }
private void VerifySqlContainers(SqlContainerResource expectedValue, SqlContainerResource actualValue) { Assert.AreEqual(expectedValue.Id, actualValue.Id); Assert.AreEqual(expectedValue.Name, actualValue.Name); Assert.AreEqual(expectedValue.Resource.Id, actualValue.Resource.Id); Assert.AreEqual(expectedValue.Resource.IndexingPolicy.IndexingMode, actualValue.Resource.IndexingPolicy.IndexingMode); Assert.AreEqual(expectedValue.Resource.PartitionKey.Kind, actualValue.Resource.PartitionKey.Kind); Assert.AreEqual(expectedValue.Resource.PartitionKey.Paths, actualValue.Resource.PartitionKey.Paths); Assert.AreEqual(expectedValue.Resource.DefaultTtl, actualValue.Resource.DefaultTtl); }
public async Task TearDown() { if (await SqlContainerCollection.ExistsAsync(_containerName)) { var id = SqlContainerCollection.Id; id = SqlContainerResource.CreateResourceIdentifier(id.SubscriptionId, id.ResourceGroupName, id.Parent.Name, id.Name, _containerName); SqlContainerResource container = this.ArmClient.GetSqlContainerResource(id); await container.DeleteAsync(WaitUntil.Completed); } }
public async Task SqlContainerListTest() { List <SqlContainerResource> sqlContainers = await CosmosDBManagementClient.SqlResources.ListSqlContainersAsync( resourceGroupName, databaseAccountName, databaseName).ToEnumerableAsync(); Assert.NotNull(sqlContainers); Assert.AreEqual(1, sqlContainers.Count); SqlContainerResource sqlContainer = await CosmosDBManagementClient.SqlResources.GetSqlContainerAsync( resourceGroupName, databaseAccountName, databaseName, containerName); Assert.NotNull(sqlContainer); VerifySqlContainers(sqlContainer, sqlContainers[0]); }
public override void ExecuteCmdlet() { if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ParentObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; DatabaseName = resourceIdentifier.ResourceName; AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier); } else if (ParameterSetName.Equals(ObjectParameterSet, StringComparison.Ordinal)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; Name = resourceIdentifier.ResourceName; DatabaseName = ResourceIdentifierExtensions.GetSqlDatabaseName(resourceIdentifier); AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier); } SqlContainerGetResults readSqlContainerGetResults = null; try { readSqlContainerGetResults = CosmosDBManagementClient.SqlResources.GetSqlContainer(ResourceGroupName, AccountName, DatabaseName, Name); } catch (CloudException e) { if (e.Response.StatusCode == System.Net.HttpStatusCode.NotFound) { throw new ResourceNotFoundException(message: string.Format(ExceptionMessage.NotFound, Name), innerException: e); } } SqlContainerResource sqlContainerResource = UpdateAzCosmosDBSqlContainer.PopulateSqlContainerResource(readSqlContainerGetResults.Resource); if (PartitionKeyPath != null) { List <string> Paths = new List <string>(PartitionKeyPath); sqlContainerResource.PartitionKey = new ContainerPartitionKey { Kind = PartitionKeyKind, Paths = Paths, Version = PartitionKeyVersion }; } if (UniqueKeyPolicy != null) { sqlContainerResource.UniqueKeyPolicy = PSUniqueKeyPolicy.ToSDKModel(UniqueKeyPolicy); } if (TtlInSeconds != null) { sqlContainerResource.DefaultTtl = TtlInSeconds; } if (ConflictResolutionPolicy != null) { sqlContainerResource.ConflictResolutionPolicy = PSConflictResolutionPolicy.ToSDKModel(ConflictResolutionPolicy); } else if (ConflictResolutionPolicyMode != null) { ConflictResolutionPolicy conflictResolutionPolicy = new ConflictResolutionPolicy { Mode = ConflictResolutionPolicyMode }; if (ConflictResolutionPolicyMode.Equals(ConflictResolutionMode.LastWriterWins, StringComparison.OrdinalIgnoreCase)) { conflictResolutionPolicy.ConflictResolutionPath = ConflictResolutionPolicyPath; } else if (ConflictResolutionPolicyMode.Equals(ConflictResolutionMode.Custom, StringComparison.OrdinalIgnoreCase)) { conflictResolutionPolicy.ConflictResolutionProcedure = ConflictResolutionPolicyProcedure; } sqlContainerResource.ConflictResolutionPolicy = conflictResolutionPolicy; } if (IndexingPolicy != null) { sqlContainerResource.IndexingPolicy = PSIndexingPolicy.ToSDKModel(IndexingPolicy); } if (AnalyticalStorageTtl != null) { sqlContainerResource.AnalyticalStorageTtl = AnalyticalStorageTtl; } CreateUpdateOptions options = ThroughputHelper.PopulateCreateUpdateOptions(Throughput, AutoscaleMaxThroughput); SqlContainerCreateUpdateParameters sqlContainerCreateUpdateParameters = new SqlContainerCreateUpdateParameters { Resource = sqlContainerResource, Options = options }; if (ShouldProcess(Name, "Updating an existing CosmosDB Sql Container")) { SqlContainerGetResults sqlContainerGetResults = CosmosDBManagementClient.SqlResources.CreateUpdateSqlContainer(ResourceGroupName, AccountName, DatabaseName, Name, sqlContainerCreateUpdateParameters); WriteObject(new PSSqlContainerGetResults(sqlContainerGetResults)); } return; }
public override void ExecuteCmdlet() { if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ParentObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; DatabaseName = resourceIdentifier.ResourceName; AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier); } SqlContainerGetResults readSqlContainerGetResults = null; try { readSqlContainerGetResults = CosmosDBManagementClient.SqlResources.GetSqlContainer(ResourceGroupName, AccountName, DatabaseName, Name); } catch (CloudException e) { if (e.Response.StatusCode != System.Net.HttpStatusCode.NotFound) { throw; } } if (readSqlContainerGetResults != null) { throw new ConflictingResourceException(message: string.Format(ExceptionMessage.Conflict, Name)); } List <string> Paths = new List <string>(); foreach (string path in PartitionKeyPath) { Paths.Add(path); } SqlContainerResource sqlContainerResource = new SqlContainerResource { Id = Name, PartitionKey = new ContainerPartitionKey { Kind = PartitionKeyKind, Paths = Paths, Version = PartitionKeyVersion } }; if (UniqueKeyPolicy != null) { sqlContainerResource.UniqueKeyPolicy = PSUniqueKeyPolicy.ConvertPSUniqueKeyPolicyToUniqueKeyPolicy(UniqueKeyPolicy); } if (TtlInSeconds != null) { sqlContainerResource.DefaultTtl = TtlInSeconds; } if (ConflictResolutionPolicy != null) { sqlContainerResource.ConflictResolutionPolicy = PSConflictResolutionPolicy.ConvertPSConflictResolutionPolicyToConflictResolutionPolicy(ConflictResolutionPolicy); } if (ConflictResolutionPolicyMode != null) { ConflictResolutionPolicy conflictResolutionPolicy = new ConflictResolutionPolicy { Mode = ConflictResolutionPolicyMode }; if (ConflictResolutionPolicyMode.Equals(ConflictResolutionMode.LastWriterWins, StringComparison.OrdinalIgnoreCase)) { conflictResolutionPolicy.ConflictResolutionPath = ConflictResolutionPolicyPath; } else if (ConflictResolutionPolicyMode.Equals(ConflictResolutionMode.Custom, StringComparison.OrdinalIgnoreCase)) { conflictResolutionPolicy.ConflictResolutionProcedure = ConflictResolutionPolicyProcedure; } sqlContainerResource.ConflictResolutionPolicy = conflictResolutionPolicy; } if (IndexingPolicy != null) { sqlContainerResource.IndexingPolicy = PSIndexingPolicy.ConvertPSIndexingToIndexingPolicy(IndexingPolicy); } CreateUpdateOptions options = new CreateUpdateOptions(); if (Throughput != null) { options.Throughput = Throughput.ToString(); } SqlContainerCreateUpdateParameters sqlContainerCreateUpdateParameters = new SqlContainerCreateUpdateParameters { Resource = sqlContainerResource, Options = options }; if (ShouldProcess(Name, "Creating a new CosmosDB Sql Container")) { SqlContainerGetResults sqlContainerGetResults = CosmosDBManagementClient.SqlResources.CreateUpdateSqlContainerWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, Name, sqlContainerCreateUpdateParameters).GetAwaiter().GetResult().Body; WriteObject(new PSSqlContainerGetResults(sqlContainerGetResults)); } return; }
public async Task SetUp() { _sqlContainer = await ArmClient.GetSqlContainerResource(_sqlContainerId).GetAsync(); }
public async Task SqlContainerCreateAndUpdateTest() { SqlContainerCreateUpdateParameters sqlContainerCreateUpdateParameters = new SqlContainerCreateUpdateParameters( resource: new SqlContainerResource(containerName) { PartitionKeyResource = new ContainerPartitionKey(new List <string> { "/address/zipCode" }, null, null) { Kind = new PartitionKind("Hash") }, IndexingPolicyResource = new IndexingPolicy( true, IndexingMode.Consistent, new List <IncludedPath> { new IncludedPath { Path = "/*" } }, new List <ExcludedPath> { new ExcludedPath { Path = "/pathToNotIndex/*" } }, new List <IList <CompositePath> > { new List <CompositePath> { new CompositePath { Path = "/orderByPath1", Order = CompositePathSortOrder.Ascending }, new CompositePath { Path = "/orderByPath2", Order = CompositePathSortOrder.Descending } } }, new List <SpatialSpec> { new SpatialSpec ( "/*", new List <SpatialType> { new SpatialType("Point") } ), } ) }, options: new CreateUpdateOptions { Throughput = sampleThroughput1 } ); SqlContainerResource sqlContainer1 = await WaitForCompletionAsync( await CosmosDBManagementClient.SqlResources.StartCreateUpdateSqlContainerAsync( resourceGroupName, databaseAccountName, databaseName, containerName, sqlContainerCreateUpdateParameters)); Assert.NotNull(sqlContainer1); SqlContainerResource sqlContainer2 = await CosmosDBManagementClient.SqlResources.GetSqlContainerAsync( resourceGroupName, databaseAccountName, databaseName, containerName); Assert.NotNull(sqlContainer2); VerifySqlContainers(sqlContainer1, sqlContainer2); ThroughputSettingsData throughputSettings1 = await CosmosDBManagementClient.SqlResources.GetSqlContainerThroughputAsync(resourceGroupName, databaseAccountName, databaseName, containerName); Assert.NotNull(throughputSettings1); Assert.NotNull(throughputSettings1.Name); Assert.AreEqual(sqlContainersThroughputType, throughputSettings1.Type); Assert.AreEqual(sampleThroughput1, throughputSettings1.Resource.Throughput); sqlContainerCreateUpdateParameters = new SqlContainerCreateUpdateParameters( resource: new SqlContainerResource(containerName) { PartitionKeyResource = new ContainerPartitionKey(new List <string> { "/address/zipCode" }, null, null) { Kind = new PartitionKind("Hash") }, IndexingPolicyResource = new IndexingPolicy( true, IndexingMode.Consistent, new List <IncludedPath> { new IncludedPath { Path = "/*" } }, new List <ExcludedPath> { new ExcludedPath { Path = "/pathToNotIndex/*" } }, new List <IList <CompositePath> > { new List <CompositePath> { new CompositePath { Path = "/orderByPath3", Order = CompositePathSortOrder.Ascending }, new CompositePath { Path = "/orderByPath4", Order = CompositePathSortOrder.Descending } } }, new List <SpatialSpec> { new SpatialSpec ( "/*", new List <SpatialType> { new SpatialType("Point") } ), } ) }, options: new CreateUpdateOptions { Throughput = sampleThroughput2 } ); SqlContainerResource sqlContainer3 = await WaitForCompletionAsync( await CosmosDBManagementClient.SqlResources.StartCreateUpdateSqlContainerAsync( resourceGroupName, databaseAccountName, databaseName, containerName, sqlContainerCreateUpdateParameters)); Assert.NotNull(sqlContainer3); SqlContainerResource sqlContainer4 = await CosmosDBManagementClient.SqlResources.GetSqlContainerAsync( resourceGroupName, databaseAccountName, databaseName, containerName); Assert.NotNull(sqlContainer4); VerifySqlContainers(sqlContainer3, sqlContainer4); ThroughputSettingsData throughputSettings2 = await CosmosDBManagementClient.SqlResources.GetSqlContainerThroughputAsync(resourceGroupName, databaseAccountName, databaseName, containerName); Assert.NotNull(throughputSettings2); Assert.NotNull(throughputSettings2.Name); Assert.AreEqual(sqlContainersThroughputType, throughputSettings2.Type); Assert.AreEqual(sampleThroughput2, throughputSettings2.Resource.Throughput); }
public override void ExecuteCmdlet() { if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; DatabaseName = resourceIdentifier.ResourceName; AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier); } List <string> Paths = new List <string>(); foreach (string path in PartitionKeyPath) { Paths.Add(path); } SqlContainerResource sqlContainerResource = new SqlContainerResource { Id = Name, PartitionKey = new ContainerPartitionKey { Kind = PartitionKeyKind, Paths = Paths, Version = PartitionKeyVersion } }; if (UniqueKeyPolicy != null) { UniqueKeyPolicy uniqueKeyPolicy = new UniqueKeyPolicy(); foreach (PSSqlUniqueKey uniqueKey in UniqueKeyPolicy.UniqueKey) { UniqueKey key = new UniqueKey(uniqueKey.Path); uniqueKeyPolicy.UniqueKeys.Add(key); } sqlContainerResource.UniqueKeyPolicy = uniqueKeyPolicy; } if (TtlInSeconds != null) { sqlContainerResource.DefaultTtl = TtlInSeconds; } if (ConflictResolutionPolicy != null) { ConflictResolutionPolicy conflictResolutionPolicy = new ConflictResolutionPolicy { Mode = ConflictResolutionPolicy.Type }; if (ConflictResolutionPolicy.Type.Equals("LastWriterWins", StringComparison.OrdinalIgnoreCase)) { conflictResolutionPolicy.ConflictResolutionPath = ConflictResolutionPolicy.Path; } else if (ConflictResolutionPolicy.Type.Equals("Custom", StringComparison.OrdinalIgnoreCase)) { conflictResolutionPolicy.ConflictResolutionProcedure = ConflictResolutionPolicy.ConflictResolutionProcedure; } sqlContainerResource.ConflictResolutionPolicy = conflictResolutionPolicy; } if (IndexingPolicy != null) { IList <IncludedPath> includedPaths = new List <IncludedPath>(); IList <ExcludedPath> excludedPaths = new List <ExcludedPath>(); foreach (string path in IndexingPolicy.IncludedPaths) { includedPaths.Add(new IncludedPath(path: path)); } foreach (string path in IndexingPolicy.ExcludedPaths) { excludedPaths.Add(new ExcludedPath(path: path)); } IndexingPolicy indexingPolicy = new IndexingPolicy { Automatic = IndexingPolicy.Automatic, IndexingMode = IndexingPolicy.IndexingMode, IncludedPaths = includedPaths, ExcludedPaths = excludedPaths }; sqlContainerResource.IndexingPolicy = indexingPolicy; } IDictionary <string, string> options = new Dictionary <string, string>(); if (Throughput != null) { options.Add("Throughput", Throughput.ToString()); } SqlContainerCreateUpdateParameters sqlContainerCreateUpdateParameters = new SqlContainerCreateUpdateParameters { Resource = sqlContainerResource, Options = options }; if (ShouldProcess(Name, "Creating or Updating CosmosDB Sql Container")) { SqlContainerGetResults sqlContainerGetResults = CosmosDBManagementClient.SqlResources.CreateUpdateSqlContainerWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, Name, sqlContainerCreateUpdateParameters).GetAwaiter().GetResult().Body; WriteObject(new PSSqlContainerGetResults(sqlContainerGetResults)); } return; }
public override void ExecuteCmdlet() { if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; DatabaseName = resourceIdentifier.ResourceName; AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier); } List <string> Paths = new List <string>(); foreach (string path in PartitionKeyPath) { Paths.Add(path); } SqlContainerResource sqlContainerResource = new SqlContainerResource { Id = Name, PartitionKey = new ContainerPartitionKey { Kind = PartitionKeyKind, Paths = Paths, Version = PartitionKeyVersion } }; if (UniqueKeyPolicy != null) { UniqueKeyPolicy uniqueKeyPolicy = new UniqueKeyPolicy { UniqueKeys = new List <UniqueKey>() }; foreach (PSUniqueKey uniqueKey in UniqueKeyPolicy.UniqueKeys) { UniqueKey key = new UniqueKey { Paths = new List <string>() }; foreach (string path in uniqueKey.Paths) { key.Paths.Add(path); } uniqueKeyPolicy.UniqueKeys.Add(key); } sqlContainerResource.UniqueKeyPolicy = uniqueKeyPolicy; } if (TtlInSeconds != null) { sqlContainerResource.DefaultTtl = TtlInSeconds; } if (ConflictResolutionPolicy != null) { ConflictResolutionPolicyMode = ConflictResolutionPolicy.Mode; if (ConflictResolutionPolicy.ConflictResolutionPath != null) { ConflictResolutionPolicyPath = ConflictResolutionPolicy.ConflictResolutionPath; } if (ConflictResolutionPolicy.ConflictResolutionProcedure != null) { ConflictResolutionPolicyProcedure = ConflictResolutionPolicy.ConflictResolutionProcedure; } } if (ConflictResolutionPolicyMode != null) { ConflictResolutionPolicy conflictResolutionPolicy = new ConflictResolutionPolicy { Mode = ConflictResolutionPolicyMode }; if (ConflictResolutionPolicyMode.Equals("LastWriterWins", StringComparison.OrdinalIgnoreCase)) { conflictResolutionPolicy.ConflictResolutionPath = ConflictResolutionPolicyPath; } else if (ConflictResolutionPolicyMode.Equals("Custom", StringComparison.OrdinalIgnoreCase)) { conflictResolutionPolicy.ConflictResolutionProcedure = ConflictResolutionPolicyProcedure; } sqlContainerResource.ConflictResolutionPolicy = conflictResolutionPolicy; } if (IndexingPolicy != null) { IndexingPolicy indexingPolicy = new IndexingPolicy { Automatic = IndexingPolicy.Automatic, IndexingMode = IndexingPolicy.IndexingMode, }; if (IndexingPolicy.IncludedPaths != null) { IList <IncludedPath> includedPaths = new List <IncludedPath>(); foreach (PSIncludedPath pSIncludedPath in IndexingPolicy.IncludedPaths) { includedPaths.Add(new IncludedPath { Path = pSIncludedPath.Path, Indexes = PSIncludedPath.ConvertPSIndexesToIndexes(pSIncludedPath.Indexes) }); } indexingPolicy.IncludedPaths = new List <IncludedPath>(includedPaths); } if (IndexingPolicy.ExcludedPaths != null && IndexingPolicy.ExcludedPaths.Count > 0) { IList <ExcludedPath> excludedPaths = new List <ExcludedPath>(); foreach (PSExcludedPath pSExcludedPath in IndexingPolicy.ExcludedPaths) { excludedPaths.Add(new ExcludedPath { Path = pSExcludedPath.Path }); } indexingPolicy.ExcludedPaths = new List <ExcludedPath>(excludedPaths); } if (IndexingPolicy.CompositeIndexes != null) { IList <IList <CompositePath> > compositeIndexes = new List <IList <CompositePath> >(); foreach (IList <PSCompositePath> pSCompositePathList in IndexingPolicy.CompositeIndexes) { IList <CompositePath> compositePathList = new List <CompositePath>(); foreach (PSCompositePath pSCompositePath in pSCompositePathList) { compositePathList.Add(new CompositePath { Order = pSCompositePath.Order, Path = pSCompositePath.Path }); } compositeIndexes.Add(compositePathList); } indexingPolicy.CompositeIndexes = new List <IList <CompositePath> >(compositeIndexes); } if (IndexingPolicy.SpatialIndexes != null && IndexingPolicy.SpatialIndexes.Count > 0) { IList <SpatialSpec> spatialIndexes = new List <SpatialSpec>(); foreach (PSSpatialSpec pSSpatialSpec in IndexingPolicy.SpatialIndexes) { spatialIndexes.Add(new SpatialSpec { Path = pSSpatialSpec.Path, Types = pSSpatialSpec.Types }); } indexingPolicy.SpatialIndexes = new List <SpatialSpec>(spatialIndexes); } sqlContainerResource.IndexingPolicy = indexingPolicy; } IDictionary <string, string> options = new Dictionary <string, string>(); if (Throughput != null) { options.Add("Throughput", Throughput.ToString()); } SqlContainerCreateUpdateParameters sqlContainerCreateUpdateParameters = new SqlContainerCreateUpdateParameters { Resource = sqlContainerResource, Options = options }; if (ShouldProcess(Name, "Setting CosmosDB Sql Container")) { SqlContainerGetResults sqlContainerGetResults = CosmosDBManagementClient.SqlResources.CreateUpdateSqlContainerWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, Name, sqlContainerCreateUpdateParameters).GetAwaiter().GetResult().Body; WriteObject(new PSSqlContainerGetResults(sqlContainerGetResults)); } return; }