Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1888:

  • Removed unnecessary files from web project.
  • Cleaned up slave.
File size: 4.0 KB
Line 
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;
28using Microsoft.WindowsAzure;
29using Microsoft.WindowsAzure.StorageClient;
30using System.Text;
31using System.Diagnostics;
32
33namespace HeuristicLab.Clients.Hive.Slave.AzureClient {
34
35
36  public class WorkerRole : RoleEntryPoint {
37    private HeuristicLab.Clients.Hive.SlaveCore.Core core;
38    private Thread coreThread;
39
40    private const string HiveServerAddressSetting = "HiveServerAddress";
41    private const string HiveServerCertificateSetting = "HiveServerCertifcateEncodedValue";
42
43    public override void Run() {
44      try {
45        Trace.WriteLine("Starting Run()...");
46        core = new HeuristicLab.Clients.Hive.SlaveCore.Core(false);
47
48        string hiveServerAddress = RoleEnvironment.GetConfigurationSettingValue(HiveServerAddressSetting);
49        string hiveServerCertificate = RoleEnvironment.GetConfigurationSettingValue(HiveServerCertificateSetting);
50
51        // values are empty, settings from app.config are used
52        if (!string.IsNullOrEmpty(hiveServerAddress) && !string.IsNullOrEmpty(hiveServerCertificate)) {
53          core.SetNewHiveServer(hiveServerAddress, hiveServerCertificate);
54        }
55
56        coreThread = new Thread(core.Start);
57        coreThread.Start();
58
59        WcfService.Instance.Connected += new EventHandler((sender, e) => {
60          HiveHelper.RegisterSlaveToGroup(RoleEnvironment.GetConfigurationSettingValue("HiveGroup"));
61        });
62
63        Trace.WriteLine("Run(): Core started successfullly");
64        while (true) {
65          Thread.Sleep(10000);
66        }
67      }
68      catch (Exception e) {
69        Trace.WriteLine(e.ToString());
70        throw e;
71      }
72    }
73
74    public override bool OnStart() {
75      try {
76        ServicePointManager.DefaultConnectionLimit = 12;
77        //core = new Core();
78        Trace.WriteLine("Running OnStart()");
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          }
86        }
87        catch (RoleEnvironmentException ex) {
88          // diagnostics connection string not in configuration
89          // -> diagnostics disabled
90          // nothing more to do
91          Trace.WriteLine(ex.ToString());
92        }
93
94        RoleEnvironment.Changed += RoleEnvironmentChanged;
95        Trace.WriteLine("Finished OnStart() successfullly");
96      }
97      catch (Exception ex) {
98        Trace.WriteLine(ex.ToString());
99        throw ex;
100      }
101      return base.OnStart();
102    }
103
104    public override void OnStop() {
105      core.Shutdown();
106      base.OnStop();
107    }
108
109    private void RoleEnvironmentChanged(object sender, RoleEnvironmentChangedEventArgs e) {
110    }
111  }
112}
Note: See TracBrowser for help on using the repository browser.