Azure service fabric 在开发人员计算机上自动创建不带DefaultServices的服务

Azure service fabric 在开发人员计算机上自动创建不带DefaultServices的服务,azure-service-fabric,Azure Service Fabric,在最近的Service Fabric Community Q&A第24版上,关于在ApplicationManifest.xml中使用DefaultService构造及其缺点进行了大量讨论。Microsoft建议在ApplicationManifest中完全忽略这一点,而是修改部署FabricApplication.ps1来构建应用程序的默认实现,以便开发人员仍然有不错的F5体验 因此,我将部署FabricApplication.ps1修改为以下内容(此摘录是脚本的底部): 上述操作失败,并出现

在最近的Service Fabric Community Q&A第24版上,关于在
ApplicationManifest.xml
中使用DefaultService构造及其缺点进行了大量讨论。Microsoft建议在ApplicationManifest中完全忽略这一点,而是修改
部署FabricApplication.ps1
来构建应用程序的默认实现,以便开发人员仍然有不错的F5体验

因此,我将部署FabricApplication.ps1修改为以下内容(此摘录是脚本的底部):

上述操作失败,并出现错误

FabricElementNotFoundException

但是,如果您取消注释行
#Get servicefactricapplication
,您将看到它实际上返回了

ApplicationName        : fabric:/Acme.Hierarchy
ApplicationTypeName    : Acme.HierarchyType
ApplicationTypeVersion : 1.0.0
ApplicationParameters  : { "_WFDebugParams_" = "[{"CodePackageName":"Code","Cod
                         ePackageLinkFolder":null,"ConfigPackageName":null,"Con
                         figPackageLinkFolder":null,"DataPackageName":null,"Dat
                         aPackageLinkFolder":null,"LockFile":null,"WorkingFolde
                         r":null,"ServiceManifestName":"Quantium.RetailToolkit.
                         Fabric.Hierarchy.HierarchyServicePkg","EntryPointType"
                         :"Main","DebugExePath":"C:\\Program Files 
                         (x86)\\Microsoft Visual Studio\\2017\\Professional\\Co
                         mmon7\\Packages\\Debugger\\VsDebugLaunchNotify.exe","D
                         ebugArguments":" 
                         {6286e1ef-907b-4371-961c-d833ab9509dd} -p [ProcessId] 
                         -tid [ThreadId]","DebugParametersFile":null}]";
                         "Acme.Hierarchy.HierarchyServ
                         ice_InstanceCount" = "1" }

Create application succeeded.
在发布脚本完成后运行失败的命令,效果非常好

有没有人能解决我如何通过不使用DefaultServices而使用Powershell脚本来获得良好的开发人员体验的问题


提前感谢

我已更新了答案,添加了不应使用默认服务(仅在生产中)的更多详细信息

在service fabric上,您有两个选项来创建服务:

  • 声明式方法,通过默认服务功能完成,您可以使用ApplicationManifest描述应作为应用程序一部分运行的服务
  • 以及部署应用程序后使用powershell命令创建这些服务的动态方法
声明式方式为您提供了定义应用程序预期结构的便利,以便服务结构根据ApplicationManifest中的声明创建和启动服务实例。它为您提供的便利对于开发目的非常有用,想象一下,如果每次您必须调试应用程序时,它必须:构建>包>部署到服务结构>您必须手动启动定义应用程序的许多服务。这太不方便了,所以这就是为什么默认服务变得方便的原因

另一种情况是应用程序定义不可变,这意味着在生产中部署相同数量的服务和实例时,这些服务和实例将保持不变

但我们知道,这些定义不太可能在几年甚至一天中的几个小时内保持不变,因为微服务的理念是它们应该是可伸缩和灵活的,这样我们就可以独立调整各个服务的配置

使用默认服务对业务流程逻辑来说太复杂了。请确定与原始部署中指定的默认服务相比,您的服务发生了哪些更改,以及在发生冲突的情况下,哪些配置应具有优先级,例如:

  • 部署的默认服务定义了一个具有5个实例的服务,在部署该服务后,执行powershell脚本以更新到10个实例,然后新的应用程序升级,默认服务具有5个实例或新的值8,会发生什么情况?哪一个是正确的
  • 如果向默认服务中未定义的现有部署中添加额外命名的服务(具有其他名称的相同类型的服务),当新部署出现并表示不应使用此服务时会发生什么情况?删除它?数据呢?如何从生产中删除此服务?如果我在开发过程中错误删除
  • 新版本删除现有服务,部署失败,如何重新创建旧服务?是否有任何数据需要作为部署的一部分进行迁移
  • 已重命名服务。我如何跟踪它被重命名,而不是删除旧的并添加新的
这些是可能发生的许多问题中的一部分。这就是为什么您应该远离默认服务,动态地(强制地)创建它们,使用动态服务,服务结构将收到一个升级命令,将发生的是:

“这是我的新应用程序类型包和新服务类型 定义,无论部署在那里的是什么版本,都要为此进行替换 版本,并保持相同的配置”

如果需要新配置,您将为部署提供参数,以覆盖旧值或在单独的命令中对其进行更改。这将使事情变得更简单,因为SF不必担心不同的配置,只需将包更改应用于已部署的服务

您还可以在以下链接中找到有关这些问题的详细信息:

关于您的主要问题:

有没有人能为我找到一个好的开发人员提供解决方案 体验不使用DefaultServices而使用Powershell 剧本

如果你想要一个好的体验,你应该使用默认的服务,这是为了给开发者一个好的体验,而不用担心启动时需要运行的服务

诀窍是,在您的CI过程中,您应该在打包应用程序之前从应用程序清单中删除默认服务,这样您以后就不会面临缺点

在CI期间删除defaultServices(如VSTS构建),您可以在开发环境中享受defaultServices的好处,不必维护powershell脚本版本(如果有新版本),并且删除默认服务是作为构建步骤添加的一个非常简单的powershell脚本。除此之外,一切都是一样的

Ps:我现在手头没有真正的脚本,但将非常简单,如下所示:

$appManifest = "C:\Temp\ApplicationManifest.xml"     #you pass as parameter

[xml]$xml = Get-Content $appManifest

$xml.ApplicationManifest.DefaultServices.RemoveAll()

$xml.save($appManifest)

这里的解决方案是使用名为Start的脚本-
$appManifest = "C:\Temp\ApplicationManifest.xml"     #you pass as parameter

[xml]$xml = Get-Content $appManifest

$xml.ApplicationManifest.DefaultServices.RemoveAll()

$xml.save($appManifest)
$cloud = $false
$singleNode = $true
$constrainedNodeTypes = $false

$lowkey = "-9223372036854775808"
$highkey = "9223372036854775807" 

$countyLowKey = 0
$countyHighKey = 57000

$appName = "fabric:/DataAggregation"
$appType = "DataAggregationType"
$appInitialVersion = "1.0.0"

if($singleNode)
{
    $webServiceInstanceCount = -1
    $deviceCreationInstanceCount = -1
    $countyServicePartitionCount = 1
    $deviceActorServicePartitionCount = 1
    $doctorServicePartitionCount = 1
}
else
{
    $webServiceInstanceCount = @{$true=-1;$false=1}[$cloud -eq $true] 
    $deviceCreationInstanceCount = @{$true=-1;$false=1}[$cloud -eq $true] 
    $countyServicePartitionCount = @{$true=10;$false=5}[$cloud -eq $true]  
    $deviceActorServicePartitionCount = @{$true=15;$false=5}[$cloud -eq $true]  
    $doctorServicePartitionCount = @{$true=100;$false=5}[$cloud -eq $true]  

    if($constrainedNodeTypes)
    {
        $webServiceConstraint = "NodeType == "
        $countyServiceConstraint = "NodeType == "
        $nationalServiceConstraint = "NodeType == "
        $deviceServiceConstraint = "NodeType == "
        $doctorServiceConstraint = "NodeType == "   
        $deviceCreationServiceConstraint = "NodeType == "        
    }
    else
    {
        $webServiceConstraint = ""
        $countyServiceConstraint = ""
        $nationalServiceConstraint = ""
        $deviceServiceConstraint = ""
        $doctorServiceConstraint = ""
        $deviceCreationServiceConstraint = ""   
    }
}

$webServiceType = "DataAggregation.WebServiceType"
$webServiceName = "DataAggregation.WebService"

$nationalServiceType = "DataAggregation.NationalServiceType"
$nationalServiceName = "DataAggregation.NationalService"
$nationalServiceReplicaCount = @{$true=1;$false=3}[$singleNode -eq $true]  

$countyServiceType = "DataAggregation.CountyServiceType"
$countyServiceName = "DataAggregation.CountyService"
$countyServiceReplicaCount = @{$true=1;$false=3}[$singleNode -eq $true]  

$deviceCreationServiceType = "DataAggregation.DeviceCreationServiceType"
$deviceCreationServiceName = "DataAggregation.DeviceCreationService"

$doctorServiceType = "DataAggregation.DoctorServiceType"
$doctorServiceName = "DataAggregation.DoctorService"
$doctorServiceReplicaCount = @{$true=1;$false=3}[$singleNode -eq $true]

$deviceActorServiceType = "DeviceActorServiceType"
$deviceActorServiceName= "DataAggregation.DeviceActorService"
$deviceActorReplicaCount = @{$true=1;$false=3}[$singleNode -eq $true]

New-ServiceFabricService -ServiceTypeName $webServiceType -Stateless -ApplicationName $appName -ServiceName "$appName/$webServiceName" -PartitionSchemeSingleton -InstanceCount $webServiceInstanceCount -PlacementConstraint $webServiceConstraint -ServicePackageActivationMode ExclusiveProcess

#create national
New-ServiceFabricService -ServiceTypeName $nationalServiceType -Stateful -HasPersistedState -ApplicationName $appName -ServiceName "$appName/$nationalServiceName" -PartitionSchemeSingleton -MinReplicaSetSize $nationalServiceReplicaCount -TargetReplicaSetSize $nationalServiceReplicaCount -PlacementConstraint $nationalServiceConstraint -ServicePackageActivationMode ExclusiveProcess

#create county
New-ServiceFabricService -ServiceTypeName $countyServiceType -Stateful -HasPersistedState -ApplicationName $appName -ServiceName "$appName/$countyServiceName" -PartitionSchemeUniformInt64 -LowKey $countyLowKey -HighKey $countyHighKey -PartitionCount $countyServicePartitionCount -MinReplicaSetSize $countyServiceReplicaCount -TargetReplicaSetSize $countyServiceReplicaCount -PlacementConstraint $countyServiceConstraint -ServicePackageActivationMode ExclusiveProcess

#create doctor
New-ServiceFabricService -ServiceTypeName $doctorServiceType -Stateful -HasPersistedState -ApplicationName $appName -ServiceName "$appName/$doctorServiceName" -PartitionSchemeUniformInt64 -LowKey $lowkey -HighKey $highkey -PartitionCount $doctorServicePartitionCount -MinReplicaSetSize $doctorServiceReplicaCount -TargetReplicaSetSize $doctorServiceReplicaCount -PlacementConstraint $doctorServiceConstraint -ServicePackageActivationMode ExclusiveProcess

#create device
New-ServiceFabricService -ServiceTypeName $deviceActorServiceType -Stateful -HasPersistedState -ApplicationName $appName -ServiceName "$appName/$deviceActorServiceName" -PartitionSchemeUniformInt64 -LowKey $lowkey -HighKey $highkey -PartitionCount $deviceActorServicePartitionCount -MinReplicaSetSize $deviceActorReplicaCount -TargetReplicaSetSize $deviceActorReplicaCount -PlacementConstraint $deviceServiceConstraint -ServicePackageActivationMode ExclusiveProcess -Verbose

#create device creation
New-ServiceFabricService -ServiceTypeName $deviceCreationServiceType -Stateless -ApplicationName $appName -ServiceName "$appName/$deviceCreationServiceName" -PartitionSchemeSingleton -InstanceCount $deviceCreationInstanceCount -PlacementConstraint $deviceCreationServiceConstraint -ServicePackageActivationMode ExclusiveProcess