mirror of
https://github.com/vale981/ray
synced 2025-03-05 10:01:43 -05:00
[Serve]Fix classloader bug in Java Deployment (#27899)
We have encountered `java.lang.ClassNotFoundException` when deploying Java Ray Serve deployments. The property `ray.job.code-search-path` which specifies the search path of user's classes is not working. The reason is that `ray.job.code-search-path` is loaded in an independent classloader in Ray context, but Serve Replica initialized user class with `AppClassLoader`. We need to change the classloader used to construct user classes to the one in Ray context.
This commit is contained in:
parent
c2abfdb2f7
commit
1c4b3879a1
1 changed files with 6 additions and 1 deletions
|
@ -89,7 +89,12 @@ public class RayServeWrappedReplica implements RayServeReplica {
|
||||||
deploymentWrapper.getConfig());
|
deploymentWrapper.getConfig());
|
||||||
|
|
||||||
// Instantiate the object defined by deploymentDef.
|
// Instantiate the object defined by deploymentDef.
|
||||||
Class deploymentClass = Class.forName(deploymentWrapper.getDeploymentDef());
|
Class deploymentClass =
|
||||||
|
Class.forName(
|
||||||
|
deploymentWrapper.getDeploymentDef(),
|
||||||
|
true,
|
||||||
|
Optional.ofNullable(Thread.currentThread().getContextClassLoader())
|
||||||
|
.orElse(getClass().getClassLoader()));
|
||||||
Object callable =
|
Object callable =
|
||||||
ReflectUtil.getConstructor(deploymentClass, deploymentWrapper.getInitArgs())
|
ReflectUtil.getConstructor(deploymentClass, deploymentWrapper.getInitArgs())
|
||||||
.newInstance(deploymentWrapper.getInitArgs());
|
.newInstance(deploymentWrapper.getInitArgs());
|
||||||
|
|
Loading…
Add table
Reference in a new issue