Skip to content

Commit b9c18ce

Browse files
XiaofeiCaoCopilot
andauthored
mgmt cosmos, support automaticfailover for CosmosDBAccount (#45751)
* code change * add revapi.json to include premium packages check * Update sdk/resourcemanager/azure-resourcemanager-cosmos/src/main/java/com/azure/resourcemanager/cosmos/models/CosmosDBAccount.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * address comments --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent dd26fe0 commit b9c18ce

File tree

6 files changed

+101
-5
lines changed

6 files changed

+101
-5
lines changed

eng/code-quality-reports/src/main/resources/revapi/revapi.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@
177177
{
178178
"regex": true,
179179
"code": "java\\.method\\.addedToInterface",
180-
"new": "method .* com\\.azure\\.resourcemanager\\..*",
181-
"justification": "resourcemanager interfaces are allowed to add methods."
180+
"new": "method .* com\\.azure\\.resourcemanager\\.(?!appplatform|appservice|authorization|cdn|compute|containerinstance|containerregistry|containerservice|cosmos|dns|eventhubs|keyvault|monitor|msi|network|privatedns|redis|resources|search|servicebus|sql|storage|trafficmanager).*",
181+
"justification": "resourcemanager interfaces are allowed to add methods, except for the 24 specific premium libraries."
182182
},
183183
{
184184
"regex": true,

sdk/resourcemanager/azure-resourcemanager-cosmos/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### Features Added
66

7+
- Supported `automaticFailoverEnabled()`, `enableAutomaticFailover` and `disableAutomaticFailover` in `CosmosDBAccount`.
8+
79
### Breaking Changes
810

911
### Bugs Fixed

sdk/resourcemanager/azure-resourcemanager-cosmos/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "java",
44
"TagPrefix": "java/resourcemanager/azure-resourcemanager-cosmos",
5-
"Tag": "java/resourcemanager/azure-resourcemanager-cosmos_b947f3e69a"
5+
"Tag": "java/resourcemanager/azure-resourcemanager-cosmos_cf91e9829d"
66
}

sdk/resourcemanager/azure-resourcemanager-cosmos/src/main/java/com/azure/resourcemanager/cosmos/implementation/CosmosDBAccountImpl.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@ public boolean localAuthDisabled() {
322322
return ResourceManagerUtils.toPrimitiveBoolean(this.innerModel().disableLocalAuth());
323323
}
324324

325+
@Override
326+
public boolean automaticFailoverEnabled() {
327+
return ResourceManagerUtils.toPrimitiveBoolean(this.innerModel().enableAutomaticFailover());
328+
}
329+
325330
@Override
326331
public CosmosDBAccountImpl withKind(DatabaseAccountKind kind) {
327332
this.innerModel().withKind(kind);
@@ -801,6 +806,18 @@ public CosmosDBAccountImpl disableLocalAuth() {
801806
return this;
802807
}
803808

809+
@Override
810+
public CosmosDBAccountImpl enableAutomaticFailover() {
811+
this.innerModel().withEnableAutomaticFailover(true);
812+
return this;
813+
}
814+
815+
@Override
816+
public CosmosDBAccountImpl disableAutomaticFailover() {
817+
this.innerModel().withEnableAutomaticFailover(false);
818+
return this;
819+
}
820+
804821
interface HasLocations {
805822
String location();
806823

sdk/resourcemanager/azure-resourcemanager-cosmos/src/main/java/com/azure/resourcemanager/cosmos/models/CosmosDBAccount.java

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,18 @@ public interface CosmosDBAccount extends GroupableResource<CosmosManager, Databa
306306
*/
307307
boolean localAuthDisabled();
308308

309+
/**
310+
* Checks whether automatic failover is enabled.
311+
* Enables automatic failover of the write region in the rare event that the region is unavailable due to an outage.
312+
* Automatic failover will result in a new write region for the account and is chosen based on the failover
313+
* priorities configured for the account.
314+
*
315+
* @return whether automatic failover is enabled
316+
*/
317+
default boolean automaticFailoverEnabled() {
318+
throw new UnsupportedOperationException("[automaticFailoverEnabled] is not supported in " + getClass());
319+
}
320+
309321
/** Grouping of cosmos db definition stages. */
310322
interface Definition extends DefinitionStages.Blank, DefinitionStages.WithGroup, DefinitionStages.WithKind,
311323
DefinitionStages.WithWriteReplication, DefinitionStages.WithReadReplication, DefinitionStages.WithCreate {
@@ -544,13 +556,28 @@ interface WithLocalAuth {
544556
WithCreate disableLocalAuth();
545557
}
546558

559+
/**
560+
* The stage of CosmosDB account definition allowing to enable automatic failover.
561+
*/
562+
interface WithAutomaticFailover {
563+
/**
564+
* Disables automatic failover.
565+
*
566+
* @return the next stage of the definition
567+
*/
568+
default WithCreate disableAutomaticFailover() {
569+
throw new UnsupportedOperationException("[disableAutomaticFailover] is not supported in " + getClass());
570+
}
571+
}
572+
547573
/**
548574
* The stage of the definition which contains all the minimum required inputs for the resource to be created,
549575
* but also allows for any other optional settings to be specified.
550576
*/
551577
interface WithCreate extends Creatable<CosmosDBAccount>, WithConsistencyPolicy, WithReadReplication,
552578
WithIpRules, WithVirtualNetworkRule, WithMultipleLocations, WithConnector, WithKeyBasedMetadataWriteAccess,
553-
WithPrivateEndpointConnection, DefinitionWithTags<WithCreate>, WithPublicNetworkAccess, WithLocalAuth {
579+
WithPrivateEndpointConnection, DefinitionWithTags<WithCreate>, WithPublicNetworkAccess, WithLocalAuth,
580+
WithAutomaticFailover {
554581
}
555582
}
556583

@@ -564,7 +591,8 @@ interface UpdateStages {
564591
interface WithOptionals extends Resource.UpdateWithTags<WithOptionals>, Appliable<CosmosDBAccount>,
565592
UpdateStages.WithConsistencyPolicy, UpdateStages.WithVirtualNetworkRule, UpdateStages.WithMultipleLocations,
566593
UpdateStages.WithConnector, UpdateStages.WithKeyBasedMetadataWriteAccess,
567-
UpdateStages.WithPrivateEndpointConnection, UpdateStages.WithIpRules, UpdateStages.WithPublicNetworkAccess {
594+
UpdateStages.WithPrivateEndpointConnection, UpdateStages.WithIpRules, UpdateStages.WithPublicNetworkAccess,
595+
UpdateStages.WithAutomaticFailover {
568596
}
569597

570598
/** The stage of the cosmos db definition allowing the definition of a write location. */
@@ -763,5 +791,30 @@ interface WithPublicNetworkAccess {
763791
*/
764792
Update disablePublicNetworkAccess();
765793
}
794+
795+
/**
796+
* The stage of CosmosDB account update allowing to toggle automatic failover.
797+
*/
798+
interface WithAutomaticFailover {
799+
/**
800+
* Enables automatic failover of the write region in the rare event that the region is unavailable due to an outage.
801+
* Automatic failover will result in a new write region for the account and is chosen based on the failover
802+
* priorities configured for the account.
803+
*
804+
* @return the next stage of the update
805+
*/
806+
default Update enableAutomaticFailover() {
807+
throw new UnsupportedOperationException("[enableAutomaticFailover] is not supported in " + getClass());
808+
}
809+
810+
/**
811+
* Disables automatic failover.
812+
*
813+
* @return the next stage of the update
814+
*/
815+
default Update disableAutomaticFailover() {
816+
throw new UnsupportedOperationException("[disableAutomaticFailover] is not supported in " + getClass());
817+
}
818+
}
766819
}
767820
}

sdk/resourcemanager/azure-resourcemanager-cosmos/src/test/java/com/azure/resourcemanager/cosmos/CosmosDBTests.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,4 +299,28 @@ public void canUpdatePublicNetworkAccess() {
299299
cosmosDBAccount.update().enablePublicNetworkAccess().apply();
300300
Assertions.assertEquals(PublicNetworkAccess.ENABLED, cosmosDBAccount.publicNetworkAccess());
301301
}
302+
303+
@Test
304+
public void canEnableAutomaticFailover() {
305+
final String cosmosDbAccountName = generateRandomResourceName("cosmosdb", 22);
306+
307+
CosmosDBAccount cosmosDBAccount = cosmosManager.databaseAccounts()
308+
.define(cosmosDbAccountName)
309+
.withRegion(Region.US_WEST_CENTRAL)
310+
.withNewResourceGroup(rgName)
311+
.withDataModelAzureTable()
312+
.withEventualConsistency()
313+
.withWriteReplication(Region.US_EAST2)
314+
.withReadReplication(Region.US_WEST)
315+
.disableLocalAuth()
316+
.create();
317+
// By default, it's enabled.
318+
Assertions.assertTrue(cosmosDBAccount.automaticFailoverEnabled());
319+
320+
cosmosDBAccount.update().disableAutomaticFailover().apply();
321+
Assertions.assertFalse(cosmosDBAccount.automaticFailoverEnabled());
322+
323+
cosmosDBAccount.update().enableAutomaticFailover().apply();
324+
Assertions.assertTrue(cosmosDBAccount.automaticFailoverEnabled());
325+
}
302326
}

0 commit comments

Comments
 (0)