helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hu...@apache.org
Subject [helix] branch dynamically-loaded-task updated: Add JarLoader interface and LocalJarLoader class (#1229)
Date Wed, 12 Aug 2020 16:33:36 GMT
This is an automated email from the ASF dual-hosted git repository.

hulee pushed a commit to branch dynamically-loaded-task
in repository https://gitbox.apache.org/repos/asf/helix.git


The following commit(s) were added to refs/heads/dynamically-loaded-task by this push:
     new 8100996  Add JarLoader interface and LocalJarLoader class (#1229)
8100996 is described below

commit 810099646b169230359abb95e5eff92ba601e240
Author: rabashizade <67170754+rabashizade@users.noreply.github.com>
AuthorDate: Wed Aug 12 12:33:27 2020 -0400

    Add JarLoader interface and LocalJarLoader class (#1229)
    
    Adds JarLoader interface to load JAR files that contain task classes
    which we want to dynamically load.
    
    Also adds LocalJarLoader implementation of JarLoader interface which
    loads a JAR file from a local directory.
---
 .../java/org/apache/helix/task/api/JarLoader.java  | 34 ++++++++++++++
 .../org/apache/helix/task/api/LocalJarLoader.java  | 53 ++++++++++++++++++++++
 2 files changed, 87 insertions(+)

diff --git a/helix-core/src/main/java/org/apache/helix/task/api/JarLoader.java b/helix-core/src/main/java/org/apache/helix/task/api/JarLoader.java
new file mode 100644
index 0000000..20cdf50
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/task/api/JarLoader.java
@@ -0,0 +1,34 @@
+package org.apache.helix.task.api;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import java.net.URL;
+
+/**
+ * The interface that is to be implemented by a specific JAR loader.
+ */
+public interface JarLoader {
+  /**
+   * Loads a JAR file and returns its URL.
+   * @param jarPath path of the JAR file
+   * @return URL of the JAR file at path jarPath
+   */
+  URL loadJar(String jarPath);
+}
diff --git a/helix-core/src/main/java/org/apache/helix/task/api/LocalJarLoader.java b/helix-core/src/main/java/org/apache/helix/task/api/LocalJarLoader.java
new file mode 100644
index 0000000..346bb98
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/task/api/LocalJarLoader.java
@@ -0,0 +1,53 @@
+package org.apache.helix.task.api;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LocalJarLoader implements JarLoader {
+  private static final Logger LOG = LoggerFactory.getLogger(LocalJarLoader.class);
+
+  /**
+   * Loads a local JAR file and returns its URL.
+   * @param jarPath path of the JAR file
+   * @return URL of the JAR file at path jarPath
+   */
+  @Override
+  public URL loadJar(String jarPath) {
+    // If taskJarFile doesn't exist or it's a directory, throw exception
+    File taskJarFile = new File(jarPath);
+    if (!taskJarFile.exists() || taskJarFile.isDirectory()) {
+      LOG.error("Failed to find JAR " + jarPath + " for new task.");
+      throw new IllegalArgumentException("No JAR for task");
+    }
+
+    try {
+      return taskJarFile.toURI().toURL();
+    } catch (MalformedURLException e) {
+      LOG.error("Failed to open JAR " + jarPath + " for new task.");
+      throw new IllegalArgumentException("Malformed JAR URL for task");
+    }
+  }
+}


Mime
View raw message