Changeset 7326 for branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Azure/ServiceManagementOperation.cs
- Timestamp:
- 01/13/12 16:01:39 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Azure/ServiceManagementOperation.cs
r7299 r7326 72 72 } 73 73 74 public static List<AffinityGroup> ListAffinityGroups(string subscriptionId, string thumbprint) { 75 string uri = String.Format(Constants.URIAffinityGroupFormat, subscriptionId); 76 ServiceWebRequest operation = new ServiceWebRequest(thumbprint); 77 XDocument response = operation.Invoke(uri); 78 List<AffinityGroup> result = null; 79 if (response.Root.HasElements) { 80 result = (from s in response.Elements() 81 select new AffinityGroup() { 82 Name = s.Descendants(wa + "Name").Single().Value, 83 Label = Utils.ConvertFromBase64String(s.Descendants(wa + "Label").Single().Value), 84 Description = s.Descendants(wa + "Description").Single().Value, 85 Location = s.Descendants(wa + "Location").Single().Value 86 }).ToList(); 87 } 88 return result; 89 } 90 91 public static List<HostedService> ListHostedServices(string subscriptionId, string thumbprint) { 92 string uri = String.Format(Constants.URIHostedServiceFormat, subscriptionId); 93 ServiceWebRequest operation = new ServiceWebRequest(thumbprint); 94 XDocument response = operation.Invoke(uri); 95 List<HostedService> result = null; 96 if (response.Root.HasElements) { 97 98 result = (from s in response.Elements() 99 select new HostedService() { 100 ServiceName = s.Descendants(wa + "ServiceName").Single().Value, 101 Url = s.Descendants(wa + "Url").Single().Value 102 }).ToList(); 103 } 104 105 if (result != null) 106 return result; 107 else 108 return new List<HostedService>(); 109 } 110 111 public static HostedService GetHostedService(string subscriptionId, string thumbprint, string serviceName) { 112 string uri = String.Format(Constants.URISpecificHostedServiceFormat, subscriptionId, serviceName); 113 ServiceWebRequest operation = new ServiceWebRequest(thumbprint); 114 XDocument response = operation.Invoke(uri); 115 HostedService service = new HostedService(); 116 service.ServiceName = response.Descendants(wa + "ServiceName").Single().Value; 117 service.Url = response.Descendants(wa + "Url").Single().Value; 118 return service; 119 } 120 121 public static HostedService GetHostedServiceDetailed(string subscriptionId, string thumbprint, string serviceName) { 122 string uri = String.Format(Constants.URISpecificHostedServiceFormat + "?embed-detail=true", subscriptionId, serviceName); 123 ServiceWebRequest operation = new ServiceWebRequest(thumbprint); 124 XDocument response = operation.Invoke(uri); 125 HostedService service = new HostedService(); 126 service.ServiceName = response.Descendants(wa + "ServiceName").Single().Value; 127 service.Url = response.Descendants(wa + "Url").First().Value; 128 if (response.Root.Elements(wa + "HostedServiceProperties").Any()) { 129 XElement xHostedServiceProperties = response.Descendants(wa + "HostedServiceProperties").Single(); 130 string loc = string.Empty, affgroup = string.Empty; 131 if (xHostedServiceProperties.HasElements) { 132 string desc = xHostedServiceProperties.Descendants(wa + "Description").Single().Value; 133 if (xHostedServiceProperties.Descendants(wa + "Location").Any()) { 134 loc = xHostedServiceProperties.Descendants(wa + "Location").Single().Value; 135 } else { 136 affgroup = xHostedServiceProperties.Descendants(wa + "AffinityGroup").Single().Value; 137 } 138 string lbl = Utils.ConvertFromBase64String(xHostedServiceProperties.Descendants(wa + "Label").Single().Value); 139 HostedServiceProperties props = new HostedServiceProperties() { 140 Description = desc, 141 Location = loc, 142 AffinityGroup = affgroup, 143 Label = lbl 144 }; 145 service.HostedServiceProperties = props; 146 } 147 } 148 149 if (response.Root.Elements(wa + "Deployments").Any()) { 150 XElement xDeployments = response.Descendants(wa + "Deployments").Single(); 151 if (xDeployments.HasElements) { 152 IEnumerable<Deployment> deps = (from s in xDeployments.Elements() 153 select GetDeploymentFromXml(s)).ToList(); 154 service.Deployments = new List<Deployment>(deps); 155 } else { 156 service.Deployments = new List<Deployment>(); 157 } 158 } 159 160 return service; 161 } 162 163 private static Deployment GetDeploymentFromXml(XElement xDeployment) { 164 Deployment deployment = new Deployment(); 165 deployment.Name = xDeployment.Descendants(wa + "Name").Single().Value; 166 deployment.DeploymentSlot = xDeployment.Descendants(wa + "DeploymentSlot").Single().Value; 167 deployment.PrivateID = xDeployment.Descendants(wa + "PrivateID").Single().Value; 168 deployment.Status = xDeployment.Descendants(wa + "Status").Single().Value; 169 deployment.Label = Utils.ConvertFromBase64String(xDeployment.Descendants(wa + "Label").Single().Value); 170 if (xDeployment.Descendants(wa + "Url").Any()) { 171 deployment.Url = xDeployment.Descendants(wa + "Url").Single().Value; 172 } 173 deployment.Configuration = Utils.ConvertFromBase64String(xDeployment.Descendants(wa + "Configuration").Single().Value); 174 175 XElement xRoleInstanceList = xDeployment.Descendants(wa + "RoleInstanceList").Single(); 176 if (xRoleInstanceList.HasElements) { 177 IEnumerable<RoleInstance> instances = (from s in xRoleInstanceList.Elements() 178 select new RoleInstance() { 179 RoleName = s.Descendants(wa + "RoleName").Single().Value, 180 InstanceName = s.Descendants(wa + "InstanceName").Single().Value, 181 InstanceStatus = s.Descendants(wa + "InstanceStatus").Single().Value 182 }).ToList(); 183 deployment.RoleInstanceList = new List<RoleInstance>(instances); 184 } 185 if (xDeployment.Descendants(wa + "RoleList").Any()) { 186 XElement xRoleList = xDeployment.Descendants(wa + "RoleList").Single(); 187 if (xRoleList.HasElements) { 188 189 IEnumerable<Role> roles = (from s in xRoleList.Elements() 190 select new Role() { 191 RoleName = s.Descendants(wa + "RoleName").Single().Value, 192 OsVersion = s.Descendants(wa + "OsVersion").Single().Value 193 }).ToList(); 194 deployment.RoleList = new List<Role>(roles); 195 } 196 } 197 198 if (xDeployment.Descendants(wa + "UpgradeDomainCount").Any()) { 199 deployment.UpgradeDomainCount = Convert.ToInt32(xDeployment.Descendants(wa + "UpgradeDomainCount").Single().Value); 200 } 201 202 if (xDeployment.Elements("UpgradeStatus").Any()) { 203 XElement xUpgradeStatus = xDeployment.Descendants(wa + "UpgradeStatus").Single(); 204 if (xUpgradeStatus.HasElements) { 205 UpgradeStatus upgradestatus = new UpgradeStatus() { 206 UpgradeType = xUpgradeStatus.Descendants(wa + "RoleName").Single().Value, 207 CurrentUpgradeDomain = Convert.ToInt32(xUpgradeStatus.Descendants(wa + "RoleName").Single().Value), 208 CurrentUpgradeDomainState = xUpgradeStatus.Descendants(wa + "RoleName").Single().Value 209 }; 210 deployment.UpgradeStatus = upgradestatus; 211 } 212 } 213 return deployment; 214 } 215 216 217 74 218 #endregion 75 219
Note: See TracChangeset
for help on using the changeset viewer.