我正在创建一个脚本,我可以使用它将Azure服务结构应用程序部署到本地群集或Azure托管群集。如果我运行脚本两次,我遇到了一个问题。当我的脚本第二次执行时,Connect-ServiceFabricCluster
命令失败。我可以重新启动PowerShell控制台或PowerShell ISE,直到第二次调用才能看到问题。这会导致更改脚本的繁琐过程。调用两次Connect-ServiceFabricCluster调用失败
function Read-XmlElementAsHashtable
{
Param (
[System.Xml.XmlElement]
$Element
)
$hashtable = @{}
if ($Element.Attributes)
{
$Element.Attributes |
ForEach-Object {
$boolVal = $null
if ([bool]::TryParse($_.Value, [ref]$boolVal)) {
$hashtable[$_.Name] = $boolVal
}
else {
$hashtable[$_.Name] = $_.Value
}
}
}
return $hashtable
}
function Read-PublishProfile
{
Param (
[ValidateScript({Test-Path $_ -PathType Leaf})]
[String]
$PublishProfileFile
)
$publishProfileXml = [Xml] (Get-Content $PublishProfileFile)
$publishProfile = @{}
$publishProfile.ClusterConnectionParameters = Read-XmlElementAsHashtable $publishProfileXml.PublishProfile.Item("ClusterConnectionParameters")
$publishProfile.UpgradeDeployment = Read-XmlElementAsHashtable $publishProfileXml.PublishProfile.Item("UpgradeDeployment")
if ($publishProfileXml.PublishProfile.Item("UpgradeDeployment"))
{
$publishProfile.UpgradeDeployment.Parameters = Read-XmlElementAsHashtable $publishProfileXml.PublishProfile.Item("UpgradeDeployment").Item("Parameters")
if ($publishProfile.UpgradeDeployment["Mode"])
{
$publishProfile.UpgradeDeployment.Parameters[$publishProfile.UpgradeDeployment["Mode"]] = $true
}
}
$publishProfileFolder = (Split-Path $PublishProfileFile)
$publishProfile.ApplicationParameterFile = [System.IO.Path]::Combine($PublishProfileFolder, $publishProfileXml.PublishProfile.ApplicationParameterFile.Path)
return $publishProfile
}
$profileSettings = Read-PublishProfile $PublishProfileFile
try
{
$clusterConnectionParameters = $profileSettings.ClusterConnectionParameters
[void](Connect-ServiceFabricCluster @clusterConnectionParameters)
}
catch [System.Fabric.FabricObjectClosedException]
{
Write-Warning "Service Fabric cluster may not be connected."
throw
}
如果你已经看过成Deploy-FabricApplication.ps1
脚本当您创建一个Azure的服务织物的应用程序,Visual Studio创建,该代码应该很熟悉,因为这是我的来源我在我的脚本中使用。
该错误消息我看到,当我运行该脚本第二次是:
WARNING: Failed to contact Naming Service. Attempting to contact Failover Manager Service...
WARNING: Failed to contact Failover Manager Service, Attempting to contact FMM...
WARNING: Service Fabric cluster may not be connected.
Connect-ServiceFabricCluster : One or more errors occurred.
At MyScript.ps1:218 char:9
+ [void](Connect-ServiceFabricCluster @clusterConnectionParameters)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Connect-ServiceFabricCluster], AggregateException
+ FullyQualifiedErrorId : CreateClusterConnectionErrorId,Microsoft.ServiceFabric.Powershell.ConnectCluster
我local.xml中发布个人资料,我做任何更改,它是创建的默认文件的Visual Studio当我创建该项目时。
<?xml version="1.0" encoding="utf-8"?>
<PublishProfile xmlns="http://schemas.microsoft.com/2015/05/fabrictools">
<ClusterConnectionParameters />
<ApplicationParameterFile Path="..\ApplicationParameters\Local.xml" />
</PublishProfile>
步骤我走,当我看到这个问题:
- 运行脚本部署
- 验证一切是否正常
- 重置本地集群
- 运行脚本来重新部署
- 脚本遇到错误
仅当连接到本地群集时,我多次连接到Azure中的群集时才能看到此问题。
有什么我错过了没有遇到第二次运行的问题?我想知道是否缺少断开连接命令,因为重新启动会清除任何状态,但我没有发现任何与服务结构集群命令断开连接的情况。
我确实在SO上找到this post,这似乎是相同的错误,但重现问题的途径是不同的。