Service Fabric 应用程序生命周期Service Fabric application lifecycle

与其他平台一样,Azure Service Fabric 上的应用程序通常经历以下几个阶段:设计、开发、测试、部署、升级、维护和删除。As with other platforms, an application on Azure Service Fabric usually goes through the following phases: design, development, testing, deployment, upgrading, maintenance, and removal. Service Fabric 为云应用程序的整个应用程序生命周期提供一流的支持:从开发到部署、到日常管理和维护,再到最终解除授权。Service Fabric provides first-class support for the full application lifecycle of cloud applications, from development through deployment, daily management, and maintenance to eventual decommissioning. 服务模型使多个不同角色可以独立参与到应用程序生命周期中。The service model enables several different roles to participate independently in the application lifecycle. 本文提供了有关 API 的概述,以及不同角色在 Service Fabric 应用程序生命周期的各个阶段如何使用它们。This article provides an overview of the APIs and how they are used by the different roles throughout the phases of the Service Fabric application lifecycle.

重要

可以使用两个 CLI 实用工具来与 Service Fabric 交互。There are two CLI utilities used to interact with Service Fabric. Azure CLI 用于管理 Azure 资源,例如 Azure 托管的 Service Fabric 群集。Azure CLI is used to manage Azure resources, such as an Azure-hosted Service Fabric cluster. Service Fabric CLI 用于直接连接到 Service Fabric 群集(不管托管在哪个位置)和管理群集、应用程序与服务。Service Fabric CLI is used to directly connect to the Service Fabric cluster (regardless of where it's hosted) and manage the cluster, applications, and services.

服务模型角色Service model roles

服务模型角色如下:The service model roles are:

  • 服务开发人员:开发可以在相同类型或不同类型的多个应用程序中重新调整用途和使用的模块化和通用服务。Service developer: Develops modular and generic services that can be repurposed and used in multiple applications of the same type or different types. 例如,队列服务可用于创建票证应用程序(帮助服务台)或电子商务应用程序(购物车)。For example, a queue service can be used for creating a ticketing application (helpdesk) or an e-commerce application (shopping cart).
  • 应用程序开发人员:通过集成满足某些特定要求或方案的服务集合来创建应用程序。Application developer: Creates applications by integrating a collection of services to satisfy certain specific requirements or scenarios. 例如,电子商务网站可能集成“JSON 无状态前端服务”、“拍卖有状态服务”,以及“队列有状态服务”来构建拍卖解决方案。For example, an e-commerce website might integrate "JSON Stateless Front-End Service," "Auction Stateful Service," and "Queue Stateful Service" to build an auctioning solution.
  • 应用程序管理员:针对应用程序配置(填写配置模板参数)、部署(映射到可用资源)以及服务质量做出决策。Application administrator: Makes decisions on the application configuration (filling in the configuration template parameters), deployment (mapping to available resources), and quality of service. 例如,应用程序管理员决定应用程序的语言区域设置(例如,美国为英语,中国为中文)。For example, an application administrator decides the language locale (English for the United States or Chinese for China, for example) of the application. 另一个已部署的应用程序可以具有不同的设置。A different deployed application can have different settings.
  • 操作员:基于由应用程序管理员指定的应用程序配置和要求部署应用程序。Operator: Deploys applications based on the application configuration and requirements specified by the application administrator. 例如,操作员预配和部署应用程序并确保它在 Azure 中运行。For example, an operator provisions and deploys the application and ensures that it is running in Azure. 操作员监视应用程序运行状况和性能信息,并根据需要维护物理基础结构。Operators monitor application health and performance information and maintain the physical infrastructure as needed.

开发Develop

  1. 服务开发人员使用 Reliable ActorsReliable Services 编程模型开发不同类型的服务。A service developer develops different types of services using the Reliable Actors or Reliable Services programming model.
  2. 服务开发人员以声明的方式描述包含一个或多个代码、配置和数据包的服务清单文件中的开发服务类型。A service developer declaratively describes the developed service types in a service manifest file consisting of one or more code, configuration, and data packages.
  3. 随后, 应用程序开发人员 构建使用不同服务类型的应用程序。An application developer then builds an application using different service types.
  4. 应用程序开发人员以声明的方式,通过引用构成服务的服务清单并相应地重写并参数化构成服务的不同配置与部署设置,描述了应用程序清单中的应用程序类型。An application developer declaratively describes the application type in an application manifest by referencing the service manifests of the constituent services and appropriately overriding and parameterizing different configuration and deployment settings of the constituent services.

有关示例,请参阅 Reliable Actors 入门Reliable Services 入门See Get started with Reliable Actors and Get started with Reliable Services for examples.

部署Deploy

  1. 应用程序管理员通过在应用程序清单中指定 ApplicationType 元素的相应参数,将应用程序类型定制为将被部署到 Service Fabric 群集的特定应用程序。An application administrator tailors the application type to a specific application to be deployed to a Service Fabric cluster by specifying the appropriate parameters of the ApplicationType element in the application manifest.
  2. 操作员使用 CopyApplicationPackage 方法Copy-ServiceFabricApplicationPackage cmdlet,将应用程序包上传到群集映像存储中。An operator uploads the application package to the cluster image store by using the CopyApplicationPackage method or the Copy-ServiceFabricApplicationPackage cmdlet. 应用程序包包含应用程序清单和服务包集合。The application package contains the application manifest and the collection of service packages. Service Fabric 部署存储在映像存储(可能是 Azure Blob 存储或 Service Fabric 系统服务)中的应用程序包中的应用程序。Service Fabric deploys applications from the application package stored in the image store, which can be an Azure blob store or the Service Fabric system service.
  3. 然后,操作员使用 ProvisionApplicationAsync 方法Register-ServiceFabricApplicationType cmdlet预配应用程序 REST 操作预配从已上传的应用程序包的目标群集中的应用程序类型。The operator then provisions the application type in the target cluster from the uploaded application package using the ProvisionApplicationAsync method, the Register-ServiceFabricApplicationType cmdlet, or the Provision an Application REST operation.
  4. 预配该应用程序后,操作员使用由应用程序管理员通过 CreateApplicationAsync 方法New-ServiceFabricApplication cmdlet创建应用程序 REST 操作所提供的参数,来启动该应用程序。After provisioning the application, an operator starts the application with the parameters supplied by the application administrator using the CreateApplicationAsync method, the New-ServiceFabricApplication cmdlet, or the Create Application REST operation.
  5. 部署应用程序后,操作员使用 CreateServiceAsync 方法New-ServiceFabricService cmdlet创建服务 REST 操作,来基于可用的服务类型为应用程序创建新的服务实例。After the application has been deployed, an operator uses the CreateServiceAsync method, the New-ServiceFabricService cmdlet, or the Create Service REST operation to create new service instances for the application based on available service types.
  6. 该应用程序现在在 Service Fabric 群集中运行。The application is now running in the Service Fabric cluster.

有关示例,请参阅 部署应用程序See Deploy an application for examples.

测试Test

  1. 部署到本地开发群集或测试群集后,服务开发人员使用 FailoverTestScenarioParametersFailoverTestScenario 类或 Invoke ServiceFabricFailoverTestScenario cmdlet 运行内置的故障转移测试方案。After deploying to the local development cluster or a test cluster, a service developer runs the built-in failover test scenario by using the FailoverTestScenarioParameters and FailoverTestScenario classes, or the Invoke-ServiceFabricFailoverTestScenario cmdlet. 故障转移测试方案在重要转换和故障转移中运行指定的服务,以确保其仍然可用并正在工作。The failover test scenario runs a specified service through important transitions and failovers to ensure that it's still available and working.
  2. 然后,服务开发人员使用 ChaosTestScenarioParametersChaosTestScenario 类或 Invoke ServiceFabricChaosTestScenario cmdlet 运行内置的混乱测试方案。The service developer then runs the built-in chaos test scenario using the ChaosTestScenarioParameters and ChaosTestScenario classes, or the Invoke-ServiceFabricChaosTestScenario cmdlet. 任意混沌测试方案会将多个节点、代码包和副本错误包括到群集中。The chaos test scenario randomly induces multiple node, code package, and replica faults into the cluster.
  3. 服务开发人员通过创建围绕群集移动主副本的测试方案,来测试服务之间的通信The service developer tests service-to-service communication by authoring test scenarios that move primary replicas around the cluster.

有关详细信息,请参阅故障分析服务简介See Introduction to the Fault Analysis Service for more information.

升级Upgrade

  1. 服务开发人员更新实例化应用程序的构成服务并/或修复 bug,并提供服务清单的新版本。A service developer updates the constituent services of the instantiated application and/or fixes bugs and provides a new version of the service manifest.
  2. 应用程序开发人员 重写并参数化一致服务的配置和部署设置,并提供应用程序清单的新版本。An application developer overrides and parameterizes the configuration and deployment settings of the consistent services and provides a new version of the application manifest. 然后,应用程序开发人员将服务清单的新版本合并到应用程序中,并在更新的应用程序包中提供应用程序类型的新版本。The application developer then incorporates the new versions of the service manifests into the application and provides a new version of the application type in an updated application package.
  3. 应用程序管理员 通过更新相应参数,将应用程序类型的新版本合并到目标应用程序中。An application administrator incorporates the new version of the application type into the target application by updating the appropriate parameters.
  4. 操作员使用 CopyApplicationPackage 方法Copy-ServiceFabricApplicationPackage cmdlet,将更新的应用程序包上传到群集映像存储中。An operator uploads the updated application package to the cluster image store using the CopyApplicationPackage method or the Copy-ServiceFabricApplicationPackage cmdlet. 应用程序包包含应用程序清单和服务包集合。The application package contains the application manifest and the collection of service packages.
  5. 操作员使用 ProvisionApplicationAsync 方法Register-ServiceFabricApplicationType cmdlet预配应用程序 REST 操作,在目标群集中预配应用程序的新版本。An operator provisions the new version of the application in the target cluster by using the ProvisionApplicationAsync method, the Register-ServiceFabricApplicationType cmdlet, or the Provision an Application REST operation.
  6. 操作员使用 UpgradeApplicationAsync 方法Start-ServiceFabricApplicationUpgrade cmdlet升级应用程序 REST 操作将目标应用程序升级到新版本。An operator upgrades the target application to the new version using the UpgradeApplicationAsync method, the Start-ServiceFabricApplicationUpgrade cmdlet, or the Upgrade an Application REST operation.
  7. 操作员使用 GetApplicationUpgradeProgressAsync 方法Get ServiceFabricApplicationUpgrade cmdlet获取应用程序升级进度 REST 操作,来检查升级进度。An operator checks the progress of upgrade using the GetApplicationUpgradeProgressAsync method, the Get-ServiceFabricApplicationUpgrade cmdlet, or the Get Application Upgrade Progress REST operation.
  8. 如有必要,操作员将使用 UpdateApplicationUpgradeAsync 方法Update-ServiceFabricApplicationUpgrade cmdlet更新应用程序升级 REST 操作,来修改并重新应用当前应用程序升级参数。If necessary, the operator modifies and reapplies the parameters of the current application upgrade using the UpdateApplicationUpgradeAsync method, the Update-ServiceFabricApplicationUpgrade cmdlet, or the Update Application Upgrade REST operation.
  9. 如有必要,操作员会使用 RollbackApplicationUpgradeAsync 方法Start-ServiceFabricApplicationRollback cmdlet回滚应用程序升级 REST 操作,来回滚当前的应用程序升级。If necessary, the operator rolls back the current application upgrade using the RollbackApplicationUpgradeAsync method, the Start-ServiceFabricApplicationRollback cmdlet, or the Rollback Application Upgrade REST operation.
  10. Service Fabric 对在群集中运行的目标应用程序进行升级,并且不会丢失其任何构成服务的可用性。Service Fabric upgrades the target application running in the cluster without losing the availability of any of its constituent services.

有关示例,请参阅应用程序升级教程See the Application upgrade tutorial for examples.

维护Maintain

  1. 对于操作系统升级和修补程序,Service Fabric 与 Azure 基础结构连接,以确保在群集中运行的所有应用程序的可用性。For operating system upgrades and patches, Service Fabric interfaces with the Azure infrastructure to guarantee availability of all the applications running in the cluster.
  2. 对于 Service Fabric 平台的升级和修补程序,Service Fabric 自行升级,并且不会丢失在群集上运行的任何应用程序的可用性。For upgrades and patches to the Service Fabric platform, Service Fabric upgrades itself without losing availability of any of the applications running on the cluster.
  3. 应用程序管理员在分析历史容量使用率数据与将来需求后,批准从群集中添加或删除节点。An application administrator approves the addition or removal of nodes from a cluster after analyzing historical capacity utilization data and projected future demand.
  4. 操作员添加和删除由应用程序管理员指定的节点。An operator adds and removes nodes specified by the application administrator.
  5. 当新节点被添加到群集中或从群集中删除现有节点时,Service Fabric 自动负载均衡正在群集中的所有节点上运行的应用程序,以获得最佳性能。When new nodes are added to or existing nodes are removed from the cluster, Service Fabric automatically load-balances the running applications across all nodes in the cluster to achieve optimal performance.

删除Remove

  1. 操作员可以使用 DeleteServiceAsync 方法Remove-ServiceFabricService cmdlet删除服务 REST 操作来删除群集中正在运行的服务的特定实例,并且不会删除整个应用程序。An operator can delete a specific instance of a running service in the cluster without removing the entire application using the DeleteServiceAsync method, the Remove-ServiceFabricService cmdlet, or the Delete Service REST operation.
  2. 操作员还可以使用 DeleteApplicationAsync 方法Remove-ServiceFabricApplication cmdlet,或删除应用程序 REST 操作,来删除应用程序实例及其所有服务。An operator can also delete an application instance and all of its services using the DeleteApplicationAsync method, the Remove-ServiceFabricApplication cmdlet, or the Delete Application REST operation.
  3. 应用程序和服务停止后,操作员可以使用 UnprovisionApplicationAsync 方法Unregister-ServiceFabricApplicationType cmdlet,或取消预配应用程序 REST 操作,来取消预配应用程序类型。Once the application and services have stopped, the operator can unprovision the application type using the UnprovisionApplicationAsync method, the Unregister-ServiceFabricApplicationType cmdlet, or the Unprovision an Application REST operation. 取消预配应用程序类型不会从 ImageStore 删除应用程序包。Unprovisioning the application type does not remove the application package from the ImageStore. 必须手动删除应用程序包。You must remove the application package manually.
  4. 操作员使用 RemoveApplicationPackage 方法Remove-ServiceFabricApplicationPackage cmdlet 从 ImageStore 中删除应用程序包。An operator removes the application package from the ImageStore using the RemoveApplicationPackage method or the Remove-ServiceFabricApplicationPackage cmdlet.

有关示例,请参阅部署应用程序See Deploy an application for examples.

后续步骤Next steps

有关开发、测试和管理 Service Fabric 应用程序与服务的详细信息,请参阅:For more information on developing, testing, and managing Service Fabric applications and services, see: