Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK changes to support ADLS as option for default storage #2484

Merged
merged 8 commits into from
Nov 16, 2016
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<Compile Include="ScenarioTests\ListClusterTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScenarioTests\ScriptActionsOnRunningCluster.cs" />
<Compile Include="UnitTests\ClusterCreateTests.cs" />
<Compile Include="UnitTests\StorageAccountTests.cs" />
<Compile Include="UnitTests\MetastoreTests.cs" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -68,6 +70,9 @@
<None Include="SessionRecords\HDInsight.Tests.DataLakeTests\TestCreateDataLakeClusterUsingClusterParameters.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\HDInsight.Tests.DataLakeTests\TestCreateDefaultFsDataLakeClusterUsingClusterParameters.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\HDInsight.Tests.GetCapabilitiesTests\TestGetCapabilities.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -143,4 +148,4 @@
<Name>HDInsightManagement</Name>
</ProjectReference>
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace HDInsight.Tests.Helpers
{
public static class GetClusterSpecHelpers
{
private const string ADLClusterRootPath = "/Clusters/SDK";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit. can you remove this from here please? The values up here are just here because htey have to be set for recording. Can you please separate out the variable that's already been set?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value is required for recording too.
The value set here is included in the CSM request that is sent out.
This value is required by the AzureDataLakeStoreInfo constructor - please see GetClusterSpecHelpers.cs:GetDefaultAzureDataLakeStoreInfo() for details.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for confirmation from @shefaliv, so that I can include the changes (if any) in the upcoming PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add the changes here. This PR will not be accepted without requested changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right but it's not a value that has to be configured when recording and can be committed. The variables up here are just hte variables that have to be manually set for recording at the time of recording.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markcowl , there are no changes for this comment. @shefaliv to confirm.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shefaliv please confirm if we can close out this comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srsiva why are there no changes needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fixed now. I moved this variable within the test.

private const string ADLDefaultStorageAccountName = "";
private const string DefaultContainer = "";
private const string StorageAccountName = "";
private const string StorageAccountKey = "";
Expand Down Expand Up @@ -227,13 +229,12 @@ public static ClusterCreateParameters GetCustomCreateParametersPaas()
ClusterSizeInNodes = 3,
ClusterType = "Hadoop",
WorkerNodeSize = "Large",
DefaultStorageAccountName = StorageAccountName,
DefaultStorageAccountKey = StorageAccountKey,
DefaultStorageInfo = GetDefaultAzureStorageInfo(),
OSType = OSType.Windows,
UserName = HttpUser,
Password = HttpPassword,
DefaultStorageContainer = DefaultContainer,
Location = "West US"
Location = "East US",
Version = "3.2"
};
var actions = new List<ScriptAction>();
var action = new ScriptAction("action", new Uri("https://uri.com"), "params");
Expand All @@ -251,17 +252,47 @@ public static ClusterCreateParameters GetCustomCreateParametersIaas()
ClusterSizeInNodes = 3,
ClusterType = "Hadoop",
WorkerNodeSize = "Large",
DefaultStorageAccountName = StorageAccountName,
DefaultStorageAccountKey = StorageAccountKey,
DefaultStorageInfo = GetDefaultAzureStorageInfo(),
OSType = OSType.Linux,
UserName = HttpUser,
Password = HttpPassword,
DefaultStorageContainer = DefaultContainer,
Location = "West US",
Location = "East US",
SshUserName = SshUser,
SshPassword = SshPassword,
Version = "3.2"
};
return clusterparams;
}

public static ClusterCreateParameters GetDataLakeDefaultFsCreateParametersIaas()
{
var storageInfo = GetDefaultAzureDataLakeStoreInfo();
return GetDefaultFsCreateParametersIaas(storageInfo);
}

public static ClusterCreateParameters GetAzureBlobDefaultFsCreateParametersIaas(bool specifyDefaultContainer = true)
{
var storageInfo = GetDefaultAzureStorageInfo(specifyDefaultContainer);
return GetDefaultFsCreateParametersIaas(storageInfo);
}

private static ClusterCreateParameters GetDefaultFsCreateParametersIaas(StorageInfo defaultStorageInfo)
{
var clusterparams = new ClusterCreateParameters
{
ClusterSizeInNodes = 3,
ClusterType = "Hadoop",
WorkerNodeSize = "Large",
DefaultStorageInfo = defaultStorageInfo,
OSType = OSType.Linux,
UserName = HttpUser,
Password = HttpPassword,
Location = "East US",
SshUserName = SshUser,
SshPassword = SshPassword,
Version = "3.2"
};

return clusterparams;
}

