Skip to content
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 @@ -4,6 +4,7 @@
<ProjectGuid>{033442D6-65E4-4A90-A6C0-9608B821A13B}</ProjectGuid>
<RootNamespace>HDInsight.Tests</RootNamespace>
<AssemblyName>HDInsight.Tests</AssemblyName>
<NuGetPackageImportStamp>c7e9322a</NuGetPackageImportStamp>
</PropertyGroup>
<Import Project="..\..\..\..\tools\Library.Settings.targets" />
<Import Project="$(LibraryToolsFolder)\Test.Dependencies.target" />
Expand All @@ -14,13 +15,14 @@
<Compile Include="ScenarioTests\CreateClusterTests.cs" />
<Compile Include="ScenarioTests\GetCapabilitiesTests.cs" />
<Compile Include="ScenarioTests\RdpTests.cs" />
<Compile Include="ScenarioTests\GetConfigurationTests.cs" />
<Compile Include="ScenarioTests\ResizeTests.cs" />
<Compile Include="ScenarioTests\HttpTests.cs" />
<Compile Include="ScenarioTests\ListClusterTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="packages.config" />
<None Include="SessionRecords\HDInsight.Tests.CreateClusterTests\TestCreateDuplicateCluster.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand All @@ -36,6 +38,9 @@
<None Include="SessionRecords\HDInsight.Tests.GetCapabilitiesTests\TestGetCapabilities.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\HDInsight.Tests.GetConfigurationTests\TestGetConfigCoreSiteCluster.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\HDInsight.Tests.HttpTests\TestDisableEnableHttp.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// Copyright (c) Microsoft. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

using System.Linq;
using System.Net;
using HDInsight.Tests.Helpers;
using Hyak.Common;
using Microsoft.Azure.Management.HDInsight;
using Microsoft.Azure.Management.HDInsight.Models;
using Microsoft.Azure.Test;
using Xunit;

namespace HDInsight.Tests
{
public class GetConfigurationTests
{
[Fact]
public void TestGetConfigCoreSiteCluster()
{
var handler = new RecordedDelegatingHandler {StatusCodeToReturn = HttpStatusCode.OK};

using (var context = UndoContext.Current)
{
context.Start();

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

var resourceGroup = HDInsightManagementTestUtilities.CreateResourceGroup(resourceManagementClient);
const string dnsname = "hdisdk-configtest";

var spec = GetClusterSpecHelpers.GetPaasClusterSpec();

client.Clusters.Create(resourceGroup, dnsname, spec);

var configs = client.Clusters.GetClusterConfigurations(resourceGroup, dnsname, "core-site");

Assert.Equal(2, configs.Configuration.Count);

client.Clusters.Delete(resourceGroup, dnsname);
}
}
}
}

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/ResourceManagement/HDInsight/HDInsight.Tests/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Azure.Management.Resources" version="2.18.0-preview" targetFramework="net45" />
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net451" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net451" />
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net451" />
<package id="Microsoft.Net.Http" version="2.2.22" targetFramework="net451" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -2777,6 +2777,185 @@ public async Task<CapabilitiesResponse> GetCapabilitiesAsync(string location, Ca
}
}

/// <summary>
/// Gets the configuration for the specified cluster.
/// </summary>
/// <param name='resourceGroupName'>
/// Required. The name of the resource group.
/// </param>
/// <param name='clusterName'>
/// Required. The name of the cluster.
/// </param>
/// <param name='configurationName'>
/// Required. The name of the cluster.
/// </param>
/// <param name='cancellationToken'>
/// Cancellation token.
/// </param>
/// <returns>
/// The Cluster Configurations operation response.
/// </returns>
public async Task<ClusterConfigurationsResponse> GetClusterConfigurationsAsync(string resourceGroupName, string clusterName, string configurationName, CancellationToken cancellationToken)
{
// Validate
if (resourceGroupName == null)
{
throw new ArgumentNullException("resourceGroupName");
}
if (clusterName == null)
{
throw new ArgumentNullException("clusterName");
}
if (configurationName == null)
{
throw new ArgumentNullException("configurationName");
}

// Tracing
bool shouldTrace = TracingAdapter.IsEnabled;
string invocationId = null;
if (shouldTrace)
{
invocationId = TracingAdapter.NextInvocationId.ToString();
Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
tracingParameters.Add("resourceGroupName", resourceGroupName);
tracingParameters.Add("clusterName", clusterName);
tracingParameters.Add("configurationName", configurationName);
TracingAdapter.Enter(invocationId, this, "GetClusterConfigurationsAsync", tracingParameters);
}

// Construct URL
string url = "";
url = url + "/subscriptions/";
if (this.Client.Credentials.SubscriptionId != null)
{
url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
}
url = url + "/resourceGroups/";
url = url + Uri.EscapeDataString(resourceGroupName);
url = url + "/providers/";
url = url + "Microsoft.HDInsight";
url = url + "/clusters/";
url = url + Uri.EscapeDataString(clusterName);
url = url + "/configurations/";
url = url + Uri.EscapeDataString(configurationName);
List<string> queryParameters = new List<string>();
queryParameters.Add("api-version=2015-03-01-preview");
if (queryParameters.Count > 0)
{
url = url + "?" + string.Join("&", queryParameters);
}
string baseUrl = this.Client.BaseUri.AbsoluteUri;
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl[baseUrl.Length - 1] == '/')
{
baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
}
if (url[0] == '/')
{
url = url.Substring(1);
}
url = baseUrl + "/" + url;
url = url.Replace(" ", "%20");

// Create HTTP transport objects
HttpRequestMessage httpRequest = null;
try
{
httpRequest = new HttpRequestMessage();
httpRequest.Method = HttpMethod.Get;
httpRequest.RequestUri = new Uri(url);

// Set Headers

// Set Credentials
cancellationToken.ThrowIfCancellationRequested();
await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

// Send Request
HttpResponseMessage httpResponse = null;
try
{
if (shouldTrace)
{
TracingAdapter.SendRequest(invocationId, httpRequest);
}
cancellationToken.ThrowIfCancellationRequested();
httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
if (shouldTrace)
{
TracingAdapter.ReceiveResponse(invocationId, httpResponse);
}
HttpStatusCode statusCode = httpResponse.StatusCode;
if (statusCode != HttpStatusCode.OK)
{
cancellationToken.ThrowIfCancellationRequested();
CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
if (shouldTrace)
{
TracingAdapter.Error(invocationId, ex);
}
throw ex;
}

// Create Result
ClusterConfigurationsResponse result = null;
// Deserialize Response
if (statusCode == HttpStatusCode.OK)
{
cancellationToken.ThrowIfCancellationRequested();
string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
result = new ClusterConfigurationsResponse();
JToken responseDoc = null;
if (string.IsNullOrEmpty(responseContent) == false)
{
responseDoc = JToken.Parse(responseContent);
}

if (responseDoc != null && responseDoc.Type != JTokenType.Null)
{
JToken configurationSequenceElement = ((JToken)responseDoc);
if (configurationSequenceElement != null && configurationSequenceElement.Type != JTokenType.Null)
{
foreach (JProperty property in configurationSequenceElement)
{
string configurationKey = ((string)property.Name);
string configurationValue = ((string)property.Value);
result.Configuration.Add(configurationKey, configurationValue);
}
}
}

}
result.StatusCode = statusCode;
if (httpResponse.Headers.Contains("x-ms-request-id"))
{
result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
}

if (shouldTrace)
{
TracingAdapter.Exit(invocationId, result);
}
return result;
}
finally
{
if (httpResponse != null)
{
httpResponse.Dispose();
}
}
}
finally
{
if (httpRequest != null)
{
httpRequest.Dispose();
}
}
}

/// <summary>
/// Gets the connectivity settings for the specified cluster.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,58 @@ public static Task<CapabilitiesResponse> GetCapabilitiesAsync(this IClusterOpera
return operations.GetCapabilitiesAsync(location, CancellationToken.None);
}

/// <summary>
/// Gets the configuration for the specified cluster.
/// </summary>
/// <param name='operations'>
/// Reference to the
/// Microsoft.Azure.Management.HDInsight.IClusterOperations.
/// </param>
/// <param name='resourceGroupName'>
/// Required. The name of the resource group.
/// </param>
/// <param name='clusterName'>
/// Required. The name of the cluster.
/// </param>
/// <param name='configurationName'>
/// Required. The name of the cluster.
/// </param>
/// <returns>
/// The Cluster Configurations operation response.
/// </returns>
public static ClusterConfigurationsResponse GetClusterConfigurations(this IClusterOperations operations, string resourceGroupName, string clusterName, string configurationName)
{
return Task.Factory.StartNew((object s) =>
{
return ((IClusterOperations)s).GetClusterConfigurationsAsync(resourceGroupName, clusterName, configurationName);
}
, operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
}

/// <summary>
/// Gets the configuration for the specified cluster.
/// </summary>
/// <param name='operations'>
/// Reference to the
/// Microsoft.Azure.Management.HDInsight.IClusterOperations.
/// </param>
/// <param name='resourceGroupName'>
/// Required. The name of the resource group.
/// </param>
/// <param name='clusterName'>
/// Required. The name of the cluster.
/// </param>
/// <param name='configurationName'>
/// Required. The name of the cluster.
/// </param>
/// <returns>
/// The Cluster Configurations operation response.
/// </returns>
public static Task<ClusterConfigurationsResponse> GetClusterConfigurationsAsync(this IClusterOperations operations, string resourceGroupName, string clusterName, string configurationName)
{
return operations.GetClusterConfigurationsAsync(resourceGroupName, clusterName, configurationName, CancellationToken.None);
}

/// <summary>
/// Gets the connectivity settings for the specified cluster.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,26 @@ public partial interface IClusterOperations
/// </returns>
Task<CapabilitiesResponse> GetCapabilitiesAsync(string location, CancellationToken cancellationToken);

/// <summary>
/// Gets the configuration for the specified cluster.
/// </summary>
/// <param name='resourceGroupName'>
/// The name of the resource group.
/// </param>
/// <param name='clusterName'>
/// The name of the cluster.
/// </param>
/// <param name='configurationName'>
/// The name of the cluster.
/// </param>
/// <param name='cancellationToken'>
/// Cancellation token.
/// </param>
/// <returns>
/// The Cluster Configurations operation response.
/// </returns>
Task<ClusterConfigurationsResponse> GetClusterConfigurationsAsync(string resourceGroupName, string clusterName, string configurationName, CancellationToken cancellationToken);

/// <summary>
/// Gets the connectivity settings for the specified cluster.
/// </summary>
Expand Down
Loading