void test_delete_job() {
    char* local_dirs = get_value("mapred.local.dir");
    char* job_dir = get_job_directory(TEST_ROOT "/local-2", username, "job_2");
    char* dont_touch = get_job_directory(TEST_ROOT "/local-2", username,
                                         DONT_TOUCH_FILE);
    char* task_dir = get_attempt_work_directory(TEST_ROOT "/local-2",
                     username, "job_2", "task_1");
    char buffer[100000];
    sprintf(buffer, "mkdir -p %s/who/let/the/dogs/out/who/who", task_dir);
    run(buffer);
    sprintf(buffer, "touch %s", dont_touch);
    run(buffer);

    // soft link to the canary file from the task directory
    sprintf(buffer, "ln -s %s %s/who/softlink", dont_touch, task_dir);
    run(buffer);
    // hard link to the canary file from the task directory
    sprintf(buffer, "ln %s %s/who/hardlink", dont_touch, task_dir);
    run(buffer);
    // create a dot file in the task directory
    sprintf(buffer, "touch %s/who/let/.dotfile", task_dir);
    run(buffer);
    // create a no permission file
    sprintf(buffer, "touch %s/who/let/protect", task_dir);
    run(buffer);
    sprintf(buffer, "chmod 000 %s/who/let/protect", task_dir);
    run(buffer);
    // create a no permission directory
    sprintf(buffer, "chmod 000 %s/who/let", task_dir);
    run(buffer);

    // delete task directory
    int ret = delete_as_user(username, local_dirs, "jobcache/job_2");
    if (ret != 0) {
        printf("FAIL: return code from delete_as_user is %d\n", ret);
        exit(1);
    }

    // check to make sure the task directory is gone
    if (access(task_dir, R_OK) == 0) {
        printf("FAIL: failed to delete the directory - %s\n", task_dir);
        exit(1);
    }
    // check to make sure the job directory is gone
    if (access(job_dir, R_OK) == 0) {
        printf("FAIL: didn't delete the directory - %s\n", job_dir);
        exit(1);
    }
    // but that the canary is not gone
    if (access(dont_touch, R_OK) != 0) {
        printf("FAIL: accidently deleted file %s\n", dont_touch);
        exit(1);
    }
    free(job_dir);
    free(task_dir);
    free(dont_touch);
    free(local_dirs);
}
예제 #2
0
void test_delete_user() {
  printf("\nTesting delete_user\n");
  char* job_dir = get_job_directory(TEST_ROOT "/local-1", username, "job_3");
  if (mkdirs(job_dir, 0700) != 0) {
    exit(1);
  }
  char buffer[100000];
  sprintf(buffer, "%s/local-1/usercache/%s", TEST_ROOT, username);
  if (access(buffer, R_OK) != 0) {
    printf("FAIL: directory missing before test\n");
    exit(1);
  }
  if (delete_as_user(username, buffer, NULL) != 0) {
    exit(1);
  }
  if (access(buffer, R_OK) == 0) {
    printf("FAIL: directory not deleted\n");
    exit(1);
  }
  if (access(TEST_ROOT "/local-1", R_OK) != 0) {
    printf("FAIL: local-1 directory does not exist\n");
    exit(1);
  }
  free(job_dir);
}
void test_delete_user() {
    printf("\nTesting delete_user\n");
    char* local_dirs = get_value("mapred.local.dir");
    char* job_dir = get_job_directory(TEST_ROOT "/local-1", username, "job_3");
    if (mkdirs(job_dir, 0700) != 0) {
        exit(1);
    }
    char buffer[100000];
    sprintf(buffer, "%s/local-1/taskTracker/%s", TEST_ROOT, username);
    if (access(buffer, R_OK) != 0) {
        printf("FAIL: directory missing before test\n");
        exit(1);
    }
    if (delete_as_user(username, local_dirs, "") != 0) {
        exit(1);
    }
    if (access(buffer, R_OK) == 0) {
        printf("FAIL: directory not deleted\n");
        exit(1);
    }
    if (access(TEST_ROOT "/local-1", R_OK) != 0) {
        printf("FAIL: local-1 directory does not exist\n");
        exit(1);
    }
    free(job_dir);
    free(local_dirs);
}
예제 #4
0
void test_get_job_directory() {
  char *expected = "/tmp/taskTracker/user/jobcache/job_200906101234_0001";
  char *job_dir = (char *) get_job_directory("/tmp", "user",
      "job_200906101234_0001");
  if (strcmp(job_dir, expected) != 0) {
    exit(1);
  }
  free(job_dir);
}
예제 #5
0
void test_get_job_directory() {
  char *expected = "/tmp/usercache/user/appcache/job_200906101234_0001";
  char *job_dir = (char *) get_job_directory("/tmp", "user",
      "job_200906101234_0001");
  if (strcmp(job_dir, expected) != 0) {
    printf("test_get_job_directory expected %s got %s\n", expected, job_dir);
    exit(1);
  }
  free(job_dir);
}
예제 #6
0
void test_get_task_launcher_file() {
  char *expected_file = ("/tmp/usercache/user/appcache/job_200906101234_0001"
			 "/task.sh");
  char *job_dir = get_job_directory("/tmp", "user",
                                    "job_200906101234_0001");
  char *task_file =  get_task_launcher_file(job_dir);
  if (strcmp(task_file, expected_file) != 0) {
    printf("failure to match expected task file %s vs %s\n", task_file,
           expected_file);
    exit(1);
  }
  free(job_dir);
  free(task_file);
}
예제 #7
0
/**
 * Function to prepare the job directories for the task JVM.
 */
int initialize_job(const char *user, const char *jobid, 
		   const char* credentials, const char* job_xml,
                   char* const* args) {
  if (jobid == NULL || user == NULL) {
    fprintf(LOGFILE, "Either jobid is null or the user passed is null.\n");
    return INVALID_ARGUMENT_NUMBER;
  }

  // create the user directory
  int result = initialize_user(user);
  if (result != 0) {
    return result;
  }

  // create the log directory for the job
  char *job_log_dir = get_job_log_directory(jobid);
  if (job_log_dir == NULL) {
    return -1;
  }
  result = create_directory_for_user(job_log_dir);
  free(job_log_dir);
  if (result != 0) {
    return -1;
  }

  // open up the credentials file
  int cred_file = open_file_as_task_tracker(credentials);
  if (cred_file == -1) {
    return -1;
  }

  int job_file = open_file_as_task_tracker(job_xml);
  if (job_file == -1) {
    return -1;
  }

  // give up root privs
  if (change_user(user_detail->pw_uid, user_detail->pw_gid) != 0) {
    return -1;
  }

  // 750
  mode_t permissions = S_IRWXU | S_IRGRP | S_IXGRP;
  char **tt_roots = get_values(TT_SYS_DIR_KEY);

  if (tt_roots == NULL) {
    return INVALID_CONFIG_FILE;
  }

  char **tt_root;
  char *primary_job_dir = NULL;
  for(tt_root=tt_roots; *tt_root != NULL; ++tt_root) {
    char *job_dir = get_job_directory(*tt_root, user, jobid);
    if (job_dir == NULL) {
      // try the next one
    } else if (mkdirs(job_dir, permissions) != 0) {
      free(job_dir);
    } else if (primary_job_dir == NULL) {
      primary_job_dir = job_dir;
    } else {
      free(job_dir);
    }
  }
  free_values(tt_roots);
  if (primary_job_dir == NULL) {
    fprintf(LOGFILE, "Did not create any job directories\n");
    return -1;
  }

  char *cred_file_name = concatenate("%s/%s", "cred file", 2,
				     primary_job_dir, CREDENTIALS_FILENAME);
  if (cred_file_name == NULL) {
    return -1;
  }
  if (copy_file(cred_file, credentials, cred_file_name, S_IRUSR|S_IWUSR) != 0){
    return -1;
  }
  char *job_file_name = concatenate("%s/%s", "job file", 2,
				     primary_job_dir, JOB_FILENAME);
  if (job_file_name == NULL) {
    return -1;
  }
  if (copy_file(job_file, job_xml, job_file_name,
        S_IRUSR|S_IWUSR|S_IRGRP) != 0) {
    return -1;
  }
  fclose(stdin);
  fflush(LOGFILE);
  if (LOGFILE != stdout) {
    fclose(stdout);
  }
  fclose(stderr);
  if (chdir(primary_job_dir)) {
    fprintf(LOGFILE, "Failure to chdir to job dir - %s\n",
      strerror(errno));
    return -1;
  }

  execvp(args[0], args);
  fprintf(LOGFILE, "Failure to exec job initialization process - %s\n",
	  strerror(errno));
  return -1;
}
예제 #8
0
void test_init_job() {
  printf("\nTesting init job\n");
  if (seteuid(0) != 0) {
    printf("FAIL: seteuid to root failed - %s\n", strerror(errno));
    exit(1);
  }
  FILE* creds = fopen(TEST_ROOT "/creds.txt", "w");
  if (creds == NULL) {
    printf("FAIL: failed to create credentials file - %s\n", strerror(errno));
    exit(1);
  }
  if (fprintf(creds, "secret key\n") < 0) {
    printf("FAIL: fprintf failed - %s\n", strerror(errno));
    exit(1);
  }
  if (fclose(creds) != 0) {
    printf("FAIL: fclose failed - %s\n", strerror(errno));
    exit(1);
  }
  FILE* job_xml = fopen(TEST_ROOT "/job.xml", "w");
  if (job_xml == NULL) {
    printf("FAIL: failed to create job file - %s\n", strerror(errno));
    exit(1);
  }
  if (fprintf(job_xml, "<jobconf/>\n") < 0) {
    printf("FAIL: fprintf failed - %s\n", strerror(errno));
    exit(1);
  }
  if (fclose(job_xml) != 0) {
    printf("FAIL: fclose failed - %s\n", strerror(errno));
    exit(1);
  }
  if (seteuid(user_detail->pw_uid) != 0) {
    printf("FAIL: failed to seteuid back to user - %s\n", strerror(errno));
    exit(1);
  }
  fflush(stdout);
  fflush(stderr);
  pid_t child = fork();
  if (child == -1) {
    printf("FAIL: failed to fork process for init_job - %s\n", 
	   strerror(errno));
    exit(1);
  } else if (child == 0) {
    char *final_pgm[] = {"touch", "my-touch-file", 0};
    if (initialize_job(username, "job_4", TEST_ROOT "/creds.txt", final_pgm) != 0) {
      printf("FAIL: failed in child\n");
      exit(42);
    }
    // should never return
    exit(1);
  }
  int status = 0;
  if (waitpid(child, &status, 0) <= 0) {
    printf("FAIL: failed waiting for process %d - %s\n", child, 
	   strerror(errno));
    exit(1);
  }
  if (access(TEST_ROOT "/logs/userlogs/job_4", R_OK) != 0) {
    printf("FAIL: failed to create job log directory\n");
    exit(1);
  }
  char* job_dir = get_job_directory(TEST_ROOT "/local-1", username, "job_4");
  if (access(job_dir, R_OK) != 0) {
    printf("FAIL: failed to create job directory %s\n", job_dir);
    exit(1);
  }
  char buffer[100000];
  sprintf(buffer, "%s/jobToken", job_dir);
  if (access(buffer, R_OK) != 0) {
    printf("FAIL: failed to create credentials %s\n", buffer);
    exit(1);
  }
  sprintf(buffer, "%s/my-touch-file", job_dir);
  if (access(buffer, R_OK) != 0) {
    printf("FAIL: failed to create touch file %s\n", buffer);
    exit(1);
  }
  free(job_dir);
  job_dir = get_job_log_directory("logs","job_4");
  if (access(job_dir, R_OK) != 0) {
    printf("FAIL: failed to create job log directory %s\n", job_dir);
    exit(1);
  }
  free(job_dir);
}