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;
}
}
Aggregations