[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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Net;
|
---|
| 24 | using System.Threading;
|
---|
| 25 | using HeuristicLab.Clients.Hive.SlaveCore;
|
---|
| 26 | using Microsoft.WindowsAzure.Diagnostics;
|
---|
| 27 | using Microsoft.WindowsAzure.ServiceRuntime;
|
---|
| 28 |
|
---|
| 29 | namespace HeuristicLab.Clients.Hive.Slave.AzureClient {
|
---|
| 30 | public class WorkerRole : RoleEntryPoint {
|
---|
| 31 | private Core core;
|
---|
| 32 | private Thread coreThread;
|
---|
| 33 |
|
---|
[8251] | 34 | private const string HiveServerAddressSetting = "HiveServerAddress";
|
---|
| 35 | private const string HiveServerCertificateSetting = "HiveServerCertifcateEncodedValue";
|
---|
| 36 |
|
---|
[8242] | 37 | public override void Run() {
|
---|
| 38 | core = new Core(false);
|
---|
[8251] | 39 |
|
---|
| 40 | string hiveServerAddress = RoleEnvironment.GetConfigurationSettingValue(HiveServerAddressSetting);
|
---|
| 41 | string hiveServerCertificate = RoleEnvironment.GetConfigurationSettingValue(HiveServerCertificateSetting);
|
---|
| 42 |
|
---|
| 43 | // values are empty, settings from app.config are used
|
---|
| 44 | if (!string.IsNullOrEmpty(hiveServerAddress) && !string.IsNullOrEmpty(hiveServerCertificate)) {
|
---|
| 45 | core.SetNewHiveServer(hiveServerAddress, hiveServerCertificate);
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[8242] | 48 | coreThread = new Thread(core.Start);
|
---|
| 49 | coreThread.Start();
|
---|
| 50 |
|
---|
| 51 | while (true) {
|
---|
| 52 | Thread.Sleep(10000);
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | public override bool OnStart() {
|
---|
| 57 | ServicePointManager.DefaultConnectionLimit = 12;
|
---|
| 58 | //core = new Core();
|
---|
| 59 | try {
|
---|
| 60 | if (!String.IsNullOrEmpty(RoleEnvironment.GetConfigurationSettingValue(Constants.DiagnosticsConnectionString))) {
|
---|
| 61 | DiagnosticMonitorConfiguration dmc = DiagnosticMonitor.GetDefaultInitialConfiguration();
|
---|
| 62 | dmc.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
|
---|
| 63 | dmc.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
|
---|
| 64 | DiagnosticMonitor.Start(Constants.DiagnosticsConnectionString, dmc);
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 | catch (RoleEnvironmentException ex) {
|
---|
| 68 | // diagnostics connection string not in configuration
|
---|
| 69 | // -> diagnostics disabled
|
---|
| 70 | // nothing more to do
|
---|
| 71 | }
|
---|
| 72 |
|
---|
[8251] | 73 | RoleEnvironment.Changed += RoleEnvironmentChanged;
|
---|
| 74 |
|
---|
[8242] | 75 | return base.OnStart();
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | public override void OnStop() {
|
---|
| 79 | core.Shutdown();
|
---|
| 80 | base.OnStop();
|
---|
| 81 | }
|
---|
[8251] | 82 |
|
---|
| 83 | private void RoleEnvironmentChanged(object sender, RoleEnvironmentChangedEventArgs e) {
|
---|
| 84 | }
|
---|
[8242] | 85 | }
|
---|
| 86 | }
|
---|