Repository: mesos
Updated Branches:
  refs/heads/master 02d8426a3 -> 12a01d925


Added TCP checks in Mesos API.

>From now on executors may implement TCP checks for tasks.

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


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

Branch: refs/heads/master
Commit: bbed0e87f6661ada310a6822b5171f32aea1f3d9
Parents: ace9432
Author: Alexander Rukletsov <[email protected]>
Authored: Tue Apr 4 12:29:03 2017 +0200
Committer: Alexander Rukletsov <[email protected]>
Committed: Mon Apr 24 12:04:51 2017 +0200

----------------------------------------------------------------------
 include/mesos/mesos.proto         | 25 ++++++++++++++++++++++---
 include/mesos/v1/mesos.proto      | 25 ++++++++++++++++++++++---
 src/checks/checker.cpp            | 26 +++++++++++++++++++-------
 src/common/type_utils.cpp         |  9 +++++++++
 src/launcher/default_executor.cpp |  6 ++++--
 src/launcher/executor.cpp         |  6 ++++--
 src/tests/check_tests.cpp         | 14 ++++++++++++++
 src/v1/mesos.cpp                  |  9 +++++++++
 8 files changed, 103 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/bbed0e87/include/mesos/mesos.proto
----------------------------------------------------------------------
diff --git a/include/mesos/mesos.proto b/include/mesos/mesos.proto
index eaa2d2a..fbb491c 100644
--- a/include/mesos/mesos.proto
+++ b/include/mesos/mesos.proto
@@ -381,10 +381,11 @@ message CheckInfo {
     UNKNOWN = 0;
     COMMAND = 1;
     HTTP = 2;
+    TCP = 3;
 
-    // TODO(alexr): Consider supporting TCP checks and custom user checks.
-    // The latter should probably be paired with a `data` field and
-    // complemented by a `data` response in `CheckStatusInfo`.
+    // TODO(alexr): Consider supporting custom user checks. They should
+    // probably be paired with a `data` field and complemented by a
+    // `data` response in `CheckStatusInfo`.
   }
 
   // Describes a command check. If applicable, enters mount and/or network
@@ -413,6 +414,13 @@ message CheckInfo {
     // validation, TLS version.
   }
 
+  // Describes a TCP check, i.e. based on establishing a TCP connection to
+  // the specified port. Note that <host> is not configurable and is resolved
+  // automatically to 127.0.0.1.
+  message Tcp {
+    required uint32 port = 1;
+  }
+
   // The type of the check.
   optional Type type = 1;
 
