#region License Information /* HeuristicLab * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.IO; using HeuristicLab.Clients.Hive.CloudManager.Model; namespace HeuristicLab.Clients.Hive.CloudManager.Azure { public class AzureProvider : IAzureProvider { public Subscription GetSubscriptionInfo(string subscriptionId, string thumbprint) { if (subscriptionId.Length == 0) { throw new ArgumentException("Subscription Id is not valid.", "subscriptionId"); } if (thumbprint.Length == 0) { throw new ArgumentException("Certificate thumbprint is not valid.", "thumbprint"); } return ServiceManagementOperation.GetSubscriptionInfo(subscriptionId, thumbprint); } public HostedService GetHostedService(Subscription subscription, string serviceName) { if (subscription == null) { throw new ArgumentNullException("Subscription must not be null.", "subscription"); } if (serviceName.Length == 0) { throw new ArgumentException("Servicename is not valid.", "serviceName"); } HostedService service = ServiceManagementOperation.GetHostedServiceDetailed(subscription.SubscriptionID, subscription.CertificateThumbprint, serviceName); service.Subscription = subscription; foreach (Deployment dep in service.Deployments) { dep.Subscription = subscription; } return service; } public StorageServiceKeys GetStorageKeys(Subscription subscription, string serviceName) { if (subscription == null) { throw new ArgumentNullException("Subscription must not be null.", "subscription"); } if (serviceName.Length == 0) { throw new ArgumentException("Servicename is not valid.", "serviceName"); } return ServiceManagementOperation.GetStorageKeys(subscription.SubscriptionID, subscription.CertificateThumbprint, serviceName); } public List ListLocations(Subscription subscription) { if (subscription == null) { throw new ArgumentNullException("Subscription must not be null.", "subscription"); } return ServiceManagementOperation.ListLocations(subscription.SubscriptionID, subscription.CertificateThumbprint); } public List ListHostedServices(Subscription subscription) { if (subscription == null) { throw new ArgumentNullException("Subscription must not be null.", "subscription"); } List services = ServiceManagementOperation.ListHostedServices(subscription.SubscriptionID, subscription.CertificateThumbprint); foreach (HostedService serv in services) { serv.Subscription = subscription; if (serv.Deployments != null) { foreach (Deployment dep in serv.Deployments) { dep.Subscription = subscription; } } } return services; } public List ListAffinityGroups(Subscription subscription) { if (subscription == null) { throw new ArgumentNullException("Subscription must not be null.", "subscription"); } return ServiceManagementOperation.ListAffinityGroups(subscription.SubscriptionID, subscription.CertificateThumbprint); } public List ListStorageServices(Subscription subscription) { if (subscription == null) { throw new ArgumentNullException("Subscription must not be null.", "subscription"); } return ServiceManagementOperation.ListStorageServices(subscription.SubscriptionID, subscription.CertificateThumbprint); } public string CreateHostedService(Subscription subscription, string serviceName, string label, string description, AffinityGroup affinityGroup) { if (subscription == null) { throw new ArgumentNullException("Subscription must not be null.", "subscription"); } if (serviceName.Length == 0) { throw new ArgumentException("Servicename is not valid.", "serviceName"); } if (label.Length == 0) { throw new ArgumentException("Label is not valid.", "label"); } if (affinityGroup == null) { throw new ArgumentNullException("AffinityGroup must not be null.", "affinityGroup"); } return ServiceManagementOperation.CreateHostedServiceWithAffinityGroup(subscription.SubscriptionID, subscription.CertificateThumbprint, serviceName, label, description, affinityGroup.Name); } public string CreateHostedService(Subscription subscription, string serviceName, string label, string description, string location) { if (subscription == null) { throw new ArgumentNullException("Subscription must not be null.", "subscription"); } if (serviceName.Length == 0) { throw new ArgumentException("Servicename is not valid.", "serviceName"); } if (label.Length == 0) { throw new ArgumentException("Label is not valid.", "label"); } if (location.Length == 0) { throw new ArgumentException("Location is not valid.", "location"); } return ServiceManagementOperation.CreateHostedServiceWithLocation(subscription.SubscriptionID, subscription.CertificateThumbprint, serviceName, label, description, location); } public string AddCertificate(Subscription subscription, HostedService service, string certficateFilePath, string certificatePassword) { if (subscription == null) { throw new ArgumentNullException("Subscription must not be null.", "subscription"); } if (service == null) { throw new ArgumentNullException("HostedService must not be null.", "service"); } return ServiceManagementOperation.AddCertificate(subscription.SubscriptionID, subscription.CertificateThumbprint, service.ServiceName, certficateFilePath, certificatePassword); } public string CreateDeployment(Subscription subscription, string serviceName, string deploymentName, string deploymentSlot, string packageUrl, string configurationUrl, string label) { return CreateDeployment(subscription, serviceName, deploymentName, deploymentSlot, packageUrl, configurationUrl, label, 1); } public string CreateDeployment(Subscription subscription, string serviceName, string deploymentName, string deploymentSlot, string packageUrl, string configurationUrl, string label, int instanceCount) { if (subscription == null) { throw new ArgumentNullException("Subscription must not be null.", "subscription"); } if (instanceCount <= 0) { throw new ArgumentException("Instance count must be greater than zero.", "instanceCount"); } string configuration = ServiceManagementOperation.DownloadBlobAsString(new Uri(Constants.DeploymentConfigurationUrl)); return ServiceManagementOperation.CreateDeployment(subscription.SubscriptionID, subscription.CertificateThumbprint, serviceName, deploymentName, deploymentSlot, packageUrl, configuration, label, instanceCount); } public string CreateDeployment(Subscription subscription, string serviceName, string deploymentName, string deploymentSlot, string packageUrl, FileInfo configuration, string label, int instanceCount) { if (subscription == null) { throw new ArgumentNullException("Subscription must not be null.", "subscription"); } if (instanceCount <= 0) { throw new ArgumentException("Instance count must be greater than zero.", "instanceCount"); } string config = File.ReadAllText(configuration.FullName); return ServiceManagementOperation.CreateDeployment(subscription.SubscriptionID, subscription.CertificateThumbprint, serviceName, deploymentName, deploymentSlot, packageUrl, config, label, instanceCount); } public string DeleteHostedService(Subscription subscription, string serviceName) { if (subscription == null) { throw new ArgumentNullException("Subscription must not be null.", "subscription"); } if (serviceName.Length == 0) { throw new ArgumentException("Servicename is not valid.", "serviceName"); } return ServiceManagementOperation.DeleteHostedService(subscription.SubscriptionID, subscription.CertificateThumbprint, serviceName); } public string DeleteDeployment(Subscription subscription, string serviceName, string deploymentName) { if (subscription == null) { throw new ArgumentNullException("Subscription must not be null.", "subscription"); } if (serviceName.Length == 0) { throw new ArgumentException("Servicename is not valid.", "serviceName"); } if (deploymentName.Length == 0) { throw new ArgumentException("Deploymentname is not valid.", "deploymentName"); } return ServiceManagementOperation.DeleteDeployment(subscription.SubscriptionID, subscription.CertificateThumbprint, serviceName, deploymentName); } public List DiscoverSlaveService(Subscription subscription) { if (subscription == null) { throw new ArgumentNullException("Subscription must not be null.", "subscription"); } List services = ServiceManagementOperation.DiscoverSlaveService(subscription.SubscriptionID, subscription.CertificateThumbprint); foreach (HostedService serv in services) { serv.Subscription = subscription; foreach (Deployment dep in serv.Deployments) { dep.Subscription = subscription; } } return services; } public string ChangeInstanceCount(Subscription subscription, string serviceName, string deploymentSlot, string roleName, int instanceCount) { if (subscription == null) { throw new ArgumentNullException("Subscription must not be null.", "subscription"); } return ServiceManagementOperation.ChangeInstanceCount(subscription.SubscriptionID, subscription.CertificateThumbprint, serviceName, deploymentSlot, roleName, instanceCount); } public Constants.OperationResult PollGetOperationStatus(Subscription subscription, string requestId, int pollIntervallSeconds, int timeoutSeconds) { if (subscription == null) { throw new ArgumentNullException("Subscription must not be null.", "subscription"); } return ServiceManagementOperation.PollGetOperationStatus(subscription.SubscriptionID, subscription.CertificateThumbprint, requestId, pollIntervallSeconds, timeoutSeconds); } } }