/**
   * 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;
  }
Example #2
0
  /**
   * 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;
  }
Example #3
0
  /*
   * (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;
            }
          }
        }
      }
    }
  }
Example #4
0
  /**
   * (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;
  }