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;
72 
79  static bool genericMatch(const ExecutionTarget& et, const JobDescription& j, const Arc::UserConfig&);
81 
84  bool isValid(bool alsoCheckJobDescription = true) const;
86  void set(const JobDescription& _j) const;
88  const JobDescription& getJobDescription() const { return *j; }
89 
90  private:
91  const UserConfig& uc;
92  mutable const JobDescription* j;
93 
94  std::string proxyDN;
95  std::string proxyIssuerCA;
96 
98 
99  static BrokerPluginLoader& getLoader();
100 
101  static Logger logger;
102  };
103 
105 
113  class ExecutionTargetSorter : public EntityConsumer<ComputingServiceType> {
114  public:
116  ExecutionTargetSorter(const Broker& b, const std::list<URL>& rejectEndpoints = std::list<URL>())
117  : b(&b), rejectEndpoints(rejectEndpoints), current(targets.first.begin()) {}
119  ExecutionTargetSorter(const Broker& b, const JobDescription& j, const std::list<URL>& rejectEndpoints = std::list<URL>())
120  : b(&b), rejectEndpoints(rejectEndpoints), current(targets.first.begin()) { set(j); }
122  ExecutionTargetSorter(const Broker& b, const std::list<ComputingServiceType>& csList, const std::list<URL>& rejectEndpoints = std::list<URL>())
123  : b(&b), rejectEndpoints(rejectEndpoints), current(targets.first.begin()) { addEntities(csList); }
125  ExecutionTargetSorter(const Broker& b, const JobDescription& j, const std::list<ComputingServiceType>& csList, const std::list<URL>& rejectEndpoints = std::list<URL>())
126  : b(&b), rejectEndpoints(rejectEndpoints), current(targets.first.begin()) { set(j); addEntities(csList); }
127  virtual ~ExecutionTargetSorter() {}
128 
130  void addEntity(const ExecutionTarget& et);
132  void addEntity(const ComputingServiceType& cs);
134  void addEntities(const std::list<ComputingServiceType>&);
135 
137  void reset() { current = targets.first.begin(); }
139  bool next() { if (!endOfList()) { ++current; }; return !endOfList(); }
141  bool endOfList() const { return current == targets.first.end(); }
142 
144  const ExecutionTarget& operator*() const { return *current; }
146  const ExecutionTarget& getCurrentTarget() const { return *current; }
148  const ExecutionTarget* operator->() const { return &*current; }
149 
151  const std::list<ExecutionTarget>& getMatchingTargets() const { return targets.first; }
153  const std::list<ExecutionTarget>& getNonMatchingTargets() const { return targets.second; }
154 
156  void clear() { targets.first.clear(); targets.second.clear(); }
158 
163  void registerJobSubmission();
164 
166  void set(const Broker& newBroker) { b = &newBroker; sort(); }
168  void set(const JobDescription& j) { b->set(j); sort(); }
170  void setRejectEndpoints(const std::list<URL>& newRejectEndpoints) { rejectEndpoints = newRejectEndpoints; }
171 
172  private:
173  void sort();
174  void insert(const ExecutionTarget& et);
175  bool reject(const ExecutionTarget& et);
176 
177  const Broker* b;
178  std::list<URL> rejectEndpoints;
179  // Map of ExecutionTargets. first: matching; second: unsuitable.
180  std::pair< std::list<ExecutionTarget>, std::list<ExecutionTarget> > targets;
181  std::list<ExecutionTarget>::iterator current;
182 
183  static Logger logger;
184  };
185 
186 } // namespace Arc
187 
188 #endif // __ARC_BROKER_H__