使用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;
e.g。
答案 0 :(得分: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)}");
}
}
}
}