列出Azure云中的所有实例端点 [英] List all instance endpoints in Azure Cloud

查看:776
本文介绍了列出Azure云中的所有实例端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Azure Cloud中列出所有端点,而不只是列出当前角色实例的端点?



尝试了以下代码,但它只列出了当前Azure实例上的端点,而不是任何其他Azure实例上的端点:

  void ListCloudInstances )
{
var instances = new StringBuilder();

foreach(RoleEnvironment.Roles中的var角色)
{
instances.AppendFormat(< h2> Role< em> {0}< / em> / h2>< br />,role.Value.Name);
if(role.Value.Instances.Count == 0)
instances.AppendFormat(< small> Role< em> {0}< / em>没有角色实例< / small> ;< br />< br />,role.Value.Name);

foreach(var roleInstance in role.Value.Instances)
{
var currentRoleMarker = RoleEnvironment.CurrentRoleInstance.Id == roleInstance.Id? *:String.Empty;
instances.AppendFormat(< h3> Role< em> {2}< / em> instance< em> {0}< / em> {1}< / h3>< br />,
roleInstance.Id,currentRoleMarker,roleInstance.Role.Name);

//列出一些关于角色实例的元数据
instances.AppendFormat(< p>角色实例故障域:{0}< / p>,roleInstance.FaultDomain);
instances.AppendFormat(< p>实例的角色:{0}< / p>,roleInstance.Role.Name);
instances.AppendFormat(< p> Role instance update domain:{0}< / p>< br />,roleInstance.UpdateDomain);

//列出端点
instances.AppendFormat(< h4> Role< em> {1}< / em> instance< em> {0}< / em> endpoints< / h4>< br />,roleInstance.Id,
roleInstance.Role.Name);

foreach(RoleInstanceEndpoint instanceInndance in roleInstance.InstanceEndpoints.Values)
{
if(roleInstance.Role.Name ==Www)
instances.AppendFormat < p>< a href = \{0}:// {1} /Admin/Settings.aspx\target = \_blank\> {1}< / a> ; / p>,
instanceEndpoint.Protocol,instanceEndpoint.IPEndpoint);
else instances.AppendFormat(< p>实例端点IP地址,端口和协议:{0} {1}< / p>,
instanceEndpoint.IPEndpoint,instanceEndpoint.Protocol);
}
}
}

instances.AppendFormat(< small> *当前角色实例为{0}< / small>,RoleEnvironment.CurrentRoleInstance 。ID);

CloudHtml.Text = instances.ToString();
}

在多角色项目上运行时输出,其中每个角色都有多个实例: / p>


角色MultiThreadedWorkerRole



角色MultiThreadedWorkerRole没有角色实例



角色Www



角色Www实例 deployment22(203).CloudService1.Www_IN_1 *



角色实例故障域:1



实例的角色:Www



角色实例更新域:1



角色Www实例 deployment22(203).CloudService1.Www_IN_1 端点



127.255.0.3:82



127.255.0.3:444


  • 当前角色实例是 deployment22(203).CloudService1.Www_IN_1


如果我重新运行上面的查询,我从角色实例中随机获取部署22(203).CloudService1.Www_IN_0到deployment22(203).CloudService1 .Www_IN_4由处理运行上述代码片段的ASP.NET Web表单的实例决定。示例:


角色MultiThreadedWorkerRole



角色MultiThreadedWorkerRole没有角色实例



角色Www



角色Www实例 deployment22(203).CloudService1.Www_IN_0 p>

角色实例故障域:0



实例的角色:Www



角色实例更新域:0



角色Www实例 deployment22(203).CloudService1.Www_IN_0端点 b
$ b

127.255.0.2:82



127.255.0.2:444 / p>


  • 当前角色实例是 deployment22(203).CloudService1.Www_IN_0



解决方案

我相信关键是在 RoleEnvironment的角色属性的文档 -


必须为角色定义至少一个内部端点,以便在运行时能够识别
实例


< blockquote>

我刚刚尝试通过创建一个具有两个角色的云项目,并使用 RoleEnvironment.Roles 没有任何内部端点,只有当前角色的实例可用。



将内部端点添加到其他角色后,为其加载其实例。
Howeber - 只有内部端点列在角色实例的 InstanceEndpoints 集合中。我看不到他们暴露的外部端点。


