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 2017/08/22 20:53:27 UTC

[7/8] mesos git commit: Used common port range interval code in the port_mapping isolator.

Used common port range interval code in the port_mapping isolator.

Switched the port_mapping isolator over to start using the
common values code to parse port ranges into an IntervalSet.

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


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

Branch: refs/heads/master
Commit: f7a38d7b1b1de6d52d5134364f257679de69505b
Parents: daa77c6
Author: James Peach <jp...@apache.org>
Authored: Tue Aug 22 13:37:51 2017 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Tue Aug 22 13:37:51 2017 -0700

----------------------------------------------------------------------
 .../mesos/isolators/network/port_mapping.cpp    | 47 ++++++++++++--------
 1 file changed, 29 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/f7a38d7b/src/slave/containerizer/mesos/isolators/network/port_mapping.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/network/port_mapping.cpp b/src/slave/containerizer/mesos/isolators/network/port_mapping.cpp
index 57d4ccd..60db6f8 100644
--- a/src/slave/containerizer/mesos/isolators/network/port_mapping.cpp
+++ b/src/slave/containerizer/mesos/isolators/network/port_mapping.cpp
@@ -55,6 +55,7 @@
 #include <stout/os/stat.hpp>
 
 #include "common/status_utils.hpp"
+#include "common/values.hpp"
 
 #include "linux/fs.hpp"
 #include "linux/ns.hpp"
@@ -107,6 +108,8 @@ using std::vector;
 
 using filter::ip::PortRange;
 
+using mesos::internal::values::rangesToIntervalSet;
+
 using mesos::slave::ContainerConfig;
 using mesos::slave::ContainerLaunchInfo;
 using mesos::slave::ContainerLimitation;
@@ -372,20 +375,6 @@ static string getNamespaceHandlePath(const string& bindMountRoot, pid_t pid)
   return path::join(bindMountRoot, stringify(pid));
 }
 
-
-// Converts from value ranges to interval set.
-static IntervalSet<uint16_t> getIntervalSet(const Value::Ranges& ranges)
-{
-  IntervalSet<uint16_t> set;
-
-  for (int i = 0; i < ranges.range_size(); i++) {
-    set += (Bound<uint16_t>::closed(ranges.range(i).begin()),
-            Bound<uint16_t>::closed(ranges.range(i).end()));
-  }
-
-  return set;
-}
-
 /////////////////////////////////////////////////
 // Implementation for PortMappingUpdate.
 /////////////////////////////////////////////////
@@ -1423,14 +1412,34 @@ Try<Isolator*> PortMappingIsolatorProcess::create(const Flags& flags)
   // treated as non-ephemeral ports.
   IntervalSet<uint16_t> nonEphemeralPorts;
   if (resources.get().ports().isSome()) {
-    nonEphemeralPorts = getIntervalSet(resources.get().ports().get());
+    Try<IntervalSet<uint16_t>> ports = rangesToIntervalSet<uint16_t>(
+        resources.get().ports().get());
+
+    if (ports.isError()) {
+      return Error(
+          "Invalid ports resource '" +
+          stringify(resources.get().ports().get()) +
+          "': " + ports.error());
+    }
+
+    nonEphemeralPorts = ports.get();
   }
 
   // Get 'ephemeral_ports' resource from 'resources' flag. These ports
   // will be allocated to each container as ephemeral ports.
   IntervalSet<uint16_t> ephemeralPorts;
   if (resources.get().ephemeral_ports().isSome()) {
-    ephemeralPorts = getIntervalSet(resources.get().ephemeral_ports().get());
+    Try<IntervalSet<uint16_t>> ports = rangesToIntervalSet<uint16_t>(
+        resources.get().ephemeral_ports().get());
+
+    if (ports.isError()) {
+      return Error(
+          "Invalid ephemeral ports resource '" +
+          stringify(resources.get().ephemeral_ports().get()) +
+          "': " + ports.error());
+    }
+
+    ephemeralPorts = ports.get();
   }
 
   // Each container requires at least one ephemeral port for slave
@@ -2491,7 +2500,8 @@ Future<Option<ContainerLaunchInfo>> PortMappingIsolatorProcess::prepare(
   IntervalSet<uint16_t> nonEphemeralPorts;
 
   if (resources.ports().isSome()) {
-    nonEphemeralPorts = getIntervalSet(resources.ports().get());
+    nonEphemeralPorts = rangesToIntervalSet<uint16_t>(
+        resources.ports().get()).get();
 
     // Sanity check to make sure that the assigned non-ephemeral ports
     // for the container are part of the non-ephemeral ports specified
@@ -2976,7 +2986,8 @@ Future<Nothing> PortMappingIsolatorProcess::update(
   IntervalSet<uint16_t> nonEphemeralPorts;
 
   if (resources.ports().isSome()) {
-    nonEphemeralPorts = getIntervalSet(resources.ports().get());
+    nonEphemeralPorts = rangesToIntervalSet<uint16_t>(
+        resources.ports().get()).get();
 
     // Sanity check to make sure that the assigned non-ephemeral ports
     // for the container are part of the non-ephemeral ports specified