1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2015 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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.IO;
|
---|
25 | using System.Threading;
|
---|
26 | using HeuristicLab.Clients.Hive;
|
---|
27 | using HeuristicLab.Core;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.HiveDrain {
|
---|
30 | /// <summary>
|
---|
31 | /// Retrieves all jobs and starts downloading their tasks
|
---|
32 | /// </summary>
|
---|
33 | public class JobDownloader {
|
---|
34 | public string RootLocation { get; set; }
|
---|
35 |
|
---|
36 | public string NamePattern { get; set; }
|
---|
37 |
|
---|
38 | public bool OneFile { get; set; }
|
---|
39 |
|
---|
40 | private ILog log;
|
---|
41 |
|
---|
42 | public JobDownloader(string location, string pattern, ILog log, bool oneFile = false) {
|
---|
43 | RootLocation = location;
|
---|
44 | NamePattern = pattern;
|
---|
45 | this.log = log;
|
---|
46 | OneFile = oneFile;
|
---|
47 | }
|
---|
48 |
|
---|
49 | public void Start() {
|
---|
50 | var jobsLoaded = HiveServiceLocator.Instance.CallHiveService<IEnumerable<Job>>(s => s.GetJobs());
|
---|
51 | Semaphore limitSemaphore = new Semaphore(HeuristicLabHiveDrainApplication.MaxParallelDownloads, HeuristicLabHiveDrainApplication.MaxParallelDownloads);
|
---|
52 |
|
---|
53 | foreach (Job j in jobsLoaded) {
|
---|
54 | if (string.IsNullOrEmpty(NamePattern) || j.Name.Contains(NamePattern)) {
|
---|
55 | string jobPath = Path.Combine(RootLocation, String.Format("{0} - {1}", j.Name, j.Id));
|
---|
56 | log.LogMessage(String.Format("\"{0}\": {1}", j.Name, j.Id));
|
---|
57 |
|
---|
58 | if (OneFile) {
|
---|
59 | JobTaskOneFileDownloader taskDownloader = new JobTaskOneFileDownloader(jobPath, j, limitSemaphore, log);
|
---|
60 | taskDownloader.Start();
|
---|
61 | } else {
|
---|
62 | JobTaskDownloader taskDownloader = new JobTaskDownloader(jobPath, j, limitSemaphore, log);
|
---|
63 | taskDownloader.Start();
|
---|
64 | }
|
---|
65 | } else {
|
---|
66 | log.LogMessage(String.Format("\"{0}\": {1} ---> ignored", j.Name, j.Id));
|
---|
67 | }
|
---|
68 | }
|
---|
69 | }
|
---|
70 | }
|
---|
71 | }
|
---|