【问题标题】:Deploy Service Fabric from powershell. Error -> Get-ServiceFabricClusterManifest : Cluster connection instance is null从 PowerShell 部署 Service Fabric。错误 -> Get-ServiceFabricClusterManifest:集群连接实例为空
【发布时间】:2016-11-01 09:10:57
【问题描述】:

我正在尝试使用 powershell 将 Service Fabric 应用程序发布到 Azure。我想连接到集群,然后调用脚本“Deploy-FabricApplication.ps1”(在Visual Studio中创建新项目时生成的脚本)

为此,我创建了负责连接集群的新脚本文件,然后从同一个脚本文件中调用“Deploy-FabricApplication.ps1”。

启动我的脚本后,我收到以下错误:

Get-ServiceFabricClusterManifest : Cluster connection instance is null
At C:\Program Files\Microsoft SDKs\Service Fabric\Tools\PSModule\ServiceFabricSDK\Publish-UpgradedServiceFabricApplication.ps1:116 char:28
+     $clusterManifestText = Get-ServiceFabricClusterManifest
+                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ResourceUnavailable: (:) [Get-ServiceFabricClusterManifest], NullReferenceException
+ FullyQualifiedErrorId : GetClusterConnectionErrorId,Microsoft.ServiceFabric.Powershell.GetClusterManifest

在连接脚本和 Deploy-FabricApplication.ps1 中,我调用“Test-ServiceFabricClusterConnection”,在两个脚本中它也返回 True,在两个脚本中,我调用“Get-ServiceFabricClusterManifest”,在这两种情况下它都返回给我清单,但是当我已将“Test-ServiceFabricClusterConnection”添加到“Publish-UpgradedServiceFabricApplication.ps1”,然后它返回了与之前提到的相同的错误,但对于“Test-ServiceFabricClusterConnection”调用。

连接脚本代码:

Param
(
    [String]
    $PublishProfileFile,

    [String]
    $ApplicationPackagePath,

    [Switch]
    $DeployOnly,

    [Boolean]
    $UnregisterUnusedApplicationVersionsAfterUpgrade,

    [String]
    [ValidateSet('None', 'ForceUpgrade', 'VetoUpgrade')]
    $OverrideUpgradeBehavior = 'None',

    [String]
    [ValidateSet('Never','Always','SameAppTypeAndVersion')]
    $OverwriteBehavior = 'Never',

    [Switch]
    $SkipPackageValidation,

    [String]
    $ConnectionEndpoint,

    [String]
    $ServerCertThumbprint,

    [String]
    $FindType,

    [String]
    $FindValue,

    [String]
    $StoreLocation,

    [String]
    $StoreName
)

$connectArgs = @{ ConnectionEndpoint = $ConnectionEndpoint;  X509Credential = $True;  StoreLocation = $StoreLocation;  StoreName = $StoreName;  ServerCertThumbprint = $ServerCertThumbprint; FindType = $FindType;  FindValue = $FindValue }

try
{
    Connect-ServiceFabricCluster @connectArgs;
    $connection = Get-ServiceFabricClusterConnection;
    Write-Host $connection;
    $m = Get-ServiceFabricClusterManifest
    Write-Host $m;
}
catch [System.Fabric.FabricObjectClosedException]
{
    Write-Warning "Service Fabric cluster may not be connected."
    throw
}

.\Deploy-FabricApplication.ps1 -PublishProfileFile $PublishProfileFile -ApplicationPackagePath $ApplicationPackagePath -OverrideUpgradeBehavior $OverrideUpgradeBehavior -OverwriteBehavior $OverwriteBehavior -DeployOnly:$DeployOnly -UnregisterUnusedApplicationVersionsAfterUpgrade:$UnregisterUnusedApplicationVersionsAfterUpgrade -UseExistingClusterConnection:$true -SkipPackageValidation:$SkipPackageValidation

总而言之,我不知道如何建立与集群的连接,然后在 Deploy-FabricApplication.ps1 中使用它

感谢您的帮助

【问题讨论】:

    标签: powershell azure azure-service-fabric


    【解决方案1】:

    当调用Connect-ServiceFabricCluster 时,会设置本地$clusterConnection 变量。一些 SDK 脚本然后期望设置该变量,但由于您在不同的范围内执行脚本,因此该局部变量对它们不可用。

    您可以点源调用 Deploy-FabricApplication.ps1

    . .\Deploy-FabricApplication.ps1 -PublishProfileFile $PublishProfileFile -ApplicationPackagePath $ApplicationPackagePath -OverrideUpgradeBehavior $OverrideUpgradeBehavior -OverwriteBehavior $OverwriteBehavior -DeployOnly:$DeployOnly -UnregisterUnusedApplicationVersionsAfterUpgrade:$UnregisterUnusedApplicationVersionsAfterUpgrade -UseExistingClusterConnection:$true -SkipPackageValidation:$SkipPackageValidation
    

    或创建一个包含本地 $clusterConnection 变量的 $global:clusterConnection 变量

    $global:clusterConnection = $clusterConnection
    

    【讨论】:

    • 感谢您的帮助,我已将局部变量分配给全局变量,现在看来它可以工作了
    • 如果您随后重置本地集群,并尝试重新使用您获得的连接Error: ...Exception: The object is closed. --> Exception from HRESULT: 0x80071BFE。启动一个新的 powershell 窗口可以修复它。
    • 并在重置后运行Connect-ServiceFabricCluster:Connect-ServiceFabricCluster : The object is closed. At line:1 char:1 + Connect-ServiceFabricCluster + CategoryInfo : InvalidOperation: (:) [Connect-ServiceFabricCluster], FabricObjectClosedException + FullyQualifiedErrorId : TestClusterConnectionErrorId,Microsoft.ServiceFabric.Powershell.ConnectCluster
    • SF 故障排除指南github.com/Microsoft/azure-docs/blob/master/articles/… - 包括对象关闭错误。
    • 重置后失败的相关问题serverfault.com/questions/832238/…
    猜你喜欢
    • 2017-01-14
    • 2017-08-06
    • 1970-01-01
    • 2018-11-09
    • 2018-02-20
    • 2019-10-22
    • 2016-12-06
    • 1970-01-01
    • 2018-07-19
    相关资源
    最近更新 更多