use of com.microsoft.azure.cosmosdb.ConnectionPolicy in project ambry by linkedin.
the class AzureContainerCompactorIntegrationTest method cleanup.
/**
* Cleanup entries in the cosmos db container deletion table.
* @throws DocumentClientException in case of any exception.
*/
private void cleanup() throws DocumentClientException {
ConnectionPolicy connectionPolicy = new ConnectionPolicy();
connectionPolicy.setRequestTimeoutInMillis(cloudConfig.cloudQueryRequestTimeout);
// Note: retry decisions are made at CloudBlobStore level. Configure Cosmos with no retries.
RetryOptions noRetries = new RetryOptions();
noRetries.setMaxRetryAttemptsOnThrottledRequests(0);
connectionPolicy.setRetryOptions(noRetries);
if (azureCloudConfig.cosmosDirectHttps) {
logger.info("Using CosmosDB DirectHttps connection mode");
connectionPolicy.setConnectionMode(ConnectionMode.Direct);
}
AsyncDocumentClient asyncDocumentClient = new AsyncDocumentClient.Builder().withServiceEndpoint(azureCloudConfig.cosmosEndpoint).withMasterKeyOrResourceToken(azureCloudConfig.cosmosKey).withConnectionPolicy(connectionPolicy).withConsistencyLevel(ConsistencyLevel.Session).build();
Set<CosmosContainerDeletionEntry> entries = cloudDestination.getCosmosDataAccessor().getDeprecatedContainers(100);
AtomicBoolean error = new AtomicBoolean(false);
while (!entries.isEmpty() && !error.get()) {
entries.stream().forEach(entry -> {
try {
RequestOptions requestOptions = new RequestOptions();
requestOptions.setPartitionKey(new PartitionKey(entry.getId()));
cloudRequestAgent.doWithRetries(() -> CosmosDataAccessor.executeCosmosAction(() -> asyncDocumentClient.deleteDocument(azureCloudConfig.cosmosDeletedContainerCollectionLink + "/docs/" + entry.getId(), requestOptions).toBlocking().single(), null), "Test Cleanup", entry.getId());
} catch (CloudStorageException ex) {
logger.warn("Failed to delete container deprecation entry {}. Unable to cleanup", entry);
error.set(true);
}
});
entries = cloudDestination.getCosmosDataAccessor().getDeprecatedContainers(100);
}
}
use of com.microsoft.azure.cosmosdb.ConnectionPolicy in project ambry by linkedin.
the class CloudTestUtil method cleanupPartition.
/**
* Cleanup the specified partition in azure by deleting all the blobs of the partition.
* @param azureCloudConfig Properties containing the credentials needed for connection to azure.
* @param partitionId partition to be deleted.
*/
static void cleanupPartition(AzureCloudConfig azureCloudConfig, PartitionId partitionId) {
ConnectionPolicy connectionPolicy = new ConnectionPolicy();
AsyncDocumentClient asyncDocumentClient = new AsyncDocumentClient.Builder().withServiceEndpoint(azureCloudConfig.cosmosEndpoint).withMasterKeyOrResourceToken(azureCloudConfig.cosmosKey).withConnectionPolicy(connectionPolicy).withConsistencyLevel(ConsistencyLevel.Session).build();
SqlQuerySpec sqlQuerySpec = new SqlQuerySpec("select * from c where c.partitionId=\"" + partitionId.toPathString() + "\"");
FeedOptions feedOptions = new FeedOptions();
feedOptions.setPartitionKey(new PartitionKey(partitionId.toPathString()));
Iterator<FeedResponse<Document>> iterator = asyncDocumentClient.queryDocuments(azureCloudConfig.cosmosCollectionLink, sqlQuerySpec, feedOptions).toBlocking().getIterator();
RequestOptions requestOptions = new RequestOptions();
requestOptions.setPartitionKey(new PartitionKey(partitionId.toPathString()));
while (iterator.hasNext()) {
FeedResponse<Document> response = iterator.next();
response.getResults().forEach(document -> asyncDocumentClient.deleteDocument(azureCloudConfig.cosmosCollectionLink + "/docs/" + document.getId(), requestOptions).toBlocking().single());
}
}
Aggregations