Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/06/12 15:50:21 (13 years ago)
Author:
spimming
Message:

#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
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

    r7545 r7563  
    2222using System;
    2323using System.Collections.Generic;
     24using System.IO;
    2425using HeuristicLab.Clients.Hive.CloudManager.Model;
    2526
     
    161162    }
    162163
     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
    163177    public string DeleteHostedService(Subscription subscription, string serviceName) {
    164178      if (subscription == null) {
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Azure/CloudBlobExtension.cs

    r7550 r7563  
    11
     2using System;
     3using System.Collections.Generic;
     4using System.IO;
     5using System.Text;
     6using System.Threading.Tasks;
    27using Microsoft.WindowsAzure.StorageClient;
    38namespace HeuristicLab.Clients.Hive.CloudManager.Azure {
    49  public static class CloudBlobExtension {
     10    private class BlockTransferDetail {
     11      public int StartPosition { get; set; }
     12      public int BytesToRead { get; set; }
     13      public string BlockId { get; set; }
     14    }
     15
    516    //check if a blob exists
    617    // see: http://stackoverflow.com/questions/2642919/checking-if-a-blob-exists-in-azure-storage
     
    1728        }
    1829      }
     30    }
     31
     32    public static void UploadParallel(this CloudBlockBlob blob, string filePath) {
     33      FileInfo file = new FileInfo(filePath);
     34      //CloudBlockBlob blob = blobContainer.GetBlockBlobReference(file.Name);
     35      blob.Properties.ContentType = "application/octet-stream";
     36
     37      // init
     38      int blockSize = 262144;
     39      long fileSize = file.Length;
     40      long leftToRead = fileSize;
     41      int startPosition = 0;
     42
     43      int blockCount = ((int)Math.Floor((double)(fileSize / blockSize))) + 1;
     44      BlockTransferDetail[] transferDetails = new BlockTransferDetail[blockCount];
     45      List<string> blockIdList = new List<string>();
     46
     47      // setup control array
     48      for (int j = 0; j < transferDetails.Length; j++) {
     49        int toRead = (int)(leftToRead > blockSize ? blockSize : leftToRead);
     50        string blockId = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(string.Format("BlockId{0}", j.ToString("0000000"))));
     51        transferDetails[j] = new BlockTransferDetail() { StartPosition = startPosition, BytesToRead = toRead, BlockId = blockId };
     52        if (toRead > 0) {
     53          blockIdList.Add(blockId);
     54        }
     55        startPosition += toRead;
     56        leftToRead -= toRead;
     57      }
     58
     59      // perform parallel upload
     60      var result = Parallel.For(0, transferDetails.Length, j => {
     61        using (FileStream fs = new FileStream(file.FullName, FileMode.Open, FileAccess.Read)) {
     62          byte[] buffer = new byte[transferDetails[j].BytesToRead];
     63          BinaryReader br = new BinaryReader(fs);
     64          fs.Seek(transferDetails[j].StartPosition, SeekOrigin.Begin);
     65          br.Read(buffer, 0, transferDetails[j].BytesToRead);
     66          if (buffer.Length > 0) {
     67            using (MemoryStream ms = new MemoryStream(buffer)) {
     68              blob.PutBlock(transferDetails[j].BlockId, ms, null);
     69            }
     70          }
     71        }
     72      });
     73      blob.PutBlockList(blockIdList);
    1974    }
    2075
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Azure/Constants.cs

    r7550 r7563  
    9292    public const string DeploymentPackageUrl = "https://hivestorage.blob.core.windows.net/hiveslave/HeuristicLab.Clients.Hive.Slave.Azure.cspkg";
    9393    public const string DeploymentConfigurationUrl = "https://hivestorage.blob.core.windows.net/hiveslave/ServiceConfiguration.Cloud.cscfg";
    94     public const string DeploymentConfigurationPath = "files/ServiceConfiguration.Cloud.cscfg";
     94
    9595    public const string DeploymentLabel = "HeuristicLab.Hive.Slave";
    9696    public const string DeploymentRoleName = "HeuristicLab.Clients.Hive.Slave.AzureClient";
     97
     98    public const string DeploymentConfigurationPath = "PackageFiles/ServiceConfiguration.Cloud.cscfg";
     99    public const string DeploymentPackagePathSmall = "PackageFiles/HeuristicLab.Clients.Hive.Slave.Azure.Small.cspkg";
     100    public const string DeploymentPackagePathMedium = "PackageFiles/HeuristicLab.Clients.Hive.Slave.Azure.Medium.cspkg";
     101    public const string DeploymentPackagePathLarge = "PackageFiles/HeuristicLab.Clients.Hive.Slave.Azure.Large.cspkg";
     102    public const string DeploymentPackagePathExtraLarge = "PackageFiles/HeuristicLab.Clients.Hive.Slave.Azure.ExtraLarge.cspkg";
    97103
    98104    #endregion
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Azure/IAzureProvider.cs

    r7545 r7563  
    2121
    2222using System.Collections.Generic;
     23using System.IO;
    2324using HeuristicLab.Clients.Hive.CloudManager.Model;
    2425
     
    3738    string CreateDeployment(Subscription subscription, string serviceName, string deploymentName, string deploymentSlot, string packageUrl, string configurationUrl, string label);
    3839    string CreateDeployment(Subscription subscription, string serviceName, string deploymentName, string deploymentSlot, string packageUrl, string configurationUrl, string label, int instanceCount);
     40    string CreateDeployment(Subscription subscription, string serviceName, string deploymentName, string deploymentSlot, string packageUrl, FileInfo configuration, string label, int instanceCount);
    3941    string DeleteHostedService(Subscription subscription, string serviceName);
    4042
Note: See TracChangeset for help on using the changeset viewer.