[Java] Fix loading driver resources issue. (#3046)

## What do these changes do?
Fix the issue how we load driver resources by a specified path.
Also this addressed the comments from the related PR [3044](https://github.com/ray-project/ray/pull/3044).

## Related PRs:
 [#3044](https://github.com/ray-project/ray/pull/3044) and [#3001](https://github.com/ray-project/ray/pull/3001).
This commit is contained in:
Wang Qing
2018-10-12 00:45:21 +08:00
committed by Hao Chen
parent 4a2ed47b6c
commit 828fe24b39
4 changed files with 18 additions and 30 deletions
@@ -158,17 +158,12 @@ public class RayConfig {
rayletExecutablePath = rayHome + "/build/src/ray/raylet/raylet";
// driver resource path
String localDriverResourcePath;
if (config.hasPath("ray.driver.resource-path")) {
localDriverResourcePath = config.getString("ray.driver.resource-path");
driverResourcePath = config.getString("ray.driver.resource-path");
} else {
localDriverResourcePath = rayHome + "/driver/resource";
LOGGER.warn("Didn't configure ray.driver.resource-path, set it to default value: {}",
localDriverResourcePath);
driverResourcePath = null;
}
driverResourcePath = localDriverResourcePath;
// validate config
validate();
LOGGER.debug("Created config: {}", this);
@@ -89,13 +89,11 @@ public class FunctionManager {
String resourcePath = driverResourcePath + "/" + driverId.toString() + "/";
ClassLoader classLoader;
try {
if (driverResourcePath != null && !driverResourcePath.isEmpty()) {
classLoader = JarLoader.loadJars(resourcePath, false);
LOGGER.info("Succeeded to load driver({}) resource. Resource path is {}",
driverId, resourcePath);
} catch (Exception e) {
LOGGER.error("Failed to load driver({}) resource. Resource path is {}",
driverId, resourcePath);
} else {
classLoader = getClass().getClassLoader();
}
@@ -25,15 +25,16 @@ ray {
// Available resources on this node, for example "CPU:4,GPU:0".
resources: ""
// Configuration items about driver.
driver {
// If worker.mode is DRIVER, specify the driver id.
// If not provided, a random id will be used.
id: ""
// If worker.mode is WORKER, it means that worker will load
// the resources from this path to execute tasks.
resource-path: /tmp/ray/driver/resource
}
// Configuration items about driver.
driver {
// If worker.mode is DRIVER, specify the driver id.
// If not provided, a random id will be used.
id: ""
// If this config is set, worker will use different paths to loadresources when
// executing tasks from different drivers. E.g. if it's set to '/tm/driver_resources',
// the path for driver 123 will be '/tmp/driver_resources/123'.
resource-path: ""
}
// Root dir of log files.
log-dir: /tmp/ray/logs
@@ -45,10 +45,6 @@ public class FunctionManagerTest {
private static FunctionDescriptor barDescriptor;
private static FunctionDescriptor barConstructorDescriptor;
private final static String resourcePath = "/tmp/ray/test/resource";
private FunctionManager functionManager;
@BeforeClass
public static void beforeClass() {
fooFunc = FunctionManagerTest::foo;
@@ -63,13 +59,9 @@ public class FunctionManagerTest {
"()V");
}
@Before
public void before() {
functionManager = new FunctionManager(FunctionManagerTest.resourcePath);
}
@Test
public void testGetFunctionFromRayFunc() {
final FunctionManager functionManager = new FunctionManager(null);
// Test normal function.
RayFunction func = functionManager.getFunction(UniqueId.NIL, fooFunc);
Assert.assertFalse(func.isConstructor());
@@ -91,6 +83,7 @@ public class FunctionManagerTest {
@Test
public void testGetFunctionFromFunctionDescriptor() {
final FunctionManager functionManager = new FunctionManager(null);
// Test normal function.
RayFunction func = functionManager.getFunction(UniqueId.NIL, fooDescriptor);
Assert.assertFalse(func.isConstructor());
@@ -129,6 +122,7 @@ public class FunctionManagerTest {
UniqueId driverId = UniqueId.fromHexString("0123456789012345678901234567890123456789");
//TODO(qwang): We should use a independent app demo instead of `tutorial`.
final String resourcePath = "/tmp/ray/test/resource";
final String srcJarPath = System.getProperty("user.dir") +
"/../tutorial/target/ray-tutorial-0.1-SNAPSHOT.jar";
final String destJarPath = resourcePath + "/" + driverId.toString() +
@@ -136,9 +130,9 @@ public class FunctionManagerTest {
File file = new File(resourcePath + "/" + driverId.toString());
file.mkdirs();
Files.copy(Paths.get(srcJarPath), Paths.get(destJarPath), StandardCopyOption.REPLACE_EXISTING);
final FunctionManager functionManager = new FunctionManager(resourcePath);
FunctionDescriptor sayHelloDescriptor = new FunctionDescriptor("org.ray.exercise.Exercise02",
"sayHello", "()Ljava/lang/String;");
RayFunction func = functionManager.getFunction(driverId, sayHelloDescriptor);