Skip to content

Commit

Permalink
Add config option to connect to Cosmos with DirectHttps mode (#1243)
Browse files Browse the repository at this point in the history
  • Loading branch information
lightningrob authored and ankagrawal committed Aug 22, 2019
1 parent ba918f5 commit 8f671c9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class AzureCloudConfig {
public static final String COSMOS_COLLECTION_LINK = "cosmos.collection.link";
public static final String COSMOS_KEY = "cosmos.key";
public static final String COSMOS_MAX_RETRIES = "cosmos.max.retries";
public static final String COSMOS_DIRECT_HTTPS = "cosmos.direct.https";
public static final int DEFAULT_COSMOS_MAX_RETRIES = 5;

/**
Expand Down Expand Up @@ -61,11 +62,20 @@ public class AzureCloudConfig {
@Default("5")
public final int cosmosMaxRetries;

/**
* Flag indicating whether to use DirectHttps CosmosDB connection mode.
* Provides better performance but may not work with all firewall settings.
*/
@Config(COSMOS_DIRECT_HTTPS)
@Default("false")
public final boolean cosmosDirectHttps;

public AzureCloudConfig(VerifiableProperties verifiableProperties) {
azureStorageConnectionString = verifiableProperties.getString(AZURE_STORAGE_CONNECTION_STRING);
cosmosEndpoint = verifiableProperties.getString(COSMOS_ENDPOINT);
cosmosCollectionLink = verifiableProperties.getString(COSMOS_COLLECTION_LINK);
cosmosKey = verifiableProperties.getString(COSMOS_KEY);
cosmosMaxRetries = verifiableProperties.getInt(COSMOS_MAX_RETRIES, DEFAULT_COSMOS_MAX_RETRIES);
cosmosDirectHttps = verifiableProperties.getBoolean(COSMOS_DIRECT_HTTPS, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.github.ambry.cloud.CloudStorageException;
import com.github.ambry.commons.BlobId;
import com.github.ambry.config.CloudConfig;
import com.microsoft.azure.documentdb.ConnectionMode;
import com.microsoft.azure.documentdb.ConnectionPolicy;
import com.microsoft.azure.documentdb.ConsistencyLevel;
import com.microsoft.azure.documentdb.Document;
Expand Down Expand Up @@ -122,6 +123,10 @@ class AzureCloudDestination implements CloudDestination {
}
// Set up CosmosDB connection, including any proxy setting
ConnectionPolicy connectionPolicy = new ConnectionPolicy();
if (azureCloudConfig.cosmosDirectHttps) {
logger.info("Using CosmosDB DirectHttps connection mode");
connectionPolicy.setConnectionMode(ConnectionMode.DirectHttps);
}
if (cloudConfig.vcrProxyHost != null) {
connectionPolicy.setProxy(new HttpHost(cloudConfig.vcrProxyHost, cloudConfig.vcrProxyPort));
connectionPolicy.setHandleServiceUnavailableFromProxy(true);
Expand Down
1 change: 1 addition & 0 deletions ambry-cloud/src/test/resources/azure-test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ azure.storage.connection.string=<storage-account-credentials>
cosmos.endpoint=<cosmos-url>
cosmos.collection.link=/dbs/ambry-metadata/colls/blob-metadata
cosmos.key=<cosmos-key>
cosmos.direct.https=true

0 comments on commit 8f671c9

Please sign in to comment.