Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java] Build Java code with Bazel #4284

Merged
merged 133 commits into from
Mar 22, 2019
Merged

Conversation

ruifangChen
Copy link
Contributor

@ruifangChen ruifangChen commented Mar 6, 2019

After this PR, we can build Java code with Bazel as well.

To build Ray Java code, we should build Ray C++ code for Java as the following commands(under ray directory) firstly:

build.sh -l java

then

bazel build //java:all      # you can build any target in Java part

Then the Ray jar package will stand under generated directory.

Also, we can run Java tests by following java/test.sh

Related issue number

Fixes #4273

@jovany-wang jovany-wang changed the title java bazel config [Java] Build Java code with Bazel Mar 6, 2019
@jovany-wang
Copy link
Contributor

Note that, after removing cmake build system, we should make sure we can support both Bazel and maven for building Java part.

Copy link
Contributor

@raulchen raulchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this! I left some quick comments. Will also try it out myself.

java/test.sh Outdated
pushd $ROOT_DIR/../java/test
java -jar -Dray.home=$ROOT_DIR/../ -Djava.library.path=$ROOT_DIR/../bazel-bin:$ROOT_DIR/../bazel-bin/externl/plasma:$ROOT_DIR/../bazel-genfiles $ROOT_DIR/../bazel-bin/java/AllTests_deploy.jar $ROOT_DIR/../java/testng.xml

java -jar -Dray.home=$ROOT_DIR/../ -Dray.run-mode=SINGLE_PROCESS -Djava.library.path=$ROOT_DIR/../bazel-bin:$ROOT_DIR/../bazel-bin/externl/plasma:$ROOT_DIR/../bazel-genfiles $ROOT_DIR/../bazel-bin/java/AllTests_deploy.jar $ROOT_DIR/../java/testng.xml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that you already link the binaries to /build/.... Why do we still need to overwrite -Djava.library.path?

BTW, I'm refining also this script at #4265.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, it seems that we're not running checkstyle in bazel?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that you already link the binaries to /build/.... Why do we still need to overwrite -Djava.library.path?

BTW, I'm refining also this script at #4265.

I forgot to delete the -Djava.library.path. I will fix it in this pr.

build.sh Outdated
cp -r $ROOT_DIR/bazel-genfiles/ray_pkg/ray $ROOT_DIR/python || true

if [ "$RAY_BUILD_JAVA" == "YES" ]; then
bazel build //:ray_java_pkg -c opt
Copy link
Contributor

@guoyuhong guoyuhong Mar 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The arrow python package is now downloaded from AWS. It looks like arrow Java package still goes with the old way, say, downloading source files from GitHub and building locally. I remember there is a special fix for arrow to enable bazel. Is that special fix only for Python? @pcmoritz

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We download the pyarrow files from AWS because it is compile differently from the official pyarrow package. This only concerns the python part (the official package is not compatible with the official tensorflow wheels).

@raulchen
Copy link
Contributor

raulchen commented Mar 6, 2019

I run the test locally and got the following error:

ERROR: /Users/haochen/code/my_ray/java/BUILD.bazel:120:1: Executing genrule //java:generate_java_gcs_fbs failed (Exit 1)
Traceback (most recent call last):
  File "/private/var/tmp/_bazel_haochen/67c2e9ea7ec45db65d1c3b95cd173f21/execroot/com_github_riselab_ray/java/modify_generated_java_flatbuffers_files.py", line 55, in <module>
    add_package_declarations(root_path)
  File "/private/var/tmp/_bazel_haochen/67c2e9ea7ec45db65d1c3b95cd173f21/execroot/com_github_riselab_ray/java/modify_generated_java_flatbuffers_files.py", line 44, in add_package_declarations
    success = add_new_line(full_name, 2, PACKAGE_DECLARATION)
  File "/private/var/tmp/_bazel_haochen/67c2e9ea7ec45db65d1c3b95cd173f21/execroot/com_github_riselab_ray/java/modify_generated_java_flatbuffers_files.py", line 31, in add_new_line
    with open(file, "w") as file_handler:
PermissionError: [Errno 13] Permission denied: '/private/var/tmp/_bazel_haochen/67c2e9ea7ec45db65d1c3b95cd173f21/execroot/com_github_riselab_ray/java/runtime/src/main/java/org/ray/runtime/generated/ConfigTableData.java'

It seems that we need to chmod the generated files.

@raulchen
Copy link
Contributor

raulchen commented Mar 6, 2019

Also, we need to delete this to make Java CI job run on bazel.

- RAY_USE_CMAKE=1

@jovany-wang
Copy link
Contributor

I run the test locally and got the following error:

ERROR: /Users/haochen/code/my_ray/java/BUILD.bazel:120:1: Executing genrule //java:generate_java_gcs_fbs failed (Exit 1)
Traceback (most recent call last):
  File "/private/var/tmp/_bazel_haochen/67c2e9ea7ec45db65d1c3b95cd173f21/execroot/com_github_riselab_ray/java/modify_generated_java_flatbuffers_files.py", line 55, in <module>
    add_package_declarations(root_path)
  File "/private/var/tmp/_bazel_haochen/67c2e9ea7ec45db65d1c3b95cd173f21/execroot/com_github_riselab_ray/java/modify_generated_java_flatbuffers_files.py", line 44, in add_package_declarations
    success = add_new_line(full_name, 2, PACKAGE_DECLARATION)
  File "/private/var/tmp/_bazel_haochen/67c2e9ea7ec45db65d1c3b95cd173f21/execroot/com_github_riselab_ray/java/modify_generated_java_flatbuffers_files.py", line 31, in add_new_line
    with open(file, "w") as file_handler:
