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

[HDInsight] Support new azure monitor feature #15068

Merged
merged 7 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion src/HDInsight/HDInsight/Az.HDInsight.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ CmdletsToExport = 'Get-AzHDInsightJob', 'New-AzHDInsightSqoopJobDefinition',
'Get-AzHDInsightClusterAutoscaleConfiguration',
'New-AzHDInsightClusterAutoscaleConfiguration',
'Set-AzHDInsightClusterAutoscaleConfiguration',
'Remove-AzHDInsightClusterAutoscaleConfiguration'
'Remove-AzHDInsightClusterAutoscaleConfiguration',
'Get-AzHDInsightAzureMonitor',
'Enable-AzHDInsightAzureMonitor', 'Disable-AzHDInsightAzureMonitor'

# Variables to export from this module
# VariablesToExport = @()
Expand Down
5 changes: 5 additions & 0 deletions src/HDInsight/HDInsight/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
- Additional information about change #1
-->
## Upcoming Release
* Support new azure monitor feature in HDInsight:
- Add cmdlet `Get-AzHDInsightAzureMonitor` to allow customer to get the Azure Monitor status of HDInsight cluster.
- Add cmdlet `Enable-AzHDInsightAzureMonitor` to allow customer to enable the Azure Monitor in HDInsight cluster.
- Add cmdlet `Disable-AzHDInsightAzureMonitor` to allow customer to disable the Azure Monitor in HDInsight cluster.


