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

[Service Fabric] add sf cluster update command #4328 #29908

Open
wants to merge 23 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 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
@@ -0,0 +1,33 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core.breaking_change import register_command_group_deprecate, register_command_deprecate
register_command_group_deprecate('sf cluster setting', redirect='sf cluster update')
# Warning Message: This command group has been deprecated and will be removed in next breaking change release.
# Use `sf cluster update` instead.

register_command_group_deprecate('sf cluster upgrade-type', redirect='sf cluster update')
# Warning Message: This command group has been deprecated and will be removed in next breaking change release.
# Use `sf cluster update` instead.

register_command_deprecate('sf cluster durability', redirect='sf cluster update')
# Warning Message: This command has been deprecated and will be removed in next breaking change release.
# Use `sf cluster update` instead.

register_command_deprecate('sf cluster reliability update', redirect='sf cluster update')
# Warning Message: This command has been deprecated and will be removed in next breaking change release.
# Use `sf cluster update` instead.

register_command_deprecate('sf cluster setting remove', redirect='sf cluster update')
# Warning Message: This command has been deprecated and will be removed in next breaking change release.
# Use `sf cluster update` instead.

register_command_deprecate('sf cluster setting set', redirect='sf cluster update')
# Warning Message: This command has been deprecated and will be removed in next breaking change release.
# Use `sf cluster update` instead.

register_command_deprecate('sf cluster upgrade-type set', redirect='sf cluster update')
# Warning Message: This command has been deprecated and will be removed in next breaking change release.
# Use `sf cluster update` instead.
30 changes: 28 additions & 2 deletions src/azure-cli/azure/cli/command_modules/servicefabric/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,32 @@

"""

helps['sf cluster update'] = """
type: command
short-summary: Manage cluster updates.
examples:
- name: Change the cluster durability level to 'Silver'.
text: >
az sf cluster update -g group-name -c cluster1 --durability-level Silver --node-type nt1

- name: Change the cluster reliability level to 'Silver'.
text: >
az sf cluster update -g group-name -c cluster1 --reliability-level Silver --auto-add-node

- name: Set the `MaxFileOperationTimeout` setting for a cluster to 5 seconds.
text: >
az sf cluster update -g group-name -c cluster1 --settings-section-set --section 'NamingService' --parameter 'MaxFileOperationTimeout' --value 5000

- name: Remove the `MaxFileOperationTimeout` setting from a cluster.
text: >
az sf cluster update -g group-name -c cluster1 --settings-section-rem --section 'NamingService' --parameter 'MaxFileOperationTimeout'

- name: Set a cluster to use the 'Automatic' upgrade mode.
text: >
az sf cluster update -g group-name -c cluster1 --upgrade-mode Automatic

"""

helps['sf cluster list'] = """
type: command
short-summary: List cluster resources.
Expand All @@ -306,7 +332,7 @@
examples:
- name: Remove 2 'nt1' nodes from a cluster.
text: >
az sf cluster node remove -g group-name -c cluster1 --node-type 'nt1' --number-of-nodes-to-remove 2
az sf cluster node remove -g group-name -c cluster1 --number-of-nodes-to-rem 2 --node-type 'nt1'

