예제 #1
0
파일: MOOSE.java 프로젝트: nickstanish/ice
  /**
   * This method just clears the Model Files DataComponent of its Entries so that we can populate it
   * with new Entries.
   */
  private void clearModelFiles() {

    ArrayList<String> toBeRemoved = new ArrayList<String>();
    for (Entry e : modelFiles.retrieveAllEntries()) {
      String name = e.getName();
      if (!"MOOSE-Based Application".equals(name) && !"Output File Name".equals(name)) {
        toBeRemoved.add(name);
      }
    }

    for (String e : toBeRemoved) {
      modelFiles.deleteEntry(e);
    }
  }
예제 #2
0
파일: MOOSE.java 프로젝트: nickstanish/ice
 /**
  * This private method takes the Postprocessor tree node and populates the postProcessorData
  * DataComponent.
  *
  * @param ppTree
  */
 private void setupPostprocessorData(TreeComposite ppTree) {
   postProcessorsData.clearEntries();
   for (int i = 0; i < ppTree.getNumberOfChildren(); i++) {
     Entry ppEntry =
         new Entry() {
           @Override
           public void setup() {
             allowedValueType = AllowedValueType.Discrete;
             allowedValues.add("yes");
             allowedValues.add("no");
             defaultValue = "no";
           }
         };
     ppEntry.setName(ppTree.getChildAtIndex(i).getName());
     ppEntry.setDescription("Select whether this Postprocessor should be displayed in real-time.");
     ppEntry.setId(i);
     postProcessorsData.addEntry(ppEntry);
   }
 }
  /**
   * Deletes the <code>Entry</code> (aka property or parameter) that is currently selected in the
   * {@link #tableViewer}. A reference to this <code>Entry</code> is stored as {@link
   * #selectedEntry} when selected in the <code>TableViewer</code>.
   */
  private void deleteParameter() {

    if (canDelete(selectedEntry)) {
      String entryName = selectedEntry.getName();
      // Find the data node that has the selected Entry. If the Entry is
      // found, remove it from the containing data node and stop.
      for (Component component : tree.getDataNodes()) {
        DataComponent dataNode = (DataComponent) component;
        if (dataNode.contains(entryName) && dataNode.retrieveEntry(entryName) == selectedEntry) {
          dataNode.deleteEntry(entryName);
          break;
        }
      }
    }

    return;
  }
  /**
   * Adds a new <code>Entry</code> (aka property or parameter) to the active or first available data
   * node in the {@link #tree}.
   */
  private void addParameter() {

    // Get either the active data node or the first available data node.
    DataComponent dataNode = canAdd(tree);

    // If there is a data node, add a new Entry to it.
    if (dataNode != null && !dataNode.contains("New parameter")) {
      // Create an Entry with a BasicEntryContentProvider.
      Entry entry = new Entry(new BasicEntryContentProvider());
      // Set the Entry's initial properties.
      entry.setName("new_parameter");
      entry.setDescription("");
      entry.setTag(entry.getName());
      entry.setRequired(false);
      entry.setValue("");
      // Add the Entry to the data node.
      dataNode.addEntry(entry);
    }

    return;
  }
예제 #5
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);
  }
예제 #6
0
파일: MOOSE.java 프로젝트: nickstanish/ice
  /**
   * This method searches the Model input tree and locates all file Entries and loads them on the
   * Model File DataComponent.
   */
  protected void loadFileEntries() {
    // Walk the tree and get all Entries that may represent a file
    BreadthFirstTreeCompositeIterator iter = new BreadthFirstTreeCompositeIterator(modelTree);
    while (iter.hasNext()) {
      TreeComposite child = iter.next();

      // Make sure we have a valid DataComponent
      if (child.getActiveDataNode() != null && child.isActive()) {
        DataComponent data = (DataComponent) child.getActiveDataNode();
        for (Entry e : data.retrieveAllEntries()) {

          // If the Entry's tag is "false" it is a commented out
          // parameter.
          if (!"false".equals(e.getTag())
              && e.getValue() != null
              && !e.getValue().isEmpty()
              && (e.getName() + " = " + e.getValue())
                  .matches(mooseLauncher.getFileDependenciesSearchString())) {

            Entry clonedEntry = (Entry) e.clone();

            // If this Entry does not have a very descriptive
            // name
            // we should reset its name to the block it belongs
            // to
            if ("file".equals(clonedEntry.getName().toLowerCase())
                || "data_file".equals(clonedEntry.getName().toLowerCase())) {
              clonedEntry.setName(child.getName());
            }

            if (!clonedEntry.getValueType().equals(AllowedValueType.File)) {
              mooseModel.convertToFileEntry(clonedEntry);
            }

            // Setup allowed values correctly
            String extension =
                FilenameUtils.getExtension(
                    project.getFile(clonedEntry.getValue()).getLocation().toOSString());

            // Create a new content provider with the new file
            // in the allowed values list
            IEntryContentProvider prov = new BasicEntryContentProvider();
            ArrayList<String> valueList = clonedEntry.getAllowedValues();

            for (String file : getProjectFileNames(extension)) {
              if (!valueList.contains(file)) {
                valueList.add(file);
              }
            }
            prov.setAllowedValueType(AllowedValueType.File);

            // Finish setting the allowed values and default
            // value
            prov.setAllowedValues(valueList);

            // Set the new provider
            clonedEntry.setContentProvider(prov);

            // Set the value
            clonedEntry.setValue(e.getValue());

            fileEntryTreeMapping.put(clonedEntry.getName(), child);

            clonedEntry.register(this);

            // Add it to the list of model files.
            modelFiles.addEntry(clonedEntry);
          }
        }
      }
    }

    return;
  }
