Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Convert.cs @ 5404

Last change on this file since 5404 was 5404, checked in by cneumuel, 13 years ago

#1233

  • changed the workflow of aquireing a new job from server.
    • if a job is available for calculation, the slave receives the jobId already with the heartbeats. The job is then exclusively assigned to this slave.
  • extended the metainfo for a slave by OperatingSystem and CpuArchitecture
  • enhanced the way plugin-dependencies are discovered by using the types used by XmlGenerator. Now only mimimum amount of plugins are transferred.
  • selection of waiting jobs now consideres assigned slave-group
  • more unit tests for service
  • added unit tests for experiment manager
File size: 8.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Data.Linq;
24using System.Linq;
25using DT = HeuristicLab.Services.Hive.Common.DataTransfer;
26
27namespace HeuristicLab.Services.Hive.DataAccess {
28  public static class Convert {
29    #region Job
30    public static DT.Job ToDto(Job source) {
31      if (source == null) return null;
32      return new DT.Job {
33        Id = source.JobId,
34        CoresNeeded = source.CoresNeeded,
35        DateCalculated = source.DateCalculated,
36        DateCreated = source.DateCreated,
37        DateFinished = source.DateFinished,
38        Exception = source.Exception,
39        ExecutionTime = source.ExecutionTime,
40        MemoryNeeded = source.MemoryNeeded,
41        ParentJobId = source.ParentJobId,
42        Priority = source.Priority,
43        SlaveId = source.SlaveId,
44        JobState = source.JobState,
45        UserId = source.UserId,
46        PluginsNeededIds = source.RequiredPlugins.Select(x => x.PluginId).ToList()
47      };
48    }
49    public static Job ToEntity(DT.Job source) {
50      if (source == null) return null;
51      var entity = new Job(); ToEntity(source, entity);
52      return entity;
53    }
54    public static void ToEntity(DT.Job source, Job target) {
55      if ((source != null) && (target != null)) {
56        target.JobId = source.Id;
57        target.CoresNeeded = source.CoresNeeded;
58        target.DateCalculated = source.DateCalculated;
59        target.DateCreated = source.DateCreated;
60        target.DateFinished = source.DateFinished;
61        target.Exception = source.Exception;
62        target.ExecutionTime = source.ExecutionTime;
63        target.MemoryNeeded = source.MemoryNeeded;
64        target.ParentJobId = source.ParentJobId;
65        target.Priority = source.Priority;
66        target.SlaveId = source.SlaveId;
67        target.JobState = source.JobState;
68        target.UserId = source.UserId;
69        // RequiredPlugins need to be added by Dao
70      }
71    }
72    #endregion
73
74    #region JobData
75    public static DT.JobData ToDto(JobData source) {
76      if (source == null) return null;
77      return new DT.JobData { JobId = source.JobId, Data = source.Data.ToArray(), LastUpdate = source.LastUpdate };
78    }
79    public static JobData ToEntity(DT.JobData source) {
80      if (source == null) return null;
81      var entity = new JobData(); ToEntity(source, entity);
82      return entity;
83    }
84    public static void ToEntity(DT.JobData source, JobData target) {
85      if ((source != null) && (target != null)) {
86        target.JobId = source.JobId; target.Data = new Binary(source.Data); target.LastUpdate = source.LastUpdate;
87      }
88    }
89    #endregion
90
91    #region HiveExperiment
92    public static DT.HiveExperiment ToDto(HiveExperiment source) {
93      if (source == null) return null;
94      return new DT.HiveExperiment { Id = source.HiveExperimentId, Description = source.Description, Name = source.Name, RootJobId = source.RootJobId, UserId = source.UserId, DateCreated = source.DateCreated };
95    }
96    public static HiveExperiment ToEntity(DT.HiveExperiment source) {
97      if (source == null) return null;
98      var entity = new HiveExperiment(); ToEntity(source, entity);
99      return entity;
100    }
101    public static void ToEntity(DT.HiveExperiment source, HiveExperiment target) {
102      if ((source != null) && (target != null)) {
103        target.HiveExperimentId = source.Id; target.Description = source.Description; target.Name = source.Name; target.RootJobId = source.RootJobId; target.UserId = source.UserId; target.DateCreated = source.DateCreated;
104      }
105    }
106    #endregion
107
108    #region Plugin
109    public static DT.Plugin ToDto(Plugin source) {
110      if (source == null) return null;
111      return new DT.Plugin { Id = source.PluginId, Name = source.Name, Version = new Version(source.Version), UserId = source.UserId, IsLocal = source.IsLocal, DateCreated = source.DateCreated };
112    }
113    public static Plugin ToEntity(DT.Plugin source) {
114      if (source == null) return null;
115      var entity = new Plugin(); ToEntity(source, entity);
116      return entity;
117    }
118    public static void ToEntity(DT.Plugin source, Plugin target) {
119      if ((source != null) && (target != null)) {
120        target.PluginId = source.Id; target.Name = source.Name; target.Version = source.Version.ToString(); target.UserId = source.UserId; target.IsLocal = source.IsLocal; target.DateCreated = source.DateCreated;
121      }
122    }
123    #endregion
124
125    #region PluginData
126    public static DT.PluginData ToDto(PluginData source) {
127      if (source == null) return null;
128      return new DT.PluginData { Id = source.PluginDataId, PluginId = source.PluginId, Data = source.Data.ToArray(), FileName = source.FileName };
129    }
130    public static PluginData ToEntity(DT.PluginData source) {
131      if (source == null) return null;
132      var entity = new PluginData(); ToEntity(source, entity);
133      return entity;
134    }
135    public static void ToEntity(DT.PluginData source, PluginData target) {
136      if ((source != null) && (target != null)) {
137        target.PluginDataId = source.Id; target.PluginId = source.PluginId; target.Data = new Binary(source.Data); target.FileName = source.FileName;
138      }
139    }
140    #endregion
141
142    #region Slave
143    public static DT.Slave ToDto(Slave source) {
144      if (source == null) return null;
145      return new DT.Slave { Id = source.ResourceId, ParentResourceId = source.ParentResourceId, Cores = source.Cores, CpuSpeed = source.CpuSpeed, FreeCores = source.FreeCores, FreeMemory = source.FreeMemory, IsAllowedToCalculate = source.IsAllowedToCalculate, Memory = source.Memory, Name = source.Name, SlaveState = source.SlaveState, CpuArchitecture = source.CpuArchitecture, OperatingSystem = source.OperatingSystem };
146    }
147    public static Slave ToEntity(DT.Slave source) {
148      if (source == null) return null;
149      var entity = new Slave(); ToEntity(source, entity);
150      return entity;
151    }
152    public static void ToEntity(DT.Slave source, Slave target) {
153      if ((source != null) && (target != null)) {
154        target.ResourceId = source.Id; target.ParentResourceId = source.ParentResourceId; target.Cores = source.Cores; target.CpuSpeed = source.CpuSpeed; target.FreeCores = source.FreeCores; target.FreeMemory = source.FreeMemory; target.IsAllowedToCalculate = source.IsAllowedToCalculate; target.Memory = source.Memory; target.Name = source.Name; target.SlaveState = source.SlaveState; target.CpuArchitecture = source.CpuArchitecture; target.OperatingSystem = source.OperatingSystem;
155      }
156    }
157    #endregion
158
159    #region SlaveGroup
160    public static DT.SlaveGroup ToDto(SlaveGroup source) {
161      if (source == null) return null;
162      return new DT.SlaveGroup { Id = source.ResourceId, Name = source.Name, ParentResourceId = source.ParentResourceId };
163    }
164    public static SlaveGroup ToEntity(DT.SlaveGroup source) {
165      if (source == null) return null;
166      var entity = new SlaveGroup(); ToEntity(source, entity);
167      return entity;
168    }
169    public static void ToEntity(DT.SlaveGroup source, SlaveGroup target) {
170      if ((source != null) && (target != null)) {
171        target.ResourceId = source.Id; target.Name = source.Name; target.ParentResourceId = source.ParentResourceId;
172      }
173    }
174    #endregion
175
176    #region Resource
177    public static DT.Resource ToDto(Resource source) {
178      if (source == null) return null;
179      return new DT.Resource { Id = source.ResourceId, Name = source.Name, ParentResourceId = source.ParentResourceId };
180    }
181    public static Resource ToEntity(DT.Resource source) {
182      if (source == null) return null;
183      var entity = new Resource(); ToEntity(source, entity);
184      return entity;
185    }
186    public static void ToEntity(DT.Resource source, Resource target) {
187      if ((source != null) && (target != null)) {
188        target.ResourceId = source.Id; target.Name = source.Name; target.ParentResourceId = source.ParentResourceId;
189      }
190    }
191    #endregion
192  }
193}
Note: See TracBrowser for help on using the repository browser.