You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bb...@apache.org on 2019/09/23 13:51:21 UTC

[mesos] branch master updated: Adjusted CSI example framework for recent changes.

This is an automated email from the ASF dual-hosted git repository.

bbannier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git


The following commit(s) were added to refs/heads/master by this push:
     new 6ded10f  Adjusted CSI example framework for recent changes.
6ded10f is described below

commit 6ded10fe66a19c61497bf8b1b42793a0abf931fd
Author: Benjamin Bannier <bb...@apache.org>
AuthorDate: Mon Sep 23 15:41:53 2019 +0200

    Adjusted CSI example framework for recent changes.
    
    This patch adjusts the CSI example framework for recent cleanups to
    example frameworks. It now uses generic flag classes which can e.g.,
    parse from both the environment and the command line.
    
    Review: https://reviews.apache.org/r/65042/
---
 src/examples/test_csi_user_framework.cpp | 80 +++++++++++++++++---------------
 1 file changed, 43 insertions(+), 37 deletions(-)

diff --git a/src/examples/test_csi_user_framework.cpp b/src/examples/test_csi_user_framework.cpp
index 1bf5d14..5e87583 100644
--- a/src/examples/test_csi_user_framework.cpp
+++ b/src/examples/test_csi_user_framework.cpp
@@ -18,6 +18,8 @@
 #include <queue>
 #include <string>
 
+#include <mesos/authorizer/acls.hpp>
+
 #include <mesos/v1/mesos.hpp>
 #include <mesos/v1/resources.hpp>
 #include <mesos/v1/scheduler.hpp>
@@ -38,10 +40,13 @@
 #include <stout/option.hpp>
 #include <stout/os.hpp>
 #include <stout/path.hpp>
+#include <stout/protobuf.hpp>
 #include <stout/uuid.hpp>
 
 #include "common/status_utils.hpp"
 
+#include "examples/flags.hpp"
+
 #include "logging/flags.hpp"
 #include "logging/logging.hpp"
 
@@ -82,17 +87,11 @@ class HTTPScheduler : public process::Process<HTTPScheduler>
 public:
   HTTPScheduler(
       const FrameworkInfo& _framework,
-      const string& _master)
-    : framework(_framework),
-      master(_master),
-      state(INITIALIZING) {}
-
-  HTTPScheduler(
-      const FrameworkInfo& _framework,
       const string& _master,
-      const Credential& credential)
+      const Option<Credential>& _credential)
     : framework(_framework),
       master(_master),
+      credential(_credential),
       state(INITIALIZING) {}
 
   ~HTTPScheduler() override {}
@@ -209,7 +208,7 @@ protected:
             process::defer(self(), &Self::connected),
             process::defer(self(), &Self::disconnected),
             process::defer(self(), &Self::received, lambda::_1),
-            None()));
+            credential));
   }
 
 private:
@@ -350,6 +349,7 @@ private:
 
   FrameworkInfo framework;
   string master;
+  Option<Credential> credential;
   process::Owned<scheduler::Mesos> mesos;
 
   enum State
@@ -361,37 +361,16 @@ private:
 };
 
 
-class Flags : public virtual mesos::internal::logging::Flags
-{
-public:
-  Flags()
-  {
-    add(&Flags::role, "role", "Role to use when registering", "*");
-
-    add(&Flags::master, "master", "ip:port of master to connect");
-
-    add(&Flags::checkpoint,
-        "checkpoint",
-        "Whether this framework should be checkpointed.",
-        false);
-
-    add(&Flags::principal,
-        "principal",
-        "Authentication principal of the framework");
-  }
-
-  string role;
-  string master;
-  string principal;
-  bool checkpoint;
-};
+class Flags : public virtual mesos::internal::examples::Flags,
+              public virtual mesos::internal::logging::Flags
+{};
 
 
 int main(int argc, char** argv)
 {
   Flags flags;
 
-  Try<flags::Warnings> load = flags.load(None(), argc, argv);
+  Try<flags::Warnings> load = flags.load("MESOS_EXAMPLE_", argc, argv);
 
   if (flags.help) {
     cout << flags.usage() << endl;
@@ -411,7 +390,9 @@ int main(int argc, char** argv)
   }
 
   FrameworkInfo framework;
+  framework.set_principal(flags.principal);
   framework.set_name(FRAMEWORK_NAME);
+  framework.set_checkpoint(flags.checkpoint);
   framework.add_roles(flags.role);
   framework.add_capabilities()->set_type(
       FrameworkInfo::Capability::MULTI_ROLE);
@@ -422,11 +403,36 @@ int main(int argc, char** argv)
 
   CHECK_SOME(user);
   framework.set_user(user.get());
-  framework.set_checkpoint(flags.checkpoint);
-  framework.set_principal(flags.principal);
+
+  Option<Credential> credential = None();
+
+  if (flags.authenticate) {
+    LOG(INFO) << "Enabling authentication for the framework";
+
+    Credential credential_;
+    credential_.set_principal(flags.principal);
+    if (flags.secret.isSome()) {
+      credential_.set_secret(flags.secret.get());
+    }
+    credential = credential_;
+  }
+
+  if (flags.master == "local") {
+    // Configure master.
+    os::setenv(
+        "MESOS_AUTHENTICATE_HTTP_FRAMEWORKS", stringify(flags.authenticate));
+
+    os::setenv("MESOS_HTTP_FRAMEWORK_AUTHENTICATORS", "basic");
+
+    mesos::ACLs acls;
+    mesos::ACL::RegisterFramework* acl = acls.add_register_frameworks();
+    acl->mutable_principals()->set_type(mesos::ACL::Entity::ANY);
+    acl->mutable_roles()->add_values("*");
+    os::setenv("MESOS_ACLS", stringify(JSON::protobuf(acls)));
+  }
 
   process::Owned<HTTPScheduler> scheduler(
-      new HTTPScheduler(framework, flags.master));
+      new HTTPScheduler(framework, flags.master, credential));
 
   process::spawn(scheduler.get());
   process::wait(scheduler.get());