Exemple #1
0
 /**
  * this function update the number of extra input file accorrdingly with the current number of
  * files it deletes or adds extra input files
  */
 private void _updateUploadFileNumber(int numFiles) throws IllegalActionException {
   int currentNumberOfFile = 0;
   try {
     currentNumberOfFile = _getUploadFileNumber();
   } catch (IllegalActionException e) {
     throw new IllegalActionException(this, "Unable to load opal paraters:" + e.getMessage());
   }
   int diff = numFiles - currentNumberOfFile;
   if (diff > 0) {
     // we have to add diff number of input files
     for (int i = 0; i < diff; i++) {
       try {
         (new FilePortParameter(this, "inputFile" + (currentNumberOfFile + 1 + i) + "Dynamic"))
             .setContainer(this);
       } catch (NameDuplicationException e) {
         throw new IllegalActionException(this, "There is a name duplication: " + e.getMessage());
       } // catch
     } // for
   } else if (diff < 0) {
     // we have to delete number of files
     for (int i = 0; i < Math.abs(diff); i++) {
       String fileName = "inputFile" + (currentNumberOfFile - i) + "Dynamic";
       try {
         FilePortParameter fileToBeDeleted =
             (FilePortParameter) this.getAttribute(fileName, FilePortParameter.class);
         fileToBeDeleted.getPort().setContainer(null);
         fileToBeDeleted.setContainer(null);
       } catch (NameDuplicationException e) {
         throw new IllegalActionException(
             this, "Unable to delete the input file " + fileName + ": " + e.getMessage());
       } // catch
     } // for
   } // if
   // diff == 0 don't do anything
 } // _updateUploadFileNumber
