Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/16/12 18:24:58 (13 years ago)
Author:
spimming
Message:

#1680:

  • List-Operations added to Interface and AzureProvider
  • AddCertificate- and AddAzureService-Dialog added
Location:
branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3
Files:
4 added
6 edited

Legend:

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

    r7299 r7339  
    4444      return ServiceManagementOperation.ListLocations(subscription.SubscriptionID, subscription.CertificateThumbprint);
    4545    }
     46
     47    public List<HostedService> ListHostedServices(Subscription subscription) {
     48      if (subscription == null) {
     49        throw new ArgumentException("Subscription must not be null.", "subscription");
     50      }
     51      return ServiceManagementOperation.ListHostedServices(subscription.SubscriptionID, subscription.CertificateThumbprint);
     52    }
     53
     54    public List<AffinityGroup> ListAffinityGroups(Subscription subscription) {
     55      if (subscription == null) {
     56        throw new ArgumentException("Subscription must not be null.", "subscription");
     57      }
     58      return ServiceManagementOperation.ListAffinityGroups(subscription.SubscriptionID, subscription.CertificateThumbprint);
     59    }
    4660  }
    4761}
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Azure/IAzureProvider.cs

    r7299 r7339  
    2727    Subscription GetSubscriptionInfo(string subscriptionId, string thumbprint);
    2828    List<string> ListLocations(Subscription subscription);
     29    List<HostedService> ListHostedServices(Subscription subscription);
     30    List<AffinityGroup> ListAffinityGroups(Subscription subscription);
     31
    2932  }
    3033}
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Azure/ServiceManagementOperation.cs

    r7326 r7339  
    161161    }
    162162
     163    public static Deployment GetDeployment(string subscriptionId, string thumbprint, string serviceName, string deploymentName) {
     164      string uri = String.Format(Constants.URISpecificDeploymentFormat, subscriptionId, serviceName, deploymentName);
     165      ServiceWebRequest operation = new ServiceWebRequest(thumbprint);
     166      XDocument response = operation.Invoke(uri);
     167      Deployment deployment = GetDeploymentFromXml(response.Root);
     168      return deployment;
     169    }
     170
     171    #endregion
     172
     173    #region Private Methods
     174
     175    private static int GetInstanceCount(XElement configuration, string roleName) {
     176      XElement instanceElement = (from s in configuration.Elements(sh + "Role")
     177                                  where s.Attribute("name").Value == roleName
     178                                  select s.Element(sh + "Instances")).First();
     179      int instanceCount = Convert.ToInt32(instanceElement.Attribute("count").Value);
     180      return instanceCount;
     181    }
     182
     183    private static void SetInstanceCount(XElement configuration, string roleName, int value) {
     184      XElement instanceElement = (from s in configuration.Elements(sh + "Role")
     185                                  where s.Attribute("name").Value == roleName
     186                                  select s.Element(sh + "Instances")).First();
     187      instanceElement.SetAttributeValue("count", value);
     188    }
     189
     190    private static string CreateHostedService(string subscriptionId, string thumbprint, string serviceName, string label, string description, string location, string affinityGroup) {
     191      string uri = string.Format(Constants.URIHostedServiceFormat, subscriptionId);
     192      XDocument payload = CreateHostedServicePayload(serviceName, label, description, location, affinityGroup);
     193      ServiceWebRequest operation = new ServiceWebRequest(thumbprint);
     194      string requestId = operation.Invoke(uri, payload);
     195      return requestId;
     196    }
     197
     198    private static XDocument CreateHostedServicePayload(string serviceName, string label, string description, string location, string affinityGroup) {
     199      string base64LabelName = Utils.ConvertToBase64String(label);
     200      XElement xServiceName = new XElement(wa + "ServiceName", serviceName);
     201      XElement xLabel = new XElement(wa + "Label", base64LabelName);
     202      XElement xDescription = new XElement(wa + "Description", description);
     203      XElement createHostedService = new XElement(wa + "CreateHostedService");
     204      createHostedService.Add(xServiceName);
     205      createHostedService.Add(xLabel);
     206      createHostedService.Add(xDescription);
     207
     208      if (location != String.Empty) {
     209        XElement xLocation = new XElement(wa + "Location", location);
     210        createHostedService.Add(xLocation);
     211      } else {
     212        XElement xAffinityGroup = new XElement(wa + "AffinityGroup", affinityGroup);
     213        createHostedService.Add(xAffinityGroup);
     214      }
     215
     216      XDocument payload = new XDocument();
     217      payload.Add(createHostedService);
     218      payload.Declaration = new XDeclaration("1.0", "UTF-8", "no");
     219
     220      return payload;
     221    }
     222
     223    private static XDocument CreateAddCertificatePayload(string certificateFilePath, string password) {
     224      XElement xData = new XElement(wa + "Data", Convert.ToBase64String(File.ReadAllBytes(certificateFilePath)));
     225      XElement xCertificateFormat = new XElement(wa + "CertificateFormat", "pfx");
     226      XElement xPassword = new XElement(wa + "Password", password);
     227
     228      XElement addcert = new XElement(wa + "CertificateFile");
     229      addcert.Add(xData);
     230      addcert.Add(xCertificateFormat);
     231      addcert.Add(xPassword);
     232
     233      XDocument payload = new XDocument();
     234      payload.Add(addcert);
     235      payload.Declaration = new XDeclaration("1.0", "UTF-8", "no");
     236
     237      return payload;
     238    }
     239
     240    private static XDocument CreateDeploymentPayload(string deploymentName, string packageUrl, string pathToConfigurationFile, string label) {
     241      string configurationFile = File.ReadAllText(pathToConfigurationFile);
     242      XElement xConfig = XElement.Parse(configurationFile);
     243      return CreateDeploymentPayload(deploymentName, packageUrl, xConfig, label);
     244    }
     245
     246    private static XDocument CreateDeploymentPayload(string deploymentName, string packageUrl, XElement configuration, string label) {
     247      string base64ConfigurationFile = Utils.ConvertToBase64String(configuration.ToString());
     248      string base64Label = Utils.ConvertToBase64String(label);
     249
     250      XElement xName = new XElement(wa + "Name", deploymentName);
     251      XElement xPackageUrl = new XElement(wa + "PackageUrl", packageUrl);
     252      XElement xLabel = new XElement(wa + "Label", base64Label);
     253      XElement xConfiguration = new XElement(wa + "Configuration", base64ConfigurationFile);
     254      XElement xStartDeployment = new XElement(wa + "StartDeployment", "true");
     255      XElement xTreatWarningsAsError = new XElement(wa + "TreatWarningsAsError", "false");
     256
     257      XElement createDeployment = new XElement(wa + "CreateDeployment");
     258      createDeployment.Add(xName);
     259      createDeployment.Add(xPackageUrl);
     260      createDeployment.Add(xLabel);
     261      createDeployment.Add(xConfiguration);
     262      createDeployment.Add(xStartDeployment);
     263      createDeployment.Add(xTreatWarningsAsError);
     264
     265      XDocument payload = new XDocument();
     266      payload.Add(createDeployment);
     267      payload.Declaration =
     268      new XDeclaration("1.0", "UTF-8", "no");
     269      return payload;
     270    }
     271
     272    private static XElement LoadConfiguration(String subscriptionId, String thumbprint, String serviceName, String deploymentSlot) {
     273      string uri = string.Format(Constants.URIDeploymentFormat, subscriptionId, serviceName, deploymentSlot);
     274      ServiceWebRequest operation = new ServiceWebRequest(thumbprint);
     275      XDocument deployment = operation.Invoke(uri);
     276      string base64Configuration = deployment.Element(wa + "Deployment").Element(wa + "Configuration").Value;
     277      string stringConfiguration = Utils.ConvertFromBase64String(base64Configuration);
     278      XElement configuration = XElement.Parse(stringConfiguration);
     279      return configuration;
     280    }
     281
     282    private static string SaveConfiguration(String subscriptionId, String thumbprint, String serviceName, String deploymentSlot, XElement configuration) {
     283      string uri = string.Format(Constants.URIDeploymentConfigurationFormat, subscriptionId, serviceName, deploymentSlot);
     284      XDocument payload = CreateConfigurationPayload(configuration);
     285      ServiceWebRequest operation = new ServiceWebRequest(thumbprint);
     286      string requestId = operation.Invoke(uri, payload);
     287      return requestId;
     288    }
     289
     290    private static XDocument CreateConfigurationPayload(XElement configuration) {
     291      string configurationString = configuration.ToString();
     292      string base64Configuration = Utils.ConvertToBase64String(configurationString);
     293
     294      XElement xConfiguration = new XElement(wa + "Configuration", base64Configuration);
     295      XElement xChangeConfiguration = new XElement(wa + "ChangeConfiguration", xConfiguration);
     296
     297      XDocument payload = new XDocument();
     298      payload.Add(xChangeConfiguration);
     299      payload.Declaration = new XDeclaration("1.0", "UTF-8", "no");
     300
     301      return payload;
     302    }
     303
     304    private static XDocument GetConfigurationFromDeployment(string subscriptionId, string thumbprint, string serviceName, string deploymentName) {
     305      Deployment deployment = GetDeployment(subscriptionId, thumbprint, serviceName, deploymentName);
     306      XDocument config = XDocument.Parse(deployment.Configuration);
     307      return config;
     308    }
     309
     310    private static bool ContainsRoleNameInConfiguration(XDocument configuration, string roleName) {
     311      if (configuration.Root.Name != sh + "ServiceConfiguration")
     312        throw new ArgumentException("No valid configuration", "configuration");
     313
     314
     315      IEnumerable<XElement> role = (from s in configuration.Root.Elements(sh + "Role")
     316                                    where s.Attribute("name").Value == roleName
     317                                    select s);
     318      return role.Count() > 0;
     319    }
     320
    163321    private static Deployment GetDeploymentFromXml(XElement xDeployment) {
    164322      Deployment deployment = new Deployment();
     
    214372    }
    215373
    216 
    217 
    218     #endregion
    219 
    220     #region Private Methods
    221 
    222     private static int GetInstanceCount(XElement configuration, string roleName) {
    223       XElement instanceElement = (from s in configuration.Elements(sh + "Role")
    224                                   where s.Attribute("name").Value == roleName
    225                                   select s.Element(sh + "Instances")).First();
    226       int instanceCount = Convert.ToInt32(instanceElement.Attribute("count").Value);
    227       return instanceCount;
    228     }
    229 
    230     private static void SetInstanceCount(XElement configuration, string roleName, int value) {
    231       XElement instanceElement = (from s in configuration.Elements(sh + "Role")
    232                                   where s.Attribute("name").Value == roleName
    233                                   select s.Element(sh + "Instances")).First();
    234       instanceElement.SetAttributeValue("count", value);
    235     }
    236 
    237     private static string CreateHostedService(string subscriptionId, string thumbprint, string serviceName, string label, string description, string location, string affinityGroup) {
    238       string uri = string.Format(Constants.URIHostedServiceFormat, subscriptionId);
    239       XDocument payload = CreateHostedServicePayload(serviceName, label, description, location, affinityGroup);
    240       ServiceWebRequest operation = new ServiceWebRequest(thumbprint);
    241       string requestId = operation.Invoke(uri, payload);
    242       return requestId;
    243     }
    244 
    245     private static XDocument CreateHostedServicePayload(string serviceName, string label, string description, string location, string affinityGroup) {
    246       string base64LabelName = Utils.ConvertToBase64String(label);
    247       XElement xServiceName = new XElement(wa + "ServiceName", serviceName);
    248       XElement xLabel = new XElement(wa + "Label", base64LabelName);
    249       XElement xDescription = new XElement(wa + "Description", description);
    250       XElement createHostedService = new XElement(wa + "CreateHostedService");
    251       createHostedService.Add(xServiceName);
    252       createHostedService.Add(xLabel);
    253       createHostedService.Add(xDescription);
    254 
    255       if (location != String.Empty) {
    256         XElement xLocation = new XElement(wa + "Location", location);
    257         createHostedService.Add(xLocation);
    258       } else {
    259         XElement xAffinityGroup = new XElement(wa + "AffinityGroup", affinityGroup);
    260         createHostedService.Add(xAffinityGroup);
    261       }
    262 
    263       XDocument payload = new XDocument();
    264       payload.Add(createHostedService);
    265       payload.Declaration = new XDeclaration("1.0", "UTF-8", "no");
    266 
    267       return payload;
    268     }
    269 
    270     private static XDocument CreateAddCertificatePayload(string certificateFilePath, string password) {
    271       XElement xData = new XElement(wa + "Data", Convert.ToBase64String(File.ReadAllBytes(certificateFilePath)));
    272       XElement xCertificateFormat = new XElement(wa + "CertificateFormat", "pfx");
    273       XElement xPassword = new XElement(wa + "Password", password);
    274 
    275       XElement addcert = new XElement(wa + "CertificateFile");
    276       addcert.Add(xData);
    277       addcert.Add(xCertificateFormat);
    278       addcert.Add(xPassword);
    279 
    280       XDocument payload = new XDocument();
    281       payload.Add(addcert);
    282       payload.Declaration = new XDeclaration("1.0", "UTF-8", "no");
    283 
    284       return payload;
    285     }
    286 
    287     private static XDocument CreateDeploymentPayload(string deploymentName, string packageUrl, string pathToConfigurationFile, string label) {
    288       string configurationFile = File.ReadAllText(pathToConfigurationFile);
    289       XElement xConfig = XElement.Parse(configurationFile);
    290       return CreateDeploymentPayload(deploymentName, packageUrl, xConfig, label);
    291     }
    292 
    293     private static XDocument CreateDeploymentPayload(string deploymentName, string packageUrl, XElement configuration, string label) {
    294       string base64ConfigurationFile = Utils.ConvertToBase64String(configuration.ToString());
    295       string base64Label = Utils.ConvertToBase64String(label);
    296 
    297       XElement xName = new XElement(wa + "Name", deploymentName);
    298       XElement xPackageUrl = new XElement(wa + "PackageUrl", packageUrl);
    299       XElement xLabel = new XElement(wa + "Label", base64Label);
    300       XElement xConfiguration = new XElement(wa + "Configuration", base64ConfigurationFile);
    301       XElement xStartDeployment = new XElement(wa + "StartDeployment", "true");
    302       XElement xTreatWarningsAsError = new XElement(wa + "TreatWarningsAsError", "false");
    303 
    304       XElement createDeployment = new XElement(wa + "CreateDeployment");
    305       createDeployment.Add(xName);
    306       createDeployment.Add(xPackageUrl);
    307       createDeployment.Add(xLabel);
    308       createDeployment.Add(xConfiguration);
    309       createDeployment.Add(xStartDeployment);
    310       createDeployment.Add(xTreatWarningsAsError);
    311 
    312       XDocument payload = new XDocument();
    313       payload.Add(createDeployment);
    314       payload.Declaration =
    315       new XDeclaration("1.0", "UTF-8", "no");
    316       return payload;
    317     }
    318 
    319     private static XElement LoadConfiguration(String subscriptionId, String thumbprint, String serviceName, String deploymentSlot) {
    320       string uri = string.Format(Constants.URIDeploymentFormat, subscriptionId, serviceName, deploymentSlot);
    321       ServiceWebRequest operation = new ServiceWebRequest(thumbprint);
    322       XDocument deployment = operation.Invoke(uri);
    323       string base64Configuration = deployment.Element(wa + "Deployment").Element(wa + "Configuration").Value;
    324       string stringConfiguration = Utils.ConvertFromBase64String(base64Configuration);
    325       XElement configuration = XElement.Parse(stringConfiguration);
    326       return configuration;
    327     }
    328 
    329     private static string SaveConfiguration(String subscriptionId, String thumbprint, String serviceName, String deploymentSlot, XElement configuration) {
    330       string uri = string.Format(Constants.URIDeploymentConfigurationFormat, subscriptionId, serviceName, deploymentSlot);
    331       XDocument payload = CreateConfigurationPayload(configuration);
    332       ServiceWebRequest operation = new ServiceWebRequest(thumbprint);
    333       string requestId = operation.Invoke(uri, payload);
    334       return requestId;
    335     }
    336 
    337     private static XDocument CreateConfigurationPayload(XElement configuration) {
    338       string configurationString = configuration.ToString();
    339       string base64Configuration = Utils.ConvertToBase64String(configurationString);
    340 
    341       XElement xConfiguration = new XElement(wa + "Configuration", base64Configuration);
    342       XElement xChangeConfiguration = new XElement(wa + "ChangeConfiguration", xConfiguration);
    343 
    344       XDocument payload = new XDocument();
    345       payload.Add(xChangeConfiguration);
    346       payload.Declaration = new XDeclaration("1.0", "UTF-8", "no");
    347 
    348       return payload;
    349     }
    350 
    351     private static XDocument GetConfigurationFromDeployment(string subscriptionId, string thumbprint, string serviceName, string deploymentName) {
    352       //Deployment deployment = GetDeployment(subscriptionId, thumbprint, serviceName, deploymentName);
    353       //XDocument config = XDocument.Parse(deployment.Configuration);
    354       return null;//config;
    355     }
    356 
    357     private static bool ContainsRoleNameInConfiguration(XDocument configuration, string roleName) {
    358       if (configuration.Root.Name != sh + "ServiceConfiguration")
    359         throw new ArgumentException("No valid configuration", "configuration");
    360 
    361 
    362       IEnumerable<XElement> role = (from s in configuration.Root.Elements(sh + "Role")
    363                                     where s.Attribute("name").Value == roleName
    364                                     select s);
    365       return role.Count() > 0;
    366     }
    367 
    368374    #endregion
    369375  }
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/HeuristicLab.Clients.Hive.CloudManager-3.3.csproj

    r7326 r7339  
    7676      <DependentUpon>Resources.resx</DependentUpon>
    7777    </Compile>
     78    <Compile Include="Views\AddAzureServiceDialog.cs">
     79      <SubType>Form</SubType>
     80    </Compile>
     81    <Compile Include="Views\AddAzureServiceDialog.Designer.cs">
     82      <DependentUpon>AddAzureServiceDialog.cs</DependentUpon>
     83    </Compile>
     84    <Compile Include="Views\AddCertificate.cs">
     85      <SubType>Form</SubType>
     86    </Compile>
     87    <Compile Include="Views\AddCertificate.Designer.cs">
     88      <DependentUpon>AddCertificate.cs</DependentUpon>
     89    </Compile>
    7890    <Compile Include="Views\AddSubscriptionDialog.cs">
    7991      <SubType>Form</SubType>
     
    160172      <Generator>ResXFileCodeGenerator</Generator>
    161173      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
     174    </EmbeddedResource>
     175    <EmbeddedResource Include="Views\AddAzureServiceDialog.resx">
     176      <DependentUpon>AddAzureServiceDialog.cs</DependentUpon>
     177    </EmbeddedResource>
     178    <EmbeddedResource Include="Views\AddCertificate.resx">
     179      <DependentUpon>AddCertificate.cs</DependentUpon>
    162180    </EmbeddedResource>
    163181    <EmbeddedResource Include="Views\AddSubscriptionDialog.resx">
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Views/CloudResourcesView.Designer.cs

    r7324 r7339  
    9292      this.btnAddSlaveService.TabIndex = 2;
    9393      this.btnAddSlaveService.UseVisualStyleBackColor = true;
     94      this.btnAddSlaveService.Click += new System.EventHandler(this.btnAddSlaveService_Click);
    9495      //
    9596      // btnAddSubscription
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Views/CloudResourcesView.cs

    r7324 r7339  
    138138      }
    139139    }
     140
     141    private void btnAddSlaveService_Click(object sender, EventArgs e) {
     142      using (var form = new AddAzureServiceDialog(Content)) {
     143        form.ShowDialog();
     144
     145      }
     146    }
    140147  }
    141148}
Note: See TracChangeset for help on using the changeset viewer.