Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/19/10 13:30:56 (14 years ago)
Author:
cneumuel
Message:

Split up "State" to "JobState" and "SlaveState" (#1159)

Location:
branches/3.3-HiveMigration/sources/HeuristicLab.Hive
Files:
3 added
22 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Contracts/3.3/ApplicationConstants.cs

    r4263 r4264  
    3535    /// </summary>
    3636    public static System.Transactions.IsolationLevel ISOLATION_LEVEL_SCOPE = System.Transactions.IsolationLevel.ReadUncommitted;
     37
    3738    public static int HEARTBEAT_MAX_DIF = 120; // value in seconds
     39   
    3840    public static int JOB_TIME_TO_LIVE = 5;
    39 
    40     //public static string RESPONSE_SERVERCONSOLE_LOGIN_SUCCESS = "Logged in";
    41     //public static string RESPONSE_SERVERCONSOLE_LOGIN_FAILED = "Login failed";
    42 
    43     //public static string RESPONSE_USERROLE_GET_ALL_USERS = "UserRole.GetAllUsers";
    44     //public static string RESPONSE_USERROLE_USER_EXISTS_ALLREADY = "UserRole.UserExistsAllready";
    45     //public static string RESPONSE_USERROLE_USER_SUCCESSFULLY_ADDED = "UserRole.UserSuccessfullyAdded";
    46     //public static string RESPONSE_USERROLE_USER_DOESNT_EXIST = "UserRole.UserDoesntExist";
    47     //public static string RESPONSE_USERROLE_USER_REMOVED = "UserRole.UserRemoved";
    48     //public static string RESPONSE_USERROLE_USERGROUP_EXISTS_ALLREADY = "UserRole.UsergroupExistsAllready";
    49     //public static string RESPONSE_USERROLE_USERGROUP_ADDED = "UserRole.UserGroupAdded";
    50     //public static string RESPONSE_USERROLE_USERGROUP_DOESNT_EXIST = "UserRole.UserGroupDoesntExist";
    51     //public static string RESPONSE_USERROLE_PERMISSIONOWNER_DOESNT_EXIST = "UserRole.PermissionOwnerDoesntExist";
    52     //public static string RESPONSE_USERROLE_PERMISSIONOWNER_REMOVED = "UserRole.PermissionOwnerRemoved";
    53     //public static string RESPONSE_USERROLE_PERMISSIONOWNER_ADDED = "UserRole.PermissionOwnerAdded";
    54     //public static string RESPONSE_USERROLE_GET_ALL_USERGROUPS = "UserRole.AllUserGroupsReturned";
    55     //public static string RESPONSE_USERROLE_ID_MUST_NOT_BE_SET = "UserRole.IdMustNotBeSet";
    56     //public static string RESPONSE_USERROLE_USERGROUP_ADDED_TO_USERGROUP = "UserRole.UserGroupAddedToUserGroup";
    57     //public static string RESPONSE_USERROLE_USERNAME_EXISTS_ALLREADY = "UserRole.UsernameExistsAllready";
    58 
    59     //public static string RESPONSE_CLIENT_GET_ALL_CLIENTS = "Client.GetAllClients";
    60     //public static string RESPONSE_CLIENT_GET_ALL_CLIENTGROUPS = "Client.GetAllClientGroups";
    61     //public static string RESPONSE_CLIENT_ID_MUST_NOT_BE_SET = "Client.IdMustNotBeSet";
    62     //public static string RESPONSE_CLIENT_CLIENTGROUP_ADDED = "Client.ClientGroupAdded";
    63     //public static string RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST = "Client.ClientGroupDoesntExist";
    64     //public static string RESPONSE_CLIENT_CLIENTGROUP_DELETED = "Client group sucessfully deleted";
    65     //public static string RESPONSE_CLIENT_RESOURCE_ADDED_TO_GROUP = "Client.ResourceAddedToGroup";
    66     //public static string RESPONSE_CLIENT_RESOURCE_REMOVED = "Client.ResourceRemoved";
    67     //public static string RESPONSE_CLIENT_RESOURCE_NOT_FOUND = "Client.ResourceNotFound";
    68     //public static string RESPONSE_CLIENT_PERMISSIONOWNER_DOESNT_EXIST = "Client.PermissionOwnerDoesntExist";
    69     //public static string RESPONSE_CLIENT_GET_GROUPS_OF_CLIENT = "Get all groups of a client";
    70 
    71     //public static string RESPONSE_COMMUNICATOR_HEARTBEAT_RECEIVED = "Communicator.HeardbeatReceived";
    72     //public static string RESPONSE_COMMUNICATOR_JOB_PULLED = "Communicator.JobPulled";
    73     //public static string RESPONSE_COMMUNICATOR_JOBRESULT_RECEIVED = "Communicator.JobResultReceived";
    74     //public static string RESPONSE_COMMUNICATOR_LOGIN_USER_ALLREADY_ONLINE = "Communicator.LoginUserAllreadyOnline";
    75     //public static string RESPONSE_COMMUNICATOR_LOGIN_SUCCESS = "Communicator.LoginSuccess";
    76     //public static string RESPONSE_COMMUNICATOR_LOGOUT_CLIENT_NOT_REGISTERED = "Communicator.LogoutClientNotRegistered";
    77     //public static string RESPONSE_COMMUNICATOR_LOGOUT_SUCCESS = "Communicator.LogoutSuccess";
    78     //public static string RESPONSE_COMMUNICATOR_NO_JOBS_LEFT = "Communicator.NoJobsLeft";
    79     //public static string RESPONSE_COMMUNICATOR_ID_MUST_NOT_BE_SET = "Communicator.IdMustNotBeSet";
    80     //public static string RESPONSE_COMMUNICATOR_NO_JOB_WITH_THIS_ID = "Communicator.NoJobWithThisId";
    81     //public static string RESPONSE_COMMUNICATOR_WRONG_JOB_STATE = "Communicator.WrongJobState";
    82     //public static string RESPONSE_COMMUNICATOR_USER_NOT_LOGGED_IN = "Communicator.UserNotLoggedIn";
    83     //public static string RESPONSE_COMMUNICATOR_JOB_IS_NOT_BEEING_CALCULATED = "Communicator.JobIsNotBeenigCalculated";
    84     //public static string RESPONSE_COMMUNICATOR_WRONG_CLIENT_FOR_JOB = "Communicator.WrongClientForJob";
    85     //public static string RESPONSE_COMMUNICATOR_JOB_ALLREADY_FINISHED = "Job allready finished. Not needed anymore";
    86     //public static string RESPONSE_COMMUNICATOR_JOB_DOESNT_EXIST = "No job exists with this id";
    87     //public static string RESPONSE_COMMUNICATOR_SEND_JOBRESULT = "Please send the Jobresult to the server";
    88     //public static string RESPONSE_COMMUNICATOR_PLUGINS_SENT = "Communicator.PluginsSent";
    89     //public static string RESPONSE_COMMUNICATOR_PLUGINS_NOT_AVAIL = "Communicator.PluginsNotAvail";
    90     //public static string RESPONSE_COMMUNICATOR_JOB_WAS_ABORTED = "Job was aborted";
    91 
    92     //public static string RESPONSE_COMMUNICATOR_FETCH_OR_FORCEFETCH_CALENDAR = "new Calendar must be fetched / force fetched";
    93 
    94     //public static string RESPONSE_JOB_ALL_JOBS = "Job.AllJobs";
    95     //public static string RESPONSE_JOB_GET_JOB_BY_ID = "Job.GetJobById";
    96     //public static string RESPONSE_JOB_ID_MUST_NOT_BE_SET = "Job.IdMustNotBeSet";
    97     //public static string RESPONSE_JOB_JOB_ADDED = "Job.JobAdded";
    98     //public static string RESPONSE_JOB_JOB_NULL = "Job.JobNull";
    99     //public static string RESPONSE_JOB_JOB_DOESNT_EXIST = "JobDoesntExist";
    100     //public static string RESPONSE_JOB_JOB_REMOVED = "Job.JobRemoved";
    101     //public static string RESPONSE_JOB_JOBSTATE_MUST_BE_OFFLINE = "Job.JobStateMustBeOffline";
    102     //public static string RESPONSE_JOB_IS_NOT_BEEING_CALCULATED = "Job.IsNotBeeingCalculated";
    103     //public static string RESPONSE_JOB_JOB_RESULT_SENT = "Job.JobResultSent";
    104     //public static string RESPONSE_JOB_REQUEST_ALLREADY_SET = "Job.RequestAllreadySet";
    105     //public static string RESPONSE_JOB_ABORT_REQUEST_ALLREADY_SET = "Job.AbortRequestAllreadySet";
    106     //public static string RESPONSE_JOB_REQUEST_SET = "Job.RequestSet";
    107     //public static string RESPONSE_JOB_ABORT_REQUEST_SET = "Job.AbortRequestSet";
    108     //public static string RESPONSE_JOB_RESULT_NOT_YET_HERE = "Requested job result is not yet finished";
    109     //public static string RESPONSE_JOB_PROJECT_NAME_EMPTY = "Please specifiy a project name";
    110     //public static string RESPONSE_JOB_PROJECT_ADDED = "Project successfully added";
    111     //public static string RESPONSE_JOB_PROJECT_DOESNT_EXIST = "The specified project doesn't exist";
    112     //public static string RESPONSE_JOB_PROJECT_DELETED = "The project was sucessfully deleted";
    113 
    114     //public static string RESPONSE_UPTIMECALENDAR_NO_CALENDAR_FOUND = "No Calendar could be found anywhere in the tree";
    115     //public static string RESPONSE_UPTIMECALENDAR_STATUS_UPDATED = "Calendar status has been updated";
    11641  }
    11742}
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Contracts/3.3/BusinessObjects/ClientDto.cs

    r4141 r4264  
    2929
    3030namespace HeuristicLab.Hive.Contracts.BusinessObjects {
    31 
    32   public enum State { NullState, Idle, Calculating, Offline, Finished, Abort, RequestSnapshot, RequestSnapshotSent, Pending, Failed };
    33   public enum CalendarState { Fetch, ForceFetch, Fetching, Fetched, NotAllowedToFetch };
    34 
    3531  [StorableClass]
    3632  [DataContract]
     
    5753    [Storable]
    5854    [DataMember]
    59     public State State { get; set; }
     55    public SlaveState State { get; set; }
    6056    [Storable]
    6157    [DataMember]
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Contracts/3.3/BusinessObjects/HeartBeatData.cs

    r4253 r4264  
    3838    [DataMember]
    3939    public Dictionary<Guid, double> JobProgress { get; set; } // TODO: define Type
     40    [DataMember]
     41    public bool IsAllowedToCalculate { get; set; } // this is true if slave is allowed to work according to calendar
    4042
    4143    public override string ToString() {
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Contracts/3.3/BusinessObjects/JobDto.cs

    r4144 r4264  
    3838    [Storable]
    3939    [DataMember]
    40     public State State { get; set; }
     40    public JobState State { get; set; }
    4141    [Storable]
    4242    [DataMember]
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Contracts/3.3/BusinessObjects/JobResult.cs

    r4170 r4264  
    4444    [Storable]
    4545    [DataMember]
    46     public State State { get; set; }
     46    public JobState State { get; set; }
    4747    [Storable]
    4848    [DataMember]
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Contracts/3.3/HeuristicLab.Hive.Contracts-3.3.csproj

    r4263 r4264  
    118118    <Compile Include="BusinessObjects\AppointmentDto.cs" />
    119119    <Compile Include="BusinessObjects\CachedHivePluginInfoDto.cs" />
     120    <Compile Include="BusinessObjects\CalendarState.cs" />
    120121    <Compile Include="BusinessObjects\ClientGroupDto.cs" />
    121122    <Compile Include="BusinessObjects\HivePluginFile.cs" />
    122123    <Compile Include="BusinessObjects\JobResultList.cs" />
     124    <Compile Include="BusinessObjects\JobState.cs" />
    123125    <Compile Include="BusinessObjects\ResourceDto.cs" />
    124126    <Compile Include="BusinessObjects\SerializedJob.cs" />
     
    129131    <Compile Include="BusinessObjects\JobResult.cs" />
    130132    <Compile Include="BusinessObjects\SerializedJobResult.cs" />
     133    <Compile Include="BusinessObjects\SlaveState.cs" />
    131134    <Compile Include="BusinessObjects\UpTimeStatisticsDto.cs" />
    132135    <Compile Include="BusinessObjects\ClientDto.cs" />
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Contracts/3.3/Interfaces/IJobManager.cs

    r4263 r4264  
    3636
    3737    [OperationContract]
    38     ResponseList<JobDto> GetAllJobsWithFilter(State jobState, int offset, int count);
     38    ResponseList<JobDto> GetAllJobsWithFilter(JobState jobState, int offset, int count);
    3939
    4040    [OperationContract]
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/HiveExperiment.cs

    r4263 r4264  
    447447      JobItem jobItem = (JobItem)sender;
    448448      Thread t = new Thread(() => {
    449         if (jobItem.State == State.Finished) {
     449        if (jobItem.State == JobState.Finished) {
    450450          FetchAndUpdateJob(jobItem.JobDto.Id);
    451451          DisposeOptimizerMappings(jobItem.JobDto.Id);
    452         } else if (jobItem.State == State.Failed) {
     452        } else if (jobItem.State == JobState.Failed) {
    453453          DisposeOptimizerMappings(jobItem.JobDto.Id);
    454454        }
     
    517517        CoresNeeded = 1, // [chn] how to determine real cores needed?
    518518        PluginsNeeded = pluginsNeeded,
    519         State = State.Offline,
     519        State = JobState.Offline,
    520520        MemoryNeeded = 0,
    521521        UserId = Guid.Empty // [chn] set real userid here!
     
    556556            IExecutionEngineFacade executionEngineFacade = GetExecutionEngineFacade();
    557557            IEnumerable<Guid> jobIdsToQuery = from job in JobItems
    558                                               where job.State != State.Finished &&
    559                                               job.State != State.Failed
     558                                              where job.State != JobState.Finished &&
     559                                              job.State != JobState.Failed
    560560                                              select job.JobDto.Id;
    561561            if (jobIdsToQuery.Count() > 0) {
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/JobItem.cs

    r4263 r4264  
    2222    public override Image ItemImage {
    2323      get {
    24         if (State == State.Offline) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutablePrepared;
    25         else if (State == State.Idle) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutablePrepared;
    26         else if (State == State.Calculating) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutableStarted;
    27         else if (State == State.Abort) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutableStopped;
    28         else if (State == State.Failed) return HeuristicLab.Common.Resources.VS2008ImageLibrary.Error;
    29         else if (State == State.Finished) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutableStopped;
     24        if (State == JobState.Offline) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutablePrepared;
     25        else if (State == JobState.Calculating) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutableStarted;
     26        else if (State == JobState.Aborted) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutableStopped;
     27        else if (State == JobState.Failed) return HeuristicLab.Common.Resources.VS2008ImageLibrary.Error;
     28        else if (State == JobState.Finished) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutableStopped;
    3029        else return HeuristicLab.Common.Resources.VS2008ImageLibrary.Event;
    3130      }
     
    6362    }
    6463
    65     public State State {
     64    public JobState State {
    6665      get { return jobResult != null ? JobResult.State : JobDto.State; }
    6766    }
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Console/3.3/AddJobForm.cs

    r4263 r4264  
    111111        if (numJobs > 0) {
    112112          for (int i = 0; i < numJobs; i++) {
    113             JobDto job = new JobDto { State = State.Offline, CoresNeeded = 1 };
     113            JobDto job = new JobDto { State = JobState.Offline, CoresNeeded = 1 };
    114114           
    115115            // if project selected (0 -> none)
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Console/3.3/HiveServerManagementConsole.cs

    r4263 r4264  
    110110    void jdf_NewDataAvailable(object sender, EventArgs e) {
    111111      JobDataFetcher fetcher = (JobDataFetcher) sender;
    112       if (fetcher.PollStates.Contains(State.Finished)) {
    113         updateJobListView(fetcher, lv_finishedJobs, 0);
    114       } else if(fetcher.PollStates.Contains(State.Calculating)) {
    115         updateJobListView(fetcher, lv_calculatingJobs, 1);
    116       } else if (fetcher.PollStates.Contains(State.Offline)) {
    117         updateJobListView(fetcher, lv_offlineJobs, 2);
    118       }
    119     }
    120 
    121     private void updateJobListView(JobDataFetcher fetcher, ListView listView, int category) {
     112      if (fetcher.PollStates.Contains(JobState.Finished)) {
     113        UpdateJobListView(fetcher, lv_finishedJobs, 0);
     114      } else if(fetcher.PollStates.Contains(JobState.Calculating)) {
     115        UpdateJobListView(fetcher, lv_calculatingJobs, 1);
     116      } else if (fetcher.PollStates.Contains(JobState.Offline)) {
     117        UpdateJobListView(fetcher, lv_offlineJobs, 2);
     118      }
     119    }
     120
     121    private void UpdateJobListView(JobDataFetcher fetcher, ListView listView, int category) {
    122122      if (listView.InvokeRequired) {
    123         listView.Invoke(new updateListView(updateJobListView), new object[] { fetcher, listView, category });
     123        listView.Invoke(new updateListView(UpdateJobListView), new object[] { fetcher, listView, category });
    124124      } else {
    125125        listView.BeginUpdate();
     
    137137    private void Init() {
    138138
    139       jdfFinished = new JobDataFetcher(new State[] {State.Finished}, 50);
    140       jdfCalculating = new JobDataFetcher(new State[] {State.Calculating}, 50);
    141       jdfOffline = new JobDataFetcher(new State[] {State.Offline}, 50);
     139      jdfFinished = new JobDataFetcher(new JobState[] {JobState.Finished}, 50);
     140      jdfCalculating = new JobDataFetcher(new JobState[] {JobState.Calculating}, 50);
     141      jdfOffline = new JobDataFetcher(new JobState[] {JobState.Offline}, 50);
    142142
    143143      cmb_finishedJob_count.SelectedItem = "50";
     
    348348          int percentageUsage = CapacityRam(((ClientDto)resource).NrOfCores, ((ClientDto)resource).NrOfFreeCores);
    349349          int usage = 3;
    350           if ((((ClientDto)resource).State != State.Offline) &&
    351             (((ClientDto)resource).State != State.NullState)) {
     350          if ((((ClientDto)resource).State != SlaveState.Offline) &&
     351            (((ClientDto)resource).State != SlaveState.NullState)) {
    352352            if ((percentageUsage >= 0) && (percentageUsage <= 25)) {
    353353              usage = 0;
     
    419419      //lvSnapshots.Enabled = true;
    420420
    421       if (job.State == State.Offline) {
     421      if (job.State == JobState.Offline) {
    422422        pbJobControl.Image = ilLargeImgJob.Images[2];
    423       } else if (job.State == State.Calculating) {
     423      } else if (job.State == JobState.Calculating) {
    424424        pbJobControl.Image = ilLargeImgJob.Images[1];
    425       } else if (job.State == State.Finished) {
     425      } else if (job.State == JobState.Finished) {
    426426        pbJobControl.Image = ilLargeImgJob.Images[0];
    427427      }
     
    480480        lvJobDetails.Items.Add(lvi);
    481481
    482         if (job.State == State.Finished) {
     482        if (job.State == JobState.Finished) {
    483483          lvi = null;
    484484            lvi = new ListViewItem();
     
    500500        int percentageUsage = CapacityRam(currentClient.NrOfCores, currentClient.NrOfFreeCores);
    501501        int usage = 3;
    502         if ((currentClient.State != State.Offline) && (currentClient.State != State.NullState)) {
     502        if ((currentClient.State != SlaveState.Offline) && (currentClient.State != SlaveState.NullState)) {
    503503          if ((percentageUsage >= 0) && (percentageUsage <= 25)) {
    504504            usage = 0;
     
    630630        JobDto selectedJob = (JobDto)jlv.SelectedItems[0].Tag;
    631631
    632         if (selectedJob != null && selectedJob.State == State.Calculating) {
     632        if (selectedJob != null && selectedJob.State == JobState.Calculating) {
    633633          jlv.ContextMenuStrip.Items.Add(offlineItemAbortJob);
    634634          jlv.ContextMenuStrip.Items.Add(menuItemGetSnapshot);
     
    806806              change = true;
    807807            }
    808             if (job.State != State.Offline) {
     808            if (job.State != JobState.Offline) {
    809809              if ((!IsEqual(job.Client, jobold.Client)) || (job.State != jobold.State)
    810810                   || (job.Percentage != jobold.Percentage)) {
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Console/3.3/JobDataFetcher.cs

    r4263 r4264  
    1313namespace HeuristicLab.Hive.Server.ServerConsole {
    1414  public class JobDataFetcher {
    15     private List<State> pollStates;
     15    private List<JobState> pollStates;
    1616
    17     public IEnumerable<State> PollStates {
     17    public IEnumerable<JobState> PollStates {
    1818      get { return pollStates; }
    1919    }
     
    4848    public int CurrentPage { get; set; }
    4949
    50     public JobDataFetcher(IEnumerable<State> states, int nrOfEntries) {
    51       pollStates = new List<State>();
     50    public JobDataFetcher(IEnumerable<JobState> states, int nrOfEntries) {
     51      pollStates = new List<JobState>();
    5252      CachedJobs = new List<JobDto>();
    5353      NrOfEntriesOnPage = nrOfEntries;
     
    8585      // * using for loop
    8686
    87       State[] pollStatesCopy = PollStates.ToArray();
     87      JobState[] pollStatesCopy = PollStates.ToArray();
    8888      for (int i = 0; i < pollStatesCopy.Length; i++) {
    8989        ResponseList<JobDto> resList = jobManager.GetAllJobsWithFilter(pollStatesCopy[i], CurrentPage * NrOfEntriesOnPage, NrOfEntriesOnPage);
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Console/3.3/JobListView.cs

    r4116 r4264  
    2828    private JobDataFetcher jdf;
    2929
    30     public JobListView(IEnumerable<State> states, int nrOfEntries)
     30    public JobListView(IEnumerable<JobState> states, int nrOfEntries)
    3131      : base() {
    3232      InitializeComponent();
     
    4040      JobDataFetcher datafetcher = (JobDataFetcher) sender;
    4141      this.BeginUpdate();
    42       if (datafetcher.PollStates.Contains(State.Finished)) {
     42      if (datafetcher.PollStates.Contains(JobState.Finished)) {
    4343        this.Items.Clear();
    4444        ListViewItem lviDummy = new ListViewItem("blahr", 0);
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/DefaultScheduler.cs

    r4263 r4264  
    2121
    2222    public bool ExistsJobForSlave(HeartBeatData hbData) {
    23       List<JobDto> allOfflineJobsForSlave = new List<JobDto>(DaoLocator.JobDao.FindFittingJobsForSlave(State.Offline, hbData.FreeCores, hbData.FreeMemory, hbData.SlaveId));
     23      List<JobDto> allOfflineJobsForSlave = new List<JobDto>(DaoLocator.JobDao.FindFittingJobsForSlave(JobState.Offline, hbData.FreeCores, hbData.FreeMemory, hbData.SlaveId));
    2424      return (allOfflineJobsForSlave != null && allOfflineJobsForSlave.Count > 0);
    2525    }
     
    3131        using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = ApplicationConstants.ISOLATION_LEVEL_SCOPE })) {
    3232          ClientDto slave = DaoLocator.ClientDao.FindById(slaveId);
    33           LinkedList<JobDto> allOfflineJobsForSlave = new LinkedList<JobDto>(DaoLocator.JobDao.FindFittingJobsForSlave(State.Offline, slave.NrOfFreeCores, slave.FreeMemory, slave.Id));
     33          LinkedList<JobDto> allOfflineJobsForSlave = new LinkedList<JobDto>(DaoLocator.JobDao.FindFittingJobsForSlave(JobState.Offline, slave.NrOfFreeCores, slave.FreeMemory, slave.Id));
    3434          if (allOfflineJobsForSlave != null && allOfflineJobsForSlave.Count > 0) {
    3535            jobToCalculate = allOfflineJobsForSlave.First.Value;
    36             jobToCalculate.State = State.Calculating;
     36            jobToCalculate.State = JobState.Calculating;
    3737            jobToCalculate.Client = slave;
    38             jobToCalculate.Client.State = State.Calculating;
     38            jobToCalculate.Client.State = SlaveState.Calculating;
    3939            jobToCalculate.DateCalculated = DateTime.Now;
    4040            DaoLocator.JobDao.AssignSlaveToJob(slave.Id, jobToCalculate.Id);
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/Facades/ServerConsoleFacade.cs

    r4263 r4264  
    108108    }
    109109
    110     public ResponseList<JobDto> GetAllJobsWithFilter(State jobState, int offset, int count) {
     110    public ResponseList<JobDto> GetAllJobsWithFilter(JobState jobState, int offset, int count) {
    111111      using (contextFactory.GetContext(false)) {
    112112        secMan.Authorize("AccessJobs", sessionID, Guid.Empty);
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/JobManager.cs

    r4263 r4264  
    5858      List<JobDto> allJobs = new List<JobDto>(DaoLocator.JobDao.FindAll());
    5959      foreach (JobDto curJob in allJobs) {
    60         if (curJob.State != State.Calculating && curJob.State != State.Finished) {
     60        if (curJob.State != JobState.Calculating && curJob.State != JobState.Finished) {
    6161          DaoLocator.JobDao.SetJobOffline(curJob);
    6262        }
     
    8686    }
    8787
    88     public ResponseList<JobDto> GetAllJobsWithFilter(State jobState, int offset, int count) {
     88    public ResponseList<JobDto> GetAllJobsWithFilter(JobState jobState, int offset, int count) {
    8989      ResponseList<JobDto> response = new ResponseList<JobDto>();
    9090      response.List = new List<JobDto>(DaoLocator.JobDao.FindWithLimitations(jobState, offset, count));
     
    153153
    154154      if (job != null && job.JobInfo != null) {
    155         if (job.JobInfo.State != State.Offline) {
     155        if (job.JobInfo.State != JobState.Offline) {
    156156          response.StatusMessage = ResponseStatus.AddNewJob_JobStateMustBeOffline;
    157157          return response;
     
    222222
    223223      //if it's a snapshot but the result hasn't reached the server yet...
    224       if (snapshot && (job.State == State.RequestSnapshot || job.State == State.RequestSnapshotSent)) {
     224      if (snapshot && (job.State == JobState.SnapshotRequested || job.State == JobState.SnapshotSent)) {
    225225        response.StatusMessage = ResponseStatus.GetLastSerializedResult_JobResultNotYetThere;
    226226
     
    229229
    230230      //if it's NOT a snapshot, NEITHER request NOR is it finished
    231       if (!requested && !snapshot && job.State != State.Finished) {
     231      if (!requested && !snapshot && job.State != JobState.Finished) {
    232232        response.StatusMessage = ResponseStatus.GetLastSerializedResult_JobResultNotYetThere;
    233233
     
    248248
    249249      JobDto job = DaoLocator.JobDao.FindById(jobId);
    250       if (job.State == State.RequestSnapshot || job.State == State.RequestSnapshotSent) {
     250      if (job.State == JobState.SnapshotRequested || job.State == JobState.SnapshotSent) {
    251251        response.StatusMessage = ResponseStatus.RequestSnapshot_SnapshotAlreadyRequested;
    252252        return response;
    253253      }
    254       if (job.State != State.Calculating) {
     254      if (job.State != JobState.Calculating) {
    255255        response.StatusMessage = ResponseStatus.RequestSnapshot_JobIsNotBeeingCalculated;
    256256        return response;
    257257      }
    258258      // job is in correct state
    259       job.State = State.RequestSnapshot;
     259      job.State = JobState.SnapshotRequested;
    260260      DaoLocator.JobDao.Update(job);
    261261
     
    275275        return response; // no commit needed
    276276      }
    277       if (job.State == State.Abort) {
     277      if (job.State == JobState.Aborted) {
    278278        //response.Success = true;
    279279        response.StatusMessage = ResponseStatus.AbortJob_AbortAlreadyRequested;
    280280        return response; // no commit needed
    281281      }
    282       if (job.State != State.Calculating && job.State != State.RequestSnapshot && job.State != State.RequestSnapshotSent) {
     282      if (job.State != JobState.Calculating && job.State != JobState.SnapshotRequested && job.State != JobState.SnapshotSent) {
    283283        //response.Success = false;
    284284        response.StatusMessage = ResponseStatus.AbortJob_JobIsNotBeeingCalculated;
     
    286286      }
    287287      // job is in correct state
    288       job.State = State.Abort;
     288      job.State = JobState.Aborted;
    289289      DaoLocator.JobDao.Update(job);
    290290
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/SlaveCommunicator.cs

    r4263 r4264  
    8383
    8484        foreach (ClientDto client in allClients) {
    85           if (client.State != State.Offline && client.State != State.NullState) {
     85          if (client.State != SlaveState.Offline && client.State != SlaveState.NullState) {
    8686            heartbeatLock.EnterUpgradeableReadLock();
    8787
     
    8989              Logger.Info("Client " + client.Id +
    9090                              " wasn't offline but hasn't sent heartbeats - setting offline");
    91               client.State = State.Offline;
     91              client.State = SlaveState.Offline;
    9292              DaoLocator.ClientDao.Update(client);
    9393              Logger.Info("Client " + client.Id +
     
    114114                Logger.Debug("setting client offline");
    115115                // client must be set offline
    116                 client.State = State.Offline;
     116                client.State = SlaveState.Offline;
    117117
    118118                //clientAdapter.Update(client);
     
    147147
    148148    private void CheckForPendingJobs() {
    149       IList<JobDto> pendingJobsInDB = new List<JobDto>(DaoLocator.JobDao.GetJobsByState(State.Pending));
     149      IList<JobDto> pendingJobsInDB = new List<JobDto>(DaoLocator.JobDao.GetJobsByState(JobState.Pending));
    150150
    151151      foreach (JobDto currJob in pendingJobsInDB) {
     
    153153          if (pendingJobs.ContainsKey(currJob.Id)) {
    154154            if (pendingJobs[currJob.Id] <= 0) {
    155               currJob.State = State.Offline;
     155              currJob.State = JobState.Offline;
    156156              DaoLocator.JobDao.Update(currJob);
    157157            } else {
     
    186186      //Really set offline?
    187187      //Reconnect issues with the currently calculating jobs
    188       slaveInfo.State = State.Idle;
     188      slaveInfo.State = SlaveState.Idle;
    189189      slaveInfo.CalendarSyncStatus = dbClient != null ? dbClient.CalendarSyncStatus : CalendarState.NotAllowedToFetch;
    190190
     
    255255      Logger.Debug("END Finished Client Fetching");
    256256      // check if the client is logged in
    257       if (client.State == State.Offline || client.State == State.NullState) {
     257      if (client.State == SlaveState.Offline || client.State == SlaveState.NullState) {
    258258        // response.Success = false;
    259259        response.StatusMessage = ResponseStatus.ProcessHeartBeat_UserNotLoggedIn;
     
    359359            response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.AbortJob, curJob.Id));
    360360            Logger.Error("There is no job calculated by this user " + hbData.SlaveId + " Job: " + curJob);
    361           } else if (curJob.State == State.Abort) {
     361          } else if (curJob.State == JobState.Aborted) {
    362362            // a request to abort the job has been set
    363363            response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.AbortJob, curJob.Id));
    364             curJob.State = State.Finished;
     364            curJob.State = JobState.Finished;
    365365          } else {
    366366            // save job progress
    367367            curJob.Percentage = jobProgress.Value;
    368368
    369             if (curJob.State == State.RequestSnapshot) {
     369            if (curJob.State == JobState.SnapshotRequested) {
    370370              // a request for a snapshot has been set
    371371              response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.RequestSnapshot, curJob.Id));
    372               curJob.State = State.RequestSnapshotSent;
     372              curJob.State = JobState.SnapshotSent;
    373373            }
    374374          }
     
    394394                Logger.Error("Job TTL reached Zero, Job gets removed: " + currJob + " and set back to offline. User that sucks: " + currJob.Client);
    395395
    396                 currJob.State = State.Offline;
     396                currJob.State = JobState.Offline;
    397397                DaoLocator.JobDao.Update(currJob);
    398398
     
    403403            } else {
    404404              Logger.Error("Job ID wasn't with the heartbeats:  " + currJob);
    405               currJob.State = State.Offline;
     405              currJob.State = JobState.Offline;
    406406              DaoLocator.JobDao.Update(currJob);
    407407            }
     
    516516        return response;
    517517      }
    518       if (job.JobInfo.State == State.Abort) {
     518      if (job.JobInfo.State == JobState.Aborted) {
    519519        //response.Success = false;
    520520        response.StatusMessage = ResponseStatus.ProcessJobResult_JobAborted;
     
    545545        return response;
    546546      }
    547       if (job.JobInfo.State == State.Finished) {
     547      if (job.JobInfo.State == JobState.Finished) {
    548548        response.StatusMessage = ResponseStatus.Ok;
    549549        response.JobId = jobId;
     
    555555      }
    556556      //Todo: RequestsnapshotSent => calculating?
    557       if (job.JobInfo.State == State.RequestSnapshotSent) {
    558         job.JobInfo.State = State.Calculating;
    559       }
    560       if (job.JobInfo.State != State.Calculating && job.JobInfo.State != State.Pending) {
     557      if (job.JobInfo.State == JobState.SnapshotSent) {
     558        job.JobInfo.State = JobState.Calculating;
     559      }
     560      if (job.JobInfo.State != JobState.Calculating && job.JobInfo.State != JobState.Pending) {
    561561        //response.Success = false;
    562562        response.StatusMessage = ResponseStatus.ProcessJobResult_InvalidJobState;
     
    571571
    572572      if (!string.IsNullOrEmpty(exception)) {
    573         job.JobInfo.State = State.Failed;
     573        job.JobInfo.State = JobState.Failed;
    574574        job.JobInfo.Exception = exception;
    575575        job.JobInfo.DateFinished = DateTime.Now;
    576576      } else if (finished) {
    577         job.JobInfo.State = State.Finished;
     577        job.JobInfo.State = JobState.Finished;
    578578        job.JobInfo.DateFinished = DateTime.Now;
    579579      }
     
    638638        return response;
    639639      }
    640       if (client.State == State.Calculating) {
     640      if (client.State == SlaveState.Calculating) {
    641641        // check wich job the client was calculating and reset it
    642642        IEnumerable<JobDto> jobsOfClient = DaoLocator.JobDao.FindActiveJobsOfSlave(client);
    643643        foreach (JobDto job in jobsOfClient) {
    644           if (job.State != State.Finished)
     644          if (job.State != JobState.Finished)
    645645            DaoLocator.JobDao.SetJobOffline(job);
    646646        }
    647647      }
    648648
    649       client.State = State.Offline;
     649      client.State = SlaveState.Offline;
    650650      DaoLocator.ClientDao.Update(client);
    651651
     
    668668        return response;
    669669      }
    670       if (job.State == State.Finished) {
     670      if (job.State == JobState.Finished) {
    671671        //response.Success = true;
    672672        response.StatusMessage = ResponseStatus.IsJobStillNeeded_JobAlreadyFinished;
     
    674674        return response;
    675675      }
    676       job.State = State.Pending;
     676      job.State = JobState.Pending;
    677677      lock (pendingJobs) {
    678678        pendingJobs.Add(job.Id, PENDING_TIMEOUT);
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.DataAccess/3.3/IJobDao.cs

    r4253 r4264  
    99    IEnumerable<JobDto> FindActiveJobsOfSlave(ClientDto slave);
    1010
    11     IEnumerable<JobDto> GetJobsByState(State state);
     11    IEnumerable<JobDto> GetJobsByState(JobState state);
    1212
    1313    void AssignSlaveToJob(Guid slaveId, Guid jobId);
     
    1919    byte[] GetBinaryJobFile(Guid jobId);
    2020
    21     IEnumerable<JobDto> FindFittingJobsForSlave(State state, int freeCores, int freeMemory, Guid slaveGuid);
     21    IEnumerable<JobDto> FindFittingJobsForSlave(JobState state, int freeCores, int freeMemory, Guid slaveGuid);
    2222    Stream GetSerializedJobStream(Guid jobId);
    2323
    24     IEnumerable<JobDto> FindWithLimitations(State jobState, int offset, int count);
     24    IEnumerable<JobDto> FindWithLimitations(JobState jobState, int offset, int count);
    2525
    2626    void SetBinaryJobFile(Guid jobId, byte[] data);
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/ClientDao.cs

    r4116 r4264  
    8383      target.NumberOfCores = source.NrOfCores;
    8484      target.NumberOfFreeCores = source.NrOfFreeCores;
    85       target.Status = Enum.GetName(typeof(State), source.State);
     85      target.Status = Enum.GetName(typeof(JobState), source.State);
    8686      return target;
    8787    }
     
    101101      target.NrOfCores = source.NumberOfCores ?? 0;
    102102      target.NrOfFreeCores = source.NumberOfFreeCores ?? 0;
    103       target.State = (State) Enum.Parse(typeof (State), source.Status, true);
     103      target.State = (SlaveState)Enum.Parse(typeof(SlaveState), source.Status, true);
    104104      return target;
    105105    }
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/JobDao.cs

    r4253 r4264  
    2525    }
    2626
    27     public IEnumerable<JobDto> FindWithLimitations(State jobState, int offset, int count) {
     27    public IEnumerable<JobDto> FindWithLimitations(JobState jobState, int offset, int count) {
    2828      IQueryable<JobDto> query = null;
    29       if (jobState == State.Finished) {
     29      if (jobState == JobState.Finished) {
    3030         query = from job in Context.Jobs
    31                  where job.JobState == Enum.GetName(typeof (State), jobState)
     31                 where job.JobState == Enum.GetName(typeof (JobState), jobState)
    3232                 orderby job.DateFinished
    3333                 select EntityToDto(job, null);
    34       } else if (jobState == State.Calculating || jobState == State.RequestSnapshot || jobState == State.RequestSnapshotSent) {
     34      } else if (jobState == JobState.Calculating || jobState == JobState.SnapshotRequested || jobState == JobState.SnapshotSent) {
    3535        query = from job in Context.Jobs
    36                     where job.JobState == Enum.GetName(typeof(State), jobState)
     36                    where job.JobState == Enum.GetName(typeof(JobState), jobState)
    3737                    orderby job.DateCalculated
    3838                    select EntityToDto(job, null);
    3939      } else {
    4040        query = from job in Context.Jobs
    41                     where job.JobState == Enum.GetName(typeof(State), jobState)
     41                    where job.JobState == Enum.GetName(typeof(JobState), jobState)
    4242                    orderby job.DateCreated
    4343                    select EntityToDto(job, null);
     
    9595    public IEnumerable<JobDto> FindActiveJobsOfSlave(ClientDto client) {
    9696      return (from j in Context.Jobs
    97               where (j.JobState == Enum.GetName(typeof (State), State.Calculating) ||
    98                      j.JobState == Enum.GetName(typeof (State), State.Abort) ||
    99                      j.JobState == Enum.GetName(typeof (State), State.RequestSnapshot) ||
    100                      j.JobState == Enum.GetName(typeof (State), State.RequestSnapshotSent)) &&
     97              where (j.JobState == Enum.GetName(typeof (JobState), JobState.Calculating) ||
     98                     j.JobState == Enum.GetName(typeof (JobState), JobState.Aborted) ||
     99                     j.JobState == Enum.GetName(typeof (JobState), JobState.SnapshotRequested) ||
     100                     j.JobState == Enum.GetName(typeof (JobState), JobState.SnapshotSent)) &&
    101101                    (j.ResourceId.Equals(client.Id))
    102102              select EntityToDto(j, null)).ToList();
    103103    }
    104104
    105     public IEnumerable<JobDto> FindFittingJobsForSlave(State state, int freeCores, int freeMemory, Guid clientId) {
     105    public IEnumerable<JobDto> FindFittingJobsForSlave(JobState state, int freeCores, int freeMemory, Guid clientId) {
    106106      ClientGroupDao cgd = new ClientGroupDao();
    107107     
     
    111111     
    112112      var q = (from ar in Context.AssignedResources               
    113                where ar.Job.JobState == Enum.GetName(typeof (State), State.Offline) &&
     113               where ar.Job.JobState == Enum.GetName(typeof (JobState), JobState.Offline) &&
    114114                     ar.Job.CoresNeeded <= freeCores &&
    115115                     ar.Job.MemoryNeeded <= freeMemory &&
     
    120120    }
    121121
    122     public IEnumerable<JobDto> GetJobsByState(State state) {
     122    public IEnumerable<JobDto> GetJobsByState(JobState state) {
    123123      return (from j in Context.Jobs
    124               where (j.JobState == Enum.GetName(typeof (State), state))
     124              where (j.JobState == Enum.GetName(typeof (JobState), state))
    125125              select EntityToDto(j, null)).ToList();
    126126    }
     
    137137      Job j = Context.Jobs.SingleOrDefault(jq => jq.JobId.Equals(job.Id));
    138138      j.Client = null;
    139       j.JobState = Enum.GetName(typeof(State), State.Offline);
     139      j.JobState = Enum.GetName(typeof(JobState), JobState.Offline);
    140140      CommitChanges();
    141141    }
     
    177177
    178178      target.Priority = source.Priority;
    179       target.JobState = Enum.GetName(typeof(State), source.State);
     179      target.JobState = Enum.GetName(typeof(JobState), source.State);
    180180      return target;
    181181    }
     
    206206     
    207207      target.Priority = source.Priority;
    208       target.State = (State) Enum.Parse(typeof (State), source.JobState, true);
     208      target.State = (JobState) Enum.Parse(typeof (JobState), source.JobState, true);
    209209      return target;
    210210    }
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Core/3.3/Core.cs

    r4263 r4264  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    26 using HeuristicLab.Hive.Slave.ExecutionEngine;
     24using System.IO;
     25using System.Threading;
     26using HeuristicLab.Core;
     27using HeuristicLab.Hive.Contracts;
     28using HeuristicLab.Hive.Contracts.BusinessObjects;
     29using HeuristicLab.Hive.Contracts.ResponseObjects;
    2730using HeuristicLab.Hive.Slave.Common;
    28 using System.Threading;
    29 using System.Reflection;
    30 using System.Diagnostics;
    31 using System.Security.Permissions;
    32 using System.Security.Policy;
    33 using System.Security;
    3431using HeuristicLab.Hive.Slave.Communication;
    35 using HeuristicLab.Hive.Contracts.BusinessObjects;
    36 using HeuristicLab.Hive.Contracts;
    37 using System.Runtime.Remoting.Messaging;
    38 using HeuristicLab.PluginInfrastructure;
    39 using System.ServiceModel;
    40 using System.ServiceModel.Description;
     32using HeuristicLab.Hive.Slave.Communication.ServerService;
    4133using HeuristicLab.Hive.Slave.Core.ClientConsoleService;
    4234using HeuristicLab.Hive.Slave.Core.ConfigurationManager;
    43 using HeuristicLab.Hive.Slave.Communication.ServerService;
    44 using HeuristicLab.Hive.JobBase;
    4535using HeuristicLab.Hive.Slave.Core.JobStorage;
     36using HeuristicLab.Hive.Slave.ExecutionEngine;
    4637using HeuristicLab.Tracing;
    47 using HeuristicLab.Core;
    48 using System.IO;
    49 using HeuristicLab.Hive.Contracts.ResponseObjects;
    5038
    5139namespace HeuristicLab.Hive.Slave.Core {
     
    10290
    10391      //Initialize the heartbeat
    104       beat = new Heartbeat { Interval = 10000 };
     92      beat = new Heartbeat { Interval = new TimeSpan(0, 0, 10) };
    10593      beat.StartHeartbeat();
    10694
     
    171159          Logger.Info("Uptime Limit reached, storing jobs and sending them back");
    172160
    173           //check if there are running jobs
    174           if (engines.Count > 0) {
    175             //make sure there is no more fetching of jobs while the snapshots get processed
    176             CurrentlyFetching = true;
    177             //request a snapshot of each running job
    178             foreach (KeyValuePair<Guid, Executor> kvp in engines) {
    179               kvp.Value.RequestSnapshot();
    180             }
    181 
    182           } else {
    183             //Disconnect afterwards
    184             WcfService.Instance.Disconnect();
    185           }
     161          ShutdownRunningJobsAndSubmitSnapshots();
    186162          break;
    187163
     
    209185          WcfService.Instance.Logout(ConfigManager.Instance.GetClientInfo().Id);
    210186          break;
     187      }
     188    }
     189
     190    private void ShutdownRunningJobsAndSubmitSnapshots() {
     191      //check if there are running jobs
     192      if (engines.Count > 0) {
     193        //make sure there is no more fetching of jobs while the snapshots get processed
     194        CurrentlyFetching = true;
     195        //request a snapshot of each running job
     196        foreach (KeyValuePair<Guid, Executor> kvp in engines) {
     197          kvp.Value.RequestSnapshot();
     198        }
     199
    211200      }
    212201    }
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Core/3.3/Heartbeat.cs

    r4254 r4264  
    3333using HeuristicLab.Hive.Slave.Communication.ServerService;
    3434using HeuristicLab.Tracing;
     35using System.Threading;
    3536//using BO = HeuristicLab.Hive.Contracts.BusinessObjects;
    3637
     
    4344    private bool offline;
    4445
    45     public double Interval { get; set; }
    46     private Timer heartbeatTimer = null;
     46    public TimeSpan Interval { get; set; }
     47
     48    private Thread heartBeatThread;
    4749
    4850    private static object locker = new object();
    4951
    5052    public Heartbeat() {
    51       Interval = 100;
     53      Interval = new TimeSpan(0,0,10);
    5254    }
    5355
    54     public Heartbeat(double interval) {
     56    public Heartbeat(TimeSpan interval) {
    5557      Interval = interval;
    5658    }
     
    5860    private WcfService wcfService;
    5961
     62    private bool abortThreadPending;
     63
    6064    /// <summary>
    6165    /// Starts the Heartbeat signal.
    6266    /// </summary>
    6367    public void StartHeartbeat() {
    64       heartbeatTimer = new System.Timers.Timer();
    65       heartbeatTimer.Interval = this.Interval;
    66       heartbeatTimer.AutoReset = true;
    67       heartbeatTimer.Elapsed += new ElapsedEventHandler(heartbeatTimer_Elapsed);
    6868      wcfService = WcfService.Instance;
    6969      wcfService.ProcessHeartBeatCompleted += new EventHandler<ProcessHeartBeatCompletedEventArgs>(wcfService_ProcessHeartBeatCompleted);
    70       heartbeatTimer.Start();
     70      abortThreadPending = false;
     71      heartBeatThread = GetHeartBeatThread();
     72      heartBeatThread.Start();
    7173    }
    7274
    73     /// <summary>
    74     /// This Method is called every time the timer ticks
    75     /// </summary>
    76     /// <param name="sender"></param>
    77     /// <param name="e"></param>
    78     void heartbeatTimer_Elapsed(object sender, ElapsedEventArgs e) {
    79       lock (locker) {
    80         // check if cwfService is disconnected for any reason (should happen at first heartbeat)
    81         // [chn] TODO: Client should always send heartbeats. when calendar disallows he should tell the server he does not want to compute anything
    82         if (wcfService.ConnState == NetworkEnum.WcfConnState.Disconnected &&
    83           (!UptimeManager.Instance.CalendarAvailable || UptimeManager.Instance.IsOnline())) {
    84           wcfService.Connect();
    85         }
    86         if (wcfService.ConnState == NetworkEnum.WcfConnState.Connected) {
    87           wcfService.LoginSync(ConfigManager.Instance.GetClientInfo());
    88         }
    89 
    90         ClientDto info = ConfigManager.Instance.GetClientInfo();
    91 
    92         PerformanceCounter counter = new PerformanceCounter("Memory", "Available Bytes", true);
    93         int mb = (int)(counter.NextValue() / 1024 / 1024);
    94 
    95         HeartBeatData heartBeatData = new HeartBeatData {
    96           SlaveId = info.Id,
    97           FreeCores = info.NrOfCores - ConfigManager.Instance.GetUsedCores(),
    98           FreeMemory = mb,
    99           JobProgress = ConfigManager.Instance.GetProgressOfAllJobs()
    100         };
    101 
    102         DateTime lastFullHour = DateTime.Parse(DateTime.Now.Hour.ToString() + ":00");
    103         TimeSpan span = DateTime.Now - lastFullHour;
    104         if (span.TotalSeconds < (Interval / 1000)) {
    105           if (UptimeManager.Instance.IsOnline() && UptimeManager.Instance.CalendarAvailable) {
    106             //That's quiet simple: Just reconnect and you're good for new jobs
    107             if (wcfService.ConnState != NetworkEnum.WcfConnState.Loggedin) {
    108               Logger.Info("Client goes online according to timetable");
     75    private Thread GetHeartBeatThread() {
     76      return new Thread(() => {
     77        while (!abortThreadPending) {
     78          lock (locker) {
     79            // check if cwfService is disconnected for any reason (should happen at first heartbeat)
     80            // [chn] TODO: Client should always send heartbeats. when calendar disallows he should tell the server he does not want to compute anything
     81            if (wcfService.ConnState == NetworkEnum.WcfConnState.Disconnected) {
    10982              wcfService.Connect();
    11083            }
    111           } else {
    112             //We have quit a lot of work to do here: snapshot all jobs, submit them back, then disconnect and then pray to god that nothing goes wrong
    113             MessageQueue.GetInstance().AddMessage(MessageContainer.MessageType.UptimeLimitDisconnect);
    114           }
    115         }
    116         if (wcfService.ConnState == NetworkEnum.WcfConnState.Failed) {
    117           wcfService.Connect();
    118         } else if (wcfService.ConnState == NetworkEnum.WcfConnState.Loggedin) {
    119           Logger.Debug("Sending Heartbeat: " + heartBeatData);
    120           wcfService.ProcessHeartBeatAsync(heartBeatData);
    121         }
    122       }
     84
     85            if (wcfService.ConnState == NetworkEnum.WcfConnState.Loggedin) {
     86
     87              // client is allowed to calculate stuff
     88              ClientDto info = ConfigManager.Instance.GetClientInfo();
     89             
     90              HeartBeatData heartBeatData = new HeartBeatData {
     91                SlaveId = info.Id,
     92                FreeCores = info.NrOfCores - ConfigManager.Instance.GetUsedCores(),
     93                FreeMemory = GetFreeMemory(),
     94                JobProgress = ConfigManager.Instance.GetProgressOfAllJobs(),
     95                IsAllowedToCalculate = UptimeManager.Instance.IsOnline() && UptimeManager.Instance.CalendarAvailable
     96              };
     97
     98              if (!heartBeatData.IsAllowedToCalculate) {
     99                // stop all running jobs and send snapshots to server
     100                MessageQueue.GetInstance().AddMessage(MessageContainer.MessageType.UptimeLimitDisconnect);
     101              }
     102
     103              Logger.Debug("Sending Heartbeat: " + heartBeatData);
     104              wcfService.ProcessHeartBeatAsync(heartBeatData);
     105            }
     106
     107          } // lock
     108          Thread.Sleep(Interval);
     109        } // while
     110        abortThreadPending = false;
     111      });
     112    }
     113
     114    private int GetFreeMemory() {
     115      PerformanceCounter counter = new PerformanceCounter("Memory", "Available Bytes", true);
     116      int mb = (int)(counter.NextValue() / 1024 / 1024);
     117      return mb;
    123118    }
    124119
     
    129124
    130125    public void StopHeartBeat() {
    131       heartbeatTimer.Dispose();
     126      abortThreadPending = true;
    132127    }
    133128  }
Note: See TracChangeset for help on using the changeset viewer.