예제 #7
0
파일: MOOSE.java 프로젝트: nickstanish/ice
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.ice.item.Item#update(org.eclipse.ice.datastructures.ICEObject
   * .IUpdateable)
   */
  @Override
  public void update(IUpdateable updateable) {

    if (updateable instanceof ResourceComponent) {
      ResourceComponent comp = (ResourceComponent) updateable;
      ResourceComponent ourComp = (ResourceComponent) form.getComponent(3);

      ArrayList<String> names = new ArrayList<String>();

      // Get a list of all our Resource Names:
      for (ICEResource r : ourComp.getResources()) {
        names.add(r.getName());
      }

      for (ICEResource r : comp.getResources()) {
        if (!names.contains(r.getName())) {
          logger.info("Adding Resource to Moose: " + r.getName());
          ourComp.add(r);
        }
      }

    } else if (updateable instanceof TreeComposite) {
      // If this is a tree composite we should reset our variables
      Thread varThread =
          new Thread(
              new Runnable() {

                @Override
                public void run() {
                  new MOOSEFileHandler().setupVariables(modelTree);
                  new MOOSEFileHandler().setupAuxVariables(modelTree);
                }
              });
      varThread.start();

    } else if (updateable instanceof Entry) {

      Entry entry = (Entry) updateable;

      // If we get here, then we have a file Entry that
      // has been changed on the modelFiles component
      // and we need to sync up the tree with it.

      // Grab the DataComponent
      if (fileEntryTreeMapping.containsKey(entry.getName())) {
        DataComponent data =
            (DataComponent) fileEntryTreeMapping.get(entry.getName()).getDataNodes().get(0);

        // If not null, loop over the Entries til we find
        // the file Entry.
        if (data != null) {
          for (Entry e : data.retrieveAllEntries()) {

            // If the Entry's tag is "false" it is a commented
            // out
            // parameter.
            if (!"false".equals(e.getTag())
                && e.getValue() != null
                && !e.getValue().isEmpty()
                && (e.getName() + " = " + e.getValue())
                    .matches(mooseLauncher.getFileDependenciesSearchString())) {

              // Set the value of the tree's file entry.
              e.setValue(entry.getValue());
              break;
            }
          }
        }
      }
    }
  }