Expand All @@ -272,13 +303,11 @@ public static ClusterCreateParameters GetCustomVmSizesCreateParametersIaas()
ClusterSizeInNodes = 1,
ClusterType = "HBase",
WorkerNodeSize = "Large",
DefaultStorageAccountName = StorageAccountName,
DefaultStorageAccountKey = StorageAccountKey,
DefaultStorageInfo = GetDefaultAzureStorageInfo(),
OSType = OSType.Linux,
UserName = HttpUser,
Password = HttpPassword,
DefaultStorageContainer = DefaultContainer,
Location = "West US",
Location = "East US",
SshUserName = SshUser,
SshPassword = SshPassword,
Version = "3.2",
Expand Down Expand Up @@ -329,5 +358,46 @@ public static ClusterCreateParametersExtended AddConfigurations(ClusterCreatePar

return cluster;
}

/// <summary>
/// Returns appropriate AzureStorageInfo based on test-mode.
/// </summary>
/// <returns></returns>
private static StorageInfo GetDefaultAzureStorageInfo(bool specifyDefaultContainer=true)
{
bool recordMode = HDInsightManagementTestUtilities.IsRecordMode();

if(recordMode)
{
return (specifyDefaultContainer)
? new AzureStorageInfo(StorageAccountName, StorageAccountKey, DefaultContainer)
: new AzureStorageInfo(StorageAccountName, StorageAccountKey);
}
else
{
string testStorageAccountName = "tmp.blob.core.windows.net";
string testStorageAccountKey = "teststorageaccountkey";
string testContainer = "testdefaultcontainer";

return (specifyDefaultContainer)
? new AzureStorageInfo(testStorageAccountName, testStorageAccountKey, testContainer)
: new AzureStorageInfo(testStorageAccountName, testStorageAccountKey);
}
}

/// <summary>
/// Returns appropriate AzureDataLakeStoreInfo based on test-mode.
/// </summary>
/// <returns></returns>
private static StorageInfo GetDefaultAzureDataLakeStoreInfo()
{
bool recordMode = HDInsightManagementTestUtilities.IsRecordMode();

return recordMode
? new AzureDataLakeStoreInfo(ADLDefaultStorageAccountName, ADLClusterRootPath)
: new AzureDataLakeStoreInfo("tmp.azuredatalakestore.net", ADLClusterRootPath);
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Microsoft.Azure.Management.Resources;
using Microsoft.Azure.Management.Resources.Models;
using Microsoft.Azure.Test;
using System;

namespace HDInsight.Tests.Helpers
{
Expand Down Expand Up @@ -85,5 +86,12 @@ public static void WaitForClusterToMoveToRunning(string resourceGroup, string dn

Xunit.Assert.True(!createError);
}

public static bool IsRecordMode()
{
string testMode = System.Environment.GetEnvironmentVariable("AZURE_TEST_MODE");
bool recordMode = !string.IsNullOrEmpty(testMode) && testMode.Equals("Record", StringComparison.OrdinalIgnoreCase);
return recordMode;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,28 +103,85 @@ public void TestCreateDataLakeClusterUsingClusterParameters()
//set variables
const string dnsname = "hdisdk-datalake5";

var spec = GetDataLakeClusterParameters();
spec.Version = "3.2";
var clusterCreateParams = GetDataLakeClusterParameters();

var createresponse = client.Clusters.Create(resourceGroup, dnsname, spec);
var createresponse = client.Clusters.Create(resourceGroup, dnsname, clusterCreateParams);
Assert.Equal(dnsname, createresponse.Cluster.Name);

//TODO: Assert if data lake configurations are set once shefali adds GetConfigurations support
var getresponse = client.Clusters.Get(resourceGroup, dnsname);
Assert.Equal(createresponse.Cluster.Properties.CreatedDate, getresponse.Cluster.Properties.CreatedDate);
Assert.Equal(createresponse.Cluster.Name, getresponse.Cluster.Name);

OperationResource result = client.Clusters.Delete(resourceGroup, dnsname);
// Assert cluster state
Assert.Equal(createresponse.Cluster.Properties.ClusterState, "Error"); // due to invalid script action
Assert.Equal(createresponse.Cluster.Properties.ErrorInfos.Count, 1);

// delete the cluster
var result = client.Clusters.Delete(resourceGroup, dnsname);
Assert.Equal(result.StatusCode, HttpStatusCode.OK);
Assert.Equal(result.State, AsyncOperationState.Succeeded);
}
}

private ClusterCreateParameters GetDataLakeClusterParameters()
[Fact]
public void TestCreateDefaultFsDataLakeClusterUsingClusterParameters()
{
var spec = GetClusterSpecHelpers.GetCustomCreateParametersPaas();
var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK };

ServicePrincipal servicePrincipal = new ServicePrincipal(new Guid(ApplicationId), new Guid(AadTenantId), CertificateFileBytes,
CertificatePassword);
spec.Principal = servicePrincipal;
return spec;
using (var context = UndoContext.Current)
{
context.Start();

//get clients
var client = HDInsightManagementTestUtilities.GetHDInsightManagementClient(handler);
var resourceManagementClient = HDInsightManagementTestUtilities.GetResourceManagementClient(handler);

//create resourcegroup
var resourceGroup = HDInsightManagementTestUtilities.CreateResourceGroup(resourceManagementClient);

//set variables
const string dnsname = "hdisdk-defaultfsdatalake1";

var clusterCreateParams = GetDefaultFsDatalakeClusterParameters();

var createresponse = client.Clusters.Create(resourceGroup, dnsname, clusterCreateParams);
Assert.Equal(dnsname, createresponse.Cluster.Name);
Assert.Equal(createresponse.Cluster.Properties.ClusterState, "Running");

var getresponse = client.Clusters.Get(resourceGroup, dnsname);
Assert.Equal(createresponse.Cluster.Properties.CreatedDate, getresponse.Cluster.Properties.CreatedDate);
Assert.Equal(createresponse.Cluster.Name, getresponse.Cluster.Name);

// delete the cluster
var result = client.Clusters.Delete(resourceGroup, dnsname);
Assert.Equal(result.StatusCode, HttpStatusCode.OK);
Assert.Equal(result.State, AsyncOperationState.Succeeded);
}
}

