- Timestamp:
- 02/01/11 15:51:11 (14 years ago)
- Location:
- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Convert.cs
r5402 r5404 143 143 public static DT.Slave ToDto(Slave source) { 144 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 };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 146 } 147 147 public static Slave ToEntity(DT.Slave source) { … … 152 152 public static void ToEntity(DT.Slave source, Slave target) { 153 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; 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 155 } 156 156 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HeuristicLab.Services.Hive.DataAccess-3.4.csproj
r5402 r5404 103 103 <Compile Include="Convert.cs" /> 104 104 <None Include="HeuristicLabServicesHiveDataAccessPlugin.cs.frame" /> 105 <Compile Include="Exceptions\DaoException.cs" /> 105 106 <Compile Include="HeuristicLabServicesHiveDataAccessPlugin.cs" /> 106 107 <Compile Include="HiveDao.cs" /> -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDao.cs
r5402 r5404 82 82 } 83 83 84 public IEnumerable<DT.Job> GetWaitingParentJobs(Guid slaveId) { 85 using (var db = CreateContext()) { 86 // todo: slaveId is unused! 84 public IEnumerable<DT.Job> GetWaitingParentJobs(IEnumerable<Guid> resourceIds, int count) { 85 using (var db = CreateContext()) { 87 86 var query = from ar in db.AssignedResources 88 where ar.Job.JobState == JobState.WaitingForChildJobs && 89 (from child in db.Jobs 90 where child.ParentJobId == ar.Job.JobId 91 select child.JobState == JobState.Finished).All(x => x) && 92 (from child in db.Jobs // avoid returning WaitForChildJobs jobs where no child-jobs exist (yet) 93 where child.ParentJobId == ar.Job.JobId 94 select child).Count() > 0 87 where resourceIds.Contains(ar.ResourceId) 88 && ar.Job.JobState == JobState.WaitingForChildJobs 89 && (from child in db.Jobs 90 where child.ParentJobId == ar.Job.JobId 91 select child.JobState == JobState.Finished).All(x => x) 92 && (from child in db.Jobs // avoid returning WaitForChildJobs jobs where no child-jobs exist (yet) 93 where child.ParentJobId == ar.Job.JobId 94 select child).Count() > 0 95 95 orderby ar.Job.Priority descending 96 96 select Convert.ToDto(ar.Job); 97 return query.ToArray(); 98 } 99 } 100 101 public IEnumerable<DT.Job> GetWaitingJobs(DT.Slave slave) { 102 using (var db = CreateContext()) { 103 var query = from j in db.Jobs 104 where j.JobState == JobState.Waiting && j.CoresNeeded <= slave.FreeCores && j.MemoryNeeded <= slave.FreeMemory 105 orderby j.Priority descending 106 select Convert.ToDto(j); 107 var waitingJobs = query.ToArray(); 108 var waitingParentJobs = GetWaitingParentJobs(slave.Id); 97 return count == 0 ? query.ToArray() : query.Take(count).ToArray(); 98 } 99 } 100 101 public IEnumerable<DT.Job> GetWaitingJobs(DT.Slave slave, int count) { 102 using (var db = CreateContext()) { 103 var resourceIds = GetParentResources(slave.Id).Select(r => r.Id); 104 var waitingParentJobs = GetWaitingParentJobs(resourceIds, count); 105 if (count > 0 && waitingParentJobs.Count() >= count) return waitingParentJobs.Take(count).ToArray(); 106 107 var query = from ar in db.AssignedResources 108 where resourceIds.Contains(ar.ResourceId) 109 && ar.Job.JobState == JobState.Waiting 110 && ar.Job.CoresNeeded <= slave.FreeCores 111 && ar.Job.MemoryNeeded <= slave.FreeMemory 112 orderby ar.Job.Priority descending 113 select Convert.ToDto(ar.Job); 114 var waitingJobs = (count == 0 ? query : query.Take(count)).ToArray(); 109 115 return waitingJobs.Union(waitingParentJobs).OrderByDescending(x => x.Priority); 110 116 } … … 350 356 using (var db = CreateContext()) { 351 357 var entity = db.Resources.OfType<SlaveGroup>().FirstOrDefault(x => x.ResourceId == id); 352 if (entity != null) db.Resources.DeleteOnSubmit(entity); 358 if (entity != null) { 359 if (db.Resources.Where(r => r.ParentResourceId == id).Count() > 0) { 360 throw new DaoException("Cannot delete SlaveGroup as long as there are Slaves in the group"); 361 } 362 db.Resources.DeleteOnSubmit(entity); 363 } 353 364 db.SubmitChanges(); 354 365 } … … 408 419 return job.AssignedResources.Select(x => Convert.ToDto(x.Resource)).ToArray(); 409 420 } 421 } 422 423 /// <summary> 424 /// Returns all parent resources of a resource (the given resource is also added) 425 /// </summary> 426 private IEnumerable<DT.Resource> GetParentResources(Guid resourceId) { 427 using (var db = CreateContext()) { 428 var resources = new List<Resource>(); 429 CollectParentResources(resources, db.Resources.Where(r => r.ResourceId == resourceId).Single()); 430 return resources.Select(r => Convert.ToDto(r)).ToArray(); 431 } 432 } 433 434 private void CollectParentResources(List<Resource> resources, Resource resource) { 435 if (resource == null) return; 436 resources.Add(resource); 437 CollectParentResources(resources, resource.ParentResource); 410 438 } 411 439 #endregion -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.dbml
r5402 r5404 49 49 <Column Name="FreeMemory" Type="System.Int32" DbType="Int" CanBeNull="true" /> 50 50 <Column Name="IsAllowedToCalculate" Type="System.Boolean" DbType="Bit" CanBeNull="false" /> 51 <Column Name="CpuArchitecture" Type="global::HeuristicLab.Services.Hive.Common.DataTransfer.CpuArchitecture" DbType="VarChar(3)" CanBeNull="false" /> 52 <Column Name="OperatingSystem" Type="System.String" DbType="VarChar(MAX)" CanBeNull="false" /> 51 53 <Association Name="Slave_Job" Member="Jobs" ThisKey="ResourceId" OtherKey="SlaveId" Type="Job" /> 52 54 </Type> -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.dbml.layout
r5402 r5404 45 45 </nestedChildShapes> 46 46 </classShape> 47 <classShape Id="26f4edfa-91dd-4941-a058-359f89e567a8" absoluteBounds="8.875, 1, 2, 2. 3478011067708335">47 <classShape Id="26f4edfa-91dd-4941-a058-359f89e567a8" absoluteBounds="8.875, 1, 2, 2.7324039713541666"> 48 48 <DataClassMoniker Name="/HiveDataContext/Slave" /> 49 49 <nestedChildShapes> 50 <elementListCompartment Id="1e61f36b-08dc-4df7-8594-c9dcd95c0791" absoluteBounds="8.89, 1.46, 1.9700000000000002, 1.7878011067708333" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />50 <elementListCompartment Id="1e61f36b-08dc-4df7-8594-c9dcd95c0791" absoluteBounds="8.89, 1.46, 1.9700000000000002, 2.1724039713541665" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" /> 51 51 </nestedChildShapes> 52 52 </classShape> … … 69 69 </nodes> 70 70 </inheritanceConnector> 71 <associationConnector edgePoints="[(1 2.25 : 2.57859537760417); (12.25 : 4.44314697265625); (10.875 : 4.44314697265625)]" fixedFrom="NotFixed" fixedTo="NotFixed">71 <associationConnector edgePoints="[(11.9843735 : 2.57859537760417); (11.9843735 : 4.44314697265625); (10.875 : 4.44314697265625)]" fixedFrom="NotFixed" fixedTo="NotFixed"> 72 72 <AssociationMoniker Name="/HiveDataContext/Resource/Resource_AssignedResource" /> 73 73 <nodes> … … 97 97 </nodes> 98 98 </associationConnector> 99 <associationConnector edgePoints="[(8.875 : 2. 17390055338542); (8.5 : 2.17390055338542)]" fixedFrom="NotFixed" fixedTo="NotFixed">99 <associationConnector edgePoints="[(8.875 : 2.36620198567708); (8.5 : 2.36620198567708)]" fixedFrom="NotFixed" fixedTo="NotFixed"> 100 100 <AssociationMoniker Name="/HiveDataContext/Slave/Slave_Job" /> 101 101 <nodes> … … 130 130 </nestedChildShapes> 131 131 </classShape> 132 <associationConnector edgePoints="[(11 : 6.28929768880208); (11.625 : 6.28929768880208)]" fixedFrom=" Algorithm" fixedTo="Algorithm">132 <associationConnector edgePoints="[(11 : 6.28929768880208); (11.625 : 6.28929768880208)]" fixedFrom="NotFixed" fixedTo="NotFixed"> 133 133 <AssociationMoniker Name="/HiveDataContext/Plugin/Plugin_PluginData" /> 134 134 <nodes> … … 144 144 </nodes> 145 145 </associationConnector> 146 <associationConnector edgePoints="[(9 : 6.19314697265625); (8.5 : 6.19314697265625)]" fixedFrom=" Algorithm" fixedTo="Algorithm">146 <associationConnector edgePoints="[(9 : 6.19314697265625); (8.5 : 6.19314697265625)]" fixedFrom="NotFixed" fixedTo="NotFixed"> 147 147 <AssociationMoniker Name="/HiveDataContext/Plugin/Plugin_RequiredPlugin" /> 148 148 <nodes> -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.designer.cs
r5402 r5404 3 3 // <auto-generated> 4 4 // This code was generated by a tool. 5 // Runtime Version:4.0.30319. 15 // Runtime Version:4.0.30319.208 6 6 // 7 7 // Changes to this file may cause incorrect behavior and will be lost if … … 1060 1060 private bool _IsAllowedToCalculate; 1061 1061 1062 private global::HeuristicLab.Services.Hive.Common.DataTransfer.CpuArchitecture _CpuArchitecture; 1063 1064 private string _OperatingSystem; 1065 1062 1066 private EntitySet<Job> _Jobs; 1063 1067 … … 1082 1086 partial void OnIsAllowedToCalculateChanging(bool value); 1083 1087 partial void OnIsAllowedToCalculateChanged(); 1088 partial void OnCpuArchitectureChanging(global::HeuristicLab.Services.Hive.Common.DataTransfer.CpuArchitecture value); 1089 partial void OnCpuArchitectureChanged(); 1090 partial void OnOperatingSystemChanging(string value); 1091 partial void OnOperatingSystemChanged(); 1084 1092 #endregion 1085 1093 … … 1246 1254 this.SendPropertyChanged("IsAllowedToCalculate"); 1247 1255 this.OnIsAllowedToCalculateChanged(); 1256 } 1257 } 1258 } 1259 1260 [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_CpuArchitecture", DbType="VarChar(3)", CanBeNull=false)] 1261 public global::HeuristicLab.Services.Hive.Common.DataTransfer.CpuArchitecture CpuArchitecture 1262 { 1263 get 1264 { 1265 return this._CpuArchitecture; 1266 } 1267 set 1268 { 1269 if ((this._CpuArchitecture != value)) 1270 { 1271 this.OnCpuArchitectureChanging(value); 1272 this.SendPropertyChanging(); 1273 this._CpuArchitecture = value; 1274 this.SendPropertyChanged("CpuArchitecture"); 1275 this.OnCpuArchitectureChanged(); 1276 } 1277 } 1278 } 1279 1280 [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_OperatingSystem", DbType="VarChar(MAX)", CanBeNull=false)] 1281 public string OperatingSystem 1282 { 1283 get 1284 { 1285 return this._OperatingSystem; 1286 } 1287 set 1288 { 1289 if ((this._OperatingSystem != value)) 1290 { 1291 this.OnOperatingSystemChanging(value); 1292 this.SendPropertyChanging(); 1293 this._OperatingSystem = value; 1294 this.SendPropertyChanged("OperatingSystem"); 1295 this.OnOperatingSystemChanged(); 1248 1296 } 1249 1297 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Interfaces/IHiveDao.cs
r5155 r5404 15 15 void UpdateJob(DT.Job dto); 16 16 void DeleteJob(Guid id); 17 IEnumerable<DT.Job> GetWaitingJobs(DT.Slave slave );17 IEnumerable<DT.Job> GetWaitingJobs(DT.Slave slave, int count); 18 18 #endregion 19 19 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Tools/prepareHiveDatabase.sql
r5402 r5404 40 40 ALTER TABLE dbo.Job ALTER COLUMN JobId ADD ROWGUIDCOL; 41 41 ALTER TABLE dbo.Job WITH NOCHECK ADD CONSTRAINT [DF_Job_JobId] DEFAULT (newid()) FOR JobId; 42 43 --ALTER TABLE [dbo].[Job] DROP CONSTRAINT [Slave_Job] 44 --ALTER TABLE [dbo].[Job] WITH CHECK ADD CONSTRAINT [Slave_Job] FOREIGN KEY([ResourceId]) 45 --REFERENCES [dbo].[Resource] ([ResourceId]) 46 --ON UPDATE CASCADE 47 --ON DELETE SET NULL 48 --GO 42 49 43 50 ALTER TABLE dbo.Plugin ALTER COLUMN PluginId ADD ROWGUIDCOL;
Note: See TracChangeset
for help on using the changeset viewer.