Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Azure/AzureProvider.cs @ 14517

Last change on this file since 14517 was 7597, checked in by spimming, 13 years ago

#1680:

  • Method to delete deployments
  • Method to poll for operation status added
  • Enum for operation status and struct for operation result added
File size: 11.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.IO;
25using HeuristicLab.Clients.Hive.CloudManager.Model;
26
27namespace HeuristicLab.Clients.Hive.CloudManager.Azure {
28  public class AzureProvider : IAzureProvider {
29
30    public Subscription GetSubscriptionInfo(string subscriptionId, string thumbprint) {
31      if (subscriptionId.Length == 0) {
32        throw new ArgumentException("Subscription Id is not valid.", "subscriptionId");
33      }
34
35      if (thumbprint.Length == 0) {
36        throw new ArgumentException("Certificate thumbprint is not valid.", "thumbprint");
37      }
38      return ServiceManagementOperation.GetSubscriptionInfo(subscriptionId, thumbprint);
39    }
40
41    public HostedService GetHostedService(Subscription subscription, string serviceName) {
42      if (subscription == null) {
43        throw new ArgumentNullException("Subscription must not be null.", "subscription");
44      }
45      if (serviceName.Length == 0) {
46        throw new ArgumentException("Servicename is not valid.", "serviceName");
47      }
48      HostedService service = ServiceManagementOperation.GetHostedServiceDetailed(subscription.SubscriptionID, subscription.CertificateThumbprint, serviceName);
49      service.Subscription = subscription;
50      foreach (Deployment dep in service.Deployments) {
51        dep.Subscription = subscription;
52      }
53      return service;
54    }
55
56    public StorageServiceKeys GetStorageKeys(Subscription subscription, string serviceName) {
57      if (subscription == null) {
58        throw new ArgumentNullException("Subscription must not be null.", "subscription");
59      }
60      if (serviceName.Length == 0) {
61        throw new ArgumentException("Servicename is not valid.", "serviceName");
62      }
63      return ServiceManagementOperation.GetStorageKeys(subscription.SubscriptionID, subscription.CertificateThumbprint, serviceName);
64    }
65
66    public List<string> ListLocations(Subscription subscription) {
67      if (subscription == null) {
68        throw new ArgumentNullException("Subscription must not be null.", "subscription");
69      }
70      return ServiceManagementOperation.ListLocations(subscription.SubscriptionID, subscription.CertificateThumbprint);
71    }
72
73    public List<HostedService> ListHostedServices(Subscription subscription) {
74      if (subscription == null) {
75        throw new ArgumentNullException("Subscription must not be null.", "subscription");
76      }
77      List<HostedService> services = ServiceManagementOperation.ListHostedServices(subscription.SubscriptionID, subscription.CertificateThumbprint);
78      foreach (HostedService serv in services) {
79        serv.Subscription = subscription;
80        if (serv.Deployments != null) {
81          foreach (Deployment dep in serv.Deployments) {
82            dep.Subscription = subscription;
83          }
84        }
85      }
86      return services;
87    }
88
89    public List<AffinityGroup> ListAffinityGroups(Subscription subscription) {
90      if (subscription == null) {
91        throw new ArgumentNullException("Subscription must not be null.", "subscription");
92      }
93      return ServiceManagementOperation.ListAffinityGroups(subscription.SubscriptionID, subscription.CertificateThumbprint);
94    }
95
96    public List<StorageService> ListStorageServices(Subscription subscription) {
97      if (subscription == null) {
98        throw new ArgumentNullException("Subscription must not be null.", "subscription");
99      }
100      return ServiceManagementOperation.ListStorageServices(subscription.SubscriptionID, subscription.CertificateThumbprint);
101    }
102
103    public string CreateHostedService(Subscription subscription, string serviceName, string label, string description, AffinityGroup affinityGroup) {
104      if (subscription == null) {
105        throw new ArgumentNullException("Subscription must not be null.", "subscription");
106      }
107      if (serviceName.Length == 0) {
108        throw new ArgumentException("Servicename is not valid.", "serviceName");
109      }
110      if (label.Length == 0) {
111        throw new ArgumentException("Label is not valid.", "label");
112      }
113      if (affinityGroup == null) {
114        throw new ArgumentNullException("AffinityGroup must not be null.", "affinityGroup");
115      }
116
117      return ServiceManagementOperation.CreateHostedServiceWithAffinityGroup(subscription.SubscriptionID, subscription.CertificateThumbprint, serviceName, label, description, affinityGroup.Name);
118    }
119
120    public string CreateHostedService(Subscription subscription, string serviceName, string label, string description, string location) {
121      if (subscription == null) {
122        throw new ArgumentNullException("Subscription must not be null.", "subscription");
123      }
124      if (serviceName.Length == 0) {
125        throw new ArgumentException("Servicename is not valid.", "serviceName");
126      }
127      if (label.Length == 0) {
128        throw new ArgumentException("Label is not valid.", "label");
129      }
130      if (location.Length == 0) {
131        throw new ArgumentException("Location is not valid.", "location");
132      }
133
134      return ServiceManagementOperation.CreateHostedServiceWithLocation(subscription.SubscriptionID, subscription.CertificateThumbprint, serviceName, label, description, location);
135    }
136
137    public string AddCertificate(Subscription subscription, HostedService service, string certficateFilePath, string certificatePassword) {
138      if (subscription == null) {
139        throw new ArgumentNullException("Subscription must not be null.", "subscription");
140      }
141      if (service == null) {
142        throw new ArgumentNullException("HostedService must not be null.", "service");
143      }
144      return ServiceManagementOperation.AddCertificate(subscription.SubscriptionID, subscription.CertificateThumbprint, service.ServiceName, certficateFilePath, certificatePassword);
145    }
146
147    public string CreateDeployment(Subscription subscription, string serviceName, string deploymentName, string deploymentSlot, string packageUrl, string configurationUrl, string label) {
148      return CreateDeployment(subscription, serviceName, deploymentName, deploymentSlot, packageUrl, configurationUrl, label, 1);
149    }
150
151    public string CreateDeployment(Subscription subscription, string serviceName, string deploymentName, string deploymentSlot, string packageUrl, string configurationUrl, string label, int instanceCount) {
152      if (subscription == null) {
153        throw new ArgumentNullException("Subscription must not be null.", "subscription");
154      }
155      if (instanceCount <= 0) {
156        throw new ArgumentException("Instance count must be greater than zero.", "instanceCount");
157      }
158
159      string configuration = ServiceManagementOperation.DownloadBlobAsString(new Uri(Constants.DeploymentConfigurationUrl));
160      return ServiceManagementOperation.CreateDeployment(subscription.SubscriptionID, subscription.CertificateThumbprint, serviceName, deploymentName, deploymentSlot, packageUrl, configuration, label, instanceCount);
161
162    }
163
164    public string CreateDeployment(Subscription subscription, string serviceName, string deploymentName, string deploymentSlot, string packageUrl, FileInfo configuration, string label, int instanceCount) {
165      if (subscription == null) {
166        throw new ArgumentNullException("Subscription must not be null.", "subscription");
167      }
168      if (instanceCount <= 0) {
169        throw new ArgumentException("Instance count must be greater than zero.", "instanceCount");
170      }
171
172      string config = File.ReadAllText(configuration.FullName);
173      return ServiceManagementOperation.CreateDeployment(subscription.SubscriptionID, subscription.CertificateThumbprint, serviceName, deploymentName, deploymentSlot, packageUrl, config, label, instanceCount);
174
175    }
176
177    public string DeleteHostedService(Subscription subscription, string serviceName) {
178      if (subscription == null) {
179        throw new ArgumentNullException("Subscription must not be null.", "subscription");
180      }
181      if (serviceName.Length == 0) {
182        throw new ArgumentException("Servicename is not valid.", "serviceName");
183      }
184
185      return ServiceManagementOperation.DeleteHostedService(subscription.SubscriptionID, subscription.CertificateThumbprint, serviceName);
186    }
187
188    public string DeleteDeployment(Subscription subscription, string serviceName, string deploymentName) {
189      if (subscription == null) {
190        throw new ArgumentNullException("Subscription must not be null.", "subscription");
191      }
192      if (serviceName.Length == 0) {
193        throw new ArgumentException("Servicename is not valid.", "serviceName");
194      }
195      if (deploymentName.Length == 0) {
196        throw new ArgumentException("Deploymentname is not valid.", "deploymentName");
197      }
198
199      return ServiceManagementOperation.DeleteDeployment(subscription.SubscriptionID, subscription.CertificateThumbprint, serviceName, deploymentName);
200    }
201
202    public List<HostedService> DiscoverSlaveService(Subscription subscription) {
203      if (subscription == null) {
204        throw new ArgumentNullException("Subscription must not be null.", "subscription");
205      }
206      List<HostedService> services = ServiceManagementOperation.DiscoverSlaveService(subscription.SubscriptionID, subscription.CertificateThumbprint);
207      foreach (HostedService serv in services) {
208        serv.Subscription = subscription;
209        foreach (Deployment dep in serv.Deployments) {
210          dep.Subscription = subscription;
211        }
212      }
213      return services;
214    }
215
216    public string ChangeInstanceCount(Subscription subscription, string serviceName, string deploymentSlot, string roleName, int instanceCount) {
217      if (subscription == null) {
218        throw new ArgumentNullException("Subscription must not be null.", "subscription");
219      }
220      return ServiceManagementOperation.ChangeInstanceCount(subscription.SubscriptionID, subscription.CertificateThumbprint, serviceName, deploymentSlot, roleName, instanceCount);
221    }
222
223    public Constants.OperationResult PollGetOperationStatus(Subscription subscription, string requestId, int pollIntervallSeconds, int timeoutSeconds) {
224      if (subscription == null) {
225        throw new ArgumentNullException("Subscription must not be null.", "subscription");
226      }
227      return ServiceManagementOperation.PollGetOperationStatus(subscription.SubscriptionID, subscription.CertificateThumbprint, requestId, pollIntervallSeconds, timeoutSeconds);
228    }
229  }
230}
Note: See TracBrowser for help on using the repository browser.