Skip to content

HDInsight Bug Fixes #1021

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

Merged
merged 12 commits into from
Oct 2, 2015
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -203,7 +203,7 @@ public void StartJob()
{
CommandRuntime = commandRuntimeMock.Object,
HDInsightJobClient = hdinsightJobManagementMock.Object,
ClusterCredential = new PSCredential("httpuser", string.Format("Password1!").ConvertToSecureString()),
HttpCredential = new PSCredential("httpuser", string.Format("Password1!").ConvertToSecureString()),
ClusterName = ClusterName
};

Expand Down Expand Up @@ -245,7 +245,7 @@ public void StartJob()
JobDetail = new JobDetailRootJsonObject
{
Completed = "false",
User = cmdlet.ClusterCredential.UserName,
User = cmdlet.HttpCredential.UserName,
Id = jobid
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="JobCommands\GetAzureHDInsightJobCommand.cs" />
<Compile Include="JobCommands\NewAzureHDInsightSqoopJobDefinitionCommand.cs" />
<Compile Include="JobCommands\WaitAzureHDInsightJobCommand.cs" />
<Compile Include="JobCommands\NewAzureHDInsightStreamingMapReduceJobDefinitionCommand.cs" />
<Compile Include="JobCommands\NewAzureHDInsightMapReduceJobDefinitionCommand.cs" />
Expand All @@ -65,12 +66,14 @@
<Compile Include="HDInsightCmdletBase.cs" />
<Compile Include="ManagementCommands\GetAzureHDInsightClusterCommand.cs" />
<Compile Include="Constants.cs" />
<Compile Include="Models\Job\AzureHDInsightSqoopJobDefinition.cs" />
<Compile Include="Models\Job\AzureHDInsightJob.cs" />
<Compile Include="Models\Job\AzureHDInsightMapReduceJobDefinition.cs" />
<Compile Include="Models\Job\AzureHDInsightStreamingMapReduceJobDefinition.cs" />
<Compile Include="Models\Job\AzureHDInsightPigJobDefinition.cs" />
<Compile Include="Models\Job\AzureHDInsightHiveJobDefinition.cs" />
<Compile Include="Models\Job\AzureHDInsightJobDefinition.cs" />
<Compile Include="Models\Job\JobDisplayOutputType.cs" />
<Compile Include="Models\Management\AzureHDInsightCluster.cs" />
<Compile Include="Models\Management\AzureHDInsightConfig.cs" />
<Compile Include="Models\Job\AzureHdInsightJobManagementClient.cs" />
Expand All @@ -80,6 +83,7 @@
<Compile Include="Models\Management\AzureHDInsightMetastore.cs" />
<Compile Include="ManagementCommands\NewAzureHDInsightClusterCommand.cs" />
<Compile Include="ClusterConfigurationUtils.cs" />
<Compile Include="Models\Management\AzureHDInsightScriptAction.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -111,11 +115,11 @@
</Reference>
<Reference Include="Microsoft.Azure.Management.HDInsight, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.HDInsight.1.0.5-preview\lib\net40\Microsoft.Azure.Management.HDInsight.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.HDInsight.1.0.6-preview\lib\net40\Microsoft.Azure.Management.HDInsight.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Management.HDInsight.Job, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.HDInsight.Job.1.0.5-preview\lib\net40\Microsoft.Azure.Management.HDInsight.Job.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.HDInsight.Job.1.0.6-preview\lib\net40\Microsoft.Azure.Management.HDInsight.Job.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static class JobDefinitions
public const string AzureHDInsightPigJobDefinition = "AzureRmHDInsightPigJobDefinition";
public const string AzureHDInsightMapReduceJobDefinition = "AzureRmHDInsightMapReduceJobDefinition";
public const string AzureHDInsightStreamingMapReduceJobDefinition = "AzureRmHDInsightStreamingMapReduceJobDefinition";
public const string AzureHDInsightSqoopJobDefinition = "AzureRmHDInsightSqoopJobDefinition";
}

public static class ClusterConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,21 @@ protected string GetClusterConnection(string resourceGroupName, string clusterNa
}
return httpEndpoint;
}

