mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From al...@apache.org
Subject [6/7] mesos git commit: Added validation for a general check.
Date Sun, 22 Jan 2017 15:07:43 GMT
Added validation for a general check.

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


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

Branch: refs/heads/master
Commit: 784afbd6f6d543f56c57254b148bccee34cf30d3
Parents: 426a82b
Author: Alexander Rukletsov <rukletsov@gmail.com>
Authored: Sun Jan 22 15:19:37 2017 +0100
Committer: Alexander Rukletsov <alexr@apache.org>
Committed: Sun Jan 22 16:06:17 2017 +0100

----------------------------------------------------------------------
 src/CMakeLists.txt            |   1 +
 src/Makefile.am               |   2 +
 src/checks/checker.cpp        | 134 +++++++++++++++++++++++++++++++++++++
 src/checks/checker.hpp        |  43 ++++++++++++
 src/checks/health_checker.hpp |   3 +
 src/master/validation.cpp     |  15 +++++
 src/master/validation.hpp     |   3 +
 src/slave/validation.cpp      |  11 +++
 8 files changed, 212 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/784afbd6/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e7d5008..348eb2c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -253,6 +253,7 @@ set(HDFS_SRC
   )
 
 set(HEALTH_CHECK_SRC
+  checks/checker.cpp
   checks/health_checker.cpp
   )
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/784afbd6/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 0dba34e..30db9fd 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -832,6 +832,7 @@ libmesos_no_3rdparty_la_SOURCES +=					\
   authorizer/acls.cpp							\
   authorizer/authorizer.cpp						\
   authorizer/local/authorizer.cpp					\
+  checks/checker.cpp							\
   checks/health_checker.cpp						\
   common/attributes.cpp							\
   common/command_utils.cpp						\
@@ -959,6 +960,7 @@ libmesos_no_3rdparty_la_SOURCES +=					\
   authentication/cram_md5/authenticator.hpp				\
   authentication/cram_md5/auxprop.hpp					\
   authorizer/local/authorizer.hpp					\
+  checks/checker.hpp							\
   checks/health_checker.hpp						\
   common/build.hpp							\
   common/command_utils.hpp						\

http://git-wip-us.apache.org/repos/asf/mesos/blob/784afbd6/src/checks/checker.cpp
----------------------------------------------------------------------
diff --git a/src/checks/checker.cpp b/src/checks/checker.cpp
new file mode 100644
index 0000000..8d7285a
--- /dev/null
+++ b/src/checks/checker.cpp
@@ -0,0 +1,134 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "checks/checker.hpp"
+
+#include <string>
+
+#include <mesos/mesos.hpp>
+
+#include <stout/strings.hpp>
+
+using std::string;
+
+namespace mesos {
+namespace internal {
+namespace checks {
+
+namespace validation {
+
+Option<Error> checkInfo(const CheckInfo& checkInfo)
+{
+  if (!checkInfo.has_type()) {
+    return Error("CheckInfo must specify 'type'");
+  }
+
+  switch (checkInfo.type()) {
+    case CheckInfo::COMMAND: {
+      if (!checkInfo.has_command()) {
+        return Error("Expecting 'command' to be set for command check");
+      }
+
+      const CommandInfo& command = checkInfo.command().command();
+
+      if (!command.has_value()) {
+        string commandType =
+          (command.shell() ? "'shell command'" : "'executable path'");
+
+        return Error("Command check must contain " + commandType);
+      }
+
+      // TODO(alexr): Make sure irrelevant fields, e.g., `uris` are not set.
+
+      break;
+    }
+
+    case CheckInfo::HTTP: {
+      if (!checkInfo.has_http()) {
+        return Error("Expecting 'http' to be set for HTTP check");
+      }
+
+      const CheckInfo::Http& http = checkInfo.http();
+
+      if (http.has_path() && !strings::startsWith(http.path(), '/')) {
+        return Error(
+            "The path '" + http.path() +
+            "' of HTTP  check must start with '/'");
+      }
+
+      break;
+    }
+
+    case CheckInfo::UNKNOWN: {
+      return Error(
+          "'" + CheckInfo::Type_Name(checkInfo.type()) + "'"
+          " is not a valid check type");
+    }
+  }
+
+  if (checkInfo.has_delay_seconds() && checkInfo.delay_seconds() < 0.0) {
+    return Error("Expecting 'delay_seconds' to be non-negative");
+  }
+
+  if (checkInfo.has_interval_seconds() && checkInfo.interval_seconds() < 0.0)
{
+    return Error("Expecting 'interval_seconds' to be non-negative");
+  }
+
+  if (checkInfo.has_timeout_seconds() && checkInfo.timeout_seconds() < 0.0) {
+    return Error("Expecting 'timeout_seconds' to be non-negative");
+  }
+
+  return None();
+}
+
+
+Option<Error> checkStatusInfo(const CheckStatusInfo& checkStatusInfo)
+{
+  if (!checkStatusInfo.has_type()) {
+    return Error("CheckStatusInfo must specify 'type'");
+  }
+
+  switch (checkStatusInfo.type()) {
+    case CheckInfo::COMMAND: {
+      if (!checkStatusInfo.has_command()) {
+        return Error(
+            "Expecting 'command' to be set for command check's status");
+      }
+      break;
+    }
+
+    case CheckInfo::HTTP: {
+      if (!checkStatusInfo.has_http()) {
+        return Error("Expecting 'http' to be set for HTTP check's status");
+      }
+      break;
+    }
+
+    case CheckInfo::UNKNOWN: {
+      return Error(
+          "'" + CheckInfo::Type_Name(checkStatusInfo.type()) + "'"
+          " is not a valid check's status type");
+    }
+  }
+
+  return None();
+}
+
+} // namespace validation {
+
+} // namespace checks {
+} // namespace internal {
+} // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/784afbd6/src/checks/checker.hpp
----------------------------------------------------------------------
diff --git a/src/checks/checker.hpp b/src/checks/checker.hpp
new file mode 100644
index 0000000..dc293f3
--- /dev/null
+++ b/src/checks/checker.hpp
@@ -0,0 +1,43 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __CHECKER_HPP__
+#define __CHECKER_HPP__
+
+#include <mesos/mesos.hpp>
+
+#include <stout/error.hpp>
+#include <stout/option.hpp>
+
+namespace mesos {
+namespace internal {
+namespace checks {
+
+namespace validation {
+
+// TODO(alexr): A better place for these functions would be something like
+// "mesos_validation.cpp", since they validate API protobufs which are not
+// solely related to this library.
+Option<Error> checkInfo(const CheckInfo& checkInfo);
+Option<Error> checkStatusInfo(const CheckStatusInfo& checkStatusInfo);
+
+} // namespace validation {
+
+} // namespace checks {
+} // namespace internal {
+} // namespace mesos {
+
+#endif // __CHECKER_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/784afbd6/src/checks/health_checker.hpp
----------------------------------------------------------------------
diff --git a/src/checks/health_checker.hpp b/src/checks/health_checker.hpp
index 3e79ea6..6e558f2 100644
--- a/src/checks/health_checker.hpp
+++ b/src/checks/health_checker.hpp
@@ -155,6 +155,9 @@ private:
 
 namespace validation {
 
+// TODO(alexr): A better place for this function would be something like
+// "mesos_validation.cpp", since it validates API protobuf which is not
+// solely related to the health checking library.
 Option<Error> healthCheck(const HealthCheck& check);
 
 } // namespace validation {