/// <summary>
/// ClusterCreateParameters used for DataLake default FS
/// </summary>
/// <returns></returns>
private ClusterCreateParameters GetDefaultFsDatalakeClusterParameters()
{
var clusterCreateParams = GetClusterSpecHelpers.GetDataLakeDefaultFsCreateParametersIaas();
clusterCreateParams.Principal = new ServicePrincipal(new Guid(ApplicationId), new Guid(AadTenantId),
CertificateFileBytes, CertificatePassword);
return clusterCreateParams;
}

/// <summary>
/// ClusterCreateParameters used for DataLake additional FS
/// </summary>
/// <returns></returns>
private ClusterCreateParameters GetDataLakeClusterParameters()
{
var clusterCreateParams = GetClusterSpecHelpers.GetCustomCreateParametersPaas();
clusterCreateParams.Principal = new ServicePrincipal(new Guid(ApplicationId), new Guid(AadTenantId),
CertificateFileBytes, CertificatePassword);
return clusterCreateParams;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ public void TestScriptActionsOnRunningCluster()
string failingScriptUri = "http://bing.com";

//this is set only for RECORD mode, playback this uri doesnt matter
if (!string.IsNullOrEmpty(clusterCreateParams.DefaultStorageAccountName))
if (HDInsightManagementTestUtilities.IsRecordMode())
{
failingScriptUri = string.Format(FailingScriptLocationFormat, clusterCreateParams.DefaultStorageAccountName, FailingScriptLocationContainer);
failingScriptUri = string.Format(FailingScriptLocationFormat, clusterCreateParams.DefaultStorageInfo.StorageAccountName, FailingScriptLocationContainer);
}

var executeScriptActionParams = GetExecuteScriptActionParams(true, scriptName, failingScriptUri);
Expand Down Expand Up @@ -234,14 +234,14 @@ private ClusterCreateParameters CreateClusterToValidateScriptActions(string reso
client.Clusters.Create(resourceGroup, dnsName, clusterCreateParams);

HDInsightManagementTestUtilities.WaitForClusterToMoveToRunning(resourceGroup, dnsName, client);

string storageAccountName =clusterCreateParams.DefaultStorageAccountName.Split('.')[0];

//upload only in record mode, storageaccount will be empty in playback mode
if (!string.IsNullOrEmpty(storageAccountName))
// upload only in record mode
if (HDInsightManagementTestUtilities.IsRecordMode())
{
//upload failing script to the cluster default storage account
var creds = new StorageCredentials(storageAccountName, clusterCreateParams.DefaultStorageAccountKey);
var defaultStorageAccount = clusterCreateParams.DefaultStorageInfo as AzureStorageInfo;
var storageAccountName = defaultStorageAccount.StorageAccountName.Split('.')[0];
var creds = new StorageCredentials(storageAccountName, defaultStorageAccount.StorageAccountKey);

var storageAccount = new CloudStorageAccount(creds, true);
var blobClient = storageAccount.CreateCloudBlobClient();
Expand Down
Loading