Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/tools/HeuristicLab.HiveDrain/HeuristicLab.HiveDrain/JobDownloader.cs @ 15342

Last change on this file since 15342 was 15342, checked in by mkommend, 7 years ago

#2829: Added Hive.Drain to HeuristicLab.Tools.

File size: 2.6 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.IO;
25using System.Threading;
26using HeuristicLab.Clients.Hive;
27using HeuristicLab.Core;
28
29namespace 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.IsNullOrEmpty(NamePattern)) {
56          string jobPath = Path.Combine(RootLocation, String.Format("{0} - {1}", j.Name, j.Id));
57          log.LogMessage(String.Format("\"{0}\": {1}", j.Name, j.Id));
58
59          if (OneFile) {
60            JobTaskOneFileDownloader taskDownloader = new JobTaskOneFileDownloader(jobPath, j, limitSemaphore, log);
61            taskDownloader.Start();
62          } else {
63            JobTaskDownloader taskDownloader = new JobTaskDownloader(jobPath, j, limitSemaphore, log);
64            taskDownloader.Start();
65          }
66        } else {
67          log.LogMessage(String.Format("\"{0}\": {1} ---> ignored", j.Name, j.Id));
68        }
69      }
70    }
71  }
72}
Note: See TracBrowser for help on using the repository browser.