656bf0b6ae74a3f41a2d5048c04ae4f45fb7d9be
[gp-arc-client-c.git] / ext / arc_get.cpp
1 /*
2  *  get.cpp
3  *  arcclientc
4  *
5  *  Created by Tamas Jung on 10/25/10.
6  *
7  */
8
9 #include "arc_get.h"
10
11 // -*- indent-tabs-mode: nil -*-
12
13
14 #include "logger.h"
15 #include <iostream>
16 #include <list>
17 #include <string>
18 #include "arc_libs.h"
19
20
21 int arc_get(int argc, char **argv) {
22         
23         
24
25         
26         Arc::OptionParser options(istring("[job ...]"),
27                                                           istring("The arcget command is used for "
28                                                                           "retrieving the results from a job."),
29                                                           istring("Argument to -c has the format "
30                                                                           "Flavour:URL e.g.\n"
31                                                                           "ARC0:ldap://grid.tsl.uu.se:2135/"
32                                                                           "nordugrid-cluster-name=grid.tsl.uu.se,"
33                                                                           "Mds-Vo-name=local,o=grid"));
34         
35         
36         std::string joblist;
37         options.AddOption('j', "joblist",
38                                           istring("file containing a list of jobs"),
39                                           istring("filename"),
40                                           joblist);
41         
42         std::list<std::string> clusters;
43         options.AddOption('c', "cluster",
44                                           istring("explicitly select or reject a specific resource"),
45                                           istring("[-]name"),
46                                           clusters);
47         
48         std::list<std::string> status;
49         options.AddOption('s', "status",
50                                           istring("only select jobs whose status is statusstr"),
51                                           istring("statusstr"),
52                                           status);
53         
54         std::string downloaddir;
55         options.AddOption('D', "dir",
56                                           istring("download directory (the job directory will"
57                                                           " be created in this directory)"),
58                                           istring("dirname"),
59                                           downloaddir);
60         
61         bool keep = false;
62         options.AddOption('k', "keep",
63                                           istring("keep the files on the server (do not clean)"),
64                                           keep);
65         
66         int timeout = -1;
67         options.AddOption('t', "timeout", istring("timeout in seconds (default 20)"),
68                                           istring("seconds"), timeout);
69         
70         std::string conffile;
71         options.AddOption('z', "conffile",
72                                           istring("configuration file (default ~/.arc/client.conf)"),
73                                           istring("filename"), conffile);
74         
75         
76         
77         std::list<std::string> jobs = options.Parse(argc, argv);
78         
79
80                 
81                 
82         Arc::UserConfig usercfg(conffile, joblist);
83         if (!usercfg) {
84                 logger.msg(Arc::ERROR, "Failed configuration initialization");
85                 return 1;
86         }
87                 
88         if (timeout > 0)
89         usercfg.Timeout(timeout);
90                 
91         if (jobs.empty() && clusters.empty()) {
92                 logger.msg(Arc::ERROR, "No jobs given");
93                 return 1;
94         }
95         
96         if (!jobs.empty())
97                 usercfg.ClearSelectedServices();
98         
99         if (!clusters.empty()) {
100                 usercfg.ClearSelectedServices();
101                 usercfg.AddServices(clusters, Arc::COMPUTING);
102         }
103         
104         Arc::JobSupervisor jobmaster(usercfg, jobs);
105         if (!jobmaster.JobsFound()) {
106                 logger.msg(Arc::ERROR, "No jobs");
107                 return 1;
108         }
109         std::list<Arc::JobController*> jobcont = jobmaster.GetJobControllers();
110         
111         // If the user specified a joblist on the command line joblist equals
112         // usercfg.JobListFile(). If not use the default, ie. usercfg.JobListFile().
113         if (jobcont.empty()) {
114                 logger.msg(Arc::ERROR, "No job controller plugins loaded");
115                 return 1;
116         }
117   int result = 0;
118         for (std::list<Arc::JobController*>::iterator it = jobcont.begin();
119                  it != jobcont.end(); it++){
120                 if (!(*it)->Get(status, downloaddir, keep)){
121                         result = 1;
122                 }
123         }
124         
125         return result;
126 }