protected string GetResourceGroupByAccountName(string clusterName)
{
try
{
var clusterId = HDInsightManagementClient.ListClusters().First(x => x.Name.Equals(clusterName, StringComparison.InvariantCultureIgnoreCase)).Id;
var rgStart = clusterId.IndexOf("resourceGroups/", StringComparison.InvariantCultureIgnoreCase) + ("resourceGroups/".Length);
var rgLength = (clusterId.IndexOf("/providers/", StringComparison.InvariantCultureIgnoreCase)) - rgStart;
return clusterId.Substring(rgStart, rgLength);
}
catch
{
throw new CloudException(string.Format("Could not find resource group for cluster {0}.", clusterName));
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,9 @@ namespace Microsoft.Azure.Commands.HDInsight
OutputType(typeof(AzureHDInsightJob))]
public class GetAzureHDInsightJobCommand : HDInsightCmdletBase
{
[Parameter(
Position = 0,
Mandatory = true,
HelpMessage = "Gets or sets the name of the resource group.")]
public string ResourceGroupName { get; set; }

#region Input Parameter Definitions
[Parameter(Mandatory = true,
Position = 1,
Position = 0,
HelpMessage = "The name of the cluster.")]
public string ClusterName
{
Expand All @@ -42,9 +37,10 @@ public string ClusterName
}

[Parameter(Mandatory = true,
Position = 2,
Position = 1,
HelpMessage = "The credentials with which to connect to the cluster.")]
public PSCredential ClusterCredential
[Alias("ClusterCredential")]
public PSCredential HttpCredential
{
get
{
Expand All @@ -62,12 +58,22 @@ public PSCredential ClusterCredential
}
}

[Parameter(Position = 3,
[Parameter(Position = 2,
HelpMessage = "The JobID of the jobDetails to stop.")]
public string JobId { get; set; }

[Parameter(HelpMessage = "Gets or sets the name of the resource group.")]
public string ResourceGroupName { get; set; }

#endregion


protected override void ProcessRecord()
{
if (ResourceGroupName == null)
{
ResourceGroupName = GetResourceGroupByAccountName(ClusterName);
}
_clusterName = GetClusterConnection(ResourceGroupName, ClusterName);
if (JobId != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Management.Automation;
using Hyak.Common;
using Microsoft.Azure.Commands.HDInsight.Commands;
using Microsoft.Azure.Commands.HDInsight.Models.Job;
using Microsoft.WindowsAzure.Commands.Common;

namespace Microsoft.Azure.Commands.HDInsight
Expand All @@ -25,45 +26,42 @@ namespace Microsoft.Azure.Commands.HDInsight
OutputType(typeof(string))]
public class GetAzureHDInsightJobOutputCommand : HDInsightCmdletBase
{
[Parameter(
Position = 0,
Mandatory = true,
HelpMessage = "Gets or sets the name of the resource group.")]
public string ResourceGroupName { get; set; }
#region Input Parameter Definitions

[Parameter(Mandatory = true,
Position = 1,
Position = 0,
HelpMessage = "The name of the cluster.")]
public string ClusterName
{
get { return _clusterName; }
set { _clusterName = value; }
}

[Parameter(Position = 2,
[Parameter(Position = 1,
Mandatory = true,
HelpMessage = "The JobID of the jobDetails to stop.")]
public string JobId { get; set; }

[Parameter(Position = 3,
[Parameter(Position = 2,
Mandatory = true,
HelpMessage = "The default container name.")]
public string DefaultContainer { get; set; }

[Parameter(Position = 4,
[Parameter(Position = 3,
Mandatory = true,
HelpMessage = "The default storage account name.")]
public string DefaultStorageAccountName { get; set; }

[Parameter(Position = 5,
[Parameter(Position = 4,
Mandatory = true,
HelpMessage = "The default storage account key.")]
public string DefaultStorageAccountKey { get; set; }

[Parameter(Mandatory = true,
Position = 6,
Position = 5,
HelpMessage = "The credentials with which to connect to the cluster.")]
public PSCredential ClusterCredential
[Alias("ClusterCredential")]
public PSCredential HttpCredential
{
get
{
Expand All @@ -79,20 +77,80 @@ public PSCredential ClusterCredential
}
}

[Parameter(HelpMessage = "Gets or sets the name of the resource group.")]
public string ResourceGroupName { get; set; }

[Parameter(HelpMessage = "The type of job output.", ParameterSetName = "Display")]
public JobDisplayOutputType DisplayOutputType { get; set; }

[Parameter(Mandatory = true, HelpMessage = "The type of output to download.", ParameterSetName = "Download")]
public JobDownloadOutputType DownloadOutputType { get; set; }

[Parameter(Mandatory = true, HelpMessage = "The folder to save the output to.", ParameterSetName = "Download")]
public string Folder { get; set; }

#endregion

protected override void ProcessRecord()
{
if (ResourceGroupName == null)
{
ResourceGroupName = GetResourceGroupByAccountName(ClusterName);
}
_clusterName = GetClusterConnection(ResourceGroupName, ClusterName);
var output = GetJobOutput();
WriteObject(output);
}

public string GetJobOutput()
if (ParameterSetName == "Display")
{
string output;
switch (DisplayOutputType)
{
case JobDisplayOutputType.StandardError:
output = GetJobError();
break;
case JobDisplayOutputType.TaskSummary:
output = GetJobTaskLogSummary();
break;
default:
output = GetJobOutput();
break;
}
WriteObject(output);
}
else
{
DownloadJobTaskLogs();
}
}

internal string GetJobOutput()
{
var output = HDInsightJobClient.GetJobOutput(JobId, DefaultStorageAccountName, DefaultStorageAccountKey, DefaultContainer);
var outputStr = Convert(output);
return outputStr;
}

private string GetJobError()
{
var output = HDInsightJobClient.GetJobError(JobId, DefaultStorageAccountName, DefaultStorageAccountKey,
DefaultContainer);
var outputStr = Convert(output);
return outputStr;
}

private string GetJobTaskLogSummary()
{
var output = HDInsightJobClient.GetJobTaskLogSummary(JobId, DefaultStorageAccountName, DefaultStorageAccountKey,
DefaultContainer);
var outputStr = Convert(output);
return outputStr;
}

private void DownloadJobTaskLogs()
{
HDInsightJobClient.GetJobTaskLogSummary(JobId, DefaultStorageAccountName, DefaultStorageAccountKey,
DefaultContainer);
}

private static string Convert(Stream stream)
{
var reader = new StreamReader(stream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ protected override void ProcessRecord()
//get variables from session
var clusterConnection = SessionState.PSVariable.Get(UseAzureHDInsightClusterCommand.ClusterEndpoint).Value.ToString();
var clusterCred =
(PSCredential) SessionState.PSVariable.Get(UseAzureHDInsightClusterCommand.ClusterCred).Value;
(PSCredential)SessionState.PSVariable.Get(UseAzureHDInsightClusterCommand.ClusterCred).Value;
var resourceGroup =
SessionState.PSVariable.Get(UseAzureHDInsightClusterCommand.CurrentResourceGroup).Value.ToString();

Expand Down Expand Up @@ -137,7 +137,7 @@ protected override void ProcessRecord()
ClusterName = clusterConnection,
ResourceGroupName = resourceGroup,
JobDefinition = hivejob,
ClusterCredential = clusterCred
HttpCredential = clusterCred
};

var jobCreationResult = startJobCommand.SubmitJob();
Expand All @@ -148,7 +148,7 @@ protected override void ProcessRecord()
WriteProgress(new ProgressRecord(0, "Waiting for job to complete", "In Progress"));
var waitJobCommand = new WaitAzureHDInsightJobCommand
{
ClusterCredential = clusterCred,
HttpCredential = clusterCred,
ResourceGroupName = resourceGroup,
ClusterName = clusterConnection,
JobId = jobid
Expand All @@ -161,7 +161,7 @@ protected override void ProcessRecord()
//get job output
var getOutputCommand = new GetAzureHDInsightJobOutputCommand
{
ClusterCredential = clusterCred,
HttpCredential = clusterCred,
ResourceGroupName = resourceGroup,
ClusterName = clusterConnection,
DefaultContainer = DefaultContainer,
Expand Down
Loading