You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2014/12/04 01:20:19 UTC
[2/4] mesos git commit: Added basic DiskInfo check in master.
Added basic DiskInfo check in master.
Review: https://reviews.apache.org/r/28626
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/34bb637b
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/34bb637b
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/34bb637b
Branch: refs/heads/master
Commit: 34bb637b2479cede846d8b1140756e06ebc2dafe
Parents: 7ac99a5
Author: Jie Yu <yu...@gmail.com>
Authored: Tue Dec 2 17:26:14 2014 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Wed Dec 3 16:12:07 2014 -0800
----------------------------------------------------------------------
src/master/master.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 61 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/34bb637b/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index c3465a6..bf9d20f 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -1904,17 +1904,76 @@ struct ResourceChecker : TaskInfoVisitor
return Error("Task uses invalid resources: " + error.get().message);
}
+ // Ensure any DiskInfos in the task are valid according to the
+ // currently supported semantics.
+ foreach (const Resource& resource, task.resources()) {
+ if (resource.has_disk()) {
+ error = validateDiskInfo(resource);
+ if (error.isSome()) {
+ return Error("Task uses invalid DiskInfo: " + error.get().message);
+ }
+ }
+ }
+
if (task.has_executor()) {
Option<Error> error = Resources::validate(task.executor().resources());
if (error.isSome()) {
return Error(
- "Executor for task " + stringify(task.task_id()) +
- " uses invalid resources: " + error.get().message);
+ "Executor uses invalid resources: " + error.get().message);
+ }
+
+ // Ensure any DiskInfos in the executor are valid according to
+ // the currently supported semantics.
+ foreach (const Resource& resource, task.executor().resources()) {
+ if (resource.has_disk()) {
+ error = validateDiskInfo(resource);
+ if (error.isSome()) {
+ return Error(
+ "Executor uses invalid DiskInfo: " + error.get().message);
+ }
+ }
}
}
return None();
}
+
+ Option<Error> validateDiskInfo(const Resource& resource)
+ {
+ CHECK(resource.has_disk());
+
+ if (resource.disk().has_persistence()) {
+ if (resource.role() == "*") {
+ return Error("Persistent disk volume is disallowed for '*' role");
+ }
+ if (!resource.disk().has_volume()) {
+ return Error("Persistent disk should specify a volume");
+ }
+ if (resource.disk().volume().mode() == Volume::RO) {
+ return Error("Read-only volume is not supported for DiskInfo");
+ }
+ if (resource.disk().volume().has_host_path()) {
+ return Error("Volume in DiskInfo should not have 'host_path' set");
+ }
+
+ // Ensure persistence ID does not have invalid characters.
+ string id = resource.disk().persistence().id();
+ if (std::count_if(id.begin(), id.end(), invalid) > 0) {
+ return Error("Persistence ID '" + id + "' contains invalid characters");
+ }
+ } else {
+ if (resource.disk().has_volume()) {
+ return Error("Non-persistent disk volume is not supported");
+ }
+ }
+
+ return None();
+ }
+
+ static bool invalid(char c)
+ {
+ return iscntrl(c) || c == '/' || c == '\\';
+ }
};