Search in sources :

Example 1 with StoredProcedure

use of com.microsoft.azure.cosmosdb.StoredProcedure in project ambry by linkedin.

the class CosmosDataAccessor method testConnectivity.

/**
 * Test connectivity to Azure CosmosDB
 */
void testConnectivity() {
    ResourceResponse<DocumentCollection> response = asyncDocumentClient.readCollection(cosmosCollectionLink, new RequestOptions()).toBlocking().single();
    if (response.getResource() == null) {
        throw new IllegalStateException("CosmosDB collection not found: " + cosmosCollectionLink);
    }
    logger.info("CosmosDB connection test succeeded.");
    if (purgeBatchSize > 1) {
        // Check for existence of BulkDelete stored procedure.
        // Source: https://github.com/Azure/azure-cosmosdb-js-server/blob/master/samples/stored-procedures/bulkDelete.js
        String sprocLink = cosmosCollectionLink + BULK_DELETE_SPROC;
        try {
            ResourceResponse<StoredProcedure> spResponse = asyncDocumentClient.readStoredProcedure(sprocLink, null).toBlocking().single();
            if (spResponse.getResource() == null) {
                logger.error("Did not find stored procedure {}, falling back to individual record deletions", sprocLink);
            } else {
                logger.info("Found stored procedure {}, will use it with batch size {}.", sprocLink, purgeBatchSize);
                bulkDeleteEnabled = true;
            }
        } catch (Exception ex) {
            logger.error("Did not find stored procedure {}, falling back to individual record deletions", sprocLink, ex);
        }
    } else {
        logger.info("Cosmos purge batch size = 1 ==> disabling bulk deletes.");
        bulkDeleteEnabled = false;
    }
}
Also used : StoredProcedure(com.microsoft.azure.cosmosdb.StoredProcedure) RequestOptions(com.microsoft.azure.cosmosdb.RequestOptions) DocumentCollection(com.microsoft.azure.cosmosdb.DocumentCollection) DocumentClientException(com.microsoft.azure.cosmosdb.DocumentClientException) CloudStorageException(com.github.ambry.cloud.CloudStorageException)

Aggregations

CloudStorageException (com.github.ambry.cloud.CloudStorageException)1 DocumentClientException (com.microsoft.azure.cosmosdb.DocumentClientException)1 DocumentCollection (com.microsoft.azure.cosmosdb.DocumentCollection)1 RequestOptions (com.microsoft.azure.cosmosdb.RequestOptions)1 StoredProcedure (com.microsoft.azure.cosmosdb.StoredProcedure)1