You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by al...@apache.org on 2016/11/14 10:41:24 UTC
[2/4] mesos git commit: Refactored HealthCheck validation for clarity.
Refactored HealthCheck validation for clarity.
Review: https://reviews.apache.org/r/52863
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/de9c366e
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/de9c366e
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/de9c366e
Branch: refs/heads/master
Commit: de9c366e4b3907d5bd2bd33a86767515fef23fbd
Parents: 2772222
Author: Alexander Rukletsov <al...@apache.org>
Authored: Fri Nov 11 12:20:14 2016 +0100
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Mon Nov 14 11:38:52 2016 +0100
----------------------------------------------------------------------
src/health-check/health_checker.cpp | 72 +++++++++++++++++++-------------
1 file changed, 43 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/de9c366e/src/health-check/health_checker.cpp
----------------------------------------------------------------------
diff --git a/src/health-check/health_checker.cpp b/src/health-check/health_checker.cpp
index e2b32e2..496aec4 100644
--- a/src/health-check/health_checker.cpp
+++ b/src/health-check/health_checker.cpp
@@ -637,46 +637,60 @@ Option<Error> healthCheck(const HealthCheck& check)
return Error("HealthCheck must specify 'type'");
}
- if (check.type() == HealthCheck::COMMAND) {
- if (!check.has_command()) {
- return Error("Expecting 'command' to be set for command health check");
- }
+ switch (check.type()) {
+ case HealthCheck::COMMAND: {
+ if (!check.has_command()) {
+ return Error("Expecting 'command' to be set for command health check");
+ }
+
+ const CommandInfo& command = check.command();
- const CommandInfo& command = check.command();
+ if (!command.has_value()) {
+ string commandType =
+ (command.shell() ? "'shell command'" : "'executable path'");
- if (!command.has_value()) {
- string commandType =
- (command.shell() ? "'shell command'" : "'executable path'");
+ return Error("Command health check must contain " + commandType);
+ }
- return Error("Command health check must contain " + commandType);
+ break;
}
- } else if (check.type() == HealthCheck::HTTP) {
- if (!check.has_http()) {
- return Error("Expecting 'http' to be set for HTTP health check");
+
+ case HealthCheck::HTTP: {
+ if (!check.has_http()) {
+ return Error("Expecting 'http' to be set for HTTP health check");
+ }
+
+ const HealthCheck::HTTPCheckInfo& http = check.http();
+
+ if (http.has_scheme() &&
+ http.scheme() != "http" &&
+ http.scheme() != "https") {
+ return Error(
+ "Unsupported HTTP health check scheme: '" + http.scheme() + "'");
+ }
+
+ if (http.has_path() && !strings::startsWith(http.path(), '/')) {
+ return Error(
+ "The path '" + http.path() +
+ "' of HTTP health check must start with '/'");
+ }
+
+ break;
}
- const HealthCheck::HTTPCheckInfo& http = check.http();
+ case HealthCheck::TCP: {
+ if (!check.has_tcp()) {
+ return Error("Expecting 'tcp' to be set for TCP health check");
+ }
- if (http.has_scheme() &&
- http.scheme() != "http" &&
- http.scheme() != "https") {
- return Error(
- "Unsupported HTTP health check scheme: '" + http.scheme() + "'");
+ break;
}
- if (http.has_path() && !strings::startsWith(http.path(), '/')) {
+ case HealthCheck::UNKNOWN: {
return Error(
- "The path '" + http.path() +
- "' of HTTP health check must start with '/'");
+ "'" + HealthCheck::Type_Name(check.type()) + "'"
+ " is not a valid health check type");
}
- } else if (check.type() == HealthCheck::TCP) {
- if (!check.has_tcp()) {
- return Error("Expecting 'tcp' to be set for TCP health check");
- }
- } else {
- return Error(
- "Unsupported health check type: '" +
- HealthCheck::Type_Name(check.type()) + "'");
}
return None();