예제 #8
0
파일: MOOSE.java 프로젝트: nickstanish/ice
  /**
   * (non-Javadoc)
   *
   * @see org.eclipse.ice.item.Item#process(java.lang.String)
   */
  @Override
  public FormStatus process(String actionName) {
    // Local Declarations
    FormStatus retStatus = FormStatus.InfoError;

    // Set our outputFile as the MooseLauncher's output file
    // so we can see the streaming output
    outputFile = mooseLauncher.getOutputFile();

    // Parse the action name
    if ("Launch the Job".equals(actionName)) {

      // FIXME WE NEED TO DO A CHECK FOR ALL THE REQUIRED BLOCKS!!!!

      // Add the ICEUpdater tree block to Outputs
      TreeComposite outputs = getTreeByName("Outputs");
      TreeComposite postProcessors = getTreeByName("Postprocessors");

      // First check to see if we have any post processors to
      // watch for.
      if (postProcessors.isActive() && postProcessors.getNumberOfChildren() > 0) {

        // If we do, we should add an ICEUpdater
        boolean iNeedUpdater = true;

        // If we already have one, then we shouldn't add another one
        for (int i = 0; i < outputs.getNumberOfChildren(); i++) {
          if ("ICEUpdater".equals(outputs.getChildAtIndex(i).getName())) {

            // But if the current one is not configured correctly
            // then we should add a new one, Here we make sure the
            // Item Id is correct...
            TreeComposite iceUpdater = outputs.getChildAtIndex(i);
            DataComponent data = (DataComponent) iceUpdater.getDataNodes().get(0);
            Entry itemIdEntry = data.retrieveEntry("item_id");
            if (Integer.valueOf(itemIdEntry.getValue()) != getId()) {
              itemIdEntry.setValue(String.valueOf(getId()));
            }

            // Now we have a valid ICEUpdater, so we don't need
            // to create a new one.
            iNeedUpdater = false;
            break;
          }
        }

        if (iNeedUpdater) {
          for (int i = 0; i < outputs.getChildExemplars().size(); i++) {
            if ("ICEUpdater".equals(outputs.getChildExemplars().get(i).getName())) {
              TreeComposite updater = (TreeComposite) outputs.getChildExemplars().get(i).clone();
              outputs.setNextChild(updater);

              DataComponent data = (DataComponent) updater.getDataNodes().get(0);
              data.retrieveEntry("item_id").setValue(String.valueOf(getId()));
              data.retrieveEntry("url")
                  .setValue(
                      "http://localhost:"
                          + System.getProperty("org.eclipse.equinox.http.jetty.http.port")
                          + "/ice/update");
              updater.setActive(true);
              updater.setActiveDataNode(data);
              break;
            }
          }
        }
      }

      // Get a reference to the Launchers files component
      DataComponent launcherFiles = (DataComponent) mooseLauncher.getForm().getComponent(1);

      // Grab the file name the user has specified for the input file
      String fileName = modelFiles.retrieveEntry("Output File Name").getValue();

      // Write the Moose file if it doesn't exist
      retStatus = mooseModel.process("Write MOOSE File");
      if (!retStatus.equals(FormStatus.Processed)) {
        return retStatus;
      }

      // Set the value of the input file to the user-specified
      // file name
      launcherFiles.retrieveEntry("Input File").setValue(fileName);

      // Update the MooseLauncher's set of input files...
      mooseLauncher.update(launcherFiles.retrieveEntry("Input File"));
      for (Entry e : modelFiles.retrieveAllEntries()) {
        Entry launcherFile = launcherFiles.retrieveEntry(e.getName());
        if (launcherFile != null) {
          launcherFile.setValue(e.getValue());
        }
      }

      // Get the application URI
      URI appUri = URI.create(modelFiles.retrieveEntry("MOOSE-Based Application").getValue());

      // Check if we're local or remote
      if ("ssh".equals(appUri.getScheme())) {

        mooseLauncher.setExecutable(
            Paths.get(appUri.getRawPath()).getFileName().toString(),
            "",
            appUri.getRawPath() + " -i ${inputFile} --no-color");

        // Setup the hosts table to use the remote host
        TableComponent hostsTable =
            (TableComponent) mooseLauncher.getForm().getComponent(JobLauncherForm.parallelId + 1);
        IRemoteConnection remoteConnection = mooseLauncher.getRemoteConnection(appUri.getHost());
        String hostname =
            remoteConnection.getService(IRemoteConnectionHostService.class).getHostname();
        int index = hostsTable.addRow();
        ArrayList<Entry> row = hostsTable.getRow(index);
        ArrayList<Integer> selected = new ArrayList<Integer>();
        selected.add(new Integer(index));
        row.get(0).setValue(hostname);
        hostsTable.setSelectedRows(selected);

      } else {

        // Set the executable string
        mooseLauncher.setExecutable(
            new File(appUri).getName(), "", appUri.getPath() + " -i ${inputFile} --no-color");
      }

      // Register as a listener of the resource component
      // so we can add the resources to our resource component
      ((ResourceComponent) mooseLauncher.getForm().getComponent(JobLauncherForm.outputId))
          .register(this);

      // Launch the Moose application
      retStatus = mooseLauncher.process(actionName);

    } else if ("Write MOOSE File".equals(actionName)) {
      // Simply pass this along to the Model
      retStatus = mooseModel.process(actionName);
    }

    // Set the status flag.
    status = retStatus;

    // Keep the status in sync
    if (status.equals(FormStatus.Processing)) {
      Thread statusThread =
          new Thread(
              new Runnable() {
                @Override
                public void run() {
                  while (!status.equals(FormStatus.Processed)) {
                    // Sleep for a bit
                    Thread.currentThread();
                    try {
                      Thread.sleep(100);
                    } catch (InterruptedException e) {
                      logger.error(getClass().getName() + " Exception!", e);
                    }

                    // Set the status
                    status = mooseLauncher.getStatus();
                  }

                  return;
                }
              });

      statusThread.start();
    }
    return retStatus;
  }
 /**
  * Gets whether or not the specified <code>Entry</code> (aka property or parameter) can be deleted
  * from its containing <code>DataComponent</code> or data node in the {@link #tree}. Any parameter
  * can be deleted.
  *
  * @param entry The property or parameter that is a candidate for deletion.
  * @return True if the entry can be deleted, false otherwise.
  */
 private boolean canDelete(Entry entry) {
   return (entry != null && !entry.isRequired());
 }
예제 #10
0
  /**
   * This operation creates a new JobLauncher and writes it to disk if the action name is equal to
   * "Create new Job Launcher" and it forwards the call to the Item base class if it is equal to
   * something else.
   *
   * @param actionName
   *     <p>The name of the action to perform.
   * @return
   *     <p>The status.
   */
  @Override
  public FormStatus process(String actionName) {

    // Local Declarations
    FormStatus status = FormStatus.InfoError;

    // Check the action
    if ("Create a Job Launcher".equals(actionName)) {

      // Local declarations within this scope:
      DataComponent exeInfo = null;
      DataComponent threadOps = null;
      TableComponent hostnames = null;
      Entry entry = null;

      // Create a new JobLauncher
      JobLauncher launcher = new JobLauncher(project);

      // Return status if form is not setup.
      if (form == null) {
        return status;
      }

      // Get the components
      exeInfo = (DataComponent) form.getComponents().get(0);
      threadOps = (DataComponent) form.getComponents().get(1);
      hostnames = (TableComponent) form.getComponents().get(2);

      // Set the launcher information - fills out the form Name,
      // description, and execution name + parameters
      ArrayList<Entry> execEntries = exeInfo.retrieveAllEntries();
      String execName = execEntries.get(0).getValue();
      String execDesc = "This operation will execute " + execEntries.get(0).getValue();
      String executable = exeInfo.retrieveAllEntries().get(1).getValue();
      // Set the executable on the launcher
      launcher.setExecutable(execName, execDesc, executable);

      // Setup the launcher -> it will setup the form
      launcher.setName(exeInfo.retrieveAllEntries().get(0).getValue());
      launcher.setDescription(
          "This operation will execute " + exeInfo.retrieveAllEntries().get(0).getValue());

      logger.info("Creating " + launcher.getForm().getName() + " profile.");

      // Setup hostnames
      for (int i = 0; i < hostnames.getRowIds().size(); i++) {
        launcher.addHost(
            hostnames.getRow(i).get(0).getValue(),
            hostnames.getRow(i).get(1).getValue(),
            hostnames.getRow(i).get(2).getValue());
      }
      // setup mpi and open mp

      // Enable or disable OpenMP
      // The first entry represents the T/F statement for enabling or
      // disabling
      // value. The next entry are the values and limitations.

      if ("Yes".equals(threadOps.retrieveAllEntries().get(0).getValue())) {
        entry = threadOps.retrieveAllEntries().get(1);
        launcher.enableOpenMP(
            Integer.parseInt(entry.getAllowedValues().get(0)),
            Integer.parseInt(entry.getAllowedValues().get(1)),
            Integer.parseInt(entry.getValue()));
      } else {
        launcher.disableOpenMP();
      }

      // Enable or disable MPI
      // The first entry represents the T/F statement for enabling or
      // disabling
      // value. The next entry are the values and limitations.
      if ("Yes".equals(threadOps.retrieveAllEntries().get(2).getValue())) {
        entry = threadOps.retrieveAllEntries().get(3);
        launcher.enableMPI(
            Integer.parseInt(entry.getAllowedValues().get(0)),
            Integer.parseInt(entry.getAllowedValues().get(1)),
            Integer.parseInt(entry.getValue()));
      } else {
        launcher.disableMPI();
      }

      // Enable or disable TBB
      // The first entry represents the T/F statement for enabling or
      // disabling
      // value. The next entry are the values and limitations.
      if ("Yes".equals(threadOps.retrieveAllEntries().get(4).getValue())) {
        entry = threadOps.retrieveAllEntries().get(5);
        launcher.enableTBB(
            Integer.parseInt(entry.getAllowedValues().get(0)),
            Integer.parseInt(entry.getAllowedValues().get(1)),
            Integer.parseInt(entry.getValue()));
      } else {
        launcher.disableTBB();
      }

      // Set the Launcher's builder name so that it can be loaded
      // correctly.
      launcher.setItemBuilderName(launcher.getName());

      // Check for the jobProfiles folder and create it if it doesn't
      // exist
      IFolder jobProfileFolder = project.getFolder("jobProfiles");
      if (!jobProfileFolder.exists()) {
        // Most likely the folder already exists, but we have to create
        // it if it does not
        try {
          jobProfileFolder.create(true, true, null);
        } catch (CoreException e) {
          logger.error(getClass().getName() + " Exception!", e);
        }
      }

      // Persist to XML JobLauncher.
      IFile file = jobProfileFolder.getFile(launcher.getName().replaceAll("\\s+", "_") + ".xml");
      // Dump the launcher
      writeLauncherItemToFile(launcher, file);

      // Update the status
      status = FormStatus.Processed;
    } else {
      // If any other action is requested, let the super class deal with
      // it.
      return super.process(actionName);
    }

    logger.info("JobProfile Message: " + "Successfully serialized the JobLauncher!");

    return status;
  }