Exemple #2
0
 /**
  * This method instantiates the parameters needed for the submission of a Opal job without
  * metadata
  */
 private void _createSimpleSubmission(AppMetadata app) throws IllegalActionException {
   _emptyParamtersArray();
   // TODO delete this _interfaceParameters is useless
   log.info("Creating simple submission form. For service URL: " + app.getURL());
   try {
     (new StringParameter(this, "commandLine")).setContainer(this);
     (new StringParameter(this, "cpuNumber")).setContainer(this);
     // let's try to get the number of files
     int numFiles;
     try {
       numFiles = Integer.parseInt(numberFiles.stringValue());
     } catch (NumberFormatException e) {
       throw new IllegalActionException(
           this, "The numberFiles parameter is not a valid integer, please correct the value");
     }
     _updateUploadFileNumber(numFiles);
   } catch (NameDuplicationException e) {
     log.error("The parameter could not be instantiated. Error message: " + e.getMessage(), e);
   }
 }
  /**
   * Description of the Method
   *
   * @exception IllegalActionException Description of the Exception
   */
  private void buildResultTree(EntityLibrary newRoot) throws IllegalActionException {
    if (isDebugging) log.debug("buildResultTree()");

    // iterate over each treepath in results
    for (int i = 0; i < results.size(); i++) {

      try {

        TreePath currentPath = results.getTreePath(i);
        if (isDebugging) log.debug(currentPath);

        EntityLibrary treeCurrent = newRoot;
        for (int j = 1; j < currentPath.getPathCount(); j++) {

          NamedObj pathCurrent = (NamedObj) currentPath.getPathComponent(j);

          if (pathCurrent instanceof EntityLibrary) {

            List<EntityLibrary> children = treeCurrent.entityList(EntityLibrary.class);

            boolean alreadyThere = false;
            for (EntityLibrary child : children) {
              if (isDebugging) log.debug(child.getName());
              if (child.getName().equals(pathCurrent.getName())) {
                // this EntityLibrary is already there
                treeCurrent = child;
                alreadyThere = true;
                break;
              }
            }
            if (!alreadyThere) {
              // create it
              EntityLibrary newEntity = copyEntityLibrary((EntityLibrary) pathCurrent);
              setContainer(treeCurrent, newEntity);
              treeCurrent = newEntity;
            }

          } else {
            List<NamedObj> children = treeCurrent.entityList(NamedObj.class);

            boolean alreadyThere = false;
            for (NamedObj child : children) {
              if (child.getName().equals(pathCurrent.getName())) {
                // this NamedObj is already there
                alreadyThere = true;
                break;
              }
            }
            if (!alreadyThere) {
              // create it
              NamedObj newEntity = cloneEntity((NamedObj) pathCurrent);
              setContainer(treeCurrent, newEntity);
              // Leaf node, all done
              break;
            }
          }
        }

      } catch (IllegalActionException iae) {
        throw new IllegalActionException("cannot build search result tree: " + iae);
      } catch (NameDuplicationException nde) {
        log.error("EXCEPTION CAUGHT: " + nde.getMessage());
      } catch (Exception e) {
        log.error("EXCEPTION CAUGHT: " + e.getMessage());
      }
    } // end for loop
  }
  /**
   * If the argument is true, make the port an output port. If the argument is false, make the port
   * not an output port. In addition, if the container is an instance of Refinement, and the
   * argument is true, find the corresponding port of the controller and make it an input and not an
   * output. This makes it possible for the controller to see the outputs of the refinements. This
   * method overrides the base class to make the same change on the mirror ports in the controller
   * and state refinments. This method invalidates the schedule and resolved types of the director
   * of the container, if there is one. It is write-synchronized on the workspace, and increments
   * the version of the workspace.
   *
   * @param isOutput True to make the port an output.
   * @exception IllegalActionException If changing the port status is not permitted.
   */
  public void setOutput(boolean isOutput) throws IllegalActionException {
    boolean disableStatus = _mirrorDisable;

    // check first that this isn't an input sibling port,
    // if it is then it *cannot* be set as an output too
    if (_hasSibling && isInput() && !isOutput()) {
      if (isOutput) {
        throw new InternalErrorException(
            "TransitionRefinementPort.setOutput:"
                + " cannot set input sibling port to be an output");
      } else {
        return;
      }
    }

    try {
      _workspace.getWriteAccess();

      if (_mirrorDisable || (getContainer() == null)) {
        // Have already called the super class.
        // This time, process the request.
        super.setOutput(isOutput);

        // now create a sibling if we
        // don't otherwise have one
        if (!_hasSibling && isOutput) {
          try {
            TransitionRefinement container = (TransitionRefinement) getContainer();
            TransitionRefinementPort sibling =
                new TransitionRefinementPort(container, getName() + "_in");

            sibling._hasSibling = true;
            sibling._mirrorDisable = true;

            // set attributes of sibling
            sibling.setInput(true);
            sibling.setMultiport(isMultiport());

            sibling._mirrorDisable = false;

            // link the port relation should already exist
            // from this port's creation in newPort()
            String relationName = getName() + "Relation";
            ModalModel model = (ModalModel) container.getContainer();
            Relation relation = model.getRelation(relationName);

            if (relation != null) {
              sibling.link(relation);
            }

            _hasSibling = true;
          } catch (IllegalActionException ex) {
            throw new InternalErrorException(
                "TransitionRefinementPort.setOutput: Internal error: " + ex.getMessage());
          } catch (NameDuplicationException ex) {
            throw new InternalErrorException(
                "TransitionRefinementPort.setOutput: Internal error: " + ex.getMessage());
          }
        }
      } else {
        _mirrorDisable = true;

        boolean success = false;
        Nameable container = getContainer();

        if (container != null) {
          Nameable modal = container.getContainer();

          if (modal instanceof ModalModel) {
            Port port = ((ModalModel) modal).getPort(getName());

            if (port instanceof IOPort) {
              ((IOPort) port).setOutput(isOutput);
              success = true;
            }
          }
        }

        if (!success) {
          super.setOutput(isOutput);
        }
      }
    } finally {
      _mirrorDisable = disableStatus;
      _workspace.doneWriting();
    }
  }
