use of com.azure.cosmos.models.ThroughputProperties in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class CosmosDiagnosticsQuickStart method createContainerIfNotExists.
// Container create
private void createContainerIfNotExists() throws Exception {
logger.info("Creating container {} if not exists", containerName);
// Create container if not exists
CosmosContainerProperties containerProperties = new CosmosContainerProperties(containerName, "/lastName");
// Provision throughput
ThroughputProperties throughputProperties = ThroughputProperties.createManualThroughput(400);
// Create container with 200 RU/s
CosmosContainerResponse containerResponse = database.createContainerIfNotExists(containerProperties, throughputProperties);
CosmosDiagnostics diagnostics = containerResponse.getDiagnostics();
logger.info("Create container diagnostics : {}", diagnostics);
container = database.getContainer(containerResponse.getProperties().getId());
logger.info("Done.");
}
use of com.azure.cosmos.models.ThroughputProperties in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SalesOrder method MigrateJavaSDKv4ResourceAsync.
/**
* https://docs.microsoft.com/en-us/azure/cosmos-db/migrate-java-v4-sdk
* Migrate previous versions to Java SDK v4
*/
/**
* Migrate previous versions to Java SDK v4
*/
public static void MigrateJavaSDKv4ResourceAsync() {
String container_id = "family_container";
String partition_key = "/pk";
CosmosAsyncDatabase database = null;
// <MigrateJavaSDKv4ResourceAsync>
// Create Async client.
// Building an async client is still a sync operation.
CosmosAsyncClient client = new CosmosClientBuilder().endpoint("your.hostname").key("yourmasterkey").consistencyLevel(ConsistencyLevel.EVENTUAL).buildAsyncClient();
// Create database with specified name
client.createDatabaseIfNotExists("YourDatabaseName").flatMap(databaseResponse -> {
testDatabaseAsync = client.getDatabase("YourDatabaseName");
// Container properties - name and partition key
CosmosContainerProperties containerProperties = new CosmosContainerProperties("YourContainerName", "/id");
// Provision manual throughput
ThroughputProperties throughputProperties = ThroughputProperties.createManualThroughput(400);
// Create container
return database.createContainerIfNotExists(containerProperties, throughputProperties);
}).flatMap(containerResponse -> {
testContainerAsync = database.getContainer("YourContainerName");
return Mono.empty();
}).subscribe();
// </MigrateJavaSDKv4ResourceAsync>
}
use of com.azure.cosmos.models.ThroughputProperties in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SalesOrder method MigrateJavaSDKv4IndexingAsync.
/**
* https://docs.microsoft.com/en-us/azure/cosmos-db/migrate-java-v4-sdk
* Indexing
*/
/**
* Indexing
*/
public static void MigrateJavaSDKv4IndexingAsync() {
String containerName = "family_container";
String partition_key = "/pk";
CosmosAsyncDatabase database = null;
// <MigrateIndexingAsync>
CosmosContainerProperties containerProperties = new CosmosContainerProperties(containerName, "/lastName");
// Custom indexing policy
IndexingPolicy indexingPolicy = new IndexingPolicy();
indexingPolicy.setIndexingMode(IndexingMode.CONSISTENT);
// Included paths
List<IncludedPath> includedPaths = new ArrayList<>();
includedPaths.add(new IncludedPath("/*"));
indexingPolicy.setIncludedPaths(includedPaths);
// Excluded paths
List<ExcludedPath> excludedPaths = new ArrayList<>();
excludedPaths.add(new ExcludedPath("/name/*"));
indexingPolicy.setExcludedPaths(excludedPaths);
containerProperties.setIndexingPolicy(indexingPolicy);
ThroughputProperties throughputProperties = ThroughputProperties.createManualThroughput(400);
database.createContainerIfNotExists(containerProperties, throughputProperties);
CosmosAsyncContainer containerIfNotExists = database.getContainer(containerName);
// </MigrateIndexingAsync>
}
use of com.azure.cosmos.models.ThroughputProperties in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SampleQueryProfilerAsync method queryProfilerDemo.
// private static String customQuery =
// "SELECT * FROM c WHERE c.partitionKey ='Z50V4-745167' AND c.parameterDateTime >= '2020-04-10T27:16:00.000Z' AND c.parameterDateTime <= '2020-04-29T21:16:00.000Z' ORDER BY c.parameterDateTime DESC";
public static void queryProfilerDemo() {
// Create Async client.
// Building an async client is still a sync operation.
client = new CosmosClientBuilder().endpoint(AccountSettings.HOST).key(AccountSettings.MASTER_KEY).consistencyLevel(ConsistencyLevel.EVENTUAL).contentResponseOnWriteEnabled(false).buildAsyncClient();
// Describe the logic of database and container creation using Reactor...
client.createDatabaseIfNotExists(databaseName).flatMap(databaseResponse -> {
database = client.getDatabase(databaseResponse.getProperties().getId());
logger.info("\n\n\n\nCreated or connected to database {}.\n\n\n\n", databaseName);
CosmosContainerProperties containerProperties = new CosmosContainerProperties(containerName, partitionKey);
ThroughputProperties throughputProperties = ThroughputProperties.createManualThroughput(manualThroughput);
return database.createContainerIfNotExists(containerProperties, throughputProperties);
}).flatMap(containerResponse -> {
container = database.getContainer(containerResponse.getProperties().getId());
logger.info("\n\n\n\nCreated or connected to container {}.\n\n\n\n", containerName);
return Mono.empty();
}).block();
// With the client set up we are ready to execute and profile our query.
Profile.tic();
CosmosQueryRequestOptions queryOptions = new CosmosQueryRequestOptions();
queryOptions.setMaxDegreeOfParallelism(1000);
queryOptions.setMaxBufferedItemCount(1000);
int preferredPageSize = 1000;
executeQuery(customQuery, queryOptions, preferredPageSize);
double toc_time = Profile.toc_ms() / 1000.0;
logger.info("\n\n\n\nTotal query runtime (sec): {}.\n\n\n\n", toc_time);
// Close client. This is always sync.
logger.info("Closing client...");
client.close();
logger.info("Done with demo.");
}
use of com.azure.cosmos.models.ThroughputProperties in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SampleSubpartitioningAsync method createContainerIfNotExists.
private void createContainerIfNotExists() throws Exception {
logger.info("Create container " + containerName + " if not exists.");
// Create container if not exists
// <Create PartitionKeyDefinition>
List<String> partitionKeyPaths = new ArrayList<String>();
partitionKeyPaths.add("/tenantId");
partitionKeyPaths.add("/userId");
partitionKeyPaths.add("/sessionId");
PartitionKeyDefinition subpartitionKeyDefinition = new PartitionKeyDefinition();
subpartitionKeyDefinition.setPaths(partitionKeyPaths);
subpartitionKeyDefinition.setKind(PartitionKind.MULTI_HASH);
subpartitionKeyDefinition.setVersion(PartitionKeyDefinitionVersion.V2);
// <CreateContainerIfNotExists>
CosmosContainerProperties containerProperties = new CosmosContainerProperties(containerName, subpartitionKeyDefinition);
ThroughputProperties throughputProperties = ThroughputProperties.createManualThroughput(400);
Mono<CosmosContainerResponse> containerIfNotExists = database.createContainerIfNotExists(containerProperties, throughputProperties);
// Create container with 400 RU/s
CosmosContainerResponse cosmosContainerResponse = containerIfNotExists.block();
container = database.getContainer(cosmosContainerResponse.getProperties().getId());
// </CreateContainerIfNotExists>
// Modify existing container
containerProperties = cosmosContainerResponse.getProperties();
Mono<CosmosContainerResponse> propertiesReplace = container.replace(containerProperties, new CosmosContainerRequestOptions());
propertiesReplace.flatMap(containerResponse -> {
logger.info("setupContainer(): Container " + container.getId() + " in " + database.getId() + "has been updated with it's new properties.");
return Mono.empty();
}).onErrorResume((exception) -> {
logger.error("setupContainer(): Unable to update properties for container " + container.getId() + " in database " + database.getId() + ". e: " + exception.getLocalizedMessage());
return Mono.empty();
}).block();
}
Aggregations