/**
 * Copyright 2017 Institute of Computing Technology, Chinese Academy of Sciences.
 * Licensed under the terms of the Apache 2.0 license.
 * Please see LICENSE file in the project root for terms
 */
package eml.studio.server.util;

import eml.studio.client.ui.widget.command.CommandParseException;
import eml.studio.client.ui.widget.command.CommandParser;
import eml.studio.client.ui.widget.command.Commander;
import eml.studio.client.ui.widget.command.FileHolder;

/**
 * TODO: combine with RunShellGenerator using uniq generate(),
 * which automatically determine local or distributed
 */
public class DistributedRunShellGenerator extends RunShellGenerator {
  @Override
  public String generate(String cmdLine) throws CommandParseException {
    Commander commander = CommandParser.parse(cmdLine);

    StringBuffer sb = new StringBuffer("");
    sb.append("#! /bin/bash\n" + "#distribute\n"
            +"echo +++++++++++++Log information+++++++++++\n" +
            "source /etc/profile\n"
            +"echo $PATH \n"
            + "exit_code=0\n\n" + "echo make action directory on hdfs ... \n"
            + "hdfs dfs -mkdir $3\n\n" + "echo download libaries ...\n"
            + "hdfs dfs -get $2/* 1>>stdout 2>>stderr\n"
            + "#((exit_code=exit_code|$?))\n" + "chmod -R +x *\n\n");

    int idx = 3;
    for (FileHolder fp : commander.getOutFileHolders()) {
      idx++;
      sb.append("echo making file moduleId directory ${" + idx + "}...\n");
      sb.append("hdfs dfs -mkdir ${" + idx + "} 1>>stdout 2>>stderr\n");
    }

    sb.append("source /etc/profile\n");
    sb.append("\necho execute command line\n"
        + "echo $1 1>>stdout 2>>stderr\n"
        + "eval $1 1>>stdout 2>>stderr\n"
        + "((exit_code=exit_code|$?))\n\n");

    sb.append("if [ \"$exit_code\" -ne \"0\" ]\n" + "then\n"
        + "        hdfs dfs -put stderr $3\n"
        + "        hdfs dfs -put stdout $3\n" + "        exit $exit_code\n"
        + "fi\n\n" + "echo upload output files to hdfs\n");

    idx = 3;
    for (FileHolder fp : commander.getOutFileHolders()) {
      idx++;
      // ${idx}表示文件模块的路径
      sb.append("describe ${" + idx + "##*/} > ${" + idx
          + "##*/}_describe.xml\n" + "hdfs dfs -put ${" + idx
          + "##*/}_describe.xml ${" + idx
          + "}/describe.xml 1>>stdout 2>>stderr\n");
    }

    sb.append("hdfs dfs -put stderr $3\n" + "hdfs dfs -put stdout $3\n\n"
        + "hdfs dfs -chmod -R 777 $3\n\n"
        + "exit $exit_code");
    

    // System.out.print( sb.toString() );
    return sb.toString();
  }
}

@@ -2006,338 +2006,8 @@
 );%0A%0A
-    idx = 3;%0A    for (FileHolder fp : commander.getOutFileHolders()) %7B%0A      idx++;%0A      // $%7Bidx%7D%E8%A1%A8%E7%A4%BA%E6%96%87%E4%BB%B6%E6%A8%A1%E5%9D%97%E7%9A%84%E8%B7%AF%E5%BE%84%0A      sb.append(%22describe $%7B%22 + idx + %22##*/%7D %3E $%7B%22 + idx%0A          + %22##*/%7D_describe.xml%5Cn%22 + %22hdfs dfs -put $%7B%22 + idx%0A          + %22##*/%7D_describe.xml $%7B%22 + idx%0A          + %22%7D/describe.xml 1%3E%3Estdout 2%3E%3Estderr%5Cn%22);%0A    %7D%0A%0A
     

Remove describe.xml copy stage in run shell. The describe.xml is useless.