YARN-5717. Add tests for container-executor is_feature_enabled. Contributed by Sidharta Seethana
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/cf3f43e9 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/cf3f43e9 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/cf3f43e9 Branch: refs/heads/HADOOP-13070 Commit: cf3f43e95bf46030875137fc36da5c1fbe14250d Parents: 0a85d07 Author: Chris Douglas <cdoug...@apache.org> Authored: Thu Oct 13 20:47:49 2016 -0700 Committer: Chris Douglas <cdoug...@apache.org> Committed: Thu Oct 13 20:49:07 2016 -0700 ---------------------------------------------------------------------- .../impl/container-executor.c | 11 ++--- .../impl/container-executor.h | 4 ++ .../main/native/container-executor/impl/main.c | 42 ++++++++-------- .../test/test-container-executor.c | 51 ++++++++++++++++++++ 4 files changed, 79 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/cf3f43e9/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.c ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.c b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.c index a9a7e96..8a995b1 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.c +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.c @@ -422,9 +422,9 @@ int change_user(uid_t user, gid_t group) { return 0; } - -static int is_feature_enabled(const char* feature_key, int default_value) { - char *enabled_str = get_value(feature_key, &executor_cfg); +int is_feature_enabled(const char* feature_key, int default_value, + struct configuration *cfg) { + char *enabled_str = get_value(feature_key, cfg); int enabled = default_value; if (enabled_str != NULL) { @@ -448,15 +448,14 @@ static int is_feature_enabled(const char* feature_key, int default_value) { } } - int is_docker_support_enabled() { return is_feature_enabled(DOCKER_SUPPORT_ENABLED_KEY, - DEFAULT_DOCKER_SUPPORT_ENABLED); + DEFAULT_DOCKER_SUPPORT_ENABLED, &executor_cfg); } int is_tc_support_enabled() { return is_feature_enabled(TC_SUPPORT_ENABLED_KEY, - DEFAULT_TC_SUPPORT_ENABLED); + DEFAULT_TC_SUPPORT_ENABLED, &executor_cfg); } char* check_docker_binary(char *docker_binary) { http://git-wip-us.apache.org/repos/asf/hadoop/blob/cf3f43e9/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.h ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.h b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.h index 5c17b29..8ad5d47 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.h +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.h @@ -264,6 +264,10 @@ int check_dir(const char* npath, mode_t st_mode, mode_t desired, int create_validate_dir(const char* npath, mode_t perm, const char* path, int finalComponent); +/** Check if a feature is enabled in the specified configuration. */ +int is_feature_enabled(const char* feature_key, int default_value, + struct configuration *cfg); + /** Check if tc (traffic control) support is enabled in configuration. */ int is_tc_support_enabled(); http://git-wip-us.apache.org/repos/asf/hadoop/blob/cf3f43e9/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/main.c ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/main.c b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/main.c index 27a269e..47bb3b9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/main.c +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/main.c @@ -43,73 +43,69 @@ #endif static void display_usage(FILE *stream) { - char usage_template[4096]; - - usage_template[0] = '\0'; - strcat(usage_template, + fprintf(stream, "Usage: container-executor --checksetup\n" " container-executor --mount-cgroups <hierarchy> " "<controller=path>...\n" ); if(is_tc_support_enabled()) { - strcat(usage_template, + fprintf(stream, " container-executor --tc-modify-state <command-file>\n" " container-executor --tc-read-state <command-file>\n" " container-executor --tc-read-stats <command-file>\n" ); } else { - strcat(usage_template, + fprintf(stream, "[DISABLED] container-executor --tc-modify-state <command-file>\n" "[DISABLED] container-executor --tc-read-state <command-file>\n" "[DISABLED] container-executor --tc-read-stats <command-file>\n"); } if(is_docker_support_enabled()) { - strcat(usage_template, + fprintf(stream, " container-executor --run-docker <command-file>\n"); } else { - strcat(usage_template, + fprintf(stream, "[DISABLED] container-executor --run-docker <command-file>\n"); } - strcat(usage_template, + fprintf(stream, " container-executor <user> <yarn-user> <command> <command-args>\n" " where command and command-args: \n" \ " initialize container: %2d appid tokens nm-local-dirs " "nm-log-dirs cmd app...\n" " launch container: %2d appid containerid workdir " - "container-script tokens pidfile nm-local-dirs nm-log-dirs resources "); + "container-script tokens pidfile nm-local-dirs nm-log-dirs resources ", + INITIALIZE_CONTAINER, LAUNCH_CONTAINER); if(is_tc_support_enabled()) { - strcat(usage_template, "optional-tc-command-file\n"); + fprintf(stream, "optional-tc-command-file\n"); } else { - strcat(usage_template, "\n"); + fprintf(stream, "\n"); } if(is_docker_support_enabled()) { - strcat(usage_template, + fprintf(stream, " launch docker container: %2d appid containerid workdir " "container-script tokens pidfile nm-local-dirs nm-log-dirs " - "docker-command-file resources "); + "docker-command-file resources ", LAUNCH_DOCKER_CONTAINER); } else { - strcat(usage_template, + fprintf(stream, "[DISABLED] launch docker container: %2d appid containerid workdir " "container-script tokens pidfile nm-local-dirs nm-log-dirs " - "docker-command-file resources "); + "docker-command-file resources ", LAUNCH_DOCKER_CONTAINER); } if(is_tc_support_enabled()) { - strcat(usage_template, "optional-tc-command-file\n"); + fprintf(stream, "optional-tc-command-file\n"); } else { - strcat(usage_template, "\n"); + fprintf(stream, "\n"); } - strcat(usage_template, + fprintf(stream, " signal container: %2d container-pid signal\n" " delete as user: %2d relative-path\n" - " list as user: %2d relative-path\n"); - - fprintf(stream, usage_template, INITIALIZE_CONTAINER, LAUNCH_CONTAINER, - LAUNCH_DOCKER_CONTAINER, SIGNAL_CONTAINER, DELETE_AS_USER, LIST_AS_USER); + " list as user: %2d relative-path\n", + SIGNAL_CONTAINER, DELETE_AS_USER, LIST_AS_USER); } /* Sets up log files for normal/error logging */ http://git-wip-us.apache.org/repos/asf/hadoop/blob/cf3f43e9/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c index f174a9f..f7d4975 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c @@ -395,6 +395,54 @@ void test_delete_app() { free(dont_touch); } +void validate_feature_enabled_value(int expected_value, const char* key, + int default_value, struct configuration *cfg) { + int value = is_feature_enabled(key, default_value, cfg); + + if (value != expected_value) { + printf("FAIL: expected value %d for key %s but found %d\n", + expected_value, key, value); + exit(1); + } +} + +void test_is_feature_enabled() { + char* filename = TEST_ROOT "/feature_flag_test.cfg"; + FILE *file = fopen(filename, "w"); + int disabled = 0; + int enabled = 1; + struct configuration cfg = {.size=0, .confdetails=NULL}; + + if (file == NULL) { + printf("FAIL: Could not open configuration file: %s\n", filename); + exit(1); + } + + fprintf(file, "feature.name1.enabled=0\n"); + fprintf(file, "feature.name2.enabled=1\n"); + fprintf(file, "feature.name3.enabled=1klajdflkajdsflk\n"); + fprintf(file, "feature.name4.enabled=asdkjfasdkljfklsdjf0\n"); + fprintf(file, "feature.name5.enabled=-1\n"); + fprintf(file, "feature.name6.enabled=2\n"); + fclose(file); + read_config(filename, &cfg); + + validate_feature_enabled_value(disabled, "feature.name1.enabled", + disabled, &cfg); + validate_feature_enabled_value(enabled, "feature.name2.enabled", + disabled, &cfg); + validate_feature_enabled_value(disabled, "feature.name3.enabled", + disabled, &cfg); + validate_feature_enabled_value(disabled, "feature.name4.enabled", + disabled, &cfg); + validate_feature_enabled_value(enabled, "feature.name5.enabled", + enabled, &cfg); + validate_feature_enabled_value(disabled, "feature.name6.enabled", + disabled, &cfg); + + + free_configurations(&cfg); +} void test_delete_user() { printf("\nTesting delete_user\n"); @@ -1091,6 +1139,9 @@ int main(int argc, char **argv) { printf("\nTesting delete_app()\n"); test_delete_app(); + printf("\nTesting is_feature_enabled()\n"); + test_is_feature_enabled(); + test_check_user(0); #ifdef __APPLE__ --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org