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__
Arc namespace contains all core ARC classes.
Definition: ArcConfig.h:11
User configuration class
Definition: UserConfig.h:196
const ExecutionTarget & operator*() const
Returns current target.
Definition: Broker.h:226
void addEntities(const std::list< ComputingServiceType > &)
Add a list of ComputingServiceTypes and rank them according to the Broker.
Broker & operator=(const Broker &b)
Assignment operator. BrokerPlugin copying is handled automatically.
bool next()
Advance to the next target. Returns false if the current target is the last one.
Definition: Broker.h:221
void reset()
Reset to the first target in the ranked list.
Definition: Broker.h:219
bool match(const ExecutionTarget &et) const
Returns true if the ExecutionTarget is allowed by BrokerPlugin.
A Broker filters and ranks acceptable targets for job submission.
Definition: Broker.h:43
ExecutionTargetSorter(const Broker &b, const std::list< ComputingServiceType > &csList, const std::list< URL > &rejectEndpoints=std::list< URL >())
Constructor passing list of targets.
Definition: Broker.h:204
Wrapper around Broker functionality.
Definition: Broker.h:195
A logger class.
Definition: Logger.h:493
bool isValid(bool alsoCheckJobDescription=true) const
Returns true if the BrokerPlugin loaded by this Broker is valid.
ExecutionTargetSorter(const Broker &b, const JobDescription &j, const std::list< ComputingServiceType > &csList, const std::list< URL > &rejectEndpoints=std::list< URL >())
Constructor passing JobDescription and list of targets.
Definition: Broker.h:207
Wrapper for pointer with automatic destruction and multiple references.
Definition: Utils.h:183
const ExecutionTarget * operator->() const
Returns pointer to current target.
Definition: Broker.h:230
void setRejectEndpoints(const std::list< URL > &newRejectEndpoints)
Set a list of endpoints to reject when matching.
Definition: Broker.h:252
Definition: JobDescription.h:842
void addEntity(const ExecutionTarget &et)
Add an ExecutionTarget and rank it according to the Broker.
ExecutionTargetSorter(const Broker &b, const std::list< URL > &rejectEndpoints=std::list< URL >())
Basic constructor.
Definition: Broker.h:198
const ExecutionTarget & getCurrentTarget() const
Returns current target.
Definition: Broker.h:228
ExecutionTargetSorter(const Broker &b, const JobDescription &j, const std::list< URL > &rejectEndpoints=std::list< URL >())
Constructor passing JobDescription.
Definition: Broker.h:201
void registerJobSubmission()
Register that job was submitted to current target.
Broker(const UserConfig &uc, const std::string &name="")
Construct a new broker and load the BrokerPlugin of the given type.
bool operator()(const ExecutionTarget &lhs, const ExecutionTarget &rhs) const
Used to sort targets. Returns true if lhs<rhs according to BrokerPlugin.
Handles loading of the required BrokerPlugin plugin.
Definition: BrokerPlugin.h:68
const JobDescription & getJobDescription() const
Get the JobDescription set by set().
Definition: Broker.h:170
static bool genericMatch(const ExecutionTarget &et, const JobDescription &j, const Arc::UserConfig &)
Perform a match between the given target and job.
const std::list< ExecutionTarget > & getNonMatchingTargets() const
Get list of non-matching targets.
Definition: Broker.h:235
const std::list< ExecutionTarget > & getMatchingTargets() const
Get sorted list of matching targets.
Definition: Broker.h:233
ExecutionTarget.
Definition: ExecutionTarget.h:494
bool endOfList() const
Returns true if current target is last in the list.
Definition: Broker.h:223
void clear()
Clear lists of targets.
Definition: Broker.h:238
~Broker()
Destructor. BrokerPlugin unloading is handled automatically.
A general concept of an object which can consume entities use by the retrievers to return results...
Definition: EntityRetriever.h:34
void set(const JobDescription &_j) const
Set the JobDescription to use during brokering.