Skip to content

Commit

Permalink
[HDInsight] Support new azure monitor feature (#15068)
Browse files Browse the repository at this point in the history
* Support new azure monitor feature

* Change the cmdlet name Get/Enable/Disable-AzHDInsightMonitor to Get/Enable/Disable-AzHDInsightAzureMonitor

* Update the help doc and sdk version and add tests

* Add online version link

* Add related test

* Change setbynameparameterset to bynameparameterset

* Change the parameter set names to verb+ByName|ResourceId|InputObject style

Co-authored-by: Zhenyu Zhou <[email protected]>
  • Loading branch information
aim-for-better and Zhenyu Zhou authored Jun 7, 2021
1 parent 2bdfadd commit 9d76b1e
Show file tree
Hide file tree
Showing 21 changed files with 4,766 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/HDInsight/HDInsight.Test/HDInsight.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.5" />
<PackageReference Include="Microsoft.Azure.Management.HDInsight" Version="6.2.0" />
<PackageReference Include="Microsoft.Azure.Management.HDInsight" Version="7.0.0" />
<PackageReference Include="Microsoft.Azure.Management.HDInsight.Job" Version="2.0.7" />
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="3.1.0-preview.2" />
<PackageReference Include="Microsoft.Azure.Management.ManagedServiceIdentity" Version="0.11.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// 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 Microsoft.Azure.ServiceManagement.Common.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using System;
using System.Collections.Generic;
using System.Text;
using Xunit;
using Xunit.Abstractions;

namespace Commands.HDInsight.Test.ScenarioTests
{
public class HDInsightAzureMonitorTests
{
public XunitTracingInterceptor _logger;

public HDInsightAzureMonitorTests(ITestOutputHelper output)
{
_logger = new XunitTracingInterceptor(output);
XunitTracingInterceptor.AddToContext(_logger);
}

//[Fact(Skip = "test case cannot be re-recorded properly, need help from service team")]
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestAzureMonitorRelatedCommands()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AzureMonitorRelatedCommands");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# 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.
# ----------------------------------------------------------------------------------

<#
.SYNOPSIS
Test Get,Enable or Disable Azure Monitor in Azure HDInsight Cluster
#>
function Test-AzureMonitorRelatedCommands{

# Create some resources that will be used throughout test
try
{
$location = "East US"

# prepare parameter for creating parameter
$params= Prepare-ClusterCreateParameter -location $location

# create cluster that will be used throughout test
$cluster = New-AzHDInsightCluster -Location $params.location -ResourceGroupName $params.resourceGroupName `
-ClusterName $params.clusterName -ClusterSizeInNodes $params.clusterSizeInNodes -ClusterType $params.clusterType `
-StorageAccountResourceId $params.storageAccountResourceId -StorageAccountKey $params.storageAccountKey `
-HttpCredential $params.httpCredential -SshCredential $params.sshCredential `
-MinSupportedTlsVersion $params.minSupportedTlsVersion
Assert-NotNull $cluster

$workspaceName = Generate-Name("workspace-ps-test")
$resourceGroupName = $cluster.ResourceGroup

#create a new Log Analytics Workspace
$sku = "pernode"
$workspace = New-AzOperationalInsightsWorkspace -Location $location -Name $workspaceName -ResourceGroupName $resourceGroupName -Sku $sku

#get workspace's primaryKey
$keys = Get-AzOperationalInsightsWorkspaceSharedKey -ResourceGroupName $resourceGroupName -Name $workspace.Name
Assert-NotNull $keys
#test Get-AzHDInsightAzureMonitor
$result = Get-AzHDInsightAzureMonitor -ClusterName $cluster.Name -ResourceGroupName $cluster.ResourceGroup
Assert-Null $result.WorkspaceId

#test Enable-AzHDInsightAzureMonitor
$workspaceId = $workspace.CustomerId
$primaryKey = $keys.PrimarySharedKey

Assert-NotNull $workspaceId
Assert-NotNull $primaryKey
Enable-AzHDInsightAzureMonitor -ClusterName $cluster.Name -ResourceGroup $cluster.ResourceGroup -WorkspaceId $workspaceId -Primary $primaryKey

$result = Get-AzHDInsightAzureMonitor -ClusterName $cluster.Name -ResourceGroupName $cluster.ResourceGroup
Assert-True {$result.ClusterMonitoringEnabled}
Assert-AreEqual $result.WorkspaceId $workspaceId

#test Disable-AzHDInsightAzureMonitor
Disable-AzHDInsightAzureMonitor -ClusterName $cluster.Name -ResourceGroupName $cluster.ResourceGroup
$result = Get-AzHDInsightAzureMonitor -ClusterName $cluster.Name -ResourceGroupName $cluster.ResourceGroup
Assert-False {$result.ClusterMonitoringEnabled}
Assert-Null $result.WorkspaceId
}
finally
{
# Delete cluster and resource group
Remove-AzHDInsightCluster -ClusterName $cluster.Name
Remove-AzResourceGroup -ResourceGroupName $cluster.ResourceGroup
}
}
Loading

0 comments on commit 9d76b1e

Please sign in to comment.