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