コード例 #1
0
ファイル: ShiwaBundleHelper.java プロジェクト: CSCSI/Triana
  /**
   * Gets the outputs.
   *
   * @param bundle the bundle
   * @return the outputs
   */
  public static HashMap<String, ConfigurationResource> getOutputs(File bundle) {

    HashMap<String, ConfigurationResource> results = new HashMap<String, ConfigurationResource>();
    try {
      //            SHIWABundle shiwaBundle = new SHIWABundle(bundle);

      ConcreteBundle concreteBundle = new ConcreteBundle(bundle);
      //            WorkflowController workflowController = new WorkflowController(shiwaBundle);

      for (Mapping configuration : concreteBundle.getPrimaryMappings()) {
        System.out.println("Config type : " + configuration.getClass().getCanonicalName());

        if (configuration instanceof ExecutionMapping) {
          System.out.println("Received bundle has an exec config");

          System.out.println(
              configuration.getAggregatedResources().size() + " aggregated resources");

          System.out.println(
              "Exec config contains " + configuration.getResources().size() + " resources.");
          for (ConfigurationResource r : configuration.getResources()) {
            results.put(r.getReferableResource().getTitle(), r);
          }
          System.out.println(results.size() + " outputs found.");
          return results;
        }
      }
    } catch (SHIWADesktopIOException e) {
      System.out.println("Returned bundle was corrupt or null.");
      ErrorTracker.getErrorTracker()
          .broadcastError(new ErrorEvent(null, e, "Returned Bundle was corrupt or null"));
    }

    return null;
  }
コード例 #2
0
ファイル: ShiwaBundleHelper.java プロジェクト: CSCSI/Triana
  /**
   * Write config resources to disk.
   *
   * @param dependency the dependency
   * @param config the config
   * @param outputLocation the output location
   * @throws IOException Signals that an I/O exception has occurred.
   */
  public static void writeConfigResourcesToDisk(
      Dependency dependency, List<ConfigurationResource> config, File outputLocation)
      throws IOException {
    String value = null;
    TransferSignature.ValueType valueType = null;
    for (ConfigurationResource portRef : config) {
      if (portRef.getReferableResource().getId().equals(dependency.getId())) {
        value = portRef.getValue();

        ConfigurationResource.RefTypes refType = portRef.getRefType();
        System.out.println("Value for " + portRef.getId() + " : " + value);

        if (refType == ConfigurationResource.RefTypes.INLINE_REF) {
          valueType = TransferSignature.ValueType.INLINE_STRING;

        } else if (refType == ConfigurationResource.RefTypes.URI_REF) {
          File success = download(value, new File("."), null);
          if (success.exists()) {
            System.out.println("Fetched " + value + " to " + success.getAbsolutePath());
            value = success.getAbsolutePath();
          } else {
            System.out.println("Failed to fetch " + value);
          }

          valueType = TransferSignature.ValueType.INLINE_URI;
        } else if (refType == ConfigurationResource.RefTypes.FILE_REF) {
          valueType = TransferSignature.ValueType.BUNDLED_FILE;
          //                            File tempFile = DataUtils.extractToTempFile(portRef);
          File tempFile = writeConfigurationResourceToFile(portRef, null, outputLocation);
          value = tempFile.getAbsolutePath();
        }
      }
    }
  }
コード例 #3
0
ファイル: ShiwaBundleHelper.java プロジェクト: CSCSI/Triana
 /**
  * Gets the configuration resource for dependency.
  *
  * @param dependency the dependency
  * @return the configuration resource for dependency
  */
 public ConfigurationResource getConfigurationResourceForDependency(Dependency dependency) {
   for (Mapping mapping : concreteBundle.getPrimaryMappings()) {
     for (ConfigurationResource configurationResource : mapping.getResources()) {
       if (dependency.getId().equals(configurationResource.getId())) {
         return configurationResource;
       }
     }
   }
   return null;
 }
