Repository: mesos
Updated Branches:
  refs/heads/master 06d2e23dc -> 6a4296de3


Updated signature of `delegate` and `execute` method.

In case of `spec::CNI_CMD_DEL` the CNI plugin is not supposed to
return any output. Hence, changing the signatures to return an
`Result` and an `Option` respectively.

Review: https://reviews.apache.org/r/51768/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/6a4296de
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/6a4296de
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/6a4296de

Branch: refs/heads/master
Commit: 6a4296de3fe781a340b3554cabde7faab0480668
Parents: 89d8d51
Author: Avinash sridharan <avin...@mesosphere.io>
Authored: Wed Oct 12 10:06:59 2016 -0700
Committer: Jie Yu <yujie....@gmail.com>
Committed: Wed Oct 12 10:59:45 2016 -0700

----------------------------------------------------------------------
 .../network/cni/plugins/port_mapper/main.cpp    |  5 ++--
 .../cni/plugins/port_mapper/port_mapper.cpp     |  8 +++---
 .../cni/plugins/port_mapper/port_mapper.hpp     | 26 ++++++++++++--------
 3 files changed, 23 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/6a4296de/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/main.cpp
----------------------------------------------------------------------
diff --git 
a/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/main.cpp
 
b/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/main.cpp
index 0bb58c4..f8d38c6 100644
--- 
a/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/main.cpp
+++ 
b/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/main.cpp
@@ -67,12 +67,13 @@ int main(int argc, char** argv)
     return EXIT_FAILURE;
   }
 
-  Try<string, PluginError> result = portMapper.get()->execute();
+  Try<Option<string>, PluginError> result = portMapper.get()->execute();
   if (result.isError()) {
     cout << result.error() << endl;
     return EXIT_FAILURE;
+  } else if (result->isSome()) {
+    cout << result->get() << endl;
   }
 
-  cout << result.get() << endl;
   return EXIT_SUCCESS;
 }

http://git-wip-us.apache.org/repos/asf/mesos/blob/6a4296de/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.cpp
----------------------------------------------------------------------
diff --git 
a/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.cpp
 
b/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.cpp
index 5de777c..0473645 100644
--- 
a/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.cpp
+++ 
b/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.cpp
@@ -218,15 +218,15 @@ Try<Owned<PortMapper>, PluginError> 
PortMapper::create(const string& _cniConfig)
 }
 
 
-Try<string, PluginError> PortMapper::execute()
+Try<Option<string>, PluginError> PortMapper::execute()
 {
-  return "OK";
+  return None();
 }
 
 
-Try<spec::NetworkInfo> PortMapper::delegate(const string& command)
+Result<spec::NetworkInfo> PortMapper::delegate(const string& command)
 {
-  return spec::NetworkInfo();
+  return None();
 }
 
 } // namespace cni {

http://git-wip-us.apache.org/repos/asf/mesos/blob/6a4296de/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.hpp
----------------------------------------------------------------------
diff --git 
a/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.hpp
 
b/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.hpp
index c0bbef6..7fad707 100644
--- 
a/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.hpp
+++ 
b/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.hpp
@@ -68,25 +68,31 @@ public:
   static Try<process::Owned<PortMapper>, spec::PluginError> create(
       const std::string& cniConfig);
 
-  // Executes the CNI plugin specified in 'delegate'. On successful
-  // execution of the 'delegate' plugin will install port-forwarding
-  // rules, if any, that are specified in `NetworkInfo`. On success
-  // will return a JSON string seen in the successful execution of the
-  // 'delegate' plugin. In case of an error will return a JSON string
-  // representation of `spec::Error` as the error message for the
-  // `Try`.
-  Try<std::string, spec::PluginError> execute();
+  // Executes the CNI plugin specified in 'delegate'. When
+  // `cniCommand` is set to `spec::CNI_CMD_ADD` successful execution
+  // of the 'delegate' plugin will install port-forwarding rules, if
+  // any, that are specified in `NetworkInfo`. On success will return
+  // a JSON string seen in the successful execution of the 'delegate'
+  // plugin. When `cniCommand` is set to `spec::CNI_CMD_DEL`
+  // successful execution of the delegate plugin will return `None`.
+  Try<Option<std::string>, spec::PluginError> execute();
 
   virtual ~PortMapper() {};
 
 protected:
   // Used to invoke the plugin specified in 'delegate'. The possible
-  // values for `command` are ADD or DEL. The `command` is used in
+  // values for `command` are `spec::CNI_CMD_ADD` or
+  // `spec::CNI_CMD_DEL`. The `command` is used in
   // setting the CNI_COMMAND environment variable before invoking the
   // 'delegate' plugin.
   //
+  // When `command` is set to `spec::CNI_CMD_ADD` returns a
+  // `spec::NetworkInfo` on successful execution of the 'delegate'
+  // plugin. When command is set to `spec::CNI_CMD_DEL` returns `None`
+  // on successful execution of the plugin.
+  //
   // NOTE: Defining `delegate` as a virtual method so that we can mock it.
-  virtual Try<spec::NetworkInfo> delegate(const std::string& command);
+  virtual Result<spec::NetworkInfo> delegate(const std::string& command);
 
 private:
   PortMapper(

Reply via email to