Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get service version at runtime

How to get the executing Service Fabric services (and application) versions at run time? I have tried the context, but both StatefulServiceContext and StatelessServiceContext do not provide that information.

like image 411
Sean Feldman Avatar asked Oct 28 '25 09:10

Sean Feldman


2 Answers

You can use FabricClient to get this information.

For the application version:

var applicationName = new Uri("fabric:/MyApp"); // or use Context.CodePackageActivationContext.ApplicationName
using (var client = new FabricClient())
{
    var applications = await client.QueryManager.GetApplicationListAsync(applicationName).ConfigureAwait(false);
    var version = applications[0].ApplicationTypeVersion;
}

For service versions -

From within a service class:

Context.CodePackageActivationContext.GetServiceManifestVersion()

Or:

var serviceName = new Uri("fabric:/MyApp/MyService"); // or use Context.ServiceName
using (var client = new FabricClient())
{
    var services = await client.QueryManager.GetServiceListAsync(applicationName, serviceName).ConfigureAwait(false);
    var version = services[0].ServiceManifestVersion;
}

Notes:

  • During an upgrade, you will get the old versions using this API. If you need the new version, use FabricClient.ApplicationManager.GetApplicationUpgradeProgressAsync and retrive the TargetApplicationTypeVersion
  • You may want to cache FabricClient if you use it often (see remarks here)
  • The CodePackageActivationContext also contains the CodePackageVersion, which is different than the version of the service manifest
like image 167
Eli Arbel Avatar answered Oct 31 '25 08:10

Eli Arbel


You can also use PowerShell. To get the application type version:

Get-ServiceFabricApplication -ApplicationName fabric:/MyApplication | Select -expand ApplicationTypeVersion

To get the service manifest version:

Get-ServiceFabricService -ApplicationName fabric:/MyApplication -ServiceName fabric:/MyApplication/MyStatefulService | Select -expand ServiceManifestVersion
like image 43
Ryan Wike Avatar answered Oct 31 '25 09:10

Ryan Wike



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!