azkaban-developers

updated Flow Trigger interfaces (#1610) This PR made several

1/23/2018 5:26:42 PM

Details

diff --git a/azkaban-web-server/src/main/java/azkaban/flowtrigger/DependencyCheck.java b/azkaban-web-server/src/main/java/azkaban/flowtrigger/DependencyCheck.java
index 119567e..efae787 100644
--- a/azkaban-web-server/src/main/java/azkaban/flowtrigger/DependencyCheck.java
+++ b/azkaban-web-server/src/main/java/azkaban/flowtrigger/DependencyCheck.java
@@ -24,12 +24,8 @@ public interface DependencyCheck {
    *
    * @return context of the running dependency.
    */
-  DependencyInstanceContext run(DependencyInstanceConfig config);
-
-  /**
-   * Kill the dependency instance
-   */
-  void kill(DependencyInstanceContext depContext);
+  DependencyInstanceContext run(DependencyInstanceConfig config,
+      DependencyInstanceRuntimeProps runtimeProps, DependencyInstanceCallback callback);
 
   /**
    * Shutdown the dependency plugin. Clean up resource if needed.
@@ -40,7 +36,6 @@ public interface DependencyCheck {
    * Initialize the dependency plugin.
    *
    * @param config dependency plugin config.
-   * @param successCallback callback to invoke when the check succeeds.
    */
-  void init(DependencyPluginConfig config, SuccessCallback successCallback);
+  void init(DependencyPluginConfig config);
 }
diff --git a/azkaban-web-server/src/main/java/azkaban/flowtrigger/DependencyInstanceConfigImpl.java b/azkaban-web-server/src/main/java/azkaban/flowtrigger/DependencyInstanceConfigImpl.java
new file mode 100644
index 0000000..257aacb
--- /dev/null
+++ b/azkaban-web-server/src/main/java/azkaban/flowtrigger/DependencyInstanceConfigImpl.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2017 LinkedIn Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package azkaban.flowtrigger;
+
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
+
+public class DependencyInstanceConfigImpl implements DependencyInstanceConfig {
+
+  private final Map<String, String> props;
+
+  public DependencyInstanceConfigImpl(final Map<String, String> props) {
+    this.props = ImmutableMap.copyOf(props);
+  }
+
+  @Override
+  public String toString() {
+    return "DependencyInstanceConfigImpl{" +
+        "props=" + this.props +
+        '}';
+  }
+
+  @Override
+  public String get(final String key) {
+    return this.props.get(key);
+  }
+}
diff --git a/azkaban-web-server/src/main/java/azkaban/flowtrigger/DependencyInstanceContext.java b/azkaban-web-server/src/main/java/azkaban/flowtrigger/DependencyInstanceContext.java
index 70250dd..cdffe77 100644
--- a/azkaban-web-server/src/main/java/azkaban/flowtrigger/DependencyInstanceContext.java
+++ b/azkaban-web-server/src/main/java/azkaban/flowtrigger/DependencyInstanceContext.java
@@ -22,4 +22,8 @@ package azkaban.flowtrigger;
  */
 public interface DependencyInstanceContext {
 
+  /**
+   * cancel the instance context.
+   */
+  void cancel();
 }
diff --git a/azkaban-web-server/src/main/java/azkaban/flowtrigger/DependencyInstanceRuntimeProps.java b/azkaban-web-server/src/main/java/azkaban/flowtrigger/DependencyInstanceRuntimeProps.java
new file mode 100644
index 0000000..5825ed7
--- /dev/null
+++ b/azkaban-web-server/src/main/java/azkaban/flowtrigger/DependencyInstanceRuntimeProps.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2017 LinkedIn Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package azkaban.flowtrigger;
+
+/**
+ * Defines the dependency instance runtime props.
+ */
+public interface DependencyInstanceRuntimeProps {
+
+  /**
+   * @return value for the property key,
+   * null if the key doesn't exist.
+   */
+  String get(final String key);
+}
diff --git a/azkaban-web-server/src/main/java/azkaban/flowtrigger/DependencyInstanceRuntimePropsImpl.java b/azkaban-web-server/src/main/java/azkaban/flowtrigger/DependencyInstanceRuntimePropsImpl.java
new file mode 100644
index 0000000..79005cf
--- /dev/null
+++ b/azkaban-web-server/src/main/java/azkaban/flowtrigger/DependencyInstanceRuntimePropsImpl.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2017 LinkedIn Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package azkaban.flowtrigger;
+
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
+
+public class DependencyInstanceRuntimePropsImpl implements DependencyInstanceRuntimeProps {
+
+  private final Map<String, String> props;
+
+  public DependencyInstanceRuntimePropsImpl(final Map<String, String> props) {
+    this.props = ImmutableMap.copyOf(props);
+  }
+
+  @Override
+  public String toString() {
+    return "DependencyInstanceRuntimePropsImpl{" +
+        "props=" + this.props +
+        '}';
+  }
+
+  @Override
+  public String get(final String key) {
+    return this.props.get(key);
+  }
+}
diff --git a/azkaban-web-server/src/main/java/azkaban/flowtrigger/DependencyPluginConfigImpl.java b/azkaban-web-server/src/main/java/azkaban/flowtrigger/DependencyPluginConfigImpl.java
new file mode 100644
index 0000000..57b9524
--- /dev/null
+++ b/azkaban-web-server/src/main/java/azkaban/flowtrigger/DependencyPluginConfigImpl.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2018 LinkedIn Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package azkaban.flowtrigger;
+
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
+
+public class DependencyPluginConfigImpl implements DependencyPluginConfig {
+
+  private final Map<String, String> props;
+
+  public DependencyPluginConfigImpl(final Map<String, String> props) {
+    this.props = ImmutableMap.copyOf(props);
+  }
+
+  @Override
+  public String toString() {
+    return "DependencyPluginConfigImpl{" +
+        "props=" + this.props +
+        '}';
+  }
+
+  @Override
+  public String get(final String key) {
+    return this.props.get(key);
+  }
+}
diff --git a/azkaban-web-server/src/test/java/azkaban/flowtrigger/FlowTriggerInterfaceTest.java b/azkaban-web-server/src/test/java/azkaban/flowtrigger/FlowTriggerInterfaceTest.java
new file mode 100644
index 0000000..e46fe42
--- /dev/null
+++ b/azkaban-web-server/src/test/java/azkaban/flowtrigger/FlowTriggerInterfaceTest.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2018 LinkedIn Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package azkaban.flowtrigger;
+
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Test;
+
+public class FlowTriggerInterfaceTest {
+
+  private final Map<String, String> testHashMap;
+
+  {
+    this.testHashMap = new HashMap<>();
+    this.testHashMap.put("key1", "value1");
+    this.testHashMap.put("key2", "value2");
+  }
+
+
+  @Test
+  public void testDependencyInstanceRuntimeProps() {
+    final DependencyInstanceRuntimeProps runtimeProps = new DependencyInstanceRuntimePropsImpl
+        (this.testHashMap);
+    assertThat(runtimeProps.get("key1")).isEqualTo("value1");
+    assertThat(runtimeProps.get("key2")).isEqualTo("value2");
+    assertThat(runtimeProps.get("nonexistingkey")).isNull();
+  }
+
+  @Test
+  public void testDependencyPluginConfig() {
+    final DependencyPluginConfig pluginConfig = new DependencyPluginConfigImpl(this.testHashMap);
+    assertThat(pluginConfig.get("key1")).isEqualTo("value1");
+    assertThat(pluginConfig.get("key2")).isEqualTo("value2");
+    assertThat(pluginConfig.get("nonexistingkey")).isNull();
+  }
+
+  @Test
+  public void testDependencyInstanceConfig() {
+    final DependencyInstanceConfig instanceConfig = new DependencyInstanceConfigImpl(this
+        .testHashMap);
+    assertThat(instanceConfig.get("key1")).isEqualTo("value1");
+    assertThat(instanceConfig.get("key2")).isEqualTo("value2");
+    assertThat(instanceConfig.get("nonexistingkey")).isNull();
+  }
+}