http://git-wip-us.apache.org/repos/asf/mesos/blob/784afbd6/src/master/validation.cpp
----------------------------------------------------------------------
diff --git a/src/master/validation.cpp b/src/master/validation.cpp
index 2e394c3..0920bd0 100644
--- a/src/master/validation.cpp
+++ b/src/master/validation.cpp
@@ -31,6 +31,7 @@
 #include <stout/none.hpp>
 #include <stout/stringify.hpp>
 
+#include "checks/checker.hpp"
 #include "checks/health_checker.hpp"
 
 #include "common/protobuf_utils.hpp"
@@ -827,6 +828,19 @@ Option<Error> validateKillPolicy(const TaskInfo& task)
 }
 
 
+Option<Error> validateCheck(const TaskInfo& task)
+{
+  if (task.has_check()) {
+    Option<Error> error = checks::validation::checkInfo(task.check());
+    if (error.isSome()) {
+      return Error("Task uses invalid check: " + error->message);
+    }
+  }
+
+  return None();
+}
+
+
 Option<Error> validateHealthCheck(const TaskInfo& task)
 {
   if (task.has_health_check()) {
@@ -913,6 +927,7 @@ Option<Error> validateTask(
     lambda::bind(internal::validateUniqueTaskID, task, framework),
     lambda::bind(internal::validateSlaveID, task, slave),
     lambda::bind(internal::validateKillPolicy, task),
+    lambda::bind(internal::validateCheck, task),
     lambda::bind(internal::validateHealthCheck, task),
     lambda::bind(internal::validateResources, task)
   };

http://git-wip-us.apache.org/repos/asf/mesos/blob/784afbd6/src/master/validation.hpp
----------------------------------------------------------------------
diff --git a/src/master/validation.hpp b/src/master/validation.hpp
index 78b70a7..fc1eaee 100644
--- a/src/master/validation.hpp
+++ b/src/master/validation.hpp
@@ -155,6 +155,9 @@ Option<Error> validateTaskAndExecutorResources(const TaskInfo&
task);
 // Validates the kill policy of the task.
 Option<Error> validateKillPolicy(const TaskInfo& task);
 
+// Validates the check of the task.
+Option<Error> validateCheck(const TaskInfo& task);
+
 // Validates the health check of the task.
 Option<Error> validateHealthCheck(const TaskInfo& task);
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/784afbd6/src/slave/validation.cpp
----------------------------------------------------------------------
diff --git a/src/slave/validation.cpp b/src/slave/validation.cpp
index 7f1ba93..3fd32fe 100644
--- a/src/slave/validation.cpp
+++ b/src/slave/validation.cpp
@@ -24,6 +24,8 @@
 #include <stout/unreachable.hpp>
 #include <stout/uuid.hpp>
 
+#include "checks/checker.hpp"
+
 #include "common/validation.hpp"
 
 using std::string;
@@ -368,6 +370,15 @@ Option<Error> validate(const mesos::executor::Call& call)
                      );
       }
 
+      if (status.has_check_status()) {
+        Option<Error> validate =
+          checks::validation::checkStatusInfo(status.check_status());
+
+        if (validate.isSome()) {
+          return validate.get();
+        }
+      }
+
       return None();
     }
 


Mime
View raw message