在 Visual Studio 中配置 Service Fabric 应用程序的升级Configure the upgrade of a Service Fabric application in Visual Studio

Azure Service Fabric 的 Visual Studio 工具提供发布到本地或远程群集的升级支持。Visual Studio tools for Azure Service Fabric provide upgrade support for publishing to local or remote clusters. 在测试和调试期间将应用程序升级到较新的版本而不是替换应用程序的三种方案:There are three scenarios in which you want to upgrade your application to a newer version instead of replacing the application during testing and debugging:

  • 应用程序数据不在升级期间丢失。Application data won't be lost during the upgrade.
  • 可用性仍然很高,因此,如果有足够的服务实例分散到升级域,则在升级期间不有任何服务中断。Availability remains high so there won't be any service interruption during the upgrade, if there are enough service instances spread across upgrade domains.
  • 在应用程序进行升级时,可以对该应用程序运行测试。Tests can be run against an application while it's being upgraded.

升级所需的参数Parameters needed to upgrade

可以选择的部署类型有两种:常规或升级。You can choose from two types of deployment: regular or upgrade. 常规部署会将群集上所有先前的部署信息和数据都清除,而升级部署则将其保留。A regular deployment erases any previous deployment information and data on the cluster, while an upgrade deployment preserves it. 在 Visual Studio 中升级 Service Fabric应用程序时,需要提供应用程序升级参数和运行状况检查策略。When you upgrade a Service Fabric application in Visual Studio, you need to provide application upgrade parameters and health check policies. 应用程序升级参数可帮助控制升级,而运行状况检查策略可确定升级是否成功。Application upgrade parameters help control the upgrade, while health check policies determine whether the upgrade was successful. 有关详细信息,请参阅 Service Fabric 应用程序升级:升级参数See Service Fabric application upgrade: upgrade parameters for more details.

有三种升级模式:Monitored、UnmonitoredAuto 和 UnmonitoredManual。 There are three upgrade modes: Monitored, UnmonitoredAuto, and UnmonitoredManual.

  • Monitored 升级自动执行升级和应用程序运行状况检查。A Monitored upgrade automates the upgrade and application health check.
  • UnmonitoredAuto 升级自动执行升级,但跳过应用程序运行状况检查。An UnmonitoredAuto upgrade automates the upgrade, but skips the application health check.
  • 执行 UnmonitoredManual 升级时,必须手动升级每个升级域。When you do an UnmonitoredManual upgrade, you need to manually upgrade each upgrade domain.

每种升级模式都需要不同的参数集。Each upgrade mode requires different sets of parameters. 若要深入了解可用的升级选项,请参阅应用程序升级参数See Application upgrade parameters to learn more about the available upgrade options.

在 Visual Studio 中升级 Service Fabric 应用程序Upgrade a Service Fabric application in Visual Studio

如果要使用 Visual Studio Service Fabric 工具升级 Service Fabric应用程序,可以选中“升级应用程序” 复选框,将发布程序指定为升级而不是常规部署。If you're using the Visual Studio Service Fabric tools to upgrade a Service Fabric application, you can specify a publish process to be an upgrade rather than a regular deployment by checking the Upgrade the application check box.

配置升级参数To configure the upgrade parameters

  1. 单击复选框旁边的“设置” 按钮。Click the Settings button next to the check box. 此时将显示“编辑升级参数” 对话框。The Edit Upgrade Parameters dialog box appears. “编辑升级参数” 对话框支持 Monitored、UnmonitoredAuto 和 UnmonitoredManual 升级模式。The Edit Upgrade Parameters dialog box supports the Monitored, UnmonitoredAuto, and UnmonitoredManual upgrade modes.

  2. 选择想要使用的升级模式,并填写参数网格。Select the upgrade mode that you want to use and then fill out the parameter grid.

    每个参数都有默认值。Each parameter has default values. 可选参数 DefaultServiceTypeHealthPolicy 采用哈希表输入。 The optional parameter DefaultServiceTypeHealthPolicy takes a hash table input. 下面是 DefaultServiceTypeHealthPolicy 的哈希表输入格式示例:Here's an example of the hash table input format for DefaultServiceTypeHealthPolicy:

    @{ ConsiderWarningAsError = "false"; MaxPercentUnhealthyDeployedApplications = 0; MaxPercentUnhealthyServices = 0; MaxPercentUnhealthyPartitionsPerService = 0; MaxPercentUnhealthyReplicasPerPartition = 0 }
    

    ServiceTypeHealthPolicyMap is another optional parameter that takes a hash table input in the following format:

    @ {"ServiceTypeName" : "MaxPercentUnhealthyPartitionsPerService,MaxPercentUnhealthyReplicasPerPartition,MaxPercentUnhealthyServices"}
    

    下面是一个真实示例:Here's a real-life example:

    @{ "ServiceTypeName01" = "5,10,5"; "ServiceTypeName02" = "5,5,5" }
    
  3. 如果选择 UnmonitoredManual 升级模式,则必须手动启动 PowerShell 控制台才能继续并完成升级过程。If you select UnmonitoredManual upgrade mode, you must manually start a PowerShell console to continue and finish the upgrade process. 若要了解手动升级的工作方式,请参阅 Service Fabric 应用程序升级:高级主题Refer to Service Fabric application upgrade: advanced topics to learn how manual upgrade works.

使用 PowerShell 升级应用程序Upgrade an application by using PowerShell

可以使用 PowerShell cmdlet 来升级 Service Fabric 应用程序。You can use PowerShell cmdlets to upgrade a Service Fabric application. 有关详细信息,请参阅 Service Fabric 应用程序升级教程Start-ServiceFabricApplicationUpgradeSee Service Fabric application upgrade tutorial and Start-ServiceFabricApplicationUpgrade for detailed information.

在应用程序清单文件中指定运行状况状态检查策略Specify a health check policy in the application manifest file

Service Fabric 应用程序中的每个服务可能有自身的运行状况策略参数,这些参数可重写默认值。Every service in a Service Fabric application can have its own health policy parameters that override the default values. 可以在应用程序清单文件中提供这些参数值。You can provide these parameter values in the application manifest file.

以下示例演示如何对应用程序列表中的每个服务应用唯一的运行状况检查策略。The following example shows how to apply a unique health check policy for each service in the application manifest.

<Policies>
    <HealthPolicy ConsiderWarningAsError="false" MaxPercentUnhealthyDeployedApplications="20">
        <DefaultServiceTypeHealthPolicy MaxPercentUnhealthyServices="20"               
                MaxPercentUnhealthyPartitionsPerService="20"
                MaxPercentUnhealthyReplicasPerPartition="20" />
        <ServiceTypeHealthPolicy ServiceTypeName="ServiceTypeName1"
                MaxPercentUnhealthyServices="20"
                MaxPercentUnhealthyPartitionsPerService="20"
                MaxPercentUnhealthyReplicasPerPartition="20" />      
    </HealthPolicy>
</Policies>

后续步骤Next steps

有关升级应用程序的详细信息,请参阅使用 Visual Studio 升级应用程序For more information about upgrading an application, see Upgrade an application using Visual Studio.