From 7e9d4fd3982fb6f529c65e97c1176cd32afbc70e Mon Sep 17 00:00:00 2001 From: Anudeep Sharma Date: Tue, 8 Nov 2016 16:39:30 -0800 Subject: [PATCH] Added replication links and other apis on the database and sql server --- .../implementation/ReadableWrappersImpl.java | 17 +-- .../resources/fluentcore/utils/Utils.java | 23 ++++ .../azure/management/sql/DatabaseMetric.java | 52 ++++++++ .../azure/management/sql/ReplicationLink.java | 81 +++++++++++++ .../azure/management/sql/RestorePoint.java | 54 +++++++++ .../azure/management/sql/ServerMetric.java | 52 ++++++++ .../management/sql/ServerUpgradeResult.java | 31 +++++ .../azure/management/sql/SqlDatabase.java | 60 +++++++++- .../azure/management/sql/SqlElasticPool.java | 2 +- .../azure/management/sql/SqlFirewallRule.java | 2 +- .../azure/management/sql/SqlServer.java | 18 +++ .../implementation/DatabaseMetricImpl.java | 55 +++++++++ .../sql/implementation/DatabasesInner.java | 2 +- .../implementation/ReplicationLinkImpl.java | 108 +++++++++++++++++ .../implementation/ReplicationLinksImpl.java | 53 +++++++++ .../sql/implementation/RestorePointImpl.java | 69 +++++++++++ .../sql/implementation/ServerMetricImpl.java | 55 +++++++++ .../ServerUpgradeResultImpl.java | 34 ++++++ .../sql/implementation/SqlDatabaseImpl.java | 55 ++++++++- .../sql/implementation/SqlServerImpl.java | 32 ++++- .../sql/SqlServerOperationsTests.java | 111 +++++++++++++++++- .../management/sql/SqlServerTestBase.java | 1 + 22 files changed, 941 insertions(+), 26 deletions(-) create mode 100644 azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/DatabaseMetric.java create mode 100644 azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/ReplicationLink.java create mode 100644 azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/RestorePoint.java create mode 100644 azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/ServerMetric.java create mode 100644 azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/ServerUpgradeResult.java create mode 100644 azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/DatabaseMetricImpl.java create mode 100644 azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/ReplicationLinkImpl.java create mode 100644 azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/ReplicationLinksImpl.java create mode 100644 azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/RestorePointImpl.java create mode 100644 azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/ServerMetricImpl.java create mode 100644 azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/ServerUpgradeResultImpl.java diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/ReadableWrappersImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/ReadableWrappersImpl.java index 79cf88793a92..1e0916b45a58 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/ReadableWrappersImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/implementation/ReadableWrappersImpl.java @@ -5,10 +5,9 @@ */ package com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation; -import com.microsoft.azure.Page; import com.microsoft.azure.PagedList; import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter; -import com.microsoft.azure.management.resources.implementation.PageImpl; +import com.microsoft.azure.management.resources.fluentcore.utils.Utils; import java.util.List; @@ -42,16 +41,8 @@ protected PagedList wrapList(PagedList pagedList) { } protected PagedList wrapList(List list) { - PageImpl page = new PageImpl<>(); - page.setItems(list); - page.setNextPageLink(null); - PagedList pagedList = new PagedList(page) { - @Override - public Page nextPage(String nextPageLink) { - return null; - } - }; - - return converter.convert(pagedList); + return converter.convert(Utils.convertToPagedList(list)); } + + } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/utils/Utils.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/utils/Utils.java index 8f2961afa69e..9eeb8ef13bd0 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/utils/Utils.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/utils/Utils.java @@ -6,6 +6,12 @@ package com.microsoft.azure.management.resources.fluentcore.utils; +import com.microsoft.azure.Page; +import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.resources.implementation.PageImpl; + +import java.util.List; + /** * Defines a few utilities. */ @@ -40,6 +46,23 @@ public static String createOdataFilterForTags(String tagName, String tagValue) { } } + /** + * Converts the List to PagedList. + * @param list list to be converted in to paged list + * @param the wrapper inner type + * @return the Paged list for the inner type. + */ + public static PagedList convertToPagedList(List list) { + PageImpl page = new PageImpl<>(); + page.setItems(list); + page.setNextPageLink(null); + return new PagedList(page) { + @Override + public Page nextPage(String nextPageLink) { + return null; + } + }; + } private Utils() { } } diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/DatabaseMetric.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/DatabaseMetric.java new file mode 100644 index 000000000000..e5969e394477 --- /dev/null +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/DatabaseMetric.java @@ -0,0 +1,52 @@ +/** + * 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; + +import com.microsoft.azure.management.apigeneration.Fluent; +import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; +import com.microsoft.azure.management.sql.implementation.DatabaseMetricInner; +import org.joda.time.DateTime; + + +/** + * An immutable client-side representation of an Azure SQL DatabaseMetric. + */ +@Fluent +public interface DatabaseMetric extends + Wrapper { + + /** + * @return the name of the resource + */ + String resourceName(); + + /** + * @return the metric display name + */ + String displayName(); + + /** + * @return the current value of the metric + */ + double currentValue(); + + /** + * @return the current limit of the metric + */ + double limit(); + + /** + * @return the units of the metric + */ + String unit(); + + /** + * @return the next reset time for the metric (ISO8601 format) + */ + DateTime nextResetTime(); +} + diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/ReplicationLink.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/ReplicationLink.java new file mode 100644 index 000000000000..64ceff4e289c --- /dev/null +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/ReplicationLink.java @@ -0,0 +1,81 @@ +/** + * 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; + +import com.microsoft.azure.management.apigeneration.Fluent; +import com.microsoft.azure.management.resources.fluentcore.arm.models.HasId; +import com.microsoft.azure.management.resources.fluentcore.arm.models.HasName; +import com.microsoft.azure.management.resources.fluentcore.arm.models.HasResourceGroup; +import com.microsoft.azure.management.resources.fluentcore.model.Refreshable; +import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; +import com.microsoft.azure.management.sql.implementation.ReplicationLinkInner; +import org.joda.time.DateTime; + + +/** + * An immutable client-side representation of an Azure SQL Replication link. + */ +@Fluent +public interface ReplicationLink extends + Refreshable, + Wrapper, + HasResourceGroup, + HasName, + HasId { + + /** + * @return name of the SQL Server to which this replication belongs + */ + String sqlServerName(); + + /** + * @return name of the SQL Database to which this replication belongs + */ + String databaseName(); + + /** + * @return the name of the Azure SQL Server hosting the partner Azure SQL Database. + */ + String partnerServer(); + + /** + * @return the name of the partner Azure SQL Database + */ + String partnerDatabase(); + + /** + * @return the Azure Region of the partner Azure SQL Database + */ + String partnerLocation(); + + /** + * @return the role of the SQL Database in the replication link + */ + ReplicationRole role(); + + /** + * @return the role of the partner SQL Database in the replication link + */ + ReplicationRole partnerRole(); + + /** + * @return start time for the replication link (ISO8601 format) + */ + DateTime startTime(); + + /** + * @return the percentage of the seeding completed for the replication link + */ + int percentComplete(); + + /** + * @return the replication state for the replication link + */ + ReplicationState replicationState(); + +} + diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/RestorePoint.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/RestorePoint.java new file mode 100644 index 000000000000..c491a9280ac2 --- /dev/null +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/RestorePoint.java @@ -0,0 +1,54 @@ +/** + * 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; + +import com.microsoft.azure.management.apigeneration.Fluent; +import com.microsoft.azure.management.resources.fluentcore.arm.models.HasId; +import com.microsoft.azure.management.resources.fluentcore.arm.models.HasName; +import com.microsoft.azure.management.resources.fluentcore.arm.models.HasResourceGroup; +import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; +import com.microsoft.azure.management.sql.implementation.RestorePointInner; +import org.joda.time.DateTime; + + +/** + * An immutable client-side representation of an Azure SQL database's Restore Point. + */ +@Fluent +public interface RestorePoint extends + Wrapper, + HasResourceGroup, + HasName, + HasId { + /** + * @return name of the SQL Server to which this replication belongs + */ + String sqlServerName(); + + /** + * @return name of the SQL Database to which this replication belongs + */ + String databaseName(); + + /** + * @return the restore point type of the Azure SQL Database restore point. + */ + RestorePointTypes restorePointType(); + + /** + * @return restore point creation time (ISO8601 format). Populated when + * restorePointType = CONTINUOUS. Null otherwise. + */ + DateTime restorePointCreationDate(); + + /** + * @return earliest restore time (ISO8601 format). Populated when restorePointType + * = DISCRETE. Null otherwise. + */ + DateTime earliestRestoreDate(); +} + diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/ServerMetric.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/ServerMetric.java new file mode 100644 index 000000000000..a4ae57f02a53 --- /dev/null +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/ServerMetric.java @@ -0,0 +1,52 @@ +/** + * 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; + +import com.microsoft.azure.management.apigeneration.Fluent; +import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; +import com.microsoft.azure.management.sql.implementation.ServerMetricInner; +import org.joda.time.DateTime; + + +/** + * An immutable client-side representation of an Azure SQL ServerMetric. + */ +@Fluent +public interface ServerMetric extends + Wrapper { + + /** + * @return the name of the resource + */ + String resourceName(); + + /** + * @return the metric display name + */ + String displayName(); + + /** + * @return the current value of the metric + */ + double currentValue(); + + /** + * @return the current limit of the metric + */ + double limit(); + + /** + * @return the units of the metric + */ + String unit(); + + /** + * @return the next reset time for the metric (ISO8601 format) + */ + DateTime nextResetTime(); +} + diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/ServerUpgradeResult.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/ServerUpgradeResult.java new file mode 100644 index 000000000000..6b110802cd91 --- /dev/null +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/ServerUpgradeResult.java @@ -0,0 +1,31 @@ +/** + * 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; + +import com.microsoft.azure.management.apigeneration.Fluent; +import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; +import com.microsoft.azure.management.sql.implementation.ServerUpgradeGetResultInner; +import org.joda.time.DateTime; + + +/** + * An immutable client-side representation of an Azure SQL upgrade result. + */ +@Fluent +public interface ServerUpgradeResult extends + Wrapper { + /** + * @return the status of the Azure SQL Server Upgrade + */ + String status(); + + /** + * @return the schedule time of the Azure SQL Server Upgrade (ISO8601 format). + */ + DateTime scheduleUpgradeAfterTime(); +} + 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 edb227532256..c8830afd1042 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 @@ -6,6 +6,7 @@ package com.microsoft.azure.management.sql; +import com.microsoft.azure.PagedList; import com.microsoft.azure.management.apigeneration.Fluent; import com.microsoft.azure.management.resources.fluentcore.arm.models.IndependentChildResource; import com.microsoft.azure.management.resources.fluentcore.model.Appliable; @@ -36,7 +37,7 @@ public interface SqlDatabase extends Wrapper { /** - * @return the SQL Server name to which this database belongs + * @return name of the SQL Server to which this database belongs */ String sqlServerName(); @@ -139,6 +140,59 @@ public interface SqlDatabase extends */ List recommendedIndex(); + /** + * @return the handler to replication links + */ + ReplicationLinks replicationLinks(); + + /** + * Pause an Azure SQL Data Warehouse database. + */ + void pauseDataWarehouse(); + + /** + * Resume an Azure SQL Data Warehouse database. + */ + void resumeDataWarehouse(); + + /** + * @return returns the list of all restore points on the database + */ + PagedList listRestorePoints(); + + /** + * @return returns the list of usages (DatabaseMetrics) of the database + */ + PagedList listUsages(); + + /** + * Entry point to access replication links from SQL Database. + */ + interface ReplicationLinks { + /** + * Gets a particular replication link. + * + * @param linkId name of the replication to get + * @return Returns the replication link id with in the SQL Database + */ + ReplicationLink get(String linkId); + + /** + * Returns all the replication links for the database. + * + * @return list of replication links for the database + */ + PagedList list(); + + /** + * Delete specified replication link in the database. + * + * @param linkId name of the replication link to delete + */ + void delete(String linkId); + } + + /************************************************************** * Fluent interfaces to provision a SqlServer **************************************************************/ @@ -177,7 +231,7 @@ interface WithElasticPoolName { * * @return The next stage of definition. */ - WithExistingDatabase withoutExistingElasticPool(); + WithExistingDatabase withoutElasticPool(); /** * Sets the existing elastic pool for the SQLDatabase. @@ -388,7 +442,7 @@ interface WithElasticPoolName { * * @return The next stage of definition. */ - WithEdition withoutExistingElasticPool(); + WithEdition withoutElasticPool(); /** * Sets the existing elastic pool for the SQLDatabase. 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 54ad447a665c..742d0ced1a01 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 @@ -27,7 +27,7 @@ public interface SqlElasticPool extends Wrapper { /** - * @return the SQL Server name to which this elastic pool belongs + * @return name of the SQL Server to which this elastic pool belongs */ String sqlServerName(); diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/SqlFirewallRule.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/SqlFirewallRule.java index 897ad8242e12..e5448767b78f 100644 --- a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/SqlFirewallRule.java +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/SqlFirewallRule.java @@ -26,7 +26,7 @@ public interface SqlFirewallRule extends Wrapper { /** - * @return the SQL Server name to which this firewall rule belongs + * @return name of the SQL Server to which this firewall rule belongs */ String sqlServerName(); 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 8533c220532e..1325b6162a13 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 @@ -57,6 +57,24 @@ public interface SqlServer extends */ Databases databases(); + // TODO - ans - Testing pending for upgrade scenario. Need to implement startUpgrade first for the same. + /** + * Cancels a pending upgrade for the Azure SQL Server. + */ + void cancelUpgrade(); + + // TODO - ans - Testing pending for upgrade scenario. Need to implement startUpgrade first for the same. + /** + * @return get information about upgrade status of the an Azure SQL Server + */ + ServerUpgradeResult getUpgrade(); + + + /** + * @return returns the list of usages (ServerMetric) of Azure SQL Server + */ + PagedList listUsages(); + /** * Entry point to access FirewallRules from the SQL Server. */ diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/DatabaseMetricImpl.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/DatabaseMetricImpl.java new file mode 100644 index 000000000000..3f36ae634d42 --- /dev/null +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/DatabaseMetricImpl.java @@ -0,0 +1,55 @@ +/** + * 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.management.apigeneration.LangDefinition; +import com.microsoft.azure.management.resources.fluentcore.model.implementation.WrapperImpl; +import com.microsoft.azure.management.sql.DatabaseMetric; +import org.joda.time.DateTime; + +/** + * Implementation for DatabaseMetric interface. + */ +@LangDefinition +class DatabaseMetricImpl + extends WrapperImpl + implements DatabaseMetric { + + protected DatabaseMetricImpl(DatabaseMetricInner innerObject) { + super(innerObject); + } + + @Override + public String resourceName() { + return this.inner().resourceName(); + } + + @Override + public String displayName() { + return this.inner().displayName(); + } + + @Override + public double currentValue() { + return this.inner().currentValue(); + } + + @Override + public double limit() { + return this.inner().limit(); + } + + @Override + public String unit() { + return this.inner().unit(); + } + + @Override + public DateTime nextResetTime() { + return this.inner().nextResetTime(); + } +} diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/DatabasesInner.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/DatabasesInner.java index 28057c9482f1..633af5a124de 100644 --- a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/DatabasesInner.java +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/DatabasesInner.java @@ -103,7 +103,7 @@ interface DatabasesService { Observable> beginResumeDataWarehouse(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("serverName") String serverName, @Path("databaseName") String databaseName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") - @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints") + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/listRestorePoints") Observable> listRestorePoints(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("serverName") String serverName, @Path("databaseName") String databaseName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/ReplicationLinkImpl.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/ReplicationLinkImpl.java new file mode 100644 index 000000000000..20cfa3c349c3 --- /dev/null +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/ReplicationLinkImpl.java @@ -0,0 +1,108 @@ +/** + * 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.management.apigeneration.LangDefinition; +import com.microsoft.azure.management.resources.fluentcore.arm.ResourceId; +import com.microsoft.azure.management.resources.fluentcore.model.implementation.WrapperImpl; +import com.microsoft.azure.management.sql.ReplicationLink; +import com.microsoft.azure.management.sql.ReplicationRole; +import com.microsoft.azure.management.sql.ReplicationState; +import org.joda.time.DateTime; + +/** + * Implementation for SqlServer and its parent interfaces. + */ +@LangDefinition +class ReplicationLinkImpl + extends WrapperImpl + implements ReplicationLink { + private final DatabasesInner innerCollection; + private final ResourceId resourceId; + + protected ReplicationLinkImpl(ReplicationLinkInner innerObject, DatabasesInner innerCollection) { + super(innerObject); + this.resourceId = ResourceId.parseResourceId(this.inner().id()); + this.innerCollection = innerCollection; + } + + @Override + public ReplicationLink refresh() { + this.setInner(this.innerCollection.getReplicationLink( + this.resourceGroupName(), + this.sqlServerName(), + this.databaseName(), + this.name())); + + return this; + } + + @Override + public String sqlServerName() { + return resourceId.parent().parent().name(); + } + + @Override + public String databaseName() { + return resourceId.parent().name(); + } + + @Override + public String partnerServer() { + return this.inner().partnerServer(); + } + + @Override + public String partnerDatabase() { + return this.inner().partnerDatabase(); + } + + @Override + public String partnerLocation() { + return this.inner().partnerLocation(); + } + + @Override + public ReplicationRole role() { + return this.inner().role(); + } + + @Override + public ReplicationRole partnerRole() { + return this.inner().partnerRole(); + } + + @Override + public DateTime startTime() { + return this.inner().startTime(); + } + + @Override + public int percentComplete() { + return this.inner().percentComplete(); + } + + @Override + public ReplicationState replicationState() { + return this.inner().replicationState(); + } + + @Override + public String name() { + return this.resourceId.name(); + } + + @Override + public String id() { + return this.resourceId.id(); + } + + @Override + public String resourceGroupName() { + return this.resourceId.resourceGroupName(); + } +} diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/ReplicationLinksImpl.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/ReplicationLinksImpl.java new file mode 100644 index 000000000000..ec3d64d933a6 --- /dev/null +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/ReplicationLinksImpl.java @@ -0,0 +1,53 @@ +/** + * 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.collection.implementation.ReadableWrappersImpl; +import com.microsoft.azure.management.sql.ReplicationLink; +import com.microsoft.azure.management.sql.SqlDatabase; + +/** + * Implementation of SqlDatabase.ReplicationLinks, which enables handling of Replication Links from the SQL Database directly. + */ +public class ReplicationLinksImpl + extends ReadableWrappersImpl + implements SqlDatabase.ReplicationLinks { + + private final String resourceGroupName; + private final String sqlServerName; + private final String databaseName; + private final DatabasesInner innerCollection; + + ReplicationLinksImpl(DatabasesInner innerCollection, String resourceGroupName, String sqlServerName, String databaseName) { + this.resourceGroupName = resourceGroupName; + this.sqlServerName = sqlServerName; + this.databaseName = databaseName; + this.innerCollection = innerCollection; + } + + @Override + public ReplicationLink get(String linkId) { + return wrapModel(this.innerCollection.getReplicationLink(this.resourceGroupName, this.sqlServerName, this.databaseName, linkId)); + } + + @Override + public PagedList list() { + return this.wrapList(this.innerCollection.listReplicationLinks(this.resourceGroupName, this.sqlServerName, this.databaseName)); + } + + + @Override + public void delete(String linkId) { + this.innerCollection.deleteReplicationLink(this.resourceGroupName, this.sqlServerName, this.databaseName, linkId); + } + + @Override + protected ReplicationLinkImpl wrapModel(ReplicationLinkInner inner) { + return new ReplicationLinkImpl(inner, this.innerCollection); + } +} diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/RestorePointImpl.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/RestorePointImpl.java new file mode 100644 index 000000000000..e008e812bca5 --- /dev/null +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/RestorePointImpl.java @@ -0,0 +1,69 @@ +/** + * 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.management.apigeneration.LangDefinition; +import com.microsoft.azure.management.resources.fluentcore.arm.ResourceId; +import com.microsoft.azure.management.resources.fluentcore.model.implementation.WrapperImpl; +import com.microsoft.azure.management.sql.RestorePoint; +import com.microsoft.azure.management.sql.RestorePointTypes; +import org.joda.time.DateTime; + +/** + * Implementation for Restore point interface. + */ +@LangDefinition +class RestorePointImpl + extends WrapperImpl + implements RestorePoint { + private final ResourceId resourceId; + + protected RestorePointImpl(RestorePointInner innerObject) { + super(innerObject); + this.resourceId = ResourceId.parseResourceId(this.inner().id()); + } + + @Override + public String name() { + return this.resourceId.name(); + } + + @Override + public String id() { + return this.resourceId.id(); + } + + @Override + public String resourceGroupName() { + return this.resourceId.resourceGroupName(); + } + + @Override + public String sqlServerName() { + return resourceId.parent().parent().name(); + } + + @Override + public String databaseName() { + return resourceId.parent().name(); + } + + @Override + public RestorePointTypes restorePointType() { + return this.inner().restorePointType(); + } + + @Override + public DateTime restorePointCreationDate() { + return this.inner().restorePointCreationDate(); + } + + @Override + public DateTime earliestRestoreDate() { + return this.inner().earliestRestoreDate(); + } +} diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/ServerMetricImpl.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/ServerMetricImpl.java new file mode 100644 index 000000000000..cacb09f51894 --- /dev/null +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/ServerMetricImpl.java @@ -0,0 +1,55 @@ +/** + * 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.management.apigeneration.LangDefinition; +import com.microsoft.azure.management.resources.fluentcore.model.implementation.WrapperImpl; +import com.microsoft.azure.management.sql.ServerMetric; +import org.joda.time.DateTime; + +/** + * Implementation for DatabaseMetric interface. + */ +@LangDefinition +class ServerMetricImpl + extends WrapperImpl + implements ServerMetric { + + protected ServerMetricImpl(ServerMetricInner innerObject) { + super(innerObject); + } + + @Override + public String resourceName() { + return this.inner().resourceName(); + } + + @Override + public String displayName() { + return this.inner().displayName(); + } + + @Override + public double currentValue() { + return this.inner().currentValue(); + } + + @Override + public double limit() { + return this.inner().limit(); + } + + @Override + public String unit() { + return this.inner().unit(); + } + + @Override + public DateTime nextResetTime() { + return this.inner().nextResetTime(); + } +} diff --git a/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/ServerUpgradeResultImpl.java b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/ServerUpgradeResultImpl.java new file mode 100644 index 000000000000..af6451441bbb --- /dev/null +++ b/azure-mgmt-sql/src/main/java/com/microsoft/azure/management/sql/implementation/ServerUpgradeResultImpl.java @@ -0,0 +1,34 @@ +/** + * 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.management.apigeneration.LangDefinition; +import com.microsoft.azure.management.resources.fluentcore.model.implementation.WrapperImpl; +import com.microsoft.azure.management.sql.ServerUpgradeResult; +import org.joda.time.DateTime; + +/** + * Implementation for Restore point interface. + */ +@LangDefinition +class ServerUpgradeResultImpl + extends WrapperImpl + implements ServerUpgradeResult { + protected ServerUpgradeResultImpl(ServerUpgradeGetResultInner innerObject) { + super(innerObject); + } + + @Override + public String status() { + return this.inner().status(); + } + + @Override + public DateTime scheduleUpgradeAfterTime() { + return this.inner().scheduleUpgradeAfterTime(); + } +} 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 01547429f477..95384bd9842f 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 @@ -6,11 +6,16 @@ package com.microsoft.azure.management.sql.implementation; +import com.microsoft.azure.PagedList; 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.resources.fluentcore.utils.PagedListConverter; +import com.microsoft.azure.management.resources.fluentcore.utils.Utils; import com.microsoft.azure.management.sql.CreateMode; import com.microsoft.azure.management.sql.DatabaseEditions; +import com.microsoft.azure.management.sql.DatabaseMetric; +import com.microsoft.azure.management.sql.RestorePoint; import com.microsoft.azure.management.sql.ServiceObjectiveName; import com.microsoft.azure.management.sql.SqlDatabase; import com.microsoft.azure.management.sql.SqlElasticPool; @@ -140,6 +145,54 @@ public List recommendedIndex() { return this.inner().recommendedIndex(); } + @Override + public ReplicationLinks replicationLinks() { + return new ReplicationLinksImpl(this.innerCollection, this.resourceGroupName(), this.sqlServerName(), this.name()); + } + + @Override + public void pauseDataWarehouse() { + this.innerCollection.pauseDataWarehouse(this.resourceGroupName(), this.sqlServerName(), this.name()); + } + + @Override + public void resumeDataWarehouse() { + this.innerCollection.resumeDataWarehouse(this.resourceGroupName(), this.sqlServerName(), this.name()); + } + + + @Override + public PagedList listRestorePoints() { + PagedListConverter converter = new PagedListConverter() { + @Override + public RestorePoint typeConvert(RestorePointInner restorePointInner) { + + return new RestorePointImpl(restorePointInner); + } + }; + return converter.convert(Utils.convertToPagedList( + this.innerCollection.listRestorePoints( + this.resourceGroupName(), + this.sqlServerName(), + this.name()))); + } + + @Override + public PagedList listUsages() { + PagedListConverter converter = new PagedListConverter() { + @Override + public DatabaseMetric typeConvert(DatabaseMetricInner databaseMetricInner) { + + return new DatabaseMetricImpl(databaseMetricInner); + } + }; + return converter.convert(Utils.convertToPagedList( + this.innerCollection.listUsages( + this.resourceGroupName(), + this.sqlServerName(), + this.name()))); + } + @Override public SqlDatabase refresh() { this.innerCollection.get(this.resourceGroupName(), this.sqlServerName(), this.name()); @@ -183,7 +236,7 @@ public SqlDatabaseImpl withEdition(DatabaseEditions edition) { } @Override - public SqlDatabaseImpl withoutExistingElasticPool() { + public SqlDatabaseImpl withoutElasticPool() { this.inner().withElasticPoolName(""); return this; } 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 563a962214c3..29ec643d6e9f 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 @@ -6,8 +6,13 @@ package com.microsoft.azure.management.sql.implementation; +import com.microsoft.azure.PagedList; import com.microsoft.azure.management.apigeneration.LangDefinition; import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableResourceImpl; +import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter; +import com.microsoft.azure.management.resources.fluentcore.utils.Utils; +import com.microsoft.azure.management.sql.ServerMetric; +import com.microsoft.azure.management.sql.ServerUpgradeResult; import com.microsoft.azure.management.sql.ServerVersion; import com.microsoft.azure.management.sql.SqlServer; import rx.Observable; @@ -17,7 +22,7 @@ * Implementation for SqlServer and its parent interfaces. */ @LangDefinition -class SqlServerImpl +public class SqlServerImpl extends GroupableResourceImpl< SqlServer, @@ -97,6 +102,31 @@ public Databases databases() { return new DatabasesImpl(this.databasesInner, myManager, this.resourceGroupName(), this.name(), this.region()); } + @Override + public void cancelUpgrade() { + this.innerCollection.cancelUpgrade(this.resourceGroupName(), this.name()); + } + + @Override + public ServerUpgradeResult getUpgrade() { + return new ServerUpgradeResultImpl(this.innerCollection.getUpgrade(this.resourceGroupName(), this.name())); + } + + @Override + public PagedList listUsages() { + PagedListConverter converter = new PagedListConverter() { + @Override + public ServerMetric typeConvert(ServerMetricInner serverMetricInner) { + + return new ServerMetricImpl(serverMetricInner); + } + }; + return converter.convert(Utils.convertToPagedList( + this.innerCollection.listUsages( + this.resourceGroupName(), + this.name()))); + } + @Override public SqlServerImpl withAdministratorLogin(String administratorLogin) { this.inner().withAdministratorLogin(administratorLogin); 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 82006d003b80..99fe7bedf221 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 @@ -17,8 +17,8 @@ import java.util.List; public class SqlServerOperationsTests extends SqlServerTestBase { - private static final String RG_NAME = "javasqlserver1238"; - private static final String SQL_SERVER_NAME = "javasqlserver1238"; + private static final String RG_NAME = "javasqlserver1237"; + private static final String SQL_SERVER_NAME = "javasqlserver1237"; private static final String SQL_DATABASE_NAME = "myTestDatabase2"; private static final String COLLATION = "SQL_Latin1_General_CP1_CI_AS"; private static final String SQL_ELASTIC_POOL_NAME = "testElasticPool"; @@ -69,7 +69,7 @@ public void canCRUDSqlDatabase() throws Exception { SqlDatabase sqlDatabase = sqlServer.databases() .define(SQL_DATABASE_NAME) - .withoutExistingElasticPool() + .withoutElasticPool() .withoutSourceDatabaseId() .withCollation(COLLATION) .withEdition(DatabaseEditions.STANDARD) @@ -108,7 +108,7 @@ public void canCRUDSqlDatabase() throws Exception { // Add another database to the server sqlDatabase = sqlServer.databases() .define("newDatabase") - .withoutExistingElasticPool() + .withoutElasticPool() .withoutSourceDatabaseId() .withCollation(COLLATION) .withEdition(DatabaseEditions.STANDARD) @@ -119,6 +119,104 @@ public void canCRUDSqlDatabase() throws Exception { validateSqlServerNotFound(sqlServer); } + @Test + public void canManageReplicationLinks() throws Exception { + // Create + String anotherSqlServerName = SQL_SERVER_NAME + "another"; + SqlServer sqlServer1 = createSqlServer(); + SqlServer sqlServer2 = createSqlServer(anotherSqlServerName); + + SqlDatabase databaseInServer1 = sqlServer1.databases() + .define(SQL_DATABASE_NAME) + .withoutElasticPool() + .withoutSourceDatabaseId() + .withCollation(COLLATION) + .withEdition(DatabaseEditions.STANDARD) + .createAsync().toBlocking().first(); + + validateSqlDatabase(databaseInServer1, SQL_DATABASE_NAME); + SqlDatabase databaseInServer2 = sqlServer2.databases() + .define(SQL_DATABASE_NAME) + .withoutElasticPool() + .withSourceDatabaseId(databaseInServer1.id()) + .withCreateMode(CreateMode.ONLINE_SECONDARY) + .create(); + Thread.sleep(2000); + PagedList replicationLinksInDb1 = databaseInServer1.replicationLinks().list(); + + Assert.assertEquals(replicationLinksInDb1.size() , 1); + Assert.assertEquals(replicationLinksInDb1.get(0).partnerDatabase(), databaseInServer2.name()); + Assert.assertEquals(replicationLinksInDb1.get(0).partnerServer(), databaseInServer2.sqlServerName()); + + PagedList replicationLinksInDb2 = databaseInServer2.replicationLinks().list(); + + Assert.assertEquals(replicationLinksInDb2.size() , 1); + Assert.assertEquals(replicationLinksInDb2.get(0).partnerDatabase(), databaseInServer1.name()); + Assert.assertEquals(replicationLinksInDb2.get(0).partnerServer(), databaseInServer1.sqlServerName()); + + Assert.assertNotNull(replicationLinksInDb1.get(0).refresh()); + Assert.assertNotNull(databaseInServer1.replicationLinks().get(replicationLinksInDb1.get(0).name())); + + databaseInServer2.replicationLinks().delete(replicationLinksInDb2.get(0).name()); + + + Assert.assertEquals(databaseInServer2.replicationLinks().list().size(), 0); + + Thread.sleep(5000); + Assert.assertEquals(databaseInServer1.replicationLinks().list().size(), 0); + + sqlServer1.databases().delete(databaseInServer1.name()); + sqlServer2.databases().delete(databaseInServer2.name()); + + sqlServerManager.sqlServers().deleteByGroup(sqlServer2.resourceGroupName(), sqlServer2.name()); + validateSqlServerNotFound(sqlServer2); + sqlServerManager.sqlServers().deleteByGroup(sqlServer1.resourceGroupName(), sqlServer1.name()); + validateSqlServerNotFound(sqlServer1); + } + + @Test + public void canDoOperationsOnDataWarehouse() throws Exception { + // Create + SqlServer sqlServer = createSqlServer(); + + validateSqlServer(sqlServer); + + // List usages for the server. + Assert.assertNotNull(sqlServer.listUsages()); + + SqlDatabase dataWarehouse = sqlServer.databases() + .define(SQL_DATABASE_NAME) + .withoutElasticPool() + .withoutSourceDatabaseId() + .withCollation(COLLATION) + .withEdition(DatabaseEditions.DATA_WAREHOUSE) + .createAsync().toBlocking().first(); + + // Get + dataWarehouse = sqlServer.databases().get(SQL_DATABASE_NAME); + + Assert.assertNotNull(dataWarehouse); + Assert.assertEquals(dataWarehouse.name(), SQL_DATABASE_NAME); + Assert.assertEquals(dataWarehouse.edition(), DatabaseEditions.DATA_WAREHOUSE); + + // TODO - ans - Get Restore points. + // Assert.assertNotNull(dataWarehouse.listRestorePoints()); + // Get usages. + Assert.assertNotNull(dataWarehouse.listUsages()); + + // Pause warehouse + dataWarehouse.pauseDataWarehouse(); + + // Resume warehouse + dataWarehouse.resumeDataWarehouse(); + + sqlServer.databases().delete(SQL_DATABASE_NAME); + + sqlServerManager.sqlServers().deleteByGroup(sqlServer.resourceGroupName(), sqlServer.name()); + validateSqlServerNotFound(sqlServer); + } + + @Test public void canCRUDSqlDatabaseWithElasticPool() throws Exception { // Create @@ -153,7 +251,7 @@ public void canCRUDSqlDatabaseWithElasticPool() throws Exception { // Remove database from elastic pools. sqlDatabase.update() - .withoutExistingElasticPool() + .withoutElasticPool() .withEdition(DatabaseEditions.STANDARD) .withServiceObjective(ServiceObjectiveName.S3) .apply(); @@ -327,6 +425,9 @@ private static void validateSqlServerNotFound(SqlServer sqlServer) { } private static SqlServer createSqlServer() { + return createSqlServer(SQL_SERVER_NAME); + } + private static SqlServer createSqlServer(String SQL_SERVER_NAME) { return sqlServerManager.sqlServers() .define(SQL_SERVER_NAME) .withRegion(Region.US_CENTRAL) diff --git a/azure-mgmt-sql/src/test/java/com/microsoft/azure/management/sql/SqlServerTestBase.java b/azure-mgmt-sql/src/test/java/com/microsoft/azure/management/sql/SqlServerTestBase.java index 38819c31e471..38498a62bbb9 100644 --- a/azure-mgmt-sql/src/test/java/com/microsoft/azure/management/sql/SqlServerTestBase.java +++ b/azure-mgmt-sql/src/test/java/com/microsoft/azure/management/sql/SqlServerTestBase.java @@ -26,6 +26,7 @@ public static void createClients() { .withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER) .withCredentials(credentials) .withLogLevel(HttpLoggingInterceptor.Level.BODY) + //.withProxy( new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", 8888))) .withReadTimeout(60, TimeUnit.SECONDS) .build();