Skip to content

Commit

Permalink
[HDInsight]Support new azure monitor (#18519)
Browse files Browse the repository at this point in the history
* {Docs} Remove stale reference in README to closed issue about extensions (#12771)

* Remove breaking change incoming notice and support new azure monitor

* fix cred scan ci error

* Replace CLIError with RequiredArgumentMissingError

Co-authored-by: Daniel Miller <[email protected]>
Co-authored-by: Azure CLI Team <[email protected]>
Co-authored-by: Zhenyu Zhou <[email protected]>
  • Loading branch information
4 people authored Jun 23, 2021
1 parent e94eced commit 8317978
Show file tree
Hide file tree
Showing 11 changed files with 3,171 additions and 865 deletions.
26 changes: 23 additions & 3 deletions src/azure-cli/azure/cli/command_modules/hdinsight/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,41 @@

helps['hdinsight monitor'] = """
type: group
short-summary: Manage Azure Monitor logs integration on an HDInsight cluster.
short-summary: Manage Classic Azure Monitor logs integration on an HDInsight cluster.
"""

helps['hdinsight monitor disable'] = """
type: command
short-summary: Disable the Azure Monitor logs integration on an HDInsight cluster.
short-summary: Disable the Classic Azure Monitor logs integration on an HDInsight cluster.
"""

helps['hdinsight monitor enable'] = """
type: command
short-summary: Enable the Azure Monitor logs integration on an HDInsight cluster.
short-summary: Enable the Classic Azure Monitor logs integration on an HDInsight cluster.
"""

helps['hdinsight monitor show'] = """
type: command
short-summary: Get the status of Classic Azure Monitor logs integration on an HDInsight cluster.
"""

helps['hdinsight azure-monitor'] = """
type: group
short-summary: Manage Azure Monitor logs integration on an HDInsight cluster.
"""

helps['hdinsight azure-monitor disable'] = """
type: command
short-summary: Disable the Azure Monitor logs integration on an HDInsight cluster.
"""

helps['hdinsight azure-monitor enable'] = """
type: command
short-summary: Enable the Azure Monitor logs integration on an HDInsight cluster.
"""

helps['hdinsight azure-monitor show'] = """
type: command
short-summary: Get the status of Azure Monitor logs integration on an HDInsight cluster.
"""

Expand Down
16 changes: 12 additions & 4 deletions src/azure-cli/azure/cli/command_modules/hdinsight/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,10 @@ def load_arguments(self, _):

# Node
c.argument('headnode_size', arg_type=node_size_type,
help='Incoming BREAKING CHANGE: The default value "large" will be removed in next CLI version.'
'The size of the node. See also: https://docs.microsoft.com/azure/'
help='The size of the node. See also: https://docs.microsoft.com/azure/'
'hdinsight/hdinsight-hadoop-provision-linux-clusters#configure-cluster-size')
c.argument('workernode_size', arg_type=node_size_type,
help='Incoming BREAKING CHANGE: The default value "large" will be removed in next CLI version.'
'The size of the node. See also: https://docs.microsoft.com/azure/'
help='The size of the node. See also: https://docs.microsoft.com/azure/'
'hdinsight/hdinsight-hadoop-provision-linux-clusters#configure-cluster-size')
c.argument('workernode_data_disks_per_node', arg_group='Node',
help='The number of data disks to use per worker node.')
Expand Down Expand Up @@ -296,6 +294,16 @@ def load_arguments(self, _):
'Required when workspace ID is provided.')
c.ignore('workspace_type')

# Azure Monitor
with self.argument_context('hdinsight azure-monitor') as c:
c.argument('workspace', validator=validate_workspace,
completer=get_resource_name_completion_list_under_subscription(
'Microsoft.OperationalInsights/workspaces'),
help='The name, resource ID or workspace ID of Log Analytics workspace.')
c.argument('primary_key', help='The certificate for the Log Analytics workspace. '
'Required when workspace ID is provided.')
c.ignore('workspace_type')

with self.argument_context('hdinsight host') as c:
c.argument('cluster_name', options_list=['--cluster-name'],
completer=get_resource_name_completion_list('Microsoft.HDInsight/clusters'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,19 @@ def load_command_table(self, _): # pylint: disable=too-many-statements
g.wait_command('wait')
g.command('delete', 'begin_delete', confirmation=True, supports_no_wait=True)

# Monitoring operations
# Monitoring operations(classic monitor)
with self.command_group('hdinsight monitor', hdinsight_extensions_sdk, client_factory=cf_hdinsight_extensions) as g:
g.show_command('show', 'get_monitoring_status')
g.custom_command('enable', 'enable_hdi_monitoring')
g.command('disable', 'begin_disable_monitoring')

# New Azure Monitor operations
with self.command_group('hdinsight azure-monitor', hdinsight_extensions_sdk,
client_factory=cf_hdinsight_extensions) as g:
g.show_command('show', 'get_azure_monitor_status')
g.custom_command('enable', 'enable_hdi_azure_monitor')
g.command('disable', 'begin_disable_azure_monitor')

# VirtualMachine operations
with self.command_group('hdinsight host', hdinsight_virtual_machines_sdk,
client_factory=cf_hdinsight_virtual_machines) as g:
Expand Down
43 changes: 43 additions & 0 deletions src/azure-cli/azure/cli/command_modules/hdinsight/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def create_cluster(cmd, client, cluster_name, resource_group_name, cluster_type,

if component_version:
# See validator
# pylint: disable=consider-using-dict-comprehension
component_version = dict([version.split('=') for version in component_version])

# Validate whether HTTP credentials were provided
Expand Down Expand Up @@ -568,6 +569,48 @@ def enable_hdi_monitoring(cmd, client, resource_group_name, cluster_name, worksp
monitor_request_parameter)


# pylint: disable=unused-argument
def enable_hdi_azure_monitor(cmd, client, resource_group_name, cluster_name, workspace, primary_key=None,
workspace_type='resource_id', no_validation_timeout=False):
from azure.mgmt.hdinsight.models import AzureMonitorRequest
from msrestazure.tools import parse_resource_id
from ._client_factory import cf_log_analytics

if workspace_type != 'resource_id' and not primary_key:
raise RequiredArgumentMissingError('primary key is required when workspace ID is provided.')

workspace_id = workspace
if workspace_type == 'resource_id':
parsed_workspace = parse_resource_id(workspace)
workspace_resource_group_name = parsed_workspace['resource_group']
workspace_name = parsed_workspace['resource_name']

log_analytics_client = cf_log_analytics(cmd.cli_ctx)
log_analytics_workspace = log_analytics_client.workspaces.get(workspace_resource_group_name, workspace_name)
if not log_analytics_workspace:
raise CLIError('Fails to retrieve workspace by {}'.format(workspace))

# Only retrieve primary key when not provided
if not primary_key:
shared_keys = log_analytics_client.shared_keys.get_shared_keys(workspace_resource_group_name,
workspace_name)
if not shared_keys:
raise CLIError('Fails to retrieve shared key for workspace {}'.format(log_analytics_workspace))

primary_key = shared_keys.primary_shared_key

workspace_id = log_analytics_workspace.customer_id

azure_monitor_request_parameter = AzureMonitorRequest(
workspace_id=workspace_id,
primary_key=primary_key
)
return client.begin_enable_azure_monitor(
resource_group_name,
cluster_name,
azure_monitor_request_parameter)


# pylint: disable=unused-argument
def execute_hdi_script_action(cmd, client, resource_group_name, cluster_name,
script_uri, script_action_name, roles, script_parameters=None,
Expand Down
Loading

0 comments on commit 8317978

Please sign in to comment.