Skip to content

Fix bugs and disable 'Remove-AzureRmServiceFabricNodeType' #4211

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 1 commit into from
Jun 29, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion src/ResourceManager/ServiceFabric/AzureRM.ServiceFabric.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ FunctionsToExport = @()
CmdletsToExport = 'Add-AzureRmServiceFabricApplicationCertificate',
'Add-AzureRmServiceFabricClientCertificate',
'Add-AzureRmServiceFabricClusterCertificate',
'Add-AzureRmServiceFabricNode', 'Add-AzureRmServiceFabricNodeType',
'Add-AzureRmServiceFabricNode',
'Add-AzureRmServiceFabricNodeType',
'Get-AzureRmServiceFabricCluster',
'New-AzureRmServiceFabricCluster',
'Remove-AzureRmServiceFabricClientCertificate',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@
<Compile Include="Commands\AddAzureRmServiceFabricClientCertificate.cs" />
<Compile Include="Commands\AddAzureRmServiceFabricClusterCertificate.cs" />
<Compile Include="Commands\AddAzureRmServiceFabricNodeType.cs" />
<Compile Include="Commands\RemoveAzureRmServiceFabricNodeType.cs" />
<Compile Include="Commands\ServiceFabricClientCertificateBase.cs" />
<Compile Include="Common\CmdletNoun.cs" />
<Compile Include="Common\Constants.cs" />
<Compile Include="Commands\GetAzureRmServiceFabricClusterResouce.cs" />
<Compile Include="Commands\NewAzureRmServiceFabricCluster.cs" />
<Compile Include="Commands\RemoveAzureRmServiceFabricNodeType.cs" />
<Compile Include="Commands\RemoveAzureRmServiceFabricClientCertificate.cs" />
<Compile Include="Commands\RemoveAzureRmServiceFabricClusterCertificate.cs" />
<Compile Include="Commands\RemoveAzureRmServiceFabricNode.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using Microsoft.WindowsAzure.Commands.Common;
using Newtonsoft.Json.Linq;
using ServiceFabricProperties = Microsoft.Azure.Commands.ServiceFabric.Properties;
using System.Text;

namespace Microsoft.Azure.Commands.ServiceFabric.Commands
{
Expand All @@ -41,6 +42,8 @@ public class AddAzureRmServiceFabricNodeType : ServiceFabricNodeTypeCmdletBase
private const string BackendAddressIdFormat = "/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Network/loadBalancers/{2}/backendAddressPools/{3}";
private const string FrontendIDFormat = "/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Network/loadBalancers/{2}/frontendIPConfigurations/{3}";
private const string ProbeIDFormat = "/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Network/loadBalancers/{2}/probes/{3}";
private readonly HashSet<string> skusSupportGoldDurability =
new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Standard_D15_v2", "Standard_G5" };

private string sku;
private string diagnosticsStorageName;
Expand Down Expand Up @@ -94,16 +97,34 @@ public string VmSku

private string tier;
[Parameter(Mandatory = false, ValueFromPipeline = true,
HelpMessage = "Tier")]
HelpMessage = "Vm Sku Tier")]
[ValidateNotNullOrEmpty()]
public string Tier
{
get { return string.IsNullOrWhiteSpace(this.tier) ? Constants.DefaultTier : this.tier; }
set { this.tier = value; }
}

private DurabilityLevel durabilityLevel = DurabilityLevel.Bronze;
[Parameter(Mandatory = false, ValueFromPipeline = true,
HelpMessage = "Specify the durability level of the NodeType.")]
[ValidateNotNullOrEmpty()]
public DurabilityLevel DurabilityLevel
{
get { return this.durabilityLevel; }
set
{
this.durabilityLevel = value;
}
}

