public PSClusterResourceProperties(ClusterResourceProperties clusterProperties) { if (clusterProperties == null) { return; } GossipCertificates = new List <PSCertificate>(); foreach (Certificate gossipCertificate in clusterProperties.GossipCertificates) { GossipCertificates.Add(new PSCertificate(gossipCertificate?.Pem)); } ExternalGossipCertificates = new List <PSCertificate>(); foreach (Certificate externalGossipCertificate in clusterProperties.ExternalGossipCertificates) { ExternalGossipCertificates.Add(new PSCertificate(externalGossipCertificate?.Pem)); } ClientCertificates = new List <PSCertificate>(); foreach (Certificate ClientCertificate in clusterProperties.ClientCertificates) { ClientCertificates.Add(new PSCertificate(ClientCertificate?.Pem)); } RepairEnabled = clusterProperties.RepairEnabled; PrometheusEndpoint = new PSSeedNode(clusterProperties.PrometheusEndpoint?.IpAddress); HoursBetweenBackups = clusterProperties.HoursBetweenBackups; InitialCassandraAdminPassword = clusterProperties.InitialCassandraAdminPassword; AuthenticationMethod = clusterProperties.AuthenticationMethod; ClusterNameOverride = clusterProperties.ClusterNameOverride; CassandraVersion = clusterProperties.CassandraVersion; DelegatedManagementSubnetId = clusterProperties.DelegatedManagementSubnetId; RestoreFromBackupId = clusterProperties.RestoreFromBackupId; ProvisioningState = clusterProperties.ProvisioningState; ExternalSeedNodes = new List <PSSeedNode>(); foreach (SeedNode externalSeedNode in clusterProperties.ExternalSeedNodes ?? Enumerable.Empty <SeedNode>()) { ExternalSeedNodes.Add(new PSSeedNode(externalSeedNode?.IpAddress)); } SeedNodes = new List <PSSeedNode>(); foreach (SeedNode seedNode in clusterProperties.SeedNodes) { SeedNodes.Add(new PSSeedNode(seedNode?.IpAddress)); } }
internal ClusterResourceData(ResourceIdentifier id, string name, ResourceType resourceType, SystemData systemData, IDictionary <string, string> tags, AzureLocation location, SystemAssignedServiceIdentity identity, ClusterResourceProperties properties) : base(id, name, resourceType, systemData, tags, location, identity) { Properties = properties; }
internal static AppPlatformServiceResourceData DeserializeAppPlatformServiceResourceData(JsonElement element) { Optional <ClusterResourceProperties> properties = default; Optional <AppPlatformSku> sku = default; IDictionary <string, string> tags = default; AzureLocation location = default; ResourceIdentifier id = default; string name = default; ResourceType type = default; SystemData systemData = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("properties")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } properties = ClusterResourceProperties.DeserializeClusterResourceProperties(property.Value); continue; } if (property.NameEquals("sku")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } sku = AppPlatformSku.DeserializeAppPlatformSku(property.Value); continue; } if (property.NameEquals("tags")) { Dictionary <string, string> dictionary = new Dictionary <string, string>(); foreach (var property0 in property.Value.EnumerateObject()) { dictionary.Add(property0.Name, property0.Value.GetString()); } tags = dictionary; continue; } if (property.NameEquals("location")) { location = new AzureLocation(property.Value.GetString()); continue; } if (property.NameEquals("id")) { id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("name")) { name = property.Value.GetString(); continue; } if (property.NameEquals("type")) { type = new ResourceType(property.Value.GetString()); continue; } if (property.NameEquals("systemData")) { systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString()); continue; } } return(new AppPlatformServiceResourceData(id, name, type, systemData, tags, location, properties.Value, sku.Value)); }
internal AppPlatformServiceResourceData(ResourceIdentifier id, string name, ResourceType resourceType, SystemData systemData, IDictionary <string, string> tags, AzureLocation location, ClusterResourceProperties properties, AppPlatformSku sku) : base(id, name, resourceType, systemData, tags, location) { Properties = properties; Sku = sku; }
public void ManagedCassandraCRUDTests() { var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { // Create client CosmosDBManagementClient cosmosDBManagementClient = CosmosDBTestUtilities.GetCosmosDBClient(context, handler); ResourceManagementClient resourcesClient = CosmosDBTestUtilities.GetResourceManagementClient(context, handler2); string resourceGroupName = CosmosDBTestUtilities.CreateResourceGroup(resourcesClient); try { string clusterName = TestUtilities.GenerateName("managedcluster"); string dcName = TestUtilities.GenerateName("managedDC"); this.output.WriteLine($"Creating cluster {clusterName} in resource group {resourceGroupName}."); string subnetId = CreateVirtualNetwork(resourcesClient, resourceGroupName); this.output.WriteLine($"Created subnet {subnetId}."); var clusterProperties = new ClusterResourceProperties { DelegatedManagementSubnetId = subnetId, InitialCassandraAdminPassword = "******", ExternalSeedNodes = new List <SeedNode> { new SeedNode { IpAddress = "10.0.1.1" } } }; var clusterPutResource = new ClusterResource { Location = "East US 2", Properties = clusterProperties }; this.output.WriteLine($"Cluster create request body:"); this.output.WriteLine(JsonConvert.SerializeObject(clusterPutResource, Formatting.Indented)); ClusterResource clusterResource = cosmosDBManagementClient.CassandraClusters .CreateUpdateWithHttpMessagesAsync(resourceGroupName: resourceGroupName, clusterName: clusterName, body: clusterPutResource).GetAwaiter().GetResult().Body; this.output.WriteLine($"Cluster create response:"); this.output.WriteLine(JsonConvert.SerializeObject(clusterResource, Formatting.Indented)); Assert.Equal(subnetId, clusterResource.Properties.DelegatedManagementSubnetId); Assert.Null(clusterResource.Properties.InitialCassandraAdminPassword); Assert.Equal("Cassandra", clusterResource.Properties.AuthenticationMethod); Assert.Equal("Succeeded", clusterResource.Properties.ProvisioningState); Assert.NotNull(clusterResource.Properties.ExternalSeedNodes); Assert.Equal(1, clusterResource.Properties.ExternalSeedNodes.Count); Assert.Equal("10.0.1.1", clusterResource.Properties.ExternalSeedNodes[0].IpAddress); clusterPutResource.Properties.ExternalSeedNodes = new List <SeedNode> { new SeedNode { IpAddress = "192.168.12.1" } }; this.output.WriteLine(""); this.output.WriteLine("Updating cluster. Put body:"); this.output.WriteLine(JsonConvert.SerializeObject(clusterPutResource, Formatting.Indented)); ClusterResource clusterResource2 = cosmosDBManagementClient.CassandraClusters .CreateUpdateWithHttpMessagesAsync(resourceGroupName: resourceGroupName, clusterName: clusterName, body: clusterPutResource).GetAwaiter().GetResult().Body; this.output.WriteLine("Response:"); this.output.WriteLine(JsonConvert.SerializeObject(clusterResource2, Formatting.Indented)); Assert.Equal(clusterName, clusterResource2.Name); Assert.Equal("East US 2", clusterResource2.Location); Assert.Equal(subnetId, clusterResource2.Properties.DelegatedManagementSubnetId); Assert.Null(clusterResource2.Properties.InitialCassandraAdminPassword); Assert.Equal("Cassandra", clusterResource2.Properties.AuthenticationMethod); Assert.Null(clusterResource2.Properties.CassandraVersion); Assert.Equal("Succeeded", clusterResource2.Properties.ProvisioningState); Assert.NotNull(clusterResource2.Properties.ExternalSeedNodes); Assert.NotEmpty(clusterResource2.Properties.ExternalSeedNodes); DataCenterResource dataCenterPutResource = new DataCenterResource { Properties = new DataCenterResourceProperties { DataCenterLocation = "East US 2", DelegatedSubnetId = subnetId, NodeCount = 3, } }; this.output.WriteLine($"Creating data center {dcName}. Put request:"); this.output.WriteLine(JsonConvert.SerializeObject(dataCenterPutResource, Formatting.Indented)); DataCenterResource dcResource = cosmosDBManagementClient.CassandraDataCenters .CreateUpdateWithHttpMessagesAsync(resourceGroupName, clusterName, dcName, dataCenterPutResource).GetAwaiter().GetResult().Body; this.output.WriteLine("Response:"); this.output.WriteLine(JsonConvert.SerializeObject(dcResource, Formatting.Indented)); Assert.Equal("East US 2", dcResource.Properties.DataCenterLocation); Assert.Equal(subnetId, dcResource.Properties.DelegatedSubnetId); Assert.Equal(3, dcResource.Properties.NodeCount); Assert.Equal(3, dcResource.Properties.SeedNodes.Count); this.output.WriteLine($"Deleting data center {dcName}."); cosmosDBManagementClient.CassandraDataCenters .DeleteWithHttpMessagesAsync(resourceGroupName, clusterName, dcName).GetAwaiter().GetResult(); this.output.WriteLine($"Deleting cluster {clusterName}."); cosmosDBManagementClient.CassandraClusters .DeleteWithHttpMessagesAsync(resourceGroupName, clusterName).GetAwaiter().GetResult(); this.output.WriteLine("Deleting deployment of vnets."); cosmosDBManagementClient.CassandraClusters .DeleteWithHttpMessagesAsync(resourceGroupName, clusterName).GetAwaiter().GetResult(); } finally { this.output.WriteLine("Deleting resource group."); resourcesClient.Deployments.Delete(resourceGroupName, ManagedCassandraResourcesOperationsTests.VnetDeploymentName); resourcesClient.ResourceGroups.Delete(resourceGroupName); } } }
public async Task ManagedCassandraCRUDTests() { using (var context = MockContext.Start(this.GetType())) { var location = this.fixture.Location; fixture.Init(context); var clusterClient = this.fixture.CosmosDBManagementClient.CassandraClusters; var dcClient = this.fixture.CosmosDBManagementClient.CassandraDataCenters; string clusterName = TestUtilities.GenerateName("managedcluster"); string dcName = TestUtilities.GenerateName("managedDC"); this.output.WriteLine($"Creating cluster {clusterName} in resource group {this.fixture.ResourceGroupName}."); string subnetId = CreateVirtualNetwork(location); this.output.WriteLine($"Created subnet {subnetId}."); var clusterProperties = new ClusterResourceProperties { DelegatedManagementSubnetId = subnetId, InitialCassandraAdminPassword = "******", ExternalSeedNodes = new List <SeedNode> { new SeedNode { IpAddress = "10.0.1.1" } } }; var clusterPutResource = new ClusterResource { Location = location, Properties = clusterProperties }; this.output.WriteLine($"Cluster create request body:"); this.output.WriteLine(JsonConvert.SerializeObject(clusterPutResource, Formatting.Indented)); ClusterResource clusterResource = (await clusterClient .CreateUpdateWithHttpMessagesAsync(resourceGroupName: this.fixture.ResourceGroupName, clusterName: clusterName, body: clusterPutResource)).Body; this.output.WriteLine($"Cluster create response:"); this.output.WriteLine(JsonConvert.SerializeObject(clusterResource, Formatting.Indented)); Assert.Equal(subnetId, clusterResource.Properties.DelegatedManagementSubnetId); Assert.Null(clusterResource.Properties.InitialCassandraAdminPassword); Assert.Equal("Cassandra", clusterResource.Properties.AuthenticationMethod); Assert.Equal("Succeeded", clusterResource.Properties.ProvisioningState); Assert.NotNull(clusterResource.Properties.ExternalSeedNodes); Assert.Equal(1, clusterResource.Properties.ExternalSeedNodes.Count); Assert.Equal("10.0.1.1", clusterResource.Properties.ExternalSeedNodes[0].IpAddress); clusterPutResource.Properties.ExternalSeedNodes = new List <SeedNode> { new SeedNode { IpAddress = "192.168.12.1" } }; this.output.WriteLine(""); this.output.WriteLine("Updating cluster. Put body:"); this.output.WriteLine(JsonConvert.SerializeObject(clusterPutResource, Formatting.Indented)); ClusterResource clusterResource2 = (await clusterClient .CreateUpdateWithHttpMessagesAsync(resourceGroupName: this.fixture.ResourceGroupName, clusterName: clusterName, body: clusterPutResource)).Body; this.output.WriteLine("Response:"); this.output.WriteLine(JsonConvert.SerializeObject(clusterResource2, Formatting.Indented)); Assert.Equal(clusterName, clusterResource2.Name); Assert.Equal(location.ToLower(), clusterResource2.Location.ToLower()); Assert.Equal(subnetId, clusterResource2.Properties.DelegatedManagementSubnetId); Assert.Null(clusterResource2.Properties.InitialCassandraAdminPassword); Assert.Equal("Cassandra", clusterResource2.Properties.AuthenticationMethod); Assert.Equal("3.11", clusterResource2.Properties.CassandraVersion); Assert.Equal("Succeeded", clusterResource2.Properties.ProvisioningState); Assert.NotNull(clusterResource2.Properties.ExternalSeedNodes); Assert.NotEmpty(clusterResource2.Properties.ExternalSeedNodes); Assert.False(clusterResource2.Properties.Deallocated); DataCenterResource dataCenterPutResource = new DataCenterResource { Properties = new DataCenterResourceProperties { DataCenterLocation = location, DelegatedSubnetId = subnetId, NodeCount = 3 } }; this.output.WriteLine($"Creating data center {dcName}. Put request:"); this.output.WriteLine(JsonConvert.SerializeObject(dataCenterPutResource, Formatting.Indented)); DataCenterResource dcResource = (await dcClient .CreateUpdateWithHttpMessagesAsync(this.fixture.ResourceGroupName, clusterName, dcName, dataCenterPutResource)).Body; this.output.WriteLine("Response:"); this.output.WriteLine(JsonConvert.SerializeObject(dcResource, Formatting.Indented)); Assert.Equal(location.ToLower(), dcResource.Properties.DataCenterLocation.ToLower()); Assert.Equal(subnetId, dcResource.Properties.DelegatedSubnetId); Assert.Equal(3, dcResource.Properties.NodeCount); Assert.Equal(3, dcResource.Properties.SeedNodes.Count); await clusterClient.DeallocateWithHttpMessagesAsync(this.fixture.ResourceGroupName, clusterName); ClusterResource clusterResource3 = await clusterClient.GetAsync(this.fixture.ResourceGroupName, clusterName); Assert.True(clusterResource3.Properties.Deallocated); await clusterClient.StartWithHttpMessagesAsync(this.fixture.ResourceGroupName, clusterName); ClusterResource clusterResource4 = await clusterClient.GetAsync(this.fixture.ResourceGroupName, clusterName); Assert.False(clusterResource4.Properties.Deallocated); this.output.WriteLine($"Deleting data center {dcName}."); await dcClient.DeleteWithHttpMessagesAsync(this.fixture.ResourceGroupName, clusterName, dcName); this.output.WriteLine($"Deleting cluster {clusterName}."); await clusterClient.DeleteWithHttpMessagesAsync(this.fixture.ResourceGroupName, clusterName); } }