0

Using "Loggedin" view i am trying to list HDInsight clusters in my subscription but when i am trying to run the code, "Loggedin" page keeps loading without any output.I am not able to figure out where i am going wrong.

While debugging, the code hangs up at the line var cluster = client.ListClusters(); in controller. At this instance, output window displays following message :

Microsoft.WindowsAzure.ServiceRuntime Verbose: 500 : Role instance status check starting Microsoft.WindowsAzure.ServiceRuntime Verbose: 502 : Role instance status check succeeded: Ready The thread 0x59fc has exited with code 259 (0x103).

Any help would be greatly appreciated.

Controller

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

    }

Model

public class ClusterList
{
    public string Name { get; set; }
    public int Node { get; set; }
}

View

 @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>
sourabh pandey
  • 481
  • 1
  • 5
  • 13
  • Your view uses model `ClusterList` but your controller is passing `List`? - this should be throwing an exception! –  Jan 11 '15 at 00:55
  • I replaced `@model listCluster.Models.ClusterList` with `@model List` , even then i am not getting any output. The page keeps loading. @Stephen Muecke – sourabh pandey Jan 11 '15 at 04:08
  • Your view still has other errors that will be throwing exceptions. `List` does not contain properties `Name` or `Node` - you need a loop to render one table row for each `ClusterList` in the collection. Other odd things include creating 2 `ClusterList` objects for each object returned by `client.ListClusters()` - one with `Name` property and the 2nd with `Node` property. Not sure what you mean by _The page keeps loading_! - the page would never even start loading because of the exceptions which you should be seeing (are you even hitting the `return View(c);` line?). –  Jan 11 '15 at 04:17
  • Yes you are right. Actually i am totally new to all these concepts. I am not able to figure out what changes to make. Can you please help me correcting the code. Thank you. – sourabh pandey Jan 11 '15 at 06:33

1 Answers1

0

One of the post on thread exit code helped me in finding the exact problem. Further the post Stephen Cleary - Don't Block on Async Code helped me solve the problem.

The following changes in the code solves the problem :

Controller

 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 remains same.

View

@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>
Community
  • 1
  • 1
sourabh pandey
  • 481
  • 1
  • 5
  • 13