/**
   * Submits local tasks
   *
   * @param session
   * @param job
   * @throws Exception
   */
  @Override
  public void submitJob(JobArea jobArea, Session session, ExecutableJob job) throws Exception {
    job.setTag(this.jobTag);
    job.setOwner(jobArea.getOwner());
    jobArea.createTag(job.getTag());
    // in the local submitter we directly access to the job area folder to avoid creating and then
    // copying local files
    final File jobLocalDir = new File(jobArea.getBasename(job.getTag()));

    // complete the replacements map with the information available in the sumbitter
    this.completeJobEnvironment(job, jobArea.getBasename(job.getTag()));

    // prepare the protocol buffer with the job data
    File pbFile = this.createJobDataPB(session, job);
    FileUtils.copyFileToDirectory(pbFile, jobLocalDir);

    // copy the wrapper script in the execution dir
    this.copyWrapperScript(job, jobLocalDir);

    // write constants script
    VariableHelper helper = new VariableHelper();
    helper.writeVariables(new File(jobLocalDir, constantsTemplate), job.getEnvironment());

    copyResourceFiles(job.getSourceConfig(), jobLocalDir);

    copyAutoOptions(job.getSourceConfig(), jobLocalDir, job.getEnvironment());

    copyArtifactsPbRequests(job.getSourceConfig(), this.environmentScriptFilename, jobLocalDir);

    // run pre-deployment scripts, if any
    runPreDeploymentScripts(job, jobLocalDir);

    // give execute permission to task scripts
    jobArea.grantExecutePermissions(job.getTag(), new String[] {this.wrapperScript});

    // execute the task
    logger.info(
        String.format(
            "Submitting job to local cluster at %s...",
            job.getTag(), jobLocalDir.getAbsolutePath()));
    Map<String, String> env = new HashMap<String, String>();
    env.put("JOB_DIR", jobLocalDir.getAbsolutePath());
    env.put("PATH", System.getenv("PATH"));
    logger.info("Output from the submission process:");
    logger.info(jobArea.execute(job.getTag(), this.wrapperScript, env));
  }