コード例 #4
0
ファイル: ShiwaBundleHelper.java プロジェクト: CSCSI/Triana
  /**
   * Write configuration resource to file.
   *
   * @param configurationResource the configuration resource
   * @param file the file
   * @param outputLocation the output location
   * @return the file
   * @throws IOException Signals that an I/O exception has occurred.
   */
  public static File writeConfigurationResourceToFile(
      ConfigurationResource configurationResource, File file, File outputLocation)
      throws IOException {
    String longName = configurationResource.getBundleFile().getFilename();
    if (file == null) {
      file = new File(outputLocation, longName.substring(longName.lastIndexOf("/") + 1));
    }
    System.out.println("   >> Made : " + file.getAbsolutePath());

    return DataUtils.extractToFile(configurationResource, file);
  }
コード例 #5
0
ファイル: ShiwaBundleHelper.java プロジェクト: CSCSI/Triana
  /**
   * Compile outputs.
   *
   * @param outputResources the output resources
   * @param outputNodeMap the output node map
   * @return the hash map
   */
  public HashMap<Node, Object> compileOutputs(
      HashMap<String, ConfigurationResource> outputResources, HashMap<String, Node> outputNodeMap) {
    HashMap<Node, Object> outputs = new HashMap<Node, Object>();
    System.out.println(outputResources.size() + " output objects.");
    for (String nodeName : outputResources.keySet()) {
      Node node = outputNodeMap.get(nodeName);
      ConfigurationResource resource = outputResources.get(nodeName);
      String resourceString = resource.getValue();

      if (resource.getRefType() == ConfigurationResource.RefTypes.INLINE_REF) {
        outputs.put(node, resourceString);
      } else if (resource.getRefType() == ConfigurationResource.RefTypes.URI_REF) {
        outputs.put(node, resourceString);
      } else if (resource.getRefType() == ConfigurationResource.RefTypes.FILE_REF) {
        //                String outputString = new String(resource.getBundleFile().getBytes());
        //                System.out.println("BundleFile at node : " + node + " contains : " +
        // outputString);
        //                outputs.put(node, outputString);
        String tempBundleLocation = resource.getBundleFile().getSystemPath();
        System.out.println(
            "BundleFile at node : " + node + " temp location : " + tempBundleLocation);
        String outputString = BundleUtils.readFile(tempBundleLocation);
        outputs.put(node, outputString);
      }

      System.out.println(
          "Node "
              + node.getAbsoluteNodeIndex()
              + " named : "
              + nodeName
              + " outputs : "
              + outputs.get(node));
    }
    return outputs;
  }
コード例 #6
0
ファイル: ShiwaBundleHelper.java プロジェクト: CSCSI/Triana
  /**
   * Creates the configuration.
   *
   * @param list the list
   * @return the mapping
   */
  public Mapping createConfiguration(List list) {
    if (list.size() > 0) {

      int inputObjectNo = 0;
      Mapping config = new DataMapping();

      for (ReferableResource referableResource :
          concreteBundle.getPrimaryConcreteTask().getSignature().getPorts()) {
        if (referableResource instanceof InputPort) {
          ConfigurationResource configurationResource =
              new ConfigurationResource(referableResource);
          // TODO serialize

          Object inputObject = list.get(inputObjectNo);

          if (inputObject instanceof File) {
            try {
              configurationResource.setRefType(ConfigurationResource.RefTypes.FILE_REF);
              BundleFile bf = DataUtils.createBundleFile((File) inputObject, config.getId() + "/");
              bf.setType(BundleFile.FileType.DATA_FILE);
              config.getBundleFiles().add(bf);
              configurationResource.setBundleFile(bf);
            } catch (SHIWADesktopIOException e) {
              e.printStackTrace();
            }
          } else {
            configurationResource.setValue(inputObject.toString());
            configurationResource.setRefType(ConfigurationResource.RefTypes.INLINE_REF);
          }
          inputObjectNo++;
          config.addResourceRef(configurationResource);
        }
      }
      getWorkflowImplementation().getAggregatedResources().add(config);
      return config;
    }
    return null;
  }
