public override void ExecuteCmdlet() { if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ParentObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; KeyspaceName = resourceIdentifier.ResourceName; AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier); } CassandraTableGetResults readCassandraTableGetResults = null; try { readCassandraTableGetResults = CosmosDBManagementClient.CassandraResources.GetCassandraTable(ResourceGroupName, AccountName, KeyspaceName, Name); } catch (CloudException e) { if (e.Response.StatusCode != System.Net.HttpStatusCode.NotFound) { throw; } } if (readCassandraTableGetResults != null) { throw new ConflictingResourceException(message: string.Format(ExceptionMessage.Conflict, Name)); } CreateUpdateOptions options = new CreateUpdateOptions(); if (Throughput != null) { options.Throughput = Throughput.ToString(); } CassandraTableResource cassandraTableResource = new CassandraTableResource { Id = Name, DefaultTtl = TtlInSeconds }; cassandraTableResource.Schema = PSCassandraSchema.ToSDKModel(Schema); CassandraTableCreateUpdateParameters cassandraTableCreateUpdateParameters = new CassandraTableCreateUpdateParameters { Resource = cassandraTableResource, Options = options }; if (ShouldProcess(Name, "Creating a new CosmosDB Cassandra Table")) { CassandraTableGetResults cassandraTableGetResults = CosmosDBManagementClient.CassandraResources.CreateUpdateCassandraTableWithHttpMessagesAsync(ResourceGroupName, AccountName, KeyspaceName, Name, cassandraTableCreateUpdateParameters).GetAwaiter().GetResult().Body; WriteObject(new PSCassandraTableGetResults(cassandraTableGetResults)); } return; }
public async Task TearDown() { if (await CassandraTableCollection.ExistsAsync(_tableName)) { var id = CassandraTableCollection.Id; id = CassandraTableResource.CreateResourceIdentifier(id.SubscriptionId, id.ResourceGroupName, id.Parent.Name, id.Name, _tableName); CassandraTableResource table = this.ArmClient.GetCassandraTableResource(id); await table.DeleteAsync(WaitUntil.Completed); } }
public override void ExecuteCmdlet() { if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; KeyspaceName = resourceIdentifier.ResourceName; AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier); } IDictionary <string, string> options = new Dictionary <string, string>(); if (Throughput != null) { options.Add("Throughput", Throughput.ToString()); } CassandraTableResource cassandraTableResource = new CassandraTableResource { Id = Name, DefaultTtl = TtlInSeconds }; cassandraTableResource.Schema = PSCassandraSchema.ConvertPSCassandraSchemaToCassandraSchema(Schema); CassandraTableCreateUpdateParameters cassandraTableCreateUpdateParameters = new CassandraTableCreateUpdateParameters { Resource = cassandraTableResource, Options = options }; if (ShouldProcess(Name, "Setting CosmosDB Cassandra Table")) { CassandraTableGetResults cassandraTableGetResults = CosmosDBManagementClient.CassandraResources.CreateUpdateCassandraTableWithHttpMessagesAsync(ResourceGroupName, AccountName, KeyspaceName, Name, cassandraTableCreateUpdateParameters).GetAwaiter().GetResult().Body; WriteObject(new PSCassandraTableGetResults(cassandraTableGetResults)); } return; }
public async Task CassandraTableCreateAndUpdate() { var parameters = BuildCreateUpdateOptions(null); var table = await CreateCassandraTable(parameters); Assert.AreEqual(_tableName, table.Data.Resource.Id); VerifyCassandraTableCreation(table, parameters); // Seems bug in swagger definition //Assert.AreEqual(TestThroughput1, table.Data.Options.Throughput); bool ifExists = await CassandraTableCollection.ExistsAsync(_tableName); Assert.True(ifExists); // NOT WORKING API //ThroughputSettingsData throughtput = await table.GetCassandraTableThroughputAsync(); CassandraTableResource table2 = await CassandraTableCollection.GetAsync(_tableName); Assert.AreEqual(_tableName, table2.Data.Resource.Id); VerifyCassandraTableCreation(table2, parameters); //Assert.AreEqual(TestThroughput1, table2.Data.Options.Throughput); VerifyCassandraTables(table, table2); parameters.Options = new CreateUpdateOptions { Throughput = TestThroughput2 }; table = (await CassandraTableCollection.CreateOrUpdateAsync(WaitUntil.Completed, _tableName, parameters)).Value; Assert.AreEqual(_tableName, table.Data.Resource.Id); VerifyCassandraTableCreation(table, parameters); // Seems bug in swagger definition table2 = await CassandraTableCollection.GetAsync(_tableName); VerifyCassandraTableCreation(table2, parameters); // Seems bug in swagger definition VerifyCassandraTables(table, table2); }
public override void ExecuteCmdlet() { if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ParentObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; KeyspaceName = 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; KeyspaceName = ResourceIdentifierExtensions.GetCassandraKeyspaceName(resourceIdentifier); AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier); } CassandraTableGetResults readCassandraTableGetResults = null; try { readCassandraTableGetResults = CosmosDBManagementClient.CassandraResources.GetCassandraTable(ResourceGroupName, AccountName, KeyspaceName, Name); } catch (CloudException e) { if (e.Response.StatusCode == System.Net.HttpStatusCode.NotFound) { throw new ResourceNotFoundException(message: string.Format(ExceptionMessage.NotFound, Name), innerException: e); } } CassandraTableResource cassandraTableResource = PopulateCassandraTableResource(readCassandraTableGetResults.Resource); if (TtlInSeconds != null) { cassandraTableResource.DefaultTtl = TtlInSeconds; } if (Schema != null) { cassandraTableResource.Schema = PSCassandraSchema.ToSDKModel(Schema); } if (AnalyticalStorageTtl != null) { cassandraTableResource.AnalyticalStorageTtl = AnalyticalStorageTtl; } CreateUpdateOptions options = ThroughputHelper.PopulateCreateUpdateOptions(Throughput, AutoscaleMaxThroughput); CassandraTableCreateUpdateParameters cassandraTableCreateUpdateParameters = new CassandraTableCreateUpdateParameters { Resource = cassandraTableResource, Options = options, }; if (ShouldProcess(Name, "Updating an existing CosmosDB Cassandra Table")) { CassandraTableGetResults cassandraTableGetResults = CosmosDBManagementClient.CassandraResources.CreateUpdateCassandraTableWithHttpMessagesAsync(ResourceGroupName, AccountName, KeyspaceName, Name, cassandraTableCreateUpdateParameters).GetAwaiter().GetResult().Body; WriteObject(new PSCassandraTableGetResults(cassandraTableGetResults)); } return; }