PermissionError: [Errno 13] Permission denied: '/private/var/tmp/_bazel_haochen/67c2e9ea7ec45db65d1c3b95cd173f21/execroot/com_github_riselab_ray/java/runtime/src/main/java/org/ray/runtime/generated/ConfigTableData.java'

It seems that we need to chmod the generated files.

The same to me. This could be reprod on mac.
I think we shouldn't use /private/var/tmp dir since the permission.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/12594/
Test FAILed.

@ruifangChen
Copy link
Contributor Author

I run the test locally and got the following error:

ERROR: /Users/haochen/code/my_ray/java/BUILD.bazel:120:1: Executing genrule //java:generate_java_gcs_fbs failed (Exit 1)
Traceback (most recent call last):
  File "/private/var/tmp/_bazel_haochen/67c2e9ea7ec45db65d1c3b95cd173f21/execroot/com_github_riselab_ray/java/modify_generated_java_flatbuffers_files.py", line 55, in <module>
    add_package_declarations(root_path)
  File "/private/var/tmp/_bazel_haochen/67c2e9ea7ec45db65d1c3b95cd173f21/execroot/com_github_riselab_ray/java/modify_generated_java_flatbuffers_files.py", line 44, in add_package_declarations
    success = add_new_line(full_name, 2, PACKAGE_DECLARATION)
  File "/private/var/tmp/_bazel_haochen/67c2e9ea7ec45db65d1c3b95cd173f21/execroot/com_github_riselab_ray/java/modify_generated_java_flatbuffers_files.py", line 31, in add_new_line
    with open(file, "w") as file_handler:
PermissionError: [Errno 13] Permission denied: '/private/var/tmp/_bazel_haochen/67c2e9ea7ec45db65d1c3b95cd173f21/execroot/com_github_riselab_ray/java/runtime/src/main/java/org/ray/runtime/generated/ConfigTableData.java'

It seems that we need to chmod the generated files.

I forgot to be compatible with the mac system, i will fix it in the pr.

ruifangChen and others added 11 commits March 6, 2019 19:12
delete the setting of -Djava.library.path
Modified according to the recommendations of raulchen

Co-Authored-By: alegithub111 <ruif_chen111@126.com>
Modified according to the recommendations of raulchen
Modified according to the recommendations of raulchen
add the mvn ckeckstyle
Revert accidentally deleted code
Delete useless comments
build.sh Outdated
ln -sf $ROOT_DIR/bazel-genfiles/redis-server $ROOT_DIR/build/src/ray/thirdparty/redis/src/redis-server
ln -sf $ROOT_DIR/bazel-bin/ray_redis_module.so $ROOT_DIR/build/src/ray/gcs/redis_module/libray_redis_module.so
ln -sf $ROOT_DIR/bazel-bin/external/plasma/plasma_store_server $ROOT_DIR/build/src/plasma/plasma_store_server
ln -sf $ROOT_DIR/bazel-bin/raylet $ROOT_DIR/build/src/ray/raylet/raylet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just link these files to java/build (also need to change code accordingly). because after this PR, we don't need to support cmake.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if don't support cmake, we can delete these links and change the code.

java/build.sh Outdated
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

mvn clean install -Dmaven.test.skip
bazel build -c opt //java:all
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, this file isn't being used any more, we can just delete it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leave the job to developers

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's not used, the file should be deleted as part of this PR I'd say

@@ -0,0 +1,1577 @@
# The following dependencies were calculated from:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't auto-generate this file in this PR, let's leave a TODO comment here to take a note.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So do we truely need all these dependencies? It seems to me that this file could be slimmed down a lot, for example GRPC should not be needed to build this.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/13143/
Test FAILed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/13146/
Test FAILed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/13153/
Test FAILed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/13155/
Test FAILed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/13158/
Test FAILed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/13176/
Test PASSed.

@raulchen
Copy link
Contributor

Fixed some bugs, and CI is finally passing.

@raulchen raulchen closed this Mar 22, 2019
@raulchen
Copy link
Contributor

@pcmoritz any luck with #4385?

@raulchen raulchen reopened this Mar 22, 2019
@pcmoritz
Copy link
Contributor

pcmoritz commented Mar 22, 2019

@raulchen: Awesome! #4385 is done now and just needs to be merged, see apache/arrow#4001. I'm also happy to merge this one first, depending on which one is ready first. One thing I still don't like about this is that java/third_party/workspace.bzl is checked in, is there no way to autogenerate that? Maybe it could be done before any other bazel command is run, so we can refer to it from the other Bazel files?

@raulchen
Copy link
Contributor

@pcmoritz java/third_party/workspace.bzl is kind of tricky to deal with. It needs to be present before running any bazel command. Because it's referenced by the WORKSPACE file.
I searched around in github, all repos using the bazel-deps tool have to check in this file.
An alternative solution is using a script to generate it before running bazel. But it means that we'll need to run this script even if we only build Python. Because otherwise, the WORKSPACE file is invalid.
I'll do more research, and try to improve this in the next PR.

Copy link
Contributor

@pcmoritz pcmoritz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, sounds good to me!

@raulchen
Copy link
Contributor

@pcmoritz Thanks. I'll merge this one first.

@raulchen raulchen merged commit 59d74d5 into ray-project:master Mar 22, 2019
@raulchen raulchen deleted the ruifang.crf_stage branch March 22, 2019 06:30
@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/13179/
Test PASSed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants