Search in sources :

Example 11 with ThroughputProperties

use of com.azure.cosmos.models.ThroughputProperties in project azure-cosmos-java-sql-api-samples by Azure-Samples.

the class SampleCRUDQuickstart method createContainerIfNotExists.

private void createContainerIfNotExists() throws Exception {
    logger.info("Create container " + containerName + " if not exists.");
    // Create container if not exists
    // <CreateContainerIfNotExists>
    CosmosContainerProperties containerProperties = new CosmosContainerProperties(containerName, "/lastName");
    // Create container with 400 RU/s
    ThroughputProperties throughputProperties = ThroughputProperties.createManualThroughput(400);
    CosmosContainerResponse containerResponse = database.createContainerIfNotExists(containerProperties, throughputProperties);
    container = database.getContainer(containerResponse.getProperties().getId());
    // </CreateContainerIfNotExists>
    logger.info("Checking container " + container.getId() + " completed!\n");
}
Also used : ThroughputProperties(com.azure.cosmos.models.ThroughputProperties) CosmosContainerProperties(com.azure.cosmos.models.CosmosContainerProperties) CosmosContainerResponse(com.azure.cosmos.models.CosmosContainerResponse)

Example 12 with ThroughputProperties

use of com.azure.cosmos.models.ThroughputProperties in project scalardb by scalar-labs.

the class CosmosAdmin method createMetadataDatabaseAndContainerIfNotExists.

private void createMetadataDatabaseAndContainerIfNotExists() {
    ThroughputProperties manualThroughput = ThroughputProperties.createManualThroughput(Integer.parseInt(DEFAULT_REQUEST_UNIT));
    client.createDatabaseIfNotExists(metadataDatabase, manualThroughput);
    CosmosContainerProperties containerProperties = new CosmosContainerProperties(METADATA_CONTAINER, "/id");
    client.getDatabase(metadataDatabase).createContainerIfNotExists(containerProperties);
}
Also used : ThroughputProperties(com.azure.cosmos.models.ThroughputProperties) CosmosContainerProperties(com.azure.cosmos.models.CosmosContainerProperties)

Example 13 with ThroughputProperties

use of com.azure.cosmos.models.ThroughputProperties in project azure-cosmos-java-sql-api-samples by Azure-Samples.

the class SampleCRUDQuickstartAsync method createContainerIfNotExists.

private void createContainerIfNotExists() throws Exception {
    logger.info("Create container " + containerName + " if not exists.");
    // Create container if not exists
    // <CreateContainerIfNotExists>
    CosmosContainerProperties containerProperties = new CosmosContainerProperties(containerName, "/lastName");
    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();
}
Also used : CosmosContainerRequestOptions(com.azure.cosmos.models.CosmosContainerRequestOptions) PartitionKey(com.azure.cosmos.models.PartitionKey) LoggerFactory(org.slf4j.LoggerFactory) CosmosQueryRequestOptions(com.azure.cosmos.models.CosmosQueryRequestOptions) ArrayList(java.util.ArrayList) CosmosContainerRequestOptions(com.azure.cosmos.models.CosmosContainerRequestOptions) Families(com.azure.cosmos.examples.common.Families) Family(com.azure.cosmos.examples.common.Family) CosmosAsyncContainer(com.azure.cosmos.CosmosAsyncContainer) ThroughputProperties(com.azure.cosmos.models.ThroughputProperties) Duration(java.time.Duration) ConsistencyLevel(com.azure.cosmos.ConsistencyLevel) CosmosException(com.azure.cosmos.CosmosException) CosmosContainerProperties(com.azure.cosmos.models.CosmosContainerProperties) Logger(org.slf4j.Logger) CosmosContainerResponse(com.azure.cosmos.models.CosmosContainerResponse) Mono(reactor.core.publisher.Mono) CosmosItemResponse(com.azure.cosmos.models.CosmosItemResponse) CosmosClientBuilder(com.azure.cosmos.CosmosClientBuilder) Collectors(java.util.stream.Collectors) Flux(reactor.core.publisher.Flux) CosmosAsyncClient(com.azure.cosmos.CosmosAsyncClient) CosmosAsyncDatabase(com.azure.cosmos.CosmosAsyncDatabase) CosmosDatabaseResponse(com.azure.cosmos.models.CosmosDatabaseResponse) CosmosPagedFlux(com.azure.cosmos.util.CosmosPagedFlux) AccountSettings(com.azure.cosmos.examples.common.AccountSettings) ThroughputProperties(com.azure.cosmos.models.ThroughputProperties) CosmosContainerProperties(com.azure.cosmos.models.CosmosContainerProperties) CosmosContainerResponse(com.azure.cosmos.models.CosmosContainerResponse)

