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 2015/02/20 20:04:23 UTC
mesos git commit: Added utility functions to determine types of
resources.
Repository: mesos
Updated Branches:
refs/heads/master a661b2ede -> 20ddfb183
Added utility functions to determine types of resources.
Review: https://reviews.apache.org/r/29742
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/20ddfb18
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/20ddfb18
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/20ddfb18
Branch: refs/heads/master
Commit: 20ddfb1832e39c76037de136c3ae842c87255237
Parents: a661b2e
Author: Michael Park <mc...@gmail.com>
Authored: Fri Feb 20 11:02:19 2015 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Fri Feb 20 11:04:14 2015 -0800
----------------------------------------------------------------------
include/mesos/resources.hpp | 21 ++++++++++++++++++---
src/common/resources.cpp | 39 +++++++++++++++++++++++++++++++--------
src/master/master.hpp | 2 +-
src/master/validation.cpp | 7 ++++---
src/slave/slave.cpp | 6 +++---
5 files changed, 57 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/20ddfb18/include/mesos/resources.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/resources.hpp b/include/mesos/resources.hpp
index c7cc46e..c242bcc 100644
--- a/include/mesos/resources.hpp
+++ b/include/mesos/resources.hpp
@@ -85,8 +85,23 @@ public:
static Option<Error> validate(
const google::protobuf::RepeatedPtrField<Resource>& resources);
+ // NOTE: The following predicate functions assume that the given
+ // resource is validated.
+
// Tests if the given Resource object is empty.
- static bool empty(const Resource& resource);
+ static bool isEmpty(const Resource& resource);
+
+ // Tests if the given Resource object is a persistent volume.
+ static bool isPersistentVolume(const Resource& resource);
+
+ // Tests if the given Resource object is reserved.
+ static bool isReserved(const Resource& resource);
+
+ // Tests if the given Resource object is reserved for the given role.
+ static bool isReserved(const Resource& resource, const std::string& role);
+
+ // Tests if the given Resource object is unreserved.
+ static bool isUnreserved(const Resource& resource);
Resources() {}
@@ -268,7 +283,7 @@ public:
{
Resources result;
foreach (const Resource& resource, resources) {
- if (resource.has_disk() && resource.disk().has_persistence()) {
+ if (isPersistentVolume(resource)) {
result += resource;
}
}
@@ -289,7 +304,7 @@ public:
Resources result;
foreach (const Resource& resource, resources) {
// TODO(jieyu): Consider dynamic reservation as well.
- if (resource.has_disk() && resource.disk().has_persistence()) {
+ if (isPersistentVolume(resource)) {
result += resource;
}
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/20ddfb18/src/common/resources.cpp
----------------------------------------------------------------------
diff --git a/src/common/resources.cpp b/src/common/resources.cpp
index 98371f6..625922d 100644
--- a/src/common/resources.cpp
+++ b/src/common/resources.cpp
@@ -386,7 +386,7 @@ Option<Error> Resources::validate(
}
-bool Resources::empty(const Resource& resource)
+bool Resources::isEmpty(const Resource& resource)
{
if (resource.type() == Value::SCALAR) {
return resource.scalar().value() == 0;
@@ -400,6 +400,30 @@ bool Resources::empty(const Resource& resource)
}
+bool Resources::isPersistentVolume(const Resource& resource)
+{
+ return resource.has_disk() && resource.disk().has_persistence();
+}
+
+
+bool Resources::isReserved(const Resource& resource)
+{
+ return !isUnreserved(resource);
+}
+
+
+bool Resources::isReserved(const Resource& resource, const std::string& role)
+{
+ return isReserved(resource) && resource.role() == role;
+}
+
+
+bool Resources::isUnreserved(const Resource& resource)
+{
+ return resource.role() == "*";
+}
+
+
/////////////////////////////////////////////////
// Public member functions.
/////////////////////////////////////////////////
@@ -464,7 +488,7 @@ hashmap<string, Resources> Resources::reserved() const
hashmap<string, Resources> result;
foreach (const Resource& resource, resources) {
- if (resource.role() != "*") {
+ if (isReserved(resource)) {
result[resource.role()] += resource;
}
}
@@ -478,8 +502,7 @@ Resources Resources::reserved(const string& role) const
Resources result;
foreach (const Resource& resource, resources) {
- if (resource.role() != "*" &&
- resource.role() == role) {
+ if (isReserved(resource, role)) {
result += resource;
}
}
@@ -493,7 +516,7 @@ Resources Resources::unreserved() const
Resources result;
foreach (const Resource& resource, resources) {
- if (resource.role() == "*") {
+ if (isUnreserved(resource)) {
result += resource;
}
}
@@ -832,7 +855,7 @@ Resources Resources::operator + (const Resources& that) const
Resources& Resources::operator += (const Resource& that)
{
- if (validate(that).isNone() && !empty(that)) {
+ if (validate(that).isNone() && !isEmpty(that)) {
bool found = false;
foreach (Resource& resource, resources) {
if (addable(resource, that)) {
@@ -880,7 +903,7 @@ Resources Resources::operator - (const Resources& that) const
Resources& Resources::operator -= (const Resource& that)
{
- if (validate(that).isNone() && !empty(that)) {
+ if (validate(that).isNone() && !isEmpty(that)) {
for (int i = 0; i < resources.size(); i++) {
Resource* resource = resources.Mutable(i);
@@ -890,7 +913,7 @@ Resources& Resources::operator -= (const Resource& that)
// Remove the resource if it becomes invalid or zero. We need
// to do the validation because we want to strip negative
// scalar Resource object.
- if (validate(*resource).isSome() || empty(*resource)) {
+ if (validate(*resource).isSome() || isEmpty(*resource)) {
resources.DeleteSubrange(i, 1);
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/20ddfb18/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index 6a39df0..a466f92 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -770,7 +770,7 @@ struct Slave
// TODO(jieyu): Apply RESERVE operation if 'resource' is
// dynamically reserved.
- if (resource.has_disk() && resource.disk().has_persistence()) {
+ if (Resources::isPersistentVolume(resource)) {
Offer::Operation create;
create.set_type(Offer::Operation::CREATE);
create.mutable_create()->add_volumes()->CopyFrom(resource);
http://git-wip-us.apache.org/repos/asf/mesos/blob/20ddfb18/src/master/validation.cpp
----------------------------------------------------------------------
diff --git a/src/master/validation.cpp b/src/master/validation.cpp
index acc35b2..cd1052a 100644
--- a/src/master/validation.cpp
+++ b/src/master/validation.cpp
@@ -63,8 +63,9 @@ Option<Error> validateDiskInfo(const RepeatedPtrField<Resource>& resources)
}
if (resource.disk().has_persistence()) {
- if (resource.role() == "*") {
- return Error("'*' role not supported for persistent volume");
+ if (Resources::isUnreserved(resource)) {
+ return Error(
+ "Persistent volumes cannot be created from unreserved resources.");
}
if (!resource.disk().has_volume()) {
return Error("Expecting 'volume' to be set for persistent volume");
@@ -101,7 +102,7 @@ Option<Error> validateUniquePersistenceID(
// Check duplicated persistence ID within the given resources.
foreach (const Resource& resource, resources) {
- if (!resource.has_disk() || !resource.disk().has_persistence()) {
+ if (!Resources::isPersistentVolume(resource)) {
continue;
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/20ddfb18/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index aec9525..0374ca0 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -1299,7 +1299,7 @@ void Slave::_runTask(
// about them (e.g., CheckpointResourcesMessage was dropped or came
// out of order), we simply fail the slave to be safe.
foreach (const Resource& resource, task.resources()) {
- if (resource.has_disk() && resource.disk().has_persistence()) {
+ if (Resources::isPersistentVolume(resource)) {
CHECK(checkpointedResources.contains(resource))
<< "Unknown persistent volume " << resource
<< " for task " << task.task_id()
@@ -1309,7 +1309,7 @@ void Slave::_runTask(
if (task.has_executor()) {
foreach (const Resource& resource, task.executor().resources()) {
- if (resource.has_disk() && resource.disk().has_persistence()) {
+ if (Resources::isPersistentVolume(resource)) {
CHECK(checkpointedResources.contains(resource))
<< "Unknown persistent volume " << resource
<< " for executor " << task.executor().executor_id()
@@ -1983,7 +1983,7 @@ void Slave::checkpointResources(const vector<Resource>& _checkpointedResources)
// DiskInfo, we may want to create either directories under a root
// directory, or LVM volumes from a given device.
foreach (const Resource& volume, newCheckpointedResources) {
- if (!volume.has_disk() || !volume.disk().has_persistence()) {
+ if (!Resources::isPersistentVolume(volume)) {
continue;
}