Example #1
0
 /**
  * Loads a {@link ExecutionScript}s in the specified flow and phase. If the target phase is empty
  * in the specified flow, this returns an empty list. Note that this method will raise an
  * exception if the specified flow does not exist.
  *
  * @param properties source properties
  * @param flowId the target flow ID
  * @param phase the target phase
  * @return the loaded execution scripts
  * @throws IllegalArgumentException if script is invalid, or some parameters were {@code null}
  * @see #extractFlowIds(Properties)
  */
 public static Set<ExecutionScript> load(
     Properties properties, String flowId, ExecutionPhase phase) {
   if (properties == null) {
     throw new IllegalArgumentException("properties must not be null"); // $NON-NLS-1$
   }
   if (flowId == null) {
     throw new IllegalArgumentException("flowId must not be null"); // $NON-NLS-1$
   }
   if (phase == null) {
     throw new IllegalArgumentException("phase must not be null"); // $NON-NLS-1$
   }
   String prefix = getPrefix(flowId, phase);
   LOG.debug("Loading execution scripts: {}*", prefix);
   Set<String> availableFlowIds = extractFlowIds(properties);
   if (availableFlowIds.contains(flowId) == false) {
     throw new IllegalArgumentException(
         MessageFormat.format("Flow \"{0}\" does not exist", flowId));
   }
   NavigableMap<String, String> contents = PropertiesUtil.createPrefixMap(properties, prefix);
   List<ExecutionScript> scripts = loadScripts(flowId, phase, contents);
   LOG.debug("Loaded {} execution scripts: {}*", scripts.size(), prefix);
   LOG.trace("Loaded {}*: {}", prefix, scripts);
   TreeSet<ExecutionScript> results = new TreeSet<ExecutionScript>(SCRIPT_COMPARATOR);
   results.addAll(scripts);
   return results;
 }
Example #2
0
 private static ExecutionScript loadScript(
     String flowId, ExecutionPhase phase, String nodeId, Map<String, String> contents) {
   assert flowId != null;
   assert phase != null;
   assert nodeId != null;
   assert contents != null;
   String prefix = getPrefix(flowId, phase, nodeId);
   String scriptId = extract(contents, prefix, KEY_ID);
   String kindSymbol = extract(contents, prefix, KEY_KIND);
   ExecutionScript.Kind kind = ExecutionScript.Kind.findFromSymbol(kindSymbol);
   String blockersString = extract(contents, prefix, KEY_BLOCKERS);
   Set<String> blockers = parseTokens(blockersString);
   Map<String, String> environmentVariables =
       PropertiesUtil.createPrefixMap(contents, KEY_ENV_PREFIX);
   ExecutionScript script;
   if (kind == ExecutionScript.Kind.COMMAND) {
     String profileName = extract(contents, prefix, KEY_PROFILE);
     String moduleName = extract(contents, prefix, KEY_MODULE);
     NavigableMap<String, String> commandMap =
         PropertiesUtil.createPrefixMap(contents, KEY_COMMAND_PREFIX);
     if (commandMap.isEmpty()) {
       throw new IllegalArgumentException(
           MessageFormat.format("\"{0}*\" is not defined", prefix + KEY_COMMAND_PREFIX));
     }
     List<String> command = new ArrayList<String>(commandMap.values());
     script =
         new CommandScript(
             scriptId, blockers, profileName, moduleName, command, environmentVariables);
   } else if (kind == ExecutionScript.Kind.HADOOP) {
     String className = extract(contents, prefix, KEY_CLASS_NAME);
     Map<String, String> properties = PropertiesUtil.createPrefixMap(contents, KEY_PROP_PREFIX);
     script = new HadoopScript(scriptId, blockers, className, properties, environmentVariables);
   } else {
     throw new IllegalArgumentException(
         MessageFormat.format("Unsupported kind in \"{0}\": {1}", prefix + KEY_KIND, kindSymbol));
   }
   LOG.trace("Loaded script {}* -> {}", script);
   return script;
 }
Example #3
0
 /**
  * Returns all flow IDs defined in the properties.
  *
  * @param properties target properties
  * @return all flow IDs
  * @throws IllegalArgumentException if some parameters were {@code null}
  */
 public static Set<String> extractFlowIds(Properties properties) {
   if (properties == null) {
     throw new IllegalArgumentException("properties must not be null"); // $NON-NLS-1$
   }
   LOG.debug("Extracting Flow IDs");
   Set<String> childKeys =
       PropertiesUtil.getChildKeys(properties, KEY_FLOW_PREFIX, String.valueOf('.'));
   int prefixLength = KEY_FLOW_PREFIX.length();
   Set<String> results = new TreeSet<String>();
   for (String childKey : childKeys) {
     assert childKey.startsWith(KEY_FLOW_PREFIX);
     results.add(childKey.substring(prefixLength));
   }
   LOG.debug("Extracted Flow IDs: {}", results);
   return results;
 }
Example #4
0
  /**
   * Loads a {@link FlowScript} with the specified ID.
   *
   * @param properties source properties
   * @param flowId the target flow ID
   * @return the loaded script
   * @throws IllegalArgumentException if script is invalid, or some parameters were {@code null}
   * @see #extractFlowIds(Properties)
   */
  public static FlowScript load(Properties properties, String flowId) {
    if (properties == null) {
      throw new IllegalArgumentException("properties must not be null"); // $NON-NLS-1$
    }
    if (flowId == null) {
      throw new IllegalArgumentException("flowId must not be null"); // $NON-NLS-1$
    }

    String prefix = getPrefix(flowId);
    LOG.debug("Loading execution scripts: {}*", prefix);

    NavigableMap<String, String> flowMap = PropertiesUtil.createPrefixMap(properties, prefix);
    String blockersString = extract(flowMap, prefix, KEY_BLOCKERS);
    Set<String> blockerIds = parseTokens(blockersString);
    EnumMap<ExecutionPhase, List<ExecutionScript>> scripts =
        new EnumMap<ExecutionPhase, List<ExecutionScript>>(ExecutionPhase.class);
    for (ExecutionPhase phase : ExecutionPhase.values()) {
      scripts.put(phase, Collections.<ExecutionScript>emptyList());
    }
    int count = 0;
    Map<String, NavigableMap<String, String>> phaseMap = partitioning(flowMap);
    for (Map.Entry<String, NavigableMap<String, String>> entry : phaseMap.entrySet()) {
      String phaseSymbol = entry.getKey();
      NavigableMap<String, String> phaseContents = entry.getValue();
      ExecutionPhase phase = ExecutionPhase.findFromSymbol(phaseSymbol);
      if (phase == null) {
        throw new IllegalArgumentException(
            MessageFormat.format("Unknown phase in \"{0}\": {1}", flowId, phaseSymbol));
      }
      List<ExecutionScript> scriptsInPhase = loadScripts(flowId, phase, phaseContents);
      scripts.put(phase, scriptsInPhase);
      count += scriptsInPhase.size();
    }
    FlowScript script = new FlowScript(flowId, blockerIds, scripts);
    LOG.debug("Loaded {} execution scripts: {}*", count, prefix);
    LOG.trace("Loaded {}*: {}", prefix, script);
    return script;
  }