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 
161  static bool genericMatch(const ExecutionTarget& et, const JobDescription& j, const Arc::UserConfig&);
163 
166  bool isValid(bool alsoCheckJobDescription = true) const;
168  void set(const JobDescription& _j) const;
170  const JobDescription& getJobDescription() const { return *j; }
171 
172  private:
173  const UserConfig& uc;
174  mutable const JobDescription* j;
175 
176  std::string proxyDN;
177  std::string proxyIssuerCA;
178 
180 
181  static BrokerPluginLoader& getLoader();
182 
183  static Logger logger;
184  };
185 
187 
195  class ExecutionTargetSorter : public EntityConsumer<ComputingServiceType> {
196  public:
198  ExecutionTargetSorter(const Broker& b, const std::list<URL>& rejectEndpoints = std::list<URL>())
199  : b(&b), rejectEndpoints(rejectEndpoints), current(targets.first.begin()) {}
201  ExecutionTargetSorter(const Broker& b, const JobDescription& j, const std::list<URL>& rejectEndpoints = std::list<URL>())
202  : b(&b), rejectEndpoints(rejectEndpoints), current(targets.first.begin()) { set(j); }
204  ExecutionTargetSorter(const Broker& b, const std::list<ComputingServiceType>& csList, const std::list<URL>& rejectEndpoints = std::list<URL>())
205  : b(&b), rejectEndpoints(rejectEndpoints), current(targets.first.begin()) { addEntities(csList); }
207  ExecutionTargetSorter(const Broker& b, const JobDescription& j, const std::list<ComputingServiceType>& csList, const std::list<URL>& rejectEndpoints = std::list<URL>())
208  : b(&b), rejectEndpoints(rejectEndpoints), current(targets.first.begin()) { set(j); addEntities(csList); }
209  virtual ~ExecutionTargetSorter() {}
210 
212  void addEntity(const ExecutionTarget& et);
214  void addEntity(const ComputingServiceType& cs);
216  void addEntities(const std::list<ComputingServiceType>&);
217 
219  void reset() { current = targets.first.begin(); }
221  bool next() { if (!endOfList()) { ++current; }; return !endOfList(); }
223  bool endOfList() const { return current == targets.first.end(); }
224 
226  const ExecutionTarget& operator*() const { return *current; }
228  const ExecutionTarget& getCurrentTarget() const { return *current; }
230  const ExecutionTarget* operator->() const { return &*current; }
231 
233  const std::list<ExecutionTarget>& getMatchingTargets() const { return targets.first; }
235  const std::list<ExecutionTarget>& getNonMatchingTargets() const { return targets.second; }
236 
238  void clear() { targets.first.clear(); targets.second.clear(); }
240 
245  void registerJobSubmission();
246 
248  void set(const Broker& newBroker) { b = &newBroker; sort(); }
250  void set(const JobDescription& j) { b->set(j); sort(); }
252  void setRejectEndpoints(const std::list<URL>& newRejectEndpoints) { rejectEndpoints = newRejectEndpoints; }
253 
254  private:
255  void sort();
256  void insert(const ExecutionTarget& et);
257  bool reject(const ExecutionTarget& et);
258 
259  const Broker* b;
260  std::list<URL> rejectEndpoints;
261  // Map of ExecutionTargets. first: matching; second: unsuitable.
262  std::pair< std::list<ExecutionTarget>, std::list<ExecutionTarget> > targets;
263  std::list<ExecutionTarget>::iterator current;
264 
265  static Logger logger;
266  };
267 
268 } // namespace Arc
269 
270 #endif // __ARC_BROKER_H__