How do I list all the endpoints in the Azure Cloud and not just the endpoints on the current role instance?

I've tried the following code but it only lists the endpoints on the current Azure instance and not on any other Azure instances:

void ListCloudInstances()
{
    var instances = new StringBuilder("");

    foreach (var role in RoleEnvironment.Roles)
    {
        instances.AppendFormat("<h2>Role <em>{0}</em></h2><br/>", role.Value.Name);
        if (role.Value.Instances.Count == 0)
            instances.AppendFormat("<small>Role <em>{0}</em> has no role instances</small><br/><br/>", role.Value.Name);

        foreach (var roleInstance in role.Value.Instances)
        {
            var currentRoleMarker = RoleEnvironment.CurrentRoleInstance.Id == roleInstance.Id ? " *" : String.Empty;
            instances.AppendFormat("<h3>Role <em>{2}</em> instance <em>{0}</em>{1}</h3><br/>", 
                roleInstance.Id, currentRoleMarker, roleInstance.Role.Name);

            // List some metadata about the role instance
            instances.AppendFormat("<p>Role instance fault domain: {0}</p>", roleInstance.FaultDomain);
            instances.AppendFormat("<p>Role for the instance: {0}</p>", roleInstance.Role.Name);
            instances.AppendFormat("<p>Role instance update domain: {0}</p><br/>", roleInstance.UpdateDomain);

            // List the endpoints
            instances.AppendFormat("<h4>Role <em>{1}</em> instance <em>{0}</em> endpoints</h4><br/>", roleInstance.Id,
                roleInstance.Role.Name);

            foreach (RoleInstanceEndpoint instanceEndpoint in roleInstance.InstanceEndpoints.Values)
            {
                if (roleInstance.Role.Name == "Www")
                    instances.AppendFormat("<p><a href=\"{0}://{1}/Admin/Settings.aspx\" target=\"_blank\">{1}</a></p>", 
                        instanceEndpoint.Protocol, instanceEndpoint.IPEndpoint);
                else instances.AppendFormat("<p>Instance endpoint IP address, port, and protocol : {0} {1}</p>",
                    instanceEndpoint.IPEndpoint, instanceEndpoint.Protocol);
            }
        }
    }

    instances.AppendFormat("<small>* Current role instance is {0}</small>", RoleEnvironment.CurrentRoleInstance.Id);

    CloudHtml.Text = instances.ToString();
}

Output from running on a multiple role project where each role has multiple instances:

Role MultiThreadedWorkerRole

Role MultiThreadedWorkerRole has no role instances

Role Www

Role Www instance deployment22(203).CloudService1.Www_IN_1 *

Role instance fault domain: 1

Role for the instance: Www

Role instance update domain: 1

Role Www instance deployment22(203).CloudService1.Www_IN_1 endpoints

127.255.0.3:82

127.255.0.3:444

  • Current role instance is deployment22(203).CloudService1.Www_IN_1

If I re-run the above query I randomly get the output from the role instances deployment22(203).CloudService1.Www_IN_0 to deployment22(203).CloudService1.Www_IN_4 as decided by which instance that processes the ASP.NET web form that runs the above code snippet. Example:

Role MultiThreadedWorkerRole

Role MultiThreadedWorkerRole has no role instances

Role Www

Role Www instance deployment22(203).CloudService1.Www_IN_0 *

Role instance fault domain: 0

Role for the instance: Www

Role instance update domain: 0

Role Www instance deployment22(203).CloudService1.Www_IN_0 endpoints

127.255.0.2:82

127.255.0.2:444

  • Current role instance is deployment22(203).CloudService1.Www_IN_0

解决方案

I believe the key is in the following note made on the documentation of the RoleEnvironment's Roles property -

At least one internal endpoint must be defined for a role to enable instances to be known at runtime

I've just tried it by creating a cloud project with two roles and iterating on the roles using RoleEnvironment.Roles, without any internal endpoints only the current role's instances were available.

After adding an internal endpoint to the other role its instances were loaded for me. Howeber - only the internal endpoints were listed in the role instance's InstanceEndpoints collection. I could not see the external endpoints they've exposed.

这篇关于列出Azure云中的所有实例端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