From 79ab7aabece033f5c34d6604ee72caa02dc63daa Mon Sep 17 00:00:00 2001 From: Anudeep Sharma Date: Mon, 31 Oct 2016 16:22:32 -0700 Subject: [PATCH] Added Elastic pools to SQLServer and also added update flow for the elastic pool --- .../models/implementation/ResourceImpl.java | 2 +- .../azure/management/sql/SqlDatabase.java | 14 +-- .../azure/management/sql/SqlElasticPool.java | 118 +++++++++++++++--- .../azure/management/sql/SqlElasticPools.java | 8 ++ .../azure/management/sql/SqlServer.java | 42 +++++++ .../sql/implementation/ElasticPoolsImpl.java | 51 ++++++++ .../sql/implementation/SqlDatabaseImpl.java | 41 +++--- .../sql/implementation/SqlDatabasesImpl.java | 5 +- .../implementation/SqlElasticPoolImpl.java | 22 ++-- .../implementation/SqlElasticPoolsImpl.java | 14 ++- .../sql/implementation/SqlServerImpl.java | 9 +- .../sql/implementation/SqlServerManager.java | 15 +-- .../sql/implementation/SqlServersImpl.java | 9 +- .../sql/SqlServerOperationsTests.java | 81 ++++++------ 14 files changed, 300 insertions(+), 131 deletions(-) create mode 100644 azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/ElasticPoolsImpl.java diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/ResourceImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/ResourceImpl.java index d431a376444b..c277dcf0629f 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/ResourceImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/models/implementation/ResourceImpl.java @@ -54,7 +54,7 @@ public String regionName() { @Override public Region region() { - return Region.fromName(this.regionName()); + return Region.fromLabelOrName(this.regionName()); } @Override diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/SqlDatabase.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/SqlDatabase.java index 4bfbc254387e..34b5908e2754 100644 --- a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/SqlDatabase.java +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/SqlDatabase.java @@ -192,29 +192,21 @@ interface WithElasticPoolName { * @param elasticPoolName for the SQL Database. * @return The next stage of definition. */ - WithCreate withExistingElasticPoolName(String elasticPoolName); + WithCreate withExistingElasticPool(String elasticPoolName); /** * Sets the existing elastic pool for the SQLDatabase. * @param sqlElasticPool for the SQL Database. * @return The next stage of definition. */ - WithCreate withExistingElasticPoolName(SqlElasticPool sqlElasticPool); - - /** - * Sets the new elastic pool for the SQLDatabase, this will create a new elastic pool while creating database. - * @param elasticPoolName name for new elastic pool to be created for the SQL Database. - * @param elasticPoolEdition edition for new elastic pool to be created for the SQL Database. - * @return The next stage of definition. - */ - WithCreate withNewElasticPool(String elasticPoolName, ElasticPoolEditions elasticPoolEdition); + WithCreate withExistingElasticPool(SqlElasticPool sqlElasticPool); /** * Sets the new elastic pool for the SQLDatabase, this will create a new elastic pool while creating database. * @param sqlElasticPool creatable definition for new elastic pool to be created for the SQL Database. * @return The next stage of definition. */ - WithCreate withNewElasticPool(SqlElasticPool.DefinitionStages.WithCreate sqlElasticPool); + WithCreate withNewElasticPool(Creatable sqlElasticPool); } /** diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/SqlElasticPool.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/SqlElasticPool.java index 34d1fa1cc791..54ad447a665c 100644 --- a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/SqlElasticPool.java +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/SqlElasticPool.java @@ -74,7 +74,6 @@ interface Definition extends DefinitionStages.Blank, DefinitionStages.WithEdition, DefinitionStages.WithCreate { - } /** @@ -101,42 +100,69 @@ interface WithEdition { } /** - * A resource definition allowing SQLServer to be attached with SQLDatabase. + * The SQL Elastic Pool definition to set the minimum DTU for database. */ - interface WithSqlServer { + interface WithDatabaseDtuMin { /** - * Creates a new SqlElasticPool resource under SQLServer. + * Sets the minimum DTU all SQL Azure Databases are guaranteed. * - * @param groupName the name of the resource group for SQLServer. - * @param sqlServerName the name of the sQLServer. - * @return the creatable for the child resource + * @param databaseDtuMin minimum DTU for all SQL Azure databases + * @return The next stage of definition. */ - Creatable withExistingSqlServer(String groupName, String sqlServerName); + SqlElasticPool.DefinitionStages.WithCreate withDatabaseDtuMin(int databaseDtuMin); + } + /** + * The SQL Elastic Pool definition to set the maximum DTU for one database. + */ + interface WithDatabaseDtuMax { + /** + * Sets the maximum DTU any one SQL Azure Database can consume. + * + * @param databaseDtuMax maximum DTU any one SQL Azure Database can consume + * @return The next stage of definition. + */ + SqlElasticPool.DefinitionStages.WithCreate withDatabaseDtuMax(int databaseDtuMax); + } + + /** + * The SQL Elastic Pool definition to set the number of shared DTU for elastic pool. + */ + interface WithDtu { /** - * Creates a new SqlElasticPool resource under SQLServer. + * Sets the total shared DTU for the SQL Azure Database Elastic Pool. * - * @param sqlServerCreatable a creatable definition for the SQLServer - * @return the creatable for the SQLDatabase + * @param dtu total shared DTU for the SQL Azure Database Elastic Pool + * @return The next stage of definition. */ - Creatable withNewSqlServer(Creatable sqlServerCreatable); + SqlElasticPool.DefinitionStages.WithCreate withDtu(int dtu); + } + /** + * The SQL Elastic Pool definition to set the storage limit for the SQL Azure Database Elastic Pool in MB. + */ + interface WithStorageCapacity { /** - * Creates a new SqlElasticPool resource under SQLServer. + * Sets the storage limit for the SQL Azure Database Elastic Pool in MB. * - * @param existingSqlServer the SQLServer under which this SqlElasticPool to be created. - * @return the creatable for the SQLDatabase + * @param storageMB storage limit for the SQL Azure Database Elastic Pool in MB + * @return The next stage of definition. */ - Creatable withExistingSqlServer(SqlServer existingSqlServer); + SqlElasticPool.DefinitionStages.WithCreate withStorageCapacity(int storageMB); } + /** * A SQL Server definition with sufficient inputs to create a new * SQL Server in the cloud, but exposing additional optional inputs to * specify. */ interface WithCreate extends - WithSqlServer, - DefinitionWithTags { + Creatable, + DefinitionWithTags, + WithDatabaseDtuMin, + WithDatabaseDtuMax, + WithDtu, + WithStorageCapacity { } } @@ -144,6 +170,10 @@ interface WithCreate extends * The template for a SQLElasticPool update operation, containing all the settings that can be modified. */ interface Update extends + UpdateStages.WithDatabaseDtuMax, + UpdateStages.WithDatabaseDtuMin, + UpdateStages.WithDtu, + UpdateStages.WithStorageCapacity, Appliable { } @@ -151,5 +181,57 @@ interface Update extends * Grouping of all the SQLElasticPool update stages. */ interface UpdateStages { + + /** + * The SQL Elastic Pool definition to set the minimum DTU for database. + */ + interface WithDatabaseDtuMin { + /** + * Sets the minimum DTU all SQL Azure Databases are guaranteed. + * + * @param databaseDtuMin minimum DTU for all SQL Azure databases + * @return The next stage of definition. + */ + Update withDatabaseDtuMin(int databaseDtuMin); + } + + /** + * The SQL Elastic Pool definition to set the maximum DTU for one database. + */ + interface WithDatabaseDtuMax { + /** + * Sets the maximum DTU any one SQL Azure Database can consume. + * + * @param databaseDtuMax maximum DTU any one SQL Azure Database can consume + * @return The next stage of definition. + */ + Update withDatabaseDtuMax(int databaseDtuMax); + } + + /** + * The SQL Elastic Pool definition to set the number of shared DTU for elastic pool. + */ + interface WithDtu { + /** + * Sets the total shared DTU for the SQL Azure Database Elastic Pool. + * + * @param dtu total shared DTU for the SQL Azure Database Elastic Pool + * @return The next stage of definition. + */ + Update withDtu(int dtu); + } + + /** + * The SQL Elastic Pool definition to set the storage limit for the SQL Azure Database Elastic Pool in MB. + */ + interface WithStorageCapacity { + /** + * Sets the storage limit for the SQL Azure Database Elastic Pool in MB. + * + * @param storageMB storage limit for the SQL Azure Database Elastic Pool in MB + * @return The next stage of definition. + */ + Update withStorageCapacity(int storageMB); + } } } diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/SqlElasticPools.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/SqlElasticPools.java index cf08999cd825..447e536dc83d 100644 --- a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/SqlElasticPools.java +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/SqlElasticPools.java @@ -8,6 +8,7 @@ import com.microsoft.azure.PagedList; import com.microsoft.azure.management.apigeneration.Fluent; +import com.microsoft.azure.management.resources.fluentcore.arm.Region; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsDeletingByParent; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; import com.microsoft.azure.management.resources.fluentcore.arm.models.GroupableResource; @@ -61,4 +62,11 @@ public interface SqlElasticPools extends * @return the list of SQLElasticPools in a SQLServer */ PagedList listBySqlServer(GroupableResource sqlServer); + + /** + * Entry point to SQL ElasticPool management API, which already have the SQLServer specified. + */ + interface SqlElasticPoolsCreatable extends SqlElasticPools { + SqlElasticPool.DefinitionStages.Blank definedWithSqlServer(String resourceGroupName, String sqlServerName, String elasticPoolName, Region region); + } } diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/SqlServer.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/SqlServer.java index fbaa1efc2616..061e332200d2 100644 --- a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/SqlServer.java +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/SqlServer.java @@ -48,6 +48,12 @@ public interface SqlServer extends */ FirewallRules firewallRules(); + + /** + * @return returns entry point to manage ElasticPools in SqlServer. + */ + ElasticPools elasticPools(); + /** * Entry point to access FirewallRules from the SQL Server. */ @@ -82,6 +88,42 @@ interface FirewallRules { */ void delete(String firewallRuleName); } + + /** + * Entry point to access FirewallRules from the SQL Server. + */ + interface ElasticPools { + /** + * Gets a particular elastic pool. + * + * @param elasticPoolName name of the elastic pool to get + * @return Returns the elastic pool rule with in the SQL Server + */ + SqlElasticPool get(String elasticPoolName); + + /** + * Creates a new elastic pool in SQL Server. + * + * @param elasticPoolName name of the elastic pool to be created + * @return Returns a stage to specify arguments of the elastic pool + */ + SqlElasticPool.DefinitionStages.Blank define(String elasticPoolName); + + /** + * Returns all the elastic pools for the server. + * + * @return list of elastic pools for the server. + */ + PagedList list(); + + /** + * Delete specified elastic pool in the server. + * + * @param elasticPoolName name of the elastic pool to delete + */ + void delete(String elasticPoolName); + } + /************************************************************** * Fluent interfaces to provision a SqlServer **************************************************************/ diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/ElasticPoolsImpl.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/ElasticPoolsImpl.java new file mode 100644 index 000000000000..737647a2c2a8 --- /dev/null +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/ElasticPoolsImpl.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.sql.implementation; + +import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.resources.fluentcore.arm.Region; +import com.microsoft.azure.management.sql.SqlElasticPool; +import com.microsoft.azure.management.sql.SqlElasticPools; +import com.microsoft.azure.management.sql.SqlServer; + +/** + * Implementation of SqlServer.FirewallRules, which enables the creating the firewall rules from the SQLServer directly. + */ +public class ElasticPoolsImpl implements SqlServer.ElasticPools { + + private final String resourceGroupName; + private final String sqlServerName; + private final SqlElasticPools.SqlElasticPoolsCreatable elasticPools; + private final Region region; + + ElasticPoolsImpl(ElasticPoolsInner innerCollection, SqlServerManager manager, String resourceGroupName, String sqlServerName, Region region) { + this.resourceGroupName = resourceGroupName; + this.sqlServerName = sqlServerName; + this.region = region; + this.elasticPools = new SqlElasticPoolsImpl(innerCollection, manager); + } + + @Override + public SqlElasticPool get(String firewallRuleName) { + return this.elasticPools.getBySqlServer(this.resourceGroupName, this.sqlServerName, firewallRuleName); + } + + @Override + public SqlElasticPool.DefinitionStages.Blank define(String firewallRuleName) { + return this.elasticPools.definedWithSqlServer(this.resourceGroupName, this.sqlServerName, firewallRuleName, this.region); + } + + @Override + public PagedList list() { + return this.elasticPools.listBySqlServer(this.resourceGroupName, this.sqlServerName); + } + + @Override + public void delete(String firewallRuleName) { + this.elasticPools.deleteByParent(this.resourceGroupName, this.sqlServerName, firewallRuleName); + } +} diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlDatabaseImpl.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlDatabaseImpl.java index 45879580c204..32d31c35d969 100644 --- a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlDatabaseImpl.java +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlDatabaseImpl.java @@ -10,11 +10,9 @@ import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.IndependentChildResourceImpl; import com.microsoft.azure.management.resources.fluentcore.model.Creatable; import com.microsoft.azure.management.sql.DatabaseEditions; -import com.microsoft.azure.management.sql.ElasticPoolEditions; import com.microsoft.azure.management.sql.ServiceObjectiveName; import com.microsoft.azure.management.sql.SqlDatabase; import com.microsoft.azure.management.sql.SqlElasticPool; -import com.microsoft.azure.management.sql.SqlElasticPools; import com.microsoft.azure.management.sql.SqlServer; import org.joda.time.DateTime; import rx.Observable; @@ -37,17 +35,14 @@ public class SqlDatabaseImpl SqlDatabase.Update, IndependentChild.DefinitionStages.WithParentResource { private final DatabasesInner innerCollection; - private final SqlElasticPools sqlElasticPools; - private SqlElasticPool.DefinitionStages.WithCreate creatableSqlElasticPool; + private Creatable sqlElasticPoolCreatable; private String elasticPoolCreatableKey; protected SqlDatabaseImpl(String name, DatabaseInner innerObject, - DatabasesInner innerCollection, - SqlElasticPools sqlElasticPools) { + DatabasesInner innerCollection) { super(name, innerObject); this.innerCollection = innerCollection; - this.sqlElasticPools = sqlElasticPools; } @Override @@ -156,7 +151,7 @@ protected Observable createChildResourceAsync() { final SqlDatabase self = this; if (this.elasticPoolCreatableKey != null) { SqlElasticPool sqlElasticPool = (SqlElasticPool) this.createdResource(this.elasticPoolCreatableKey); - withExistingElasticPoolName(sqlElasticPool); + withExistingElasticPool(sqlElasticPool); } return this.innerCollection.createOrUpdateAsync(this.resourceGroupName(), this.sqlServerName(), this.name(), this.inner()) .map(new Func1() { @@ -182,48 +177,42 @@ public SqlDatabaseImpl withEdition(DatabaseEditions edition) { } @Override - public SqlDatabaseImpl withExistingElasticPoolName(String elasticPoolName) { + public SqlDatabaseImpl withExistingElasticPool(String elasticPoolName) { this.inner().withElasticPoolName(elasticPoolName); return this; } @Override - public SqlDatabaseImpl withExistingElasticPoolName(SqlElasticPool sqlElasticPool) { - return this.withExistingElasticPoolName(sqlElasticPool.name()); + public SqlDatabaseImpl withExistingElasticPool(SqlElasticPool sqlElasticPool) { + return this.withExistingElasticPool(sqlElasticPool.name()); } @Override - public SqlDatabaseImpl withNewElasticPool(String elasticPoolName, ElasticPoolEditions elasticPoolEdition) { - creatableSqlElasticPool = this.sqlElasticPools.define(elasticPoolName).withEdition(elasticPoolEdition); - return this.withExistingElasticPoolName(elasticPoolName); - } - - @Override - public SqlDatabaseImpl withNewElasticPool(SqlElasticPool.DefinitionStages.WithCreate sqlElasticPool) { - creatableSqlElasticPool = sqlElasticPool; + public SqlDatabaseImpl withNewElasticPool(Creatable sqlElasticPool) { + sqlElasticPoolCreatable = sqlElasticPool; return this; } @Override public Creatable withExistingSqlServer(String groupName, String sqlServerName) { - if (creatableSqlElasticPool != null) { - handleElasticPoolCreatable(creatableSqlElasticPool.withExistingSqlServer(groupName, sqlServerName)); + if (sqlElasticPoolCreatable != null) { + handleElasticPoolCreatable(sqlElasticPoolCreatable); } return withExistingParentResource(groupName, sqlServerName); } @Override public Creatable withNewSqlServer(Creatable sqlServerCreatable) { - if (creatableSqlElasticPool != null) { - handleElasticPoolCreatable(creatableSqlElasticPool.withNewSqlServer(sqlServerCreatable)); + if (sqlElasticPoolCreatable != null) { + handleElasticPoolCreatable(sqlElasticPoolCreatable); } return withNewParentResource(sqlServerCreatable); } @Override public Creatable withExistingSqlServer(SqlServer existingSqlServer) { - if (creatableSqlElasticPool != null) { - handleElasticPoolCreatable(creatableSqlElasticPool.withExistingSqlServer(existingSqlServer)); + if (sqlElasticPoolCreatable != null) { + handleElasticPoolCreatable(sqlElasticPoolCreatable); } return withExistingParentResource(existingSqlServer); } @@ -234,6 +223,6 @@ void handleElasticPoolCreatable(Creatable sqlElasticPoolCreatabl this.elasticPoolCreatableKey = sqlElasticPoolCreatable.key(); this.addCreatableDependency(sqlElasticPoolCreatable); } - this.creatableSqlElasticPool = null; + this.sqlElasticPoolCreatable = null; } } diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlDatabasesImpl.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlDatabasesImpl.java index f590042c58e5..ab3f444903d8 100644 --- a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlDatabasesImpl.java +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlDatabasesImpl.java @@ -39,8 +39,7 @@ protected SqlDatabaseImpl wrapModel(String name) { return new SqlDatabaseImpl( name, inner, - this.innerCollection, - manager.sqlElasticPools()); + this.innerCollection); } @Override @@ -59,7 +58,7 @@ protected SqlDatabaseImpl wrapModel(DatabaseInner inner) { return null; } - return new SqlDatabaseImpl(inner.name(), inner, this.innerCollection, manager.sqlElasticPools()); + return new SqlDatabaseImpl(inner.name(), inner, this.innerCollection); } @Override diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlElasticPoolImpl.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlElasticPoolImpl.java index 3d8b61ae661d..1aa07527f297 100644 --- a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlElasticPoolImpl.java +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlElasticPoolImpl.java @@ -8,7 +8,6 @@ import com.microsoft.azure.management.resources.fluentcore.arm.models.IndependentChild; import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.IndependentChildResourceImpl; -import com.microsoft.azure.management.resources.fluentcore.model.Creatable; import com.microsoft.azure.management.sql.ElasticPoolEditions; import com.microsoft.azure.management.sql.ElasticPoolState; import com.microsoft.azure.management.sql.SqlElasticPool; @@ -106,17 +105,26 @@ public SqlElasticPoolImpl withEdition(ElasticPoolEditions edition) { } @Override - public Creatable withExistingSqlServer(String groupName, String sqlServerName) { - return this.withExistingParentResource(groupName, sqlServerName); + public SqlElasticPoolImpl withDatabaseDtuMin(int databaseDtuMin) { + this.inner().withDatabaseDtuMin(databaseDtuMin); + return this; } @Override - public Creatable withNewSqlServer(Creatable sqlServerCreatable) { - return this.withNewParentResource(sqlServerCreatable); + public SqlElasticPoolImpl withDatabaseDtuMax(int databaseDtuMax) { + this.inner().withDatabaseDtuMax(databaseDtuMax); + return this; } @Override - public Creatable withExistingSqlServer(SqlServer existingSqlServer) { - return this.withExistingParentResource(existingSqlServer); + public SqlElasticPoolImpl withDtu(int dtu) { + this.inner().withDtu(dtu); + return this; + } + + @Override + public SqlElasticPoolImpl withStorageCapacity(int storageMB) { + this.inner().withStorageMB(storageMB); + return this; } } diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlElasticPoolsImpl.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlElasticPoolsImpl.java index 91e3c8f9a073..f3c7d05834e3 100644 --- a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlElasticPoolsImpl.java +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlElasticPoolsImpl.java @@ -8,6 +8,7 @@ import com.microsoft.azure.PagedList; import com.microsoft.azure.management.apigeneration.LangDefinition; +import com.microsoft.azure.management.resources.fluentcore.arm.Region; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByParent; import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByParent; import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.IndependentChildResourcesImpl; @@ -26,7 +27,7 @@ public class SqlElasticPoolsImpl extends IndependentChildResourcesImpl< ElasticPoolInner, ElasticPoolsInner, SqlServerManager> - implements SqlElasticPools, + implements SqlElasticPools.SqlElasticPoolsCreatable, SupportsGettingByParent, SupportsListingByParent { protected SqlElasticPoolsImpl(ElasticPoolsInner innerCollection, SqlServerManager manager) { @@ -90,4 +91,15 @@ public PagedList listBySqlServer(String resourceGroupName, Strin public PagedList listBySqlServer(GroupableResource sqlServer) { return this.listByParent(sqlServer); } + + @Override + public SqlElasticPool.DefinitionStages.Blank definedWithSqlServer(String resourceGroupName, String sqlServerName, String elasticPoolName, Region region) { + ElasticPoolInner inner = new ElasticPoolInner(); + inner.withLocation(region.name()); + + return new SqlElasticPoolImpl( + elasticPoolName, + inner, + this.innerCollection).withExistingParentResource(resourceGroupName, sqlServerName); + } } diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlServerImpl.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlServerImpl.java index b4f7b2d4117b..c5a50256b83b 100644 --- a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlServerImpl.java +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlServerImpl.java @@ -29,13 +29,15 @@ public class SqlServerImpl SqlServer.Definition, SqlServer.Update { private final ServersInner innerCollection; + private final ElasticPoolsInner elasticPoolsInner; protected SqlServerImpl(String name, ServerInner innerObject, ServersInner innerCollection, - SqlServerManager manager) { + SqlServerManager manager, ElasticPoolsInner elasticPoolsInner) { super(name, innerObject, manager); this.innerCollection = innerCollection; + this.elasticPoolsInner = elasticPoolsInner; } @Override @@ -81,6 +83,11 @@ public FirewallRules firewallRules() { return new FirewallRulesImpl(this.innerCollection, this.myManager, this.resourceGroupName(), this.name()); } + @Override + public ElasticPools elasticPools() { + return new ElasticPoolsImpl(this.elasticPoolsInner, this.myManager, this.resourceGroupName(), this.name(), this.region()); + } + @Override public SqlServerImpl withAdminUserName(String administratorUserName) { this.inner().withAdministratorLogin(administratorUserName); diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlServerManager.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlServerManager.java index ea0adec14cc2..d830b2435573 100644 --- a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlServerManager.java +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlServerManager.java @@ -12,7 +12,6 @@ import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.Manager; import com.microsoft.azure.management.sql.SqlDatabases; -import com.microsoft.azure.management.sql.SqlElasticPools; import com.microsoft.azure.management.sql.SqlServers; /** @@ -21,7 +20,6 @@ public class SqlServerManager extends Manager { private SqlServers sqlServers; private SqlDatabases sqlDatabases; - private SqlElasticPools sqlElasticPools; protected SqlServerManager(RestClient restClient, String subscriptionId) { super( @@ -96,6 +94,7 @@ public SqlServers sqlServers() { if (sqlServers == null) { sqlServers = new SqlServersImpl( super.innerManagementClient.servers(), + super.innerManagementClient.elasticPools(), this); } @@ -114,16 +113,4 @@ public SqlDatabases sqlDatabases() { return sqlDatabases; } - - /** - * @return the SQL ElasticPool management API entry point - */ - public SqlElasticPools sqlElasticPools() { - if (sqlElasticPools == null) { - sqlElasticPools = new SqlElasticPoolsImpl( - super.innerManagementClient.elasticPools(), - this); - } - return sqlElasticPools; - } } diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlServersImpl.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlServersImpl.java index 093b7dc8d221..1eac0312e2a1 100644 --- a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlServersImpl.java +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/SqlServersImpl.java @@ -15,10 +15,13 @@ public class SqlServersImpl extends GroupableResourcesImpl implements SqlServers { + private final ElasticPoolsInner elasticPoolsInner; + protected SqlServersImpl( ServersInner innerCollection, - SqlServerManager manager) { + ElasticPoolsInner elasticPoolsInner, SqlServerManager manager) { super(innerCollection, manager); + this.elasticPoolsInner = elasticPoolsInner; } @Override @@ -34,7 +37,7 @@ protected SqlServerImpl wrapModel(String name) { name, inner, this.innerCollection, - super.myManager); + super.myManager, this.elasticPoolsInner); } @Override @@ -58,7 +61,7 @@ protected SqlServerImpl wrapModel(ServerInner inner) { inner.name(), inner, this.innerCollection, - this.myManager); + this.myManager, this.elasticPoolsInner); } @Override diff --git a/azure-mgmt-sql/src/test/java/com/microsoft/azure/management/sql/SqlServerOperationsTests.java b/azure-mgmt-sql/src/test/java/com/microsoft/azure/management/sql/SqlServerOperationsTests.java index 6090eb3bf118..5c16a634ea2e 100644 --- a/azure-mgmt-sql/src/test/java/com/microsoft/azure/management/sql/SqlServerOperationsTests.java +++ b/azure-mgmt-sql/src/test/java/com/microsoft/azure/management/sql/SqlServerOperationsTests.java @@ -112,37 +112,27 @@ public void canCRUDSqlDatabase() throws Exception { @Test public void canCRUDSqlDatabaseWithElasticPool() throws Exception { // Create - Creatable sqlServerCreatable = sqlServerManager.sqlServers() - .define(SQL_SERVER_NAME) - .withRegion(Region.US_CENTRAL) - .withNewResourceGroup(RG_NAME) - .withAdminUserName("userName") - .withPassword("P@ssword~1") - .withVersion(ServerVersion.ONE_TWO_FULL_STOP_ZERO); + SqlServer sqlServer = createSqlServer(); + + Creatable sqlElasticPoolCreatable = sqlServer.elasticPools() + .define(SQL_ELASTIC_POOL_NAME) + .withEdition(ElasticPoolEditions.STANDARD); SqlDatabase sqlDatabase = sqlServerManager.sqlDatabases() .define(SQL_DATABASE_NAME) .withCollation(COLLATION) .withEdition(DatabaseEditions.STANDARD) - .withNewElasticPool( - sqlServerManager.sqlElasticPools() - .define(SQL_ELASTIC_POOL_NAME) - .withEdition(ElasticPoolEditions.STANDARD)) - .withNewSqlServer(sqlServerCreatable) + .withNewElasticPool(sqlElasticPoolCreatable) + .withExistingSqlServer(sqlServer) .createAsync().toBlocking().first(); validateSqlDatabase(sqlDatabase); - SqlServer sqlServer = sqlServerManager.sqlServers().getByGroup(RG_NAME, SQL_SERVER_NAME); + sqlServer = sqlServerManager.sqlServers().getByGroup(RG_NAME, SQL_SERVER_NAME); validateSqlServer(sqlServer); // Get Elastic pool - SqlElasticPool sqlElasticPool = sqlServerManager.sqlElasticPools().getBySqlServer(RG_NAME, SQL_SERVER_NAME, SQL_ELASTIC_POOL_NAME); - validateSqlElasticPool(sqlElasticPool); - - validateSqlElasticPool(sqlServerManager.sqlElasticPools().getById(sqlElasticPool.id())); - validateSqlElasticPool(sqlServerManager.sqlElasticPools().getBySqlServer(sqlServer, SQL_ELASTIC_POOL_NAME)); - validateSqlElasticPool(sqlServerManager.sqlElasticPools().getBySqlServer(sqlServer.resourceGroupName(), sqlServer.name(), SQL_ELASTIC_POOL_NAME)); + validateSqlElasticPool(sqlServer.elasticPools().get(SQL_ELASTIC_POOL_NAME)); // Get validateSqlDatabaseWithElasticPool(sqlServerManager.sqlDatabases().getById(sqlDatabase.id())); @@ -156,12 +146,14 @@ public void canCRUDSqlDatabaseWithElasticPool() throws Exception { sqlServerManager.sqlDatabases().deleteById(sqlDatabase.id()); validateSqlDatabaseNotFound(SQL_DATABASE_NAME); - // Add another database to the server + SqlElasticPool sqlElasticPool = sqlServer.elasticPools().get(SQL_ELASTIC_POOL_NAME); + + // Add another database to the server and pool. sqlDatabase = sqlServerManager.sqlDatabases() .define("newDatabase") .withCollation(COLLATION) .withEdition(DatabaseEditions.STANDARD) - .withExistingElasticPoolName(sqlElasticPool) + .withExistingElasticPool(sqlElasticPool) .withExistingSqlServer(sqlServer) .createAsync().toBlocking().first(); sqlServerManager.sqlDatabases().deleteByParent(sqlDatabase.resourceGroupName(), sqlDatabase.sqlServerName(), sqlDatabase.name()); @@ -174,45 +166,42 @@ public void canCRUDSqlDatabaseWithElasticPool() throws Exception { @Test public void canCRUDSqlElasticPool() throws Exception { // Create - Creatable sqlServerCreatable = sqlServerManager.sqlServers() - .define(SQL_SERVER_NAME) - .withRegion(Region.US_CENTRAL) - .withNewResourceGroup(RG_NAME) - .withAdminUserName("userName") - .withPassword("P@ssword~1") - .withVersion(ServerVersion.ONE_TWO_FULL_STOP_ZERO); + SqlServer sqlServer = createSqlServer(); + + sqlServer = sqlServerManager.sqlServers().getByGroup(RG_NAME, SQL_SERVER_NAME); + validateSqlServer(sqlServer); - SqlElasticPool sqlElasticPool = sqlServerManager.sqlElasticPools() + SqlElasticPool sqlElasticPool = sqlServer.elasticPools() .define(SQL_ELASTIC_POOL_NAME) .withEdition(ElasticPoolEditions.STANDARD) - .withNewSqlServer(sqlServerCreatable) .createAsync().toBlocking().first(); - validateSqlElasticPool(sqlElasticPool); + sqlElasticPool = sqlElasticPool.update() + .withDtu(100) + .withDatabaseDtuMax(20) + .withDatabaseDtuMin(10) + .withStorageCapacity(102400).apply(); - SqlServer sqlServer = sqlServerManager.sqlServers().getByGroup(RG_NAME, SQL_SERVER_NAME); - validateSqlServer(sqlServer); + validateSqlElasticPool(sqlElasticPool); // Get - validateSqlElasticPool(sqlServerManager.sqlElasticPools().getById(sqlElasticPool.id())); - validateSqlElasticPool(sqlServerManager.sqlElasticPools().getBySqlServer(sqlServer, SQL_ELASTIC_POOL_NAME)); - validateSqlElasticPool(sqlServerManager.sqlElasticPools().getBySqlServer(sqlServer.resourceGroupName(), sqlServer.name(), SQL_ELASTIC_POOL_NAME)); + validateSqlElasticPool(sqlServer.elasticPools().get(SQL_ELASTIC_POOL_NAME)); // List - validateListSqlElasticPool(sqlServerManager.sqlElasticPools().listBySqlServer(sqlServer.resourceGroupName(), sqlServer.name())); - validateListSqlElasticPool(sqlServerManager.sqlElasticPools().listBySqlServer(sqlServer)); + validateListSqlElasticPool(sqlServer.elasticPools().list()); - sqlServerManager.sqlElasticPools().deleteById(sqlElasticPool.id()); - validateSqlElasticPoolNotFound(SQL_ELASTIC_POOL_NAME); + // Delete + sqlServer.elasticPools().delete(SQL_ELASTIC_POOL_NAME); + validateSqlElasticPoolNotFound(sqlServer, SQL_ELASTIC_POOL_NAME); // Add another database to the server - sqlElasticPool = sqlServerManager.sqlElasticPools() + sqlElasticPool = sqlServer.elasticPools() .define("newElasticPool") .withEdition(ElasticPoolEditions.STANDARD) - .withExistingSqlServer(sqlServer) .createAsync().toBlocking().first(); - sqlServerManager.sqlElasticPools().deleteByParent(sqlElasticPool.resourceGroupName(), sqlElasticPool.sqlServerName(), sqlElasticPool.name()); - validateSqlElasticPoolNotFound("newElasticPool"); + + sqlServer.elasticPools().delete(sqlElasticPool.name()); + validateSqlElasticPoolNotFound(sqlServer, "newElasticPool"); sqlServerManager.sqlServers().deleteByGroup(sqlServer.resourceGroupName(), sqlServer.name()); validateSqlServerNotFound(sqlServer); @@ -275,8 +264,8 @@ private static void validateSqlFirewallRuleNotFound() { } - private static void validateSqlElasticPoolNotFound(String elasticPoolName) { - Assert.assertNull(sqlServerManager.sqlElasticPools().getBySqlServer(RG_NAME, SQL_SERVER_NAME, elasticPoolName)); + private static void validateSqlElasticPoolNotFound(SqlServer sqlServer, String elasticPoolName) { + Assert.assertNull(sqlServer.elasticPools().get(elasticPoolName)); } private static void validateSqlDatabaseNotFound(String newDatabase) {