Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/12/12 16:35:53 (13 years ago)
Author:
spimming
Message:

#1680:

  • Method to delete deployments
  • Method to poll for operation status added
  • Enum for operation status and struct for operation result added
Location:
branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Azure
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Azure/AzureProvider.cs

    r7563 r7597  
    186186    }
    187187
     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
    188202    public List<HostedService> DiscoverSlaveService(Subscription subscription) {
    189203      if (subscription == null) {
     
    206220      return ServiceManagementOperation.ChangeInstanceCount(subscription.SubscriptionID, subscription.CertificateThumbprint, serviceName, deploymentSlot, roleName, instanceCount);
    207221    }
     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    }
    208229  }
    209230}
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Azure/Constants.cs

    r7563 r7597  
    2020#endregion
    2121
     22using System;
     23using System.Net;
    2224using System.Xml.Linq;
    2325namespace HeuristicLab.Clients.Hive.CloudManager.Azure {
     
    114116    }
    115117
     118    public enum OperationStatus {
     119      InProgress,
     120      Failed,
     121      Succeeded,
     122      TimedOut
     123    }
     124
     125    #endregion
     126
     127    #region Structs
     128
     129    public struct OperationResult {
     130      public Constants.OperationStatus Status { get; set; }
     131      public HttpStatusCode StatusCode { get; set; }
     132      public TimeSpan RunningTime { get; set; }
     133      public string Code { get; set; }
     134      public string Message { get; set; }
     135    }
     136
    116137    #endregion
    117138  }
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Azure/IAzureProvider.cs

    r7563 r7597  
    4040    string CreateDeployment(Subscription subscription, string serviceName, string deploymentName, string deploymentSlot, string packageUrl, FileInfo configuration, string label, int instanceCount);
    4141    string DeleteHostedService(Subscription subscription, string serviceName);
     42    string DeleteDeployment(Subscription subscription, string serviceName, string deploymentName);
     43    Constants.OperationResult PollGetOperationStatus(Subscription subscription, string requestId, int pollIntervallSeconds, int timeoutSeconds);
    4244
    4345    List<HostedService> DiscoverSlaveService(Subscription subscription);
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Azure/ServiceManagementOperation.cs

    r7545 r7597  
    2525using System.Linq;
    2626using System.Net;
     27using System.Threading;
    2728using System.Xml.Linq;
    2829using HeuristicLab.Clients.Hive.CloudManager.Model;
     
    260261    }
    261262
     263    public static string DeleteDeployment(string subscriptionId, string thumbprint, string serviceName, string deploymentName) {
     264      string uri = string.Format(Constants.URISpecificDeploymentFormat, subscriptionId, serviceName, deploymentName);
     265      ServiceWebRequest operation = new ServiceWebRequest(thumbprint);
     266      string requestId = operation.Invoke(uri, Constants.HttpMethodDELETE);
     267      return requestId;
     268    }
     269
    262270    public static string ChangeInstanceCount(string subscriptionId, string thumbprint, string serviceName, string deploymentSlot, string roleName, int instanceCount) {
    263271      string requestId = string.Empty;
     
    270278    }
    271279
    272     public static string GetOperationStatus(string subscriptionId, string thumbprint, string requestId) {
     280    public static string GetOperationStatusString(string subscriptionId, string thumbprint, string requestId) {
     281      string status = GetOperationStatus(subscriptionId, thumbprint, requestId).Element(wa + "Status").Value;
     282      return status;
     283    }
     284
     285    public static XElement GetOperationStatus(string subscriptionId, string thumbprint, string requestId) {
    273286      string uri = string.Format(Constants.URIGetOperationStatusFormat, subscriptionId, requestId);
    274287      ServiceWebRequest operation = new ServiceWebRequest(thumbprint);
    275288      XDocument operationStatus = operation.Invoke(uri);
    276       string status = operationStatus.Element(wa + "Operation").Element(wa + "Status").Value;
    277       return status;
     289      return operationStatus.Element(wa + "Operation");
     290    }
     291
     292    public static Constants.OperationResult PollGetOperationStatus(string subscriptionId, string thumbprint, string requestId, int pollIntervallSeconds, int timeoutSeconds) {
     293      Constants.OperationResult result = new Constants.OperationResult();
     294      DateTime beginPollTime = DateTime.UtcNow;
     295      TimeSpan pollInterval = new TimeSpan(0, 0, pollIntervallSeconds);
     296      DateTime endPollTime = beginPollTime + new TimeSpan(0, 0, timeoutSeconds);
     297
     298      bool done = false;
     299      while (!done) {
     300        XElement operationStatus = GetOperationStatus(subscriptionId, thumbprint, requestId);
     301        result.RunningTime = DateTime.UtcNow - beginPollTime;
     302        try {
     303          result.Status = (Constants.OperationStatus)Enum.Parse(typeof(Constants.OperationStatus), operationStatus.Element(wa + "Status").Value);
     304        }
     305        catch (Exception ex) {
     306          throw new ApplicationException(string.Format("Get Operation Status {0} returned unexpected status: {1}{2}", requestId, Environment.NewLine, operationStatus.ToString(SaveOptions.OmitDuplicateNamespaces)));
     307        }
     308
     309        switch (result.Status) {
     310          case Constants.OperationStatus.InProgress:
     311            Thread.Sleep((int)pollInterval.TotalMilliseconds);
     312            break;
     313          case Constants.OperationStatus.Failed:
     314            result.StatusCode = (HttpStatusCode)Convert.ToInt32(operationStatus.Element(wa + "HttpStatusCode").Value);
     315            XElement error = operationStatus.Element(wa + "Error");
     316            result.Code = error.Element(wa + "Code").Value;
     317            result.Message = error.Element(wa + "Message").Value;
     318            done = true;
     319            break;
     320          case Constants.OperationStatus.Succeeded:
     321            result.StatusCode = (HttpStatusCode)Convert.ToInt32(operationStatus.Element(wa + "HttpStatusCode").Value);
     322            done = true;
     323            break;
     324        }
     325
     326        if (!done && DateTime.UtcNow > endPollTime) {
     327          result.Status = Constants.OperationStatus.TimedOut;
     328          done = true;
     329        }
     330      }
     331      return result;
    278332    }
    279333
Note: See TracChangeset for help on using the changeset viewer.