public override void ExecuteCmdlet()
{
if (this.DurabilityLevel == DurabilityLevel.Gold && !skusSupportGoldDurability.Contains(this.VmSku))
{
throw new PSArgumentException("Only Standard_D15_v2 and Standard_G5 supports Gold durability,please specify -VmSku to right value");
}

if (CheckNodeTypeExistence())
{
throw new PSArgumentException(string.Format("{0} exists", this.NodeType));
Expand Down Expand Up @@ -160,7 +181,7 @@ private PSCluster AddNodeTypeToSfrp()
EndPort = Constants.DefaultApplicationEndPort
},
ClientConnectionEndpointPort = Constants.DefaultClientConnectionEndpoint,
DurabilityLevel = Constants.DefaultDurabilityLevel,
DurabilityLevel = this.DurabilityLevel.ToString(),
EphemeralPorts = new Management.ServiceFabric.Models.EndpointRangeDescription()
{
StartPort = Constants.DefaultEphemeralStart,
Expand Down Expand Up @@ -327,6 +348,7 @@ private VirtualMachineScaleSetExtension GetFabriExtension(VirtualMachineScaleSet
}

settings["nodeTypeRef"] = this.NodeType;
settings["durabilityLevel"] = this.DurabilityLevel.ToString();

if (settings["nicPrefixOverride"] != null)
{
Expand Down Expand Up @@ -423,13 +445,27 @@ private List<StorageAccount> CreateStorageAccount()

private string GetStorageRandomName()
{
var name = string.Empty;
var name = this.NodeType.ToLower();

if (!dontRandom)
{
name = string.Concat(
this.NodeType,
System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetRandomFileName()));
do
{
name = string.Concat(
name,
System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetRandomFileName()));

StringBuilder sb = new StringBuilder();
foreach (var n in name)
{
if ((n >= 'a' && n <= 'z') || (n >= '0' && n <= '9'))
{
sb.Append(n);
}
}

name = sb.ToString();
} while (name.Length < 3);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
using Microsoft.Azure.Commands.ServiceFabric.Models;
using Microsoft.Azure.Management.Compute;
using Microsoft.Azure.Management.ServiceFabric;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using ServiceFabricProperties = Microsoft.Azure.Commands.ServiceFabric.Properties;


namespace Microsoft.Azure.Commands.ServiceFabric.Commands
{
[Cmdlet(VerbsCommon.Remove, CmdletNoun.AzureRmServiceFabricNodeType, SupportsShouldProcess = true), OutputType(typeof(PSCluster))]
Expand All @@ -42,6 +44,10 @@ public class RemoveAzureRmServiceFabricNodeType : ServiceFabricNodeTypeCmdletBas

public override void ExecuteCmdlet()
{
WriteWarning("After the NodeType is removed, you may see the nodes of the NodeType are in error state," +
"you need to run 'Remove-ServiceFabricNodeState' on those nodes to fix them, read this document for details on how to " +
" https://docs.microsoft.com/powershell/module/servicefabric/remove-servicefabricnodestate?view=azureservicefabricps");

if (!CheckNodeTypeExistence())
{
throw new PSArgumentException(this.NodeType);
Expand Down Expand Up @@ -87,9 +93,8 @@ public override void ExecuteCmdlet()

if (ShouldProcess(target: this.NodeType, action: string.Format("Remove a nodetype {0} ", this.NodeType)))
{
this.ComputeClient.VirtualMachineScaleSets.Delete(this.ResourceGroupName, this.NodeType);

cluster = RemoveNodeTypeFromSfrp();
this.ComputeClient.VirtualMachineScaleSets.Delete(this.ResourceGroupName, this.NodeType);

WriteObject((PSCluster)cluster, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.Commands.Common.Authentication.Models;
using Microsoft.Azure.Commands.ServiceFabric.Models;
using Microsoft.Azure.Commands.Common.Authentication;
using Microsoft.Azure.KeyVault.Models;
Expand Down Expand Up @@ -155,7 +154,6 @@ public ServiceFabricClusterCertificateCmdlet()
public override void ExecuteCmdlet()
{
this.Validate();

}

protected virtual List<string> GetPfxSrcFiles()
Expand Down Expand Up @@ -298,7 +296,7 @@ internal List<CertificateInformation> GetOrCreateCertificateInformation()

if (string.IsNullOrEmpty(this.KeyVaultName))
{
this.KeyVaultName = this.ResourceGroupName;
this.KeyVaultName = CreateDefaultKeyVaultName(this.ResourceGroupName);
}

if (ParameterSetName != ExistingKeyVault)
Expand Down Expand Up @@ -471,7 +469,7 @@ protected void GetKeyVaultReady(out Vault vault, out CertificateBundle certifica
WriteVerboseWithTimestamp(string.Format("Key Vault is created: {0}", vault.Id));
}

SetCertificateName();
this.keyVaultCertificateName = CreateDefaultCertificateName(this.ResourceGroupName);

if (!string.IsNullOrEmpty(srcPfxPath))
{
Expand All @@ -494,10 +492,68 @@ protected void GetKeyVaultReady(out Vault vault, out CertificateBundle certifica
}
}

protected void SetCertificateName()
protected static string CreateDefaultCertificateName(string resourceGroupName)
{
this.keyVaultCertificateName = string.Format("{0}{1}", this.ResourceGroupName,
DateTime.Now.ToString("yyyyMMddHHmmss"));
StringBuilder sb = new StringBuilder();
foreach (var c in resourceGroupName)
{
if (IsValidKeyVaultObjectChar(c))
{
sb.Append(c);
}
}

return string.Format("{0}{1}", sb.ToString(), DateTime.Now.ToString("yyyyMMddHHmmss"));
}

protected static string CreateDefaultKeyVaultName(string resourceGroupName)
{
StringBuilder sb = new StringBuilder();
var targetCopy = resourceGroupName;
while (sb.Length < 3)
{
foreach (var c in targetCopy)
{
if (IsValidKeyVaultChar(c))
{
sb.Append(c);
}
}

// resource group name can't be used for key vault name
// use random string instread
if (sb.Length == 0)
{
targetCopy = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());
}
}

if (sb.Length > 24)
{
return sb.ToString().Substring(0, 24);
}

return sb.ToString();
}

private static bool IsValidKeyVaultChar(char name)
{
if (name >= 'a' && name <= 'z') return true;
if (name >= 'A' && name <= 'Z') return true;
if (name >= '0' && name <= '9') return true;
if (name == '-') return true;

return false;
}

private static bool IsValidKeyVaultObjectChar(char name)
{
if (name >= 'a' && name <= 'z') return true;
if (name >= 'A' && name <= 'Z') return true;
if (name >= '0' && name <= '9') return true;
if (name == '-') return true;

return false;
}

private string GetThumbprintFromSecret(string secretUrl)
Expand Down Expand Up @@ -583,4 +639,4 @@ private void ExtractSecretNameFromSecretIdentifier(string secretIdentifier, out
version = tokens[4];
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ protected Dictionary<string, Dictionary<string, string>> FabricSettingsToDiction
{
foreach (var setting in fabricSettings)
{
settings[setting.Name] = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
if (!settings.ContainsKey(setting.Name))
{
settings[setting.Name] = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
}

foreach (var ps in setting.Parameters)
{
if (settings[setting.Name].ContainsKey(ps.Name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Accept wildcard characters: False
```

### -Tier
Tier.
Vm Sku Tier.

```yaml
Type: String
Expand All @@ -107,6 +107,22 @@ Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```

### -DurabilityLevel
Specify the durability level of the NodeType.

```yaml
Type: DurabilityLevel
Parameter Sets: (All)
Aliases: Level
Accepted values: Bronze, Silver, Gold

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```

### -VmPassword
The password of login to the Vm.

Expand Down