#region License Information /* HeuristicLab * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Net; using System.Threading; using HeuristicLab.Clients.Hive.SlaveCore; using Microsoft.WindowsAzure.Diagnostics; using Microsoft.WindowsAzure.ServiceRuntime; using Microsoft.WindowsAzure; using Microsoft.WindowsAzure.StorageClient; using System.Text; using System.Diagnostics; namespace HeuristicLab.Clients.Hive.Slave.AzureClient { public class WorkerRole : RoleEntryPoint { private HeuristicLab.Clients.Hive.SlaveCore.Core core; private Thread coreThread; private const string HiveServerAddressSetting = "HiveServerAddress"; private const string HiveServerCertificateSetting = "HiveServerCertifcateEncodedValue"; public override void Run() { try { Trace.WriteLine("Starting Run()..."); core = new HeuristicLab.Clients.Hive.SlaveCore.Core(false); string hiveServerAddress = RoleEnvironment.GetConfigurationSettingValue(HiveServerAddressSetting); string hiveServerCertificate = RoleEnvironment.GetConfigurationSettingValue(HiveServerCertificateSetting); // values are empty, settings from app.config are used if (!string.IsNullOrEmpty(hiveServerAddress) && !string.IsNullOrEmpty(hiveServerCertificate)) { core.SetNewHiveServer(hiveServerAddress, hiveServerCertificate); } coreThread = new Thread(core.Start); coreThread.Start(); WcfService.Instance.Connected += new EventHandler((sender, e) => { HiveHelper.RegisterSlaveToGroup(RoleEnvironment.GetConfigurationSettingValue("HiveGroup")); }); Trace.WriteLine("Run(): Core started successfullly"); while (true) { Thread.Sleep(10000); } } catch (Exception e) { Trace.WriteLine(e.ToString()); throw e; } } public override bool OnStart() { try { ServicePointManager.DefaultConnectionLimit = 12; //core = new Core(); Trace.WriteLine("Running OnStart()"); try { if (!String.IsNullOrEmpty(RoleEnvironment.GetConfigurationSettingValue(Constants.DiagnosticsConnectionString))) { DiagnosticMonitorConfiguration dmc = DiagnosticMonitor.GetDefaultInitialConfiguration(); dmc.Logs.ScheduledTransferPeriod = TimeSpan.FromSeconds(5); dmc.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose; DiagnosticMonitor.Start(Constants.DiagnosticsConnectionString, dmc); } } catch (RoleEnvironmentException ex) { // diagnostics connection string not in configuration // -> diagnostics disabled // nothing more to do Trace.WriteLine(ex.ToString()); } RoleEnvironment.Changed += RoleEnvironmentChanged; Trace.WriteLine("Finished OnStart() successfullly"); } catch (Exception ex) { Trace.WriteLine(ex.ToString()); throw ex; } return base.OnStart(); } public override void OnStop() { core.Shutdown(); base.OnStop(); } private void RoleEnvironmentChanged(object sender, RoleEnvironmentChangedEventArgs e) { } } }