-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCpusetResourceEstimatorModule.cpp
More file actions
89 lines (70 loc) · 2.26 KB
/
CpusetResourceEstimatorModule.cpp
File metadata and controls
89 lines (70 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// special thanks to blue yonder
// for their threshold project
// https://github.com/blue-yonder/mesos-threshold-oversubscription
//
#include <process/future.hpp>
#include <process/owned.hpp>
#include <process/process.hpp>
#include <process/id.hpp>
#include <process/dispatch.hpp>
#include <stout/nothing.hpp>
#include <stout/try.hpp>
#include <stout/option.hpp>
#include <stout/os.hpp>
#include "slave/flags.hpp"
#include <mesos/mesos.pb.h>
#include <mesos/slave/isolator.hpp>
#include <mesos/slave/isolator.pb.h>
#include <mesos/module/resource_estimator.hpp>
#include <mesos/mesos.hpp>
#include <mesos/module.hpp>
#include <mesos/resources.hpp>
#include <string>
#include "CpusetResourceEstimator.hpp"
struct ParsingError
{
std::string message;
ParsingError(std::string const& description, std::string const& error)
: message("Failed to parse " + description + ": " + error)
{}
};
template <typename Interface, typename ThresholdActor>
static Interface* create(mesos::Parameters const& parameters) {
mesos::Resources resources;
Option<std::string> dbpath;
try {
for (auto const& parameter : parameters.parameter()) {
// Parse the resource to offer for oversubscription
if (parameter.key() == "resources") {
Try<mesos::Resources> parsed = mesos::Resources::parse(parameter.value());
if (parsed.isError()) {
throw ParsingError("resources", parsed.error());
}
resources = parsed.get();
}
// Parse any thresholds
if (parameter.key() == "cpusetdbpath") {
dbpath = parameter.value();
}
}
} catch (ParsingError e) {
LOG(ERROR) << e.message;
return nullptr;
}
const std::string dbpathval = (dbpath.isSome()) ? dbpath.get() : os::getcwd();
return new ThresholdActor(resources, dbpathval);
}
static mesos::slave::ResourceEstimator* createEstimator(mesos::Parameters const& parameters) {
return create<mesos::slave::ResourceEstimator, CpusetResourceEstimator>(parameters);
}
static bool compatible() {
return true;
}
mesos::modules::Module<mesos::slave::ResourceEstimator> CpusetThresholdResourceEstimator(
MESOS_MODULE_API_VERSION,
MESOS_VERSION,
"Apache Mesos",
"ct-clmsn@gmail.com",
"Cpuset Resource Estimator Module.",
compatible,
createEstimator);