Exemple #5
0
  /**
   * this function adds all the parameters necessary to have the documentation of the OpalClient
   * abviously this documentation is fetch from the remote server
   */
  private void _addDocumentation(AppMetadata app) throws IllegalActionException {
    // let's get the variable we need
    Attribute documentation = this.getAttribute("KeplerDocumentation");
    if (documentation == null)
      throw new IllegalActionException(
          this, "Unable to set the custom documentation (KeplerDocumentation not present).");
    Attribute userDoc = documentation.getAttribute("userLevelDocumentation");
    if (userDoc == null)
      throw new IllegalActionException(
          this, "Unable to set the custom documentation (userLevelDocumentation not present).");
    // -- we have to delete all the documentation that is already there
    // before updating it
    List tempList = documentation.attributeList();
    Attribute[] paramArray = (Attribute[]) tempList.toArray(new Attribute[tempList.size()]);
    for (int i = 0; i < paramArray.length; i++) {
      try {
        if (paramArray[i].getName().startsWith("prop:")
            || paramArray[i].getName().startsWith("port:output")
            || paramArray[i].getName().startsWith("port:baseUrl"))
          // let's remove the parameters
          paramArray[i].setContainer(null);
      } catch (NameDuplicationException e) {
        log.error(
            "The parameter could not be deleted from the documentation. Error message: "
                + e.getMessage());
        throw new IllegalActionException(
            this,
            "Error resetting the ducumentation, there is a duplicated name: " + e.getMessage());
      }
    }
    // After deleting we can finally set the documentation
    String stringDoc = _docHead;
    // let's set the general documentaion
    if (app.getUsage() != null) stringDoc += "<p>" + app.getUsage() + "</p>";
    if (app.getInfo() != null) {
      String[] infos = app.getInfo();
      for (int i = 0; i < infos.length; i++) stringDoc += "<pre>" + forXML(infos[i]) + "</pre>";
    } // if
    log.debug("the stringDoc is: " + stringDoc);
    ((ConfigurableAttribute) userDoc).setExpression(stringDoc);

    // -- let's set the documentation for the various properties --
    // some properties are always there... hence also the documentation
    // should be always there
    try {
      ((ConfigurableAttribute) userDoc).value();
      ConfigurableAttribute parameterDoc = new ConfigurableAttribute(documentation, "port:output");
      parameterDoc.setExpression(
          "It returns a list of Strings, containing the URL of the output files");
      parameterDoc = new ConfigurableAttribute(documentation, "port:baseUrl");
      parameterDoc.setExpression(
          "The base URL containing the working directory of the running jobs");
      parameterDoc = new ConfigurableAttribute(documentation, "prop:serviceURL");
      parameterDoc.setExpression("The URL of the Opal service that you want to execute");
      parameterDoc = new ConfigurableAttribute(documentation, "prop:numberOfExtraInputFiles");
      parameterDoc.setExpression(
          "The number of extra input files that are needed to execture the application");
      // parameterDoc = new ConfigurableAttribute(documentation,
      // "prop:methods");
      // parameterDoc.setExpression("Not implemented yet.");
    } catch (NameDuplicationException e) {
      log.error("The parameter could not be instantiated. Error message: " + e.getMessage());
      throw new IllegalActionException(
          this, "Error building the ducumentation, there is a duplicated name: " + e.getMessage());
    } catch (IOException e) {
      log.error("There is an error while setting the general documentation: " + e.getMessage());
    }
    // we have to list the documentation for every parameters
    if (app.isArgMetadataEnable()) {
      Group[] group = app.getGroups();
      try {
        if (group != null) {
          for (int i = 0; i < group.length; i++) {
            // first the parameters
            ArgParam[] argParams = group[i].getArgParams();
            if (argParams != null) {
              for (int paramCount = 0; paramCount < argParams.length; paramCount++) {
                ConfigurableAttribute parameterDoc =
                    new ConfigurableAttribute(
                        documentation, "prop:" + argParams[paramCount].getId());
                parameterDoc.setExpression(forXML(argParams[paramCount].getTextDesc()));
              } // for argParam
            } // argParams
            // and then the flags
            ArgFlag[] argFlags = group[i].getArgFlags();
            if (argFlags != null) {
              for (int paramCount = 0; paramCount < argFlags.length; paramCount++) {
                ConfigurableAttribute parameterDoc =
                    new ConfigurableAttribute(
                        documentation, "prop:" + argFlags[paramCount].getId());
                parameterDoc.setExpression(forXML(argFlags[paramCount].getTextDesc()));
                log.info(
                    "The parameter "
                        + argFlags[paramCount].getId()
                        + " has the following doc: "
                        + parameterDoc.value());
                parameterDoc.validate();
              }
            } // argFlags
          }
        } // group
      } catch (NameDuplicationException e) {
        log.error("The parameter could not be instantiated. Error message: " + e.getMessage());
        throw new IllegalActionException(
            this,
            "Error building the ducumentation, there is a duplicated name: " + e.getMessage());
      } catch (IOException e) {
        log.error(
            "There is an error while setting the documentation of an element with messge: "
                + e.getMessage());
      }
    } // if we have metadata
    else {
      // if we don't have metadata we document the standard parameters
      try {
        ConfigurableAttribute parameterDoc =
            new ConfigurableAttribute(documentation, "prop:commandLine");
        parameterDoc.setExpression(
            "Insert the command line you want to execute (without the application name)");
        parameterDoc = new ConfigurableAttribute(documentation, "prop:cpuNumber");
        parameterDoc.setExpression("If it is a parallel application insert the CPU number");
        parameterDoc = new ConfigurableAttribute(documentation, "prop:inputFile");
        parameterDoc.setExpression("Select an input file");
      } catch (NameDuplicationException e) {
        log.error("The parameter could not be instantiated. Error message: " + e.getMessage());
        throw new IllegalActionException(
            this,
            "Error building the ducumentation, there is a duplicated name: " + e.getMessage());
      }
    }
  } // _addDocumentation
