Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,12 @@ private void createClients() {
CosmosAsyncContainer cosmosAsyncContainer = null;
boolean databaseCreated = false;
try {
cosmosAsyncDatabase = asyncClient.getDatabase(this.configuration.getDatabaseId()).read().block().getDatabase();
cosmosAsyncDatabase = asyncClient.getDatabase(this.configuration.getDatabaseId());
cosmosAsyncDatabase.read().block();
} catch (CosmosException e) {
if (e.getStatusCode() == HttpConstants.StatusCodes.NOTFOUND) {
cosmosAsyncDatabase = asyncClient.createDatabase(this.configuration.getDatabaseId()).block().getDatabase();
asyncClient.createDatabase(this.configuration.getDatabaseId()).block();
cosmosAsyncDatabase = asyncClient.getDatabase(this.configuration.getDatabaseId());
logger.info("Database {} is created for this test on host {}", this.configuration.getDatabaseId(), endpoint);
databaseCreated = true;
databaseListToClear.add(cosmosAsyncDatabase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ abstract class AsyncBenchmark<T> {
logger = LoggerFactory.getLogger(this.getClass());

try {
cosmosAsyncDatabase = cosmosClient.getDatabase(
this.configuration.getDatabaseId()
).read().doOnError(error ->
cosmosAsyncDatabase = cosmosClient.getDatabase(this.configuration.getDatabaseId());
cosmosAsyncDatabase.read().doOnError(error ->
logger.error("Database {} creation failed due to ", this.configuration.getDatabaseId(), error)
).block().getDatabase();
).block();
} catch (CosmosException e) {
if (e.getStatusCode() == HttpConstants.StatusCodes.NOTFOUND) {
cosmosAsyncDatabase = cosmosClient.createDatabase(cfg.getDatabaseId()).block().getDatabase();
cosmosClient.createDatabase(cfg.getDatabaseId()).block();
cosmosAsyncDatabase = cosmosClient.getDatabase(cfg.getDatabaseId());
logger.info("Database {} is created for this test", this.configuration.getDatabaseId());
databaseCreated = true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ public T apply(T o, Throwable throwable) {
}
cosmosClient = cosmosClientBuilder.buildClient();
try {
cosmosDatabase = cosmosClient.getDatabase(this.configuration.getDatabaseId()).read().getDatabase();
cosmosDatabase = cosmosClient.getDatabase(this.configuration.getDatabaseId());
cosmosDatabase.read();
logger.info("Database {} is created for this test", this.configuration.getDatabaseId());
} catch (CosmosException e) {
if (e.getStatusCode() == HttpConstants.StatusCodes.NOTFOUND) {
cosmosDatabase = cosmosClient.createDatabase(cfg.getDatabaseId()).getDatabase();
cosmosClient.createDatabase(cfg.getDatabaseId());
cosmosDatabase = cosmosClient.getDatabase(cfg.getDatabaseId());
databaseCreated = true;
} else {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.azure.cosmos.CosmosAsyncClient;
import com.azure.cosmos.CosmosAsyncContainer;
import com.azure.cosmos.CosmosAsyncDatabase;
import com.azure.cosmos.models.CosmosAsyncDatabaseResponse;
import com.azure.cosmos.models.CosmosAsyncItemResponse;
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.CosmosException;
Expand Down Expand Up @@ -102,7 +101,7 @@ private void createDbAndContainerBlocking() {

client.createDatabaseIfNotExists(DATABASE_NAME)
.doOnSuccess(cosmosDatabaseResponse -> log("Database: " + DATABASE_NAME))
.flatMap(dbResponse -> dbResponse.getDatabase()
.flatMap(dbResponse -> client.getDatabase(DATABASE_NAME)
.createContainerIfNotExists(new CosmosContainerProperties(CONTAINER_NAME,
"/country")))
.doOnSuccess(cosmosContainerResponse -> log("Container: " + CONTAINER_NAME))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ public static CosmosAsyncClient getCosmosClient() {
}

public static CosmosAsyncDatabase createNewDatabase(CosmosAsyncClient client, String databaseName) {
return client.createDatabaseIfNotExists(databaseName).block().getDatabase();
client.createDatabaseIfNotExists(databaseName).block();
return client.getDatabase(databaseName);
}

public static void deleteDatabase(CosmosAsyncDatabase cosmosDatabase) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void runDemo() {
// This will create (or read) a database and its container.
CosmosAsyncContainer container = client.createDatabaseIfNotExists(DATABASE_NAME)
// TIP: Our APIs are Reactor Core based, so try to chain your calls
.flatMap(response -> response.getDatabase()
.flatMap(response -> client.getDatabase(DATABASE_NAME)
.createContainerIfNotExists(CONTAINER_NAME, "/id"))
.flatMap(response -> Mono.just(client.getDatabase(DATABASE_NAME).getContainer(CONTAINER_NAME)))
.block();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.azure.cosmos.implementation.Database;
import com.azure.cosmos.implementation.HttpConstants;
import com.azure.cosmos.implementation.directconnectivity.rntbd.RntbdMetrics;
import com.azure.cosmos.models.CosmosAsyncDatabaseResponse;
import com.azure.cosmos.models.CosmosDatabaseResponse;
import com.azure.cosmos.models.CosmosDatabaseProperties;
import com.azure.cosmos.models.CosmosDatabaseRequestOptions;
import com.azure.cosmos.models.CosmosPermissionProperties;
Expand Down Expand Up @@ -194,7 +194,7 @@ boolean isContentResponseOnWriteEnabled() {
* @return a {@link Mono} containing the cosmos database response with the created or existing database or
* an error.
*/
Mono<CosmosAsyncDatabaseResponse> createDatabaseIfNotExists(CosmosDatabaseProperties databaseSettings) {
Mono<CosmosDatabaseResponse> createDatabaseIfNotExists(CosmosDatabaseProperties databaseSettings) {
return createDatabaseIfNotExistsInternal(getDatabase(databaseSettings.getId()));
}

Expand All @@ -208,11 +208,11 @@ Mono<CosmosAsyncDatabaseResponse> createDatabaseIfNotExists(CosmosDatabaseProper
* @return a {@link Mono} containing the cosmos database response with the created or existing database or
* an error.
*/
public Mono<CosmosAsyncDatabaseResponse> createDatabaseIfNotExists(String id) {
public Mono<CosmosDatabaseResponse> createDatabaseIfNotExists(String id) {
return createDatabaseIfNotExistsInternal(getDatabase(id));
}

private Mono<CosmosAsyncDatabaseResponse> createDatabaseIfNotExistsInternal(CosmosAsyncDatabase database) {
private Mono<CosmosDatabaseResponse> createDatabaseIfNotExistsInternal(CosmosAsyncDatabase database) {
return database.read().onErrorResume(exception -> {
final Throwable unwrappedException = Exceptions.unwrap(exception);
if (unwrappedException instanceof CosmosException) {
Expand All @@ -239,7 +239,7 @@ private Mono<CosmosAsyncDatabaseResponse> createDatabaseIfNotExistsInternal(Cosm
* @param throughputProperties the throughputProperties.
* @return the mono.
*/
public Mono<CosmosAsyncDatabaseResponse> createDatabaseIfNotExists(String id, ThroughputProperties throughputProperties) {
public Mono<CosmosDatabaseResponse> createDatabaseIfNotExists(String id, ThroughputProperties throughputProperties) {
return this.getDatabase(id).read().onErrorResume(exception -> {
final Throwable unwrappedException = Exceptions.unwrap(exception);
if (unwrappedException instanceof CosmosException) {
Expand Down Expand Up @@ -267,16 +267,15 @@ public Mono<CosmosAsyncDatabaseResponse> createDatabaseIfNotExists(String id, Th
* @param options {@link CosmosDatabaseRequestOptions}.
* @return an {@link Mono} containing the single cosmos database response with the created database or an error.
*/
public Mono<CosmosAsyncDatabaseResponse> createDatabase(CosmosDatabaseProperties databaseSettings,
CosmosDatabaseRequestOptions options) {
public Mono<CosmosDatabaseResponse> createDatabase(CosmosDatabaseProperties databaseSettings,
CosmosDatabaseRequestOptions options) {
if (options == null) {
options = new CosmosDatabaseRequestOptions();
}
Database wrappedDatabase = new Database();
wrappedDatabase.setId(databaseSettings.getId());
return asyncDocumentClient.createDatabase(wrappedDatabase, ModelBridgeInternal.toRequestOptions(options))
.map(databaseResourceResponse -> ModelBridgeInternal.createCosmosAsyncDatabaseResponse(databaseResourceResponse,
this))
.map(databaseResourceResponse -> ModelBridgeInternal.createCosmosDatabaseResponse(databaseResourceResponse))
.single();
}

Expand All @@ -291,7 +290,7 @@ public Mono<CosmosAsyncDatabaseResponse> createDatabase(CosmosDatabaseProperties
* @param databaseSettings {@link CosmosDatabaseProperties}.
* @return an {@link Mono} containing the single cosmos database response with the created database or an error.
*/
public Mono<CosmosAsyncDatabaseResponse> createDatabase(CosmosDatabaseProperties databaseSettings) {
public Mono<CosmosDatabaseResponse> createDatabase(CosmosDatabaseProperties databaseSettings) {
return createDatabase(databaseSettings, new CosmosDatabaseRequestOptions());
}

Expand All @@ -306,7 +305,7 @@ public Mono<CosmosAsyncDatabaseResponse> createDatabase(CosmosDatabaseProperties
* @param id id of the database.
* @return a {@link Mono} containing the single cosmos database response with the created database or an error.
*/
public Mono<CosmosAsyncDatabaseResponse> createDatabase(String id) {
public Mono<CosmosDatabaseResponse> createDatabase(String id) {
return createDatabase(new CosmosDatabaseProperties(id), new CosmosDatabaseRequestOptions());
}

Expand All @@ -323,18 +322,17 @@ public Mono<CosmosAsyncDatabaseResponse> createDatabase(String id) {
* @param options {@link CosmosDatabaseRequestOptions}.
* @return an {@link Mono} containing the single cosmos database response with the created database or an error.
*/
public Mono<CosmosAsyncDatabaseResponse> createDatabase(CosmosDatabaseProperties databaseSettings,
ThroughputProperties throughputProperties,
CosmosDatabaseRequestOptions options) {
public Mono<CosmosDatabaseResponse> createDatabase(CosmosDatabaseProperties databaseSettings,
ThroughputProperties throughputProperties,
CosmosDatabaseRequestOptions options) {
if (options == null) {
options = new CosmosDatabaseRequestOptions();
}
ModelBridgeInternal.setThroughputProperties(options, throughputProperties);
Database wrappedDatabase = new Database();
wrappedDatabase.setId(databaseSettings.getId());
return asyncDocumentClient.createDatabase(wrappedDatabase, ModelBridgeInternal.toRequestOptions(options))
.map(databaseResourceResponse -> ModelBridgeInternal.createCosmosAsyncDatabaseResponse(databaseResourceResponse,
this))
.map(databaseResourceResponse -> ModelBridgeInternal.createCosmosDatabaseResponse(databaseResourceResponse))
.single();
}

Expand All @@ -350,7 +348,7 @@ public Mono<CosmosAsyncDatabaseResponse> createDatabase(CosmosDatabaseProperties
* @param throughputProperties the throughput properties for the database.
* @return an {@link Mono} containing the single cosmos database response with the created database or an error.
*/
public Mono<CosmosAsyncDatabaseResponse> createDatabase(CosmosDatabaseProperties databaseSettings, ThroughputProperties throughputProperties) {
public Mono<CosmosDatabaseResponse> createDatabase(CosmosDatabaseProperties databaseSettings, ThroughputProperties throughputProperties) {
CosmosDatabaseRequestOptions options = new CosmosDatabaseRequestOptions();
ModelBridgeInternal.setThroughputProperties(options, throughputProperties);
return createDatabase(databaseSettings, options);
Expand All @@ -368,7 +366,7 @@ public Mono<CosmosAsyncDatabaseResponse> createDatabase(CosmosDatabaseProperties
* @param throughput the throughput for the database.
* @return a {@link Mono} containing the single cosmos database response with the created database or an error.
*/
Mono<CosmosAsyncDatabaseResponse> createDatabase(String id, int throughput) {
Mono<CosmosDatabaseResponse> createDatabase(String id, int throughput) {
CosmosDatabaseRequestOptions options = new CosmosDatabaseRequestOptions();
ModelBridgeInternal.setThroughputProperties(options, ThroughputProperties.createManualThroughput(throughput));
return createDatabase(new CosmosDatabaseProperties(id), options);
Expand All @@ -381,7 +379,7 @@ Mono<CosmosAsyncDatabaseResponse> createDatabase(String id, int throughput) {
* @param throughputProperties the throughputProperties.
* @return the mono.
*/
public Mono<CosmosAsyncDatabaseResponse> createDatabase(String id, ThroughputProperties throughputProperties) {
public Mono<CosmosDatabaseResponse> createDatabase(String id, ThroughputProperties throughputProperties) {
CosmosDatabaseRequestOptions options = new CosmosDatabaseRequestOptions();
ModelBridgeInternal.setThroughputProperties(options, throughputProperties);
return createDatabase(new CosmosDatabaseProperties(id), options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.azure.cosmos.implementation.Offer;
import com.azure.cosmos.implementation.Paths;
import com.azure.cosmos.models.CosmosContainerResponse;
import com.azure.cosmos.models.CosmosAsyncDatabaseResponse;
import com.azure.cosmos.models.CosmosDatabaseResponse;
import com.azure.cosmos.models.CosmosUserResponse;
import com.azure.cosmos.models.CosmosContainerProperties;
import com.azure.cosmos.models.CosmosContainerRequestOptions;
Expand Down Expand Up @@ -63,7 +63,7 @@ public String getId() {
* @return an {@link Mono} containing the single cosmos database respone with
* the read database or an error.
*/
public Mono<CosmosAsyncDatabaseResponse> read() {
public Mono<CosmosDatabaseResponse> read() {
return read(new CosmosDatabaseRequestOptions());
}

Expand All @@ -78,12 +78,12 @@ public Mono<CosmosAsyncDatabaseResponse> read() {
* @return an {@link Mono} containing the single cosmos database response with
* the read database or an error.
*/
public Mono<CosmosAsyncDatabaseResponse> read(CosmosDatabaseRequestOptions options) {
public Mono<CosmosDatabaseResponse> read(CosmosDatabaseRequestOptions options) {
if (options == null) {
options = new CosmosDatabaseRequestOptions();
}
return getDocClientWrapper().readDatabase(getLink(), ModelBridgeInternal.toRequestOptions(options))
.map(response -> ModelBridgeInternal.createCosmosAsyncDatabaseResponse(response, getClient())).single();
.map(response -> ModelBridgeInternal.createCosmosDatabaseResponse(response)).single();
}

/**
Expand All @@ -95,7 +95,7 @@ public Mono<CosmosAsyncDatabaseResponse> read(CosmosDatabaseRequestOptions optio
*
* @return an {@link Mono} containing the single cosmos database response.
*/
public Mono<CosmosAsyncDatabaseResponse> delete() {
public Mono<CosmosDatabaseResponse> delete() {
return delete(new CosmosDatabaseRequestOptions());
}

Expand All @@ -109,12 +109,12 @@ public Mono<CosmosAsyncDatabaseResponse> delete() {
* @param options the request options.
* @return an {@link Mono} containing the single cosmos database response.
*/
public Mono<CosmosAsyncDatabaseResponse> delete(CosmosDatabaseRequestOptions options) {
public Mono<CosmosDatabaseResponse> delete(CosmosDatabaseRequestOptions options) {
if (options == null) {
options = new CosmosDatabaseRequestOptions();
}
return getDocClientWrapper().deleteDatabase(getLink(), ModelBridgeInternal.toRequestOptions(options))
.map(response -> ModelBridgeInternal.createCosmosAsyncDatabaseResponse(response, getClient())).single();
.map(response -> ModelBridgeInternal.createCosmosDatabaseResponse(response)).single();
}

/* CosmosAsyncContainer operations */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
package com.azure.cosmos;

import com.azure.core.annotation.ServiceClient;
import com.azure.cosmos.models.CosmosAsyncDatabaseResponse;
import com.azure.cosmos.models.CosmosDatabaseProperties;
import com.azure.cosmos.models.CosmosDatabaseRequestOptions;
import com.azure.cosmos.models.CosmosDatabaseResponse;
import com.azure.cosmos.models.FeedOptions;
import com.azure.cosmos.models.ModelBridgeInternal;
import com.azure.cosmos.models.SqlQuerySpec;
import com.azure.cosmos.models.ThroughputProperties;
import com.azure.cosmos.util.CosmosPagedFlux;
Expand Down Expand Up @@ -136,11 +134,9 @@ public CosmosDatabaseResponse createDatabase(String id, ThroughputProperties thr
return mapDatabaseResponseAndBlock(asyncClientWrapper.createDatabase(id, throughputProperties));
}

CosmosDatabaseResponse mapDatabaseResponseAndBlock(Mono<CosmosAsyncDatabaseResponse> databaseMono) {
CosmosDatabaseResponse mapDatabaseResponseAndBlock(Mono<CosmosDatabaseResponse> databaseMono) {
try {
return databaseMono
.map(this::convertResponse)
.block();
return databaseMono.block();
} catch (Exception ex) {
final Throwable throwable = Exceptions.unwrap(ex);
if (throwable instanceof CosmosException) {
Expand Down Expand Up @@ -203,10 +199,6 @@ public CosmosDatabase getDatabase(String id) {
return new CosmosDatabase(id, this, asyncClientWrapper.getDatabase(id));
}

CosmosDatabaseResponse convertResponse(CosmosAsyncDatabaseResponse response) {
return ModelBridgeInternal.createCosmosDatabaseResponse(response, this);
}

CosmosAsyncClient asyncClient() {
return this.asyncClientWrapper;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.azure.cosmos.CosmosAsyncContainer;
import com.azure.cosmos.models.CosmosContainerResponse;
import com.azure.cosmos.CosmosAsyncDatabase;
import com.azure.cosmos.models.CosmosAsyncDatabaseResponse;
import com.azure.cosmos.models.CosmosDatabaseResponse;
import com.azure.cosmos.models.CosmosAsyncItemResponse;
import com.azure.cosmos.models.CosmosContainerProperties;
import com.azure.cosmos.models.CosmosContainerRequestOptions;
Expand Down Expand Up @@ -53,7 +53,7 @@ Flux<FeedResponse<JsonNode>> createDocumentChangeFeedQuery(CosmosAsyncContainer
* @param options the {@link CosmosContainerRequestOptions} for this request; it can be set as null.
* @return an {@link Mono} containing the single cosmos database response with the read database or an error.
*/
Mono<CosmosAsyncDatabaseResponse> readDatabase(CosmosAsyncDatabase database, CosmosDatabaseRequestOptions options);
Mono<CosmosDatabaseResponse> readDatabase(CosmosAsyncDatabase database, CosmosDatabaseRequestOptions options);

/**
* Reads a {@link CosmosAsyncContainer}.
Expand Down
Loading