-
Notifications
You must be signed in to change notification settings - Fork 4.1k
[HDInsight] Support new azure monitor feature #15068
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
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4a63d13
Support new azure monitor feature
137195c
Change the cmdlet name Get/Enable/Disable-AzHDInsightMonitor to Get/E…
61f9545
Update the help doc and sdk version and add tests
5a2c41a
Add online version link
e9c074d
Add related test
9e6221d
Change setbynameparameterset to bynameparameterset
1de6bd6
Change the parameter set names to verb+ByName|ResourceId|InputObject …
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/HDInsight/HDInsight/ManagementCommands/DisableAzureHDInsightAzureMonitorCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } | ||
| } | ||
| } | ||
141 changes: 141 additions & 0 deletions
141
src/HDInsight/HDInsight/ManagementCommands/EnableAzureHDInsightAzureMonitorCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"; | ||
aim-for-better marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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); | ||
| } | ||
| } | ||
| } | ||
| } | ||
95 changes: 95 additions & 0 deletions
95
src/HDInsight/HDInsight/ManagementCommands/GetAzureHDInsightAzureMonitorCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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".
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed. Thanks~ |
||
| private const string SetByNameParameterSet = "SetByNameParameterSet"; | ||
aim-for-better marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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)); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.