You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by me...@apache.org on 2015/12/18 07:04:59 UTC
[1/2] mesos git commit: Added labels field to Ports in DiscoveryInfo.
Repository: mesos
Updated Branches:
refs/heads/master 42f746937 -> f9f379ddc
Added labels field to Ports in DiscoveryInfo.
Added labels field to Port information, for service discovery to
associate arbitrary tags by applications to ports for a given task.
Review: https://reviews.apache.org/r/41187/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/343b4a2a
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/343b4a2a
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/343b4a2a
Branch: refs/heads/master
Commit: 343b4a2a11bf15ecf031320564503a641f3c6b71
Parents: 42f7469
Author: Avinash sridharan <av...@mesosphere.io>
Authored: Thu Dec 17 19:47:41 2015 -0800
Committer: Adam B <ad...@mesosphere.io>
Committed: Thu Dec 17 19:47:41 2015 -0800
----------------------------------------------------------------------
include/mesos/mesos.proto | 10 ++++++++++
include/mesos/v1/mesos.proto | 10 ++++++++++
2 files changed, 20 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/343b4a2a/include/mesos/mesos.proto
----------------------------------------------------------------------
diff --git a/include/mesos/mesos.proto b/include/mesos/mesos.proto
index 28a6985..2431fdd 100644
--- a/include/mesos/mesos.proto
+++ b/include/mesos/mesos.proto
@@ -1540,10 +1540,20 @@ message Label {
* Named port used for service discovery.
*/
message Port {
+ // Port number on which the framework exposes a service.
required uint32 number = 1;
+ // Name of the service hosted on this port.
optional string name = 2;
+ // Layer 4-7 protocol on which the framework exposes its services.
optional string protocol = 3;
+ // This field restricts discovery within a framework (FRAMEWORK),
+ // within a Mesos cluster (CLUSTER), or places no restrictions (EXTERNAL).
+ // The visibility setting for a Port overrides the general visibility setting
+ // in the DiscoveryInfo.
optional DiscoveryInfo.Visibility visibility = 4;
+ // This can be used to decorate the message with metadata to be
+ // interpreted by external applications such as firewalls.
+ optional Labels labels = 5;
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/343b4a2a/include/mesos/v1/mesos.proto
----------------------------------------------------------------------
diff --git a/include/mesos/v1/mesos.proto b/include/mesos/v1/mesos.proto
index dfb2487..4aed098 100644
--- a/include/mesos/v1/mesos.proto
+++ b/include/mesos/v1/mesos.proto
@@ -1539,10 +1539,20 @@ message Label {
* Named port used for service discovery.
*/
message Port {
+ // Port number on which the framework exposes a service.
required uint32 number = 1;
+ // Name of the service hosted on this port.
optional string name = 2;
+ // Layer 4-7 protocol on which the framework exposes its services.
optional string protocol = 3;
+ // This field restricts discovery within a framework (FRAMEWORK),
+ // within a Mesos cluster (CLUSTER), or places no restrictions (EXTERNAL).
+ // The visibility setting for a Port overrides the general visibility setting
+ // in the DiscoveryInfo.
optional DiscoveryInfo.Visibility visibility = 4;
+ // This can be used to decorate the message with metadata to be
+ // interpreted by external applications such as firewalls.
+ optional Labels labels = 5;
}
[2/2] mesos git commit: Provided JSON bindings to expose
DiscoveryInfo to HTTP endpoints.
Posted by me...@apache.org.
Provided JSON bindings to expose DiscoveryInfo to HTTP endpoints.
Provided JSON bindings so that mesos can expose DiscoveryInfo protobuf
messages to HTTP endpoints.
Review: https://reviews.apache.org/r/41188/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/f9f379dd
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/f9f379dd
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/f9f379dd
Branch: refs/heads/master
Commit: f9f379ddc315fb07e9862238dbe6e83988ac66c6
Parents: 343b4a2
Author: Avinash sridharan <av...@mesosphere.io>
Authored: Thu Dec 17 19:48:47 2015 -0800
Committer: Adam B <ad...@mesosphere.io>
Committed: Thu Dec 17 19:48:47 2015 -0800
----------------------------------------------------------------------
src/slave/http.cpp | 3 +
src/tests/common/http_tests.cpp | 41 +++++++++++++-
src/tests/slave_tests.cpp | 107 +++++++++++++++++++++++++++++++++++
3 files changed, 150 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/f9f379dd/src/slave/http.cpp
----------------------------------------------------------------------
diff --git a/src/slave/http.cpp b/src/slave/http.cpp
index d1b1158..66abdcb 100644
--- a/src/slave/http.cpp
+++ b/src/slave/http.cpp
@@ -106,6 +106,9 @@ JSON::Object model(const TaskInfo& task)
if (task.has_executor()) {
object.values["executor_id"] = task.executor().executor_id().value();
}
+ if (task.has_discovery()) {
+ object.values["discovery"] = JSON::protobuf(task.discovery());
+ }
return object;
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/f9f379dd/src/tests/common/http_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/common/http_tests.cpp b/src/tests/common/http_tests.cpp
index 3aca5b0..0ea0634 100644
--- a/src/tests/common/http_tests.cpp
+++ b/src/tests/common/http_tests.cpp
@@ -35,6 +35,7 @@ using namespace mesos::internal;
using std::vector;
+using mesos::internal::protobuf::createLabel;
using mesos::internal::protobuf::createTask;
// TODO(bmahler): Add tests for other JSON models.
@@ -69,11 +70,25 @@ TEST(HTTPTest, ModelTask)
statuses.push_back(status);
+ Labels labels;
+ labels.add_labels()->CopyFrom(createLabel("ACTION", "port:7987 DENY"));
+
+ Ports ports;
+ Port* port = ports.add_ports();
+ port->set_number(80);
+ port->mutable_labels()->CopyFrom(labels);
+
+ DiscoveryInfo discovery;
+ discovery.set_visibility(DiscoveryInfo::CLUSTER);
+ discovery.set_name("discover");
+ discovery.mutable_ports()->CopyFrom(ports);
+
TaskInfo task;
task.set_name("task");
task.mutable_task_id()->CopyFrom(taskId);
task.mutable_slave_id()->CopyFrom(slaveId);
task.mutable_command()->set_value("echo hello");
+ task.mutable_discovery()->CopyFrom(discovery);
Task task_ = createTask(task, state, frameworkId);
task_.add_statuses()->CopyFrom(statuses[0]);
@@ -101,7 +116,31 @@ TEST(HTTPTest, ModelTask)
" \"state\":\"TASK_RUNNING\","
" \"timestamp\":0"
" }"
- " ]"
+ " ],"
+ " \"discovery\":"
+ " {"
+ " \"name\":\"discover\","
+ " \"ports\":"
+ " {"
+ " \"ports\":"
+ " ["
+ " {"
+ " \"number\":80,"
+ " \"labels\":"
+ " {"
+ " \"labels\":"
+ " ["
+ " {"
+ " \"key\":\"ACTION\","
+ " \"value\":\"port:7987 DENY\""
+ " }"
+ " ]"
+ " }"
+ " }"
+ " ]"
+ " },"
+ " \"visibility\":\"CLUSTER\""
+ " }"
"}");
ASSERT_SOME(expected);
http://git-wip-us.apache.org/repos/asf/mesos/blob/f9f379dd/src/tests/slave_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/slave_tests.cpp b/src/tests/slave_tests.cpp
index f191993..109d31c 100644
--- a/src/tests/slave_tests.cpp
+++ b/src/tests/slave_tests.cpp
@@ -2142,6 +2142,113 @@ TEST_F(SlaveTest, ContainerizerUsageFailure)
}
+// This test verifies that DiscoveryInfo and Port messages, set in TaskInfo,
+// are exposed over the slave state endpoint. The test launches a task with
+// the DiscoveryInfo and Port message fields populated. It then makes an HTTP
+// request to the state endpoint of the slave and retrieves the JSON data from
+// the endpoint. The test passes if the DiscoveryInfo and Port message data in
+// JSON matches the corresponding data set in the TaskInfo used to launch the
+// task.
+TEST_F(SlaveTest, DiscoveryInfoAndPorts)
+{
+ Try<PID<Master>> master = StartMaster();
+ ASSERT_SOME(master);
+
+ MockExecutor exec(DEFAULT_EXECUTOR_ID);
+
+ Try<PID<Slave>> slave = StartSlave(&exec);
+ ASSERT_SOME(slave);
+
+ MockScheduler sched;
+ MesosSchedulerDriver driver(
+ &sched, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL);
+
+ EXPECT_CALL(sched, registered(&driver, _, _));
+
+ Future<vector<Offer>> offers;
+ EXPECT_CALL(sched, resourceOffers(&driver, _))
+ .WillOnce(FutureArg<1>(&offers))
+ .WillRepeatedly(Return()); // Ignore subsequent offers.
+
+ driver.start();
+
+ AWAIT_READY(offers);
+ EXPECT_NE(0u, offers.get().size());
+
+ TaskInfo task = createTask(offers.get()[0], "sleep 100", DEFAULT_EXECUTOR_ID);
+
+ Labels labels1;
+ labels1.add_labels()->CopyFrom(createLabel("ACTION", "port:7987 DENY"));
+
+ Labels labels2;
+ labels2.add_labels()->CopyFrom(createLabel("ACTION", "port:7789 PERMIT"));
+
+ Ports ports;
+ Port* port1 = ports.add_ports();
+ port1->set_number(80);
+ port1->mutable_labels()->CopyFrom(labels1);
+
+ Port* port2 = ports.add_ports();
+ port2->set_number(8081);
+ port2->mutable_labels()->CopyFrom(labels2);
+
+ DiscoveryInfo discovery;
+ discovery.set_name("test_discovery");
+ discovery.set_visibility(DiscoveryInfo::CLUSTER);
+ discovery.mutable_ports()->CopyFrom(ports);
+
+ task.mutable_discovery()->CopyFrom(discovery);
+
+ EXPECT_CALL(exec, registered(_, _, _, _));
+
+ Future<Nothing> launchTask;
+ EXPECT_CALL(exec, launchTask(_, _))
+ .WillOnce(FutureSatisfy(&launchTask));
+
+ driver.launchTasks(offers.get()[0].id(), {task});
+
+ AWAIT_READY(launchTask);
+
+ // Verify label key and value in slave state.json.
+ Future<process::http::Response> response =
+ process::http::get(slave.get(), "state.json");
+
+ AWAIT_EXPECT_RESPONSE_STATUS_EQ(process::http::OK().status, response);
+ EXPECT_SOME_EQ(APPLICATION_JSON, response.get().headers.get("Content-Type"));
+
+ Try<JSON::Object> parse = JSON::parse<JSON::Object>(response.get().body);
+ ASSERT_SOME(parse);
+
+ Result<JSON::Object> discoveryResult = parse.get().find<JSON::Object>(
+ "frameworks[0].executors[0].tasks[0].discovery");
+ EXPECT_SOME(discoveryResult);
+
+ JSON::Object discoveryObject = discoveryResult.get();
+ EXPECT_EQ(JSON::Object(JSON::protobuf(discovery)), discoveryObject);
+
+ // Check the ports are set in the `DiscoveryInfo` object.
+ Result<JSON::Object> portResult1 = parse.get().find<JSON::Object>(
+ "frameworks[0].executors[0].tasks[0].discovery.ports.ports[0]");
+ Result<JSON::Object> portResult2 = parse.get().find<JSON::Object>(
+ "frameworks[0].executors[0].tasks[0].discovery.ports.ports[1]");
+
+ EXPECT_SOME(portResult1);
+ EXPECT_SOME(portResult2);
+
+ // Verify that the ports retrieved from state.json are the ones that were set.
+ EXPECT_EQ(JSON::Object(JSON::protobuf(*port1)), portResult1.get());
+ EXPECT_EQ(JSON::Object(JSON::protobuf(*port2)), portResult2.get());
+
+ EXPECT_CALL(exec, shutdown(_))
+ .Times(AtMost(1));
+
+ driver.stop();
+ driver.join();
+
+ Shutdown(); // Must shutdown before 'containerizer' gets deallocated.
+}
+
+
// This test verifies that label values can be set for tasks and that
// they are exposed over the slave state endpoint.
TEST_F(SlaveTest, TaskLabels)