예제 #1
0
  /**
   * Resolves something.
   *
   * @throws Exception if failed
   */
  @Test
  public void resolve() throws Exception {
    CommandScript script =
        new CommandScript(
            "testing",
            set("blk1", "blk2"),
            "profile",
            "module",
            Arrays.asList(
                ExecutionScript.PLACEHOLDER_HOME + "/cmd1",
                ExecutionScript.PLACEHOLDER_EXECUTION_ID,
                ExecutionScript.PLACEHOLDER_ARGUMENTS),
            map("ASAKUSA_HOME", ExecutionScript.PLACEHOLDER_HOME));

    ExecutionContext context =
        new ExecutionContext("b", "f", "e", ExecutionPhase.MAIN, map("arg", "ARG"));
    CommandScript resolved =
        script.resolve(
            context, handler(ExecutionScriptHandler.KEY_ENV_PREFIX + "ASAKUSA_HOME", "ah"));
    assertThat(resolved.isResolved(), is(true));
    assertThat(
        resolved.getCommandLineTokens(),
        is(Arrays.asList("ah/cmd1", "e", context.getArgumentsAsString())));
    assertThat(resolved.getEnvironmentVariables().size(), is(1));
    assertThat(resolved.getEnvironmentVariables().get("ASAKUSA_HOME"), is("ah"));
  }
예제 #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());
       }
     }
   }
 }
예제 #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()));
 }