使用" Loggedin"我试图在我的订阅中列出HDInsight群集,但是当我尝试运行代码时," Loggedin"页面保持加载没有任何输出。我无法弄清楚我哪里出错了。
调试时,代码在控制器的var cluster = client.ListClusters();
行挂起。
在此实例中,输出窗口显示以下消息:
Microsoft.WindowsAzure.ServiceRuntime详细:500:角色实例状态检查启动Microsoft.WindowsAzure.ServiceRuntime详细:502:角色实例状态检查成功:就绪线程0x59fc已退出,代码为259(0x103)。
非常感谢任何帮助。
控制器
public ActionResult Loggedin()
{
Guid subscriptionId = new Guid("Subscription_id"); //your-subscription-id
string certName = "Friendly_name"; //your friendly name
// Create an HDInsight Client
X509Store store = new X509Store(StoreName.My);
store.Open(OpenFlags.ReadOnly);
X509Certificate2 cert = store.Certificates.Cast<X509Certificate2>().First(item => item.FriendlyName == certName);
HDInsightCertificateCredential creds = new HDInsightCertificateCredential(subscriptionId, cert);
IHDInsightClient client = HDInsightClient.Connect(creds);
var cluster = client.ListClusters();
var c = new List<ClusterList>();
foreach (var item in cluster)
{
c.Add(new ClusterList() { Name = item.Name });
c.Add(new ClusterList() { Node = item.ClusterSizeInNodes });
}
return View(c);
}
模型
public class ClusterList
{
public string Name { get; set; }
public int Node { get; set; }
}
查看
@model List<listCluster.Models.ClusterList>
@{
ViewBag.Title = "Loggedin";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Loggedin</h2>
<div>
<table>
<tr>
<th>@Html.Label("Name")</th>
<th>@Html.Label("Node")</th>
</tr>
<tr>
<td>@Model.Name</td>
<td>@Model.Node</td>
</tr>
</table>
</div>
&#13;
答案 0 :(得分:0)
thread exit code上的一篇文章帮助我找到了确切的问题。 此外,帖子Stephen Cleary - Don't Block on Async Code帮助我解决了这个问题。
代码中的以下更改解决了问题:
控制器
public async Task<ActionResult> Loggedin()
{
ViewBag.Message = "Your application description page.";
var c = new List<ClusterList>();
var call = Task.Factory.StartNew(() => c=GetAsync());
await call;
return View(c);
}
public List<ClusterList> GetAsync()
{
Guid subscriptionId = new Guid("your-subscription-id"); //your-subscription-id
string certName = "Friendly";//your-subscription-management-cert-name
// Create an HDInsight Client
X509Store store = new X509Store(StoreName.My);
store.Open(OpenFlags.ReadOnly);
X509Certificate2 cert = store.Certificates.Cast<X509Certificate2>().Single(item => item.FriendlyName == certName); //your friendly name
HDInsightCertificateCredential creds = new HDInsightCertificateCredential(subscriptionId, cert);
IHDInsightClient client = HDInsightClient.Connect(creds);
var cluster = client.ListClusters();
var c1 = new List<ClusterList>();
foreach(var item in cluster)
{
c1.Add(new ClusterList() { Name = item.Name, Node = item.ClusterSizeInNodes });
}
return c1;
}
模型保持不变。
查看
@model List<listCluster.ClusterList>
@{
ViewBag.Title = "Loggedin";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Loggedin</h2>
<div>
<table>
<tr>
<th>@Html.Label("Name")</th>
<th>@Html.Label("Node")</th>
</tr>
@foreach(var item in Model)
{
<tr>
<td>@item.Name</td>
<td align="center">@item.Node</td>
</tr>
}
</table>
</div>
&#13;