- Timestamp:
- 04/17/13 10:49:49 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS/HeuristicLab.Clients.Hive.Slave.AzureClient/3.3/WorkerRole.cs
r8251 r9365 26 26 using Microsoft.WindowsAzure.Diagnostics; 27 27 using Microsoft.WindowsAzure.ServiceRuntime; 28 using Microsoft.WindowsAzure; 29 using Microsoft.WindowsAzure.StorageClient; 30 using System.Text; 28 31 29 32 namespace HeuristicLab.Clients.Hive.Slave.AzureClient { 33 34 30 35 public class WorkerRole : RoleEntryPoint { 31 36 private Core core; … … 36 41 37 42 public override void Run() { 38 core = new Core(false); 43 try { 44 LogError(new Exception("Starting Run()...")); 45 core = new Core(false); 39 46 40 string hiveServerAddress = RoleEnvironment.GetConfigurationSettingValue(HiveServerAddressSetting);41 string hiveServerCertificate = RoleEnvironment.GetConfigurationSettingValue(HiveServerCertificateSetting);47 string hiveServerAddress = RoleEnvironment.GetConfigurationSettingValue(HiveServerAddressSetting); 48 string hiveServerCertificate = RoleEnvironment.GetConfigurationSettingValue(HiveServerCertificateSetting); 42 49 43 // values are empty, settings from app.config are used 44 if (!string.IsNullOrEmpty(hiveServerAddress) && !string.IsNullOrEmpty(hiveServerCertificate)) { 45 core.SetNewHiveServer(hiveServerAddress, hiveServerCertificate); 50 // values are empty, settings from app.config are used 51 if (!string.IsNullOrEmpty(hiveServerAddress) && !string.IsNullOrEmpty(hiveServerCertificate)) { 52 core.SetNewHiveServer(hiveServerAddress, hiveServerCertificate); 53 } 54 55 coreThread = new Thread(core.Start); 56 coreThread.Start(); 57 58 LogError(new Exception("Run(): Core started successfullly")); 59 while (true) { 60 Thread.Sleep(10000); 61 } 46 62 } 47 48 coreThread = new Thread(core.Start); 49 coreThread.Start(); 50 51 while (true) { 52 Thread.Sleep(10000); 63 catch (Exception e) { 64 LogError(e); 65 throw e; 53 66 } 54 67 } 55 68 56 69 public override bool OnStart() { 57 ServicePointManager.DefaultConnectionLimit = 12;58 //core = new Core();59 70 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); 71 ServicePointManager.DefaultConnectionLimit = 12; 72 //core = new Core(); 73 LogError(new Exception("Running OnStart()")); 74 try { 75 if (!String.IsNullOrEmpty(RoleEnvironment.GetConfigurationSettingValue(Constants.DiagnosticsConnectionString))) { 76 DiagnosticMonitorConfiguration dmc = DiagnosticMonitor.GetDefaultInitialConfiguration(); 77 dmc.Logs.ScheduledTransferPeriod = TimeSpan.FromSeconds(5); 78 dmc.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose; 79 DiagnosticMonitor.Start(Constants.DiagnosticsConnectionString, dmc); 80 } 65 81 } 82 catch (RoleEnvironmentException ex) { 83 // diagnostics connection string not in configuration 84 // -> diagnostics disabled 85 // nothing more to do 86 LogError(ex); 87 } 88 89 RoleEnvironment.Changed += RoleEnvironmentChanged; 90 LogError(new Exception("Finished OnStart() successfullly")); 66 91 } 67 catch (RoleEnvironmentException ex) { 68 // diagnostics connection string not in configuration 69 // -> diagnostics disabled 70 // nothing more to do 92 catch (Exception ex) { 93 LogError(ex); 94 throw ex; 71 95 } 96 return base.OnStart(); 97 } 72 98 73 RoleEnvironment.Changed += RoleEnvironmentChanged; 74 75 return base.OnStart(); 99 private void LogError(Exception e) { 100 var storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=optimizationstorage1;AccountKey=n7Leom8ZFWkof/VQ2a4aRSvwOlX+Gwr3uojQF9CFJw1osmGCV0WwaNC8s7nkZ+qteLduAgW2l75WFpbXrkvG4Q=="); 101 var blobClient = storageAccount.CreateCloudBlobClient(); 102 var container = blobClient.GetContainerReference("slavelog"); 103 container.CreateIfNotExist(); 104 var guid = Guid.NewGuid(); 105 var blob = container.GetBlobReference(guid.ToString()); 106 var builder = new StringBuilder(); 107 builder.Append("ToString: ").Append(e.ToString()).Append("\n"); 108 builder.Append("Message: ").Append(e.Message).Append("\n"); 109 blob.UploadText(builder.ToString()); 76 110 } 77 111
Note: See TracChangeset
for help on using the changeset viewer.