【问题标题】:How to find association of Service Fabric application services to nodes?如何找到 Service Fabric 应用程序服务与节点的关联?
【发布时间】:2018-11-01 18:30:31
【问题描述】:

使用System.Fabric.FabricClient.QueryClient 方法从远程服务结构集群中提取信息,如何将应用程序服务与托管这些服务的节点关联?

我已利用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;

例如

  • 应用程序A
    • 服务A_A
      • NodeFe0
      • NodeFe1
    • 服务A_B
      • NodeBe0
      • NodeBe1
      • NodeBe2
  • AppB
    • 服务B_A
      • NodeFe0
      • NodeFe1

【问题讨论】:

    标签: c# azure-service-fabric


    【解决方案1】:

    此代码可帮助您大致了解哪些服务分区在哪些节点上运行

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

    【讨论】:

    • 谢谢!正是我想要达到的目标。我曾尝试使用GetDeployedApplicationListAsyncGetDeployedServiceTypeListAsync,但并没有得到我想要的结果。
    猜你喜欢
    • 2018-10-17
    • 2016-10-04
    • 2017-01-29
    • 2018-10-03
    • 1970-01-01
    • 2018-03-03
    • 2019-02-14
    • 2016-08-12
    • 1970-01-01
    相关资源
    最近更新 更多