|
12 | 12 | // limitations under the License.
|
13 | 13 | // ----------------------------------------------------------------------------------
|
14 | 14 |
|
15 |
| -using System; |
16 |
| -using System.Collections.Generic; |
17 |
| -using System.Collections.ObjectModel; |
18 |
| -using System.Linq; |
19 |
| -using System.Management.Automation; |
20 | 15 | using AutoMapper;
|
21 | 16 | using Microsoft.WindowsAzure.Commands.ServiceManagement.Helpers;
|
22 | 17 | using Microsoft.WindowsAzure.Commands.ServiceManagement.Properties;
|
23 | 18 | using Microsoft.WindowsAzure.Commands.Utilities.Common;
|
24 | 19 | using Microsoft.WindowsAzure.Management.Compute;
|
25 | 20 | using Microsoft.WindowsAzure.Management.Compute.Models;
|
| 21 | +using System; |
| 22 | +using System.Collections.Generic; |
| 23 | +using System.Collections.ObjectModel; |
| 24 | +using System.Linq; |
| 25 | +using System.Management.Automation; |
26 | 26 |
|
27 | 27 | namespace Microsoft.WindowsAzure.Commands.ServiceManagement.HostedServices
|
28 | 28 | {
|
@@ -70,88 +70,95 @@ protected override void OnProcessRecord()
|
70 | 70 | public void GetRoleProcess()
|
71 | 71 | {
|
72 | 72 | OperationStatusResponse getDeploymentOperation;
|
73 |
| - var currentDeployment = this.GetCurrentDeployment(out getDeploymentOperation); |
74 |
| - if (currentDeployment != null) |
| 73 | + try |
75 | 74 | {
|
76 |
| - if (this.InstanceDetails.IsPresent) |
| 75 | + var currentDeployment = this.GetCurrentDeployment(out getDeploymentOperation); |
| 76 | + if (currentDeployment != null) |
77 | 77 | {
|
78 |
| - Collection<PVM.RoleInstanceContext> instanceContexts = new Collection<PVM.RoleInstanceContext>(); |
79 |
| - IList<RoleInstance> roleInstances = null; |
80 |
| - |
81 |
| - if (string.IsNullOrEmpty(this.RoleName)) |
82 |
| - { |
83 |
| - roleInstances = currentDeployment.RoleInstances; |
84 |
| - } |
85 |
| - else |
86 |
| - { |
87 |
| - roleInstances = new List<RoleInstance>(currentDeployment.RoleInstances.Where(r => r.RoleName.Equals(this.RoleName, StringComparison.OrdinalIgnoreCase))); |
88 |
| - } |
89 |
| - |
90 |
| - foreach (var role in roleInstances) |
| 78 | + if (this.InstanceDetails.IsPresent) |
91 | 79 | {
|
92 |
| - var vmRole = currentDeployment.Roles == null || !currentDeployment.Roles.Any() ? null |
93 |
| - : currentDeployment.Roles.FirstOrDefault(r => string.Equals(r.RoleName, role.RoleName, StringComparison.OrdinalIgnoreCase)); |
| 80 | + Collection<PVM.RoleInstanceContext> instanceContexts = new Collection<PVM.RoleInstanceContext>(); |
| 81 | + IList<RoleInstance> roleInstances = null; |
94 | 82 |
|
95 |
| - instanceContexts.Add(new PVM.RoleInstanceContext |
| 83 | + if (string.IsNullOrEmpty(this.RoleName)) |
96 | 84 | {
|
97 |
| - ServiceName = this.ServiceName, |
98 |
| - OperationId = getDeploymentOperation.Id, |
99 |
| - OperationDescription = this.CommandRuntime.ToString(), |
100 |
| - OperationStatus = getDeploymentOperation.Status.ToString(), |
101 |
| - InstanceErrorCode = role.InstanceErrorCode, |
102 |
| - InstanceFaultDomain = role.InstanceFaultDomain, |
103 |
| - InstanceName = role.InstanceName, |
104 |
| - InstanceSize = role.InstanceSize, |
105 |
| - InstanceStateDetails = role.InstanceStateDetails, |
106 |
| - InstanceStatus = role.InstanceStatus, |
107 |
| - InstanceUpgradeDomain = role.InstanceUpgradeDomain, |
108 |
| - RoleName = role.RoleName, |
109 |
| - IPAddress = role.IPAddress, |
110 |
| - PublicIPAddress = role.PublicIPs == null || !role.PublicIPs.Any() ? null : role.PublicIPs.First().Address, |
111 |
| - PublicIPName = role.PublicIPs == null || !role.PublicIPs.Any() ? null |
112 |
| - : !string.IsNullOrEmpty(role.PublicIPs.First().Name) ? role.PublicIPs.First().Name |
113 |
| - : PersistentVMHelper.GetPublicIPName(vmRole), |
114 |
| - PublicIPIdleTimeoutInMinutes = role.PublicIPs == null || !role.PublicIPs.Any() ? null |
115 |
| - : role.PublicIPs.First().IdleTimeoutInMinutes, |
116 |
| - PublicIPDomainNameLabel = role.PublicIPs == null || !role.PublicIPs.Any() ? null : role.PublicIPs.First().DomainNameLabel, |
117 |
| - PublicIPFqdns = role.PublicIPs == null || !role.PublicIPs.Any() ? null : role.PublicIPs.First().Fqdns.ToList(), |
118 |
| - DeploymentID = currentDeployment.PrivateId, |
119 |
| - InstanceEndpoints = Mapper.Map<PVM.InstanceEndpointList>(role.InstanceEndpoints) |
120 |
| - }); |
121 |
| - } |
| 85 | + roleInstances = currentDeployment.RoleInstances; |
| 86 | + } |
| 87 | + else |
| 88 | + { |
| 89 | + roleInstances = new List<RoleInstance>(currentDeployment.RoleInstances.Where(r => r.RoleName.Equals(this.RoleName, StringComparison.OrdinalIgnoreCase))); |
| 90 | + } |
122 | 91 |
|
123 |
| - WriteObject(instanceContexts, true); |
124 |
| - } |
125 |
| - else |
126 |
| - { |
127 |
| - var roleContexts = new Collection<PVM.RoleContext>(); |
128 |
| - IList<Role> roles = null; |
129 |
| - if (string.IsNullOrEmpty(this.RoleName)) |
130 |
| - { |
131 |
| - roles = currentDeployment.Roles; |
| 92 | + foreach (var role in roleInstances) |
| 93 | + { |
| 94 | + var vmRole = currentDeployment.Roles == null || !currentDeployment.Roles.Any() ? null |
| 95 | + : currentDeployment.Roles.FirstOrDefault(r => string.Equals(r.RoleName, role.RoleName, StringComparison.OrdinalIgnoreCase)); |
| 96 | + |
| 97 | + instanceContexts.Add(new PVM.RoleInstanceContext |
| 98 | + { |
| 99 | + ServiceName = this.ServiceName, |
| 100 | + OperationId = getDeploymentOperation.Id, |
| 101 | + OperationDescription = this.CommandRuntime.ToString(), |
| 102 | + OperationStatus = getDeploymentOperation.Status.ToString(), |
| 103 | + InstanceErrorCode = role.InstanceErrorCode, |
| 104 | + InstanceFaultDomain = role.InstanceFaultDomain, |
| 105 | + InstanceName = role.InstanceName, |
| 106 | + InstanceSize = role.InstanceSize, |
| 107 | + InstanceStateDetails = role.InstanceStateDetails, |
| 108 | + InstanceStatus = role.InstanceStatus, |
| 109 | + InstanceUpgradeDomain = role.InstanceUpgradeDomain, |
| 110 | + RoleName = role.RoleName, |
| 111 | + IPAddress = role.IPAddress, |
| 112 | + PublicIPAddress = role.PublicIPs == null || !role.PublicIPs.Any() ? null : role.PublicIPs.First().Address, |
| 113 | + PublicIPName = role.PublicIPs == null || !role.PublicIPs.Any() ? null |
| 114 | + : !string.IsNullOrEmpty(role.PublicIPs.First().Name) ? role.PublicIPs.First().Name |
| 115 | + : PersistentVMHelper.GetPublicIPName(vmRole), |
| 116 | + PublicIPIdleTimeoutInMinutes = role.PublicIPs == null || !role.PublicIPs.Any() ? null |
| 117 | + : role.PublicIPs.First().IdleTimeoutInMinutes, |
| 118 | + PublicIPDomainNameLabel = role.PublicIPs == null || !role.PublicIPs.Any() ? null : role.PublicIPs.First().DomainNameLabel, |
| 119 | + PublicIPFqdns = role.PublicIPs == null || !role.PublicIPs.Any() ? null : role.PublicIPs.First().Fqdns.ToList(), |
| 120 | + DeploymentID = currentDeployment.PrivateId, |
| 121 | + InstanceEndpoints = Mapper.Map<PVM.InstanceEndpointList>(role.InstanceEndpoints) |
| 122 | + }); |
| 123 | + } |
| 124 | + |
| 125 | + WriteObject(instanceContexts, true); |
132 | 126 | }
|
133 | 127 | else
|
134 | 128 | {
|
135 |
| - roles = new List<Role>(currentDeployment.Roles.Where(r => r.RoleName.Equals(this.RoleName, StringComparison.OrdinalIgnoreCase))); |
136 |
| - } |
| 129 | + var roleContexts = new Collection<PVM.RoleContext>(); |
| 130 | + IList<Role> roles = null; |
| 131 | + if (string.IsNullOrEmpty(this.RoleName)) |
| 132 | + { |
| 133 | + roles = currentDeployment.Roles; |
| 134 | + } |
| 135 | + else |
| 136 | + { |
| 137 | + roles = new List<Role>(currentDeployment.Roles.Where(r => r.RoleName.Equals(this.RoleName, StringComparison.OrdinalIgnoreCase))); |
| 138 | + } |
137 | 139 |
|
138 |
| - foreach (var r in roles.Select(role => new PVM.RoleContext |
139 |
| - { |
140 |
| - InstanceCount = currentDeployment.RoleInstances.Count(ri => ri.RoleName.Equals(role.RoleName, StringComparison.OrdinalIgnoreCase)), |
141 |
| - RoleName = role.RoleName, |
142 |
| - OperationDescription = this.CommandRuntime.ToString(), |
143 |
| - OperationStatus = getDeploymentOperation.Status.ToString(), |
144 |
| - OperationId = getDeploymentOperation.Id, |
145 |
| - ServiceName = this.ServiceName, |
146 |
| - DeploymentID = currentDeployment.PrivateId |
147 |
| - })) |
148 |
| - { |
149 |
| - roleContexts.Add(r); |
150 |
| - } |
| 140 | + foreach (var r in roles.Select(role => new PVM.RoleContext |
| 141 | + { |
| 142 | + InstanceCount = currentDeployment.RoleInstances.Count(ri => ri.RoleName.Equals(role.RoleName, StringComparison.OrdinalIgnoreCase)), |
| 143 | + RoleName = role.RoleName, |
| 144 | + OperationDescription = this.CommandRuntime.ToString(), |
| 145 | + OperationStatus = getDeploymentOperation.Status.ToString(), |
| 146 | + OperationId = getDeploymentOperation.Id, |
| 147 | + ServiceName = this.ServiceName, |
| 148 | + DeploymentID = currentDeployment.PrivateId |
| 149 | + })) |
| 150 | + { |
| 151 | + roleContexts.Add(r); |
| 152 | + } |
151 | 153 |
|
152 |
| - WriteObject(roleContexts, true); |
| 154 | + WriteObject(roleContexts, true); |
| 155 | + } |
153 | 156 | }
|
154 | 157 | }
|
| 158 | + catch (Exception ex) |
| 159 | + { |
| 160 | + WriteExceptionError(ex); |
| 161 | + } |
155 | 162 | }
|
156 | 163 |
|
157 | 164 | private DeploymentGetResponse GetCurrentDeployment(out OperationStatusResponse operation)
|
|
0 commit comments