Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 7563 was 7563, checked in by spimming, 12 years ago

#1680:

  • Create deployment with local configuration file
  • New extension method to parallel upload a file to blob storage
  • Constants for deployment packages and configuration added
File size: 10.1 KB
RevLine 
[7299]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;
[7563]24using System.IO;
[7299]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
[7386]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      }
[7402]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;
[7386]54    }
55
[7545]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
[7299]66    public List<string> ListLocations(Subscription subscription) {
67      if (subscription == null) {
[7354]68        throw new ArgumentNullException("Subscription must not be null.", "subscription");
[7299]69      }
70      return ServiceManagementOperation.ListLocations(subscription.SubscriptionID, subscription.CertificateThumbprint);
71    }
[7339]72
73    public List<HostedService> ListHostedServices(Subscription subscription) {
74      if (subscription == null) {
[7354]75        throw new ArgumentNullException("Subscription must not be null.", "subscription");
[7339]76      }
[7402]77      List<HostedService> services = ServiceManagementOperation.ListHostedServices(subscription.SubscriptionID, subscription.CertificateThumbprint);
78      foreach (HostedService serv in services) {
79        serv.Subscription = subscription;
[7424]80        if (serv.Deployments != null) {
81          foreach (Deployment dep in serv.Deployments) {
82            dep.Subscription = subscription;
83          }
[7402]84        }
85      }
86      return services;
[7339]87    }
88
89    public List<AffinityGroup> ListAffinityGroups(Subscription subscription) {
90      if (subscription == null) {
[7354]91        throw new ArgumentNullException("Subscription must not be null.", "subscription");
[7339]92      }
93      return ServiceManagementOperation.ListAffinityGroups(subscription.SubscriptionID, subscription.CertificateThumbprint);
94    }
[7354]95
[7545]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
[7354]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
[7374]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    }
[7386]163
[7563]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
[7386]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 List<HostedService> DiscoverSlaveService(Subscription subscription) {
189      if (subscription == null) {
190        throw new ArgumentNullException("Subscription must not be null.", "subscription");
191      }
[7402]192      List<HostedService> services = ServiceManagementOperation.DiscoverSlaveService(subscription.SubscriptionID, subscription.CertificateThumbprint);
193      foreach (HostedService serv in services) {
194        serv.Subscription = subscription;
195        foreach (Deployment dep in serv.Deployments) {
196          dep.Subscription = subscription;
197        }
198      }
199      return services;
[7386]200    }
[7429]201
202    public string ChangeInstanceCount(Subscription subscription, string serviceName, string deploymentSlot, string roleName, int instanceCount) {
203      if (subscription == null) {
204        throw new ArgumentNullException("Subscription must not be null.", "subscription");
205      }
206      return ServiceManagementOperation.ChangeInstanceCount(subscription.SubscriptionID, subscription.CertificateThumbprint, serviceName, deploymentSlot, roleName, instanceCount);
207    }
[7299]208  }
209}
Note: See TracBrowser for help on using the repository browser.