Example 14 with ThroughputProperties

use of com.azure.cosmos.models.ThroughputProperties in project azure-cosmos-java-sql-api-samples by Azure-Samples.

the class CosmosDiagnosticsQuickStartAsync 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
    Mono<CosmosContainerResponse> containerResponseMono = database.createContainerIfNotExists(containerProperties, throughputProperties);
    CosmosContainerResponse cosmosContainerResponse = containerResponseMono.block();
    CosmosDiagnostics diagnostics = cosmosContainerResponse.getDiagnostics();
    logger.info("Create container diagnostics : {}", diagnostics);
    container = database.getContainer(cosmosContainerResponse.getProperties().getId());
    logger.info("Done.");
}
Also used : ThroughputProperties(com.azure.cosmos.models.ThroughputProperties) CosmosContainerProperties(com.azure.cosmos.models.CosmosContainerProperties) CosmosDiagnostics(com.azure.cosmos.CosmosDiagnostics) CosmosContainerResponse(com.azure.cosmos.models.CosmosContainerResponse)

Example 15 with ThroughputProperties

use of com.azure.cosmos.models.ThroughputProperties in project azure-cosmos-java-sql-api-samples by Azure-Samples.

the class AutoscaleContainerCRUDQuickstart method readContainerThroughput.

private void readContainerThroughput() throws Exception {
    // Read the throughput on a resource
    ThroughputProperties autoscaleContainerThroughput = container.readThroughput().getProperties();
    // The autoscale max throughput (RU/s) of the resource
    int autoscaleMaxThroughput = autoscaleContainerThroughput.getAutoscaleMaxThroughput();
// The throughput (RU/s) the resource is currently scaled to
// int currentThroughput = autoscaleContainerThroughput.Throughput;
// logger.info("Autoscale max throughput: {} current throughput: {}",autoscaleMaxThroughput,currentThroughput);
}
Also used : ThroughputProperties(com.azure.cosmos.models.ThroughputProperties)

Aggregations

ThroughputProperties (com.azure.cosmos.models.ThroughputProperties)24 CosmosContainerProperties (com.azure.cosmos.models.CosmosContainerProperties)22 CosmosContainerResponse (com.azure.cosmos.models.CosmosContainerResponse)15 CosmosAsyncContainer (com.azure.cosmos.CosmosAsyncContainer)11 CosmosAsyncDatabase (com.azure.cosmos.CosmosAsyncDatabase)11 ArrayList (java.util.ArrayList)10 CosmosClientBuilder (com.azure.cosmos.CosmosClientBuilder)9 ConsistencyLevel (com.azure.cosmos.ConsistencyLevel)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 CosmosAsyncClient (com.azure.cosmos.CosmosAsyncClient)7 CosmosException (com.azure.cosmos.CosmosException)7 AccountSettings (com.azure.cosmos.examples.common.AccountSettings)7 Mono (reactor.core.publisher.Mono)7 CosmosDatabaseResponse (com.azure.cosmos.models.CosmosDatabaseResponse)6 CosmosItemResponse (com.azure.cosmos.models.CosmosItemResponse)6 Flux (reactor.core.publisher.Flux)6 CosmosContainerRequestOptions (com.azure.cosmos.models.CosmosContainerRequestOptions)5 PartitionKey (com.azure.cosmos.models.PartitionKey)5 CosmosPagedFlux (com.azure.cosmos.util.CosmosPagedFlux)5