task-controller.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <stdarg.h>
  21. #include <string.h>
  22. #include <errno.h>
  23. #include <unistd.h>
  24. #include <sys/types.h>
  25. #include <pwd.h>
  26. #include <assert.h>
  27. #include <getopt.h>
  28. #include <sys/stat.h>
  29. #include <sys/signal.h>
  30. #include <getopt.h>
  31. #include <grp.h>
  32. #include <dirent.h>
  33. #include <fcntl.h>
  34. #include <fts.h>
  35. #include "configuration.h"
  36. //command definitions
  37. enum command {
  38. INITIALIZE_USER,
  39. INITIALIZE_JOB,
  40. INITIALIZE_DISTRIBUTEDCACHE_FILE,
  41. LAUNCH_TASK_JVM,
  42. INITIALIZE_TASK,
  43. TERMINATE_TASK_JVM,
  44. KILL_TASK_JVM,
  45. ENABLE_TASK_FOR_CLEANUP
  46. };
  47. enum errorcodes {
  48. INVALID_ARGUMENT_NUMBER = 1,
  49. INVALID_USER_NAME, //2
  50. INVALID_COMMAND_PROVIDED, //3
  51. SUPER_USER_NOT_ALLOWED_TO_RUN_TASKS, //4
  52. INVALID_TT_ROOT, //5
  53. SETUID_OPER_FAILED, //6
  54. UNABLE_TO_EXECUTE_TASK_SCRIPT, //7
  55. UNABLE_TO_KILL_TASK, //8
  56. INVALID_TASK_PID, //9
  57. ERROR_RESOLVING_FILE_PATH, //10
  58. RELATIVE_PATH_COMPONENTS_IN_FILE_PATH, //11
  59. UNABLE_TO_STAT_FILE, //12
  60. FILE_NOT_OWNED_BY_TASKTRACKER, //13
  61. PREPARE_ATTEMPT_DIRECTORIES_FAILED, //14
  62. INITIALIZE_JOB_FAILED, //15
  63. PREPARE_TASK_LOGS_FAILED, //16
  64. INVALID_TT_LOG_DIR, //17
  65. OUT_OF_MEMORY, //18
  66. INITIALIZE_DISTCACHEFILE_FAILED, //19
  67. INITIALIZE_USER_FAILED, //20
  68. UNABLE_TO_BUILD_PATH, //21
  69. INVALID_TASKCONTROLLER_PERMISSIONS //22
  70. };
  71. #define USER_DIR_PATTERN "%s/taskTracker/%s"
  72. #define TT_JOB_DIR_PATTERN USER_DIR_PATTERN"/jobcache/%s"
  73. #define USER_DISTRIBUTED_CACHE_DIR_PATTERN USER_DIR_PATTERN"/distcache/%s"
  74. #define JOB_DIR_TO_JOB_WORK_PATTERN "%s/work"
  75. #define JOB_DIR_TO_ATTEMPT_DIR_PATTERN "%s/%s"
  76. #define ATTEMPT_LOG_DIR_PATTERN "%s/userlogs/%s"
  77. #define TASK_SCRIPT_PATTERN "%s/%s/taskjvm.sh"
  78. #define TT_LOCAL_TASK_DIR_PATTERN "%s/taskTracker/%s/jobcache/%s/%s"
  79. #define TT_SYS_DIR_KEY "mapred.local.dir"
  80. #define TT_LOG_DIR_KEY "hadoop.log.dir"
  81. #define TT_GROUP_KEY "mapreduce.tasktracker.group"
  82. #ifndef HADOOP_CONF_DIR
  83. #define EXEC_PATTERN "/bin/task-controller"
  84. extern char * hadoop_conf_dir;
  85. #endif
  86. extern struct passwd *user_detail;
  87. extern FILE *LOGFILE;
  88. int run_task_as_user(const char * user, const char *jobid, const char *taskid,
  89. const char *tt_root);
  90. int initialize_user(const char *user);
  91. int initialize_task(const char *jobid, const char *taskid, const char *user);
  92. int initialize_job(const char *jobid, const char *user);
  93. int initialize_distributed_cache_file(const char *tt_root,
  94. const char* unique_string, const char *user);
  95. int kill_user_task(const char *user, const char *task_pid, int sig);
  96. int enable_task_for_cleanup(const char *tt_root, const char *user,
  97. const char *jobid, const char *dir_to_be_deleted);
  98. int prepare_attempt_directory(const char *attempt_dir, const char *user);
  99. // The following functions are exposed for testing
  100. int check_variable_against_config(const char *config_key,
  101. const char *passed_value);
  102. int get_user_details(const char *user);
  103. char *get_task_launcher_file(const char *job_dir, const char *attempt_dir);