2

Using the System.Fabric.FabricClient.QueryClient methods to pull information from a remote service fabric cluster, how can I associate the application services with the nodes hosting those services?

I've leveraged the answer at the ListEndPoints answer to get more details about my services and partitions but I do not see the properties I need for mapping services to nodes.

var fabricClient = new FabricClient(credentials, connectionString);
var nodes = fabricClient.QueryManager.GetNodeListAsync().Result;
var apps = fabricClient.QueryManager.GetApplicationListAsync().Result;
var services = fabricClient.QueryManager.GetServiceListAsync(app.ApplicationName).Result;
var partitions = fabricClient.QueryManager.GetPartitionListAsync(service.ServiceName).Result;

e.g.

  • AppA
    • ServiceA_A
      • NodeFe0
      • NodeFe1
    • ServiceA_B
      • NodeBe0
      • NodeBe1
      • NodeBe2
  • AppB
    • ServiceB_A
      • NodeFe0
      • NodeFe1
Stringfellow
  • 2,788
  • 2
  • 21
  • 36

1 Answers1

3

This code helps you get an overview of which service partition is running on which nodes

var fabricClient = new FabricClient();
var nodes = await fabricClient.QueryManager.GetNodeListAsync("");
var apps = fabricClient.QueryManager.GetApplicationListAsync().Result;
foreach (var app in apps)
{
    Console.WriteLine($"Discovered application:'{app.ApplicationName}");
    var deployedPartitions = new Dictionary<Guid, List<string>>();
    foreach (var node in nodes)
    {
        //get deployed partitions per node
        var deployed = await fabricClient.QueryManager.GetDeployedReplicaListAsync(node.NodeName, app.ApplicationName);

        foreach (var dep in deployed)
        {
             List<string> list;
             if (!deployedPartitions.TryGetValue(dep.Partitionid, out list))
             {
                  list = new List<string>();
                  deployedPartitions.Add(dep.Partitionid, list);
             }
             list.Add(node.NodeName);
         }
     }

     var services = await fabricClient.QueryManager.GetServiceListAsync(app.ApplicationName);
     foreach (var service in services)
     {
         Console.WriteLine($"Discovered Service:'{service.ServiceName}");
         var partitions = await fabricClient.QueryManager.GetPartitionListAsync(service.ServiceName);
         foreach (var partition in partitions)
         {
              var partitionId = partition.PartitionInformation.Id;
              if (deployedPartitions.TryGetValue(partitionId, out var nodeNames))
              {
                  Console.WriteLine($"Discovered {service.ServiceKind} Service:'{service.ServiceName} PartitionId: '{partitionId}' running on nodes {string.Join(", ", nodeNames)}");
              }
         }
    }
 }
LoekD
  • 11,402
  • 17
  • 27
  • Thank you! Exactly what I was trying to achieve. I had tried using `GetDeployedApplicationListAsync` and `GetDeployedServiceTypeListAsync` but was not quite getting the result I wanted. – Stringfellow May 25 '18 at 14:03