Exemple #6
0
  /**
   * this function instantiate all the parameter necessary to display an advanced submission form
   * for the current selected opal service
   */
  private void _createSubmission(AppMetadata app) throws IllegalActionException {
    _emptyParamtersArray();
    log.info("Creating complex submission form. For service URL: " + app.getURL());
    try {
      Group[] group = app.getGroups();
      ArrayList tempParam = new ArrayList();
      if (group != null) {
        for (int i = 0; i < group.length; i++) {
          // first the parameters
          ArgParam[] argParams = group[i].getArgParams();
          if (argParams != null) {
            for (int paramCount = 0; paramCount < argParams.length; paramCount++) {
              if (argParams[paramCount].getType().equals("FILE")
                  && argParams[paramCount].getIoType().equals("INPUT")) {
                // This is an input file box
                FilePortParameter param =
                    new FilePortParameter(this, argParams[paramCount].getId());
                if (argParams[paramCount].getSelectedValue() != null)
                  // setting the default value
                  param.setExpression(argParams[paramCount].getSelectedValue());
                tempParam.add(param);
              } else if (argParams[paramCount].getValues() != null) {
                String[] choices = argParams[paramCount].getValues();
                // this is a multiple choices
                StringParameter param = new StringParameter(this, argParams[paramCount].getId());
                for (int z = 0; z < choices.length; z++) param.addChoice(choices[z]);
                if (argParams[paramCount].getSelectedValue() != null)
                  // setting the default value
                  param.setExpression(argParams[paramCount].getSelectedValue());
                tempParam.add(param);
              } else {
                // this is a string
                StringParameter param = new StringParameter(this, argParams[paramCount].getId());
                if (argParams[paramCount].getSelectedValue() != null)
                  // setting the default value
                  param.setExpression(argParams[paramCount].getSelectedValue());
                tempParam.add(param);
              } // else
            } // for argParam
          } // argParams
          // and then the flags
          ArgFlag[] argFlags = group[i].getArgFlags();
          if (argFlags != null) {
            for (int paramCount = 0; paramCount < argFlags.length; paramCount++) {
              Parameter check = null;
              if (argFlags[paramCount].isSelected())
                check = new Parameter(this, argFlags[paramCount].getId(), BooleanToken.TRUE);
              else check = new Parameter(this, argFlags[paramCount].getId(), BooleanToken.FALSE);
              check.setTypeEquals(BaseType.BOOLEAN);
              tempParam.add(check);
            }
          } // argFlags
        }
      } // group
      // set the numberFiles to 0
      StringParameter param = (StringParameter) this.getAttribute("numberFiles");
      if (param != null) param.setToken(new StringToken("0"));

      // not needed anymore delete the tempParam
      // _interfaceParameters = (Parameter []) tempParam.toArray(new
      // Parameter[tempParam.size()]);
    } catch (NameDuplicationException e) {
      log.error("The parameter could not be instantiated. Error message: " + e.getMessage());
      throw new IllegalActionException(
          this, "The complex submission form could not be initialized: " + e.getMessage());
    }
    return;
  }