コード例 #1
0
  /**
   * Lock provider for batch.
   *
   * @throws Exception if failed
   */
  @Test
  public void batch() throws Exception {
    Map<String, String> conf = new HashMap<>();
    conf.put(BasicLockProvider.KEY_DIRECTORY, folder.getRoot().getAbsolutePath());
    conf.put(ExecutionLockProvider.KEY_SCOPE, ExecutionLock.Scope.BATCH.getSymbol());

    ServiceProfile<ExecutionLockProvider> profile =
        new ServiceProfile<>(
            "testing",
            BasicLockProvider.class,
            conf,
            ProfileContext.system(getClass().getClassLoader()));
    ExecutionLockProvider instance1 = profile.newInstance();
    ExecutionLockProvider instance2 = profile.newInstance();

    try (ExecutionLock lock = instance1.newInstance("batch1")) {
      lock.beginFlow("flow1", "exec1");
      try {
        instance2.newInstance("batch1");
        fail("cannot run same batch");
      } catch (IOException e) {
        // ok.
      }
      try (ExecutionLock other = instance2.newInstance("batch2")) {
        // can acquire any flow/exec lock
        other.beginFlow("flow2", "exec1");
        other.endFlow("flow2", "exec1");
        other.beginFlow("flow1", "exec2");
        other.endFlow("flow1", "exec2");
        other.beginFlow("flow2", "exec2");
        other.endFlow("flow2", "exec2");
      }
    }
  }
コード例 #2
0
 /**
  * Missing directory config.
  *
  * @throws Exception if failed
  */
 @Test(expected = IOException.class)
 public void missing_directory_config() throws Exception {
   Map<String, String> conf = new HashMap<>();
   ServiceProfile<ExecutionLockProvider> profile =
       new ServiceProfile<>(
           "testing",
           BasicLockProvider.class,
           conf,
           ProfileContext.system(getClass().getClassLoader()));
   ExecutionLockProvider instance = profile.newInstance();
   instance.newInstance("batch");
 }
コード例 #3
0
 private HadoopScriptHandler handler(String... keyValuePairs) {
   Map<String, String> conf = map(keyValuePairs);
   ServiceProfile<HadoopScriptHandler> profile =
       new ServiceProfile<>(
           "hadoop",
           BasicHadoopScriptHandler.class,
           conf,
           ProfileContext.system(getClass().getClassLoader()));
   try {
     return profile.newInstance();
   } catch (Exception e) {
     throw new AssertionError(e);
   }
 }
コード例 #4
0
  /**
   * Missing directory config.
   *
   * @throws Exception if failed
   */
  @Test(expected = IOException.class)
  public void invalid_directory() throws Exception {
    File lockDir = folder.newFile("INVALID");

    Map<String, String> conf = new HashMap<>();
    conf.put(BasicLockProvider.KEY_DIRECTORY, lockDir.getAbsolutePath());

    ServiceProfile<ExecutionLockProvider> profile =
        new ServiceProfile<>(
            "testing",
            BasicLockProvider.class,
            conf,
            ProfileContext.system(getClass().getClassLoader()));
    ExecutionLockProvider instance = profile.newInstance();
    instance.newInstance("batch");
  }
コード例 #5
0
  /**
   * Configure using variable.
   *
   * @throws Exception if failed
   */
  @Test(expected = IOException.class)
  public void invalid_variable() throws Exception {
    File lockDir = folder.getRoot();
    VariableResolver var =
        new VariableResolver(Collections.singletonMap("LOCATION", lockDir.getAbsolutePath()));
    Map<String, String> conf = new HashMap<>();
    conf.put(BasicLockProvider.KEY_DIRECTORY, "${__INVALID__}");

    ServiceProfile<ExecutionLockProvider> profile =
        new ServiceProfile<>(
            "testing",
            BasicLockProvider.class,
            conf,
            new ProfileContext(getClass().getClassLoader(), var));
    profile.newInstance();
  }
