Changeset 5826


Ignore:
Timestamp:
03/24/11 16:15:23 (11 years ago)
Author:
ascheibe
Message:

#1233 slave ui now receives status information and displays it in doughnut chart

Location:
branches/HeuristicLab.Hive-3.4/sources
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.SlaveTrayIcon/MainWindow.Designer.cs

    r5677 r5826  
    8585      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    8686      this.ClientSize = new System.Drawing.Size(617, 454);
    87       this.ContextMenuStrip = this.contextMenuNotifyIcon;
    8887      this.Controls.Add(this.slaveView);
    8988      this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Views/3.4/SlaveItem.cs

    r5795 r5826  
    6262
    6363    public void Open() {
    64       pipeFactory = new DuplexChannelFactory<ISlaveCommunication>(this, "SlaveCommunicationServiceEndpoint");
    65       RegisterEvents();
     64      try {
     65        pipeFactory = new DuplexChannelFactory<ISlaveCommunication>(this, "SlaveCommunicationServiceEndpoint");
     66        RegisterEvents();
     67      }
     68      catch (Exception ex) {
     69        OnMessageLogged("Error establishing connection to Core. Are you missing a configuration file?\n" + ex.ToString());
     70      }
    6671    }
    6772
     
    7277        return true;
    7378      }
    74       catch (Exception e) {
    75         OnMessageLogged("Couldn't connect to Slave core. Is it possible that the Slave Core isn't running?\nException is: " + e.ToString());
     79      catch (Exception) {
     80        OnMessageLogged("Couldn't connect to Slave core. Is it possible that the Slave Core isn't running?\n");
    7681        return false;
    7782      }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Views/3.4/SlaveView.Designer.cs

    r5789 r5826  
    5555      this.btnAbout = new System.Windows.Forms.Button();
    5656      this.jobChart = new System.Windows.Forms.DataVisualization.Charting.Chart();
     57      this.btnRestartService = new System.Windows.Forms.Button();
    5758      ((System.ComponentModel.ISupportInitialize)(this.jobChart)).BeginInit();
    5859      this.SuspendLayout();
     
    6162      //
    6263      this.txtLog.BackColor = System.Drawing.Color.White;
    63       this.txtLog.Location = new System.Drawing.Point(3, 150);
     64      this.txtLog.Location = new System.Drawing.Point(3, 184);
    6465      this.txtLog.Multiline = true;
    6566      this.txtLog.Name = "txtLog";
    6667      this.txtLog.ReadOnly = true;
    6768      this.txtLog.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
    68       this.txtLog.Size = new System.Drawing.Size(584, 273);
     69      this.txtLog.Size = new System.Drawing.Size(584, 239);
    6970      this.txtLog.TabIndex = 1;
    7071      //
     
    111112      // btnAbout
    112113      //
    113       this.btnAbout.Location = new System.Drawing.Point(476, 119);
     114      this.btnAbout.Location = new System.Drawing.Point(476, 149);
    114115      this.btnAbout.Name = "btnAbout";
    115116      this.btnAbout.Size = new System.Drawing.Size(111, 28);
     
    132133      series1.Name = "Series1";
    133134      this.jobChart.Series.Add(series1);
    134       this.jobChart.Size = new System.Drawing.Size(272, 138);
     135      this.jobChart.Size = new System.Drawing.Size(293, 174);
    135136      this.jobChart.TabIndex = 7;
     137      //
     138      // btnRestartService
     139      //
     140      this.btnRestartService.Location = new System.Drawing.Point(476, 119);
     141      this.btnRestartService.Name = "btnRestartService";
     142      this.btnRestartService.Size = new System.Drawing.Size(111, 28);
     143      this.btnRestartService.TabIndex = 8;
     144      this.btnRestartService.Text = "RestartService";
     145      this.btnRestartService.UseVisualStyleBackColor = true;
     146      this.btnRestartService.Click += new System.EventHandler(this.btnRestartService_Click);
    136147      //
    137148      // SlaveView
     
    139150      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    140151      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     152      this.Controls.Add(this.btnRestartService);
    141153      this.Controls.Add(this.jobChart);
    142154      this.Controls.Add(this.btnAbout);
     
    163175    private System.Windows.Forms.Button btnAbout;
    164176    private System.Windows.Forms.DataVisualization.Charting.Chart jobChart;
     177    private System.Windows.Forms.Button btnRestartService;
    165178  }
    166179}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Views/3.4/SlaveView.cs

    r5795 r5826  
    2121
    2222using System;
     23using System.Security.Principal;
     24using System.ServiceProcess;
    2325using System.Threading;
    2426using System.Threading.Tasks;
     
    4749    public SlaveView() {
    4850      InitializeComponent();
     51
     52      if (!CheckRunAsAdmin())
     53        btnRestartService.Enabled = false;
     54      btnRestart.Enabled = false;
     55
    4956    }
    5057
     
    99106    #region Event Handlers
    100107    void Content_SlaveStatusChanged(object sender, EventArgs<StatusCommons> e) {
    101       txtLog.AppendText("got a status changed object from slave\n");
    102108      RenderChart(e.Value);
    103109    }
     
    114120
    115121    private void RenderChart(StatusCommons status) {
     122      jobChart.Series[0].Points.Clear();
    116123
    117124      DataPoint pJobs = new DataPoint(status.Jobs.Count, status.Jobs.Count);
     
    120127      DataPoint pJobsFetched = new DataPoint(status.JobsFetched, status.JobsFetched);
    121128
     129      pJobs.LegendText = "Current jobs: " + status.Jobs.Count;
     130      pJobs.Color = System.Drawing.Color.Orange;
     131      pJobsAborted.LegendText = "Aborted jobs: " + status.JobsAborted;
     132      pJobsAborted.Color = System.Drawing.Color.Red;
     133      pJobsDone.LegendText = "Finished jobs: " + status.JobsDone;
     134      pJobsDone.Color = System.Drawing.Color.Green;
     135      pJobsFetched.LegendText = "Fetched jobs: " + status.JobsFetched;
     136      pJobsFetched.Color = System.Drawing.Color.Blue;
     137
    122138      jobChart.Series[0].Points.Add(pJobs);
    123139      jobChart.Series[0].Points.Add(pJobsAborted);
     
    137153
    138154    private void btnRestart_Click(object sender, System.EventArgs e) {
    139       if (Content != null)
     155      if (Content != null) {
    140156        Content.RestartCore();
     157        btnRestart.Enabled = false;
     158        btnSleep.Enabled = true;
     159      }
    141160    }
    142161
    143162    private void btnSleep_Click(object sender, System.EventArgs e) {
    144       if (Content != null)
     163      if (Content != null) {
    145164        Content.Sleep();
     165        btnRestart.Enabled = true;
     166        btnSleep.Enabled = false;
     167      }
    146168    }
    147169
     
    150172      diag.ShowDialog();
    151173    }
     174
     175    private void btnRestartService_Click(object sender, EventArgs e) {
     176      if (CheckRunAsAdmin()) {
     177        RestartService();
     178      } else {
     179        MessageBox.Show("You need to run this application as Administrator to restart the service");
     180      }
     181    }
     182
     183    private bool CheckRunAsAdmin() {
     184      bool isRunAsAdmin = false;
     185      WindowsIdentity user = WindowsIdentity.GetCurrent();
     186      WindowsPrincipal principal = new WindowsPrincipal(user);
     187
     188      try {
     189        isRunAsAdmin = principal.IsInRole(WindowsBuiltInRole.Administrator);
     190      }
     191      catch { }
     192      return isRunAsAdmin;
     193    }
     194
     195    private void RestartService() {
     196      string serviceName = "HeuristicLab.Clients.Hive.SlaveCore.SlaveWindowsService";
     197      TimeSpan timeout = TimeSpan.FromMilliseconds(5000);
     198
     199      ServiceController service = new ServiceController(serviceName);
     200      try {
     201        if (service.Status == ServiceControllerStatus.Running) {
     202          service.Stop();
     203          service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
     204        }
     205
     206        service.Start();
     207        service.WaitForStatus(ServiceControllerStatus.Running, timeout);
     208      }
     209      catch (InvalidOperationException ex) {
     210        MessageBox.Show("Error starting service: Hive Slave Service not found!\n" + ex.ToString());
     211      }
     212      catch (Exception ex) {
     213        MessageBox.Show("Error starting service, exception is: \n" + ex.ToString());
     214      }
     215    }
    152216  }
    153217}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Core.cs

    r5793 r5826  
    2424using System.Diagnostics;
    2525using System.IO;
    26 using System.Runtime.CompilerServices;
    2726using System.ServiceModel;
    2827using System.Threading;
     
    3332
    3433
    35 
    3634namespace HeuristicLab.Clients.Hive.SlaveCore {
    3735  /// <summary>
    38   /// The core component of the Hive Client
     36  /// The core component of the Hive Slave.
     37  /// Handles commands sent from the Hive Server.
    3938  /// </summary>
    4039  public class Core : MarshalByRefObject {
    41 
    42     //TODO: this class should be a singleton; there is only one instance, the reference is meanwhile save in TheCore
    43     public static Core TheCore;
    44 
    4540    public EventLog ServiceEventLog { get; set; }
    4641
     
    6863    }
    6964
    70     public Core() {
    71       TheCore = this;
    72     }
     65    public Core() { }
    7366
    7467    /// <summary>
     
    8073
    8174      try {
     75        ConfigManager manager = ConfigManager.Instance;
     76        manager.Core = this;
     77
    8278        //start the client communication service (pipe between slave and slave gui)
    8379        slaveComm = new ServiceHost(typeof(SlaveCommunicationService));
     
    8783        clientCom.LogMessage("Hive Slave started");
    8884
    89         ConfigManager manager = ConfigManager.Instance;
    90         manager.Core = this;
    91 
    9285        wcfService = WcfService.Instance;
    9386        RegisterServiceEvents();
    9487
    95         StartHeartbeats(); // Start heartbeats thread
     88        StartHeartbeats(); // Start heartbeats thread       
    9689        DispatchMessageQueue(); // dispatch messages until abortRequested
    9790      }
     
    125118        MessageContainer container = queue.GetMessage();
    126119        DetermineAction(container);
     120        clientCom.StatusChanged(ConfigManager.Instance.GetStatusForClientConsole());
    127121      }
    128122    }
     
    149143    /// Reads and analyzes the Messages from the MessageQueue and starts corresponding actions
    150144    /// </summary>
    151     /// <param name="container">The Container, containing the message</param>
     145    /// <param name="container">The container, containing the message</param>
    152146    private void DetermineAction(MessageContainer container) {
    153147      clientCom.LogMessage("Message: " + container.Message.ToString() + " for job: " + container.JobId);
     
    169163              }
    170164              JobData jobData = wcfService.GetJobData(job.Id);
    171               if (job == null) throw new JobDataNotFoundException(jobId);
     165              if (jobData == null) throw new JobDataNotFoundException(jobId);
     166              SlaveStatusInfo.JobsFetched++;
    172167              job = wcfService.UpdateJobState(job.Id, JobState.Calculating, null);
    173168              StartJobInAppDomain(job, jobData);
     
    228223            clientCom.LogMessage("Sending the paused job with id: " + job.Id);
    229224            wcfService.UpdateJobData(job, sJob, ConfigManager.Instance.GetClientInfo().Id, JobState.Paused);
    230             SlaveStatusInfo.JobsProcessed++;    //TODO: count or not count, thats the question
    231225          }
    232226          catch (Exception e) {
     
    254248            clientCom.LogMessage("Sending the stoppped job with id: " + job.Id);
    255249            wcfService.UpdateJobData(job, sJob, ConfigManager.Instance.GetClientInfo().Id, JobState.Finished);
    256             SlaveStatusInfo.JobsProcessed++;    //TODO: count or not count, thats the question
    257250          }
    258251          catch (Exception e) {
     
    365358    /// stop slave, except for client gui communication,
    366359    /// primarily used by gui if core is running as windows service
    367     /// </summary>
    368     //TODO: do we need an AbortSleep?
     360    /// </summary>   
    369361    private void Sleep() {
    370362      clientCom.LogMessage("Sleep received");
     
    380372    /// atm only used when executor is waiting for child jobs
    381373    /// </summary>
    382     /// <param name="data"></param>
    383     [MethodImpl(MethodImplOptions.Synchronized)]
    384374    public void PauseWaitJob(JobData data) {
    385375      if (!Jobs.ContainsKey(data.JobId)) {
     
    397387    /// once the connection gets reestablished, the job gets submitted
    398388    /// </summary>
    399     /// <param name="jobId"></param>
    400     [MethodImpl(MethodImplOptions.Synchronized)]
    401389    public void SendFinishedJob(Guid jobId) {
    402390      try {
     
    413401        cJob.ExecutionTime = engines[jobId].ExecutionTime;
    414402
     403        if (engines[jobId].Aborted) {
     404          SlaveStatusInfo.JobsAborted++;
     405        } else {
     406          SlaveStatusInfo.JobsProcessed++;
     407        }
     408
     409        if (engines[jobId].CurrentException != string.Empty) {
     410          wcfService.UpdateJobState(jobId, JobState.Failed, engines[jobId].CurrentException);
     411        }
     412
    415413        JobData sJob = engines[jobId].GetFinishedJob();
    416         // cJob.Exception = engines[jId].CurrentException; // can there be an exception if the job is sent normally. the exception should be entered in the statelog with the corresponding state (Failed)
    417         cJob.ExecutionTime = engines[jobId].ExecutionTime;
    418 
    419414        try {
    420415          clientCom.LogMessage("Sending the finished job with id: " + jobId);
    421416          wcfService.UpdateJobData(cJob, sJob, ConfigManager.Instance.GetClientInfo().Id, JobState.Finished);
    422           SlaveStatusInfo.JobsProcessed++;
    423417        }
    424418        catch (Exception e) {
     
    426420        }
    427421        finally {
    428           KillAppDomain(jobId); // kill app-domain in every case
     422          KillAppDomain(jobId);
    429423          heartbeatManager.AwakeHeartBeatThread();
    430424        }
     
    437431    /// <summary>
    438432    /// A new Job from the wcfService has been received and will be started within a AppDomain.
    439     /// </summary>
    440     /// <param name="sender"></param>
    441     /// <param name="e"></param>
     433    /// </summary>   
    442434    private void StartJobInAppDomain(Job myJob, JobData jobData) {
    443435      clientCom.LogMessage("Received new job with id " + myJob.Id);
     436      clientCom.StatusChanged(ConfigManager.Instance.GetStatusForClientConsole());
    444437      if (engines.ContainsKey(myJob.Id))
    445438        throw new Exception("Job with key " + myJob.Id + " already exists");
     
    472465            engines.Add(myJob.Id, engine);
    473466            engine.Start(jobData.Data);
    474             SlaveStatusInfo.JobsFetched++;
    475             clientCom.LogMessage("Increment FetchedJobs to:" + SlaveStatusInfo.JobsFetched);
    476467          }
    477468        }
     
    501492    /// This is necessary if the core thread has to execute certain actions, e.g.
    502493    /// killing of an app domain.
    503     /// </summary>
    504     /// <typeparam name="T"></typeparam>
    505     /// <param name="action"></param>
    506     /// <param name="parameter"></param>
     494    /// </summary>   
    507495    /// <returns>true if the calling method can continue execution, else false</returns>
    508496    public void EnqueueExecutorMessage<T>(Action<T> action, T parameter) {
     
    516504    /// Kill a appdomain with a specific id.
    517505    /// </summary>
    518     /// <param name="id">the GUID of the job</param>
    519     //[MethodImpl(MethodImplOptions.Synchronized)]
     506    /// <param name="id">the GUID of the job</param>   
    520507    public void KillAppDomain(Guid id) {
    521508      if (Thread.CurrentThread.ManagedThreadId != this.coreThreadId) {
     
    562549      }
    563550      GC.Collect();
     551      clientCom.StatusChanged(ConfigManager.Instance.GetStatusForClientConsole());
    564552    }
    565553  }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Executor.cs

    r5795 r5826  
    3838    private Semaphore pauseStopSem = new Semaphore(0, 1);
    3939
     40    public bool Aborted { get; set; }
     41
    4042    private Exception currentException;
    4143    public String CurrentException {
     
    6870      try {
    6971        CreationTime = DateTime.Now;
     72        Aborted = false;
    7073        Job = PersistenceUtil.Deserialize<IJob>(serializedJob);
    7174
     
    182185      currentException = ex.Value;
    183186      Core.EnqueueExecutorMessage(Core.SendFinishedJob, JobId);
     187      Aborted = true;
    184188    }
    185189
     
    187191      if (wasJobAborted) {
    188192        pauseStopSem.Release();
     193        Aborted = true;
    189194      } else {
    190         //it's a clean and finished job, so send it
     195        //it's a clean and finished job, so send it       
    191196        Core.EnqueueExecutorMessage(Core.SendFinishedJob, JobId);
    192197      }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/HeartbeatManager.cs

    r5721 r5826  
    7878      while (!threadStopped) {
    7979        sleepForever = false;
     80        SlaveClientCom.Instance.ClientCom.StatusChanged(ConfigManager.Instance.GetStatusForClientConsole());
     81
    8082        try {
    8183          lock (locker) {
    8284            if (wcfService.ConnState != NetworkEnum.WcfConnState.Connected) {
    83               wcfService.Connect(ConfigManager.Instance.GetClientInfo()); // Login happens automatically upon successfull connection
     85              // login happens automatically upon successfull connection
     86              wcfService.Connect(ConfigManager.Instance.GetClientInfo());
     87              SlaveStatusInfo.LoginTime = DateTime.Now;
    8488            }
    8589            if (wcfService.ConnState == NetworkEnum.WcfConnState.Connected) {
     
    111115        }
    112116        catch (Exception e) {
    113           SlaveClientCom.Instance.ClientCom.LogMessage("Heartbeat Thread failed badly: " + e.Message);
     117          SlaveClientCom.Instance.ClientCom.LogMessage("Heartbeat thread failed: " + e.ToString());
    114118          OnExceptionOccured(e);
    115119        }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/ServiceContracts/ISlaveCommunication.cs

    r5599 r5826  
    4949    void AbortAll();
    5050
    51     [OperationContract]
    52     void ShutdownSlave();
    53 
    5451    //callbacks
    5552    [OperationContract]
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/SlaveCommunicationService.cs

    r5599 r5826  
    3333      try {
    3434        ISlaveCommunicationCallbacks callback = OperationContext.Current.GetCallbackChannel<ISlaveCommunicationCallbacks>();
    35         if (!subscribers.Contains(callback))
     35        if (!subscribers.Contains(callback)) {
    3636          subscribers.Add(callback);
     37        }
    3738        return true;
    3839      }
     
    99100    }
    100101
    101     public void ShutdownSlave() {
    102       Core.TheCore.Shutdown();
    103     }
    104 
    105102    public void AbortAll() {
    106103      MessageContainer mc = new MessageContainer(MessageContainer.MessageType.AbortAll);
Note: See TracChangeset for help on using the changeset viewer.