Skip to content
Merged
1 change: 1 addition & 0 deletions distribution/bin/check-licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ def build_compatible_license_names():
compatible_licenses['SPDX-License-Identifier: MIT'] = 'MIT License'

compatible_licenses['The Go license'] = 'The Go license'
compatible_licenses['Universal Permissive License, Version 1.0'] = 'Universal Permissive License, Version 1.0'

compatible_licenses['-'] = '-'
return compatible_licenses
Expand Down
10 changes: 10 additions & 0 deletions indexing-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@
<artifactId>commons-collections4</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js-scriptengine</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.cronutils</groupId>
<artifactId>cron-utils</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.
*/

package org.apache.druid.indexing.overlord.setup;

import javax.script.Bindings;
import javax.script.Compilable;
import javax.script.Invocable;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class JavaScriptUtil
{
public static <T> T compileSelectorFunction(Class<T> interfaceClass, String function)
{
final ScriptEngine engine = new ScriptEngineManager().getEngineByName("js");
Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
bindings.put("polyglot.js.nashorn-compat", true);
try {
((Compilable) engine).compile("var apply = " + function).eval();
return ((Invocable) engine).getInterface(interfaceClass);
}
catch (ScriptException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@
import org.apache.druid.indexing.overlord.config.WorkerTaskRunnerConfig;
import org.apache.druid.js.JavaScriptConfig;

import javax.script.Compilable;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class JavaScriptWorkerSelectStrategy implements WorkerSelectStrategy
{
public interface SelectorFunction
Expand All @@ -59,26 +53,14 @@ public JavaScriptWorkerSelectStrategy(
this.function = fn;
}

private SelectorFunction compileSelectorFunction()
{
final ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript");
try {
((Compilable) engine).compile("var apply = " + function).eval();
return ((Invocable) engine).getInterface(SelectorFunction.class);
}
catch (ScriptException e) {
throw new RuntimeException(e);
}
}

@Override
public ImmutableWorkerInfo findWorkerForTask(
WorkerTaskRunnerConfig config,
ImmutableMap<String, ImmutableWorkerInfo> zkWorkers,
Task task
)
{
fnSelector = fnSelector == null ? compileSelectorFunction() : fnSelector;
fnSelector = fnSelector == null ? JavaScriptUtil.compileSelectorFunction(SelectorFunction.class, function) : fnSelector;
String worker = fnSelector.apply(config, zkWorkers, task);
return worker == null ? null : zkWorkers.get(worker);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,10 @@
import org.hamcrest.CoreMatchers;
import org.joda.time.Period;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import javax.script.ScriptEngineManager;

public class JavaScriptWorkerSelectStrategyTest
{
@Rule
Expand Down Expand Up @@ -76,13 +72,6 @@ public class JavaScriptWorkerSelectStrategyTest
JavaScriptConfig.getEnabledInstance()
);

@Before
public void checkJdkCompatibility()
{
// skip tests for newer JDKs without javascript support
Assume.assumeNotNull(new ScriptEngineManager().getEngineByName("javascript"));
}

@Test
public void testSerde() throws Exception
{
Expand Down
16 changes: 16 additions & 0 deletions licenses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5038,6 +5038,22 @@ libraries:

---

name: GraalVM
license_category: binary
license_name: Universal Permissive License, Version 1.0
license_file_path: licenses/bin/graal.UPL
version: 22.3.5
module: core
libraries:
- org.graalvm.js: js
- org.graalvm.js: js-scriptengine
- org.graalvm.regex: regex
- org.graalvm.sdk: graal-sdk
- org.graalvm.js: js-scriptengine
- org.graalvm.truffle: truffle-api

---

name: jakarta.el
license_category: binary
module: core
Expand Down
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
<jna.version>5.13.0</jna.version>
<jna-platform.version>5.13.0</jna-platform.version>
<hadoop.compile.version>3.3.6</hadoop.compile.version>
<graaljs.version>22.3.5</graaljs.version>
<mockito.version>5.14.2</mockito.version>
<aws.sdk.version>1.12.638</aws.sdk.version>
<caffeine.version>2.8.0</caffeine.version>
Expand Down Expand Up @@ -669,6 +670,16 @@
<artifactId>jaxb-runtime</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js</artifactId>
<version>${graaljs.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js-scriptengine</artifactId>
<version>${graaljs.version}</version>
</dependency>
<dependency>
<groupId>org.jdbi</groupId>
<artifactId>jdbi</artifactId>
Expand Down
10 changes: 10 additions & 0 deletions services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,16 @@
<groupId>org.jdbi</groupId>
<artifactId>jdbi</artifactId>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js-scriptengine</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Test Dependencies -->
<dependency>
<groupId>org.apache.druid</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,10 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import org.apache.druid.indexing.overlord.setup.JavaScriptUtil;
import org.apache.druid.js.JavaScriptConfig;
import org.apache.druid.query.Query;

import javax.script.Compilable;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class JavaScriptTieredBrokerSelectorStrategy implements TieredBrokerSelectorStrategy
{
public interface SelectorFunction
Expand All @@ -57,22 +52,10 @@ public JavaScriptTieredBrokerSelectorStrategy(
this.function = fn;
}

private SelectorFunction compileSelectorFunction()
{
final ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript");
try {
((Compilable) engine).compile("var apply = " + function).eval();
return ((Invocable) engine).getInterface(SelectorFunction.class);
}
catch (ScriptException e) {
throw new RuntimeException(e);
}
}

@Override
public Optional<String> getBrokerServiceName(TieredBrokerConfig config, Query query)
{
fnSelector = fnSelector == null ? compileSelectorFunction() : fnSelector;
fnSelector = fnSelector == null ? JavaScriptUtil.compileSelectorFunction(SelectorFunction.class, function) : fnSelector;
return Optional.fromNullable(fnSelector.apply(config, query));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,10 @@
import org.apache.druid.query.topn.TopNQueryBuilder;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import javax.script.ScriptEngineManager;
import java.util.LinkedHashMap;

public class JavaScriptTieredBrokerSelectorStrategyTest
Expand All @@ -51,13 +48,6 @@ public class JavaScriptTieredBrokerSelectorStrategyTest
JavaScriptConfig.getEnabledInstance()
);

@Before
public void checkJdkCompatibility()
{
// skip tests for newer JDKs without javascript support
Assume.assumeNotNull(new ScriptEngineManager().getEngineByName("javascript"));
}

@Test
public void testSerde() throws Exception
{
Expand Down
Loading