简体   繁体   中英

How to find association of Service Fabric application services to nodes?

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;

eg

  • AppA
    • ServiceA_A
      • NodeFe0
      • NodeFe1
    • ServiceA_B
      • NodeBe0
      • NodeBe1
      • NodeBe2
  • AppB
    • ServiceB_A
      • NodeFe0
      • NodeFe1

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)}");
              }
         }
    }
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM