task-controller.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 "configuration.h"
  33. //command definitions
  34. enum command {
  35. RUN_TASK,
  36. KILL_TASK
  37. };
  38. enum errorcodes {
  39. INVALID_ARGUMENT_NUMBER = 1,
  40. INVALID_USER_NAME,
  41. INVALID_COMMAND_PROVIDED,
  42. SUPER_USER_NOT_ALLOWED_TO_RUN_TASKS,
  43. OUT_OF_MEMORY,
  44. INVALID_TT_ROOT,
  45. INVALID_PID_PATH,
  46. UNABLE_TO_OPEN_PID_FILE_WRITE_MODE,
  47. UNABLE_TO_OPEN_PID_FILE_READ_MODE,
  48. UNABLE_TO_WRITE_TO_PID_FILE,
  49. UNABLE_TO_CHANGE_PERMISSION_OF_PID_FILE,
  50. UNABLE_TO_CHANGE_PERMISSION_AND_DELETE_PID_FILE,
  51. SETUID_OPER_FAILED,
  52. INVALID_TASK_SCRIPT_PATH,
  53. UNABLE_TO_EXECUTE_TASK_SCRIPT,
  54. UNABLE_TO_READ_PID,
  55. UNABLE_TO_KILL_TASK,
  56. UNABLE_TO_FIND_PARENT_PID_FILE,
  57. UNABLE_TO_READ_PARENT_PID,
  58. SETSID_FAILED,
  59. ERROR_RESOLVING_FILE_PATH,
  60. RELATIVE_PATH_COMPONENTS_IN_FILE_PATH,
  61. UNABLE_TO_STAT_FILE,
  62. FILE_NOT_OWNED_BY_TASKTRACKER,
  63. UNABLE_TO_CHANGE_OWNERSHIP_OF_PID_FILE,
  64. UNABLE_TO_CHANGE_OWNERSHIP_AND_DELETE_PID_FILE
  65. };
  66. #define TT_PID_PATTERN "%s/hadoop-%s-tasktracker.pid"
  67. #define TT_LOCAL_TASK_SCRIPT_PATTERN "%s/taskTracker/jobcache/%s/%s/taskjvm.sh"
  68. #define TT_SYS_DIR "%s/taskTracker/jobcache/%s/%s/.pid"
  69. #define TT_SYS_DIR_KEY "mapred.local.dir"
  70. #define MAX_ITEMS 10
  71. #ifndef HADOOP_CONF_DIR
  72. #define EXEC_PATTERN "/bin/task-controller"
  73. extern char * hadoop_conf_dir;
  74. #endif
  75. extern struct passwd *user_detail;
  76. extern FILE *LOGFILE;
  77. void display_usage(FILE *stream);
  78. int run_task_as_user(const char * user, const char *jobid, const char *taskid, const char *tt_root);
  79. int verify_parent();
  80. int kill_user_task(const char *user, const char *jobid, const char *taskid, const char *tt_root);
  81. int get_user_details(const char *user);