## Version 4.2.1
* Supported getting default vmsize from backend if customer does not provide the related parameters: `-WorkerNodeSize`, `-HeadNodeSize`, `-ZookeeperNodeSize`, `-EdgeNodeSize`, `-KafkaManagementNodeSize`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// ----------------------------------------------------------------------------------
//
// 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.Commands.HDInsight.Commands;
using Microsoft.Azure.Commands.HDInsight.Models;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.HDInsight
{
[Cmdlet("Disable", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "HDInsightAzureMonitor", DefaultParameterSetName = SetByNameParameterSet, SupportsShouldProcess = true)]
[OutputType(typeof(bool))]
public class DisableAzureHDInsightAzureMonitorCommand : HDInsightCmdletBase
{
#region Input Parameter Definitions

private const string SetByNameParameterSet = "SetByNameParameterSet";
private const string SetByResourceIdParameterSet = "SetByResourceIdParameterSet";
private const string SetByInputObjectParameterSet = "SetByInputObjectParameterSet";

[Parameter(
Position = 0,
Mandatory = false,
ParameterSetName = SetByNameParameterSet,
HelpMessage = "Gets or sets the name of the resource group.")]
[ResourceGroupCompleter]
public string ResourceGroupName { get; set; }

[Parameter(
Position = 1,
Mandatory = true,
ParameterSetName = SetByNameParameterSet,
HelpMessage = "Gets or sets the name of the cluster.")]
[ResourceNameCompleter("Microsoft.HDInsight/clusters", nameof(ResourceGroupName))]
[ValidateNotNullOrEmpty]
public string ClusterName { get; set; }

[Parameter(
Position = 0,
Mandatory = true,
ValueFromPipelineByPropertyName = true,
ParameterSetName = SetByResourceIdParameterSet,
HelpMessage = "Gets or sets the resource id.")]
[ValidateNotNullOrEmpty]
public string ResourceId { get; set; }

[Parameter(
Position = 0,
Mandatory = true,
ValueFromPipeline = true,
ParameterSetName = SetByInputObjectParameterSet,
HelpMessage = "Gets or sets the input object.")]
[ValidateNotNull]
public AzureHDInsightCluster InputObject { get; set; }

#endregion

public override void ExecuteCmdlet()
{
if (this.IsParameterBound(c => c.ResourceId))
{
var resourceIdentifier = new ResourceIdentifier(ResourceId);
this.ClusterName = resourceIdentifier.ResourceName;
this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
}

if (this.IsParameterBound(c => c.InputObject))
{
this.ClusterName = this.InputObject.Name;
this.ResourceGroupName = this.InputObject.ResourceGroup;
}

if (ClusterName != null && ResourceGroupName == null)
{
ResourceGroupName = GetResourceGroupByAccountName(ClusterName);
}

if (ShouldProcess("Disable Azure Monitor"))
{
// ToDO: need to change the api
HDInsightManagementClient.DisableMonitoring(ResourceGroupName, ClusterName);
WriteObject(true);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// ----------------------------------------------------------------------------------
//
// 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.WindowsAzure.Commands.Common;
using Microsoft.Azure.Commands.HDInsight.Commands;
using Microsoft.Azure.Management.HDInsight.Models;
using System.Management.Automation;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Commands.HDInsight.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;

namespace Microsoft.Azure.Commands.HDInsight
{
[Cmdlet("Enable", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "HDInsightAzureMonitor", DefaultParameterSetName = SetByNameParameterSet, SupportsShouldProcess = true)]
[OutputType(typeof(bool))]
public class EnableAzureHDInsightAzureMonitorCommand : HDInsightCmdletBase
{
#region Input Parameter Definitions

private const string SetByNameParameterSet = "SetByNameParameterSet";
private const string SetByResourceIdParameterSet = "SetByResourceIdParameterSet";
private const string SetByInputObjectParameterSet = "SetByInputObjectParameterSet";

[Parameter(
Position = 0,
Mandatory = false,
ParameterSetName = SetByNameParameterSet,
HelpMessage = "Gets or sets the name of the resource group.")]
[ResourceGroupCompleter]
public string ResourceGroupName { get; set; }

[Parameter(
Position = 1,
Mandatory = true,
ParameterSetName = SetByNameParameterSet,
HelpMessage = "Gets or sets the name of the cluster.")]
[ResourceNameCompleter("Microsoft.HDInsight/clusters", nameof(ResourceGroupName))]
[ValidateNotNullOrEmpty]
public string ClusterName { get; set; }

[Parameter(
Position = 0,
Mandatory = true,
ValueFromPipelineByPropertyName = true,
ParameterSetName = SetByResourceIdParameterSet,
HelpMessage = "Gets or sets the resource id.")]
[ValidateNotNullOrEmpty]
public string ResourceId { get; set; }

[Parameter(
Position = 0,
Mandatory = true,
ValueFromPipeline = true,
ParameterSetName = SetByInputObjectParameterSet,
HelpMessage = "Gets or sets the input object.")]
[ValidateNotNull]
public AzureHDInsightCluster InputObject { get; set; }

[Parameter(
Position = 2,
Mandatory = true,
ParameterSetName = SetByNameParameterSet,
HelpMessage = "Gets or sets the ID of the Log Analytics workspace.")]
[Parameter(
Position = 1,
Mandatory = true,
ParameterSetName = SetByResourceIdParameterSet,
HelpMessage = "Gets or sets the ID of the Log Analytics workspace.")]
[Parameter(
Position = 1,
Mandatory = true,
ParameterSetName = SetByInputObjectParameterSet,
HelpMessage = "Gets or sets the ID of the Log Analytics workspace.")]
public string WorkspaceId { get; set; }

[Parameter(
Position = 3,
Mandatory = true,
ParameterSetName = SetByNameParameterSet,
HelpMessage = "Gets to sets the primary key of the Log Analytics workspace.")]
[Parameter(
Position = 2,
Mandatory = true,
ParameterSetName = SetByResourceIdParameterSet,
HelpMessage = "Gets to sets the primary key of the Log Analytics workspace.")]
[Parameter(
Position = 2,
Mandatory = true,
ParameterSetName = SetByInputObjectParameterSet,
HelpMessage = "Gets to sets the primary key of the Log Analytics workspace.")]
public string PrimaryKey { get; set; }

#endregion

public override void ExecuteCmdlet()
{
if (this.IsParameterBound(c => c.ResourceId))
{
var resourceIdentifier = new ResourceIdentifier(ResourceId);
this.ClusterName = resourceIdentifier.ResourceName;
this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
}

if (this.IsParameterBound(c => c.InputObject))
{
this.ClusterName = this.InputObject.Name;
this.ResourceGroupName = this.InputObject.ResourceGroup;
}

if (ClusterName != null && ResourceGroupName == null)
{
ResourceGroupName = GetResourceGroupByAccountName(ClusterName);
}

var monitoringParams = new ClusterMonitoringRequest
{
WorkspaceId = WorkspaceId,
PrimaryKey = PrimaryKey
};

if (ShouldProcess("Enable Azure Monitor"))
{
// ToDO: need to change the api
HDInsightManagementClient.EnableMonitoring(ResourceGroupName, ClusterName, monitoringParams);
WriteObject(true);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// ----------------------------------------------------------------------------------
//
// 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.Commands.HDInsight.Commands;
using Microsoft.Azure.Commands.HDInsight.Models;
using Microsoft.Azure.Commands.HDInsight.Models.Management;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.HDInsight
{
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "HDInsightAzureMonitor", DefaultParameterSetName = SetByNameParameterSet)]
[OutputType(typeof(AzureHDInsightMonitoring))]
public class GetAzureHDInsightAzureMonitorCommand : HDInsightCmdletBase
{
#region Input Parameter Definitions
Copy link
Contributor

Choose a reason for hiding this comment

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

My proposal is to remove all the prefixes "Set" as you cmdlet verb is not "Set".

        private const string ByNameParameterSet = "ByNameParameterSet";
        private const string ByResourceIdParameterSet = "ByResourceIdParameterSet";
        private const string ByInputObjectParameterSet = "ByInputObjectParameterSet";

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed. Thanks~

private const string SetByNameParameterSet = "SetByNameParameterSet";
private const string SetByResourceIdParameterSet = "SetByResourceIdParameterSet";
private const string SetByInputObjectParameterSet = "SetByInputObjectParameterSet";

[Parameter(
Position = 0,
Mandatory = false,
ParameterSetName = SetByNameParameterSet,
HelpMessage = "Gets or sets the name of the resource group.")]
[ResourceGroupCompleter]
public string ResourceGroupName { get; set; }

[Parameter(
Position = 1,
Mandatory = true,
ParameterSetName = SetByNameParameterSet,
HelpMessage = "Gets or sets the name of the cluster.")]
[ResourceNameCompleter("Microsoft.HDInsight/clusters", nameof(ResourceGroupName))]
[ValidateNotNullOrEmpty]
public string ClusterName { get; set; }

[Parameter(
Position = 0,
Mandatory = true,
ValueFromPipelineByPropertyName = true,
ParameterSetName = SetByResourceIdParameterSet,
HelpMessage = "Gets or sets the resource id.")]
[ValidateNotNullOrEmpty]
public string ResourceId { get; set; }

[Parameter(
Position = 0,
Mandatory = true,
ValueFromPipeline = true,
ParameterSetName = SetByInputObjectParameterSet,
HelpMessage = "Gets or sets the input object.")]
[ValidateNotNull]
public AzureHDInsightCluster InputObject { get; set; }

#endregion

public override void ExecuteCmdlet()
{
if (this.IsParameterBound(c => c.ResourceId))
{
var resourceIdentifier = new ResourceIdentifier(ResourceId);
this.ClusterName = resourceIdentifier.ResourceName;
this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
}

if (this.IsParameterBound(c => c.InputObject))
{
this.ClusterName = this.InputObject.Name;
this.ResourceGroupName = this.InputObject.ResourceGroup;
}

if (ClusterName != null && ResourceGroupName == null)
{
ResourceGroupName = GetResourceGroupByAccountName(ClusterName);
}
// ToDO: need to change the api and redefine a class to replace AzureHDInsightMonitoring
var clusterMonitoringResource = HDInsightManagementClient.GetMonitoring(ResourceGroupName, ClusterName);
WriteObject(new AzureHDInsightMonitoring(clusterMonitoringResource));
}
}
}
Loading