diff --git a/src/DataStax.AstraDB.DataApi/Admin/AstraDatabasesAdmin.cs b/src/DataStax.AstraDB.DataApi/Admin/AstraDatabasesAdmin.cs index 5e6d4174..7f1fb619 100644 --- a/src/DataStax.AstraDB.DataApi/Admin/AstraDatabasesAdmin.cs +++ b/src/DataStax.AstraDB.DataApi/Admin/AstraDatabasesAdmin.cs @@ -17,6 +17,7 @@ using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.Core.Commands; using DataStax.AstraDB.DataApi.Utils; +using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; @@ -37,6 +38,7 @@ public class AstraDatabasesAdmin { private readonly CommandOptions _adminOptions; private readonly DataAPIClient _client; + private readonly ILogger _logger; private CommandOptions[] OptionsTree => new CommandOptions[] { _client.ClientOptions, _adminOptions }; @@ -57,6 +59,7 @@ internal AstraDatabasesAdmin(DataAPIClient client, CommandOptions adminOptions) Guard.NotNull(client, nameof(client)); _client = client; _adminOptions = adminOptions; + _logger = client.Logger; } internal string DevOpsAPISuffix(DBEnvironment? environment) => environment switch @@ -166,6 +169,51 @@ internal async Task CreateDatabaseAsync(CreateDatabaseOption Guard.NotNullOrEmpty(options.Name, nameof(options.Name)); Guard.NotNull(options.CloudProvider, nameof(options.CloudProvider)); Guard.NotNullOrEmpty(options.Region, nameof(options.Region)); + + if (options.PCUGroupId != null) + { + _logger.LogInformation("PCUGroupId specified ({PCUGroupId}): validating against available PCU groups.", options.PCUGroupId); + var listPCUOptions = ListPCUGroupsOptions.FromCommandOptions(options); + List pcuGroups = null; + try + { + pcuGroups = await ListPCUGroupsAsync(listPCUOptions, runSynchronously).ConfigureAwait(false); + } + catch (Exception ex) + { + _logger.LogWarning(ex, "Failed to retrieve PCU groups; skipping PCU group validation."); + } + + if (pcuGroups != null) + { + _logger.LogInformation("Retrieved {Count} PCU group(s); searching for id={PCUGroupId}.", pcuGroups.Count, options.PCUGroupId); + var matchedGroup = pcuGroups.FirstOrDefault(g => + string.Equals(g.Id, options.PCUGroupId, StringComparison.OrdinalIgnoreCase)); + + if (matchedGroup == null) + { + _logger.LogInformation("PCU group '{PCUGroupId}' was not found: aborting database creation.", options.PCUGroupId); + throw new InvalidOperationException( + $"No PCU group with id '{options.PCUGroupId}' was found."); + } + + _logger.LogInformation("Found PCU group '{PCUGroupId}': cloudProvider={CloudProvider}, region={Region}.", matchedGroup.Id, matchedGroup.CloudProvider, matchedGroup.Region); + + bool cloudProviderMatches = matchedGroup.CloudProvider == options.CloudProvider; + bool regionMatches = string.Equals(matchedGroup.Region, options.Region, StringComparison.OrdinalIgnoreCase); + + if (!cloudProviderMatches || !regionMatches) + { + _logger.LogInformation("PCU group '{PCUGroupId}' was found in a different region: aborting database creation.", matchedGroup.Id); + throw new InvalidOperationException( + $"PCU group '{options.PCUGroupId}' is in cloudProvider={matchedGroup.CloudProvider}, region={matchedGroup.Region}, " + + $"which does not match the requested cloudProvider={options.CloudProvider}, region={options.Region}."); + } + + _logger.LogInformation("PCU group '{PCUGroupId}' validated successfully; proceeding with database creation.", options.PCUGroupId); + } + } + Command command = CreateCommand() .AddUrlPath("databases") .WithPayload(options.ToPayload()) @@ -407,6 +455,49 @@ internal async Task> FindAvailableRegionsAsync(FindAvailableReg return response; } + /// + /// Synchronous version of + /// + /// + public List ListPCUGroups(ListPCUGroupsOptions options = null) + { + return ListPCUGroupsAsync(options, true).ResultSync(); + } + + /// + /// List the PCU (Provisioned Capacity Units) Groups pertaining to the current org. + /// + /// Additional options to the DevOps API query, such as cloud provider/region filters and general request execution parameters. + /// A list of the PCU Groups according to the requested filtering. + public Task> ListPCUGroupsAsync(ListPCUGroupsOptions options = null) + { + return ListPCUGroupsAsync(options, false); + } + + internal async Task> ListPCUGroupsAsync(ListPCUGroupsOptions options, bool runSynchronously) + { + if (options != null && (options.CloudProvider == null) != (options.Region == null)) + throw new ArgumentException( + "Either both or none of CloudProvider and Region must be set for filtering PCU Groups.", + nameof(options)); + + var command = CreateCommand() + .AddUrlPath("pcus/actions/get") + .WithPayload(new Dictionary()) + .WithTimeoutManager(new DatabaseAdminTimeoutManager()) + .AddCommandOptions(options); + + var response = await command.RunAsyncRaw>(HttpMethod.Post, runSynchronously); + // apply cloud/region filter if required: + if (options?.CloudProvider == null) + { + return response; + } + return response + .Where(group => group.CloudProvider == options.CloudProvider && group.Region == options.Region) + .ToList(); + } + private DatabaseAdminAstra GetDatabaseAdmin(DatabaseInfo dbInfo, GetDatabaseAdminOptions options = null) { var commandOptions = CommandOptions.Merge(new CommandOptions[] {_adminOptions, options}); diff --git a/src/DataStax.AstraDB.DataApi/Admin/CloudProviderType.cs b/src/DataStax.AstraDB.DataApi/Admin/CloudProviderType.cs index 7aabc0c9..1f127ff0 100644 --- a/src/DataStax.AstraDB.DataApi/Admin/CloudProviderType.cs +++ b/src/DataStax.AstraDB.DataApi/Admin/CloudProviderType.cs @@ -21,7 +21,6 @@ namespace DataStax.AstraDB.DataApi.Admin; /// /// Specifies the cloud provider on which an Astra DB database is deployed. /// -[JsonConverter(typeof(JsonStringEnumConverter))] public enum CloudProviderType { /// Amazon Web Services. @@ -32,5 +31,5 @@ public enum CloudProviderType GCP, /// Microsoft Azure. [JsonStringEnumMemberName("azure")] - Azure -} \ No newline at end of file + AZURE +} diff --git a/src/DataStax.AstraDB.DataApi/Admin/CreateDatabaseOptions.cs b/src/DataStax.AstraDB.DataApi/Admin/CreateDatabaseOptions.cs index 58e98927..7c9f23d4 100644 --- a/src/DataStax.AstraDB.DataApi/Admin/CreateDatabaseOptions.cs +++ b/src/DataStax.AstraDB.DataApi/Admin/CreateDatabaseOptions.cs @@ -25,6 +25,10 @@ namespace DataStax.AstraDB.DataApi.Admin; /// public class CreateDatabaseOptions : BlockingCommandOptions { + private const string DefaultTier = "serverless"; + private const int DefaultCapacityUnits = 1; + private const string DefaultDbType = "vector"; + /// /// Name of the database to be created. /// @@ -49,15 +53,33 @@ public class CreateDatabaseOptions : BlockingCommandOptions set => base.Keyspace = value; } + /// + /// Database tier (defaults to "serverless"). + /// + public string Tier { get; set; } = DefaultTier; + + /// + /// Capacity units for the database (defaults to 1). + /// + public int CapacityUnits { get; set; } = DefaultCapacityUnits; + + /// + /// Database type (defaults to "vector"). + /// + public string DBType { get; set; } = DefaultDbType; + + /// + /// PCU group ID to use for provisioning the database. Optional. + /// + public string PCUGroupId { get; set; } = null; + internal object ToPayload() { var payload = new Dictionary(); - // hardcoded properties - payload["tier"] = "serverless"; - payload["capacityUnits"] = 1; - payload["dbType"] = "vector"; - // specified properties + payload["tier"] = Tier; + payload["capacityUnits"] = CapacityUnits; + payload["dbType"] = DBType; if ( Name != null ) { payload["name"] = Name; @@ -74,6 +96,10 @@ internal object ToPayload() { payload["keyspace"] = Keyspace; } + if ( PCUGroupId != null ) + { + payload["pcuGroupUUID"] = PCUGroupId; + } return payload; } diff --git a/src/DataStax.AstraDB.DataApi/Core/CreateKeyspaceOptions.cs b/src/DataStax.AstraDB.DataApi/Admin/CreateKeyspaceOptions.cs similarity index 92% rename from src/DataStax.AstraDB.DataApi/Core/CreateKeyspaceOptions.cs rename to src/DataStax.AstraDB.DataApi/Admin/CreateKeyspaceOptions.cs index 226ce0d2..d61bc2be 100644 --- a/src/DataStax.AstraDB.DataApi/Core/CreateKeyspaceOptions.cs +++ b/src/DataStax.AstraDB.DataApi/Admin/CreateKeyspaceOptions.cs @@ -14,7 +14,9 @@ * limitations under the License. */ -namespace DataStax.AstraDB.DataApi.Core; +using DataStax.AstraDB.DataApi.Core; + +namespace DataStax.AstraDB.DataApi.Admin; /// /// Options specific to the database admin command to create a keyspace. diff --git a/src/DataStax.AstraDB.DataApi/Core/DoesKeyspaceExistOptions.cs b/src/DataStax.AstraDB.DataApi/Admin/DoesKeyspaceExistOptions.cs similarity index 93% rename from src/DataStax.AstraDB.DataApi/Core/DoesKeyspaceExistOptions.cs rename to src/DataStax.AstraDB.DataApi/Admin/DoesKeyspaceExistOptions.cs index d0b12b6f..81448021 100644 --- a/src/DataStax.AstraDB.DataApi/Core/DoesKeyspaceExistOptions.cs +++ b/src/DataStax.AstraDB.DataApi/Admin/DoesKeyspaceExistOptions.cs @@ -14,7 +14,9 @@ * limitations under the License. */ -namespace DataStax.AstraDB.DataApi.Core; +using DataStax.AstraDB.DataApi.Core; + +namespace DataStax.AstraDB.DataApi.Admin; /// /// Command options specific to the database admin's DoesKeyspaceExist methods. diff --git a/src/DataStax.AstraDB.DataApi/Core/DropKeyspaceOptions.cs b/src/DataStax.AstraDB.DataApi/Admin/DropKeyspaceOptions.cs similarity index 90% rename from src/DataStax.AstraDB.DataApi/Core/DropKeyspaceOptions.cs rename to src/DataStax.AstraDB.DataApi/Admin/DropKeyspaceOptions.cs index 11a1a30f..e857a051 100644 --- a/src/DataStax.AstraDB.DataApi/Core/DropKeyspaceOptions.cs +++ b/src/DataStax.AstraDB.DataApi/Admin/DropKeyspaceOptions.cs @@ -14,7 +14,9 @@ * limitations under the License. */ -namespace DataStax.AstraDB.DataApi.Core; +using DataStax.AstraDB.DataApi.Core; + +namespace DataStax.AstraDB.DataApi.Admin; /// /// Options specific to the database admin command to drop a keyspace. diff --git a/src/DataStax.AstraDB.DataApi/Core/ListKeyspacesOptions.cs b/src/DataStax.AstraDB.DataApi/Admin/ListKeyspacesOptions.cs similarity index 93% rename from src/DataStax.AstraDB.DataApi/Core/ListKeyspacesOptions.cs rename to src/DataStax.AstraDB.DataApi/Admin/ListKeyspacesOptions.cs index 405f8b54..6787766f 100644 --- a/src/DataStax.AstraDB.DataApi/Core/ListKeyspacesOptions.cs +++ b/src/DataStax.AstraDB.DataApi/Admin/ListKeyspacesOptions.cs @@ -14,9 +14,9 @@ * limitations under the License. */ -using DataStax.AstraDB.DataApi.Admin; +using DataStax.AstraDB.DataApi.Core; -namespace DataStax.AstraDB.DataApi.Core; +namespace DataStax.AstraDB.DataApi.Admin; /// /// Command options specific to the database admin's ListKeyspaces methods. diff --git a/src/DataStax.AstraDB.DataApi/Admin/ListPCUGroupsOptions.cs b/src/DataStax.AstraDB.DataApi/Admin/ListPCUGroupsOptions.cs new file mode 100644 index 00000000..3e9c7ff7 --- /dev/null +++ b/src/DataStax.AstraDB.DataApi/Admin/ListPCUGroupsOptions.cs @@ -0,0 +1,60 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using DataStax.AstraDB.DataApi.Core; + +namespace DataStax.AstraDB.DataApi.Admin; + +/// +/// Options for AstraDatabasesAdmin's ListPCUGroups command. +/// +public class ListPCUGroupsOptions : CommandOptions +{ + + /// + /// If set, filters results to this cloud provider only. + /// Either both or none of CloudProvider and Region must be set + /// + public CloudProviderType? CloudProvider { get; set; } + + /// + /// If set, filters results to this region only. + /// Either both or none of CloudProvider and Region must be set + /// + public string Region { get; set; } + + internal ListPCUGroupsOptions(CommandOptions source) : base(source) + { + } + + /// + /// Creates a new instance of with default values. + /// + public ListPCUGroupsOptions() : base() + { + } + + static internal ListPCUGroupsOptions FromCommandOptions( + CommandOptions options, CloudProviderType? cloudProvider = null, string region = null + ) + { + if (options == null) return null; + return new ListPCUGroupsOptions(options) { + CloudProvider = cloudProvider, Region = region + }; + } + +} diff --git a/src/DataStax.AstraDB.DataApi/Admin/PCUGroup.cs b/src/DataStax.AstraDB.DataApi/Admin/PCUGroup.cs new file mode 100644 index 00000000..37384050 --- /dev/null +++ b/src/DataStax.AstraDB.DataApi/Admin/PCUGroup.cs @@ -0,0 +1,201 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Text.Json.Serialization; + +namespace DataStax.AstraDB.DataApi.Admin; + +/// +/// The specifications for a PCU (Provisioned Capacity Unit) group, +/// such as the ones returned when querying the DevOps API for PCU groups. +/// +public class PCUGroup +{ + /// + /// The unique identifier for the PCU group (a UUID as a string). + /// + [JsonPropertyName("uuid")] + public string Id { get; set; } + + /// + /// The organization ID this PCU group belongs to. + /// + [JsonPropertyName("orgId")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string OrgId { get; set; } + + /// + /// The title (name) of the PCU group. + /// + [JsonPropertyName("title")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string Title { get; set; } + + /// + /// The cloud provider for this PCU group (e.g. 'AWS'). + /// + [JsonPropertyName("cloudProvider")] + public CloudProviderType? CloudProvider { get; set; } + + /// + /// The region this PCU group is ascribed to. + /// + [JsonPropertyName("region")] + public string Region { get; set; } + + /// + /// The instance type for this PCU group. + /// + [JsonPropertyName("instanceType")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string InstanceType { get; set; } + + /// + /// The PCU type descriptor. + /// + [JsonPropertyName("pcuType")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public PCUType PCUType { get; set; } + + /// + /// The provisioning type (e.g. 'shared'). + /// + [JsonPropertyName("provisionType")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string ProvisionType { get; set; } + + /// + /// The minimum shared hourly PCUs in the group. + /// + [JsonPropertyName("min")] + public int Min { get; set; } + + /// + /// The maximum shared hourly PCUs in the group. + /// + [JsonPropertyName("max")] + public int Max { get; set; } + + /// + /// The absolute required PCUs in the group. + /// + [JsonPropertyName("reserved")] + public int Reserved { get; set; } + + /// + /// A description of the PCU group. + /// + [JsonPropertyName("description")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string Description { get; set; } + + /// + /// Creation time of the PCU group. + /// + [JsonPropertyName("createdAt")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DateTime? CreatedAt { get; set; } + + /// + /// Update time of the PCU group. + /// + [JsonPropertyName("updatedAt")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DateTime? UpdatedAt { get; set; } + + /// + /// Identifier of the user who created the PCU group. + /// + [JsonPropertyName("createdBy")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string CreatedBy { get; set; } + + /// + /// Identifier of the user who updated the PCU group. + /// + [JsonPropertyName("updatedBy")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string UpdatedBy { get; set; } + + /// + /// The current status of the PCU group (e.g. 'INITIALIZING'). + /// + [JsonPropertyName("status")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string Status { get; set; } +} + +/// +/// A PCU (Provisioned Capacity Unit) group type descriptor, +/// describing a specific PCU configuration available in a region. +/// +public class PCUType +{ + /// + /// The type of PCU group (e.g. 'standard'). + /// + [JsonPropertyName("type")] + public string Type { get; set; } + + /// + /// The region where this PCU type is available. + /// + [JsonPropertyName("region")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string Region { get; set; } + + /// + /// The cloud provider for this PCU type (e.g. 'AWS'). + /// + [JsonPropertyName("provider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public CloudProviderType? CloudProvider { get; set; } + + /// + /// Hardware specifications for this PCU type. + /// + [JsonPropertyName("details")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public PCUTypeDetails Details { get; set; } +} + +/// +/// The details of a PCU (Provisioned Capacity Unit) group type, +/// describing the hardware specifications for a particular PCU configuration. +/// +public class PCUTypeDetails +{ + /// + /// The number of virtual CPUs for this PCU type. + /// + [JsonPropertyName("vCPU")] + public int VCpu { get; set; } + + /// + /// The amount of memory for this PCU type. + /// + [JsonPropertyName("memory")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string Memory { get; set; } + + /// + /// The amount of disk cache for this PCU type. + /// + [JsonPropertyName("disk_cache")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string DiskCache { get; set; } +} diff --git a/src/DataStax.AstraDB.DataApi/Core/RegionInfo.cs b/src/DataStax.AstraDB.DataApi/Admin/RegionInfo.cs similarity index 87% rename from src/DataStax.AstraDB.DataApi/Core/RegionInfo.cs rename to src/DataStax.AstraDB.DataApi/Admin/RegionInfo.cs index 50330d73..7e3325f5 100644 --- a/src/DataStax.AstraDB.DataApi/Core/RegionInfo.cs +++ b/src/DataStax.AstraDB.DataApi/Admin/RegionInfo.cs @@ -14,12 +14,12 @@ * limitations under the License. */ -using DataStax.AstraDB.DataApi.Admin; +using DataStax.AstraDB.DataApi.Core; using System; using System.Collections.Generic; using System.Text.Json.Serialization; -namespace DataStax.AstraDB.DataApi.Core; +namespace DataStax.AstraDB.DataApi.Admin; /// /// The metadata information for a region. @@ -73,4 +73,10 @@ public class RegionInfo /// [JsonPropertyName("zone")] public string Zone { get; set; } -} \ No newline at end of file + + /// + /// The types of PCU (Provisioned Capacity Units) available for this region. + /// + [JsonPropertyName("pcu_types")] + public List PCUTypes { get; set; } +} diff --git a/src/DataStax.AstraDB.DataApi/Core/Commands/Command.cs b/src/DataStax.AstraDB.DataApi/Core/Commands/Command.cs index 5ac6c64d..e4e81287 100644 --- a/src/DataStax.AstraDB.DataApi/Core/Commands/Command.cs +++ b/src/DataStax.AstraDB.DataApi/Core/Commands/Command.cs @@ -294,6 +294,8 @@ internal T Deserialize(string input) { deserializeOptions.Converters.Add(new SimpleDictionaryConverter()); } + deserializeOptions.Converters.Add(new CloudProviderTypeConverter()); + deserializeOptions.Converters.Add(new CloudProviderTypeNullableConverter()); deserializeOptions.Converters.Add(new IpAddressConverter()); deserializeOptions.Converters.Add(new AnalyzerOptionsConverter()); diff --git a/src/DataStax.AstraDB.DataApi/Core/DatabaseInfo.cs b/src/DataStax.AstraDB.DataApi/Core/DatabaseInfo.cs index f9b947df..efd41abe 100644 --- a/src/DataStax.AstraDB.DataApi/Core/DatabaseInfo.cs +++ b/src/DataStax.AstraDB.DataApi/Core/DatabaseInfo.cs @@ -32,7 +32,7 @@ internal DatabaseInfo(RawDatabaseInfo rawInfo) OrgId = rawInfo.OrgId; OwnerId = rawInfo.OwnerId; Status = Enum.TryParse(rawInfo.Status, true, out var status) ? status : AstraDatabaseStatus.UNKNOWN; - CloudProvider = Enum.TryParse(rawInfo.Info.CloudProvider, true, out var cloudProvider) ? cloudProvider : AstraDatabaseCloudProvider.AWS; + CloudProvider = Enum.TryParse(rawInfo.Info.CloudProvider, true, out var cloudProvider) ? cloudProvider : CloudProviderType.AWS; CreatedAt = rawInfo.CreationTime; LastUsed = rawInfo.LastUsageTime; Keyspaces = rawInfo.Info.Keyspaces; @@ -51,7 +51,7 @@ internal DatabaseInfo(RawDatabaseInfo rawInfo) /// The current lifecycle status of the database. public AstraDatabaseStatus Status { get; set; } /// The cloud provider where the database is deployed. - public AstraDatabaseCloudProvider CloudProvider { get; set; } + public CloudProviderType CloudProvider { get; set; } /// The date and time when the database was created. public DateTime CreatedAt { get; set; } /// The date and time when the database was last used. @@ -79,19 +79,6 @@ public class AstraDatabaseRegionInfo public string Name { get; set; } } -/// -/// The cloud provider where an Astra database is deployed. -/// -public enum AstraDatabaseCloudProvider -{ - /// Amazon Web Services. - AWS, - /// Google Cloud Platform. - GCP, - /// Microsoft Azure. - AZURE -} - /// /// The lifecycle status of an Astra database. /// diff --git a/src/DataStax.AstraDB.DataApi/Core/UserDefinedTypeField.cs b/src/DataStax.AstraDB.DataApi/Core/UserDefinedTypeField.cs index 56cc86ae..c0092beb 100644 --- a/src/DataStax.AstraDB.DataApi/Core/UserDefinedTypeField.cs +++ b/src/DataStax.AstraDB.DataApi/Core/UserDefinedTypeField.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + namespace DataStax.AstraDB.DataApi.Core; /// diff --git a/src/DataStax.AstraDB.DataApi/SerDes/CloudProviderTypeConverter.cs b/src/DataStax.AstraDB.DataApi/SerDes/CloudProviderTypeConverter.cs new file mode 100644 index 00000000..89f65aeb --- /dev/null +++ b/src/DataStax.AstraDB.DataApi/SerDes/CloudProviderTypeConverter.cs @@ -0,0 +1,78 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using DataStax.AstraDB.DataApi.Admin; +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace DataStax.AstraDB.DataApi.SerDes; + + +/// +/// JSON converter for , with case-insensitive deserialization logic. +/// +public class CloudProviderTypeConverter : JsonConverter +{ + /// + /// Reads and converts values into a , case-insensitively. + /// + public override CloudProviderType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + var value = reader.GetString(); + if (string.Equals(value, "aws", StringComparison.OrdinalIgnoreCase)) return CloudProviderType.AWS; + if (string.Equals(value, "gcp", StringComparison.OrdinalIgnoreCase)) return CloudProviderType.GCP; + if (string.Equals(value, "azure", StringComparison.OrdinalIgnoreCase)) return CloudProviderType.AZURE; + throw new JsonException($"Unknown CloudProviderType value: '{value}'"); + } + + /// + /// Writes an value as string. + /// + public override void Write(Utf8JsonWriter writer, CloudProviderType value, JsonSerializerOptions options) + { + var serialized = value switch + { + CloudProviderType.AWS => "aws", + CloudProviderType.GCP => "gcp", + CloudProviderType.AZURE => "azure", + _ => throw new JsonException($"Unknown CloudProviderType value: '{value}'") + }; + writer.WriteStringValue(serialized); + } +} + +/// +/// JSON converter for ?, with case-insensitive deserialization logic. +/// +public class CloudProviderTypeNullableConverter : JsonConverter +{ + private static readonly CloudProviderTypeConverter _inner = new(); + + /// + public override CloudProviderType? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType == JsonTokenType.Null) return null; + return _inner.Read(ref reader, typeof(CloudProviderType), options); + } + + /// + public override void Write(Utf8JsonWriter writer, CloudProviderType? value, JsonSerializerOptions options) + { + if (value is null) { writer.WriteNullValue(); return; } + _inner.Write(writer, value.Value, options); + } +} diff --git a/src/DataStax.AstraDB.DataApi/Tables/DropUserDefinedTypeRequest.cs b/src/DataStax.AstraDB.DataApi/Tables/DropUserDefinedTypeRequest.cs index 49113c9f..2d7e8fe3 100644 --- a/src/DataStax.AstraDB.DataApi/Tables/DropUserDefinedTypeRequest.cs +++ b/src/DataStax.AstraDB.DataApi/Tables/DropUserDefinedTypeRequest.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using System.Collections.Generic; using System.Text.Json.Serialization; diff --git a/src/DataStax.AstraDB.DataApi/Utils/DeserializationUtils.cs b/src/DataStax.AstraDB.DataApi/Utils/DeserializationUtils.cs index abb39d61..f0203bf6 100644 --- a/src/DataStax.AstraDB.DataApi/Utils/DeserializationUtils.cs +++ b/src/DataStax.AstraDB.DataApi/Utils/DeserializationUtils.cs @@ -1,3 +1,18 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ using System.Linq; using System.Text.Json; diff --git a/src/DataStax.AstraDB.DataApi/Utils/TypeUtilities.cs b/src/DataStax.AstraDB.DataApi/Utils/TypeUtilities.cs index 3f9a7575..293e28e2 100644 --- a/src/DataStax.AstraDB.DataApi/Utils/TypeUtilities.cs +++ b/src/DataStax.AstraDB.DataApi/Utils/TypeUtilities.cs @@ -1,4 +1,18 @@ - +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.Tables; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/AssemblyInfo.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/AssemblyInfo.cs index bc1b946c..fb5c44e1 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/AssemblyInfo.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/AssemblyInfo.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using Xunit; [assembly: CollectionBehavior(DisableTestParallelization = true)] diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Constants.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Constants.cs index 87b5f349..47716091 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Constants.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Constants.cs @@ -1,3 +1,18 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ namespace DataStax.AstraDB.DataApi.IntegrationTests; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/FileLogger.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/FileLogger.cs index 4acefb88..8ded5cef 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/FileLogger.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/FileLogger.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using Microsoft.Extensions.Logging; namespace DataStax.AstraDB.DataApi.IntegrationTests; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/AdminFixture.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/AdminFixture.cs index 77102828..ac5fab1e 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/AdminFixture.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/AdminFixture.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Admin; using DataStax.AstraDB.DataApi.Core; using System.Text.RegularExpressions; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/AssemblyFixture.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/AssemblyFixture.cs index 858ac2da..27517119 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/AssemblyFixture.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/AssemblyFixture.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Admin; using DataStax.AstraDB.DataApi.Core; using Microsoft.Extensions.Configuration; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/BaseFixture.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/BaseFixture.cs index a22f927b..bad8e4f8 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/BaseFixture.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/BaseFixture.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Core; using Microsoft.Extensions.Logging; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/CollectionCursorFixture.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/CollectionCursorFixture.cs index 4f7ab639..cecccfb8 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/CollectionCursorFixture.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/CollectionCursorFixture.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Collections; using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.Core.Query; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/CollectionFARRCursorFixture.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/CollectionFARRCursorFixture.cs index 1f2f863c..7f2ead58 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/CollectionFARRCursorFixture.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/CollectionFARRCursorFixture.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Collections; using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.Core.Query; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/CollectionsFixture.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/CollectionsFixture.cs index a7fd7083..f07d4cc4 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/CollectionsFixture.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/CollectionsFixture.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Collections; using DataStax.AstraDB.DataApi.Core; using Xunit; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/DatabaseFixture.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/DatabaseFixture.cs index e96f0e64..23cb2002 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/DatabaseFixture.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/DatabaseFixture.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Core; using Xunit; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/FindAndUpdateFixture.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/FindAndUpdateFixture.cs index 1713eb24..191ce83a 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/FindAndUpdateFixture.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/FindAndUpdateFixture.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Collections; using DataStax.AstraDB.DataApi.Core; using Xunit; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/ReplaceAndDeleteFixture.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/ReplaceAndDeleteFixture.cs index 5d3e39da..a22a9b9c 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/ReplaceAndDeleteFixture.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/ReplaceAndDeleteFixture.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Collections; using DataStax.AstraDB.DataApi.Core; using Xunit; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/SkipWhenAstraAttribute.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/SkipWhenAstraAttribute.cs index 1bc8edde..21ab3734 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/SkipWhenAstraAttribute.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/SkipWhenAstraAttribute.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using Microsoft.Extensions.Configuration; using System.Reflection; using Xunit.v3; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/SkipWhenNotAstraAttribute.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/SkipWhenNotAstraAttribute.cs index 73afb1d1..818e9c53 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/SkipWhenNotAstraAttribute.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/SkipWhenNotAstraAttribute.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using Microsoft.Extensions.Configuration; using System.Reflection; using Xunit.v3; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/TableAlterFixture.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/TableAlterFixture.cs index 3805e989..9a03093d 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/TableAlterFixture.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/TableAlterFixture.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.Tables; using Xunit; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/TableIndexesFixture.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/TableIndexesFixture.cs index bce1ed60..c0ccb3ac 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/TableIndexesFixture.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/TableIndexesFixture.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.Tables; using Xunit; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/TablesFixture.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/TablesFixture.cs index 7989070d..cea2308a 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/TablesFixture.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/TablesFixture.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.Tables; using DataStax.AstraDB.DataApi.Utils; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/UpdatesFixture.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/UpdatesFixture.cs index be3abe07..407456dc 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/UpdatesFixture.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/UpdatesFixture.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Collections; using DataStax.AstraDB.DataApi.Core; using Xunit; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/UserDefinedTypesFixture.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/UserDefinedTypesFixture.cs index 55251595..53d0f58b 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/UserDefinedTypesFixture.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Fixtures/UserDefinedTypesFixture.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.Tables; using Xunit; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/TestObjects.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/TestObjects.cs index 725d2205..ec05dd7c 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/TestObjects.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/TestObjects.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Collections; using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.SerDes; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/AdditionalCollectionTests.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/AdditionalCollectionTests.cs index 06f68780..08be05ee 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/AdditionalCollectionTests.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/AdditionalCollectionTests.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Collections; using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.Core.Query; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/AdditionalTableTests.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/AdditionalTableTests.cs index dc487ed5..c80c9cc6 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/AdditionalTableTests.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/AdditionalTableTests.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.Core.Commands; using DataStax.AstraDB.DataApi.Core.Query; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/AdminTests.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/AdminTests.cs index 2437d9a0..5f50ebec 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/AdminTests.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/AdminTests.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Admin; using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.Core.Results; @@ -546,6 +562,44 @@ public async Task DatabaseAdminAstra_GetRegions() Assert.NotEmpty(regionsAll); Assert.True(regionsAll.Count >= regionsOnly.Count); + + // region PCU information checks + Assert.NotEmpty(regionsDefault[0].PCUTypes); + var pcu_type = regionsDefault[0].PCUTypes[0]; + Assert.IsType(pcu_type); + Assert.IsType(pcu_type.Type); + Assert.IsType(pcu_type.Details); + } + + [SkipWhenNotAstra] + [Fact(Skip="Run manually when an ORG ADMIN token is used, or this endpoint will error")] + public async Task DatabaseAdminAstra_GetPCUGroups() + { + var admin = fixture.Client.GetAstraDatabasesAdmin(); + + var pcuGroupsFull = await admin.ListPCUGroupsAsync(); + Assert.NotNull(pcuGroupsFull); + + var pcuGroupsFiltered = await admin.ListPCUGroupsAsync(new ListPCUGroupsOptions { + CloudProvider = CloudProviderType.AWS, + Region = "us-west-1" + }); + Assert.NotNull(pcuGroupsFiltered); + + Assert.True(pcuGroupsFull.Count >= pcuGroupsFiltered.Count); + + // bad filtering patterns + await Assert.ThrowsAsync( + () => admin.ListPCUGroupsAsync(new ListPCUGroupsOptions { + Region = "us-west-1" + }) + ); + await Assert.ThrowsAsync( + () => admin.ListPCUGroupsAsync(new ListPCUGroupsOptions { + CloudProvider = CloudProviderType.GCP + }) + ); + } [SkipWhenNotAstra] @@ -609,8 +663,8 @@ public async Task CreateDatabaseNonblockingSync() var admin = fixture.Client.GetAstraDatabasesAdmin().CreateDatabase( new (){ Name = dbName, - CloudProvider = CloudProviderType.GCP, - Region = "europe-west4", + CloudProvider = CloudProviderType.AWS, + Region = "us-west-2", Keyspace = "fedault_seykpace", waitForCompletion = false, } @@ -690,6 +744,82 @@ public async Task CreateDatabaseBlockingAsync() Assert.NotNull(tableNames); } + // dotnet test --filter FullyQualifiedName=DataStax.AstraDB.DataApi.IntegrationTests.AdminTests.CreateDatabaseBadPCUGroupNonblockingAsync + // ENSURE THE TOKEN CAN READ PCU GROUPS FOR THIS TEST (else you'll get another failure and test will fail) + [Fact(Skip = AdminCollection.SkipMessage)] + public async Task CreateDatabaseBadPCUGroupNonblockingAsync() + { + var dbName = "test-db-badpcugroup-create-async-x"; + var creationOptions = new CreateDatabaseOptions() { + Name = dbName, + CloudProvider = CloudProviderType.AWS, + Region = "us-west-2", + waitForCompletion = false, + PCUGroupId = "bad_group_id", + }; + + var astraAdmin = fixture.Client.GetAstraDatabasesAdmin(); + + await Assert.ThrowsAsync(async () => + { + await astraAdmin.CreateDatabaseAsync(creationOptions); + }); + } + + // dotnet test --filter FullyQualifiedName=DataStax.AstraDB.DataApi.IntegrationTests.AdminTests.CreateDatabaseMisplacedPCUGroupNonblockingAsync + // ENSURE THE TOKEN CAN READ PCU GROUPS FOR THIS TEST (else you'll get another failure and test will fail) + [Fact(Skip = AdminCollection.SkipMessage)] + public async Task CreateDatabaseMisplacedPCUGroupNonblockingAsync() + { + var dbName = "test-db-misplacedpcugroup-create-async-x"; + // Manually ensure the PCU Group ID exists, but for another provider/region! + var creationOptions = new CreateDatabaseOptions() { + Name = dbName, + CloudProvider = CloudProviderType.GCP, + Region = "us-east1", + waitForCompletion = false, + PCUGroupId = "8424aa7c-a26b-44cc-8ae3-c65aec7a184f", + }; + + var astraAdmin = fixture.Client.GetAstraDatabasesAdmin(); + + await Assert.ThrowsAsync(async () => + { + await astraAdmin.CreateDatabaseAsync(creationOptions); + }); + } + + // dotnet test --filter FullyQualifiedName=DataStax.AstraDB.DataApi.IntegrationTests.AdminTests.CreateDatabaseCorrectPCUGroupNonblockingAsync + // ENSURE THE TOKEN CAN READ PCU GROUPS FOR THIS TEST (else you'll get another failure and test will fail) + [Fact(Skip = AdminCollection.SkipMessage)] + public async Task CreateDatabaseCorrectPCUGroupNonblockingAsync() + { + var dbName = "test-db-correctpcugroup-create-async-x"; + // Manually ensure the PCU Group ID exists, but for another provider/region! + var creationOptions = new CreateDatabaseOptions() { + Name = dbName, + CloudProvider = CloudProviderType.AWS, + Region = "us-west-2", + waitForCompletion = false, + PCUGroupId = "8424aa7c-a26b-44cc-8ae3-c65aec7a184f", + }; + + var astraAdmin = fixture.Client.GetAstraDatabasesAdmin(); + + var dbAdmin = await astraAdmin.CreateDatabaseAsync(creationOptions); + + var dbStatus = await astraAdmin.GetDatabaseStatusAsync(dbAdmin.Id); + Assert.True(dbStatus == AstraDatabaseStatus.ASSOCIATING + || dbStatus == AstraDatabaseStatus.INITIALIZING + || dbStatus == AstraDatabaseStatus.PENDING); + + var dbAdmin2 = astraAdmin.GetDatabaseAdmin(dbAdmin.GetAPIEndpoint()); + var dbStatus2 = await astraAdmin.GetDatabaseStatusAsync(dbAdmin2.Id); + Assert.True(dbStatus2 == AstraDatabaseStatus.ASSOCIATING + || dbStatus2 == AstraDatabaseStatus.INITIALIZING + || dbStatus2 == AstraDatabaseStatus.PENDING); + } + // dotnet test --filter FullyQualifiedName=DataStax.AstraDB.DataApi.IntegrationTests.AdminTests.DropDatabaseNonblockingSync [Fact(Skip = AdminCollection.SkipMessage)] public void DropDatabaseNonblockingSync() diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/CollectionCursorTests.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/CollectionCursorTests.cs index 808985c7..d0c0e5d5 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/CollectionCursorTests.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/CollectionCursorTests.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Collections; using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.Core.Commands; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/CollectionFARRCursorTests.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/CollectionFARRCursorTests.cs index 64cb40a3..06980b84 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/CollectionFARRCursorTests.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/CollectionFARRCursorTests.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Collections; using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.Core.Commands; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/CollectionTests.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/CollectionTests.cs index 02e36960..42c527a2 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/CollectionTests.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/CollectionTests.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Collections; using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.Core.Commands; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/DatabaseTests.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/DatabaseTests.cs index 3c4657de..45ae0971 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/DatabaseTests.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/DatabaseTests.cs @@ -1,3 +1,20 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using DataStax.AstraDB.DataApi.Admin; using DataStax.AstraDB.DataApi.Collections; using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.Core.Commands; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/ExamplesTests.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/ExamplesTests.cs index 12cd96a2..8b517da9 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/ExamplesTests.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/ExamplesTests.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Collections; using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.IntegrationTests.Fixtures; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/FindAndUpdateTests.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/FindAndUpdateTests.cs index f0abf7fd..c0da2e68 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/FindAndUpdateTests.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/FindAndUpdateTests.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.Core.Query; using DataStax.AstraDB.DataApi.IntegrationTests.Fixtures; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/ReplaceAndDeleteTests.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/ReplaceAndDeleteTests.cs index c1657dd3..40806065 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/ReplaceAndDeleteTests.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/ReplaceAndDeleteTests.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Collections; using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.Core.Query; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/SearchTests.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/SearchTests.cs index e36f3628..62349b4b 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/SearchTests.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/SearchTests.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Collections; using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.Core.Query; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/SerializationTests.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/SerializationTests.cs index 3114f7b7..257d3f41 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/SerializationTests.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/SerializationTests.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Collections; using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.Core.Commands; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/TableAlterTests.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/TableAlterTests.cs index e7566553..b43ec118 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/TableAlterTests.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/TableAlterTests.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.IntegrationTests.Fixtures; using DataStax.AstraDB.DataApi.Tables; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/TableIndexesTests.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/TableIndexesTests.cs index f9074edf..d6d6ecfa 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/TableIndexesTests.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/TableIndexesTests.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Collections; using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.Core.Commands; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/TableTests.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/TableTests.cs index 7f867ef3..47e21694 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/TableTests.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/TableTests.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.Core.Query; using DataStax.AstraDB.DataApi.Core.Results; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/UpdateTests.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/UpdateTests.cs index ed766064..952e1883 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/UpdateTests.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/UpdateTests.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Collections; using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.Core.Query; diff --git a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/UserDefinedTypesTests.cs b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/UserDefinedTypesTests.cs index c4cbd264..f8d224cd 100644 --- a/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/UserDefinedTypesTests.cs +++ b/test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/UserDefinedTypesTests.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.Core.Query; using DataStax.AstraDB.DataApi.IntegrationTests.Fixtures; diff --git a/test/DataStax.AstraDB.DataApi.UnitTests/CollectionFindAndRerankOptionsTests.cs b/test/DataStax.AstraDB.DataApi.UnitTests/CollectionFindAndRerankOptionsTests.cs index db57b6db..f43c99b2 100644 --- a/test/DataStax.AstraDB.DataApi.UnitTests/CollectionFindAndRerankOptionsTests.cs +++ b/test/DataStax.AstraDB.DataApi.UnitTests/CollectionFindAndRerankOptionsTests.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Core; using DataStax.AstraDB.DataApi.Collections; using DataStax.AstraDB.DataApi.Core.Query; diff --git a/test/DataStax.AstraDB.DataApi.UnitTests/CommandOptionsTests.cs b/test/DataStax.AstraDB.DataApi.UnitTests/CommandOptionsTests.cs index 737cc655..204fd637 100644 --- a/test/DataStax.AstraDB.DataApi.UnitTests/CommandOptionsTests.cs +++ b/test/DataStax.AstraDB.DataApi.UnitTests/CommandOptionsTests.cs @@ -1,3 +1,19 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + using DataStax.AstraDB.DataApi.Core; namespace DataStax.AstraDB.DataApi.Tests; diff --git a/test/DataStax.AstraDB.DataApi.UnitTests/PCUGroupDeserializationTests.cs b/test/DataStax.AstraDB.DataApi.UnitTests/PCUGroupDeserializationTests.cs new file mode 100644 index 00000000..9e148267 --- /dev/null +++ b/test/DataStax.AstraDB.DataApi.UnitTests/PCUGroupDeserializationTests.cs @@ -0,0 +1,140 @@ +/* + * Copyright DataStax, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using DataStax.AstraDB.DataApi.Admin; +using DataStax.AstraDB.DataApi.Core; +using DataStax.AstraDB.DataApi.Core.Commands; +using Xunit; + +namespace DataStax.AstraDB.DataApi.UnitTests; + + +public class PCUGroupDeserializationTests +{ + [Fact] + public void FullPCUGroupDeserializationTest() + { + var json = """ + [ + { + "uuid": "9aaddbb5-4622-447c-9bc5-b036bb9d7ed8", + "orgId": "org-id", + "title": "some title", + "cloudProvider": "AWS", + "region": "us-east-1", + "instanceType": "standard", + "pcuType": { + "type": "standard", + "region": "eu-west-1", + "provider": "aws", + "details": { + "vCPU": 0, + "memory": "mstring", + "disk_cache": "dcstring" + } + }, + "provisionType": "shared", + "min": 1, + "max": 1, + "reserved": 1, + "description": "some description", + "createdAt": "2021-06-01T12:00:00.000Z", + "updatedAt": "2021-06-01T12:00:00.000Z", + "createdBy": "user", + "updatedBy": "user", + "status": "INITIALIZING" + } + ] + """; + + // same deserialization setup as in the devops for AstraDatabasesAdmin: + var devOpsOptions = new CommandOptions { SerializeDateAsDollarDate = false }; + var command = new Command("test", new DataAPIClient(), new[] { devOpsOptions }, null); + + var groups = command.Deserialize>(json); + Assert.Single(groups); + + var group = groups[0]; + Assert.IsType(group); + Assert.Equal("org-id", group.OrgId); + Assert.Equal(1, group.Min); + Assert.Equal(new DateTime(2021, 6, 1, 12, 0, 0, DateTimeKind.Utc), group.CreatedAt); + Assert.Equal(CloudProviderType.AWS, group.CloudProvider); + + var pcutype = group.PCUType; + Assert.IsType(pcutype); + Assert.Equal("eu-west-1", pcutype.Region); + Assert.Equal(CloudProviderType.AWS, pcutype.CloudProvider); + + var details = pcutype.Details; + Assert.IsType(details); + Assert.Equal(0, details.VCpu); + Assert.Equal("mstring", details.Memory); + } + + [Fact] + public void IncompleteNoDetailsPCUGroupDeserializationTest() + { + var json = """ + [ + { + "uuid": "9aaddbb5-4622-447c-9bc5-b036bb9d7ed8", + "cloudProvider": "AWS", + "region": "us-east-1", + "pcuType": { + "type": "standard", + "region": "eu-west-1", + "provider": "aws" + } + } + ] + """; + + // same deserialization setup as in the devops for AstraDatabasesAdmin: + var devOpsOptions = new CommandOptions { SerializeDateAsDollarDate = false }; + var command = new Command("test", new DataAPIClient(), new[] { devOpsOptions }, null); + + var groups = command.Deserialize>(json); + Assert.Single(groups); + + var pcutype = groups[0].PCUType; + Assert.Null(pcutype.Details); + } + + [Fact] + public void IncompleteNoTypePCUGroupDeserializationTest() + { + var json = """ + [ + { + "uuid": "9aaddbb5-4622-447c-9bc5-b036bb9d7ed8", + "cloudProvider": "AWS", + "region": "us-east-1" + } + ] + """; + + // same deserialization setup as in the devops for AstraDatabasesAdmin: + var devOpsOptions = new CommandOptions { SerializeDateAsDollarDate = false }; + var command = new Command("test", new DataAPIClient(), new[] { devOpsOptions }, null); + + var groups = command.Deserialize>(json); + Assert.Single(groups); + + var pcutype = groups[0].PCUType; + Assert.Null(pcutype); + } +}