diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/LinuxContainerExecutor.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/LinuxContainerExecutor.java index eaf664f..ed0a293 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/LinuxContainerExecutor.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/LinuxContainerExecutor.java @@ -362,6 +362,7 @@ public void startLocalizer(LocalizerStartContext ctx) PrivilegedOperation.RunAsUserCommand.INITIALIZE_CONTAINER .getValue()), appId, + locId, nmPrivateContainerTokensPath.toUri().getPath().toString(), StringUtils.join(PrivilegedOperation.LINUX_FILE_PATH_SEPARATOR, localDirs), diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/ContainerLocalizer.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/ContainerLocalizer.java index 541911a..639a69d 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/ContainerLocalizer.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/ContainerLocalizer.java @@ -63,7 +63,6 @@ import org.apache.hadoop.util.Shell; import org.apache.hadoop.util.concurrent.HadoopExecutors; import org.apache.hadoop.yarn.YarnUncaughtExceptionHandler; -import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; import org.apache.hadoop.yarn.api.ApplicationConstants; import org.apache.hadoop.yarn.api.records.LocalResource; import org.apache.hadoop.yarn.api.records.LocalResourceVisibility; @@ -447,7 +446,6 @@ public static void main(String[] argv) throws Throwable { // MKDIR $x/$user/appcache/$appid/filecache // LOAD $x/$user/appcache/$appid/appTokens try { - createLogDir(); String user = argv[0]; String appId = argv[1]; String locId = argv[2]; @@ -483,31 +481,6 @@ public static void main(String[] argv) throws Throwable { } } - /** - * Create the log directory, if the directory exists, make sure its permission - * is 750. - */ - private static void createLogDir() { - FileContext localFs; - try { - localFs = FileContext.getLocalFSFileContext(new Configuration()); - - String logDir = System.getProperty( - YarnConfiguration.YARN_APP_CONTAINER_LOG_DIR); - - if (logDir != null && !logDir.trim().isEmpty()) { - Path containerLogPath = new Path(logDir); - FsPermission containerLogDirPerm= new FsPermission((short)0750); - localFs.mkdir(containerLogPath, containerLogDirPerm, true); - // set permission again to make sure the permission is correct - // in case the directory is already there. - localFs.setPermission(containerLogPath, containerLogDirPerm); - } - } catch (IOException e) { - throw new YarnRuntimeException("Unable to create the log dir", e); - } - } - private static void initDirs(Configuration conf, String user, String appId, FileContext lfs, List localDirs) throws IOException { if (null == localDirs || 0 == localDirs.size()) { diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.c hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.c index 3b04f88..88c44f9 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.c +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.c @@ -1052,11 +1052,52 @@ int create_log_dirs(const char *app_id, char * const * log_dirs) { return 0; } +char* get_container_log_directory(const char *log_root, const char* app_id, + const char *container_id) { + return concatenate("%s/%s/%s", "container log dir", 3, log_root, app_id, + container_id); +} + +int create_container_log_dirs(const char *container_id, const char *app_id, + char * const * log_dirs) { + char* const* log_root; + int created_any_dir = 0; + for(log_root=log_dirs; *log_root != NULL; ++log_root) { + char *container_log_dir = get_container_log_directory(*log_root, app_id, + container_id); + if (container_log_dir == NULL) { + fprintf(LOGFILE, + "Failed to get container log directory name! Log root directory: %s, App id: %s, Container id: %s\n", + *log_root, app_id, container_id); + continue; + } + + if (create_directory_for_user(container_log_dir) != 0) { + fprintf(LOGFILE, "Failed to create container log directory(%s)!\n", + container_log_dir); + free(container_log_dir); + return -1; + } + + if (!created_any_dir) { + created_any_dir = 1; + } + + free(container_log_dir); + } + + if (!created_any_dir) { + fprintf(LOGFILE, "Did not create any container log directory.\n"); + return -1; + } + return 0; +} /** * Function to prepare the application directories for the container. */ int initialize_app(const char *user, const char *app_id, + const char *container_id, const char* nmPrivate_credentials_file, char* const* local_dirs, char* const* log_roots, char* const* args) { @@ -1077,6 +1118,13 @@ int initialize_app(const char *user, const char *app_id, return log_create_result; } + // create the log directories for the container on all disks + int container_log_create_result = create_container_log_dirs(container_id, + app_id, log_roots); + if (container_log_create_result != 0) { + return container_log_create_result; + } + // open up the credentials file int cred_file = open_file_as_nm(nmPrivate_credentials_file); if (cred_file == -1) { diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.h hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.h index 6d4220f..32c91ea 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.h +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.h @@ -91,6 +91,7 @@ void free_executor_configurations(); // initialize the application directory int initialize_app(const char *user, const char *app_id, + const char *container_id, const char *credentials, char* const* local_dirs, char* const* log_dirs, char* const* args); diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/main.c hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/main.c index ca84d40..259719a 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/main.c +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/main.c @@ -360,13 +360,14 @@ static int validate_run_as_user_commands(int argc, char **argv, int *operation) char * resources_value = NULL; switch (command) { case INITIALIZE_CONTAINER: - if (argc < 9) { - fprintf(ERRORFILE, "Too few arguments (%d vs 9) for initialize container\n", + if (argc < 10) { + fprintf(ERRORFILE, "Too few arguments (%d vs 10) for initialize container\n", argc); fflush(ERRORFILE); return INVALID_ARGUMENT_NUMBER; } cmd_input.app_id = argv[optind++]; + cmd_input.container_id = argv[optind++]; cmd_input.cred_file = argv[optind++]; cmd_input.local_dirs = argv[optind++];// good local dirs as a comma separated list cmd_input.log_dirs = argv[optind++];// good log dirs as a comma separated list @@ -563,6 +564,7 @@ int main(int argc, char **argv) { exit_code = initialize_app(cmd_input.yarn_user_name, cmd_input.app_id, + cmd_input.container_id, cmd_input.cred_file, split(cmd_input.local_dirs), split(cmd_input.log_dirs), diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c index 4e8db6c..d66aa34 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c @@ -774,7 +774,8 @@ void test_init_app() { exit(1); } else if (child == 0) { char *final_pgm[] = {"touch", "my-touch-file", 0}; - if (initialize_app(yarn_username, "app_4", TEST_ROOT "/creds.txt", + if (initialize_app(yarn_username, "app_4", "container_1", + TEST_ROOT "/creds.txt", local_dirs, log_dirs, final_pgm) != 0) { printf("FAIL: failed in child\n"); exit(42); @@ -815,6 +816,14 @@ void test_init_app() { exit(1); } free(app_dir); + + char *container_dir = get_container_log_directory(TEST_ROOT "/logs/userlogs", + "app_4", "container_1"); + if (container_dir != NULL && access(container_dir, R_OK) != 0) { + printf("FAIL: failed to create container log directory %s\n", container_dir); + exit(1); + } + free(container_dir); } void test_run_container() { diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestLinuxContainerExecutorWithMocks.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestLinuxContainerExecutorWithMocks.java index 9a56656..1ffdf95 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestLinuxContainerExecutorWithMocks.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestLinuxContainerExecutorWithMocks.java @@ -269,7 +269,7 @@ public void testStartLocalizer() throws IOException { .build()); List result=readMockParams(); - Assert.assertEquals(result.size(), 24); + Assert.assertEquals(result.size(), 25); Assert.assertEquals(result.get(0), YarnConfiguration.DEFAULT_NM_NONSECURE_MODE_LOCAL_USER); Assert.assertEquals(result.get(1), "test"); Assert.assertEquals(result.get(2), "0" );