diff --git a/bazel/ray.bzl b/bazel/ray.bzl index 169eeab24..53fc0adee 100644 --- a/bazel/ray.bzl +++ b/bazel/ray.bzl @@ -1,5 +1,4 @@ load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_library_public") -load("@com_github_checkstyle_java//checkstyle:checkstyle.bzl", "checkstyle_test") load("@bazel_skylib//rules:copy_file.bzl", "copy_file") load("@bazel_common//tools/maven:pom_file.bzl", "pom_file") @@ -77,14 +76,6 @@ def define_java_module( resources = native.glob([name + "/src/main/resources/**"]) + additional_resources, **kwargs ) - checkstyle_test( - name = "io_ray_ray_" + name + "-checkstyle", - target = ":io_ray_ray_" + name, - config = "//java:checkstyle.xml", - suppressions = "//java:checkstyle-suppressions.xml", - size = "small", - tags = ["checkstyle"], - ) if define_test_lib: test_lib_name = "io_ray_ray_" + name + "_test" pom_file_targets.append(test_lib_name) @@ -93,14 +84,6 @@ def define_java_module( srcs = native.glob([name + "/src/test/java/**/*.java"]), deps = test_deps, ) - checkstyle_test( - name = "io_ray_ray_" + name + "_test-checkstyle", - target = ":io_ray_ray_" + name + "_test", - config = "//java:checkstyle.xml", - suppressions = "//java:checkstyle-suppressions.xml", - size = "small", - tags = ["checkstyle"], - ) pom_file( name = "io_ray_ray_" + name + "_pom", targets = pom_file_targets, diff --git a/bazel/ray_deps_build_all.bzl b/bazel/ray_deps_build_all.bzl index 4d4d3632e..a81480664 100644 --- a/bazel/ray_deps_build_all.bzl +++ b/bazel/ray_deps_build_all.bzl @@ -3,7 +3,6 @@ load("@com_github_ray_project_ray//java:dependencies.bzl", "gen_java_deps") load("@com_github_ray_project_ray//streaming/java:dependencies.bzl", "gen_streaming_java_deps") load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps") load("@com_github_jupp0r_prometheus_cpp//bazel:repositories.bzl", "prometheus_cpp_repositories") -load("@com_github_checkstyle_java//:repo.bzl", "checkstyle_deps") load("@com_github_grpc_grpc//third_party/py:python_configure.bzl", "python_configure") load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps") load("@rules_proto_grpc//:repositories.bzl", "rules_proto_grpc_toolchains") @@ -13,7 +12,6 @@ def ray_deps_build_all(): bazel_skylib_workspace() gen_java_deps() gen_streaming_java_deps() - checkstyle_deps() boost_deps() prometheus_cpp_repositories() python_configure(name = "local_config_python") diff --git a/bazel/ray_deps_setup.bzl b/bazel/ray_deps_setup.bzl index 02bda17cc..5a26e9696 100644 --- a/bazel/ray_deps_setup.bzl +++ b/bazel/ray_deps_setup.bzl @@ -131,12 +131,6 @@ def ray_deps_setup(): sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44", ) - auto_http_archive( - name = "com_github_checkstyle_java", - url = "https://github.com/ray-project/checkstyle_java/archive/ef367030d1433877a3360bbfceca18a5d0791bdd.tar.gz", - sha256 = "847d391156d7dcc9424e6a8ba06ff23ea2914c725b18d92028074b2ed8de3da9", - ) - auto_http_archive( # This rule is used by @com_github_nelhage_rules_boost and # declaring it here allows us to avoid patching the latter. diff --git a/ci/travis/format.sh b/ci/travis/format.sh index 7a6b45751..3f4b753f4 100755 --- a/ci/travis/format.sh +++ b/ci/travis/format.sh @@ -49,6 +49,7 @@ FLAKE8_VERSION=$(flake8 --version | head -n 1 | awk '{print $1}') YAPF_VERSION=$(yapf --version | awk '{print $2}') SHELLCHECK_VERSION=$(shellcheck --version | awk '/^version:/ {print $2}') MYPY_VERSION=$(mypy --version | awk '{print $2}') +GOOGLE_JAVA_FORMAT_JAR=/tmp/google-java-format-1.7-all-deps.jar # params: tool name, tool version, required version tool_version_check() { @@ -69,6 +70,15 @@ else echo "WARNING: clang-format is not installed!" fi +if command -v java >/dev/null; then + if [ ! -f "$GOOGLE_JAVA_FORMAT_JAR" ]; then + echo "Java code format tool google-java-format.jar is not installed, start to install it." + wget https://github.com/google/google-java-format/releases/download/google-java-format-1.7/google-java-format-1.7-all-deps.jar -O "$GOOGLE_JAVA_FORMAT_JAR" + fi +else + echo "WARNING:java is not installed, skip format java files!" +fi + if [[ $(flake8 --version) != *"flake8_quotes"* ]]; then echo "WARNING: Ray uses flake8 with flake8_quotes. Might error without it. Install with: pip install flake8-quotes" fi @@ -112,6 +122,18 @@ GIT_LS_EXCLUDES=( ':(exclude)python/ray/cloudpickle/' ) +JAVA_EXCLUDES=( + 'java/api/src/main/java/io/ray/api/ActorCall.java' + 'java/api/src/main/java/io/ray/api/PyActorCall.java' + 'java/api/src/main/java/io/ray/api/RayCall.java' +) + +JAVA_EXCLUDES_REGEX="" +for f in "${JAVA_EXCLUDES[@]}"; do + JAVA_EXCLUDES_REGEX="$JAVA_EXCLUDES_REGEX|(${f//\//\/})" +done +JAVA_EXCLUDES_REGEX=${JAVA_EXCLUDES_REGEX#|} + # TODO(barakmich): This should be cleaned up. I've at least excised the copies # of these arguments to this location, but the long-term answer is to actually # make a flake8 config file @@ -132,7 +154,6 @@ mypy_on_each() { popd } - # Format specified files format_files() { local shell_files=() python_files=() bazel_files=() @@ -205,6 +226,11 @@ format_all() { git ls-files -- '*.cc' '*.h' '*.proto' "${GIT_LS_EXCLUDES[@]}" | xargs -P 5 clang-format -i fi + echo "$(date)" "format java...." + if command -v java >/dev/null & [ -f "$GOOGLE_JAVA_FORMAT_JAR" ]; then + git ls-files -- '*.java' "${GIT_LS_EXCLUDES[@]}" | sed -E "\:$JAVA_EXCLUDES_REGEX:d" | xargs -P 5 java -jar "$GOOGLE_JAVA_FORMAT_JAR" -i + fi + if command -v shellcheck >/dev/null; then local shell_files non_shell_files non_shell_files=($(git ls-files -- ':(exclude)*.sh')) @@ -254,6 +280,12 @@ format_changed() { fi fi + if command -v java >/dev/null & [ -f "$GOOGLE_JAVA_FORMAT_JAR" ]; then + if ! git diff --diff-filter=ACRM --quiet --exit-code "$MERGEBASE" -- '*.java' &>/dev/null; then + git diff --name-only --diff-filter=ACRM "$MERGEBASE" -- '*.java' | sed -E "\:$JAVA_EXCLUDES_REGEX:d" | xargs -P 5 java -jar "$GOOGLE_JAVA_FORMAT_JAR" -i + fi + fi + if command -v shellcheck >/dev/null; then local shell_files non_shell_files non_shell_files=($(git diff --name-only --diff-filter=ACRM "$MERGEBASE" -- ':(exclude)*.sh')) diff --git a/java/api/src/main/java/io/ray/api/ActorHandle.java b/java/api/src/main/java/io/ray/api/ActorHandle.java index 0d9c499c6..682698d9f 100644 --- a/java/api/src/main/java/io/ray/api/ActorHandle.java +++ b/java/api/src/main/java/io/ray/api/ActorHandle.java @@ -1,11 +1,12 @@ package io.ray.api; /** - * A handle to a Java actor.
+ * A handle to a Java actor. * - * A handle can be used to invoke a remote actor method, with the {@code "call"} method. For + *
A handle can be used to invoke a remote actor method, with the {@code "call"} method. For * example: - *
{@code
+ *
+ * {@code
* class MyActor {
* public int echo(int x) {
* return x;
@@ -19,11 +20,9 @@ package io.ray.api;
* Assert.assertEqual(result.get(), 1);
* }
*
- * Note, the {@code "call"} method is defined in {@link ActorCall} interface, with multiple
+ * Note, the {@code "call"} method is defined in {@link ActorCall} interface, with multiple
* overloaded versions.
*
* @param The type of the concrete actor class.
*/
-public interface ActorHandle extends BaseActorHandle, ActorCall {
-
-}
+public interface ActorHandle extends BaseActorHandle, ActorCall {}
diff --git a/java/api/src/main/java/io/ray/api/BaseActorHandle.java b/java/api/src/main/java/io/ray/api/BaseActorHandle.java
index 07360f723..bd875d075 100644
--- a/java/api/src/main/java/io/ray/api/BaseActorHandle.java
+++ b/java/api/src/main/java/io/ray/api/BaseActorHandle.java
@@ -3,15 +3,13 @@ package io.ray.api;
import io.ray.api.id.ActorId;
/**
- * A handle to an actor.
+ * A handle to an actor.
*
- * A handle can be used to invoke a remote actor method.
+ *
A handle can be used to invoke a remote actor method.
*/
public interface BaseActorHandle {
- /**
- * @return The id of this actor.
- */
+ /** Returns the id of this actor. */
ActorId getId();
/**
diff --git a/java/api/src/main/java/io/ray/api/ObjectRef.java b/java/api/src/main/java/io/ray/api/ObjectRef.java
index 6b58781dc..23e67f3f5 100644
--- a/java/api/src/main/java/io/ray/api/ObjectRef.java
+++ b/java/api/src/main/java/io/ray/api/ObjectRef.java
@@ -2,15 +2,14 @@ package io.ray.api;
/**
* Represents a reference to an object in the object store.
+ *
* @param The object type.
*/
public interface ObjectRef {
/**
- * Fetch the object from the object store, this method will block
- * until the object is locally available.
+ * Fetch the object from the object store, this method will block until the object is locally
+ * available.
*/
T get();
-
}
-
diff --git a/java/api/src/main/java/io/ray/api/PyActorHandle.java b/java/api/src/main/java/io/ray/api/PyActorHandle.java
index 01fb2dc4d..a2d603971 100644
--- a/java/api/src/main/java/io/ray/api/PyActorHandle.java
+++ b/java/api/src/main/java/io/ray/api/PyActorHandle.java
@@ -1,18 +1,11 @@
package io.ray.api;
-/**
- * Handle of a Python actor.
- */
+/** Handle of a Python actor. */
public interface PyActorHandle extends BaseActorHandle, PyActorCall {
- /**
- * @return Module name of the Python actor class.
- */
+ /** Returns the module name of the Python actor class. */
String getModuleName();
- /**
- * @return Name of the Python actor class.
- */
+ /** Returns the name of the Python actor class. */
String getClassName();
}
-
diff --git a/java/api/src/main/java/io/ray/api/Ray.java b/java/api/src/main/java/io/ray/api/Ray.java
index 7763fae43..3100d60a1 100644
--- a/java/api/src/main/java/io/ray/api/Ray.java
+++ b/java/api/src/main/java/io/ray/api/Ray.java
@@ -12,16 +12,12 @@ import java.util.Map;
import java.util.Optional;
import java.util.concurrent.Callable;
-/**
- * This class contains all public APIs of Ray.
- */
+/** This class contains all public APIs of Ray. */
public final class Ray extends RayCall {
private static RayRuntime runtime = null;
- /**
- * Initialize Ray runtime with the default runtime implementation.
- */
+ /** Initialize Ray runtime with the default runtime implementation. */
public static void init() {
try {
Class clz = Class.forName("io.ray.runtime.DefaultRayRuntimeFactory");
@@ -30,7 +26,6 @@ public final class Ray extends RayCall {
} catch (Exception e) {
throw new RuntimeException("Failed to initialize Ray runtime.", e);
}
-
}
/**
@@ -45,9 +40,7 @@ public final class Ray extends RayCall {
}
}
- /**
- * Shutdown Ray runtime.
- */
+ /** Shutdown Ray runtime. */
public static synchronized void shutdown() {
if (runtime != null) {
internal().shutdown();
@@ -57,7 +50,8 @@ public final class Ray extends RayCall {
/**
* Check if {@link #init} has been called yet.
- * @return True if {@link #init} has already been called and false otherwise.
+ *
+ * Returns True if {@link #init} has already been called and false otherwise.
*/
public static boolean isInitialized() {
return runtime != null;
@@ -66,8 +60,8 @@ public final class Ray extends RayCall {
/**
* Store an object in the object store.
*
- * @param obj The Java object to be stored.
- * @return A ObjectRef instance that represents the in-store object.
+ * @param obj The Java object to be stored. Returns A ObjectRef instance that represents the
+ * in-store object.
*/
public static ObjectRef put(T obj) {
return internal().put(obj);
@@ -76,8 +70,7 @@ public final class Ray extends RayCall {
/**
* Get an object by `ObjectRef` from the object store.
*
- * @param objectRef The reference of the object to get.
- * @return The Java object.
+ * @param objectRef The reference of the object to get. Returns The Java object.
*/
public static T get(ObjectRef objectRef) {
return internal().get(objectRef);
@@ -86,45 +79,43 @@ public final class Ray extends RayCall {
/**
* Get a list of objects by `ObjectRef`s from the object store.
*
- * @param objectList A list of object references.
- * @return A list of Java objects.
+ * @param objectList A list of object references. Returns A list of Java objects.
*/
public static List get(List> objectList) {
return internal().get(objectList);
}
/**
- * Wait for a list of RayObjects to be locally available,
- * until specified number of objects are ready, or specified timeout has passed.
+ * Wait for a list of RayObjects to be locally available, until specified number of objects are
+ * ready, or specified timeout has passed.
*
* @param waitList A list of object references to wait for.
* @param numReturns The number of objects that should be returned.
- * @param timeoutMs The maximum time in milliseconds to wait before returning.
- * @return Two lists, one containing locally available objects, one containing the rest.
+ * @param timeoutMs The maximum time in milliseconds to wait before returning. Returns Two lists,
+ * one containing locally available objects, one containing the rest.
*/
- public static WaitResult wait(List> waitList, int numReturns,
- int timeoutMs) {
+ public static WaitResult wait(List> waitList, int numReturns, int timeoutMs) {
return internal().wait(waitList, numReturns, timeoutMs);
}
/**
- * A convenient helper method for Ray.wait. It will wait infinitely until
- * specified number of objects are locally available.
+ * A convenient helper method for Ray.wait. It will wait infinitely until specified number of
+ * objects are locally available.
*
* @param waitList A list of object references to wait for.
- * @param numReturns The number of objects that should be returned.
- * @return Two lists, one containing locally available objects, one containing the rest.
+ * @param numReturns The number of objects that should be returned. Returns Two lists, one
+ * containing locally available objects, one containing the rest.
*/
public static WaitResult wait(List> waitList, int numReturns) {
return internal().wait(waitList, numReturns, Integer.MAX_VALUE);
}
/**
- * A convenient helper method for Ray.wait. It will wait infinitely until
- * all objects are locally available.
+ * A convenient helper method for Ray.wait. It will wait infinitely until all objects are locally
+ * available.
*
- * @param waitList A list of object references to wait for.
- * @return Two lists, one containing locally available objects, one containing the rest.
+ * @param waitList A list of object references to wait for. Returns Two lists, one containing
+ * locally available objects, one containing the rest.
*/
public static WaitResult wait(List> waitList) {
return internal().wait(waitList, waitList.size(), Integer.MAX_VALUE);
@@ -132,13 +123,12 @@ public final class Ray extends RayCall {
/**
* Get a handle to a named actor of current job.
- *
- * Gets a handle to a named actor with the given name. The actor must
- * have been created with name specified.
*
- * @param name The name of the named actor.
- * @return an ActorHandle to the actor if the actor of specified name exists or an
- * Optional.empty()
+ *
Gets a handle to a named actor with the given name. The actor must have been created with
+ * name specified.
+ *
+ * @param name The name of the named actor. Returns an ActorHandle to the actor if the actor of
+ * specified name exists or an Optional.empty()
*/
public static Optional getActor(String name) {
return internal().getActor(name, false);
@@ -146,13 +136,12 @@ public final class Ray extends RayCall {
/**
* Get a handle to a global named actor.
- *
- * Gets a handle to a global named actor with the given name. The actor must
- * have been created with global name specified.
*
- * @param name The global name of the named actor.
- * @return an ActorHandle to the actor if the actor of specified name exists or an
- * Optional.empty()
+ *
Gets a handle to a global named actor with the given name. The actor must have been created
+ * with global name specified.
+ *
+ * @param name The global name of the named actor. Returns an ActorHandle to the actor if the
+ * actor of specified name exists or an Optional.empty()
*/
public static Optional getGlobalActor(String name) {
return internal().getActor(name, true);
@@ -162,7 +151,7 @@ public final class Ray extends RayCall {
* If users want to use Ray API in their own threads, call this method to get the async context
* and then call {@link #setAsyncContext} at the beginning of the new thread.
*
- * @return The async context.
+ * Returns The async context.
*/
public static Object getAsyncContext() {
return internal().getAsyncContext();
@@ -186,8 +175,7 @@ public final class Ray extends RayCall {
* If users want to use Ray API in their own threads, they should wrap their {@link Runnable}
* objects with this method.
*
- * @param runnable The runnable to wrap.
- * @return The wrapped runnable.
+ * @param runnable The runnable to wrap. Returns The wrapped runnable.
*/
public static Runnable wrapRunnable(Runnable runnable) {
return internal().wrapRunnable(runnable);
@@ -197,16 +185,13 @@ public final class Ray extends RayCall {
* If users want to use Ray API in their own threads, they should wrap their {@link Callable}
* objects with this method.
*
- * @param callable The callable to wrap.
- * @return The wrapped callable.
+ * @param callable The callable to wrap. Returns The wrapped callable.
*/
public static Callable wrapCallable(Callable callable) {
return internal().wrapCallable(callable);
}
- /**
- * Get the underlying runtime instance.
- */
+ /** Get the underlying runtime instance. */
public static RayRuntime internal() {
if (runtime == null) {
throw new IllegalStateException(
@@ -215,59 +200,49 @@ public final class Ray extends RayCall {
return runtime;
}
- /**
- * Update the resource for the specified client.
- * Set the resource for the specific node.
- */
+ /** Update the resource for the specified client. Set the resource for the specific node. */
public static void setResource(UniqueId nodeId, String resourceName, double capacity) {
internal().setResource(resourceName, capacity, nodeId);
}
- /**
- * Set the resource for local node.
- */
+ /** Set the resource for local node. */
public static void setResource(String resourceName, double capacity) {
internal().setResource(resourceName, capacity, UniqueId.NIL);
}
- /**
- * Get the runtime context.
- */
+ /** Get the runtime context. */
public static RuntimeContext getRuntimeContext() {
return internal().getRuntimeContext();
}
/**
- * Create a placement group.
- * A placement group is used to place actors according to a specific strategy
- * and resource constraints.
- * It will sends a request to GCS to preallocate the specified resources, which is asynchronous.
- * If the specified resource cannot be allocated, it will wait for the resource
- * to be updated and rescheduled.
- * This function only works when gcs actor manager is turned on.
+ * Create a placement group. A placement group is used to place actors according to a specific
+ * strategy and resource constraints. It will sends a request to GCS to preallocate the specified
+ * resources, which is asynchronous. If the specified resource cannot be allocated, it will wait
+ * for the resource to be updated and rescheduled. This function only works when gcs actor manager
+ * is turned on.
*
* @param name Name of the placement group.
* @param bundles Pre-allocated resource list.
- * @param strategy Actor placement strategy.
- * @return A handle to the created placement group.
+ * @param strategy Actor placement strategy. Returns A handle to the created placement group.
*/
- public static PlacementGroup createPlacementGroup(String name,
- List