Changeset 17059 for stable/HeuristicLab.Clients.Hive/3.3/HiveClient.cs
- Timestamp:
- 07/04/19 14:28:13 (5 years ago)
- Location:
- stable
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Clients.Hive
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive merged eligible /trunk/HeuristicLab.Clients.Hive merged eligible /branches/1721-RandomForestPersistence/HeuristicLab.Clients.Hive 10321-10322 /branches/2916_IndexedDataTableSerialization/HeuristicLab.Clients.Hive 15918 /branches/2947_ConfigurableIndexedDataTable/HeuristicLab.Clients.Hive 16148-16526 /branches/2972_PDPRowSelect/HeuristicLab.Clients.Hive 16444-16518 /branches/Algorithms.GradientDescent/HeuristicLab.Clients.Hive 5516-5520 /branches/Async/HeuristicLab.Clients.Hive 13329-15286 /branches/Benchmarking/sources/HeuristicLab.Clients.Hive 6917-7005 /branches/CloningRefactoring/HeuristicLab.Clients.Hive 4656-4721 /branches/CodeEditor/HeuristicLab.Clients.Hive 11700-11806 /branches/DataAnalysis Refactoring/HeuristicLab.Clients.Hive 5471-5808 /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Clients.Hive 5815-6180 /branches/DataAnalysis/HeuristicLab.Clients.Hive 4458-4459,4462,4464 /branches/DataPreprocessing/HeuristicLab.Clients.Hive 10085-11101 /branches/GP.Grammar.Editor/HeuristicLab.Clients.Hive 6284-6795 /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Clients.Hive 5060 /branches/HLScript/HeuristicLab.Clients.Hive 10331-10358 /branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Clients.Hive 11570-12508 /branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Clients.Hive 6123-9799 /branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Clients.Hive 11130-12721 /branches/HiveProjectManagement/HeuristicLab.Clients.Hive 15377-15760 /branches/HiveStatistics/sources/HeuristicLab.Clients.Hive 12440-12877 /branches/LogResidualEvaluator/HeuristicLab.Clients.Hive 10202-10483 /branches/NET40/sources/HeuristicLab.Clients.Hive 5138-5162 /branches/NSGA-II Changes/HeuristicLab.Clients.Hive 12033-12122 /branches/ParallelEngine/HeuristicLab.Clients.Hive 5175-5192 /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Clients.Hive 7568-7810 /branches/QAPAlgorithms/HeuristicLab.Clients.Hive 6350-6627 /branches/Restructure trunk solution/HeuristicLab.Clients.Hive 6828 /branches/RuntimeOptimizer/HeuristicLab.Clients.Hive 8943-9078 /branches/ScatterSearch (trunk integration)/HeuristicLab.Clients.Hive 7787-8333 /branches/SlaveShutdown/HeuristicLab.Clients.Hive 8944-8956 /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Clients.Hive 10204-10479 /branches/SuccessProgressAnalysis/HeuristicLab.Clients.Hive 5370-5682 /branches/Trunk/HeuristicLab.Clients.Hive 6829-6865 /branches/UnloadJobs/HeuristicLab.Clients.Hive 9168-9215 /branches/VNS/HeuristicLab.Clients.Hive 5594-5752 /branches/crossvalidation-2434/HeuristicLab.Clients.Hive 12948-12950 /branches/histogram/HeuristicLab.Clients.Hive 5959-6341 /branches/symbreg-factors-2650/HeuristicLab.Clients.Hive 14232-14825 /trunk/sources/HeuristicLab.Clients.Hive 9493,9496,9498,9504-9506,9515-9517,9520-9521,9523,9530-9531,9534-9537,9540,9542-9544,9552-9555,9568-9569,9587,9590-9592,9600,9607-9608,9610-9611,9613,9618,9623-9624,9626,9647-9649,9652,9657-9660,9664-9666,9675,9692,9695,9699,9702,9710,9714,9718-9720,9740-9741,9751-9752,9755,9762,9764-9775,9777-9778,9782-9786,9792,9794-9795,9803-9812,9816-9822,9824-9825,9828,9830,9833,9837-9841,9845,9848-9851,9855,9859-9860,9863,9865-9868,9871,9893-9897,9900-9902,9905-9907,9910,9915-9916,9919-9921,9928,9930,9934-9935,9938-9941,9944,9946,9949,9955-9956,9958-9959,9964-9965,9973-9975,9978,9980-9982,9988-9989,9991-9992,9994-9995,9997,10000-10005,10009-10010,10015,10130,10149-10150,10154,10170-10171,10173-10176,10195-10196,10212-10213,10231,10261,10273,10291-10292,10295,10298,10323-10324,10346,10348,10355,10359-10360,10362-10363,10365-10366,10368,10375,10378,10391,10401,10406-10407,10414,10417-10418,10428,10432-10433,10435,10440,10448,10453,10460,10465-10466,10469-10470,10472,10474-10477,10480,10484,10486,10488-10500,10503-10504,10506,10510-10512,10519-10523,10526,10531,10540-10541,10543,10545,10561-10566,10575-10578,10596-10597,10599,10601-10607,10639,10642-10643,10646,10651-10653,10727,10731,10745,10747,10761,10767,10774,10787-10791,10793-10794,10796,10799-10800,10826,10857-10862,10865,10885,10889,10894-10896,10924,10926-10927,10937,10941,10953,10955-10956,10958-10961,10963,10975,10983-10986,10988-10989,10996,11007-11008,11012-11014,11019,11024-11027,11031,11034-11035,11048,11050-11052,11056-11058,11060,11065-11067,11071,11074-11082,11086-11088,11091-11093,11095-11097,11099-11100,11102,11108,11111-11117,11123-11128,11131,11135,11153,11156,11161,11214,11241,11243,11248-11251,11256,11263,11274,11280,11282-11283,11285-11287,11290,11292,11294-11296,11298,11300,11302,11306,11308-11309,11313,11315,11317,11324,11326,11330-11332,11337-11348,11352-11353,11361-11362,11364-11367,11380-11382,11384,11389,11391-11392,11394,11403-11404,11410-11411,11417-11420,11422,11426-11430,11432,11434-11437,11439-11448,11450,11453,11455-11457,11464,11466-11467,11469-11472,11474,11477-11480,11483,11494-11498,11504,11514-11515,11523-11525,11532-11533,11536,11540-11542,11544-11545,11547-11549,11555,11557,11581,11592,11596-11597,11599-11600,11605,11608,11610,11615-11616,11618,11623,11631,11634,11650-11652,11657,11675,11679-11680,11703-11706,11715,11717,11721,11723-11725,11734-11736,11756-11758,11762-11764,11766,11771-11772,11781-11782,11784,11787-11790,11794,11807-11811,11815-11816,11818-11819,11822,11825-11831,11833-11837,11839-11840,11853-11854,11856,11877-11879,11882,11890,11909,11912-11918,11921,11930,11933-11934,11936,11938-11939,11942,11945,11948,11950-11951,11955-11956,11958-11961,11963,11967,11970-11971,11978,11982-11984,11987-11994,11996,11998-12004,12015-12744,12755,12770,12772,12787,12790-12798,12801,12807,12810-12812,12816-12819,12835-12837,12839,12844-12846,12851,12855,12868,12873,12875,12878-12879,12883,12885-12886,12889,12894-12907,12911-12918,12920-12921,12925-12927,12932,12934,12936-12938,12940,12946-12948,12953-12954,12959-12961,12971-12973,12975-12978,12981-12983,12986-12987,13000-13005,13008,13014,13016,13024-13027,13030,13033-13034,13036,13038-13040,13051,13054-13060,13064-13066,13078,13080,13087,13093-13094,13100-13104,13109,13116,13118-13121,13131,13133,13136-13143,13154,13157-13160,13162-13165,13167-13169,13173,13180-13181,13183,13186,13198,13200-13201,13203-13205,13209-13210,13212,13214,13217-13219,13222-13228,13230-13239,13241-13245,13247-13257,13260-13261,13266-13271,13288,13300,13307-13309,13311,13313-13315,13318,13392-13393,13395,13402,13406,13411,13413-13415,13419-13420,13425,13427-13430,13433-13434,13438-13442,13445-13447,13450,13458,13471,13473-13474,13484,13491,13494,13498-13504,13507-13514,13516-13517,13525-13526,13529,13534-13535,13539-13540,13549-13550,13552,13560,13566-13567,13570-13573,13579-13582,13584-13586,13592-13593,13597,13614,13616,13621,13626-13629,13635,13644-13646,13648,13650-13655,13657-13662,13666,13669-13671,13675-13684,13690-13693,13695,13697-13705,13707-13709,13711,13715,13721,13724,13746,13760-13761,13764-13766,13779,13784-13786,13796,13800-13802,13807,13813,13826,13838,13863,13869,13889-13891,13895,13898-13901,13916-13917,13921-13922,13925,13932-13935,13938-13939,13941-13942,13958,13963-13964,13975,13978,13983-13987,13992-13993,13998,14000-14001,14007-14008,14011,14014-14017,14024-14026,14032,14034,14036-14037,14056-14057,14071,14082-14083,14095-14096,14098-14100,14102-14103,14107,14109-14110,14118-14122,14124-14127,14130-14132,14135-14136,14140,14142,14144,14150,14152,14155-14160,14162-14164,14167-14169,14174-14175,14177-14179,14181,14189,14191,14196,14198,14200,14202-14207,14209,14221-14224,14226-14230,14234-14236,14244-14247,14250,14255-14258,14260,14267-14268,14270-14273,14282,14284-14300,14307,14314-14316,14319,14322,14332,14340-14350,14352-14358,14367-14369,14371-14372,14376,14378,14381-14382,14384,14388,14390-14391,14393-14394,14396,14400,14405,14407-14408,14412,14418,14422-14423,14425,14432-14439,14443,14457-14458,14463-14465,14468-14469,14475-14476,14478-14479,14481-14483,14486,14493-14494,14504,14506-14509,14516-14517,14519,14522-14523,14527-14529,14531-14533,14548,14553,14561,14582,14597,14623,14630,14647,14651-14652,14654,14656,14659-14660,14662-14663,14672,14685,14687,14692,14697,14706,14708-14709,14718,14721-14722,14726,14732,14734,14737-14738,14740,14748-14750,14769-14770,14772-14775,14779-14781,14786,14789-14791,14793,14805,14809-14810,14817,14819-14820,14826-14832,14839-14843,14845-14847,14851-14854,14857,14860-14865,14871,14877,14882,14886,14889-14890,14899,14901,14904,14911-14912,14916,14918,14936-14938,14940,14943-14951,14955,14971,14978-14979,14982,14984,14987,14992,14995,15002-15010,15013,15015-15016,15023-15024,15026,15029,15040,15042,15044,15046-15054,15058,15067-15077,15079-15080,15083-15088,15091-15096,15098-15099,15102-15107,15110-15114,15119-15126,15129,15135,15139,15156-15158,15160,15162-15169,15172-15173,15178-15181,15184-15185,15187,15191-15192,15194,15198,15201,15203,15205-15211,15213-15214,15221-15228,15230,15233-15236,15240-15241,15246-15248,15264-15266,15271,15276,15287-15288,15300-15302,15312,15325-15327,15329,15335-15336,15339,15357-15358,15361,15367-15368,15370-15372,15376,15383,15388,15390,15393,15395-15398,15400,15402,15408-15409,15419,15427,15447-15448,15452,15461,15464,15478,15480-15481,15483,15486,15498-15499,15502,15505,15513,15517-15518,15532,15534,15545,15548,15551,15556,15560,15570,15591,15594,15596,15598,15607,15610-15611,15621-15623,15626,15637-15638,15645,15665,15667,15672-15674 /trunk/sources/HeuristicLab.Problems.TestFunctions.MultiObjective/HeuristicLab.Clients.Hive 14175
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
stable/HeuristicLab.Clients.Hive/3.3/HiveClient.cs
r15584 r17059 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 8Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 57 57 } 58 58 59 private IItemList<Project> projects; 60 public IItemList<Project> Projects { 61 get { return projects; } 62 } 63 64 private IItemList<Resource> resources; 65 public IItemList<Resource> Resources { 66 get { return resources; } 67 } 68 69 private Dictionary<Guid, HashSet<Guid>> projectAncestors; 70 public Dictionary<Guid, HashSet<Guid>> ProjectAncestors { 71 get { return projectAncestors; } 72 } 73 74 private Dictionary<Guid, HashSet<Guid>> projectDescendants; 75 public Dictionary<Guid, HashSet<Guid>> ProjectDescendants { 76 get { return projectDescendants; } 77 } 78 79 private Dictionary<Guid, HashSet<Guid>> resourceAncestors; 80 public Dictionary<Guid, HashSet<Guid>> ResourceAncestors { 81 get { return resourceAncestors; } 82 } 83 84 private Dictionary<Guid, HashSet<Guid>> resourceDescendants; 85 public Dictionary<Guid, HashSet<Guid>> ResourceDescendants { 86 get { return resourceDescendants; } 87 } 88 89 private Dictionary<Guid, string> projectNames; 90 public Dictionary<Guid, string> ProjectNames { 91 get { return projectNames; } 92 } 93 94 private HashSet<Project> disabledParentProjects; 95 public HashSet<Project> DisabledParentProjects { 96 get { return disabledParentProjects; } 97 } 98 99 private Dictionary<Guid, string> resourceNames; 100 public Dictionary<Guid, string> ResourceNames { 101 get { return resourceNames; } 102 } 103 104 private HashSet<Resource> disabledParentResources; 105 public HashSet<Resource> DisabledParentResources { 106 get { return disabledParentResources; } 107 } 108 59 109 private List<Plugin> onlinePlugins; 60 110 public List<Plugin> OnlinePlugins { … … 93 143 94 144 try { 145 projects = new ItemList<Project>(); 146 resources = new ItemList<Resource>(); 95 147 jobs = new HiveItemCollection<RefreshableJob>(); 96 var jobsLoaded = HiveServiceLocator.Instance.CallHiveService<IEnumerable<Job>>(s => s.GetJobs()); 97 98 try { 99 foreach (var j in jobsLoaded) { 100 jobs.Add(new RefreshableJob(j)); 101 } 102 } catch (NullReferenceException) { 103 // jobs was set to null during ClearHiveClient 104 } 148 projectNames = new Dictionary<Guid, string>(); 149 resourceNames = new Dictionary<Guid, string>(); 150 151 projectAncestors = new Dictionary<Guid, HashSet<Guid>>(); 152 projectDescendants = new Dictionary<Guid, HashSet<Guid>>(); 153 resourceAncestors = new Dictionary<Guid, HashSet<Guid>>(); 154 resourceDescendants = new Dictionary<Guid, HashSet<Guid>>(); 155 156 HiveServiceLocator.Instance.CallHiveService(service => { 157 service.GetProjects().ForEach(p => projects.Add(p)); 158 service.GetSlaveGroups().ForEach(g => resources.Add(g)); 159 service.GetSlaves().ForEach(s => resources.Add(s)); 160 service.GetJobs().ForEach(p => jobs.Add(new RefreshableJob(p))); 161 projectNames = service.GetProjectNames(); 162 resourceNames = service.GetResourceNames(); 163 }); 164 165 RefreshResourceGenealogy(); 166 RefreshProjectGenealogy(); 167 RefreshDisabledParentProjects(); 168 RefreshDisabledParentResources(); 169 } 170 catch { 171 jobs = null; 172 projects = null; 173 resources = null; 174 throw; 175 } 176 finally { 177 OnRefreshed(); 178 } 179 } 180 181 public void RefreshProjectsAndResources() { 182 OnRefreshing(); 183 184 try { 185 projects = new ItemList<Project>(); 186 projectNames = new Dictionary<Guid, string>(); 187 resources = new ItemList<Resource>(); 188 resourceNames = new Dictionary<Guid, string>(); 189 190 projectAncestors = new Dictionary<Guid, HashSet<Guid>>(); 191 projectDescendants = new Dictionary<Guid, HashSet<Guid>>(); 192 resourceAncestors = new Dictionary<Guid, HashSet<Guid>>(); 193 resourceDescendants = new Dictionary<Guid, HashSet<Guid>>(); 194 195 HiveServiceLocator.Instance.CallHiveService(service => { 196 service.GetProjects().ForEach(p => projects.Add(p)); 197 service.GetSlaveGroups().ForEach(g => resources.Add(g)); 198 service.GetSlaves().ForEach(s => resources.Add(s)); 199 projectNames = service.GetProjectNames(); 200 resourceNames = service.GetResourceNames(); 201 }); 202 203 RefreshResourceGenealogy(); 204 RefreshProjectGenealogy(); 205 RefreshDisabledParentProjects(); 206 RefreshDisabledParentResources(); 105 207 } catch { 106 jobs = null; 208 projects = null; 209 resources = null; 107 210 throw; 108 211 } finally { 109 212 OnRefreshed(); 110 213 } 214 } 215 216 public void RefreshAsync(Action<Exception> exceptionCallback) { 217 var call = new Func<Exception>(delegate() { 218 try { 219 Refresh(); 220 } 221 catch (Exception ex) { 222 return ex; 223 } 224 return null; 225 }); 226 call.BeginInvoke(delegate(IAsyncResult result) { 227 Exception ex = call.EndInvoke(result); 228 if (ex != null) exceptionCallback(ex); 229 }, null); 230 } 231 232 private void RefreshResourceGenealogy() { 233 resourceAncestors.Clear(); 234 resourceDescendants.Clear(); 235 236 // fetch resource ancestor set 237 HiveServiceLocator.Instance.CallHiveService(service => { 238 var ra = service.GetResourceGenealogy(); 239 ra.Keys.ToList().ForEach(k => resourceAncestors.Add(k, new HashSet<Guid>())); 240 resourceAncestors.Keys.ToList().ForEach(k => resourceAncestors[k].UnionWith(ra[k])); 241 }); 242 243 // build resource descendant set 244 resourceAncestors.Keys.ToList().ForEach(k => resourceDescendants.Add(k, new HashSet<Guid>())); 245 foreach (var ra in resourceAncestors) { 246 foreach(var ancestor in ra.Value) { 247 resourceDescendants[ancestor].Add(ra.Key); 248 } 249 } 250 } 251 252 private void RefreshProjectGenealogy() { 253 projectAncestors.Clear(); 254 projectDescendants.Clear(); 255 256 // fetch project ancestor list 257 HiveServiceLocator.Instance.CallHiveService(service => { 258 var pa = service.GetProjectGenealogy(); 259 pa.Keys.ToList().ForEach(k => projectAncestors.Add(k, new HashSet<Guid>())); 260 projectAncestors.Keys.ToList().ForEach(k => projectAncestors[k].UnionWith(pa[k])); 261 }); 262 263 // build project descendant list 264 projectAncestors.Keys.ToList().ForEach(k => projectDescendants.Add(k, new HashSet<Guid>())); 265 foreach(var pa in projectAncestors) { 266 foreach(var ancestor in pa.Value) { 267 projectDescendants[ancestor].Add(pa.Key); 268 } 269 } 270 } 271 272 private void RefreshDisabledParentProjects() { 273 disabledParentProjects = new HashSet<Project>(); 274 275 foreach (var pid in projects 276 .Where(x => x.ParentProjectId.HasValue) 277 .SelectMany(x => projectAncestors[x.Id]).Distinct() 278 .Where(x => !projects.Select(y => y.Id).Contains(x))) { 279 var p = new Project(); 280 p.Id = pid; 281 p.ParentProjectId = projectAncestors[pid].FirstOrDefault(); 282 p.Name = projectNames[pid]; 283 disabledParentProjects.Add(p); 284 } 285 } 286 287 private void RefreshDisabledParentResources() { 288 disabledParentResources = new HashSet<Resource>(); 289 290 foreach (var rid in resources 291 .Where(x => x.ParentResourceId.HasValue) 292 .SelectMany(x => resourceAncestors[x.Id]).Distinct() 293 .Where(x => !resources.Select(y => y.Id).Contains(x))) { 294 var r = new SlaveGroup(); 295 r.Id = rid; 296 r.ParentResourceId = resourceAncestors[rid].FirstOrDefault(); 297 r.Name = resourceNames[rid]; 298 disabledParentResources.Add(r); 299 } 300 } 301 302 public IEnumerable<Project> GetAvailableProjectAncestors(Guid id) { 303 if (projectAncestors.ContainsKey(id)) return projects.Where(x => projectAncestors[id].Contains(x.Id)); 304 else return Enumerable.Empty<Project>(); 305 } 306 307 public IEnumerable<Project> GetAvailableProjectDescendants(Guid id) { 308 if (projectDescendants.ContainsKey(id)) return projects.Where(x => projectDescendants[id].Contains(x.Id)); 309 else return Enumerable.Empty<Project>(); 310 } 311 312 public IEnumerable<Resource> GetAvailableResourceAncestors(Guid id) { 313 if (resourceAncestors.ContainsKey(id)) return resources.Where(x => resourceAncestors[id].Contains(x.Id)); 314 else return Enumerable.Empty<Resource>(); 315 } 316 317 public IEnumerable<Resource> GetAvailableResourceDescendants(Guid id) { 318 if (resourceDescendants.ContainsKey(id)) return resources.Where(x => resourceDescendants[id].Contains(x.Id)); 319 else return Enumerable.Empty<Resource>(); 320 } 321 322 public IEnumerable<Resource> GetAvailableResourcesForProject(Guid id) { 323 var assignedProjectResources = HiveServiceLocator.Instance.CallHiveService(s => s.GetAssignedResourcesForProject(id)); 324 return resources.Where(x => assignedProjectResources.Select(y => y.ResourceId).Contains(x.Id)); 325 } 326 327 public IEnumerable<Resource> GetDisabledResourceAncestors(IEnumerable<Resource> availableResources) { 328 var missingParentIds = availableResources 329 .Where(x => x.ParentResourceId.HasValue) 330 .SelectMany(x => resourceAncestors[x.Id]).Distinct() 331 .Where(x => !availableResources.Select(y => y.Id).Contains(x)); 332 333 return resources.OfType<SlaveGroup>().Union(disabledParentResources).Where(x => missingParentIds.Contains(x.Id)); 111 334 } 112 335 #endregion … … 116 339 if (item.Id == Guid.Empty) { 117 340 if (item is RefreshableJob) { 118 HiveClient.Instance.UploadJob((RefreshableJob)item, cancellationToken);341 item.Id = HiveClient.Instance.UploadJob((RefreshableJob)item, cancellationToken); 119 342 } 120 343 if (item is JobPermission) { … … 126 349 HiveServiceLocator.Instance.CallHiveService((s) => s.GrantPermission(hep.JobId, hep.GrantedUserId, hep.Permission)); 127 350 } 351 if (item is Project) { 352 item.Id = HiveServiceLocator.Instance.CallHiveService(s => s.AddProject((Project)item)); 353 } 128 354 } else { 129 if (item is Job) 130 HiveServiceLocator.Instance.CallHiveService(s => s.UpdateJob((Job)item)); 355 if (item is Job) { 356 var job = (Job)item; 357 HiveServiceLocator.Instance.CallHiveService(s => s.UpdateJob(job, job.ResourceIds)); 358 } 359 if (item is Project) 360 HiveServiceLocator.Instance.CallHiveService(s => s.UpdateProject((Project)item)); 131 361 } 132 362 } 133 363 public static void StoreAsync(Action<Exception> exceptionCallback, IHiveItem item, CancellationToken cancellationToken) { 134 var call = new Func<Exception>(delegate 364 var call = new Func<Exception>(delegate() { 135 365 try { 136 366 Store(item, cancellationToken); 137 } catch (Exception ex) { 367 } 368 catch (Exception ex) { 138 369 return ex; 139 370 } 140 371 return null; 141 372 }); 142 call.BeginInvoke(delegate 373 call.BeginInvoke(delegate(IAsyncResult result) { 143 374 Exception ex = call.EndInvoke(result); 144 375 if (ex != null) exceptionCallback(ex); … … 153 384 154 385 if (item is Job) 155 HiveServiceLocator.Instance.CallHiveService(s => s. DeleteJob(item.Id));386 HiveServiceLocator.Instance.CallHiveService(s => s.UpdateJobState(item.Id, JobState.StatisticsPending)); 156 387 if (item is RefreshableJob) { 157 388 RefreshableJob job = (RefreshableJob)item; … … 159 390 job.StopResultPolling(); 160 391 } 161 HiveServiceLocator.Instance.CallHiveService(s => s. DeleteJob(item.Id));392 HiveServiceLocator.Instance.CallHiveService(s => s.UpdateJobState(item.Id, JobState.StatisticsPending)); 162 393 } 163 394 if (item is JobPermission) { … … 227 458 } 228 459 460 public static void UpdateJob(Action<Exception> exceptionCallback, RefreshableJob refreshableJob, CancellationToken cancellationToken) { 461 refreshableJob.IsProgressing = true; 462 refreshableJob.Progress.Status = "Saving Job..."; 463 HiveClient.StoreAsync( 464 new Action<Exception>((Exception ex) => { 465 exceptionCallback(ex); 466 }), refreshableJob.Job, cancellationToken); 467 refreshableJob.IsProgressing = false; 468 refreshableJob.Progress.Finish(); 469 } 470 471 public static void UpdateJob(RefreshableJob refreshableJob) { 472 refreshableJob.IsProgressing = true; 473 474 try { 475 refreshableJob.Progress.Start("Saving Job..."); 476 HiveClient.StoreAsync(new Action<Exception>((Exception ex) => { 477 throw new Exception("Update failed.", ex); 478 }), refreshableJob.Job, new CancellationToken()); 479 } finally { 480 refreshableJob.IsProgressing = false; 481 refreshableJob.Progress.Finish(); 482 } 483 } 484 485 486 229 487 #region Upload Job 230 488 private Semaphore taskUploadSemaphore = new Semaphore(Settings.Default.MaxParallelUploads, Settings.Default.MaxParallelUploads); 231 489 private static object jobCountLocker = new object(); 232 490 private static object pluginLocker = new object(); 233 private void UploadJob(RefreshableJob refreshableJob, CancellationToken cancellationToken) {491 private Guid UploadJob(RefreshableJob refreshableJob, CancellationToken cancellationToken) { 234 492 try { 235 493 refreshableJob.IsProgressing = true; 236 494 refreshableJob.Progress.Start("Connecting to server..."); 237 IEnumerable<string> resourceNames = ToResourceNameList(refreshableJob.Job.ResourceNames);238 var resourceIds = new List<Guid>();239 foreach (var resourceName in resourceNames) {240 Guid resourceId = HiveServiceLocator.Instance.CallHiveService((s) => s.GetResourceId(resourceName));241 if (resourceId == Guid.Empty) {242 throw new ResourceNotFoundException(string.Format("Could not find the resource '{0}'", resourceName));243 }244 resourceIds.Add(resourceId);245 }246 495 247 496 foreach (OptimizerHiveTask hiveJob in refreshableJob.HiveTasks.OfType<OptimizerHiveTask>()) { … … 251 500 // upload Job 252 501 refreshableJob.Progress.Status = "Uploading Job..."; 253 refreshableJob.Job.Id = HiveServiceLocator.Instance.CallHiveService((s) => s.AddJob(refreshableJob.Job ));502 refreshableJob.Job.Id = HiveServiceLocator.Instance.CallHiveService((s) => s.AddJob(refreshableJob.Job, refreshableJob.Job.ResourceIds)); 254 503 refreshableJob.Job = HiveServiceLocator.Instance.CallHiveService((s) => s.GetJob(refreshableJob.Job.Id)); // update owner and permissions 255 504 cancellationToken.ThrowIfCancellationRequested(); … … 273 522 foreach (HiveTask hiveTask in refreshableJob.HiveTasks) { 274 523 var task = TS.Task.Factory.StartNew((hj) => { 275 UploadTaskWithChildren(refreshableJob.Progress, (HiveTask)hj, null, resourceIds,jobCount, totalJobCount, configFilePlugin.Id, refreshableJob.Job.Id, refreshableJob.Log, cancellationToken);524 UploadTaskWithChildren(refreshableJob.Progress, (HiveTask)hj, null, jobCount, totalJobCount, configFilePlugin.Id, refreshableJob.Job.Id, refreshableJob.Log, cancellationToken); 276 525 }, hiveTask); 277 526 task.ContinueWith((x) => refreshableJob.Log.LogException(x.Exception), TaskContinuationOptions.OnlyOnFaulted); … … 279 528 } 280 529 TS.Task.WaitAll(tasks.ToArray()); 281 } finally { 530 } 531 finally { 282 532 refreshableJob.Job.Modified = false; 283 533 refreshableJob.IsProgressing = false; 284 534 refreshableJob.Progress.Finish(); 285 535 } 536 return (refreshableJob.Job != null) ? refreshableJob.Job.Id : Guid.Empty; 286 537 } 287 538 … … 317 568 /// </summary> 318 569 /// <param name="parentHiveTask">shall be null if its the root task</param> 319 private void UploadTaskWithChildren(IProgress progress, HiveTask hiveTask, HiveTask parentHiveTask, IEnumerable<Guid> groups,int[] taskCount, int totalJobCount, Guid configPluginId, Guid jobId, ILog log, CancellationToken cancellationToken) {570 private void UploadTaskWithChildren(IProgress progress, HiveTask hiveTask, HiveTask parentHiveTask, int[] taskCount, int totalJobCount, Guid configPluginId, Guid jobId, ILog log, CancellationToken cancellationToken) { 320 571 taskUploadSemaphore.WaitOne(); 321 572 bool semaphoreReleased = false; … … 356 607 hiveTask.Task.Id = HiveServiceLocator.Instance.CallHiveService((s) => s.AddChildTask(parentHiveTask.Task.Id, hiveTask.Task, taskData)); 357 608 } else { 358 hiveTask.Task.Id = HiveServiceLocator.Instance.CallHiveService((s) => s.AddTask(hiveTask.Task, taskData , groups.ToList()));609 hiveTask.Task.Id = HiveServiceLocator.Instance.CallHiveService((s) => s.AddTask(hiveTask.Task, taskData)); 359 610 } 360 611 } … … 371 622 var task = TS.Task.Factory.StartNew((tuple) => { 372 623 var arguments = (Tuple<HiveTask, HiveTask>)tuple; 373 UploadTaskWithChildren(progress, arguments.Item1, arguments.Item2, groups,taskCount, totalJobCount, configPluginId, jobId, log, cancellationToken);624 UploadTaskWithChildren(progress, arguments.Item1, arguments.Item2, taskCount, totalJobCount, configPluginId, jobId, log, cancellationToken); 374 625 }, new Tuple<HiveTask, HiveTask>(child, hiveTask)); 375 626 task.ContinueWith((x) => log.LogException(x.Exception), TaskContinuationOptions.OnlyOnFaulted); … … 426 677 } else if (refreshableJob.IsPaused()) { 427 678 refreshableJob.ExecutionState = Core.ExecutionState.Paused; 428 } else { 679 } else { 429 680 refreshableJob.ExecutionState = Core.ExecutionState.Started; 430 681 } 431 682 refreshableJob.OnLoaded(); 432 } finally { 683 } 684 finally { 433 685 refreshableJob.IsProgressing = false; 434 686 refreshableJob.Progress.Finish(); … … 467 719 try { 468 720 return PersistenceUtil.Deserialize<ItemTask>(taskData.Data); 469 } catch { 721 } 722 catch { 470 723 return null; 471 724 } … … 478 731 public static void TryAndRepeat(Action action, int repetitions, string errorMessage, ILog log = null) { 479 732 while (true) { 480 try { action(); return; } catch (Exception e) { 733 try { action(); return; } 734 catch (Exception e) { 481 735 if (repetitions == 0) throw new HiveException(errorMessage, e); 482 736 if (log != null) log.LogMessage(string.Format("{0}: {1} - will try again!", errorMessage, e.ToString())); … … 495 749 }); 496 750 } 751 752 public string GetProjectAncestry(Guid projectId) { 753 if (projectId == null || projectId == Guid.Empty) return ""; 754 var projects = projectAncestors[projectId].Reverse().ToList(); 755 projects.Add(projectId); 756 return string.Join(" » ", projects.Select(x => ProjectNames[x]).ToArray()); 757 } 758 759 public IEnumerable<Resource> GetAssignedResourcesForJob(Guid jobId) { 760 var assignedJobResource = HiveServiceLocator.Instance.CallHiveService(service => service.GetAssignedResourcesForJob(jobId)); 761 return Resources.Where(x => assignedJobResource.Select(y => y.ResourceId).Contains(x.Id)); 762 } 497 763 } 498 764 }
Note: See TracChangeset
for help on using the changeset viewer.