Skip to content

Commit e70f1c0

Browse files
iliu816NoriZC
andauthored
[Az.ServiceFabric] Add cmdlets Disable-AzServiceFabricManagedNodeType, Enable-AzServiceFabricManagedNodeType, Move-AzServiceFabricManagedNodeType (#28457)
Co-authored-by: NoriZC <[email protected]>
1 parent 0a2cced commit e70f1c0

File tree

10 files changed

+3287
-2151
lines changed

10 files changed

+3287
-2151
lines changed

src/ServiceFabric/ServiceFabric.Test/ScenarioTests/ServiceFabricManagedClustersTests.ps1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,24 @@ function Test-NodeTypeOperations
8282
Assert-AreEqual "StandardSSD_LRS" $snt.DataDiskType
8383
Assert-True { $snt.IsStateless }
8484

85-
$restart = Restart-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name snt -NodeName snt_0, snt_1 -PassThru
85+
$restart = Restart-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name snt -NodeName snt_0 -PassThru
8686
Assert-True { $restart }
8787

8888
$delete = Remove-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name snt -NodeName snt_1 -PassThru
8989
Assert-True { $delete }
9090

91+
$disable = Disable-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name snt -NodeName snt_2 -PassThru
92+
Assert-True { $disable }
93+
94+
$enable = Enable-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name snt -NodeName snt_2 -PassThru
95+
Assert-True { $enable }
96+
9197
$reimage = Set-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name snt -NodeName snt_3 -Reimage -PassThru
9298
Assert-True { $reimage }
9399

100+
$move = Move-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name snt -NodeName snt_4 -PassThru
101+
Assert-True { $move }
102+
94103
$snt = Get-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name snt
95104
$removeResponse = $snt | Remove-AzServiceFabricManagedNodeType -PassThru
96105
Assert-True { $removeResponse }

src/ServiceFabric/ServiceFabric.Test/SessionRecords/Microsoft.Azure.Commands.ServiceFabric.Test.ScenarioTests.ServiceFabricManagedClustersTests/TestNodeTypeOperations.json

Lines changed: 2378 additions & 2150 deletions
Large diffs are not rendered by default.

src/ServiceFabric/ServiceFabric/Az.ServiceFabric.psd1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ CmdletsToExport = 'Add-AzServiceFabricClientCertificate',
8383
'Add-AzServiceFabricManagedNodeTypeVMExtension',
8484
'Add-AzServiceFabricManagedNodeTypeVMSecret',
8585
'Add-AzServiceFabricNode', 'Add-AzServiceFabricNodeType',
86+
'Disable-AzServiceFabricManagedNodeType',
87+
'Enable-AzServiceFabricManagedNodeType',
8688
'Get-AzServiceFabricApplication',
8789
'Get-AzServiceFabricApplicationType',
8890
'Get-AzServiceFabricApplicationTypeVersion',
@@ -92,6 +94,7 @@ CmdletsToExport = 'Add-AzServiceFabricClientCertificate',
9294
'Get-AzServiceFabricManagedClusterApplicationTypeVersion',
9395
'Get-AzServiceFabricManagedClusterService',
9496
'Get-AzServiceFabricManagedNodeType', 'Get-AzServiceFabricService',
97+
'Move-AzServiceFabricManagedNodeType',
9598
'New-AzServiceFabricApplication',
9699
'New-AzServiceFabricApplicationType',
97100
'New-AzServiceFabricApplicationTypeVersion',

src/ServiceFabric/ServiceFabric/ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Added new cmdlets for managed node types:
22+
- `Disable-AzServiceFabricManagedNodeType`
23+
- `Enable-AzServiceFabricManagedNodeType`
24+
- `Move-AzServiceFabricManagedNodeType`
2125
* Updated SF to latest api preview version `2023-11-01-preview`
2226
* Fixed `Set-AzServiceFabricManagedClusterApplication` to correctly overwrite existing application upgrade policy when `-RecreateApplication` parameter is specified and no other upgrade policy parameters are bound.
2327
* Added parameter `AutoGeneratedDomainNameLabelScope` to allow customers to initiate migration to public CA cluster certificates in cmdlet `New-AzServiceFabricManagedCluster` and `Set-AzServiceFabricManagedCluster`.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// ----------------------------------------------------------------------------------
2+
// Copyright Microsoft Corporation
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
// ----------------------------------------------------------------------------------
13+
14+
using System;
15+
using System.Management.Automation;
16+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
17+
using Microsoft.Azure.Commands.ServiceFabric.Common;
18+
using Microsoft.Azure.Management.ServiceFabricManagedClusters.Models;
19+
20+
namespace Microsoft.Azure.Commands.ServiceFabric.Commands
21+
{
22+
[Cmdlet(VerbsLifecycle.Disable, ResourceManager.Common.AzureRMConstants.AzurePrefix + Constants.ServiceFabricPrefix + "ManagedNodeType", SupportsShouldProcess = true), OutputType(typeof(bool))]
23+
public class DisableAzServiceFabricManagedNodeType : ServiceFabricManagedCmdletBase
24+
{
25+
#region Params
26+
27+
#region Common params
28+
29+
[Parameter(Mandatory = true, Position = 0, ValueFromPipelineByPropertyName = true,
30+
HelpMessage = "Specify the name of the resource group.")]
31+
[ResourceGroupCompleter]
32+
[ValidateNotNullOrEmpty()]
33+
public string ResourceGroupName { get; set; }
34+
35+
[Parameter(Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true,
36+
HelpMessage = "Specify the name of the cluster.")]
37+
[ResourceNameCompleter(Constants.ManagedClustersFullType, nameof(ResourceGroupName))]
38+
[ValidateNotNullOrEmpty()]
39+
public string ClusterName { get; set; }
40+
41+
[Parameter(Mandatory = true, Position = 2, ValueFromPipelineByPropertyName = true,
42+
HelpMessage = "Specify the name of the node type.")]
43+
[ValidateNotNullOrEmpty()]
44+
[Alias("NodeTypeName")]
45+
public string Name { get; set; }
46+
47+
#endregion
48+
49+
[Parameter(Mandatory = true, HelpMessage = "List of node names for the operation.")]
50+
[ValidateNotNullOrEmpty()]
51+
public string[] NodeName { get; set; }
52+
53+
[Parameter(Mandatory = false)]
54+
public SwitchParameter PassThru { get; set; }
55+
56+
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background and return a Job to track progress.")]
57+
public SwitchParameter AsJob { get; set; }
58+
59+
#endregion
60+
61+
public override void ExecuteCmdlet()
62+
{
63+
if (ShouldProcess(target: this.Name, action: string.Format("Deallocate node(s) {0}, from node type {1} on cluster {2}", string.Join(", ", this.NodeName), this.Name, this.ClusterName)))
64+
{
65+
try
66+
{
67+
var actionParams = new NodeTypeActionParameters(nodes: this.NodeName);
68+
var beginRequestResponse = this.SfrpMcClient.NodeTypes.BeginDeallocateWithHttpMessagesAsync(
69+
this.ResourceGroupName,
70+
this.ClusterName,
71+
this.Name,
72+
actionParams).GetAwaiter().GetResult();
73+
74+
this.PollLongRunningOperation(beginRequestResponse);
75+
76+
if (this.PassThru)
77+
{
78+
WriteObject(true);
79+
}
80+
}
81+
catch (Exception ex)
82+
{
83+
PrintSdkExceptionDetail(ex);
84+
throw;
85+
}
86+
}
87+
}
88+
}
89+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// ----------------------------------------------------------------------------------
2+
// Copyright Microsoft Corporation
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
// ----------------------------------------------------------------------------------
13+
14+
using System;
15+
using System.Management.Automation;
16+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
17+
using Microsoft.Azure.Commands.ServiceFabric.Common;
18+
using Microsoft.Azure.Management.ServiceFabricManagedClusters.Models;
19+
20+
namespace Microsoft.Azure.Commands.ServiceFabric.Commands
21+
{
22+
[Cmdlet(VerbsLifecycle.Enable, ResourceManager.Common.AzureRMConstants.AzurePrefix + Constants.ServiceFabricPrefix + "ManagedNodeType", SupportsShouldProcess = true), OutputType(typeof(bool))]
23+
public class EnableAzServiceFabricManagedNodeType : ServiceFabricManagedCmdletBase
24+
{
25+
#region Params
26+
27+
#region Common params
28+
29+
[Parameter(Mandatory = true, Position = 0, ValueFromPipelineByPropertyName = true,
30+
HelpMessage = "Specify the name of the resource group.")]
31+
[ResourceGroupCompleter]
32+
[ValidateNotNullOrEmpty()]
33+
public string ResourceGroupName { get; set; }
34+
35+
[Parameter(Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true,
36+
HelpMessage = "Specify the name of the cluster.")]
37+
[ResourceNameCompleter(Constants.ManagedClustersFullType, nameof(ResourceGroupName))]
38+
[ValidateNotNullOrEmpty()]
39+
public string ClusterName { get; set; }
40+
41+
[Parameter(Mandatory = true, Position = 2, ValueFromPipelineByPropertyName = true,
42+
HelpMessage = "Specify the name of the node type.")]
43+
[ValidateNotNullOrEmpty()]
44+
[Alias("NodeTypeName")]
45+
public string Name { get; set; }
46+
47+
#endregion
48+
49+
[Parameter(Mandatory = true, HelpMessage = "List of node names for the operation.")]
50+
[ValidateNotNullOrEmpty()]
51+
public string[] NodeName { get; set; }
52+
53+
[Parameter(Mandatory = false)]
54+
public SwitchParameter PassThru { get; set; }
55+
56+
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background and return a Job to track progress.")]
57+
public SwitchParameter AsJob { get; set; }
58+
59+
#endregion
60+
61+
public override void ExecuteCmdlet()
62+
{
63+
if (ShouldProcess(target: this.Name, action: string.Format("Start node(s) {0}, from node type {1} on cluster {2}", string.Join(", ", this.NodeName), this.Name, this.ClusterName)))
64+
{
65+
try
66+
{
67+
var actionParams = new NodeTypeActionParameters(nodes: this.NodeName);
68+
var beginRequestResponse = this.SfrpMcClient.NodeTypes.BeginStartWithHttpMessagesAsync(
69+
this.ResourceGroupName,
70+
this.ClusterName,
71+
this.Name,
72+
actionParams).GetAwaiter().GetResult();
73+
74+
this.PollLongRunningOperation(beginRequestResponse);
75+
76+
if (this.PassThru)
77+
{
78+
WriteObject(true);
79+
}
80+
}
81+
catch (Exception ex)
82+
{
83+
PrintSdkExceptionDetail(ex);
84+
throw;
85+
}
86+
}
87+
}
88+
}
89+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// ----------------------------------------------------------------------------------
2+
// Copyright Microsoft Corporation
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
// ----------------------------------------------------------------------------------
13+
14+
using System;
15+
using System.Management.Automation;
16+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
17+
using Microsoft.Azure.Commands.ServiceFabric.Common;
18+
using Microsoft.Azure.Management.ServiceFabricManagedClusters.Models;
19+
20+
namespace Microsoft.Azure.Commands.ServiceFabric.Commands
21+
{
22+
[Cmdlet(VerbsCommon.Move, ResourceManager.Common.AzureRMConstants.AzurePrefix + Constants.ServiceFabricPrefix + "ManagedNodeType", SupportsShouldProcess = true), OutputType(typeof(bool))]
23+
public class MoveAzServiceFabricManagedNodeType : ServiceFabricManagedCmdletBase
24+
{
25+
#region Params
26+
27+
#region Common params
28+
29+
[Parameter(Mandatory = true, Position = 0, ValueFromPipelineByPropertyName = true,
30+
HelpMessage = "Specify the name of the resource group.")]
31+
[ResourceGroupCompleter]
32+
[ValidateNotNullOrEmpty()]
33+
public string ResourceGroupName { get; set; }
34+
35+
[Parameter(Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true,
36+
HelpMessage = "Specify the name of the cluster.")]
37+
[ResourceNameCompleter(Constants.ManagedClustersFullType, nameof(ResourceGroupName))]
38+
[ValidateNotNullOrEmpty()]
39+
public string ClusterName { get; set; }
40+
41+
[Parameter(Mandatory = true, Position = 2, ValueFromPipelineByPropertyName = true,
42+
HelpMessage = "Specify the name of the node type.")]
43+
[ValidateNotNullOrEmpty()]
44+
[Alias("NodeTypeName")]
45+
public string Name { get; set; }
46+
47+
#endregion
48+
49+
[Parameter(Mandatory = true, HelpMessage = "List of node names for the operation.")]
50+
[ValidateNotNullOrEmpty()]
51+
public string[] NodeName { get; set; }
52+
53+
[Parameter(Mandatory = false,
54+
HelpMessage = "Using this flag will force the nodes to redeploy even if service fabric is unable to disable the nodes.")]
55+
public SwitchParameter ForceRedeploy { get; set; }
56+
57+
[Parameter(Mandatory = false)]
58+
public SwitchParameter PassThru { get; set; }
59+
60+
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background and return a Job to track progress.")]
61+
public SwitchParameter AsJob { get; set; }
62+
63+
#endregion
64+
65+
public override void ExecuteCmdlet()
66+
{
67+
if (ShouldProcess(target: this.Name, action: string.Format("Redeploy node(s) {0}, from node type {1} on cluster {2}", string.Join(", ", this.NodeName), this.Name, this.ClusterName)))
68+
{
69+
try
70+
{
71+
var actionParams = new NodeTypeActionParameters(nodes: this.NodeName, force: this.ForceRedeploy.IsPresent);
72+
var beginRequestResponse = this.SfrpMcClient.NodeTypes.BeginRedeployWithHttpMessagesAsync(
73+
this.ResourceGroupName,
74+
this.ClusterName,
75+
this.Name,
76+
actionParams).GetAwaiter().GetResult();
77+
78+
this.PollLongRunningOperation(beginRequestResponse);
79+
80+
if (this.PassThru)
81+
{
82+
WriteObject(true);
83+
}
84+
}
85+
catch (Exception ex)
86+
{
87+
PrintSdkExceptionDetail(ex);
88+
throw;
89+
}
90+
}
91+
}
92+
}
93+
}

0 commit comments

Comments
 (0)