YARN-5717. Add tests for container-executor is_feature_enabled. Contributed by Sidharta Seethana

This commit is contained in:
Chris Douglas 2016-10-13 20:47:49 -07:00
parent 0a85d07983
commit cf3f43e95b
4 changed files with 79 additions and 29 deletions

View File

@ -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) {

View File

@ -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();

View File

@ -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 */

View File

@ -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__