public void TestAzureStorageInfo() { string existingStorageName = "testblob"; string existingStorageNameFqdn = "testblob.blob.core.windows.net"; string mooncakeStorageNameFqdn = "testblob.blob.core.chinacloudapi.cn"; string existingStorageKey = "testtest=="; string containerName = "testcontainer"; string existingStorageNameFqdnUri = string.Format("wasb://{0}@{1}", containerName, existingStorageNameFqdn); // Test for optional storageContainer var testStorageInfoOptionalContainer = new AzureStorageInfo(existingStorageNameFqdn, existingStorageKey); Assert.Equal(testStorageInfoOptionalContainer.StorageContainer, ""); var testStorageInfoContainer = new AzureStorageInfo(existingStorageNameFqdn, existingStorageKey, containerName); Assert.Equal(testStorageInfoContainer.StorageContainer, containerName); // Test storageAccountName is null TestAndAssert(() => { return new AzureStorageInfo("", existingStorageKey, containerName); }, GetErrorMessage(Constants.ERROR_INPUT_CANNOT_BE_EMPTY, "storageAccountName") ); // Test storageAccountKey is null TestAndAssert(() => { return new AzureStorageInfo(existingStorageNameFqdn, "", containerName); }, GetErrorMessage(Constants.ERROR_INPUT_CANNOT_BE_EMPTY, "storageAccountKey") ); // Test non-fully-qualified storageAccountName var testStorageAccountShortName = new AzureStorageInfo(existingStorageName, existingStorageKey); Assert.Equal(testStorageAccountShortName.StorageAccountName, existingStorageNameFqdn); // Test fully-qualified storageAccountName var testStorageAccountFullyQualifiedName = new AzureStorageInfo(existingStorageNameFqdn, existingStorageKey); Assert.Equal(testStorageAccountFullyQualifiedName.StorageAccountName, existingStorageNameFqdn); // Test fully-qualified-mooncake storageAccountName var testStorageAccountMooncakeFullyQualifiedName = new AzureStorageInfo(mooncakeStorageNameFqdn, existingStorageKey); Assert.Equal(testStorageAccountMooncakeFullyQualifiedName.StorageAccountName, mooncakeStorageNameFqdn); // Test storageAccountName with url input TestAndAssert(() => { return new AzureStorageInfo(existingStorageNameFqdnUri, existingStorageKey); }, GetErrorMessage(Constants.ERROR_SCHEME_SPECIFIED_IN_STORAGE_FQDN, "storageAccountName") ); // Test for StorageAccountUri var testWasbStorageInfo = new AzureStorageInfo(existingStorageNameFqdn, existingStorageKey, containerName); Assert.Equal(existingStorageNameFqdnUri, testWasbStorageInfo.StorageAccountUri); }
private static void AddDefaultStorageAccountToCoreConfig(string clusterName, ClusterCreateParameters clusterCreateParameters, Dictionary<string, string> coreConfig) { string coreConfigDefaultFSKey = "fs.defaultFS"; string coreConfigDefaultFSKeyFor_2_1_Clusters = "fs.default.name"; var defaultStorageAccountKey = (clusterCreateParameters.Version != null && clusterCreateParameters.Version.Equals("2.1")) ? coreConfigDefaultFSKeyFor_2_1_Clusters : coreConfigDefaultFSKey; var azureStorageAccountInfo = clusterCreateParameters.DefaultStorageInfo as AzureStorageInfo; var azureDataLakeStorageInfo = clusterCreateParameters.DefaultStorageInfo as AzureDataLakeStoreInfo; if(azureStorageAccountInfo != null) { if (string.IsNullOrWhiteSpace(azureStorageAccountInfo.StorageContainer)) { var storageInfoWithContainerName = new AzureStorageInfo(azureStorageAccountInfo.StorageAccountName, azureStorageAccountInfo.StorageAccountKey, clusterName); clusterCreateParameters.DefaultStorageInfo = storageInfoWithContainerName; coreConfig[defaultStorageAccountKey] = storageInfoWithContainerName.StorageAccountUri; } else { coreConfig[defaultStorageAccountKey] = azureStorageAccountInfo.StorageAccountUri; } } else if (azureDataLakeStorageInfo != null) { // setup the parameters required for DataLake containers coreConfig[defaultStorageAccountKey] = "adl://home"; coreConfig["dfs.adls.home.hostname"] = azureDataLakeStorageInfo.StorageAccountName; coreConfig["dfs.adls.home.mountpoint"] = azureDataLakeStorageInfo.StorageRootPath; } }