我需要验证服务是否已在SF群集中正确部署(未测试)。目前我正在使用这样的东西。还有什么我应该看的?请建议。
using (var result = new HttpClient())
{
if ( result.GetAsync(url).Result.StatusCode == httpStatusCode.ServiceUnavailable)
{
// Not deployed correctly
}
else
{
// Deployment success.
}
}
更新:我可以通过yoape和This SO使用下面的答案,并获取我需要的应用信息。谢谢yoape。
答案 0 :(得分:1)
您可以使用FabricClient
在Service Fabric中查询特定服务的状态。
您可以从群集内外连接到FabricClient
。如果您有安全集群,则需要在打开连接时提供证书(有关如何设置,请参阅this SO answer)。
var fabricClient = new FabricClient("{your-cluster-name}.{your-cluster-region}.cloudapp.azure.com:19000");
var applicationList = await fabricClient.QueryManager.GetApplicationListAsync();
var application = applicationList.FirstOrDefault(app => app.Name == "myAppName");
// if null then your application doesn't exist in the cluster
var serviceList = await fabricClient.QueryManager.GetServiceListAsync(application.ApplicationName, serviceName);
var service = serviceList.FirstOrDefault();
// if null then the service doesn't exist at all in your application in this cluster.
现在,只需检查刚检索到的服务的ServiceStatus
if( service.ServiceState == ServiceStatus.Active){
// All good, yoour service is up and running
}
else{
// It could be either upgrading, deleting, failed and so on...
}