-
Notifications
You must be signed in to change notification settings - Fork 97
CosmosDB: Add missing implementations for creating other data models #431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| package com.microsoft.azure.management.cosmosdb.implementation; | ||
|
|
||
| import com.microsoft.azure.management.apigeneration.LangDefinition; | ||
| import com.microsoft.azure.management.cosmosdb.Capability; | ||
| import com.microsoft.azure.management.cosmosdb.CosmosDBAccount; | ||
| import com.microsoft.azure.management.cosmosdb.DatabaseAccountKind; | ||
| import com.microsoft.azure.management.cosmosdb.DatabaseAccountListConnectionStringsResult; | ||
|
|
@@ -23,6 +24,7 @@ | |
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.Comparator; | ||
| import java.util.List; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
@@ -145,6 +147,15 @@ public DatabaseAccountListConnectionStringsResult call(DatabaseAccountListConnec | |
| }); | ||
| } | ||
|
|
||
| @Override | ||
| public List<Capability> capabilities() { | ||
| List<Capability> capabilities = this.inner().capabilities(); | ||
| if (capabilities == null) { | ||
| capabilities = new ArrayList<>(); | ||
| } | ||
| return Collections.unmodifiableList(capabilities); | ||
| } | ||
|
|
||
| @Override | ||
| public void regenerateKey(KeyKind keyKind) { | ||
| this.regenerateKeyAsync(keyKind).toBlocking().last(); | ||
|
|
@@ -162,6 +173,52 @@ public CosmosDBAccountImpl withKind(DatabaseAccountKind kind) { | |
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public CosmosDBAccountImpl withKind(DatabaseAccountKind kind, Capability... capabilities) { | ||
| this.inner().withKind(kind); | ||
| this.inner().withCapabilities(Arrays.asList(capabilities)); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public CosmosDBAccountImpl withDataModelSql() { | ||
| this.inner().withKind(DatabaseAccountKind.GLOBAL_DOCUMENT_DB); | ||
| return this; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure the "defaultExperience" tags are not needed on these? If you create each API type in the portal, they all have a "defaultExperience" tag.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tags do not impact resource provisioning; if they do then it's a bug. While the tests I've added set a generic tag it's not required to create an CosmosDB account. |
||
| } | ||
|
|
||
| @Override | ||
| public CosmosDBAccountImpl withDataModelMongoDB() { | ||
| this.inner().withKind(DatabaseAccountKind.MONGO_DB); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public CosmosDBAccountImpl withDataModelCassandra() { | ||
| this.inner().withKind(DatabaseAccountKind.PARSE); | ||
| List<Capability> capabilities = new ArrayList<Capability>(); | ||
| capabilities.add(new Capability().withName("EnableCassandra")); | ||
| this.inner().withCapabilities(capabilities); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public CosmosDBAccountImpl withDataModelAzureTable() { | ||
| this.inner().withKind(DatabaseAccountKind.PARSE); | ||
| List<Capability> capabilities = new ArrayList<Capability>(); | ||
| capabilities.add(new Capability().withName("EnableTable")); | ||
| this.inner().withCapabilities(capabilities); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public CosmosDBAccountImpl withDataModelGremlin() { | ||
| this.inner().withKind(DatabaseAccountKind.PARSE); | ||
| List<Capability> capabilities = new ArrayList<Capability>(); | ||
| capabilities.add(new Capability().withName("EnableGremlin")); | ||
| this.inner().withCapabilities(capabilities); | ||
| return this; | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public CosmosDBAccountImpl withIpRangeFilter(String ipRangeFilter) { | ||
|
|
@@ -251,6 +308,7 @@ private DatabaseAccountCreateUpdateParametersInner createUpdateParametersInner(D | |
| DatabaseAccountOfferType.STANDARD.toString()); | ||
| createUpdateParametersInner.withIpRangeFilter(inner.ipRangeFilter()); | ||
| createUpdateParametersInner.withKind(inner.kind()); | ||
| createUpdateParametersInner.withCapabilities(inner.capabilities()); | ||
| createUpdateParametersInner.withTags(inner.getTags()); | ||
| this.addLocationsForCreateUpdateParameters(createUpdateParametersInner, this.failoverPolicies); | ||
| return createUpdateParametersInner; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| /** | ||
| * 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.cosmosdb; | ||
|
|
||
| import com.microsoft.azure.management.cosmosdb.implementation.CosmosDBManager; | ||
| import com.microsoft.azure.management.resources.core.TestBase; | ||
| import com.microsoft.azure.management.resources.fluentcore.arm.Region; | ||
| import com.microsoft.azure.management.resources.fluentcore.utils.SdkContext; | ||
| import com.microsoft.azure.management.resources.implementation.ResourceManager; | ||
| import com.microsoft.rest.RestClient; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class CosmosDBTests extends TestBase { | ||
|
|
||
| private static String RG_NAME = ""; | ||
| protected ResourceManager resourceManager; | ||
| protected CosmosDBManager cosmosDBManager; | ||
| // final String sqlPrimaryServerName = SdkContext.randomResourceName("sqlpri", 22); | ||
|
|
||
| public CosmosDBTests() { | ||
| super(TestBase.RunCondition.BOTH); | ||
| } | ||
|
|
||
| @Override | ||
| protected void initializeClients(RestClient restClient, String defaultSubscription, String domain) throws IOException { | ||
| RG_NAME = generateRandomResourceName("rgcosmosdb", 20); | ||
| resourceManager = ResourceManager | ||
| .authenticate(restClient) | ||
| .withSubscription(defaultSubscription); | ||
|
|
||
| cosmosDBManager = CosmosDBManager.authenticate(restClient, defaultSubscription); | ||
| } | ||
|
|
||
| @Override | ||
| protected void cleanUpResources() { | ||
| resourceManager.resourceGroups().beginDeleteByName(RG_NAME); | ||
| } | ||
|
|
||
| @Test | ||
| public void CanCreateCosmosDbSqlAccount() { | ||
| final String cosmosDbAccountName = SdkContext.randomResourceName("cosmosdb", 22); | ||
|
|
||
| CosmosDBAccount cosmosDBAccount = cosmosDBManager.databaseAccounts() | ||
| .define(cosmosDbAccountName) | ||
| .withRegion(Region.US_WEST_CENTRAL) | ||
| .withNewResourceGroup(RG_NAME) | ||
| .withDataModelSql() | ||
| .withEventualConsistency() | ||
| .withWriteReplication(Region.US_EAST) | ||
| .withReadReplication(Region.US_CENTRAL) | ||
| .withIpRangeFilter("") | ||
| .withTag("tag1", "value1") | ||
| .create(); | ||
|
|
||
| Assert.assertEquals(cosmosDBAccount.name(), cosmosDbAccountName.toLowerCase()); | ||
| Assert.assertEquals(cosmosDBAccount.kind(), DatabaseAccountKind.GLOBAL_DOCUMENT_DB); | ||
| Assert.assertEquals(cosmosDBAccount.writableReplications().size(), 1); | ||
| Assert.assertEquals(cosmosDBAccount.readableReplications().size(), 2); | ||
| Assert.assertEquals(cosmosDBAccount.defaultConsistencyLevel(), DefaultConsistencyLevel.EVENTUAL); | ||
| } | ||
|
|
||
| @Test | ||
| public void CanCreateCosmosDbMongoDBAccount() { | ||
| final String cosmosDbAccountName = SdkContext.randomResourceName("cosmosdb", 22); | ||
|
|
||
| CosmosDBAccount cosmosDBAccount = cosmosDBManager.databaseAccounts() | ||
| .define(cosmosDbAccountName) | ||
| .withRegion(Region.US_WEST_CENTRAL) | ||
| .withNewResourceGroup(RG_NAME) | ||
| .withDataModelMongoDB() | ||
| .withEventualConsistency() | ||
| .withWriteReplication(Region.US_EAST) | ||
| .withReadReplication(Region.US_CENTRAL) | ||
| .withIpRangeFilter("") | ||
| .withTag("tag1", "value1") | ||
| .create(); | ||
|
|
||
| Assert.assertEquals(cosmosDBAccount.name(), cosmosDbAccountName.toLowerCase()); | ||
| Assert.assertEquals(cosmosDBAccount.kind(), DatabaseAccountKind.MONGO_DB); | ||
| Assert.assertEquals(cosmosDBAccount.writableReplications().size(), 1); | ||
| Assert.assertEquals(cosmosDBAccount.readableReplications().size(), 2); | ||
| Assert.assertEquals(cosmosDBAccount.defaultConsistencyLevel(), DefaultConsistencyLevel.EVENTUAL); | ||
| } | ||
|
|
||
| @Test | ||
| public void CanCreateCosmosDbCassandraAccount() { | ||
| final String cosmosDbAccountName = SdkContext.randomResourceName("cosmosdb", 22); | ||
|
|
||
| CosmosDBAccount cosmosDBAccount = cosmosDBManager.databaseAccounts() | ||
| .define(cosmosDbAccountName) | ||
| .withRegion(Region.US_WEST_CENTRAL) | ||
| .withNewResourceGroup(RG_NAME) | ||
| .withDataModelCassandra() | ||
| .withEventualConsistency() | ||
| .withWriteReplication(Region.US_EAST) | ||
| .withReadReplication(Region.US_CENTRAL) | ||
| .withIpRangeFilter("") | ||
| .withTag("tag1", "value1") | ||
| .create(); | ||
|
|
||
| Assert.assertEquals(cosmosDBAccount.name(), cosmosDbAccountName.toLowerCase()); | ||
| Assert.assertEquals(cosmosDBAccount.kind(), DatabaseAccountKind.PARSE); | ||
| Assert.assertEquals(cosmosDBAccount.capabilities().get(0).name(), "EnableCassandra"); | ||
| Assert.assertEquals(cosmosDBAccount.writableReplications().size(), 1); | ||
| Assert.assertEquals(cosmosDBAccount.readableReplications().size(), 2); | ||
| Assert.assertEquals(cosmosDBAccount.defaultConsistencyLevel(), DefaultConsistencyLevel.EVENTUAL); | ||
| } | ||
|
|
||
| @Test | ||
| public void CanCreateCosmosDbAzureTableAccount() { | ||
| final String cosmosDbAccountName = SdkContext.randomResourceName("cosmosdb", 22); | ||
|
|
||
| CosmosDBAccount cosmosDBAccount = cosmosDBManager.databaseAccounts() | ||
| .define(cosmosDbAccountName) | ||
| .withRegion(Region.US_WEST_CENTRAL) | ||
| .withNewResourceGroup(RG_NAME) | ||
| .withDataModelAzureTable() | ||
| .withEventualConsistency() | ||
| .withWriteReplication(Region.US_EAST) | ||
| .withReadReplication(Region.US_CENTRAL) | ||
| .withIpRangeFilter("") | ||
| .withTag("tag1", "value1") | ||
| .create(); | ||
|
|
||
| Assert.assertEquals(cosmosDBAccount.name(), cosmosDbAccountName.toLowerCase()); | ||
| Assert.assertEquals(cosmosDBAccount.kind(), DatabaseAccountKind.PARSE); | ||
| Assert.assertEquals(cosmosDBAccount.capabilities().get(0).name(), "EnableTable"); | ||
| Assert.assertEquals(cosmosDBAccount.writableReplications().size(), 1); | ||
| Assert.assertEquals(cosmosDBAccount.readableReplications().size(), 2); | ||
| Assert.assertEquals(cosmosDBAccount.defaultConsistencyLevel(), DefaultConsistencyLevel.EVENTUAL); | ||
| } | ||
|
|
||
| } |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be just withDataModel method and then a parameter of Enum type with all the supported DB Types as enum members? Too many methods in Intelisence that start with the same prefix (a long one in this case) creates some clutter IMHO
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also it is kind of weird construct
withDataModelSql. More natural would bewithSqlAccountorwithSqlTypebut in that case you will have types in a hard to find order in the intelisence. So reiterating my proposal to have one method and bunch of enum values 😃Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the management portal it is called API. Perhaps

withApi(Api.SQL)😃There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not need to match exactly what the Azure Portal does. Data model fits better the type of the account (see the explanation behind the little "i").
There's already a method that takes enums (see the withKind() overload I just added). These new methods are direct shortcuts for creating the respective CosmosDB account.