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 @@ -256,15 +256,17 @@ private void createClients() {
}

try {
cosmosAsyncContainer = cosmosAsyncDatabase.getContainer(this.configuration.getCollectionId()).read().block().getContainer();
cosmosAsyncContainer = cosmosAsyncDatabase.getContainer(this.configuration.getCollectionId());
cosmosAsyncContainer.read().block();
} catch (CosmosException e) {
if (e.getStatusCode() == HttpConstants.StatusCodes.NOTFOUND) {
cosmosAsyncContainer =
cosmosAsyncDatabase.createContainer(
this.configuration.getCollectionId(),
Configuration.DEFAULT_PARTITION_KEY_PATH,
ThroughputProperties.createManualThroughput(this.configuration.getThroughput())
).block().getContainer();
cosmosAsyncDatabase.createContainer(
this.configuration.getCollectionId(),
Configuration.DEFAULT_PARTITION_KEY_PATH,
ThroughputProperties.createManualThroughput(this.configuration.getThroughput())
).block();

cosmosAsyncContainer = cosmosAsyncDatabase.getContainer(this.configuration.getCollectionId());
logger.info("Collection {} is created for this test on host {}", this.configuration.getCollectionId(), endpoint);
if(!databaseCreated) {
collectionListToClear.add(cosmosAsyncContainer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,21 @@ abstract class AsyncBenchmark<T> {
}

try {
cosmosAsyncContainer = cosmosAsyncDatabase.getContainer(
this.configuration.getCollectionId()
).read().doOnError(error ->
cosmosAsyncContainer = cosmosAsyncDatabase.getContainer(this.configuration.getCollectionId());

cosmosAsyncContainer.read().doOnError(error ->
logger.error("Database {} creation failed due to ", this.configuration.getDatabaseId(), error)
).block().getContainer();
).block();

} catch (CosmosException e) {
if (e.getStatusCode() == HttpConstants.StatusCodes.NOTFOUND) {
cosmosAsyncContainer = cosmosAsyncDatabase.createContainer(
cosmosAsyncDatabase.createContainer(
this.configuration.getCollectionId(),
Configuration.DEFAULT_PARTITION_KEY_PATH,
ThroughputProperties.createManualThroughput(this.configuration.getThroughput())
).block().getContainer();
).block();

cosmosAsyncContainer = cosmosAsyncDatabase.getContainer(this.configuration.getCollectionId());
logger.info("Collection {} is created for this test", this.configuration.getCollectionId());
collectionCreated = true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,14 @@ public T apply(T o, Throwable throwable) {
}

try {
cosmosContainer = cosmosDatabase.getContainer(this.configuration.getCollectionId()).read().getContainer();
cosmosContainer = cosmosDatabase.getContainer(this.configuration.getCollectionId());
cosmosContainer.read();
} catch (CosmosException e) {
if (e.getStatusCode() == HttpConstants.StatusCodes.NOTFOUND) {
cosmosContainer = cosmosDatabase.createContainer(this.configuration.getCollectionId(),
cosmosDatabase.createContainer(this.configuration.getCollectionId(),
Configuration.DEFAULT_PARTITION_KEY_PATH,
ThroughputProperties.createManualThroughput(this.configuration.getThroughput()))
.getContainer();
ThroughputProperties.createManualThroughput(this.configuration.getThroughput()));
cosmosContainer = cosmosDatabase.getContainer(this.configuration.getCollectionId());
logger.info("Collection {} is created for this test", this.configuration.getCollectionId());
collectionCreated = true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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 @@ -98,12 +99,13 @@ private void createAndReplaceItem() {
}

private void createDbAndContainerBlocking() {

client.createDatabaseIfNotExists(DATABASE_NAME)
.doOnSuccess(cosmosDatabaseResponse -> log("Database: " + cosmosDatabaseResponse.getDatabase().getId()))
.doOnSuccess(cosmosDatabaseResponse -> log("Database: " + DATABASE_NAME))
.flatMap(dbResponse -> dbResponse.getDatabase()
.createContainerIfNotExists(new CosmosContainerProperties(CONTAINER_NAME,
"/country")))
.doOnSuccess(cosmosContainerResponse -> log("Container: " + cosmosContainerResponse.getContainer().getId()))
.createContainerIfNotExists(new CosmosContainerProperties(CONTAINER_NAME,
"/country")))
.doOnSuccess(cosmosContainerResponse -> log("Container: " + CONTAINER_NAME))
.doOnError(throwable -> log(throwable.getMessage()))
.publishOn(Schedulers.elastic())
.block();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.azure.cosmos.DirectConnectionConfig;
import com.azure.cosmos.ConsistencyLevel;
import com.azure.cosmos.CosmosAsyncContainer;
import com.azure.cosmos.models.CosmosAsyncContainerResponse;
import com.azure.cosmos.models.CosmosContainerResponse;
import com.azure.cosmos.CosmosAsyncDatabase;
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.CosmosException;
Expand Down Expand Up @@ -137,7 +137,7 @@ public static void deleteDatabase(CosmosAsyncDatabase cosmosDatabase) {
public static CosmosAsyncContainer createNewCollection(CosmosAsyncClient client, String databaseName, String collectionName) {
CosmosAsyncDatabase databaseLink = client.getDatabase(databaseName);
CosmosAsyncContainer collectionLink = databaseLink.getContainer(collectionName);
CosmosAsyncContainerResponse containerResponse = null;
CosmosContainerResponse containerResponse = null;

try {
containerResponse = collectionLink.read().block();
Expand Down Expand Up @@ -167,13 +167,13 @@ public static CosmosAsyncContainer createNewCollection(CosmosAsyncClient client,
throw new RuntimeException(String.format("Failed to create collection %s in database %s.", collectionName, databaseName));
}

return containerResponse.getContainer();
return databaseLink.getContainer(containerSettings.getId());
}

public static CosmosAsyncContainer createNewLeaseCollection(CosmosAsyncClient client, String databaseName, String leaseCollectionName) {
CosmosAsyncDatabase databaseLink = client.getDatabase(databaseName);
CosmosAsyncContainer leaseCollectionLink = databaseLink.getContainer(leaseCollectionName);
CosmosAsyncContainerResponse leaseContainerResponse = null;
CosmosContainerResponse leaseContainerResponse = null;

try {
leaseContainerResponse = leaseCollectionLink.read().block();
Expand Down Expand Up @@ -208,7 +208,7 @@ public static CosmosAsyncContainer createNewLeaseCollection(CosmosAsyncClient cl
throw new RuntimeException(String.format("Failed to create collection %s in database %s.", leaseCollectionName, databaseName));
}

return leaseContainerResponse.getContainer();
return databaseLink.getContainer(containerSettings.getId());
}

public static void createNewDocuments(CosmosAsyncContainer containerClient, int count, Duration delay) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

import com.azure.cosmos.CosmosAsyncClient;
import com.azure.cosmos.CosmosAsyncContainer;
import com.azure.cosmos.CosmosAsyncDatabase;
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.models.PartitionKey;
import reactor.core.publisher.Mono;

public class HelloWorldDemo {
private static final String DATABASE_NAME = "contoso-travel";
private static final String CONTAINER_NAME = "passengers";

public static void main(String[] args) {
new HelloWorldDemo().runDemo();
}
Expand All @@ -23,12 +27,12 @@ void runDemo() {

// Get a reference to the container
// This will create (or read) a database and its container.
CosmosAsyncContainer container = client.createDatabaseIfNotExists("contoso-travel")
CosmosAsyncContainer container = client.createDatabaseIfNotExists(DATABASE_NAME)
// TIP: Our APIs are Reactor Core based, so try to chain your calls
.flatMap(response -> response.getDatabase()
.createContainerIfNotExists("passengers", "/id"))
.flatMap(response -> Mono.just(response.getContainer()))
.block(); // Blocking for demo purposes (avoid doing this in production unless you must)
.createContainerIfNotExists(CONTAINER_NAME, "/id"))
.flatMap(response -> Mono.just(client.getDatabase(DATABASE_NAME).getContainer(CONTAINER_NAME)))
.block();

// Create an item
container.createItem(new Passenger("carla.davis@outlook.com", "Carla Davis", "SEA", "IND"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,6 @@ public static CosmosAsyncUser createCosmosAsyncUser(String id, CosmosAsyncDataba
return new CosmosAsyncUser(id, database);
}

@Warning(value = INTERNAL_USE_ONLY_WARNING)
public static CosmosContainer createCosmosContainer(String id, CosmosDatabase database, CosmosAsyncContainer container) {
return new CosmosContainer(id, database, container);
}

@Warning(value = INTERNAL_USE_ONLY_WARNING)
public static CosmosDatabase createCosmosDatabase(String id, CosmosClient client, CosmosAsyncDatabase database) {
return new CosmosDatabase(id, client, database);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.azure.cosmos.implementation.RequestOptions;
import com.azure.cosmos.implementation.Utils;
import com.azure.cosmos.implementation.query.QueryInfo;
import com.azure.cosmos.models.CosmosAsyncContainerResponse;
import com.azure.cosmos.models.CosmosContainerResponse;
import com.azure.cosmos.models.CosmosAsyncItemResponse;
import com.azure.cosmos.models.CosmosConflictProperties;
import com.azure.cosmos.models.CosmosContainerProperties;
Expand Down Expand Up @@ -70,7 +70,7 @@ public String getId() {
* @return an {@link Mono} containing the single Cosmos container response with
* the read container or an error.
*/
public Mono<CosmosAsyncContainerResponse> read() {
public Mono<CosmosContainerResponse> read() {
return read(new CosmosContainerRequestOptions());
}

Expand All @@ -85,12 +85,12 @@ public Mono<CosmosAsyncContainerResponse> read() {
* @return an {@link Mono} containing the single Cosmos container response with
* the read container or an error.
*/
public Mono<CosmosAsyncContainerResponse> read(CosmosContainerRequestOptions options) {
public Mono<CosmosContainerResponse> read(CosmosContainerRequestOptions options) {
if (options == null) {
options = new CosmosContainerRequestOptions();
}
return database.getDocClientWrapper().readCollection(getLink(), ModelBridgeInternal.toRequestOptions(options))
.map(response -> ModelBridgeInternal.createCosmosAsyncContainerResponse(response, database)).single();
.map(response -> ModelBridgeInternal.createCosmosContainerResponse(response, database)).single();
}

/**
Expand All @@ -104,12 +104,12 @@ public Mono<CosmosAsyncContainerResponse> read(CosmosContainerRequestOptions opt
* @return an {@link Mono} containing the single Cosmos container response for
* the deleted database or an error.
*/
public Mono<CosmosAsyncContainerResponse> delete(CosmosContainerRequestOptions options) {
public Mono<CosmosContainerResponse> delete(CosmosContainerRequestOptions options) {
if (options == null) {
options = new CosmosContainerRequestOptions();
}
return database.getDocClientWrapper().deleteCollection(getLink(), ModelBridgeInternal.toRequestOptions(options))
.map(response -> ModelBridgeInternal.createCosmosAsyncContainerResponse(response, database)).single();
.map(response -> ModelBridgeInternal.createCosmosContainerResponse(response, database)).single();
}

/**
Expand All @@ -122,7 +122,7 @@ public Mono<CosmosAsyncContainerResponse> delete(CosmosContainerRequestOptions o
* @return an {@link Mono} containing the single Cosmos container response for
* the deleted container or an error.
*/
public Mono<CosmosAsyncContainerResponse> delete() {
public Mono<CosmosContainerResponse> delete() {
return delete(new CosmosContainerRequestOptions());
}

Expand All @@ -138,7 +138,7 @@ public Mono<CosmosAsyncContainerResponse> delete() {
* @return an {@link Mono} containing the single Cosmos container response with
* the replaced container properties or an error.
*/
public Mono<CosmosAsyncContainerResponse> replace(CosmosContainerProperties containerProperties) {
public Mono<CosmosContainerResponse> replace(CosmosContainerProperties containerProperties) {
return replace(containerProperties, null);
}

Expand All @@ -155,15 +155,15 @@ public Mono<CosmosAsyncContainerResponse> replace(CosmosContainerProperties cont
* @return an {@link Mono} containing the single Cosmos container response with
* the replaced container properties or an error.
*/
public Mono<CosmosAsyncContainerResponse> replace(
public Mono<CosmosContainerResponse> replace(
CosmosContainerProperties containerProperties,
CosmosContainerRequestOptions options) {
if (options == null) {
options = new CosmosContainerRequestOptions();
}
return database.getDocClientWrapper()
.replaceCollection(ModelBridgeInternal.getV2Collection(containerProperties), ModelBridgeInternal.toRequestOptions(options))
.map(response -> ModelBridgeInternal.createCosmosAsyncContainerResponse(response, database)).single();
.map(response -> ModelBridgeInternal.createCosmosContainerResponse(response, database)).single();
}

/* CosmosAsyncItem operations */
Expand Down
Loading