Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Clients.Hive.Slave.AzureClient/3.3/WorkerRole.cs @ 12448

Last change on this file since 12448 was 9549, checked in by fschoepp, 12 years ago

#1888:

  • Removed unnecessary files from web project.
  • Cleaned up slave.
File size: 4.0 KB
RevLine 
[8242]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Net;
24using System.Threading;
25using HeuristicLab.Clients.Hive.SlaveCore;
26using Microsoft.WindowsAzure.Diagnostics;
27using Microsoft.WindowsAzure.ServiceRuntime;
[9365]28using Microsoft.WindowsAzure;
29using Microsoft.WindowsAzure.StorageClient;
30using System.Text;
[9549]31using System.Diagnostics;
[8242]32
33namespace HeuristicLab.Clients.Hive.Slave.AzureClient {
[9365]34
35
[8242]36  public class WorkerRole : RoleEntryPoint {
[9508]37    private HeuristicLab.Clients.Hive.SlaveCore.Core core;
[8242]38    private Thread coreThread;
39
[8251]40    private const string HiveServerAddressSetting = "HiveServerAddress";
41    private const string HiveServerCertificateSetting = "HiveServerCertifcateEncodedValue";
42
[8242]43    public override void Run() {
[9365]44      try {
[9549]45        Trace.WriteLine("Starting Run()...");
[9508]46        core = new HeuristicLab.Clients.Hive.SlaveCore.Core(false);
[8251]47
[9365]48        string hiveServerAddress = RoleEnvironment.GetConfigurationSettingValue(HiveServerAddressSetting);
49        string hiveServerCertificate = RoleEnvironment.GetConfigurationSettingValue(HiveServerCertificateSetting);
[8251]50
[9365]51        // values are empty, settings from app.config are used
52        if (!string.IsNullOrEmpty(hiveServerAddress) && !string.IsNullOrEmpty(hiveServerCertificate)) {
53          core.SetNewHiveServer(hiveServerAddress, hiveServerCertificate);
54        }
[8251]55
[9365]56        coreThread = new Thread(core.Start);
57        coreThread.Start();
[8242]58
[9508]59        WcfService.Instance.Connected += new EventHandler((sender, e) => {
60          HiveHelper.RegisterSlaveToGroup(RoleEnvironment.GetConfigurationSettingValue("HiveGroup"));
61        });
62
[9549]63        Trace.WriteLine("Run(): Core started successfullly");
[9365]64        while (true) {
65          Thread.Sleep(10000);
66        }
[8242]67      }
[9365]68      catch (Exception e) {
[9549]69        Trace.WriteLine(e.ToString());
70        throw e;
[9365]71      }
[8242]72    }
73
74    public override bool OnStart() {
75      try {
[9365]76        ServicePointManager.DefaultConnectionLimit = 12;
77        //core = new Core();
[9549]78        Trace.WriteLine("Running OnStart()");
[9365]79        try {
80          if (!String.IsNullOrEmpty(RoleEnvironment.GetConfigurationSettingValue(Constants.DiagnosticsConnectionString))) {
81            DiagnosticMonitorConfiguration dmc = DiagnosticMonitor.GetDefaultInitialConfiguration();
82            dmc.Logs.ScheduledTransferPeriod = TimeSpan.FromSeconds(5);
83            dmc.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
84            DiagnosticMonitor.Start(Constants.DiagnosticsConnectionString, dmc);
85          }
[8242]86        }
[9365]87        catch (RoleEnvironmentException ex) {
88          // diagnostics connection string not in configuration
89          // -> diagnostics disabled
90          // nothing more to do
[9549]91          Trace.WriteLine(ex.ToString());
[9365]92        }
93
94        RoleEnvironment.Changed += RoleEnvironmentChanged;
[9549]95        Trace.WriteLine("Finished OnStart() successfullly");
[8242]96      }
[9365]97      catch (Exception ex) {
[9549]98        Trace.WriteLine(ex.ToString());
99        throw ex;
[8242]100      }
101      return base.OnStart();
102    }
103
104    public override void OnStop() {
105      core.Shutdown();
106      base.OnStop();
107    }
[8251]108
109    private void RoleEnvironmentChanged(object sender, RoleEnvironmentChangedEventArgs e) {
110    }
[8242]111  }
112}
Note: See TracBrowser for help on using the repository browser.