Esempio n. 1
0
  /**
   * This operations sets up some VIBE-specific information for the launcher, including the default
   * project installation directory.
   */
  @Override
  protected void setupItemInfo() {

    // Set the name and description of the Item
    setName("VIBE Launcher");
    setDescription("Run a VIBE simulation.");

    // Set the name of the home directory
    CAEBAT_ROOT = "/home/batsim/caebat";
    IPS_ROOT = "$IPS_ROOT";

    // Set up the necessary io services if they aren't already done.
    ioService = getIOService();
    if (ioService == null) {
      setIOService(new IOService());
      ioService = getIOService();
    }
    if (ioService.getReader("IPSReader") == null) {
      ioService.addReader(new IPSReader());
    }
    if (ioService.getWriter("IPSWriter") == null) {
      ioService.addWriter(new IPSWriter());
    }
    return;
  }
Esempio n. 2
0
  /**
   * Overrides process by setting the executable correctly and then forwarding later. Still calls
   * super.process(actionName) once the executable is set correctly for the workstation.conf file.
   *
   * @param actionName The name of the action.
   * @return The status of the action
   */
  @Override
  public FormStatus process(String actionName) {

    // Local Declarations
    String separator = System.getProperty("file.separator");
    IPSReader reader = (IPSReader) ioService.getReader("IPSReader");
    IPSWriter writer = (IPSWriter) ioService.getWriter("IPSWriter");
    DataComponent fileComponent = (DataComponent) form.getComponent(1);
    Entry inputFileEntry = fileComponent.retrieveEntry("Input File");
    Entry kvPairFileEntry = fileComponent.retrieveEntry("Use custom key-value pair file?");
    IFile inputFile = project.getFile(inputFileEntry.getValue());

    // Get the Run ID that may be used to locate the simulation files
    String runID = "";
    ArrayList<Entry> runIDMatches = reader.findAll(inputFile, "RUN_ID=.*");
    if (runIDMatches != null && !runIDMatches.isEmpty()) {
      runID = runIDMatches.get(0).getName().split("=")[1];
    }

    // Get the Case Name which may also be used to locate the simulation
    // files
    String caseName = "";
    ArrayList<Entry> caseNameMatches = reader.findAll(inputFile, "SIM_NAME=.*");
    if (caseNameMatches != null && !caseNameMatches.isEmpty()) {
      caseName = caseNameMatches.get(0).getName().split("=")[1];
    }
    // Determine if we need to use the Run ID or the Case Name to find the
    // files
    if (caseName.contains("${RUN_ID}")) {
      caseName = runID;
    }

    // Get the base path for the simulation files
    String dataDir = "";
    ArrayList<Entry> simRootMatches = reader.findAll(inputFile, "SIM_ROOT=.*");
    if (simRootMatches != null && !simRootMatches.isEmpty()) {
      dataDir = simRootMatches.get(0).getName().split("=")[1];
    }
    if (dataDir.endsWith("/$SIM_NAME")) {
      dataDir = dataDir.substring(0, dataDir.length() - 10);
    } else if (dataDir.endsWith("${SIM_NAME}")) {
      dataDir = dataDir.substring(0, dataDir.length() - 12);
    } else if (dataDir.endsWith(caseName)) {
      dataDir = dataDir.substring(0, dataDir.length() - (caseName.length() + 1));
    }

    // Get the input file directory for the simulation
    String inputDir = "";
    ArrayList<Entry> inputDirMatches = reader.findAll(inputFile, ".*INPUT_DIR.*");
    if (inputDirMatches != null && !inputDirMatches.isEmpty()) {
      inputDir = inputDirMatches.get(0).getName().split("=")[1];
    }

    // If we are supplying a new KV Pair file replace it in the input file
    update(fileComponent.retrieveEntry("Use custom key-value pair file?"));
    String setKVPerms = "";
    String backupKVFile = "";
    String mvKVPairFile = "";
    if (kvPairFileEntry.getValue() != "false") {
      String kvFileName = fileComponent.retrieveEntry("Key-value pair file").getValue();
      // writer.replace(inputFile, "input_keyvalue", kvFileName);
      setKVPerms = "chmod 775 " + kvFileName + " && ";
      backupKVFile = "mv input/input_keyvalue input/input_keyvalue.bak && ";
      mvKVPairFile = "mv " + kvFileName + " input/input_keyvalue && ";
    }

    // Pull some information from the form
    TableComponent hostTable = (TableComponent) form.getComponent(4);
    CAEBAT_ROOT = hostTable.getRow(0).get(2).getValue();

    // Set up the execution command
    String exportRoot = "export CAEBAT_ROOT=" + CAEBAT_ROOT + "/vibe/components && ";
    String copyCase = "cp -r " + dataDir + "/" + caseName + "/* . && ";
    String fixSIMROOT =
        "sed -i.bak 's?SIM_ROOT\\ *=\\ *.*?" + "SIM_ROOT\\ =\\ '`pwd`'?g' ${inputFile} && ";

    // The main execution of the simulation.
    String VIBEExec =
        "${installDir}ipsframework-code/install/bin/ips.py"
            + " -a --log=temp.log --platform="
            + CAEBAT_ROOT
            + "/vibe/examples/config/batsim.conf"
            + " --simulation=${inputFile}; ";
    fullExecCMD =
        exportRoot + copyCase + setKVPerms + backupKVFile + mvKVPairFile + fixSIMROOT + VIBEExec;

    // Setup the executable information
    setExecutable(getName(), getDescription(), this.fullExecCMD);

    return super.process(actionName);
  }