コード例 #7
0
ファイル: ShiwaBundleHelper.java プロジェクト: CSCSI/Triana
  /**
   * Creates the transfer signature.
   *
   * @param workflow the workflow
   * @param configuration the configuration
   * @return the transfer signature
   * @throws IOException Signals that an I/O exception has occurred.
   */
  public TransferSignature createTransferSignature(ConcreteTask workflow, Mapping configuration)
      throws IOException {
    TransferSignature signature = new TransferSignature();

    signature.setName(workflow.getDefinition().getFilename());

    if (workflow.getLanguage() != null) {
      signature.setLanguage(workflow.getLanguage().toString());
    }

    for (ReferableResource referableResource : workflow.getSignature().getPorts()) {
      if (referableResource instanceof InputPort) {
        String value = null;
        boolean isReference = false;

        if (configuration != null) {
          for (ConfigurationResource portRef : configuration.getResources()) {
            System.out.println(
                portRef.getReferableResource().getId() + " " + referableResource.getId());
            if (portRef.getReferableResource().getId().equals(referableResource.getId())) {
              value = portRef.getValue();
              isReference = (portRef.getRefType() == ConfigurationResource.RefTypes.FILE_REF);
            }
          }
        }

        if (value != null) {
          if (isReference) {
            signature.addInputReference(
                referableResource.getTitle(), referableResource.getDataType(), value);
          } else {
            signature.addInput(
                referableResource.getTitle(), referableResource.getDataType(), value);
          }
        } else {
          signature.addInput(referableResource.getTitle(), referableResource.getDataType());
        }
      } else if (referableResource instanceof OutputPort) {
        signature.addOutput(referableResource.getTitle(), referableResource.getDataType());
      }
    }

    //        for (Dependency dependency : workflow.getDependencies()) {
    //            String value = null;
    //            TransferSignature.ValueType valueType = null;
    //
    //            if (configuration != null) {
    //                for (ConfigurationResource portRef :
    // getFirstConfigurationOfType(Configuration.ConfigType.ENVIRONMENT_CONFIGURATION).getResources()) {
    //                    if (portRef.getReferableResource().getId().equals(dependency.getId())) {
    //                        value = portRef.getValue();
    //
    //                        ConfigurationResource.RefTypes refType = portRef.getRefType();
    //                        System.out.println("Value for " + portRef.getId() + " : " + value);
    //
    //                        if(refType == ConfigurationResource.RefTypes.INLINE_REF){
    //                            valueType = TransferSignature.ValueType.INLINE_STRING;
    //
    //                        } else if (refType == ConfigurationResource.RefTypes.URI_REF){
    //                            File success = download(value, new File("."), null);
    //                            if(success.exists()){
    //                                System.out.println("Fetched " + value + " to " +
    // success.getAbsolutePath());
    //                                value = success.getAbsolutePath();
    //                            } else {
    //                                System.out.println("Failed to fetch " + value);
    //                            }
    //
    //                            valueType = TransferSignature.ValueType.INLINE_URI;
    //                        } else if (refType == ConfigurationResource.RefTypes.FILE_REF){
    //                            valueType =  TransferSignature.ValueType.BUNDLED_FILE;
    ////                            File tempFile = DataUtils.extractToTempFile(portRef);
    //                            File tempFile = writeConfigurationResourceToFile(portRef, null);
    //                            value = tempFile.getAbsolutePath();
    //                        }
    //                    }
    //                }
    //            }

    //            signature.addOutput(dependency.getTitle(),
    //                    dependency.getDataType(),
    //                    dependency.getDescription(),
    //                    value,
    //                    valueType
    //            );
    //        }

    if (configuration != null) {
      signature.setHasConfiguration(true);
    }
    return signature;
  }