private List<ScriptJob<?>> buildExecutionJobs(
     ExecutionContext context, Set<ExecutionScript> executions)
     throws IOException, InterruptedException {
   assert context != null;
   assert executions != null;
   List<ScriptJob<?>> results = new ArrayList<ScriptJob<?>>();
   for (ExecutionScript execution : executions) {
     switch (execution.getKind()) {
       case COMMAND:
         {
           CommandScript exec = (CommandScript) execution;
           String profileName = exec.getProfileName();
           CommandScriptHandler handler =
               profileName == null ? null : commandHandlers.get(profileName);
           if (handler == null) {
             LOG.debug(
                 "Profile {} is not defined in comand script handlers, try wildcard: {}",
                 profileName,
                 exec.getId());
             handler = commandHandlers.get(CommandScriptHandler.PROFILE_WILDCARD);
           }
           if (handler == null) {
             throw new IOException(
                 MessageFormat.format(
                     "Profile \"{5}\" is not defined (batch={0}, flow={1}, phase={2}, module={3}, id={4})",
                     context.getBatchId(),
                     context.getFlowId(),
                     context.getPhase().getSymbol(),
                     exec.getModuleName(),
                     exec.getId(),
                     profileName));
           }
           results.add(new ScriptJob<CommandScript>(exec.resolve(context, handler), handler));
           break;
         }
       case HADOOP:
         {
           HadoopScript exec = (HadoopScript) execution;
           results.add(
               new ScriptJob<HadoopScript>(exec.resolve(context, hadoopHandler), hadoopHandler));
           break;
         }
       default:
         throw new AssertionError(
             MessageFormat.format("Unknown execution script: {0}", execution));
     }
   }
   return results;
 }
Example #2
0
 /**
  * Stores this script into the specified object.
  *
  * @param properties target properties
  * @throws IllegalArgumentException if some parameters were {@code null}
  */
 public void storeTo(Properties properties) {
   if (properties == null) {
     throw new IllegalArgumentException("properties must not be null"); // $NON-NLS-1$
   }
   properties.setProperty(getPrefix(getId()) + KEY_BLOCKERS, join(getBlockerIds()));
   for (Map.Entry<ExecutionPhase, Set<ExecutionScript>> phase : getScripts().entrySet()) {
     int index = 0;
     for (ExecutionScript script : phase.getValue()) {
       String scriptPrefix = getPrefix(getId(), phase.getKey(), String.format("%04d", index++));
       properties.setProperty(scriptPrefix + KEY_ID, script.getId());
       properties.setProperty(scriptPrefix + KEY_KIND, script.getKind().getSymbol());
       properties.setProperty(scriptPrefix + KEY_BLOCKERS, join(script.getBlockerIds()));
       String envPrefix = scriptPrefix + KEY_ENV_PREFIX;
       for (Map.Entry<String, String> entry : script.getEnvironmentVariables().entrySet()) {
         properties.setProperty(envPrefix + entry.getKey(), entry.getValue());
       }
       switch (script.getKind()) {
         case COMMAND:
           {
             CommandScript s = (CommandScript) script;
             properties.setProperty(scriptPrefix + KEY_PROFILE, s.getProfileName());
             properties.setProperty(scriptPrefix + KEY_MODULE, s.getModuleName());
             List<String> command = s.getCommandLineTokens();
             assert command.size() <= 9999;
             String commandPrefix = scriptPrefix + KEY_COMMAND_PREFIX;
             for (int i = 0, n = command.size(); i < n; i++) {
               properties.setProperty(String.format("%s%04d", commandPrefix, i), command.get(i));
             }
             break;
           }
         case HADOOP:
           {
             HadoopScript s = (HadoopScript) script;
             properties.setProperty(scriptPrefix + KEY_CLASS_NAME, s.getClassName());
             String propPrefix = scriptPrefix + KEY_PROP_PREFIX;
             for (Map.Entry<String, String> entry : s.getHadoopProperties().entrySet()) {
               properties.setProperty(propPrefix + entry.getKey(), entry.getValue());
             }
             break;
           }
         default:
           throw new AssertionError(script.getKind());
       }
     }
   }
 }
Example #3
0
 /** Simple testing. */
 @Test
 public void simple() {
   CommandScript script =
       new CommandScript(
           "testing",
           set("blk1", "blk2"),
           "profile",
           "module",
           Arrays.asList("cmd1", "cmd2"),
           map("ASAKUSA_HOME", folder.getRoot().getAbsolutePath()));
   assertThat(script.getKind(), is(ExecutionScript.Kind.COMMAND));
   assertThat(script.getId(), is("testing"));
   assertThat(script.getBlockerIds(), is(set("blk1", "blk2")));
   assertThat(script.getProfileName(), is("profile"));
   assertThat(script.getModuleName(), is("module"));
   assertThat(script.getCommandLineTokens(), is(Arrays.asList("cmd1", "cmd2")));
   assertThat(script.getEnvironmentVariables().size(), is(1));
   assertThat(
       script.getEnvironmentVariables().get("ASAKUSA_HOME"),
       is(folder.getRoot().getAbsolutePath()));
 }