@@ -422,6 +430,9 @@ message CheckInfo {
   // HTTP check.
   optional Http http = 3;
 
+  // TCP check.
+  optional Tcp tcp = 7;
+
   // Amount of time to wait to start checking the task after it
   // transitions to `TASK_RUNNING` or `TASK_STARTING` if the latter
   // is used by the executor.
@@ -1759,6 +1770,11 @@ message CheckStatusInfo {
     optional uint32 status_code = 1;
   }
 
+  message Tcp {
+    // Whether a TCP connection succeeded.
+    optional bool succeeded = 1;
+  }
+
   // TODO(alexr): Consider adding a `data` field, which can contain, e.g.,
   // truncated stdout/stderr output for command checks or HTTP response body
   // for HTTP checks. Alternatively, it can be an even shorter `message` field
@@ -1774,6 +1790,9 @@ message CheckStatusInfo {
   // Status of an HTTP check.
   optional Http http = 3;
 
+  // Status of a TCP check.
+  optional Tcp tcp = 4;
+
   // TODO(alexr): Consider introducing a "last changed at" timestamp, since
   // task status update's timestamp may not correspond to the last check's
   // state, e.g., for reconciliation.

http://git-wip-us.apache.org/repos/asf/mesos/blob/bbed0e87/include/mesos/v1/mesos.proto
----------------------------------------------------------------------
diff --git a/include/mesos/v1/mesos.proto b/include/mesos/v1/mesos.proto
index 1a32a7b..54a9efc 100644
--- a/include/mesos/v1/mesos.proto
+++ b/include/mesos/v1/mesos.proto
@@ -381,10 +381,11 @@ message CheckInfo {
     UNKNOWN = 0;
     COMMAND = 1;
     HTTP = 2;
+    TCP = 3;
 
-    // TODO(alexr): Consider supporting TCP checks and custom user checks.
-    // The latter should probably be paired with a `data` field and
-    // complemented by a `data` response in `CheckStatusInfo`.
+    // TODO(alexr): Consider supporting custom user checks. They should
+    // probably be paired with a `data` field and complemented by a
+    // `data` response in `CheckStatusInfo`.
   }
 
   // Describes a command check. If applicable, enters mount and/or network
@@ -413,6 +414,13 @@ message CheckInfo {
     // validation, TLS version.
   }
 
+  // Describes a TCP check, i.e. based on establishing a TCP connection to
+  // the specified port. Note that <host> is not configurable and is resolved
+  // automatically to 127.0.0.1.
+  message Tcp {
+    required uint32 port = 1;
+  }
+
   // The type of the check.
   optional Type type = 1;
 
@@ -422,6 +430,9 @@ message CheckInfo {
   // HTTP check.
   optional Http http = 3;
 
+  // TCP check.
+  optional Tcp tcp = 7;
+
   // Amount of time to wait to start checking the task after it
   // transitions to `TASK_RUNNING` or `TASK_STARTING` if the latter
   // is used by the executor.
@@ -1753,6 +1764,11 @@ message CheckStatusInfo {
     optional uint32 status_code = 1;
   }
 
+  message Tcp {
+    // Whether a TCP connection succeeded.
+    optional bool succeeded = 1;
+  }
+
   // TODO(alexr): Consider adding a `data` field, which can contain, e.g.,
   // truncated stdout/stderr output for command checks or HTTP response body
   // for HTTP checks. Alternatively, it can be an even shorter `message` field
@@ -1768,6 +1784,9 @@ message CheckStatusInfo {
   // Status of an HTTP check.
   optional Http http = 3;
 
+  // Status of a TCP check.
+  optional Tcp tcp = 4;
+
   // TODO(alexr): Consider introducing a "last changed at" timestamp, since
   // task status update's timestamp may not correspond to the last check's
   // state, e.g., for reconciliation.

http://git-wip-us.apache.org/repos/asf/mesos/blob/bbed0e87/src/checks/checker.cpp
----------------------------------------------------------------------
diff --git a/src/checks/checker.cpp b/src/checks/checker.cpp
index a883656..2fcf527 100644
--- a/src/checks/checker.cpp
+++ b/src/checks/checker.cpp
@@ -345,12 +345,14 @@ CheckerProcess::CheckerProcess(
       previousCheckStatus.mutable_command();
       break;
     }
-
     case CheckInfo::HTTP: {
       previousCheckStatus.mutable_http();
       break;
     }
-
+    case CheckInfo::TCP: {
+      previousCheckStatus.mutable_tcp();
+      break;
+    }
     case CheckInfo::UNKNOWN: {
       LOG(FATAL) << "Received UNKNOWN check type";
       break;
@@ -398,14 +400,15 @@ void CheckerProcess::performCheck()
           &Self::processCommandCheckResult, stopwatch, lambda::_1));
       break;
     }
-
     case CheckInfo::HTTP: {
       httpCheck().onAny(defer(
           self(),
           &Self::processHttpCheckResult, stopwatch, lambda::_1));
       break;
     }
-
+    case CheckInfo::TCP: {
+      break;
+    }
     case CheckInfo::UNKNOWN: {
       LOG(FATAL) << "Received UNKNOWN check type";
       break;
@@ -1099,7 +1102,6 @@ Option<Error> checkInfo(const CheckInfo& checkInfo)
 
       break;
     }
-
     case CheckInfo::HTTP: {
       if (!checkInfo.has_http()) {
         return Error("Expecting 'http' to be set for HTTP check");
@@ -1114,7 +1116,13 @@ Option<Error> checkInfo(const CheckInfo& checkInfo)
 
       break;
     }
+    case CheckInfo::TCP: {
+      if (!checkInfo.has_tcp()) {
+        return Error("Expecting 'tcp' to be set for TCP check");
+      }
 
+      break;
+    }
     case CheckInfo::UNKNOWN: {
       return Error(
           "'" + CheckInfo::Type_Name(checkInfo.type()) + "'"
@@ -1152,14 +1160,18 @@ Option<Error> checkStatusInfo(const CheckStatusInfo& 
checkStatusInfo)
       }
       break;
     }
-
     case CheckInfo::HTTP: {
       if (!checkStatusInfo.has_http()) {
         return Error("Expecting 'http' to be set for HTTP check's status");
       }
       break;
     }
-
+    case CheckInfo::TCP: {
+      if (!checkStatusInfo.has_tcp()) {
+        return Error("Expecting 'tcp' to be set for TCP check's status");
+      }
+      break;
+    }
     case CheckInfo::UNKNOWN: {
       return Error(
           "'" + CheckInfo::Type_Name(checkStatusInfo.type()) + "'"

http://git-wip-us.apache.org/repos/asf/mesos/blob/bbed0e87/src/common/type_utils.cpp
----------------------------------------------------------------------
diff --git a/src/common/type_utils.cpp b/src/common/type_utils.cpp
index dc0dd71..9bc32af 100644
--- a/src/common/type_utils.cpp
+++ b/src/common/type_utils.cpp
@@ -487,6 +487,15 @@ ostream& operator<<(ostream& stream, const 
CheckStatusInfo& checkStatusInfo)
         }
       }
       break;
+    case CheckInfo::TCP:
+      if (checkStatusInfo.has_tcp()) {
+        stream << "TCP";
+        if (checkStatusInfo.tcp().has_succeeded()) {
+          stream << (checkStatusInfo.tcp().succeeded() ? " connection success"
+                                                       : " connection 
failure");
+        }
+      }
+      break;
     case CheckInfo::UNKNOWN:
       stream << "UNKNOWN";
       break;

http://git-wip-us.apache.org/repos/asf/mesos/blob/bbed0e87/src/launcher/default_executor.cpp
----------------------------------------------------------------------
diff --git a/src/launcher/default_executor.cpp 
b/src/launcher/default_executor.cpp
index ef60f5b..95505fc 100644
--- a/src/launcher/default_executor.cpp
+++ b/src/launcher/default_executor.cpp
@@ -1147,12 +1147,14 @@ private:
           checkStatusInfo.mutable_command();
           break;
         }
-
         case CheckInfo::HTTP: {
           checkStatusInfo.mutable_http();
           break;
         }
-
+        case CheckInfo::TCP: {
+          checkStatusInfo.mutable_tcp();
+          break;
+        }
         case CheckInfo::UNKNOWN: {
           LOG(FATAL) << "UNKNOWN check type is invalid";
           break;

http://git-wip-us.apache.org/repos/asf/mesos/blob/bbed0e87/src/launcher/executor.cpp
----------------------------------------------------------------------
diff --git a/src/launcher/executor.cpp b/src/launcher/executor.cpp
index d14fbfb..c9cecb5 100644
--- a/src/launcher/executor.cpp
+++ b/src/launcher/executor.cpp
@@ -1004,12 +1004,14 @@ private:
           checkStatusInfo.mutable_command();
           break;
         }
-
         case CheckInfo::HTTP: {
           checkStatusInfo.mutable_http();
           break;
         }
-
+        case CheckInfo::TCP: {
+          checkStatusInfo.mutable_tcp();
+          break;
+        }
         case CheckInfo::UNKNOWN: {
           LOG(FATAL) << "UNKNOWN check type is invalid";
           break;

http://git-wip-us.apache.org/repos/asf/mesos/blob/bbed0e87/src/tests/check_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/check_tests.cpp b/src/tests/check_tests.cpp
index 2d1a122..67124c9 100644
--- a/src/tests/check_tests.cpp
+++ b/src/tests/check_tests.cpp
@@ -1761,6 +1761,13 @@ TEST_F(CheckTest, CheckInfoValidation)
     EXPECT_EQ(
         "Expecting 'http' to be set for HTTP check",
         validate->message);
+
+    checkInfo.set_type(CheckInfo::TCP);
+    validate = validation::checkInfo(checkInfo);
+    EXPECT_SOME(validate);
+    EXPECT_EQ(
+        "Expecting 'tcp' to be set for TCP check",
+        validate->message);
   }
 
   // Command check must specify an actual command in `command.command.value`.
@@ -1893,6 +1900,13 @@ TEST_F(CheckTest, CheckStatusInfoValidation)
     EXPECT_EQ(
         "Expecting 'http' to be set for HTTP check's status",
         validate->message);
+
+    checkStatusInfo.set_type(CheckInfo::TCP);
+    validate = validation::checkStatusInfo(checkStatusInfo);
+    EXPECT_SOME(validate);
+    EXPECT_EQ(
+        "Expecting 'tcp' to be set for TCP check's status",
+        validate->message);
   }
 }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/bbed0e87/src/v1/mesos.cpp
----------------------------------------------------------------------
diff --git a/src/v1/mesos.cpp b/src/v1/mesos.cpp
index 9c7d641..babe39e 100644
--- a/src/v1/mesos.cpp
+++ b/src/v1/mesos.cpp
@@ -409,6 +409,15 @@ ostream& operator<<(ostream& stream, const 
CheckStatusInfo& checkStatusInfo)
         }
       }
       break;
+    case CheckInfo::TCP:
+      if (checkStatusInfo.has_tcp()) {
+        stream << "TCP";
+        if (checkStatusInfo.tcp().has_succeeded()) {
+          stream << (checkStatusInfo.tcp().succeeded() ? " connection success"
+                                                       : " connection 
failure");
+        }
+      }
+      break;
     case CheckInfo::UNKNOWN:
       stream << "UNKNOWN";
       break;

Reply via email to