我应该在代码或清单文件中的什么地方添加 ServicePlacementPreferPrimaryDomainPolicyDescription?
Where should I add ServicePlacementPreferPrimaryDomainPolicyDescription in code or manifest file?
我有一个集群跨区域,我想指定首选域。问题是查看 https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-cluster-resource-manager-advanced-placement-rules-placement-policies 中的示例代码,我不知道 serviceDescription 来自哪里。任何人都知道我应该在我的服务结构服务代码库中的什么地方放置这些代码?
另外,难道没有类似的方法在服务结构清单文件中指定它而不是代码更改(就像人们如何指定 frontend/backend 放置一样)?
谢谢,
使用此代码更改服务说明:
FabricClient fabricClient = new FabricClient();
StatefulServiceDescription serviceDescription = new StatefulServiceDescription();
serviceDescription.PlacementConstraints = "(HasSSD == true && SomeProperty >= 4)";
await fabricClient.ServiceManager.CreateServiceAsync(serviceDescription);
(来源here)
根据XSD,您可以将它们定义为xml,类似于放置约束。
C:\Program Files\Microsoft SDKs\Service Fabric\schemas\ServiceFabricServiceModel.xsd
根据MS Docs,您当然可以按代码配置它,如下所示:
FabricClient fabricClient = new FabricClient();
StatefulServiceDescription serviceDescription = new StatefulServiceDescription();
serviceDescription.PlacementConstraints = "(HasSSD == true && SomeProperty >= 4)";
// add other required servicedescription fields
//...
await fabricClient.ServiceManager.CreateServiceAsync(serviceDescription);
关于从哪里开始执行此操作的问题 - 根据您的需要,有几个选项:
- 编写一个单独的应用程序获取 运行 作为 CI/CD 部署管道的一部分(或通过 powershell
New-ServiceFabricService
完成)
这种方法的问题在于,开发人员在每次部署后都必须 运行 这有点烦人 - 因此我更喜欢:
- 编写一个默认实例化的无状态服务(即在
ApplicationManifest.xml
内的 <DefaultServices>
内放置一个条目)。在此服务中,您可以使用 FabricClient
、策略、指标 instantiate/modify 放置约束 - 并通过应用程序 parameters/configuration 驱动这些
- 通过您的 API 网关延迟实例化服务。这对于 partitioned/stateful 服务(例如,如果您按 tenantid 分区)或您想要维护工作池的地方(例如
partition_id = random_number % pool size
)等特别有效
您还可以配置放置约束 declaratively via application parameters. Unfortunately this doesn't seem to work atm for placement policies (and probably not for metrics。
如果您的需求很简单,那么声明式方法可能是最简单的!按照上面 link,在您的应用程序清单文件中添加一个 [Stateless1_InstanceCount]
参数并将其置于默认服务下:
<DefaultServices>
<Service Name="Stateless1">
<StatelessService ServiceTypeName="Stateless1Type" InstanceCount="[Stateless1_InstanceCount]">
<SingletonPartition />
<PlacementConstraints>[Stateless1_PlacementConstraints]</PlacementConstraints>
</StatelessService>
</Service>
</DefaultServices>
我有一个集群跨区域,我想指定首选域。问题是查看 https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-cluster-resource-manager-advanced-placement-rules-placement-policies 中的示例代码,我不知道 serviceDescription 来自哪里。任何人都知道我应该在我的服务结构服务代码库中的什么地方放置这些代码?
另外,难道没有类似的方法在服务结构清单文件中指定它而不是代码更改(就像人们如何指定 frontend/backend 放置一样)?
谢谢,
使用此代码更改服务说明:
FabricClient fabricClient = new FabricClient();
StatefulServiceDescription serviceDescription = new StatefulServiceDescription();
serviceDescription.PlacementConstraints = "(HasSSD == true && SomeProperty >= 4)";
await fabricClient.ServiceManager.CreateServiceAsync(serviceDescription);
(来源here)
根据XSD,您可以将它们定义为xml,类似于放置约束。
C:\Program Files\Microsoft SDKs\Service Fabric\schemas\ServiceFabricServiceModel.xsd
根据MS Docs,您当然可以按代码配置它,如下所示:
FabricClient fabricClient = new FabricClient();
StatefulServiceDescription serviceDescription = new StatefulServiceDescription();
serviceDescription.PlacementConstraints = "(HasSSD == true && SomeProperty >= 4)";
// add other required servicedescription fields
//...
await fabricClient.ServiceManager.CreateServiceAsync(serviceDescription);
关于从哪里开始执行此操作的问题 - 根据您的需要,有几个选项:
- 编写一个单独的应用程序获取 运行 作为 CI/CD 部署管道的一部分(或通过 powershell
New-ServiceFabricService
完成) 这种方法的问题在于,开发人员在每次部署后都必须 运行 这有点烦人 - 因此我更喜欢: - 编写一个默认实例化的无状态服务(即在
ApplicationManifest.xml
内的<DefaultServices>
内放置一个条目)。在此服务中,您可以使用FabricClient
、策略、指标 instantiate/modify 放置约束 - 并通过应用程序 parameters/configuration 驱动这些
- 通过您的 API 网关延迟实例化服务。这对于 partitioned/stateful 服务(例如,如果您按 tenantid 分区)或您想要维护工作池的地方(例如
partition_id = random_number % pool size
)等特别有效
您还可以配置放置约束 declaratively via application parameters. Unfortunately this doesn't seem to work atm for placement policies (and probably not for metrics。
如果您的需求很简单,那么声明式方法可能是最简单的!按照上面 link,在您的应用程序清单文件中添加一个 [Stateless1_InstanceCount]
参数并将其置于默认服务下:
<DefaultServices>
<Service Name="Stateless1">
<StatelessService ServiceTypeName="Stateless1Type" InstanceCount="[Stateless1_InstanceCount]">
<SingletonPartition />
<PlacementConstraints>[Stateless1_PlacementConstraints]</PlacementConstraints>
</StatelessService>
</Service>
</DefaultServices>