You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2015/06/02 01:29:48 UTC
mesos git commit: Added printing of extended attributes to Resource
objects.
Repository: mesos
Updated Branches:
refs/heads/master 388e5d5bb -> 31c40e03c
Added printing of extended attributes to Resource objects.
Review: https://reviews.apache.org/r/34676
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/31c40e03
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/31c40e03
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/31c40e03
Branch: refs/heads/master
Commit: 31c40e03cbf299e44febc895db57a8d15707a298
Parents: 388e5d5
Author: Brian Wickman <wi...@apache.org>
Authored: Mon Jun 1 16:29:25 2015 -0700
Committer: Vinod Kone <vi...@gmail.com>
Committed: Mon Jun 1 16:29:26 2015 -0700
----------------------------------------------------------------------
src/common/resources.cpp | 61 +++++++++++++++++++++++++++++++++++++-
src/tests/resources_tests.cpp | 54 +++++++++++++++++++++++++++++++++
2 files changed, 114 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/31c40e03/src/common/resources.cpp
----------------------------------------------------------------------
diff --git a/src/common/resources.cpp b/src/common/resources.cpp
index d93f38e..01c79fb 100644
--- a/src/common/resources.cpp
+++ b/src/common/resources.cpp
@@ -338,6 +338,9 @@ Try<Resource> Resources::parse(
}
+// TODO(wickman) It is possible for Resources::ostream<< to produce
+// unparseable resources, i.e. those with
+// ReservationInfo/DiskInfo/RevocableInfo.
Try<Resources> Resources::parse(
const string& text,
const string& defaultRole)
@@ -1113,9 +1116,65 @@ Resources& Resources::operator -= (const Resources& that)
}
+ostream& operator << (ostream& stream, const Volume& volume) {
+ string volumeConfig = volume.container_path();
+
+ if (volume.has_host_path()) {
+ volumeConfig = volume.host_path() + ":" + volumeConfig;
+
+ if (volume.has_mode()) {
+ switch (volume.mode()) {
+ case Volume::RW: volumeConfig += ":rw"; break;
+ case Volume::RO: volumeConfig += ":ro"; break;
+ default:
+ LOG(FATAL) << "Unknown Volume mode: " << volume.mode();
+ break;
+ }
+ }
+ }
+
+ stream << volumeConfig;
+
+ return stream;
+}
+
+
+ostream& operator << (ostream& stream, const Resource::DiskInfo& disk) {
+ if (disk.has_persistence()) {
+ stream << disk.persistence().id();
+ }
+
+ if (disk.has_volume()) {
+ stream << ":" << disk.volume();
+ }
+
+ return stream;
+}
+
+
ostream& operator << (ostream& stream, const Resource& resource)
{
- stream << resource.name() << "(" << resource.role() << "):";
+ stream << resource.name();
+
+ stream << "(" << resource.role();
+
+ if (resource.has_reservation()) {
+ stream << ", " << resource.reservation().principal();
+ }
+
+ stream << ")";
+
+ if (resource.has_disk()) {
+ stream << "[" << resource.disk() << "]";
+ }
+
+ // Once extended revocable attributes are available, change this to a more
+ // meaningful value.
+ if (resource.has_revocable()) {
+ stream << "{REV}";
+ }
+
+ stream << ":";
switch (resource.type()) {
case Value::SCALAR: stream << resource.scalar(); break;
http://git-wip-us.apache.org/repos/asf/mesos/blob/31c40e03/src/tests/resources_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/resources_tests.cpp b/src/tests/resources_tests.cpp
index 459a68b..b4a9bbf 100644
--- a/src/tests/resources_tests.cpp
+++ b/src/tests/resources_tests.cpp
@@ -180,6 +180,60 @@ TEST(ResourcesTest, Printing)
}
+TEST(ResourcesTest, PrintingExtendedAttributes)
+{
+ Resource disk;
+ disk.set_name("disk");
+ disk.set_type(Value::SCALAR);
+ disk.mutable_scalar()->set_value(1);
+
+ // Standard resource.
+ ostringstream stream;
+ stream << disk;
+ EXPECT_EQ(stream.str(), "disk(*):1");
+
+ // Standard resource with role.
+ stream.str("");
+ disk.set_role("alice");
+ stream << disk;
+ EXPECT_EQ(stream.str(), "disk(alice):1");
+
+ // Standard revocable resource.
+ stream.str("");
+ disk.mutable_revocable();
+ stream << disk;
+ EXPECT_EQ(stream.str(), "disk(alice){REV}:1");
+ disk.clear_revocable();
+
+ // Disk resource with persistent volume.
+ stream.str("");
+ disk.mutable_disk()->mutable_persistence()->set_id("hadoop");
+ disk.mutable_disk()->mutable_volume()->set_container_path("/data");
+ stream << disk;
+ EXPECT_EQ(stream.str(), "disk(alice)[hadoop:/data]:1");
+
+ // Ensure {REV} comes after [disk].
+ stream.str("");
+ disk.mutable_revocable();
+ stream << disk;
+ EXPECT_EQ(stream.str(), "disk(alice)[hadoop:/data]{REV}:1");
+ disk.clear_revocable();
+
+ // Disk resource with host path.
+ stream.str("");
+ disk.mutable_disk()->mutable_volume()->set_host_path("/hdfs");
+ disk.mutable_disk()->mutable_volume()->set_mode(Volume::RW);
+ stream << disk;
+ EXPECT_EQ(stream.str(), "disk(alice)[hadoop:/hdfs:/data:rw]:1");
+
+ // Disk resource with host path and reservation.
+ stream.str("");
+ disk.mutable_reservation()->set_principal("hdfs-1234-4321");
+ stream << disk;
+ EXPECT_EQ(stream.str(), "disk(alice, hdfs-1234-4321)[hadoop:/hdfs:/data:rw]:1");
+}
+
+
TEST(ResourcesTest, InitializedIsEmpty)
{
Resources r;