Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7551


Ignore:
Timestamp:
03/05/12 17:13:58 (12 years ago)
Author:
spimming
Message:

#1680:

  • Validation for controls added
  • DTO for parameters (CreateDeploymentTask)
  • Initialize storage account and get reference for specified container
  • Make dialog fixed size
Location:
branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Views
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Views/AddAzureServiceDialog.Designer.cs

    r7547 r7551  
    5555      this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components);
    5656      this.gbStorageService = new System.Windows.Forms.GroupBox();
     57      this.cbCreateBlobIfNotExists = new System.Windows.Forms.CheckBox();
     58      this.tbBlobContainer = new System.Windows.Forms.TextBox();
     59      this.label11 = new System.Windows.Forms.Label();
     60      this.cmbStorageServices = new System.Windows.Forms.ComboBox();
    5761      this.label8 = new System.Windows.Forms.Label();
    58       this.comboBox1 = new System.Windows.Forms.ComboBox();
    59       this.label11 = new System.Windows.Forms.Label();
    60       this.tbBlobContainer = new System.Windows.Forms.TextBox();
    61       this.cbCreateBlobIfNotExists = new System.Windows.Forms.CheckBox();
    6262      this.rbVMSizeMedium = new System.Windows.Forms.RadioButton();
    6363      this.rbVMSizeSmall = new System.Windows.Forms.RadioButton();
     
    108108      this.cmbChooseHostedService.Size = new System.Drawing.Size(486, 21);
    109109      this.cmbChooseHostedService.TabIndex = 6;
     110      this.cmbChooseHostedService.Validating += new System.ComponentModel.CancelEventHandler(this.cmbChooseHostedService_Validating);
    110111      //
    111112      // gbNewHostedService
     
    341342      this.gbStorageService.Controls.Add(this.tbBlobContainer);
    342343      this.gbStorageService.Controls.Add(this.label11);
    343       this.gbStorageService.Controls.Add(this.comboBox1);
     344      this.gbStorageService.Controls.Add(this.cmbStorageServices);
    344345      this.gbStorageService.Controls.Add(this.label8);
    345346      this.gbStorageService.Location = new System.Drawing.Point(15, 267);
     
    350351      this.gbStorageService.Text = "Set storage service";
    351352      //
     353      // cbCreateBlobIfNotExists
     354      //
     355      this.cbCreateBlobIfNotExists.AutoSize = true;
     356      this.cbCreateBlobIfNotExists.Checked = true;
     357      this.cbCreateBlobIfNotExists.CheckState = System.Windows.Forms.CheckState.Checked;
     358      this.cbCreateBlobIfNotExists.Location = new System.Drawing.Point(9, 98);
     359      this.cbCreateBlobIfNotExists.Name = "cbCreateBlobIfNotExists";
     360      this.cbCreateBlobIfNotExists.Size = new System.Drawing.Size(182, 17);
     361      this.cbCreateBlobIfNotExists.TabIndex = 21;
     362      this.cbCreateBlobIfNotExists.Text = "Create blob container if not exists";
     363      this.cbCreateBlobIfNotExists.UseVisualStyleBackColor = true;
     364      //
     365      // tbBlobContainer
     366      //
     367      this.tbBlobContainer.Location = new System.Drawing.Point(9, 72);
     368      this.tbBlobContainer.Name = "tbBlobContainer";
     369      this.tbBlobContainer.Size = new System.Drawing.Size(452, 20);
     370      this.tbBlobContainer.TabIndex = 10;
     371      this.tbBlobContainer.Validating += new System.ComponentModel.CancelEventHandler(this.tbBlobContainer_Validating);
     372      //
     373      // label11
     374      //
     375      this.label11.AutoSize = true;
     376      this.label11.Location = new System.Drawing.Point(6, 56);
     377      this.label11.Name = "label11";
     378      this.label11.Size = new System.Drawing.Size(96, 13);
     379      this.label11.TabIndex = 11;
     380      this.label11.Text = "Set blob container:";
     381      //
     382      // cmbStorageServices
     383      //
     384      this.cmbStorageServices.FormattingEnabled = true;
     385      this.cmbStorageServices.Location = new System.Drawing.Point(9, 32);
     386      this.cmbStorageServices.Name = "cmbStorageServices";
     387      this.cmbStorageServices.Size = new System.Drawing.Size(452, 21);
     388      this.cmbStorageServices.TabIndex = 10;
     389      this.cmbStorageServices.Validating += new System.ComponentModel.CancelEventHandler(this.cmbStorageServices_Validating);
     390      //
    352391      // label8
    353392      //
     
    358397      this.label8.TabIndex = 10;
    359398      this.label8.Text = "Select storage account:";
    360       //
    361       // comboBox1
    362       //
    363       this.comboBox1.FormattingEnabled = true;
    364       this.comboBox1.Location = new System.Drawing.Point(9, 32);
    365       this.comboBox1.Name = "comboBox1";
    366       this.comboBox1.Size = new System.Drawing.Size(452, 21);
    367       this.comboBox1.TabIndex = 10;
    368       //
    369       // label11
    370       //
    371       this.label11.AutoSize = true;
    372       this.label11.Location = new System.Drawing.Point(6, 56);
    373       this.label11.Name = "label11";
    374       this.label11.Size = new System.Drawing.Size(96, 13);
    375       this.label11.TabIndex = 11;
    376       this.label11.Text = "Set blob container:";
    377       //
    378       // tbBlobContainer
    379       //
    380       this.tbBlobContainer.Location = new System.Drawing.Point(9, 72);
    381       this.tbBlobContainer.Name = "tbBlobContainer";
    382       this.tbBlobContainer.Size = new System.Drawing.Size(452, 20);
    383       this.tbBlobContainer.TabIndex = 10;
    384       //
    385       // cbCreateBlobIfNotExists
    386       //
    387       this.cbCreateBlobIfNotExists.AutoSize = true;
    388       this.cbCreateBlobIfNotExists.Location = new System.Drawing.Point(9, 98);
    389       this.cbCreateBlobIfNotExists.Name = "cbCreateBlobIfNotExists";
    390       this.cbCreateBlobIfNotExists.Size = new System.Drawing.Size(182, 17);
    391       this.cbCreateBlobIfNotExists.TabIndex = 21;
    392       this.cbCreateBlobIfNotExists.Text = "Create blob container if not exists";
    393       this.cbCreateBlobIfNotExists.UseVisualStyleBackColor = true;
    394399      //
    395400      // rbVMSizeMedium
     
    490495      this.Controls.Add(this.cmbChooseSubscription);
    491496      this.Controls.Add(this.label1);
     497      this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
    492498      this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
     499      this.MaximizeBox = false;
     500      this.MinimizeBox = false;
    493501      this.Name = "AddAzureServiceDialog";
    494502      this.Text = "Create New Azure Slave";
     
    545553    private System.Windows.Forms.TextBox tbBlobContainer;
    546554    private System.Windows.Forms.Label label11;
    547     private System.Windows.Forms.ComboBox comboBox1;
     555    private System.Windows.Forms.ComboBox cmbStorageServices;
    548556    private System.Windows.Forms.Label label8;
    549557    private System.Windows.Forms.ToolTip toolTip;
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Views/AddAzureServiceDialog.cs

    r7429 r7551  
    77using HeuristicLab.Clients.Hive.CloudManager.Model;
    88using HeuristicLab.Core;
     9using Microsoft.WindowsAzure;
     10using Microsoft.WindowsAzure.StorageClient;
    911
    1012namespace HeuristicLab.Clients.Hive.CloudManager.Views {
     
    1416    private BindingList<string> locations;
    1517    private BindingList<AffinityGroup> affinityGroups;
     18    private BindingList<StorageService> storageServices;
    1619
    1720    private BackgroundWorker workerUpdate;
     
    3437      this.locations = new BindingList<string>();
    3538      this.affinityGroups = new BindingList<AffinityGroup>();
     39      this.storageServices = new BindingList<StorageService>();
    3640
    3741      SetLookupBinding(cmbLocation, locations, "", "");
     
    3943      SetLookupBinding(cmbChooseHostedService, hostedServices, "ServiceName", "ServiceName");
    4044      SetLookupBinding(cmbChooseSubscription, subscriptions, "SubscriptionName", "SubscriptionID");
     45      SetLookupBinding(cmbStorageServices, storageServices, "ServiceName", "Url");
    4146
    4247      if (!cbNewHostedService.Checked) {
     
    5257
    5358      workerCreate = new BackgroundWorker();
    54       workerCreate.DoWork += new DoWorkEventHandler(CreateDoploymentTask);
     59      workerCreate.DoWork += new DoWorkEventHandler(CreateDeploymentTask);
    5560      workerCreate.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CreateDeploymentCompleted);
    5661
     
    187192          hostedService.HostedServiceProperties = properties;
    188193
    189           var parameters = Tuple.Create<Subscription, bool, bool, string, string, HostedService, int>(sub, newHostedServiceChecked, regionChecked, certificateFile, certificatePassword, hostedService, instanceCount);
     194          //var parameters1 = Tuple.Create<Subscription, bool, bool, string, string, HostedService, int>
     195          //  (sub, newHostedServiceChecked, regionChecked, certificateFile, certificatePassword, hostedService, instanceCount);
     196          CreateDeploymentData parameters = new CreateDeploymentData();
     197          parameters.Subscription = sub;
     198          parameters.CreateNewHosteService = newHostedServiceChecked;
     199          parameters.UseRegion = regionChecked;
     200          parameters.CertificateFilePath = certificateFile;
     201          parameters.CertificatePassword = certificatePassword;
     202          parameters.HostedService = hostedService;
     203          parameters.InstanceCount = instanceCount;
     204          parameters.StorageService = (StorageService)cmbStorageServices.SelectedItem;
     205          parameters.BlobContainerName = tbBlobContainer.Text;
    190206
    191207          bwCompleted = false;
     
    206222        List<string> locs = CloudManagerClient.Instance.AzureProvider.ListLocations(item);
    207223        List<AffinityGroup> groups = CloudManagerClient.Instance.AzureProvider.ListAffinityGroups(item);
     224        List<StorageService> storage = CloudManagerClient.Instance.AzureProvider.ListStorageServices(item);
    208225
    209226        this.Invoke((MethodInvoker)delegate { UpdateSubscriptionItem(subscriptions, item); });
     
    211228        this.Invoke((MethodInvoker)delegate { UpdateBindingList<string>(locations, locs); });
    212229        this.Invoke((MethodInvoker)delegate { UpdateBindingList<AffinityGroup>(affinityGroups, groups); });
     230        this.Invoke((MethodInvoker)delegate { UpdateBindingList<StorageService>(storageServices, storage); });
    213231      }
    214232      catch (Exception ex) {
     
    226244    }
    227245
    228     private void CreateDoploymentTask(object sender, DoWorkEventArgs e) {
     246    private void CreateDeploymentTask(object sender, DoWorkEventArgs e) {
    229247      bool errorOccured = false;
    230       Tuple<Subscription, bool, bool, string, string, HostedService, int> parameters = (Tuple<Subscription, bool, bool, string, string, HostedService, int>)e.Argument;
    231 
    232       Subscription sub = parameters.Item1;
    233       bool newHostedServiceChecked = parameters.Item2;
    234       bool regionChecked = parameters.Item3;
    235       string certFile = parameters.Item4;
    236       string certPw = parameters.Item5;
    237       HostedService hostedService = parameters.Item6;
    238       int instanceCount = parameters.Item7;
     248      CreateDeploymentData parameters = (CreateDeploymentData)e.Argument;
     249
     250      Subscription sub = parameters.Subscription;
     251      bool newHostedServiceChecked = parameters.CreateNewHosteService;
     252      bool regionChecked = parameters.UseRegion;
     253      string certFile = parameters.CertificateFilePath;
     254      string certPw = parameters.CertificatePassword;
     255      HostedService hostedService = parameters.HostedService;
     256      int instanceCount = parameters.InstanceCount;
     257      StorageService storageService = parameters.StorageService;
     258      string blobContainerName = parameters.BlobContainerName;
     259      bool createContainerIfNotExists = parameters.CreateContainerIfNotExists;
     260
     261      CloudStorageAccount storageAccount;
     262      CloudBlobClient blobClient;
     263      CloudBlobContainer blobContainer;
     264
     265      // STEP 1 - Initialize storage account
     266      try {
     267        // get access key to storage service
     268        StorageServiceKeys keys = CloudManagerClient.Instance.AzureProvider.GetStorageKeys(sub, storageService.ServiceName);
     269        storageAccount = CloudStorageAccount.Parse(string.Format(Constants.StorageServiceConnectionFormat, storageService.ServiceName, keys.Primary));
     270        blobClient = storageAccount.CreateCloudBlobClient();
     271        blobContainer = blobClient.GetContainerReference(blobContainerName);
     272        if (createContainerIfNotExists) {
     273          blobContainer.CreateIfNotExist();
     274        } else {
     275          if (!blobContainer.Exists()) {
     276            throw new ApplicationException("Specified blob container doesn't exist.");
     277          }
     278        }
     279      }
     280      catch (Exception ex) {
     281        errorOccured = true;
     282        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     283      }
     284
    239285
    240286      // STEP 1 - Create Hosted Service
    241287      try {
    242         if (newHostedServiceChecked) {
     288        if ((!errorOccured) && (newHostedServiceChecked)) {
    243289          if (regionChecked) {
    244290            CloudManagerClient.Instance.AzureProvider.CreateHostedService(sub, hostedService.ServiceName, hostedService.HostedServiceProperties.Label, hostedService.HostedServiceProperties.Description, hostedService.HostedServiceProperties.Location);
     
    337383    }
    338384
     385    private bool isValidStorageContainerName(string name) {
     386      string regexString = @"[a-z0-9]+[a-z0-9-]{0,61}[a-z0-9]+";  //TODO
     387      Regex regex = new Regex(regexString);
     388      if (regex.IsMatch(name)) {
     389        return true;
     390      } else {
     391        return false;
     392      }
     393    }
     394
    339395    private void tbInstanceCount_Validating(object sender, CancelEventArgs e) {
    340396      if (!isValidInstanceCount(tbInstanceCount.Text)) {
     
    363419      }
    364420    }
     421
     422    private void tbBlobContainer_Validating(object sender, CancelEventArgs e) {
     423      string name = tbBlobContainer.Text.Trim();
     424      if (name == string.Empty) {
     425        errorProvider.SetError(tbBlobContainer, "A name is required for the blob container.");
     426        e.Cancel = true;
     427      } else if (!isValidStorageContainerName(name)) {
     428        errorProvider.SetError(tbBlobContainer, "A blob container name must be between 1 and 63 " +
     429                                              "characters long, and be composed of lowercase letters, numbers " +
     430                                              "and hyphens. Hyphens shouldn't be first or last letter.");
     431        e.Cancel = true;
     432      } else {
     433        errorProvider.SetError(tbBlobContainer, "");
     434      }
     435    }
     436
     437    private void cmbChooseHostedService_Validating(object sender, CancelEventArgs e) {
     438      if ((!cbNewHostedService.Checked) && (cmbChooseHostedService.SelectedItem == null)) {
     439        errorProvider.SetError(cmbChooseHostedService, "A hoste service is required.");
     440        e.Cancel = true;
     441      } else {
     442        errorProvider.SetError(cmbChooseHostedService, "");
     443      }
     444    }
     445
     446    private void cmbStorageServices_Validating(object sender, CancelEventArgs e) {
     447      if (cmbStorageServices.SelectedItem == null) {
     448        errorProvider.SetError(cmbStorageServices, "A storage service is required.");
     449        e.Cancel = true;
     450      } else {
     451        errorProvider.SetError(cmbStorageServices, "");
     452      }
     453    }
     454
     455    private class CreateDeploymentData {
     456      public Subscription Subscription { get; set; }
     457      public bool CreateNewHosteService { get; set; }
     458      public bool UseRegion { get; set; }
     459      public string CertificateFilePath { get; set; }
     460      public string CertificatePassword { get; set; }
     461      public HostedService HostedService { get; set; }
     462      public int InstanceCount { get; set; }
     463      public StorageService StorageService { get; set; }
     464      public string BlobContainerName { get; set; }
     465      public bool CreateContainerIfNotExists { get; set; }
     466    }
    365467  }
    366468}
Note: See TracChangeset for help on using the changeset viewer.