Skip to content

Commit a863403

Browse files
committed
managed service cmdlets and module export update
1 parent 7052244 commit a863403

9 files changed

+1532
-1
lines changed

src/ServiceFabric/ServiceFabric/Az.ServiceFabric.psd1

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,23 @@ CmdletsToExport = 'Add-AzServiceFabricClientCertificate',
113113
'Remove-AzServiceFabricManagedNodeTypeVMExtension',
114114
'Restart-AzServiceFabricManagedNodeType',
115115
'Update-AzServiceFabricNodeType',
116-
'Update-AzServiceFabricVmImage'
116+
'Update-AzServiceFabricVmImage',
117+
'New-AzServiceFabricManagedClusterApplication',
118+
'Get-AzServiceFabricManagedClusterApplication',
119+
'Set-AzServiceFabricManagedClusterApplication',
120+
'Remove-AzServiceFabricManagedClusterApplication',
121+
'New-AzServiceFabricManagedClusterApplicationType',
122+
'Get-AzServiceFabricManagedClusterApplicationType',
123+
'Set-AzServiceFabricManagedClusterApplicationType',
124+
'Remove-AzServiceFabricManagedClusterApplicationType',
125+
'New-AzServiceFabricManagedClusterApplicationTypeVersion',
126+
'Get-AzServiceFabricManagedClusterApplicationTypeVersion',
127+
'Set-AzServiceFabricManagedClusterApplicationTypeVersion',
128+
'Remove-AzServiceFabricManagedClusterApplicationTypeVersion',
129+
'New-AzServiceFabricManagedClusterService',
130+
'Get-AzServiceFabricManagedClusterService',
131+
'Set-AzServiceFabricManagedClusterService',
132+
'Remove-AzServiceFabricManagedClusterService'
117133

118134
# Variables to export from this module
119135
# VariablesToExport = @()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Linq;
17+
using System.Management.Automation;
18+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
19+
using Microsoft.Azure.Commands.ServiceFabric.Common;
20+
using Microsoft.Azure.Commands.ServiceFabric.Models.ManagedClusters;
21+
using Microsoft.Azure.Management.ServiceFabricManagedClusters;
22+
23+
namespace Microsoft.Azure.Commands.ServiceFabric.Commands
24+
{
25+
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzurePrefix + Constants.ServiceFabricPrefix + "ManagedClusterService", DefaultParameterSetName = ByResourceGroupAndCluster), OutputType(typeof(PSManagedService))]
26+
public class GetAzServiceFabricManagedClusterService : ManagedApplicationCmdletBase
27+
{
28+
private const string ByResourceGroupAndCluster = "ByResourceGroupAndCluster";
29+
private const string ByName = "ByName";
30+
private const string ByResourceId = "ByResourceId";
31+
32+
#region Parameters
33+
[Parameter(Mandatory = true, Position = 0, ValueFromPipelineByPropertyName = true, ParameterSetName = ByResourceGroupAndCluster,
34+
HelpMessage = "Specify the name of the resource group.")]
35+
[Parameter(Mandatory = true, Position = 0, ValueFromPipelineByPropertyName = true, ParameterSetName = ByName,
36+
HelpMessage = "Specify the name of the resource group.")]
37+
[ResourceGroupCompleter]
38+
[ValidateNotNullOrEmpty]
39+
public override string ResourceGroupName { get; set; }
40+
41+
[Parameter(Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true, ParameterSetName = ByResourceGroupAndCluster,
42+
HelpMessage = "Specify the name of the cluster.")]
43+
[Parameter(Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true, ParameterSetName = ByName,
44+
HelpMessage = "Specify the name of the cluster.")]
45+
[ResourceNameCompleter(Constants.ManagedClustersFullType, nameof(ResourceGroupName))]
46+
[ValidateNotNullOrEmpty]
47+
public override string ClusterName { get; set; }
48+
49+
[Parameter(Mandatory = true, Position = 2, ValueFromPipelineByPropertyName = true, ParameterSetName = ByResourceGroupAndCluster,
50+
HelpMessage = "Specify the name of the managed application.")]
51+
[Parameter(Mandatory = true, Position = 2, ValueFromPipelineByPropertyName = true, ParameterSetName = ByName,
52+
HelpMessage = "Specify the name of the managed application.")]
53+
[ValidateNotNullOrEmpty]
54+
public string ApplicationName { get; set; }
55+
56+
[Parameter(Mandatory = true, Position = 3, ValueFromPipelineByPropertyName = true, ParameterSetName = ByName,
57+
HelpMessage = "Specify the name of the managed service.")]
58+
[ValidateNotNullOrEmpty]
59+
[Alias("ServiceName")]
60+
public string Name { get; set; }
61+
62+
[Parameter(Mandatory = true, ParameterSetName = ByResourceId, ValueFromPipelineByPropertyName = true,
63+
HelpMessage = "Arm ResourceId of the managed service.")]
64+
[ResourceIdCompleter(Constants.ManagedClustersFullType)]
65+
[ValidateNotNullOrEmpty]
66+
public string ResourceId { get; set; }
67+
#endregion
68+
69+
public override void ExecuteCmdlet()
70+
{
71+
try
72+
{
73+
switch (ParameterSetName)
74+
{
75+
case ByResourceGroupAndCluster:
76+
var managedServiceList = this.ReturnListByPageResponse(
77+
this.SfrpMcClient.Services.ListByApplications(this.ResourceGroupName, this.ClusterName, this.ApplicationName),
78+
this.SfrpMcClient.Services.ListByApplicationsNext);
79+
WriteObject(managedServiceList.Select(service => new PSManagedService(service)), true);
80+
break;
81+
case ByName:
82+
GetByName();
83+
break;
84+
case ByResourceId:
85+
SetParametersByResourceId(this.ResourceId);
86+
GetByName();
87+
break;
88+
default:
89+
throw new PSArgumentException("Invalid ParameterSetName");
90+
}
91+
}
92+
catch (Exception ex)
93+
{
94+
this.PrintSdkExceptionDetail(ex);
95+
throw;
96+
}
97+
}
98+
99+
private void GetByName()
100+
{
101+
var managedService = this.SfrpMcClient.Services.Get(this.ResourceGroupName, this.ClusterName, this.ApplicationName, this.Name);
102+
WriteObject(new PSManagedService(managedService), false);
103+
}
104+
105+
private void SetParametersByResourceId(string resourceId)
106+
{
107+
this.GetParametersByResourceId(resourceId, Constants.serviceProvider, out string resourceGroup, out string resourceName, out string parentResourceName, out string grandParentResourceName);
108+
this.ResourceGroupName = resourceGroup;
109+
this.ClusterName = grandParentResourceName;
110+
this.ApplicationName = parentResourceName;
111+
this.Name = resourceName;
112+
}
113+
}
114+
}

0 commit comments

Comments
 (0)