简体   繁体   English

如何找到Service Fabric应用程序服务与节点的关联?

[英]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? 使用System.Fabric.FabricClient.QueryClient方法从远程服务结构群集中提取信息,如何将应用程序服务与托管这些服务的节点相关联?

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. 我已经利用ListEndPoints答案中的答案来获取有关我的服务和分区的更多详细信息,但是我看不到将服务映射到节点所需的属性。

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 APPA
    • ServiceA_A ServiceA_A
      • NodeFe0 NodeFe0
      • NodeFe1 NodeFe1
    • ServiceA_B ServiceA_B
      • NodeBe0 NodeBe0
      • NodeBe1 NodeBe1
      • NodeBe2 NodeBe2
  • AppB APPB
    • ServiceB_A ServiceB_A
      • NodeFe0 NodeFe0
      • NodeFe1 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)}");
              }
         }
    }
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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