Search in sources :

Example 6 with CosmosContainerResponse

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

the class AutoscaleContainerCRUDQuickstart method createContainerIfNotExists.

// Container create
private void createContainerIfNotExists() throws Exception {
    logger.info("Create autoscale container " + containerName + " if not exists.");
    // Container and autoscale throughput settings
    CosmosContainerProperties autoscaleContainerProperties = new CosmosContainerProperties(containerName, "/lastName");
    // Set autoscale max RU/s
    ThroughputProperties autoscaleThroughputProperties = ThroughputProperties.createAutoscaledThroughput(4000);
    // Create the container with autoscale enabled
    CosmosContainerResponse databaseResponse = database.createContainer(autoscaleContainerProperties, autoscaleThroughputProperties, new CosmosContainerRequestOptions());
    container = database.getContainer(databaseResponse.getProperties().getId());
    logger.info("Done.");
}
Also used : CosmosContainerRequestOptions(com.azure.cosmos.models.CosmosContainerRequestOptions) ThroughputProperties(com.azure.cosmos.models.ThroughputProperties) CosmosContainerProperties(com.azure.cosmos.models.CosmosContainerProperties) CosmosContainerResponse(com.azure.cosmos.models.CosmosContainerResponse)

Example 7 with CosmosContainerResponse

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

the class DocumentCRUDQuickstart method createContainerIfNotExists.

// Container create
private void createContainerIfNotExists() throws Exception {
    logger.info("Create container " + containerName + " if not exists.");
    // 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);
    container = database.getContainer(containerResponse.getProperties().getId());
    logger.info("Done.");
}
Also used : ThroughputProperties(com.azure.cosmos.models.ThroughputProperties) CosmosContainerProperties(com.azure.cosmos.models.CosmosContainerProperties) CosmosContainerResponse(com.azure.cosmos.models.CosmosContainerResponse)

Example 8 with CosmosContainerResponse

use of com.azure.cosmos.models.CosmosContainerResponse 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.");
}
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 9 with CosmosContainerResponse

use of com.azure.cosmos.models.CosmosContainerResponse 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();
}
Also used : CosmosContainerRequestOptions(com.azure.cosmos.models.CosmosContainerRequestOptions) PartitionKey(com.azure.cosmos.models.PartitionKey) LoggerFactory(org.slf4j.LoggerFactory) CosmosQueryRequestOptions(com.azure.cosmos.models.CosmosQueryRequestOptions) SampleCRUDQuickstartAsync(com.azure.cosmos.examples.crudquickstart.async.SampleCRUDQuickstartAsync) ArrayList(java.util.ArrayList) CosmosContainerRequestOptions(com.azure.cosmos.models.CosmosContainerRequestOptions) 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) PartitionKind(com.azure.cosmos.models.PartitionKind) CosmosContainerProperties(com.azure.cosmos.models.CosmosContainerProperties) Logger(org.slf4j.Logger) UserSessionData(com.azure.cosmos.examples.common.UserSessionData) CosmosContainerResponse(com.azure.cosmos.models.CosmosContainerResponse) PartitionKeyDefinitionVersion(com.azure.cosmos.models.PartitionKeyDefinitionVersion) Mono(reactor.core.publisher.Mono) CosmosItemResponse(com.azure.cosmos.models.CosmosItemResponse) CosmosClientBuilder(com.azure.cosmos.CosmosClientBuilder) Collectors(java.util.stream.Collectors) PartitionKeyBuilder(com.azure.cosmos.models.PartitionKeyBuilder) UserSession(com.azure.cosmos.examples.common.UserSession) Flux(reactor.core.publisher.Flux) List(java.util.List) CosmosAsyncClient(com.azure.cosmos.CosmosAsyncClient) CosmosAsyncDatabase(com.azure.cosmos.CosmosAsyncDatabase) PartitionKeyDefinition(com.azure.cosmos.models.PartitionKeyDefinition) 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) ArrayList(java.util.ArrayList) CosmosContainerProperties(com.azure.cosmos.models.CosmosContainerProperties) PartitionKeyDefinition(com.azure.cosmos.models.PartitionKeyDefinition) CosmosContainerResponse(com.azure.cosmos.models.CosmosContainerResponse)

Example 10 with CosmosContainerResponse

use of com.azure.cosmos.models.CosmosContainerResponse 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)

Aggregations

CosmosContainerResponse (com.azure.cosmos.models.CosmosContainerResponse)25 CosmosContainerProperties (com.azure.cosmos.models.CosmosContainerProperties)19 ThroughputProperties (com.azure.cosmos.models.ThroughputProperties)15 CosmosContainerRequestOptions (com.azure.cosmos.models.CosmosContainerRequestOptions)7 CosmosClientBuilder (com.azure.cosmos.CosmosClientBuilder)6 CosmosDatabaseResponse (com.azure.cosmos.models.CosmosDatabaseResponse)6 ArrayList (java.util.ArrayList)6 CosmosAsyncContainer (com.azure.cosmos.CosmosAsyncContainer)5 CosmosAsyncDatabase (com.azure.cosmos.CosmosAsyncDatabase)5 CosmosException (com.azure.cosmos.CosmosException)5 PartitionKey (com.azure.cosmos.models.PartitionKey)5 ConsistencyLevel (com.azure.cosmos.ConsistencyLevel)4 CosmosAsyncClient (com.azure.cosmos.CosmosAsyncClient)4 CosmosContainer (com.azure.cosmos.CosmosContainer)4 CosmosDatabase (com.azure.cosmos.CosmosDatabase)4 AccountSettings (com.azure.cosmos.examples.common.AccountSettings)4 CosmosItemResponse (com.azure.cosmos.models.CosmosItemResponse)4 IndexingPolicy (com.azure.cosmos.models.IndexingPolicy)4 Duration (java.time.Duration)4 CosmosQueryRequestOptions (com.azure.cosmos.models.CosmosQueryRequestOptions)3