"""

Expand All @@ -321,7 +347,7 @@
examples:
- name: Add a new node type to a cluster.
text: >
az sf cluster node-type add -g group-name -c cluster1 --node-type 'n2' --capacity 5 --vm-user-name 'adminName' --vm-password testPassword0
az sf cluster node-type add -g group-name -c cluster1 --node-type 'n2' --capacity 5 --vm-user-name 'adminName' --vm-password testPassword0 --durability-level Bronze

"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,6 @@ def load_arguments(self, _): # pylint: disable=too-many-statements
with self.argument_context('sf cluster client-certificate remove') as c:
c.argument('thumbprints', nargs='+', help='A single or Space-separated list of client certificate thumbprint(s) to be remove.')

with self.argument_context('sf cluster node') as c:
c.argument('number_of_nodes_to_add', options_list=['--number-of-nodes-to-add', '--nodes-to-add'], help='number of nodes to add.')
c.argument('number_of_nodes_to_remove', options_list=['--number-of-nodes-to-remove', '--nodes-to-remove'], help='number of nodes to remove.')

with self.argument_context('sf cluster node-type') as c:
c.argument('capacity', help='The capacity tag applied to nodes in the node type. The cluster resource manager uses these tags to understand how much capacity a node has.')
c.argument('vm_tier', help='VM tier.')

with self.argument_context('sf cluster') as c:
c.argument('durability_level', arg_type=get_enum_type(['Bronze', 'Silver', 'Gold']), help='durability level.')

Expand Down Expand Up @@ -147,6 +139,29 @@ def load_arguments(self, _): # pylint: disable=too-many-statements
help='JSON encoded parameters configuration. Use @{file} to load from a file. '
'For example: [{"section": "NamingService","parameter": "MaxOperationTimeout"}]')

with self.argument_context('sf cluster node') as c:
c.argument('number_of_nodes_to_add', options_list=['--number-of-nodes-to-add', '--nodes-to-add'], help='number of nodes to add.')
c.argument('number_of_nodes_to_remove', options_list=['--number-of-nodes-to-rem', '--nodes-to-remove'], help='number of nodes to remove.')
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need to rename --number-of-nodes-to-remove to --number-of-nodes-to-rem, I personally think that --number-of-nodes-to-remove has better readability than --number-of-nodes-to-rem

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was a complaint about length of the options in pipeline I believe. Also if the options are too long, the help output is not readable. This is a problem with one of our other commands az sf managed-applicatioin update -h

Copy link
Contributor

Choose a reason for hiding this comment

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

Please note that this will cause a breaking change for the customer, perhaps you can add a few shorter option names to bypass the complaint of length


with self.argument_context('sf cluster node-type') as c:
c.argument('capacity', help='The capacity tag applied to nodes in the node type. The cluster resource manager uses these tags to understand how much capacity a node has.')
c.argument('vm_tier', help='VM tier.')

with self.argument_context('sf cluster update') as c:
c.argument('durability_level', arg_type=get_enum_type(['Bronze', 'Silver', 'Gold']), help='durability level.')
c.argument('node_type', help='Nodetype name')
c.argument('parameter', help='parameter name')
c.argument('section', help='section name')
c.argument('value', help='Specify the value')
c.argument('version', help='cluster code version')
c.argument('upgrade_mode', arg_type=get_enum_type(['manual', 'automatic']), help='cluster upgrade mode')
c.argument('reliability_level', arg_type=get_enum_type(['Bronze', 'Silver', 'Gold', 'Platinum']), help='Reliability level.')
c.argument('auto_add_node', arg_type=get_three_state_flag(), help='Add node count automatically when changing reliability.')
c.argument('settings_section_set', arg_type=get_three_state_flag(),
help='Flag to set setting')
c.argument('settings_section_rem', arg_type=get_three_state_flag(),
help='Flag to remove setting')

with self.argument_context('sf cluster client-certificate remove') as c:
c.argument('client_certificate_common_names', options_list=['--client-certificate-common-names', '--client-cert-cn'], type=get_json_object,
help='JSON encoded parameters configuration. Use @{file} to load from a file. '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def load_command_table(self, _):
g.custom_command('create', 'new_cluster')
g.custom_command('client-certificate add', 'add_client_cert')
g.custom_command('client-certificate remove', 'remove_client_cert')
g.custom_command('update', 'update_cluster')
g.custom_command('setting set', 'set_cluster_setting')
g.custom_command('setting remove', 'remove_cluster_setting')
g.custom_command('reliability update', 'update_cluster_reliability_level')
Expand Down
73 changes: 73 additions & 0 deletions src/azure-cli/azure/cli/command_modules/servicefabric/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,22 +579,27 @@ def set_cluster_setting(cmd,
parameter=None,
value=None,
settings_section_description=None):

cli_ctx = cmd.cli_ctx

def _set(setting_dict, section, parameter, value):
if section not in setting_dict:
setting_dict[section] = {}
setting_dict[section][parameter] = value
return setting_dict

if settings_section_description and (section or parameter or value):
raise CLIError(
'Only can use either \'--settings-section-description\' or \'--section\', \'--parameter\' and \'--value\' to set the settings')

if section or parameter or value:
if section is None or parameter is None or value is None:
raise CLIError(
'\'--section\' , \'--parameter\' and \'--value\' can not be None')

cluster = client.get(resource_group_name, cluster_name)
setting_dict = _fabric_settings_to_dict(cluster.fabric_settings)

if settings_section_description:
for setting in settings_section_description:
if 'section' in setting and 'parameter' in setting and 'value' in setting:
Expand All @@ -604,6 +609,7 @@ def _set(setting_dict, section, parameter, value):
raise CLIError('settings_section_description is invalid')
else:
setting_dict = _set(setting_dict, section, parameter, value)

settings = _dict_to_fabric_settings(setting_dict)
patch_request = ClusterUpdateParameters(fabric_settings=settings)
update_cluster_poll = client.begin_update(resource_group_name, cluster_name, patch_request)
Expand Down Expand Up @@ -632,8 +638,10 @@ def _remove(setting_dict, section, parameter):
if settings_section_description and (section or parameter):
raise CLIError(
'Only can use either \'--settings-section-description\' or \'--section\' and \'--parameter \' to set the settings')

cluster = client.get(resource_group_name, cluster_name)
setting_dict = _fabric_settings_to_dict(cluster.fabric_settings)

if settings_section_description:
for setting in settings_section_description:
if 'section' in setting and 'parameter' in setting:
Expand Down Expand Up @@ -684,6 +692,71 @@ def update_cluster_reliability_level(cmd,
return LongRunningOperation(cli_ctx)(update_cluster_poll)


def validate_arguments(*args):
for arg in args:
if arg is None or arg is False:
raise CLIError(
'Invalid argument {}, Please run command: `az sf cluster update -h` for help message and examples of how to use the command'.
format(arg))


def validate_none_arguments(*args):
for arg in args:
if arg is not None and arg is True:
raise CLIError(
'Invalid argument {}, Please run command: `az sf cluster update -h` for help message and examples of how to use the command'.
format(arg))


def update_cluster(cmd,
client,
resource_group_name,
cluster_name,
node_type=None,
reliability_level=None,
auto_add_node=False,
section=None,
parameter=None,
settings_section_set=False,
settings_section_rem=False,
value=None,
upgrade_mode=None,
version=None,
durability_level=None):

if settings_section_set is True:
validate_none_arguments(node_type, reliability_level, auto_add_node,
settings_section_rem, upgrade_mode, version, durability_level)
validate_arguments(section, parameter, value)
return set_cluster_setting(cmd, client, resource_group_name, cluster_name, section, parameter, value)

if settings_section_rem is True:
validate_none_arguments(node_type, reliability_level, auto_add_node, value,
settings_section_set, upgrade_mode, version, durability_level)
validate_arguments(section, parameter)
return remove_cluster_setting(cmd, client, resource_group_name, cluster_name, section, parameter)

if reliability_level is not None:
validate_none_arguments(node_type, section, parameter, settings_section_set,
settings_section_rem, value, upgrade_mode, version, durability_level)
return update_cluster_reliability_level(cmd, client, resource_group_name,
cluster_name, reliability_level, auto_add_node)

if durability_level is not None:
validate_none_arguments(auto_add_node, reliability_level, section, parameter,
settings_section_set, settings_section_rem, value, upgrade_mode, version)
validate_arguments(node_type)
return update_cluster_durability(cmd, client, resource_group_name, cluster_name, node_type, durability_level)

if upgrade_mode is not None:
validate_none_arguments(node_type, reliability_level, auto_add_node, section, parameter,
settings_section_set, settings_section_rem, value, durability_level)
return update_cluster_upgrade_type(cmd, client, resource_group_name, cluster_name, upgrade_mode, version)

raise CLIError(
'Invalid arguments. Please run command: `az sf cluster update -h` for help message and examples of how to use the command')


def add_cluster_node_type(cmd,
client,
resource_group_name,
Expand Down
Loading