Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/25/10 19:57:44 (14 years ago)
Author:
kgrading
Message:

improved the DAL further, changed minor details for the presentation (#830)

Location:
trunk/sources/HeuristicLab.Hive.Server.Core/3.2
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Server.Core/3.2/ClientCommunicator.cs

    r3203 r3220  
    4141using Linq = HeuristicLab.Hive.Server.LINQDataAccess;
    4242using System.Transactions;
     43using HeuristicLab.Hive.Server.LINQDataAccess;
    4344
    4445namespace HeuristicLab.Hive.Server.Core {
     
    107108                              " wasn't offline but hasn't sent heartbeats - Resetting all his jobs");
    108109              foreach (JobDto job in DaoLocator.JobDao.FindActiveJobsOfClient(client)) {
    109                 jobManager.ResetJobsDependingOnResults(job);
     110                //maybe implementa n additional Watchdog? Till then, just set them offline..
     111                DaoLocator.JobDao.SetJobOffline(job);               
     112                //jobManager.ResetJobsDependingOnResults(job);
    110113              }
    111114            } else {
     
    193196      heartbeatLock.ExitWriteLock();
    194197
     198      ClientDto dbClient = DaoLocator.ClientDao.FindById(clientInfo.Id);
     199
     200      //Really set offline?
     201      //Reconnect issues with the currently calculating jobs
    195202      clientInfo.State = State.idle;
    196 
    197       if (DaoLocator.ClientDao.FindById(clientInfo.Id) == null)
     203      clientInfo.CalendarSyncStatus = dbClient != null ? dbClient.CalendarSyncStatus : CalendarState.NotAllowedToFetch;
     204
     205      if (dbClient == null)
    198206        DaoLocator.ClientDao.Insert(clientInfo);
    199207      else
     
    336344    private void processJobProcess(HeartBeatData hbData, ResponseHB response) {
    337345      HiveLogger.Info(this.ToString() + " processJobProcess: Started for Client " + hbData.ClientId);
    338 
    339       if (hbData.JobProgress != null && hbData.JobProgress.Count > 0) {
    340         List<JobDto> jobsOfClient = new List<JobDto>(DaoLocator.JobDao.FindActiveJobsOfClient(DaoLocator.ClientDao.FindById(hbData.ClientId)));
     346      List<JobDto> jobsOfClient = new List<JobDto>(DaoLocator.JobDao.FindActiveJobsOfClient(DaoLocator.ClientDao.FindById(hbData.ClientId)));
     347      if (hbData.JobProgress != null && hbData.JobProgress.Count > 0) {       
    341348        if (jobsOfClient == null || jobsOfClient.Count == 0) {
    342349          response.Success = false;
     
    369376          DaoLocator.JobDao.Update(curJob);
    370377        }
    371         foreach (JobDto currJob in jobsOfClient) {
    372           bool found = false;
     378       }
     379      foreach (JobDto currJob in jobsOfClient) {
     380        bool found = false;
     381        if(hbData.JobProgress != null) {
    373382          foreach (Guid jobId in hbData.JobProgress.Keys) {
    374383            if (jobId == currJob.Id) {
     
    377386            }
    378387          }
    379           if (!found) {
    380             lock (newAssignedJobs) {
    381               if (newAssignedJobs.ContainsKey(currJob.Id)) {
    382                 newAssignedJobs[currJob.Id]--;
    383                 HiveLogger.Error(this.ToString() + " processJobProcess: Job TTL Reduced by one for job: " + currJob + "and is now: " + newAssignedJobs[currJob.Id] + ". User that sucks: " + currJob.Client);
    384                 if (newAssignedJobs[currJob.Id] <= 0) {
    385                   HiveLogger.Error(this.ToString() + " processJobProcess: Job TTL reached Zero, Job gets removed: " + currJob + " and set back to offline. User that sucks: " + currJob.Client);
    386 
    387                   currJob.State = State.offline;
    388                   DaoLocator.JobDao.Update(currJob);
    389 
    390                   response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.AbortJob, currJob.Id));
    391 
    392                   newAssignedJobs.Remove(currJob.Id);
    393                 }
    394               } else {
    395                 HiveLogger.Error(this.ToString() + " processJobProcess: Job ID wasn't with the heartbeats:  " + currJob);
     388        }
     389        if (!found) {
     390          lock (newAssignedJobs) {
     391            if (newAssignedJobs.ContainsKey(currJob.Id)) {
     392              newAssignedJobs[currJob.Id]--;
     393              HiveLogger.Error(this.ToString() + " processJobProcess: Job TTL Reduced by one for job: " + currJob + "and is now: " + newAssignedJobs[currJob.Id] + ". User that sucks: " + currJob.Client);
     394              if (newAssignedJobs[currJob.Id] <= 0) {
     395                HiveLogger.Error(this.ToString() + " processJobProcess: Job TTL reached Zero, Job gets removed: " + currJob + " and set back to offline. User that sucks: " + currJob.Client);
     396
    396397                currJob.State = State.offline;
    397398                DaoLocator.JobDao.Update(currJob);
    398               }
    399             } // lock
    400           } else {
    401             lock (newAssignedJobs) {
    402 
    403               if (newAssignedJobs.ContainsKey(currJob.Id)) {
    404                 HiveLogger.Info(this.ToString() + " processJobProcess: Job is sending a heart beat, removing it from the newAssignedJobList: " + currJob);
     399
     400                response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.AbortJob, currJob.Id));
     401
    405402                newAssignedJobs.Remove(currJob.Id);
    406403              }
     404            } else {
     405              HiveLogger.Error(this.ToString() + " processJobProcess: Job ID wasn't with the heartbeats:  " + currJob);
     406              currJob.State = State.offline;
     407              DaoLocator.JobDao.Update(currJob);
     408            }
     409          } // lock
     410        } else {
     411          lock (newAssignedJobs) {
     412
     413            if (newAssignedJobs.ContainsKey(currJob.Id)) {
     414              HiveLogger.Info(this.ToString() + " processJobProcess: Job is sending a heart beat, removing it from the newAssignedJobList: " + currJob);
     415              newAssignedJobs.Remove(currJob.Id);
    407416            }
    408417          }
  • trunk/sources/HeuristicLab.Hive.Server.Core/3.2/ClientFacade.cs

    r3203 r3220  
    3232using System.ServiceModel;
    3333using HeuristicLab.Hive.Server.Core.InternalInterfaces;
     34using System.Transactions;
    3435
    3536namespace HeuristicLab.Hive.Server.Core {
     
    103104        new MultiStream();
    104105
    105       ResponseJob job =
    106         this.SendJob(clientId);
     106      ResponseJob job = null;
     107
     108      job = this.SendJob(clientId);     
    107109
    108110      //first send response
     
    114116
    115117      //second stream the job binary data
    116       stream.AddStream(
    117         ((IInternalJobManager)(jobManager)).
    118         GetJobStreamById(
    119           job.Job.Id));
    120 
     118     
     119      if(job.Job != null)
     120        stream.AddStream(
     121          ((IInternalJobManager) (jobManager)).
     122            GetJobStreamById(
     123            job.Job.Id));
     124     
    121125      OperationContext clientContext = OperationContext.Current;
    122126        clientContext.OperationCompleted += new EventHandler(delegate(object sender, EventArgs args) {
  • trunk/sources/HeuristicLab.Hive.Server.Core/3.2/DbTestApp.cs

    r3011 r3220  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Data.SqlClient;
    2425using System.Text;
    2526using HeuristicLab.PluginInfrastructure;
     
    3536using HeuristicLab.Core;
    3637using HeuristicLab.Hive.Server.LINQDataAccess;
     38using System.Transactions;
    3739
    3840namespace HeuristicLab.Hive.Server {
    3941  [Application("Hive DB Test App", "Test Application for the Hive DataAccess Layer")]
    4042  class HiveDbTestApplication : ApplicationBase {
    41     /*  private void TestClientAdapter() {
    42         IClientAdapter clientAdapter =
    43           ServiceLocator.GetClientAdapter();
    44 
    45         ClientInfo client = new ClientInfo();
    46         client.Login = DateTime.Now;
    47         clientAdapter.Update(client);
    48 
    49         ClientInfo clientRead =
    50           clientAdapter.GetById(client.Id);
    51         Debug.Assert(
    52           clientRead != null &&
    53           client.Id == clientRead.Id);
    54 
    55         client.CpuSpeedPerCore = 2000;
    56         clientAdapter.Update(client);
    57         clientRead =
    58           clientAdapter.GetById(client.Id);
    59         Debug.Assert(
    60          clientRead != null &&
    61          client.Id == clientRead.Id &&
    62          clientRead.CpuSpeedPerCore == 2000);
    63 
    64         ICollection<ClientInfo> clients =
    65           clientAdapter.GetAll();
    66         int count = clients.Count;
    67 
    68         clientAdapter.Delete(client);
    69 
    70         clients = clientAdapter.GetAll();
    71         Debug.Assert(count - 1 == clients.Count);
    72       }
    73 
    74       private void TestClientGroupAdapter() {
    75         ISessionFactory factory =
    76           ServiceLocator.GetSessionFactory();
    77 
    78         ISession session =
    79           factory.GetSessionForCurrentThread();
    80 
    81         ITransaction trans = null;
    82 
    83         try {
    84           IClientGroupAdapter clientGroupAdapter =
    85           session.GetDataAdapter<ClientGroup, IClientGroupAdapter>();
    86 
    87           trans =
    88             session.BeginTransaction();
    89 
    90           ClientInfo client =
    91             new ClientInfo();
    92           client.Name = "Stefan";
    93           client.Login = DateTime.Now;
    94 
    95           ClientInfo client2 =
    96             new ClientInfo();
    97           client2.Name = "Martin";
    98           client2.Login = DateTime.Now;
    99 
    100           ClientInfo client3 =
    101             new ClientInfo();
    102           client3.Name = "Heinz";
    103           client3.Login = DateTime.Now;
    104 
    105           ClientGroup group =
    106             new ClientGroup();
    107 
    108           ClientGroup subGroup =
    109             new ClientGroup();
    110           subGroup.Resources.Add(client);
    111 
    112           group.Resources.Add(client3);
    113           group.Resources.Add(client2);
    114           group.Resources.Add(subGroup);
    115 
    116           clientGroupAdapter.Update(group);
    117 
    118           ClientGroup read =
    119             clientGroupAdapter.GetById(group.Id);
    120 
    121           ICollection<ClientGroup> clientGroups =
    122             clientGroupAdapter.GetAll();
    123 
    124           IClientAdapter clientAdapter =
    125             session.GetDataAdapter<ClientInfo, IClientAdapter>();
    126 
    127           clientAdapter.Delete(client3);
    128 
    129           read =
    130              clientGroupAdapter.GetById(group.Id);
    131 
    132           clientGroupAdapter.Delete(subGroup);
    133 
    134           read =
    135              clientGroupAdapter.GetById(group.Id);
    136 
    137           clientGroups =
    138             clientGroupAdapter.GetAll();
    139 
    140           clientGroupAdapter.Delete(group);
    141 
    142           clientGroups =
    143             clientGroupAdapter.GetAll();
    144 
    145           clientAdapter.Delete(client);
    146           clientAdapter.Delete(client2);
    147         }
    148         finally {
    149           if (trans != null)
    150             trans.Rollback();
    151 
    152           session.EndSession();
    153         }
    154       }
    155 
    156       private void InsertTestClientGroups() {
    157         ISessionFactory factory =
    158           ServiceLocator.GetSessionFactory();
    159 
    160         ISession session =
    161           factory.GetSessionForCurrentThread();
    162 
    163         ITransaction trans = null;
    164 
    165         try {
    166           IClientGroupAdapter clientGroupAdapter =
    167           session.GetDataAdapter<ClientGroup, IClientGroupAdapter>();
    168 
    169           trans =
    170             session.BeginTransaction();
    171 
    172           ClientInfo client =
    173             new ClientInfo();
    174           client.Name = "Stefan";
    175           client.Login = DateTime.Now;
    176 
    177           ClientInfo client2 =
    178             new ClientInfo();
    179           client2.Name = "Martin";
    180           client2.Login = DateTime.Now;
    181 
    182           ClientGroup group =
    183             new ClientGroup();
    184           group.Name = "Gruppe1";
    185 
    186           ClientGroup subGroup =
    187             new ClientGroup();
    188           subGroup.Name = "Untergruppe1";
    189           subGroup.Resources.Add(client);
    190 
    191           group.Resources.Add(client2);
    192           group.Resources.Add(subGroup);
    193 
    194           clientGroupAdapter.Update(group);
    195 
    196           trans.Commit();
    197         }
    198         finally {
    199           session.EndSession();
    200         }
    201       }
    202 
    203       private void TestJobAdapter() {
    204         IJobAdapter jobAdapter =
    205           ServiceLocator.GetJobAdapter();
    206         IClientAdapter clientAdapter =
    207           ServiceLocator.GetClientAdapter();
    208 
    209         Job job = new Job();
    210 
    211         ClientInfo client = new ClientInfo();
    212         client.Login = DateTime.Now;
    213 
    214         job.Client = client;
    215         jobAdapter.Update(job);
    216 
    217         ICollection<Job> jobs = jobAdapter.GetAll();
    218 
    219         jobAdapter.Delete(job);
    220         clientAdapter.Delete(client);
    221 
    222         jobs = jobAdapter.GetAll();
    223       }
    224 
    225       private void TestJobResultsAdapter() {
    226         Job job = new Job();
    227 
    228         ClientInfo client = new ClientInfo();
    229         client.Login = DateTime.Now;
    230 
    231         job.Client = client;
    232 
    233         IJobResultsAdapter resultsAdapter =
    234           ServiceLocator.GetJobResultsAdapter();
    235 
    236         byte[] resultByte = {0x0f, 0x1f, 0x2f, 0x3f, 0x4f};
    237 
    238         JobResult result = new JobResult();
    239         result.Client = client;
    240         result.Job = job;
    241         result.Result = resultByte;
    242 
    243         resultsAdapter.Update(result);
    244 
    245         JobResult read =
    246           resultsAdapter.GetById(result.Id);
    247         Debug.Assert(
    248           read.Id == result.Id &&
    249           result.Client.Id == read.Client.Id &&
    250           result.Job.Id == read.Job.Id &&
    251           result.Result == result.Result);
    252 
    253         int count =
    254           resultsAdapter.GetAll().Count;
    255 
    256         resultsAdapter.Delete(result);
    257 
    258         ICollection<JobResult> allResults =
    259           resultsAdapter.GetAll();
    260 
    261         Debug.Assert(allResults.Count == count - 1);
    262 
    263         IJobAdapter jboAdapter =
    264           ServiceLocator.GetJobAdapter();
    265         jboAdapter.Delete(job);
    266         IClientAdapter clientAdapter =
    267           ServiceLocator.GetClientAdapter();
    268         clientAdapter.Delete(client);
    269       }     
    270 
    271       private void TestTransaction() {
    272         ISessionFactory factory =
    273           ServiceLocator.GetSessionFactory();
    274 
    275         ISession session =
    276           factory.GetSessionForCurrentThread();
    277 
    278         IClientAdapter clientAdapter =
    279           session.GetDataAdapter<ClientInfo, IClientAdapter>();
    280 
    281         ITransaction trans =
    282           session.BeginTransaction();
    283 
    284         ClientInfo client = new ClientInfo();
    285         client.Login = DateTime.Now;
    286         clientAdapter.Update(client);
    287 
    288         trans.Rollback();
    289 
    290         session.EndSession();
    291       }  */
    292 
    293     private void TestJobStreaming() {
     43    /*private void TestJobStreaming() {
    29444      ISessionFactory factory =
    29545         ServiceLocator.GetSessionFactory();
     
    489239
    490240      //SpeedTest();
    491       TestJobBytearrFetching();
    492 
     241      //TestJobBytearrFetching();
     242      TestJobStreamFetching();
     243
     244    }
     245
     246    private void TestJobStreamFetching() {
     247      //using (TransactionScope scope = new TransactionScope()) {
     248      HiveDataContext context = ContextFactory.Context;
     249
     250      ContextFactory.Context.Connection.Open();
     251      ContextFactory.Context.Transaction = ContextFactory.Context.Connection.BeginTransaction();
     252     
     253      ClientFacade facade = new ClientFacade();
     254      Stream stream = facade.SendStreamedJob(new Guid("F5CFB334-66A0-417C-A585-71711BA21D3F"));
     255     
     256      byte[] buffer = new byte[3024];
     257      int read = 0;
     258     
     259      while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) {}
     260     
     261      stream.Close();
     262
     263      //Stream stream = DaoLocator.JobDao.GetSerializedJobStream(new Guid("bbb51f87-4e2f-4499-a9b6-884e589c78b6"));
     264      //}
    493265    }
    494266
  • trunk/sources/HeuristicLab.Hive.Server.Core/3.2/ExecutionEngineFacade.cs

    r3011 r3220  
    4444    }
    4545
     46    public ResponseObject<JobDto> AddJobWithGroupStrings(SerializedJob job, IEnumerable<string> resources) {     
     47      return jobManager.AddJobWithGroupStrings(job, resources);
     48    }
     49
    4650    public Response RequestSnapshot(Guid jobId) {
    4751      return jobManager.RequestSnapshot(jobId);
  • trunk/sources/HeuristicLab.Hive.Server.Core/3.2/JobManager.cs

    r3018 r3220  
    3434using HeuristicLab.Tracing;
    3535using System.Transactions;
     36using HeuristicLab.Hive.Server.LINQDataAccess;
    3637
    3738namespace HeuristicLab.Hive.Server.Core {
     
    149150      }
    150151    }   */
     152
     153    public ResponseObject<JobDto> AddJobWithGroupStrings(SerializedJob job, IEnumerable<string> resources) {
     154      IClientGroupDao cgd = DaoLocator.ClientGroupDao;
     155      foreach (string res in resources) {
     156        foreach(ClientGroupDto cg in cgd.FindByName(res)) {
     157          job.JobInfo.AssignedResourceIds.Add(cg.Id);
     158        }
     159      }
     160      return AddNewJob(job);
     161    }
    151162
    152163    /// <summary>
  • trunk/sources/HeuristicLab.Hive.Server.Core/3.2/ServerConsoleFacade.cs

    r3203 r3220  
    180180    }
    181181
     182    public ResponseObject<JobDto> AddJobWithGroupStrings(SerializedJob job, IEnumerable<string> resources) {
     183      return jobManager.AddJobWithGroupStrings(job, resources);
     184    }
    182185  }
    183186}
Note: See TracChangeset for help on using the changeset viewer.