0

In c#, I want to get a list of service fabric node information where my stateless service runs. This will be useful in tests. I know how to do this for stateful service using FabricClient class and ActorServiceProxy class, but when it comes to stateless service, I couldn't find a way. Do you have an idea?

Thanks,

Thror
  • 223
  • 4
  • 12

2 Answers2

1

You can still use the FabricClient to get this information. Have a play with the QueryManager to check for the info you need

Here's some quick code I use to quickly query the latest version of our TenantApp Service then I check to see they're all running in a healthy state or they've been upgraded properly.

var currentAppTypes = await fabricClient.QueryManager.GetApplicationTypeListAsync();
var tenantAppTypes = currentAppTypes.Where(x => x.ApplicationTypeName.Equals("TenantAppsType"));
var latestTenantAppType = currentAppTypes.Where(x => x.ApplicationTypeName.Equals("TenantAppsType"))?
.OrderByDescending(x =>
{
    var versions = x.ApplicationTypeVersion.Split('.');
    if (versions.Length == 3)
    {
         return (int.Parse(versions[0]) * 1000000) +
                (int.Parse(versions[1]) * 1000) +
                 int.Parse(versions[2]);
     }
     return 0;
})?.FirstOrDefault();
if (latestTenantAppType != null)
{
       var currentSvcTypes = await fabricClient.QueryManager.GetServiceTypeListAsync(latestTenantAppType.ApplicationTypeName, latestTenantAppType.ApplicationTypeVersion);
      // etc
}

Or if you just want to get all the applications running

var currentApps = await fabricClient.QueryManager.GetApplicationListAsync();

Once you have the service information you can check the nodes its on or you can check the nodes directly themselves

var currentNodes = fabricClient.QueryManager.GetNodeListAsync();
var nodeInfo = await fabricClient.QueryManager.GetNodeLoadInformationAsync("nodeName");

Hope this helps

Peter Lea
  • 1,731
  • 2
  • 15
  • 24
  • Peter, thanks for your reply. Assuming my Stateless web api scale number is 2. Cluster has 5 nodes in total. How can I find out which two nodes run my web api? I looked into the codes you posted but couldn't find where it provides this information. – Thror Feb 14 '18 at 22:01
1

For anyone still trying to do this, I had a timer requirement that required me to work out how many nodes were running my app on the fly. This is roughly the code I used:

string currentNodeName = ServiceContext.NodeContext.NodeName;
var fabricClient = new FabricClient();
var nodeList = (await fabricClient.QueryManager.GetNodeListAsync()).ToList();

var serviceName = ServiceContext.ServiceName.LocalPath.Split('/')[1];
var nodesRunningApplication = new List<Node>();
foreach (var node in nodeList)
{
    var nodeApplicationList = await fabricClient.QueryManager.GetDeployedApplicationListAsync(node.NodeName);
    var nodeApplication = nodeApplicationList.FirstOrDefault(p => 
        p.ApplicationName.LocalPath.Split('/')[1] == serviceName);

    if (nodeApplication != null)
    {
        nodesRunningApplication.Add(node);
    }
}
AdamCrawford
  • 4,968
  • 1
  • 18
  • 12