Fawkes API Fawkes Development Version
lookup_estimator.h
1/***************************************************************************
2 * lookup_estimator.h - Estimate skill exec times via lookups from mongodb
3 *
4 * Created: Tue 24 Mar 2020 11:18:59 CET 11:18
5 * Copyright 2020 Tarik Viehmann <viehmann@kbsg.rwth-aachen.de>
6 ****************************************************************************/
7
8/* This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Library General Public License for more details.
17 *
18 * Read the full text in the LICENSE.GPL file in the doc directory.
19 */
20
21#pragma once
22
23#include <aspect/logging.h>
24#include <config/config.h>
25#include <core/threading/mutex.h>
26#include <execution_time_estimator/aspect/execution_time_estimator.h>
27#include <plugins/mongodb/aspect/mongodb_conncreator.h>
28
29#include <bsoncxx/builder/basic/document.hpp>
30#include <string>
31#include <vector>
32
34
35namespace fawkes {
37{
38 /// Friend the ExecutionTimeEstimatorLookupEstimatorThread so that only it can access init
39 friend class ::ExecutionTimeEstimatorLookupEstimatorThread;
40
41public:
42 LookupEstimator(MongoDBConnCreator *mongo_connection_manager,
43 Configuration * config,
44 const std::string & cfg_prefix,
45 Logger * logger);
46 float get_execution_time(const Skill &skill) override;
47 bool can_provide_exec_time(const Skill &skill) const override;
48 std::pair<SkillerInterface::SkillStatusEnum, std::string> execute(const Skill &skill) override;
49
50private:
51 bsoncxx::builder::basic::document get_skill_query(const Skill &skill) const;
52
53 MongoDBConnCreator *mongo_connection_manager_;
54 Logger * logger_;
55
56 constexpr static char logger_name_[] = "LookupEstimator";
57 constexpr static char skill_name_field_[] = "name";
58 constexpr static char duration_field_[] = "duration";
59
60 mutable fawkes::Mutex mutex_;
61 mongocxx::client * mongodb_client_lookup_;
62
63 Property<bool> fully_match_args_;
64 Property<bool> include_failures_;
65
66 const std::string instance_;
67 const std::string database_;
68 const std::string collection_;
69
70 const std::map<std::string, bool> skill_match_args;
71
72 std::string error_;
74};
75} // namespace fawkes
Get estimates for skill execution times from samples of a mongodb database.
Definition: lookup_thread.h:36
Interface for configuration handling.
Definition: config.h:68
A configurable property that is skill-specific and may have a default value.
A structured representation of a skill.
An abstract estimator for the execution time of a skill.
Interface for logging.
Definition: logger.h:42
Estimate the execution time of skills by drawing a random sample from a set of possible values stored...
LookupEstimator(MongoDBConnCreator *mongo_connection_manager, Configuration *config, const std::string &cfg_prefix, Logger *logger)
Constructor.
float get_execution_time(const Skill &skill) override
Get the estimated execution time for the given skill string.
bool can_provide_exec_time(const Skill &skill) const override
Check if this estimator can give an estimate for a given skill.
std::pair< SkillerInterface::SkillStatusEnum, std::string > execute(const Skill &skill) override
Let the estimator know that we are executing this skill, so it can apply possible side effects.
Interface for a MongoDB connection creator.
Mutex mutual exclusion lock.
Definition: mutex.h:33
SkillStatusEnum
This determines the current status of skill execution.
Fawkes library namespace.