コード例 #6
0
 @Override
 protected void configureExtension(ServiceProfile<?> profile)
     throws InterruptedException, IOException {
   try {
     this.executor =
         JschProcessExecutor.extract(
             profile.getPrefix(),
             profile.getConfiguration(),
             profile.getContext().getContextParameters());
   } catch (IllegalArgumentException e) {
     throw new IOException(
         MessageFormat.format("Failed to configure SSH: {0}", profile.getPrefix()), e);
   } catch (JSchException e) {
     throw new IOException(
         MessageFormat.format("Failed to configure SSH: {0}", profile.getPrefix()), e);
   }
 }
コード例 #7
0
  /**
   * Missing directory config.
   *
   * @throws Exception if failed
   */
  @Test
  public void missing_directory() throws Exception {
    File lockDir = folder.newFolder("missing");
    Assume.assumeThat(lockDir.delete(), is(true));

    Map<String, String> conf = new HashMap<>();
    conf.put(BasicLockProvider.KEY_DIRECTORY, lockDir.getAbsolutePath());

    ServiceProfile<ExecutionLockProvider> profile =
        new ServiceProfile<>(
            "testing",
            BasicLockProvider.class,
            conf,
            ProfileContext.system(getClass().getClassLoader()));
    ExecutionLockProvider instance = profile.newInstance();
    try (ExecutionLock lock = instance.newInstance("batch")) {
      lock.beginFlow("a", "b");
      lock.endFlow("a", "b");
    }
  }
コード例 #8
0
  /**
   * Simple testing.
   *
   * @throws Exception if failed
   */
  @Test
  public void simple() throws Exception {
    File lockDir = folder.getRoot();
    int start = lockDir.list().length;

    Map<String, String> conf = new HashMap<>();
    conf.put(BasicLockProvider.KEY_DIRECTORY, lockDir.getAbsolutePath());

    ServiceProfile<ExecutionLockProvider> profile =
        new ServiceProfile<>(
            "testing",
            BasicLockProvider.class,
            conf,
            ProfileContext.system(getClass().getClassLoader()));
    ExecutionLockProvider instance = profile.newInstance();
    try (ExecutionLock lock = instance.newInstance("batch")) {
      lock.beginFlow("flow", "exec");
      assertThat(lockDir.list().length, is(greaterThan(start)));
    }
    assertThat(lockDir.list().length, is(start));
  }
コード例 #9
0
  @Override
  protected void doConfigure(
      ServiceProfile<?> profile,
      Map<String, String> desiredProperties,
      Map<String, String> desiredEnvironmentVariables)
      throws InterruptedException, IOException {
    Map<String, String> conf = profile.getConfiguration();
    String trackerClassName = conf.get(ExecutionTracker.KEY_CLASS);
    String trackingId = conf.get(ExecutionTracker.KEY_ID);

    assertThat(trackerClassName, is(notNullValue()));
    assertThat(trackingId, is(notNullValue()));

    try {
      Class<?> trackerClass = profile.getContext().getClassLoader().loadClass(trackerClassName);
      this.tracker = trackerClass.asSubclass(ExecutionTracker.class).newInstance();
      this.id = ExecutionTracker.Id.get(trackingId);
    } catch (Exception e) {
      throw new AssertionError(e);
    }
  }
コード例 #10
0
  /**
   * Configure using variable.
   *
   * @throws Exception if failed
   */
  @Test
  public void with_variable() throws Exception {
    File lockDir = folder.getRoot();
    int start = lockDir.list().length;
    VariableResolver var =
        new VariableResolver(Collections.singletonMap("LOCATION", lockDir.getAbsolutePath()));
    Map<String, String> conf = new HashMap<>();
    conf.put(BasicLockProvider.KEY_DIRECTORY, "${LOCATION}");

    ServiceProfile<ExecutionLockProvider> profile =
        new ServiceProfile<>(
            "testing",
            BasicLockProvider.class,
            conf,
            new ProfileContext(getClass().getClassLoader(), var));
    ExecutionLockProvider instance = profile.newInstance();
    try (ExecutionLock lock = instance.newInstance("batch")) {
      lock.beginFlow("flow", "exec");
      assertThat(lockDir.list().length, is(greaterThan(start)));
    }
    assertThat(lockDir.list().length, is(start));
  }