ARC SDK
Broker.h
1 // -*- indent-tabs-mode: nil -*-
2 
3 #ifndef __ARC_BROKER_H__
4 #define __ARC_BROKER_H__
5 
6 #include <algorithm>
7 #include <set>
8 #include <string>
9 
10 #include <arc/URL.h>
11 #include <arc/Utils.h>
12 #include <arc/compute/EntityRetriever.h>
13 #include <arc/compute/JobDescription.h>
14 #include <arc/compute/BrokerPlugin.h>
15 
16 namespace Arc {
17 
18  class ExecutionTarget;
19  class Logger;
20  class URL;
21  class UserConfig;
22 
24 
43  class Broker {
44  public:
46 
51  Broker(const UserConfig& uc, const std::string& name = "");
53 
59  Broker(const UserConfig& uc, const JobDescription& j, const std::string& name = "");
61  Broker(const Broker& b);
63  ~Broker();
65  Broker& operator=(const Broker& b);
66 
68  bool operator() (const ExecutionTarget& lhs, const ExecutionTarget& rhs) const;
70  bool match(const ExecutionTarget& et) const;
71 
73 
170  static bool genericMatch(const ExecutionTarget& et, const JobDescription& j, const Arc::UserConfig&);
172 
175  bool isValid(bool alsoCheckJobDescription = true) const;
177  void set(const JobDescription& _j) const;
179  const JobDescription& getJobDescription() const { return *j; }
180 
181  private:
182  const UserConfig& uc;
183  mutable const JobDescription* j;
184 
185  std::string proxyDN;
186  std::string proxyIssuerCA;
187 
189 
190  static BrokerPluginLoader& getLoader();
191 
192  static Logger logger;
193  };
194 
196 
204  class ExecutionTargetSorter : public EntityConsumer<ComputingServiceType> {
205  public:
207  ExecutionTargetSorter(const Broker& b, const std::list<URL>& rejectEndpoints = std::list<URL>())
208  : b(&b), rejectEndpoints(rejectEndpoints), current(targets.first.begin()) {}
210  ExecutionTargetSorter(const Broker& b, const JobDescription& j, const std::list<URL>& rejectEndpoints = std::list<URL>())
211  : b(&b), rejectEndpoints(rejectEndpoints), current(targets.first.begin()) { set(j); }
213  ExecutionTargetSorter(const Broker& b, const std::list<ComputingServiceType>& csList, const std::list<URL>& rejectEndpoints = std::list<URL>())
214  : b(&b), rejectEndpoints(rejectEndpoints), current(targets.first.begin()) { addEntities(csList); }
216  ExecutionTargetSorter(const Broker& b, const JobDescription& j, const std::list<ComputingServiceType>& csList, const std::list<URL>& rejectEndpoints = std::list<URL>())
217  : b(&b), rejectEndpoints(rejectEndpoints), current(targets.first.begin()) { set(j); addEntities(csList); }
218  virtual ~ExecutionTargetSorter() {}
219 
221  void addEntity(const ExecutionTarget& et);
223  void addEntity(const ComputingServiceType& cs);
225  void addEntities(const std::list<ComputingServiceType>&);
226 
228  void reset() { current = targets.first.begin(); }
230  bool next() { if (!endOfList()) { ++current; }; return !endOfList(); }
232  bool endOfList() const { return current == targets.first.end(); }
233 
235  const ExecutionTarget& operator*() const { return *current; }
237  const ExecutionTarget& getCurrentTarget() const { return *current; }
239  const ExecutionTarget* operator->() const { return &*current; }
240 
242  const std::list<ExecutionTarget>& getMatchingTargets() const { return targets.first; }
244  const std::list<ExecutionTarget>& getNonMatchingTargets() const { return targets.second; }
245 
247  void clear() { targets.first.clear(); targets.second.clear(); }
249 
254  void registerJobSubmission();
255 
257  void set(const Broker& newBroker) { b = &newBroker; sort(); }
259  void set(const JobDescription& j) { b->set(j); sort(); }
261  void setRejectEndpoints(const std::list<URL>& newRejectEndpoints) { rejectEndpoints = newRejectEndpoints; }
262 
263  private:
264  void sort();
265  void insert(const ExecutionTarget& et);
266  bool reject(const ExecutionTarget& et);
267 
268  const Broker* b;
269  std::list<URL> rejectEndpoints;
270  // Map of ExecutionTargets. first: matching; second: unsuitable.
271  std::pair< std::list<ExecutionTarget>, std::list<ExecutionTarget> > targets;
272  std::list<ExecutionTarget>::iterator current;
273 
274  static Logger logger;
275  };
276 
277 } // namespace Arc
278 
279 #endif // __ARC_BROKER_H__