- Timestamp:
- 02/21/11 17:35:42 (14 years ago)
- Location:
- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/HiveService.cs
r5511 r5526 31 31 32 32 #region Job Methods 33 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]34 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]33 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 34 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 35 35 public Guid AddJob(Job job, JobData jobData, IEnumerable<Guid> resourceIds) { 36 36 using (trans.OpenTransaction()) { … … 51 51 } 52 52 53 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 54 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 53 55 public Guid AddChildJob(Guid parentJobId, Job job, JobData jobData) { 54 56 using (trans.OpenTransaction()) { … … 58 60 } 59 61 62 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 63 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 64 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 60 65 public Job GetJob(Guid jobId) { 61 66 return dao.GetJob(jobId); 62 67 } 63 68 69 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 70 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 64 71 public IEnumerable<Job> GetJobs() { 65 72 return dao.GetJobs(x => true); 66 73 } 67 74 75 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 76 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 68 77 public IEnumerable<LightweightJob> GetLightweightJobs(IEnumerable<Guid> jobIds) { 69 78 return dao.GetJobs(x => jobIds.Contains(x.JobId)).Select(x => new LightweightJob(x)).ToArray(); 70 79 } 71 80 81 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 82 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 72 83 public IEnumerable<LightweightJob> GetLightweightChildJobs(Guid? parentJobId, bool recursive, bool includeParent) { 73 84 return GetChildJobs(parentJobId, recursive, includeParent).Select(x => new LightweightJob(x)).ToArray(); 74 85 } 75 86 87 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 88 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 89 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 76 90 public JobData GetJobData(Guid jobId) { 77 91 return dao.GetJobData(jobId); 78 92 } 79 93 94 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 95 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 96 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 80 97 public void UpdateJob(Job job) { 81 98 using (trans.OpenTransaction()) { … … 84 101 } 85 102 103 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 104 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 105 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 86 106 public void UpdateJobData(Job job, JobData jobData) { 87 107 using (trans.OpenTransaction()) { … … 92 112 } 93 113 114 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 115 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 116 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 94 117 public void DeleteJob(Guid jobId) { 95 118 using (trans.OpenTransaction()) { … … 98 121 } 99 122 123 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 124 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 125 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 100 126 public void DeleteChildJobs(Guid parentJobId) { 101 127 using (trans.OpenTransaction()) { … … 111 137 112 138 #region Job Control Methods 139 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 140 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 141 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 113 142 public void StopJob(Guid jobId) { 114 143 using (trans.OpenTransaction()) { … … 116 145 } 117 146 } 147 148 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 149 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 150 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 118 151 public void PauseJob(Guid jobId) { 119 152 using (trans.OpenTransaction()) { … … 124 157 125 158 #region HiveExperiment Methods 126 159 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 160 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 127 161 public HiveExperiment GetHiveExperiment(Guid id) { 128 162 return dao.GetHiveExperiments(x => … … 132 166 } 133 167 168 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 169 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 134 170 public IEnumerable<HiveExperiment> GetHiveExperiments() { 135 171 return dao.GetHiveExperiments(x => x.OwnerUserId == auth.UserId || x.HiveExperimentPermissions.Count(hep => hep.Permission != Permission.NotAllowed && hep.GrantedUserId == auth.UserId) > 0); 136 172 } 137 173 174 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 175 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 138 176 public Guid AddHiveExperiment(HiveExperiment hiveExperimentDto) { 139 177 using (trans.OpenTransaction()) { … … 144 182 } 145 183 184 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 185 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 146 186 public void UpdateHiveExperiment(HiveExperiment hiveExperimentDto) { 147 187 using (trans.OpenTransaction()) { … … 150 190 } 151 191 192 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 193 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 152 194 public void DeleteHiveExperiment(Guid hiveExperimentId) { 153 195 using (trans.OpenTransaction()) { … … 159 201 160 202 #region Login Methods 203 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 161 204 public void Hello(Slave slaveInfo) { 162 205 using (trans.OpenTransaction()) { … … 171 214 } 172 215 216 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 173 217 public void GoodBye(Guid slaveId) { 174 218 using (trans.OpenTransaction()) { … … 183 227 184 228 #region Heartbeat Methods 229 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 185 230 public List<MessageContainer> Heartbeat(Heartbeat heartbeat) { 186 231 using (trans.OpenTransaction()) { … … 191 236 192 237 #region Plugin Methods 238 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 239 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 193 240 public Guid AddPlugin(Plugin plugin, List<PluginData> pluginDatas) { 194 241 using (trans.OpenTransaction()) { … … 203 250 } 204 251 } 252 253 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 254 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 255 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 205 256 public IEnumerable<Plugin> GetPlugins() { 206 257 return dao.GetPlugins(x => true); 207 258 } 208 259 260 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 261 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 262 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)] 209 263 public IEnumerable<PluginData> GetPluginDatas(List<Guid> pluginIds) { 210 264 List<PluginData> pluginDatas = new List<PluginData>(); … … 226 280 227 281 #region Slave Methods 282 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 283 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 228 284 public Guid AddSlave(Slave slave) { 229 285 using (trans.OpenTransaction()) { … … 232 288 } 233 289 290 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 291 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 234 292 public Guid AddSlaveGroup(SlaveGroup slaveGroup) { 235 293 using (trans.OpenTransaction()) { … … 238 296 } 239 297 298 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 299 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 240 300 public Slave GetSlave(Guid slaveId) { 241 301 return dao.GetSlave(slaveId); … … 246 306 } 247 307 308 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 309 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 248 310 public IEnumerable<Slave> GetSlaves() { 249 311 return dao.GetSlaves(x => true); 250 312 } 251 313 314 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 315 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 252 316 public IEnumerable<SlaveGroup> GetSlaveGroups() { 253 317 return dao.GetSlaveGroups(x => true); 254 318 } 255 319 320 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 321 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 256 322 public void UpdateSlave(Slave slave) { 257 323 using (trans.OpenTransaction()) { … … 260 326 } 261 327 328 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 329 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 262 330 public void UpdateSlaveGroup(SlaveGroup slaveGroup) { 263 331 using (trans.OpenTransaction()) { … … 266 334 } 267 335 336 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 337 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 268 338 public void DeleteSlave(Guid slaveId) { 269 339 using (trans.OpenTransaction()) { … … 272 342 } 273 343 344 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 345 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 274 346 public void DeleteSlaveGroup(Guid slaveGroupId) { 275 347 using (trans.OpenTransaction()) { … … 278 350 } 279 351 352 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 353 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 280 354 public void AddResourceToGroup(Guid slaveGroupId, Guid resourceId) { 281 355 using (trans.OpenTransaction()) { … … 286 360 } 287 361 362 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 363 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 288 364 public void RemoveResourceFromGroup(Guid slaveGroupId, Guid resourceId) { 289 365 using (trans.OpenTransaction()) { … … 294 370 } 295 371 372 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)] 373 // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)] 296 374 public Guid GetResourceId(string resourceName) { 297 375 using (trans.OpenTransaction()) { … … 325 403 326 404 #endregion 327 328 329 405 } 330 406 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/LifecycleManager.cs
r5511 r5526 36 36 public void Start() { 37 37 if (ExecutionState == Core.ExecutionState.Stopped) { 38 // kick off the event immediately 39 timer_Tick(this, EventArgs.Empty); 40 41 // start the timer 38 42 this.timer.Interval = (int)new TimeSpan(0, 0, 30).TotalMilliseconds; 39 43 this.timer.Start(); … … 54 58 lock (locker) { 55 59 using (trans.OpenTransaction()) { 56 var slaves = dao.GetSlaves(x => x.SlaveState != SlaveState.Offline); 57 foreach (Slave slave in slaves) { 58 if (!slave.LastHeartbeat.HasValue || (DateTime.Now - slave.LastHeartbeat.Value).TotalSeconds > ApplicationConstants.HeartbeatTimeout) { 59 slave.SlaveState = SlaveState.Offline; 60 AbortJobs(slave.Id); 61 dao.UpdateSlave(slave); 62 } 63 } 60 SetTimeoutSlavesOffline(); 61 FinishParentJobs(); 64 62 } 65 63 } 66 64 } 67 65 68 private void AbortJobs(Guid slaveId) { 69 var jobs = dao.GetJobs(x => x.StateLogs.Last().SlaveId == slaveId); 66 /// <summary> 67 /// Searches for slaves which are timed out, puts them and their jobs offline 68 /// </summary> 69 private void SetTimeoutSlavesOffline() { 70 var slaves = dao.GetSlaves(x => x.SlaveState != SlaveState.Offline); 71 foreach (Slave slave in slaves) { 72 if (!slave.LastHeartbeat.HasValue || (DateTime.Now - slave.LastHeartbeat.Value).TotalSeconds > ApplicationConstants.HeartbeatTimeout) { 73 slave.SlaveState = SlaveState.Offline; 74 SetJobsWaiting(slave.Id); 75 dao.UpdateSlave(slave); 76 } 77 } 78 } 79 80 /// <summary> 81 /// Looks for parent jobs which have FinishWhenChildJobsFinished and set their state to finished 82 /// </summary> 83 private void FinishParentJobs() { 84 var parentJobsToFinish = dao.GetParentJobs(dao.GetResources(x => true).Select(x => x.Id), 0, true); 85 foreach (var job in parentJobsToFinish) { 86 job.SetState(JobState.Finished); 87 dao.UpdateJob(job); 88 } 89 } 90 91 private void SetJobsWaiting(Guid slaveId) { 92 var jobs = dao.GetJobs(x => x.State == JobState.Calculating).Where(x => x.StateLog.Last().SlaveId == slaveId); 70 93 foreach (var j in jobs) { 71 94 j.StateLog.Add(new StateLog() { 72 UserId = auth.UserId,73 95 State = JobState.Waiting, 74 96 JobId = j.Id,
Note: See TracChangeset
for help on using the changeset viewer.