mirror of
https://github.com/vale981/ray
synced 2025-03-05 10:01:43 -05:00
[Java] Format ray java code (#13056)
This commit is contained in:
parent
cc1c2c3dc9
commit
d1dd3410c8
422 changed files with 4384 additions and 5035 deletions
|
@ -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,
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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'))
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package io.ray.api;
|
||||
|
||||
/**
|
||||
* A handle to a Java actor. <p>
|
||||
* A handle to a Java actor.
|
||||
*
|
||||
* A handle can be used to invoke a remote actor method, with the {@code "call"} method. For
|
||||
* <p>A handle can be used to invoke a remote actor method, with the {@code "call"} method. For
|
||||
* example:
|
||||
* <pre> {@code
|
||||
*
|
||||
* <pre>{@code
|
||||
* class MyActor {
|
||||
* public int echo(int x) {
|
||||
* return x;
|
||||
|
@ -19,11 +20,9 @@ package io.ray.api;
|
|||
* Assert.assertEqual(result.get(), 1);
|
||||
* }</pre>
|
||||
*
|
||||
* Note, the {@code "call"} method is defined in {@link ActorCall} interface, with multiple
|
||||
* <p>Note, the {@code "call"} method is defined in {@link ActorCall} interface, with multiple
|
||||
* overloaded versions.
|
||||
*
|
||||
* @param <A> The type of the concrete actor class.
|
||||
*/
|
||||
public interface ActorHandle<A> extends BaseActorHandle, ActorCall<A> {
|
||||
|
||||
}
|
||||
public interface ActorHandle<A> extends BaseActorHandle, ActorCall<A> {}
|
||||
|
|
|
@ -3,15 +3,13 @@ package io.ray.api;
|
|||
import io.ray.api.id.ActorId;
|
||||
|
||||
/**
|
||||
* A handle to an actor. <p>
|
||||
* A handle to an actor.
|
||||
*
|
||||
* A handle can be used to invoke a remote actor method.
|
||||
* <p>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();
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,15 +2,14 @@ package io.ray.api;
|
|||
|
||||
/**
|
||||
* Represents a reference to an object in the object store.
|
||||
*
|
||||
* @param <T> The object type.
|
||||
*/
|
||||
public interface ObjectRef<T> {
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* <p>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 <T> ObjectRef<T> 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> T get(ObjectRef<T> 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 <T> List<T> get(List<ObjectRef<T>> 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 <T> WaitResult<T> wait(List<ObjectRef<T>> waitList, int numReturns,
|
||||
int timeoutMs) {
|
||||
public static <T> WaitResult<T> wait(List<ObjectRef<T>> 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 <T> WaitResult<T> wait(List<ObjectRef<T>> 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 <T> WaitResult<T> wait(List<ObjectRef<T>> 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.
|
||||
* <p>
|
||||
* 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()
|
||||
* <p>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 <T extends BaseActorHandle> Optional<T> 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.
|
||||
* <p>
|
||||
* 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()
|
||||
* <p>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 <T extends BaseActorHandle> Optional<T> 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.
|
||||
* <p>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 <T> Callable<T> wrapCallable(Callable<T> 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<Map<String, Double>> bundles, PlacementStrategy strategy) {
|
||||
public static PlacementGroup createPlacementGroup(
|
||||
String name, List<Map<String, Double>> bundles, PlacementStrategy strategy) {
|
||||
return internal().createPlacementGroup(name, bundles, strategy);
|
||||
}
|
||||
|
||||
public static PlacementGroup createPlacementGroup(List<Map<String, Double>> bundles,
|
||||
PlacementStrategy strategy) {
|
||||
public static PlacementGroup createPlacementGroup(
|
||||
List<Map<String, Double>> bundles, PlacementStrategy strategy) {
|
||||
return internal().createPlacementGroup(bundles, strategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Intentionally exit the current actor.
|
||||
* <p>
|
||||
* This method is used to disconnect an actor and exit the worker.
|
||||
*
|
||||
* @throws RuntimeException An exception is raised if this is a driver or this worker is not
|
||||
* an actor.
|
||||
* <p>This method is used to disconnect an actor and exit the worker.
|
||||
*
|
||||
* @throws RuntimeException An exception is raised if this is a driver or this worker is not an
|
||||
* actor.
|
||||
*/
|
||||
public static void exitActor() {
|
||||
runtime.exitActor();
|
||||
|
@ -275,8 +250,8 @@ public final class Ray extends RayCall {
|
|||
|
||||
/**
|
||||
* Get a placement group by placement group Id.
|
||||
* @param id placement group id.
|
||||
* @return The placement group.
|
||||
*
|
||||
* @param id placement group id. Returns The placement group.
|
||||
*/
|
||||
public static PlacementGroup getPlacementGroup(PlacementGroupId id) {
|
||||
return internal().getPlacementGroup(id);
|
||||
|
@ -284,15 +259,16 @@ public final class Ray extends RayCall {
|
|||
|
||||
/**
|
||||
* Get all placement groups in this cluster.
|
||||
* @return All placement groups.
|
||||
*
|
||||
* <p>Returns All placement groups.
|
||||
*/
|
||||
public static List<PlacementGroup> getAllPlacementGroups() {
|
||||
return internal().getAllPlacementGroups();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a placement group by id.
|
||||
* Throw RayException if remove failed.
|
||||
* Remove a placement group by id. Throw RayException if remove failed.
|
||||
*
|
||||
* @param id Id of the placement group.
|
||||
*/
|
||||
public static void removePlacementGroup(PlacementGroupId id) {
|
||||
|
|
|
@ -3,8 +3,8 @@ package io.ray.api;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents the result of a Ray.wait call. It contains 2 lists,
|
||||
* one containing the locally available objects, one containing the rest.
|
||||
* Represents the result of a Ray.wait call. It contains 2 lists, one containing the locally
|
||||
* available objects, one containing the rest.
|
||||
*/
|
||||
public final class WaitResult<T> {
|
||||
|
||||
|
@ -16,18 +16,13 @@ public final class WaitResult<T> {
|
|||
this.unready = unready;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of ready objects.
|
||||
*/
|
||||
/** Get the list of ready objects. */
|
||||
public List<ObjectRef<T>> getReady() {
|
||||
return ready;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of unready objects.
|
||||
*/
|
||||
/** Get the list of unready objects. */
|
||||
public List<ObjectRef<T>> getUnready() {
|
||||
return unready;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,10 +21,9 @@ public class ActorCreator<A> extends BaseActorCreator<ActorCreator<A>> {
|
|||
/**
|
||||
* Set the JVM options for the Java worker that this actor is running in.
|
||||
*
|
||||
* Note, if this is set, this actor won't share Java worker with other actors or tasks.
|
||||
* <p>Note, if this is set, this actor won't share Java worker with other actors or tasks.
|
||||
*
|
||||
* @param jvmOptions JVM options for the Java worker that this actor is running in.
|
||||
* @return self
|
||||
* @param jvmOptions JVM options for the Java worker that this actor is running in. Returns self
|
||||
* @see io.ray.api.options.ActorCreationOptions.Builder#setJvmOptions(java.lang.String)
|
||||
*/
|
||||
public ActorCreator<A> setJvmOptions(String jvmOptions) {
|
||||
|
@ -35,10 +34,9 @@ public class ActorCreator<A> extends BaseActorCreator<ActorCreator<A>> {
|
|||
/**
|
||||
* Create a java actor remotely and return a handle to the created actor.
|
||||
*
|
||||
* @return a handle to the created java actor.
|
||||
* <p>Returns a handle to the created java actor.
|
||||
*/
|
||||
public ActorHandle<A> remote() {
|
||||
return Ray.internal().createActor(func, args, buildOptions());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,11 +25,10 @@ public class ActorTaskCaller<R> {
|
|||
* Execute an java actor method remotely and return an object reference to the result object in
|
||||
* the object store.
|
||||
*
|
||||
* @return an object reference to an object in the object store.
|
||||
* <p>Returns an object reference to an object in the object store.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ObjectRef<R> remote() {
|
||||
return Ray.internal().callActor(actor, func, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,13 +14,11 @@ public class BaseActorCreator<T extends BaseActorCreator> {
|
|||
protected ActorCreationOptions.Builder builder = new ActorCreationOptions.Builder();
|
||||
|
||||
/**
|
||||
* Set the actor name of a named actor.
|
||||
* This named actor is only accessible from this job by this name via
|
||||
* {@link Ray#getActor(java.lang.String)}. If you want create a named actor that is accessible
|
||||
* from all jobs, use {@link BaseActorCreator#setGlobalName(java.lang.String)} instead.
|
||||
* Set the actor name of a named actor. This named actor is only accessible from this job by this
|
||||
* name via {@link Ray#getActor(java.lang.String)}. If you want create a named actor that is
|
||||
* accessible from all jobs, use {@link BaseActorCreator#setGlobalName(java.lang.String)} instead.
|
||||
*
|
||||
* @param name The name of the named actor.
|
||||
* @return self
|
||||
* @param name The name of the named actor. Returns self
|
||||
* @see io.ray.api.options.ActorCreationOptions.Builder#setName(String)
|
||||
*/
|
||||
public T setName(String name) {
|
||||
|
@ -29,12 +27,11 @@ public class BaseActorCreator<T extends BaseActorCreator> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set the name of this actor. This actor will be accessible from all jobs by this name via
|
||||
* {@link Ray#getGlobalActor(java.lang.String)}. If you want to create a named actor that is
|
||||
* only accessible from this job, use {@link BaseActorCreator#setName(java.lang.String)} instead.
|
||||
* Set the name of this actor. This actor will be accessible from all jobs by this name via {@link
|
||||
* Ray#getGlobalActor(java.lang.String)}. If you want to create a named actor that is only
|
||||
* accessible from this job, use {@link BaseActorCreator#setName(java.lang.String)} instead.
|
||||
*
|
||||
* @param name The name of the named actor.
|
||||
* @return self
|
||||
* @param name The name of the named actor. Returns self
|
||||
* @see io.ray.api.options.ActorCreationOptions.Builder#setGlobalName(String)
|
||||
*/
|
||||
public T setGlobalName(String name) {
|
||||
|
@ -43,13 +40,12 @@ public class BaseActorCreator<T extends BaseActorCreator> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set a custom resource requirement to reserve for the lifetime of this actor.
|
||||
* This method can be called multiple times. If the same resource is set multiple times,
|
||||
* the latest quantity will be used.
|
||||
* Set a custom resource requirement to reserve for the lifetime of this actor. This method can be
|
||||
* called multiple times. If the same resource is set multiple times, the latest quantity will be
|
||||
* used.
|
||||
*
|
||||
* @param resourceName resource name
|
||||
* @param resourceQuantity resource quantity
|
||||
* @return self
|
||||
* @param resourceQuantity resource quantity Returns self
|
||||
* @see ActorCreationOptions.Builder#setResource(java.lang.String, java.lang.Double)
|
||||
*/
|
||||
public T setResource(String resourceName, Double resourceQuantity) {
|
||||
|
@ -58,12 +54,11 @@ public class BaseActorCreator<T extends BaseActorCreator> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set custom resource requirements to reserve for the lifetime of this actor.
|
||||
* This method can be called multiple times. If the same resource is set multiple times,
|
||||
* the latest quantity will be used.
|
||||
* Set custom resource requirements to reserve for the lifetime of this actor. This method can be
|
||||
* called multiple times. If the same resource is set multiple times, the latest quantity will be
|
||||
* used.
|
||||
*
|
||||
* @param resources requirements for multiple resources.
|
||||
* @return self
|
||||
* @param resources requirements for multiple resources. Returns self
|
||||
* @see BaseActorCreator#setResources(java.util.Map)
|
||||
*/
|
||||
public T setResources(Map<String, Double> resources) {
|
||||
|
@ -76,8 +71,7 @@ public class BaseActorCreator<T extends BaseActorCreator> {
|
|||
* unexpectedly. The minimum valid value is 0 (default), which indicates that the actor doesn't
|
||||
* need to be restarted. A value of -1 indicates that an actor should be restarted indefinitely.
|
||||
*
|
||||
* @param maxRestarts max number of actor restarts
|
||||
* @return self
|
||||
* @param maxRestarts max number of actor restarts Returns self
|
||||
* @see ActorCreationOptions.Builder#setMaxRestarts(int)
|
||||
*/
|
||||
public T setMaxRestarts(int maxRestarts) {
|
||||
|
@ -87,12 +81,11 @@ public class BaseActorCreator<T extends BaseActorCreator> {
|
|||
|
||||
/**
|
||||
* Set the max number of concurrent calls to allow for this actor.
|
||||
* <p>
|
||||
* The max concurrency defaults to 1 for threaded execution.
|
||||
* Note that the execution order is not guaranteed when {@code max_concurrency > 1}.
|
||||
*
|
||||
* @param maxConcurrency The max number of concurrent calls to allow for this actor.
|
||||
* @return self
|
||||
* <p>The max concurrency defaults to 1 for threaded execution. Note that the execution order is
|
||||
* not guaranteed when {@code max_concurrency > 1}.
|
||||
*
|
||||
* @param maxConcurrency The max number of concurrent calls to allow for this actor. Returns self
|
||||
* @see ActorCreationOptions.Builder#setMaxConcurrency(int)
|
||||
*/
|
||||
public T setMaxConcurrency(int maxConcurrency) {
|
||||
|
@ -104,8 +97,7 @@ public class BaseActorCreator<T extends BaseActorCreator> {
|
|||
* Set the placement group to place this actor in.
|
||||
*
|
||||
* @param group The placement group of the actor.
|
||||
* @param bundleIndex The index of the bundle to place this actor in.
|
||||
* @return self
|
||||
* @param bundleIndex The index of the bundle to place this actor in. Returns self
|
||||
* @see ActorCreationOptions.Builder#setPlacementGroup(PlacementGroup, int)
|
||||
*/
|
||||
public T setPlacementGroup(PlacementGroup group, int bundleIndex) {
|
||||
|
@ -121,5 +113,4 @@ public class BaseActorCreator<T extends BaseActorCreator> {
|
|||
protected ActorCreationOptions buildOptions() {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,8 +14,7 @@ public class BaseTaskCaller<T extends BaseTaskCaller<T>> {
|
|||
/**
|
||||
* Set a name for this task.
|
||||
*
|
||||
* @param name task name
|
||||
* @return self
|
||||
* @param name task name Returns self
|
||||
* @see CallOptions.Builder#setName(java.lang.String)
|
||||
*/
|
||||
public T setName(String name) {
|
||||
|
@ -28,8 +27,7 @@ public class BaseTaskCaller<T extends BaseTaskCaller<T>> {
|
|||
* times. If the same resource is set multiple times, the latest quantity will be used.
|
||||
*
|
||||
* @param name resource name
|
||||
* @param value resource capacity
|
||||
* @return self
|
||||
* @param value resource capacity Returns self
|
||||
* @see CallOptions.Builder#setResource(java.lang.String, java.lang.Double)
|
||||
*/
|
||||
public T setResource(String name, Double value) {
|
||||
|
@ -41,8 +39,7 @@ public class BaseTaskCaller<T extends BaseTaskCaller<T>> {
|
|||
* Set custom requirements for multiple resources. This method can be called multiple times. If
|
||||
* the same resource is set multiple times, the latest quantity will be used.
|
||||
*
|
||||
* @param resources requirements for multiple resources.
|
||||
* @return self
|
||||
* @param resources requirements for multiple resources. Returns self
|
||||
* @see CallOptions.Builder#setResources(java.util.Map)
|
||||
*/
|
||||
public T setResources(Map<String, Double> resources) {
|
||||
|
|
|
@ -4,9 +4,7 @@ import io.ray.api.PyActorHandle;
|
|||
import io.ray.api.Ray;
|
||||
import io.ray.api.function.PyActorClass;
|
||||
|
||||
/**
|
||||
* A helper to create python actor.
|
||||
*/
|
||||
/** A helper to create python actor. */
|
||||
public class PyActorCreator extends BaseActorCreator<PyActorCreator> {
|
||||
private final PyActorClass pyActorClass;
|
||||
private final Object[] args;
|
||||
|
@ -19,7 +17,7 @@ public class PyActorCreator extends BaseActorCreator<PyActorCreator> {
|
|||
/**
|
||||
* Create a python actor remotely and return a handle to the created actor.
|
||||
*
|
||||
* @return a handle to the created python actor.
|
||||
* <p>Returns a handle to the created python actor.
|
||||
*/
|
||||
public PyActorHandle remote() {
|
||||
return Ray.internal().createActor(pyActorClass, args, buildOptions());
|
||||
|
|
|
@ -25,11 +25,10 @@ public class PyActorTaskCaller<R> {
|
|||
* Execute a python actor method remotely and return an object reference to the result object in
|
||||
* the object store.
|
||||
*
|
||||
* @return an object reference to an object in the object store.
|
||||
* <p>Returns an object reference to an object in the object store.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ObjectRef<R> remote() {
|
||||
return Ray.internal().callActor(actor, method, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,11 +22,10 @@ public class PyTaskCaller<R> extends BaseTaskCaller<PyTaskCaller<R>> {
|
|||
* Execute a python function remotely and return an object reference to the result object in the
|
||||
* object store.
|
||||
*
|
||||
* @return an object reference to an object in the object store.
|
||||
* <p>Returns an object reference to an object in the object store.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ObjectRef<R> remote() {
|
||||
return Ray.internal().call(func, args, buildOptions());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class TaskCaller<R> extends BaseTaskCaller<TaskCaller<R>> {
|
|||
* Execute a java function remotely and return an object reference to the result object in the
|
||||
* object store.
|
||||
*
|
||||
* @return an object reference to an object in the object store.
|
||||
* <p>Returns an object reference to an object in the object store.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ObjectRef<R> remote() {
|
||||
|
|
|
@ -4,9 +4,7 @@ import io.ray.api.ActorHandle;
|
|||
import io.ray.api.Ray;
|
||||
import io.ray.api.function.RayFuncVoid;
|
||||
|
||||
/**
|
||||
* A helper to call java actor method which doesn't have a return value.
|
||||
*/
|
||||
/** A helper to call java actor method which doesn't have a return value. */
|
||||
public class VoidActorTaskCaller {
|
||||
private final ActorHandle actor;
|
||||
private final RayFuncVoid func;
|
||||
|
@ -18,11 +16,8 @@ public class VoidActorTaskCaller {
|
|||
this.args = args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a function remotely.
|
||||
*/
|
||||
/** Execute a function remotely. */
|
||||
public void remote() {
|
||||
Ray.internal().callActor(actor, func, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,7 @@ package io.ray.api.call;
|
|||
import io.ray.api.Ray;
|
||||
import io.ray.api.function.RayFuncVoid;
|
||||
|
||||
/**
|
||||
* A helper to call java remote function which doesn't have a return value.
|
||||
*/
|
||||
/** A helper to call java remote function which doesn't have a return value. */
|
||||
public class VoidTaskCaller extends BaseTaskCaller<VoidTaskCaller> {
|
||||
private final RayFuncVoid func;
|
||||
private final Object[] args;
|
||||
|
@ -15,11 +13,8 @@ public class VoidTaskCaller extends BaseTaskCaller<VoidTaskCaller> {
|
|||
this.args = args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a function remotely.
|
||||
*/
|
||||
/** Execute a function remotely. */
|
||||
public void remote() {
|
||||
Ray.internal().call(func, args, buildOptions());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,11 +38,9 @@ public class PyActorClass {
|
|||
* Create a python actor class.
|
||||
*
|
||||
* @param moduleName The full module name of this actor class
|
||||
* @param className The name of this actor class
|
||||
* @return a python actor class
|
||||
* @param className The name of this actor class Returns a python actor class
|
||||
*/
|
||||
public static PyActorClass of(String moduleName, String className) {
|
||||
return new PyActorClass(moduleName, className);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@ package io.ray.api.function;
|
|||
|
||||
/**
|
||||
* A class that represents a method of a Python actor.
|
||||
* <p>
|
||||
* Note, information about the actor will be inferred from the actor handle,
|
||||
* so it's not specified in this class.
|
||||
*
|
||||
* <p>Note, information about the actor will be inferred from the actor handle, so it's not
|
||||
* specified in this class.
|
||||
*
|
||||
* <pre>
|
||||
* there is a Python actor class A.
|
||||
|
@ -43,8 +43,7 @@ public class PyActorMethod<R> {
|
|||
/**
|
||||
* Create a python actor method.
|
||||
*
|
||||
* @param methodName The name of this actor method
|
||||
* @return a python actor method.
|
||||
* @param methodName The name of this actor method Returns a python actor method.
|
||||
*/
|
||||
public static PyActorMethod<Object> of(String methodName) {
|
||||
return of(methodName, Object.class);
|
||||
|
@ -55,11 +54,9 @@ public class PyActorMethod<R> {
|
|||
*
|
||||
* @param methodName The name of this actor method
|
||||
* @param returnType Class of the return value of this actor method
|
||||
* @param <R> The type of the return value of this actor method
|
||||
* @return a python actor method.
|
||||
* @param <R> The type of the return value of this actor method Returns a python actor method.
|
||||
*/
|
||||
public static <R> PyActorMethod<R> of(String methodName, Class<R> returnType) {
|
||||
return new PyActorMethod<>(methodName, returnType);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,11 +49,9 @@ public class PyFunction<R> {
|
|||
* Create a python function.
|
||||
*
|
||||
* @param moduleName The full module name of this function
|
||||
* @param functionName The name of this function
|
||||
* @return a python function.
|
||||
* @param functionName The name of this function Returns a python function.
|
||||
*/
|
||||
public static PyFunction<Object> of(
|
||||
String moduleName, String functionName) {
|
||||
public static PyFunction<Object> of(String moduleName, String functionName) {
|
||||
return of(moduleName, functionName, Object.class);
|
||||
}
|
||||
|
||||
|
@ -63,12 +61,9 @@ public class PyFunction<R> {
|
|||
* @param moduleName The full module name of this function
|
||||
* @param functionName The name of this function
|
||||
* @param returnType Class of the return value of this function
|
||||
* @param <R> Type of the return value of this function
|
||||
* @return a python function.
|
||||
* @param <R> Type of the return value of this function Returns a python function.
|
||||
*/
|
||||
public static <R> PyFunction<R> of(
|
||||
String moduleName, String functionName, Class<R> returnType) {
|
||||
public static <R> PyFunction<R> of(String moduleName, String functionName, Class<R> returnType) {
|
||||
return new PyFunction<>(moduleName, functionName, returnType);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,8 +2,5 @@ package io.ray.api.function;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Base interface of all Ray remote java functions.
|
||||
*/
|
||||
public interface RayFunc extends Serializable {
|
||||
}
|
||||
/** Base interface of all Ray remote java functions. */
|
||||
public interface RayFunc extends Serializable {}
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
package io.ray.api.function;
|
||||
|
||||
/**
|
||||
* Functional interface for a remote function that has 0 parameter.
|
||||
*/
|
||||
/** Functional interface for a remote function that has 0 parameter. */
|
||||
@FunctionalInterface
|
||||
public interface RayFunc0<R> extends RayFuncR<R> {
|
||||
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
package io.ray.api.function;
|
||||
|
||||
/**
|
||||
* Functional interface for a remote function that has 1 parameter.
|
||||
*/
|
||||
/** Functional interface for a remote function that has 1 parameter. */
|
||||
@FunctionalInterface
|
||||
public interface RayFunc1<T0, R> extends RayFuncR<R> {
|
||||
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
package io.ray.api.function;
|
||||
|
||||
/**
|
||||
* Functional interface for a remote function that has 2 parameters.
|
||||
*/
|
||||
/** Functional interface for a remote function that has 2 parameters. */
|
||||
@FunctionalInterface
|
||||
public interface RayFunc2<T0, T1, R> extends RayFuncR<R> {
|
||||
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
package io.ray.api.function;
|
||||
|
||||
/**
|
||||
* Functional interface for a remote function that has 3 parameters.
|
||||
*/
|
||||
/** Functional interface for a remote function that has 3 parameters. */
|
||||
@FunctionalInterface
|
||||
public interface RayFunc3<T0, T1, T2, R> extends RayFuncR<R> {
|
||||
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
package io.ray.api.function;
|
||||
|
||||
/**
|
||||
* Functional interface for a remote function that has 4 parameters.
|
||||
*/
|
||||
/** Functional interface for a remote function that has 4 parameters. */
|
||||
@FunctionalInterface
|
||||
public interface RayFunc4<T0, T1, T2, T3, R> extends RayFuncR<R> {
|
||||
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
package io.ray.api.function;
|
||||
|
||||
/**
|
||||
* Functional interface for a remote function that has 5 parameters.
|
||||
*/
|
||||
/** Functional interface for a remote function that has 5 parameters. */
|
||||
@FunctionalInterface
|
||||
public interface RayFunc5<T0, T1, T2, T3, T4, R> extends RayFuncR<R> {
|
||||
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
package io.ray.api.function;
|
||||
|
||||
/**
|
||||
* Functional interface for a remote function that has 6 parameters.
|
||||
*/
|
||||
/** Functional interface for a remote function that has 6 parameters. */
|
||||
@FunctionalInterface
|
||||
public interface RayFunc6<T0, T1, T2, T3, T4, T5, R> extends RayFuncR<R> {
|
||||
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package io.ray.api.function;
|
||||
|
||||
/**
|
||||
* Interface of all Ray remote functions which have a return value
|
||||
* Interface of all Ray remote functions which have a return value.
|
||||
*
|
||||
* @param <R> Type of function return value
|
||||
*/
|
||||
public interface RayFuncR<R> extends RayFunc {
|
||||
|
||||
}
|
||||
public interface RayFuncR<R> extends RayFunc {}
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
package io.ray.api.function;
|
||||
|
||||
/**
|
||||
* Interface of all `RayFuncVoidX` classes.
|
||||
*/
|
||||
public interface RayFuncVoid extends RayFunc {
|
||||
|
||||
}
|
||||
/** Interface of all `RayFuncVoidX` classes. */
|
||||
public interface RayFuncVoid extends RayFunc {}
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
package io.ray.api.function;
|
||||
|
||||
/**
|
||||
* Functional interface for a remote function that has 0 parameter.
|
||||
*/
|
||||
/** Functional interface for a remote function that has 0 parameter. */
|
||||
@FunctionalInterface
|
||||
public interface RayFuncVoid0 extends RayFuncVoid {
|
||||
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
package io.ray.api.function;
|
||||
|
||||
/**
|
||||
* Functional interface for a remote function that has 1 parameter.
|
||||
*/
|
||||
/** Functional interface for a remote function that has 1 parameter. */
|
||||
@FunctionalInterface
|
||||
public interface RayFuncVoid1<T0> extends RayFuncVoid {
|
||||
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
package io.ray.api.function;
|
||||
|
||||
/**
|
||||
* Functional interface for a remote function that has 2 parameters.
|
||||
*/
|
||||
/** Functional interface for a remote function that has 2 parameters. */
|
||||
@FunctionalInterface
|
||||
public interface RayFuncVoid2<T0, T1> extends RayFuncVoid {
|
||||
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
package io.ray.api.function;
|
||||
|
||||
/**
|
||||
* Functional interface for a remote function that has 3 parameters.
|
||||
*/
|
||||
/** Functional interface for a remote function that has 3 parameters. */
|
||||
@FunctionalInterface
|
||||
public interface RayFuncVoid3<T0, T1, T2> extends RayFuncVoid {
|
||||
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
package io.ray.api.function;
|
||||
|
||||
/**
|
||||
* Functional interface for a remote function that has 4 parameters.
|
||||
*/
|
||||
/** Functional interface for a remote function that has 4 parameters. */
|
||||
@FunctionalInterface
|
||||
public interface RayFuncVoid4<T0, T1, T2, T3> extends RayFuncVoid {
|
||||
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
package io.ray.api.function;
|
||||
|
||||
/**
|
||||
* Functional interface for a remote function that has 5 parameters.
|
||||
*/
|
||||
/** Functional interface for a remote function that has 5 parameters. */
|
||||
@FunctionalInterface
|
||||
public interface RayFuncVoid5<T0, T1, T2, T3, T4> extends RayFuncVoid {
|
||||
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
package io.ray.api.function;
|
||||
|
||||
/**
|
||||
* Functional interface for a remote function that has 6 parameters.
|
||||
*/
|
||||
/** Functional interface for a remote function that has 6 parameters. */
|
||||
@FunctionalInterface
|
||||
public interface RayFuncVoid6<T0, T1, T2, T3, T4, T5> extends RayFuncVoid {
|
||||
|
||||
|
|
|
@ -25,18 +25,14 @@ public class ActorId extends BaseId implements Serializable {
|
|||
return new ActorId(bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a nil ActorId.
|
||||
*/
|
||||
/** Generate a nil ActorId. */
|
||||
private static ActorId nil() {
|
||||
byte[] b = new byte[LENGTH];
|
||||
Arrays.fill(b, (byte) 0xFF);
|
||||
return new ActorId(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an ActorId with random value. Used for local mode and test only.
|
||||
*/
|
||||
/** Generate an ActorId with random value. Used for local mode and test only. */
|
||||
public static ActorId fromRandom() {
|
||||
byte[] b = new byte[LENGTH];
|
||||
new Random().nextBytes(b);
|
||||
|
|
|
@ -11,34 +11,30 @@ public abstract class BaseId implements Serializable {
|
|||
private int hashCodeCache = 0;
|
||||
private Boolean isNilCache = null;
|
||||
|
||||
/**
|
||||
* Create a BaseId instance according to the input byte array.
|
||||
*/
|
||||
/** Create a BaseId instance according to the input byte array. */
|
||||
protected BaseId(byte[] id) {
|
||||
if (id.length != size()) {
|
||||
throw new IllegalArgumentException("Failed to construct BaseId, expect " + size()
|
||||
+ " bytes, but got " + id.length + " bytes.");
|
||||
throw new IllegalArgumentException(
|
||||
"Failed to construct BaseId, expect "
|
||||
+ size()
|
||||
+ " bytes, but got "
|
||||
+ id.length
|
||||
+ " bytes.");
|
||||
}
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the byte data of this id.
|
||||
*/
|
||||
/** Get the byte data of this id. */
|
||||
public byte[] getBytes() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the byte data to a ByteBuffer.
|
||||
*/
|
||||
/** Convert the byte data to a ByteBuffer. */
|
||||
public ByteBuffer toByteBuffer() {
|
||||
return ByteBuffer.wrap(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return True if this id is nil.
|
||||
*/
|
||||
/** Returns true if this id is nil. */
|
||||
public boolean isNil() {
|
||||
if (isNilCache == null) {
|
||||
boolean localIsNil = true;
|
||||
|
@ -55,7 +51,8 @@ public abstract class BaseId implements Serializable {
|
|||
|
||||
/**
|
||||
* Derived class should implement this function.
|
||||
* @return The length of this id in bytes.
|
||||
*
|
||||
* <p>Returns The length of this id in bytes.
|
||||
*/
|
||||
public abstract int size();
|
||||
|
||||
|
@ -96,5 +93,4 @@ public abstract class BaseId implements Serializable {
|
|||
bb.get(id);
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,32 +5,24 @@ import java.nio.ByteBuffer;
|
|||
import java.nio.ByteOrder;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Represents the id of a Ray job.
|
||||
*/
|
||||
/** Represents the id of a Ray job. */
|
||||
public class JobId extends BaseId implements Serializable {
|
||||
|
||||
public static final int LENGTH = 4;
|
||||
|
||||
public static final JobId NIL = genNil();
|
||||
|
||||
/**
|
||||
* Create a JobID instance according to the given bytes.
|
||||
*/
|
||||
/** Create a JobID instance according to the given bytes. */
|
||||
private JobId(byte[] id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a JobId from a given hex string.
|
||||
*/
|
||||
/** Create a JobId from a given hex string. */
|
||||
public static JobId fromHexString(String hex) {
|
||||
return new JobId(hexString2Bytes(hex));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a JobId from the given ByteBuffer.
|
||||
*/
|
||||
/** Creates a JobId from the given ByteBuffer. */
|
||||
public static JobId fromByteBuffer(ByteBuffer bb) {
|
||||
return new JobId(byteBuffer2Bytes(bb));
|
||||
}
|
||||
|
@ -49,9 +41,7 @@ public class JobId extends BaseId implements Serializable {
|
|||
return JobId.fromByteBuffer(wbb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a nil JobId.
|
||||
*/
|
||||
/** Generate a nil JobId. */
|
||||
private static JobId genNil() {
|
||||
byte[] b = new byte[LENGTH];
|
||||
Arrays.fill(b, (byte) 0xFF);
|
||||
|
|
|
@ -5,23 +5,17 @@ import java.nio.ByteBuffer;
|
|||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Represents the id of a Ray object.
|
||||
*/
|
||||
/** Represents the id of a Ray object. */
|
||||
public class ObjectId extends BaseId implements Serializable {
|
||||
|
||||
public static final int LENGTH = 28;
|
||||
|
||||
/**
|
||||
* Create an ObjectId from a ByteBuffer.
|
||||
*/
|
||||
/** Create an ObjectId from a ByteBuffer. */
|
||||
public static ObjectId fromByteBuffer(ByteBuffer bb) {
|
||||
return new ObjectId(byteBuffer2Bytes(bb));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an ObjectId with random value.
|
||||
*/
|
||||
/** Generate an ObjectId with random value. */
|
||||
public static ObjectId fromRandom() {
|
||||
// This is tightly coupled with ObjectID definition in C++. If that changes,
|
||||
// this must be changed as well.
|
||||
|
@ -41,5 +35,4 @@ public class ObjectId extends BaseId implements Serializable {
|
|||
public int size() {
|
||||
return LENGTH;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,9 +5,7 @@ import java.nio.ByteBuffer;
|
|||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Represents the id of a placement group.
|
||||
*/
|
||||
/** Represents the id of a placement group. */
|
||||
public class PlacementGroupId extends BaseId implements Serializable {
|
||||
|
||||
public static final int LENGTH = 16;
|
||||
|
@ -18,32 +16,24 @@ public class PlacementGroupId extends BaseId implements Serializable {
|
|||
super(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a PlacementGroupId from the given ByteBuffer.
|
||||
*/
|
||||
/** Creates a PlacementGroupId from the given ByteBuffer. */
|
||||
public static PlacementGroupId fromByteBuffer(ByteBuffer bb) {
|
||||
return new PlacementGroupId(byteBuffer2Bytes(bb));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a PlacementGroupId instance according to the given bytes.
|
||||
*/
|
||||
/** Create a PlacementGroupId instance according to the given bytes. */
|
||||
public static PlacementGroupId fromBytes(byte[] bytes) {
|
||||
return new PlacementGroupId(bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a nil PlacementGroupId.
|
||||
*/
|
||||
/** Generate a nil PlacementGroupId. */
|
||||
private static PlacementGroupId nil() {
|
||||
byte[] b = new byte[LENGTH];
|
||||
Arrays.fill(b, (byte) 0xFF);
|
||||
return new PlacementGroupId(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an PlacementGroupId with random value. Used for local mode and test only.
|
||||
*/
|
||||
/** Generate an PlacementGroupId with random value. Used for local mode and test only. */
|
||||
public static PlacementGroupId fromRandom() {
|
||||
byte[] b = new byte[LENGTH];
|
||||
new Random().nextBytes(b);
|
||||
|
|
|
@ -4,9 +4,7 @@ import java.io.Serializable;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Represents the id of a Ray task.
|
||||
*/
|
||||
/** Represents the id of a Ray task. */
|
||||
public class TaskId extends BaseId implements Serializable {
|
||||
|
||||
public static final int UNIQUE_BYTES_LENGTH = 8;
|
||||
|
@ -15,30 +13,22 @@ public class TaskId extends BaseId implements Serializable {
|
|||
|
||||
public static final TaskId NIL = genNil();
|
||||
|
||||
/**
|
||||
* Create a TaskId from a hex string.
|
||||
*/
|
||||
/** Create a TaskId from a hex string. */
|
||||
public static TaskId fromHexString(String hex) {
|
||||
return new TaskId(hexString2Bytes(hex));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a TaskId from a ByteBuffer.
|
||||
*/
|
||||
/** Creates a TaskId from a ByteBuffer. */
|
||||
public static TaskId fromByteBuffer(ByteBuffer bb) {
|
||||
return new TaskId(byteBuffer2Bytes(bb));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a TaskId from given bytes.
|
||||
*/
|
||||
/** Creates a TaskId from given bytes. */
|
||||
public static TaskId fromBytes(byte[] bytes) {
|
||||
return new TaskId(bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a nil TaskId.
|
||||
*/
|
||||
/** Generate a nil TaskId. */
|
||||
private static TaskId genNil() {
|
||||
byte[] b = new byte[LENGTH];
|
||||
Arrays.fill(b, (byte) 0xFF);
|
||||
|
|
|
@ -5,41 +5,30 @@ import java.nio.ByteBuffer;
|
|||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Represents a unique id of all Ray concepts, including
|
||||
* workers, actors, checkpoints, etc.
|
||||
*/
|
||||
/** Represents a unique id of all Ray concepts, including workers, actors, checkpoints, etc. */
|
||||
public class UniqueId extends BaseId implements Serializable {
|
||||
|
||||
public static final int LENGTH = 28;
|
||||
public static final UniqueId NIL = genNil();
|
||||
|
||||
/**
|
||||
* Create a UniqueId from a hex string.
|
||||
*/
|
||||
/** Create a UniqueId from a hex string. */
|
||||
public static UniqueId fromHexString(String hex) {
|
||||
return new UniqueId(hexString2Bytes(hex));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a UniqueId from a ByteBuffer.
|
||||
*/
|
||||
/** Creates a UniqueId from a ByteBuffer. */
|
||||
public static UniqueId fromByteBuffer(ByteBuffer bb) {
|
||||
return new UniqueId(byteBuffer2Bytes(bb));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a nil UniqueId.
|
||||
*/
|
||||
/** Generate a nil UniqueId. */
|
||||
private static UniqueId genNil() {
|
||||
byte[] b = new byte[LENGTH];
|
||||
Arrays.fill(b, (byte) 0xFF);
|
||||
return new UniqueId(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an UniqueId with random value.
|
||||
*/
|
||||
/** Generate an UniqueId with random value. */
|
||||
public static UniqueId randomId() {
|
||||
byte[] b = new byte[LENGTH];
|
||||
new Random().nextBytes(b);
|
||||
|
|
|
@ -5,9 +5,7 @@ import io.ray.api.placementgroup.PlacementGroup;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The options for creating actor.
|
||||
*/
|
||||
/** The options for creating actor. */
|
||||
public class ActorCreationOptions extends BaseTaskOptions {
|
||||
public final boolean global;
|
||||
public final String name;
|
||||
|
@ -17,9 +15,15 @@ public class ActorCreationOptions extends BaseTaskOptions {
|
|||
public final PlacementGroup group;
|
||||
public final int bundleIndex;
|
||||
|
||||
private ActorCreationOptions(boolean global, String name, Map<String, Double> resources,
|
||||
int maxRestarts, String jvmOptions, int maxConcurrency,
|
||||
PlacementGroup group, int bundleIndex) {
|
||||
private ActorCreationOptions(
|
||||
boolean global,
|
||||
String name,
|
||||
Map<String, Double> resources,
|
||||
int maxRestarts,
|
||||
String jvmOptions,
|
||||
int maxConcurrency,
|
||||
PlacementGroup group,
|
||||
int bundleIndex) {
|
||||
super(resources);
|
||||
this.global = global;
|
||||
this.name = name;
|
||||
|
@ -30,9 +34,7 @@ public class ActorCreationOptions extends BaseTaskOptions {
|
|||
this.bundleIndex = bundleIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* The inner class for building ActorCreationOptions.
|
||||
*/
|
||||
/** The inner class for building ActorCreationOptions. */
|
||||
public static class Builder {
|
||||
private boolean global;
|
||||
private String name;
|
||||
|
@ -44,13 +46,11 @@ public class ActorCreationOptions extends BaseTaskOptions {
|
|||
private int bundleIndex;
|
||||
|
||||
/**
|
||||
* Set the actor name of a named actor.
|
||||
* This named actor is only accessible from this job by this name via
|
||||
* {@link Ray#getActor(java.lang.String)}. If you want create a named actor that is accessible
|
||||
* from all jobs, use {@link Builder#setGlobalName(java.lang.String)} instead.
|
||||
* Set the actor name of a named actor. This named actor is only accessible from this job by
|
||||
* this name via {@link Ray#getActor(java.lang.String)}. If you want create a named actor that
|
||||
* is accessible from all jobs, use {@link Builder#setGlobalName(java.lang.String)} instead.
|
||||
*
|
||||
* @param name The name of the named actor.
|
||||
* @return self
|
||||
* @param name The name of the named actor. Returns self
|
||||
*/
|
||||
public Builder setName(String name) {
|
||||
this.name = name;
|
||||
|
@ -63,8 +63,7 @@ public class ActorCreationOptions extends BaseTaskOptions {
|
|||
* {@link Ray#getGlobalActor(java.lang.String)}. If you want to create a named actor that is
|
||||
* only accessible from this job, use {@link Builder#setName(java.lang.String)} instead.
|
||||
*
|
||||
* @param name The name of the named actor.
|
||||
* @return self
|
||||
* @param name The name of the named actor. Returns self
|
||||
*/
|
||||
public Builder setGlobalName(String name) {
|
||||
this.name = name;
|
||||
|
@ -73,13 +72,12 @@ public class ActorCreationOptions extends BaseTaskOptions {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set a custom resource requirement to reserve for the lifetime of this actor.
|
||||
* This method can be called multiple times. If the same resource is set multiple times,
|
||||
* the latest quantity will be used.
|
||||
* Set a custom resource requirement to reserve for the lifetime of this actor. This method can
|
||||
* be called multiple times. If the same resource is set multiple times, the latest quantity
|
||||
* will be used.
|
||||
*
|
||||
* @param resourceName resource name
|
||||
* @param resourceQuantity resource quantity
|
||||
* @return self
|
||||
* @param resourceQuantity resource quantity Returns self
|
||||
*/
|
||||
public Builder setResource(String resourceName, Double resourceQuantity) {
|
||||
this.resources.put(resourceName, resourceQuantity);
|
||||
|
@ -87,12 +85,11 @@ public class ActorCreationOptions extends BaseTaskOptions {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set custom resource requirements to reserve for the lifetime of this actor.
|
||||
* This method can be called multiple times. If the same resource is set multiple times,
|
||||
* the latest quantity will be used.
|
||||
* Set custom resource requirements to reserve for the lifetime of this actor. This method can
|
||||
* be called multiple times. If the same resource is set multiple times, the latest quantity
|
||||
* will be used.
|
||||
*
|
||||
* @param resources requirements for multiple resources.
|
||||
* @return self
|
||||
* @param resources requirements for multiple resources. Returns self
|
||||
*/
|
||||
public Builder setResources(Map<String, Double> resources) {
|
||||
this.resources.putAll(resources);
|
||||
|
@ -104,8 +101,7 @@ public class ActorCreationOptions extends BaseTaskOptions {
|
|||
* unexpectedly. The minimum valid value is 0 (default), which indicates that the actor doesn't
|
||||
* need to be restarted. A value of -1 indicates that an actor should be restarted indefinitely.
|
||||
*
|
||||
* @param maxRestarts max number of actor restarts
|
||||
* @return self
|
||||
* @param maxRestarts max number of actor restarts Returns self
|
||||
*/
|
||||
public Builder setMaxRestarts(int maxRestarts) {
|
||||
this.maxRestarts = maxRestarts;
|
||||
|
@ -114,11 +110,10 @@ public class ActorCreationOptions extends BaseTaskOptions {
|
|||
|
||||
/**
|
||||
* Set the JVM options for the Java worker that this actor is running in.
|
||||
* <p>
|
||||
* Note, if this is set, this actor won't share Java worker with other actors or tasks.
|
||||
*
|
||||
* @param jvmOptions JVM options for the Java worker that this actor is running in.
|
||||
* @return self
|
||||
* <p>Note, if this is set, this actor won't share Java worker with other actors or tasks.
|
||||
*
|
||||
* @param jvmOptions JVM options for the Java worker that this actor is running in. Returns self
|
||||
*/
|
||||
public Builder setJvmOptions(String jvmOptions) {
|
||||
this.jvmOptions = jvmOptions;
|
||||
|
@ -127,12 +122,12 @@ public class ActorCreationOptions extends BaseTaskOptions {
|
|||
|
||||
/**
|
||||
* Set the max number of concurrent calls to allow for this actor.
|
||||
* <p>
|
||||
* The max concurrency defaults to 1 for threaded execution.
|
||||
* Note that the execution order is not guaranteed when {@code max_concurrency > 1}.
|
||||
*
|
||||
* @param maxConcurrency The max number of concurrent calls to allow for this actor.
|
||||
* @return self
|
||||
* <p>The max concurrency defaults to 1 for threaded execution. Note that the execution order is
|
||||
* not guaranteed when {@code max_concurrency > 1}.
|
||||
*
|
||||
* @param maxConcurrency The max number of concurrent calls to allow for this actor. Returns
|
||||
* self
|
||||
*/
|
||||
public Builder setMaxConcurrency(int maxConcurrency) {
|
||||
if (maxConcurrency <= 0) {
|
||||
|
@ -147,8 +142,7 @@ public class ActorCreationOptions extends BaseTaskOptions {
|
|||
* Set the placement group to place this actor in.
|
||||
*
|
||||
* @param group The placement group of the actor.
|
||||
* @param bundleIndex The index of the bundle to place this actor in.
|
||||
* @return self
|
||||
* @param bundleIndex The index of the bundle to place this actor in. Returns self
|
||||
*/
|
||||
public Builder setPlacementGroup(PlacementGroup group, int bundleIndex) {
|
||||
this.group = group;
|
||||
|
@ -161,5 +155,4 @@ public class ActorCreationOptions extends BaseTaskOptions {
|
|||
global, name, resources, maxRestarts, jvmOptions, maxConcurrency, group, bundleIndex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,9 +4,7 @@ import java.io.Serializable;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The options class for RayCall or ActorCreation.
|
||||
*/
|
||||
/** The options class for RayCall or ActorCreation. */
|
||||
public abstract class BaseTaskOptions implements Serializable {
|
||||
|
||||
public final Map<String, Double> resources;
|
||||
|
@ -18,19 +16,22 @@ public abstract class BaseTaskOptions implements Serializable {
|
|||
public BaseTaskOptions(Map<String, Double> resources) {
|
||||
for (Map.Entry<String, Double> entry : resources.entrySet()) {
|
||||
if (entry.getValue() == null || entry.getValue().compareTo(0.0) <= 0) {
|
||||
throw new IllegalArgumentException(String.format("Resource values should be "
|
||||
+ "positive. Specified resource: %s = %s.", entry.getKey(), entry.getValue()));
|
||||
throw new IllegalArgumentException(
|
||||
String.format(
|
||||
"Resource values should be " + "positive. Specified resource: %s = %s.",
|
||||
entry.getKey(), entry.getValue()));
|
||||
}
|
||||
// Note: A resource value should be an integer if it is greater than 1.0.
|
||||
// e.g. 3.0 is a valid resource value, but 3.5 is not.
|
||||
if (entry.getValue().compareTo(1.0) >= 0
|
||||
&& entry.getValue().compareTo(Math.floor(entry.getValue())) != 0) {
|
||||
throw new IllegalArgumentException(String.format("A resource value should be "
|
||||
throw new IllegalArgumentException(
|
||||
String.format(
|
||||
"A resource value should be "
|
||||
+ "an integer if it is greater than 1.0. Specified resource: %s = %s.",
|
||||
entry.getKey(), entry.getValue()));
|
||||
}
|
||||
}
|
||||
this.resources = resources;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,8 +22,7 @@ public class CallOptions extends BaseTaskOptions {
|
|||
/**
|
||||
* Set a name for this task.
|
||||
*
|
||||
* @param name task name
|
||||
* @return self
|
||||
* @param name task name Returns self
|
||||
*/
|
||||
public Builder setName(String name) {
|
||||
this.name = name;
|
||||
|
@ -35,8 +34,7 @@ public class CallOptions extends BaseTaskOptions {
|
|||
* multiple times. If the same resource is set multiple times, the latest quantity will be used.
|
||||
*
|
||||
* @param name resource name
|
||||
* @param value resource capacity
|
||||
* @return self
|
||||
* @param value resource capacity Returns self
|
||||
*/
|
||||
public Builder setResource(String name, Double value) {
|
||||
this.resources.put(name, value);
|
||||
|
@ -47,8 +45,7 @@ public class CallOptions extends BaseTaskOptions {
|
|||
* Set custom requirements for multiple resources. This method can be called multiple times. If
|
||||
* the same resource is set multiple times, the latest quantity will be used.
|
||||
*
|
||||
* @param resources requirements for multiple resources.
|
||||
* @return self
|
||||
* @param resources requirements for multiple resources. Returns self
|
||||
*/
|
||||
public Builder setResources(Map<String, Double> resources) {
|
||||
this.resources.putAll(resources);
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package io.ray.api.placementgroup;
|
||||
|
||||
/**
|
||||
* A placement group is used to place interdependent actors according to a specific strategy
|
||||
* {@link PlacementStrategy}.
|
||||
* When a placement group is created, the corresponding actor slots and resources are preallocated.
|
||||
* A placement group consists of one or more bundles plus a specific placement strategy.
|
||||
* A placement group is used to place interdependent actors according to a specific strategy {@link
|
||||
* PlacementStrategy}. When a placement group is created, the corresponding actor slots and
|
||||
* resources are preallocated. A placement group consists of one or more bundles plus a specific
|
||||
* placement strategy.
|
||||
*/
|
||||
public interface PlacementGroup {
|
||||
}
|
||||
public interface PlacementGroup {}
|
||||
|
|
|
@ -1,33 +1,21 @@
|
|||
package io.ray.api.placementgroup;
|
||||
|
||||
/**
|
||||
* State of placement group.
|
||||
*/
|
||||
/** State of placement group. */
|
||||
public enum PlacementGroupState {
|
||||
|
||||
/**
|
||||
* Wait for resource to schedule.
|
||||
*/
|
||||
/** Wait for resource to schedule. */
|
||||
PENDING(0),
|
||||
|
||||
/**
|
||||
* The placement group has created on some node.
|
||||
*/
|
||||
/** The placement group has created on some node. */
|
||||
CREATED(1),
|
||||
|
||||
/**
|
||||
* The placement group has removed.
|
||||
*/
|
||||
/** The placement group has removed. */
|
||||
REMOVED(2),
|
||||
|
||||
/**
|
||||
* The placement group is rescheduling.
|
||||
*/
|
||||
/** The placement group is rescheduling. */
|
||||
RESCHEDULING(3),
|
||||
|
||||
/**
|
||||
* Unrecognized state.
|
||||
*/
|
||||
/** Unrecognized state. */
|
||||
UNRECOGNIZED(-1);
|
||||
|
||||
private int value = 0;
|
||||
|
|
|
@ -1,33 +1,23 @@
|
|||
package io.ray.api.placementgroup;
|
||||
|
||||
/**
|
||||
* The actor placement strategy.
|
||||
*/
|
||||
/** The actor placement strategy. */
|
||||
public enum PlacementStrategy {
|
||||
/**
|
||||
* Packs Bundles close together inside nodes as tight as possible.
|
||||
*/
|
||||
/** Packs Bundles close together inside nodes as tight as possible. */
|
||||
PACK(0),
|
||||
|
||||
/**
|
||||
* Places Bundles across distinct nodes as even as possible.
|
||||
*/
|
||||
/** Places Bundles across distinct nodes as even as possible. */
|
||||
SPREAD(1),
|
||||
|
||||
/**
|
||||
* Packs Bundles into one node. The group is not allowed to span multiple nodes.
|
||||
*/
|
||||
/** Packs Bundles into one node. The group is not allowed to span multiple nodes. */
|
||||
STRICT_PACK(2),
|
||||
|
||||
/**
|
||||
* Places Bundles across distinct nodes.
|
||||
* The group is not allowed to deploy more than one bundle on a node.
|
||||
* Places Bundles across distinct nodes. The group is not allowed to deploy more than one bundle
|
||||
* on a node.
|
||||
*/
|
||||
STRICT_SPREAD(3),
|
||||
|
||||
/**
|
||||
* Unrecognized strategy.
|
||||
*/
|
||||
/** Unrecognized strategy. */
|
||||
UNRECOGNIZED(-1);
|
||||
|
||||
private int value = 0;
|
||||
|
|
|
@ -22,37 +22,31 @@ import java.util.Map;
|
|||
import java.util.Optional;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Base interface of a Ray runtime.
|
||||
*/
|
||||
/** Base interface of a Ray runtime. */
|
||||
public interface RayRuntime {
|
||||
|
||||
/**
|
||||
* Shutdown the runtime.
|
||||
*/
|
||||
/** Shutdown the runtime. */
|
||||
void shutdown();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
<T> ObjectRef<T> put(T obj);
|
||||
|
||||
/**
|
||||
* Get an object 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.
|
||||
*/
|
||||
<T> T get(ObjectRef<T> objectRef);
|
||||
|
||||
/**
|
||||
* Get a list of objects from the object store.
|
||||
*
|
||||
* @param objectRefs The list of object references.
|
||||
* @return A list of Java objects.
|
||||
* @param objectRefs The list of object references. Returns A list of Java objects.
|
||||
*/
|
||||
<T> List<T> get(List<ObjectRef<T>> objectRefs);
|
||||
|
||||
|
@ -62,8 +56,8 @@ public interface RayRuntime {
|
|||
*
|
||||
* @param waitList A list of ObjectRef 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.
|
||||
*/
|
||||
<T> WaitResult<T> wait(List<ObjectRef<T>> waitList, int numReturns, int timeoutMs);
|
||||
|
||||
|
@ -88,13 +82,12 @@ public interface RayRuntime {
|
|||
|
||||
/**
|
||||
* Get a handle to a named actor.
|
||||
* <p>
|
||||
* Gets a handle to a named actor with the given name. The actor must
|
||||
* have been created with name specified.
|
||||
*
|
||||
* <p>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.
|
||||
* @param global Whether the named actor is global.
|
||||
* @return ActorHandle to the actor.
|
||||
* @param global Whether the named actor is global. Returns ActorHandle to the actor.
|
||||
*/
|
||||
<T extends BaseActorHandle> Optional<T> getActor(String name, boolean global);
|
||||
|
||||
|
@ -111,8 +104,7 @@ public interface RayRuntime {
|
|||
*
|
||||
* @param func The remote function to run.
|
||||
* @param args The arguments of the remote function.
|
||||
* @param options The options for this call.
|
||||
* @return The result object.
|
||||
* @param options The options for this call. Returns The result object.
|
||||
*/
|
||||
ObjectRef call(RayFunc func, Object[] args, CallOptions options);
|
||||
|
||||
|
@ -121,8 +113,7 @@ public interface RayRuntime {
|
|||
*
|
||||
* @param pyFunction The Python function.
|
||||
* @param args Arguments of the function.
|
||||
* @param options The options for this call.
|
||||
* @return The result object.
|
||||
* @param options The options for this call. Returns The result object.
|
||||
*/
|
||||
ObjectRef call(PyFunction pyFunction, Object[] args, CallOptions options);
|
||||
|
||||
|
@ -131,8 +122,7 @@ public interface RayRuntime {
|
|||
*
|
||||
* @param actor A handle to the actor.
|
||||
* @param func The remote function to run, it must be a method of the given actor.
|
||||
* @param args The arguments of the remote function.
|
||||
* @return The result object.
|
||||
* @param args The arguments of the remote function. Returns The result object.
|
||||
*/
|
||||
ObjectRef callActor(ActorHandle<?> actor, RayFunc func, Object[] args);
|
||||
|
||||
|
@ -141,8 +131,7 @@ public interface RayRuntime {
|
|||
*
|
||||
* @param pyActor A handle to the actor.
|
||||
* @param pyActorMethod The actor method.
|
||||
* @param args Arguments of the function.
|
||||
* @return The result object.
|
||||
* @param args Arguments of the function. Returns The result object.
|
||||
*/
|
||||
ObjectRef callActor(PyActorHandle pyActor, PyActorMethod pyActorMethod, Object[] args);
|
||||
|
||||
|
@ -152,28 +141,25 @@ public interface RayRuntime {
|
|||
* @param actorFactoryFunc A remote function whose return value is the actor object.
|
||||
* @param args The arguments for the remote function.
|
||||
* @param <T> The type of the actor object.
|
||||
* @param options The options for creating actor.
|
||||
* @return A handle to the actor.
|
||||
* @param options The options for creating actor. Returns A handle to the actor.
|
||||
*/
|
||||
<T> ActorHandle<T> createActor(RayFunc actorFactoryFunc, Object[] args,
|
||||
ActorCreationOptions options);
|
||||
<T> ActorHandle<T> createActor(
|
||||
RayFunc actorFactoryFunc, Object[] args, ActorCreationOptions options);
|
||||
|
||||
/**
|
||||
* Create a Python actor on a remote node.
|
||||
*
|
||||
* @param pyActorClass The Python actor class.
|
||||
* @param args Arguments of the actor constructor.
|
||||
* @param options The options for creating actor.
|
||||
* @return A handle to the actor.
|
||||
* @param options The options for creating actor. Returns A handle to the actor.
|
||||
*/
|
||||
PyActorHandle createActor(PyActorClass pyActorClass, Object[] args,
|
||||
ActorCreationOptions options);
|
||||
PyActorHandle createActor(PyActorClass pyActorClass, Object[] args, ActorCreationOptions options);
|
||||
|
||||
PlacementGroup createPlacementGroup(String name, List<Map<String, Double>> bundles,
|
||||
PlacementStrategy strategy);
|
||||
PlacementGroup createPlacementGroup(
|
||||
String name, List<Map<String, Double>> bundles, PlacementStrategy strategy);
|
||||
|
||||
PlacementGroup createPlacementGroup(List<Map<String, Double>> bundles,
|
||||
PlacementStrategy strategy);
|
||||
PlacementGroup createPlacementGroup(
|
||||
List<Map<String, Double>> bundles, PlacementStrategy strategy);
|
||||
|
||||
RuntimeContext getRuntimeContext();
|
||||
|
||||
|
@ -184,48 +170,47 @@ public interface RayRuntime {
|
|||
/**
|
||||
* Wrap a {@link Runnable} with necessary context capture.
|
||||
*
|
||||
* @param runnable The runnable to wrap.
|
||||
* @return The wrapped runnable.
|
||||
* @param runnable The runnable to wrap. Returns The wrapped runnable.
|
||||
*/
|
||||
Runnable wrapRunnable(Runnable runnable);
|
||||
|
||||
/**
|
||||
* Wrap a {@link Callable} with necessary context capture.
|
||||
*
|
||||
* @param callable The callable to wrap.
|
||||
* @return The wrapped callable.
|
||||
* @param callable The callable to wrap. Returns The wrapped callable.
|
||||
*/
|
||||
<T> Callable<T> wrapCallable(Callable<T> callable);
|
||||
|
||||
/**
|
||||
* Intentionally exit the current actor.
|
||||
*/
|
||||
/** Intentionally exit the current actor. */
|
||||
void exitActor();
|
||||
|
||||
/**
|
||||
* Get a placement group by id.
|
||||
* @param id placement group id.
|
||||
* @return The placement group.
|
||||
*
|
||||
* @param id placement group id. Returns The placement group.
|
||||
*/
|
||||
PlacementGroup getPlacementGroup(PlacementGroupId id);
|
||||
|
||||
/**
|
||||
* Get all placement groups in this cluster.
|
||||
* @return All placement groups.
|
||||
*
|
||||
* <p>Returns All placement groups.
|
||||
*/
|
||||
List<PlacementGroup> getAllPlacementGroups();
|
||||
|
||||
/**
|
||||
* Remove a placement group by id.
|
||||
*
|
||||
* @param id Id of the placement group.
|
||||
*/
|
||||
void removePlacementGroup(PlacementGroupId id);
|
||||
|
||||
/**
|
||||
* Wait for the placement group to be ready within the specified time.
|
||||
*
|
||||
* @param id Id of placement group.
|
||||
* @param timeoutMs Timeout in milliseconds.
|
||||
* @return True if the placement group is created. False otherwise.
|
||||
* @param timeoutMs Timeout in milliseconds. Returns True if the placement group is created. False
|
||||
* otherwise.
|
||||
*/
|
||||
boolean waitPlacementGroupReady(PlacementGroupId id, int timeoutMs);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package io.ray.api.runtime;
|
||||
|
||||
/**
|
||||
* A factory that produces a RayRuntime instance.
|
||||
*/
|
||||
/** A factory that produces a RayRuntime instance. */
|
||||
public interface RayRuntimeFactory {
|
||||
|
||||
RayRuntime createRayRuntime();
|
||||
|
|
|
@ -3,9 +3,7 @@ package io.ray.api.runtimecontext;
|
|||
import io.ray.api.id.UniqueId;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A class that represents the information of a node.
|
||||
*/
|
||||
/** A class that represents the information of a node. */
|
||||
public class NodeInfo {
|
||||
|
||||
public final UniqueId nodeId;
|
||||
|
@ -24,9 +22,15 @@ public class NodeInfo {
|
|||
|
||||
public final Map<String, Double> resources;
|
||||
|
||||
public NodeInfo(UniqueId nodeId, String nodeAddress, String nodeHostname, int nodeManagerPort,
|
||||
String objectStoreSocketName, String rayletSocketName,
|
||||
boolean isAlive, Map<String, Double> resources) {
|
||||
public NodeInfo(
|
||||
UniqueId nodeId,
|
||||
String nodeAddress,
|
||||
String nodeHostname,
|
||||
int nodeManagerPort,
|
||||
String objectStoreSocketName,
|
||||
String rayletSocketName,
|
||||
boolean isAlive,
|
||||
Map<String, Double> resources) {
|
||||
this.nodeId = nodeId;
|
||||
this.nodeAddress = nodeAddress;
|
||||
this.nodeHostname = nodeHostname;
|
||||
|
@ -39,12 +43,19 @@ public class NodeInfo {
|
|||
|
||||
public String toString() {
|
||||
return "NodeInfo{"
|
||||
+ "nodeId='" + nodeId + '\''
|
||||
+ ", nodeAddress='" + nodeAddress + "\'"
|
||||
+ ", nodeHostname'" + nodeHostname + "\'"
|
||||
+ ", isAlive=" + isAlive
|
||||
+ ", resources=" + resources
|
||||
+ "nodeId='"
|
||||
+ nodeId
|
||||
+ '\''
|
||||
+ ", nodeAddress='"
|
||||
+ nodeAddress
|
||||
+ "\'"
|
||||
+ ", nodeHostname'"
|
||||
+ nodeHostname
|
||||
+ "\'"
|
||||
+ ", isAlive="
|
||||
+ isAlive
|
||||
+ ", resources="
|
||||
+ resources
|
||||
+ "}";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,27 +4,23 @@ import io.ray.api.id.ActorId;
|
|||
import io.ray.api.id.JobId;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A class used for getting information of Ray runtime.
|
||||
*/
|
||||
/** A class used for getting information of Ray runtime. */
|
||||
public interface RuntimeContext {
|
||||
|
||||
/**
|
||||
* Get the current Job ID.
|
||||
*/
|
||||
/** Get the current Job ID. */
|
||||
JobId getCurrentJobId();
|
||||
|
||||
/**
|
||||
* Get the current actor ID.
|
||||
*
|
||||
* Note, this can only be called in actors.
|
||||
* <p>Note, this can only be called in actors.
|
||||
*/
|
||||
ActorId getCurrentActorId();
|
||||
|
||||
/**
|
||||
* Returns true if the current actor was restarted, false if it's created for the first time.
|
||||
*
|
||||
* Note, this method should only be called from an actor creation task.
|
||||
* <p>Note, this method should only be called from an actor creation task.
|
||||
*/
|
||||
boolean wasCurrentActorRestarted();
|
||||
|
||||
|
@ -33,8 +29,6 @@ public interface RuntimeContext {
|
|||
*/
|
||||
boolean isSingleProcess();
|
||||
|
||||
/**
|
||||
* Get all node information in Ray cluster.
|
||||
*/
|
||||
/** Get all node information in Ray cluster. */
|
||||
List<NodeInfo> getAllNodeInfo();
|
||||
}
|
||||
|
|
|
@ -4,13 +4,4 @@
|
|||
|
||||
<suppressions>
|
||||
<suppress checks="OperatorWrap" files=".*" />
|
||||
<suppress checks="JavadocParagraph" files=".*" />
|
||||
<suppress checks="SummaryJavadoc" files=".*" />
|
||||
<suppress checks="MemberNameCheck" files="PathConfig.java"/>
|
||||
<suppress checks="MemberNameCheck" files="RayParameters.java"/>
|
||||
<suppress checks="AbbreviationAsWordInNameCheck" files="RayParameters.java"/>
|
||||
<suppress checks=".*" files="RayCall.java"/>
|
||||
<suppress checks=".*" files="ActorCall.java"/>
|
||||
<!-- suppress check for flatbuffer-generated files. -->
|
||||
<suppress checks=".*" files="io[\\/]ray[\\/]runtime[\\/]generated[\\/]" />
|
||||
</suppressions>
|
||||
|
|
|
@ -26,6 +26,11 @@
|
|||
<module name="FileTabCharacter">
|
||||
<property name="eachLine" value="true"/>
|
||||
</module>
|
||||
<!-- exclude the generated files from being parsed, which make checkstyle check more fast -->
|
||||
<module name="BeforeExecutionExclusionFileFilter">
|
||||
<property name="fileNamePattern"
|
||||
value="io[\\/]ray[\\/].*runtime[\\/]generated[\\/]|RayCall.java|ActorCall.java"/>
|
||||
</module>
|
||||
|
||||
<module name="TreeWalker">
|
||||
<!-- Below are custom config items in addition to the original google style config. -->
|
||||
|
@ -58,20 +63,6 @@
|
|||
value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/>
|
||||
</module>
|
||||
<module name="NeedBraces"/>
|
||||
<module name="LeftCurly"/>
|
||||
<module name="RightCurly">
|
||||
<property name="id" value="RightCurlySame"/>
|
||||
<property name="tokens"
|
||||
value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE,
|
||||
LITERAL_DO"/>
|
||||
</module>
|
||||
<module name="RightCurly">
|
||||
<property name="id" value="RightCurlyAlone"/>
|
||||
<property name="option" value="alone"/>
|
||||
<property name="tokens"
|
||||
value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, STATIC_INIT,
|
||||
INSTANCE_INIT"/>
|
||||
</module>
|
||||
<module name="WhitespaceAround">
|
||||
<property name="allowEmptyConstructors" value="true"/>
|
||||
<property name="allowEmptyMethods" value="true"/>
|
||||
|
@ -164,14 +155,6 @@
|
|||
<message key="ws.notPreceded"
|
||||
value="GenericWhitespace ''{0}'' is not preceded with whitespace."/>
|
||||
</module>
|
||||
<module name="Indentation">
|
||||
<property name="basicOffset" value="2"/>
|
||||
<property name="braceAdjustment" value="0"/>
|
||||
<property name="caseIndent" value="2"/>
|
||||
<property name="throwsIndent" value="4"/>
|
||||
<property name="lineWrappingIndentation" value="4"/>
|
||||
<property name="arrayInitIndent" value="2"/>
|
||||
</module>
|
||||
<module name="AbbreviationAsWordInName">
|
||||
<property name="ignoreFinal" value="false"/>
|
||||
<property name="allowedAbbreviationLength" value="1"/>
|
||||
|
@ -232,9 +215,6 @@
|
|||
<message key="name.invalidPattern"
|
||||
value="Method name ''{0}'' must match pattern ''{1}''."/>
|
||||
</module>
|
||||
<module name="SingleLineJavadoc">
|
||||
<property name="ignoreInlineTags" value="false"/>
|
||||
</module>
|
||||
<module name="EmptyCatchBlock">
|
||||
<property name="exceptionVariableName" value="expected"/>
|
||||
</module>
|
||||
|
|
34
java/pom.xml
34
java/pom.xml
|
@ -63,6 +63,7 @@
|
|||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<projetct.version>1.1.0-SNAPSHOT</projetct.version>
|
||||
<projetct.version>1.1.0-SNAPSHOT</projetct.version>
|
||||
</properties>
|
||||
|
||||
<profiles>
|
||||
|
@ -176,7 +177,14 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.1.0</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.puppycrawl.tools</groupId>
|
||||
<artifactId>checkstyle</artifactId>
|
||||
<version>8.19</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>validate</id>
|
||||
|
@ -218,6 +226,26 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>com.diffplug.spotless</groupId>
|
||||
<artifactId>spotless-maven-plugin</artifactId>
|
||||
<version>2.5.0</version>
|
||||
<configuration>
|
||||
<java>
|
||||
<excludes>
|
||||
<exclude>**/RayCall.java</exclude>
|
||||
<exclude>**/ActorCall.java</exclude>
|
||||
<exclude>**/PyActorCall.java</exclude>
|
||||
<exclude>**/runtime/generated/**/*.*</exclude>
|
||||
</excludes>
|
||||
<googleJavaFormat>
|
||||
<version>1.7</version>
|
||||
<style>GOOGLE</style>
|
||||
</googleJavaFormat>
|
||||
</java>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
<plugins>
|
||||
|
@ -229,6 +257,10 @@
|
|||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.diffplug.spotless</groupId>
|
||||
<artifactId>spotless-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
|
|
@ -45,9 +45,7 @@ import java.util.stream.Collectors;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Core functionality to implement Ray APIs.
|
||||
*/
|
||||
/** Core functionality to implement Ray APIs. */
|
||||
public abstract class AbstractRayRuntime implements RayRuntimeInternal {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractRayRuntime.class);
|
||||
|
@ -63,9 +61,7 @@ public abstract class AbstractRayRuntime implements RayRuntimeInternal {
|
|||
protected TaskSubmitter taskSubmitter;
|
||||
protected WorkerContext workerContext;
|
||||
|
||||
/**
|
||||
* Whether the required thread context is set on the current thread.
|
||||
*/
|
||||
/** Whether the required thread context is set on the current thread. */
|
||||
final ThreadLocal<Boolean> isContextSet = ThreadLocal.withInitial(() -> false);
|
||||
|
||||
public AbstractRayRuntime(RayConfig rayConfig) {
|
||||
|
@ -78,7 +74,7 @@ public abstract class AbstractRayRuntime implements RayRuntimeInternal {
|
|||
@Override
|
||||
public <T> ObjectRef<T> put(T obj) {
|
||||
ObjectId objectId = objectStore.put(obj);
|
||||
return new ObjectRefImpl<T>(objectId, (Class<T>)(obj == null ? Object.class : obj.getClass()));
|
||||
return new ObjectRefImpl<T>(objectId, (Class<T>) (obj == null ? Object.class : obj.getClass()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -101,8 +97,11 @@ public abstract class AbstractRayRuntime implements RayRuntimeInternal {
|
|||
|
||||
@Override
|
||||
public void free(List<ObjectRef<?>> objectRefs, boolean localOnly) {
|
||||
objectStore.delete(objectRefs.stream().map(ref -> ((ObjectRefImpl<?>) ref).getId()).collect(
|
||||
Collectors.toList()), localOnly);
|
||||
objectStore.delete(
|
||||
objectRefs.stream()
|
||||
.map(ref -> ((ObjectRefImpl<?>) ref).getId())
|
||||
.collect(Collectors.toList()),
|
||||
localOnly);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -120,13 +119,11 @@ public abstract class AbstractRayRuntime implements RayRuntimeInternal {
|
|||
|
||||
@Override
|
||||
public ObjectRef call(PyFunction pyFunction, Object[] args, CallOptions options) {
|
||||
PyFunctionDescriptor functionDescriptor = new PyFunctionDescriptor(
|
||||
pyFunction.moduleName,
|
||||
"",
|
||||
pyFunction.functionName);
|
||||
PyFunctionDescriptor functionDescriptor =
|
||||
new PyFunctionDescriptor(pyFunction.moduleName, "", pyFunction.functionName);
|
||||
// Python functions always have a return value, even if it's `None`.
|
||||
return callNormalFunction(functionDescriptor, args,
|
||||
/*returnType=*/Optional.of(pyFunction.returnType), options);
|
||||
return callNormalFunction(
|
||||
functionDescriptor, args, /*returnType=*/ Optional.of(pyFunction.returnType), options);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -139,17 +136,18 @@ public abstract class AbstractRayRuntime implements RayRuntimeInternal {
|
|||
|
||||
@Override
|
||||
public ObjectRef callActor(PyActorHandle pyActor, PyActorMethod pyActorMethod, Object... args) {
|
||||
PyFunctionDescriptor functionDescriptor = new PyFunctionDescriptor(pyActor.getModuleName(),
|
||||
pyActor.getClassName(), pyActorMethod.methodName);
|
||||
PyFunctionDescriptor functionDescriptor =
|
||||
new PyFunctionDescriptor(
|
||||
pyActor.getModuleName(), pyActor.getClassName(), pyActorMethod.methodName);
|
||||
// Python functions always have a return value, even if it's `None`.
|
||||
return callActorFunction(pyActor, functionDescriptor, args,
|
||||
/*returnType=*/Optional.of(pyActorMethod.returnType));
|
||||
return callActorFunction(
|
||||
pyActor, functionDescriptor, args, /*returnType=*/ Optional.of(pyActorMethod.returnType));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> ActorHandle<T> createActor(RayFunc actorFactoryFunc,
|
||||
Object[] args, ActorCreationOptions options) {
|
||||
public <T> ActorHandle<T> createActor(
|
||||
RayFunc actorFactoryFunc, Object[] args, ActorCreationOptions options) {
|
||||
FunctionDescriptor functionDescriptor =
|
||||
functionManager.getFunction(workerContext.getCurrentJobId(), actorFactoryFunc)
|
||||
.functionDescriptor;
|
||||
|
@ -157,20 +155,20 @@ public abstract class AbstractRayRuntime implements RayRuntimeInternal {
|
|||
}
|
||||
|
||||
@Override
|
||||
public PyActorHandle createActor(PyActorClass pyActorClass, Object[] args,
|
||||
ActorCreationOptions options) {
|
||||
PyFunctionDescriptor functionDescriptor = new PyFunctionDescriptor(
|
||||
pyActorClass.moduleName,
|
||||
pyActorClass.className,
|
||||
PYTHON_INIT_METHOD_NAME);
|
||||
public PyActorHandle createActor(
|
||||
PyActorClass pyActorClass, Object[] args, ActorCreationOptions options) {
|
||||
PyFunctionDescriptor functionDescriptor =
|
||||
new PyFunctionDescriptor(
|
||||
pyActorClass.moduleName, pyActorClass.className, PYTHON_INIT_METHOD_NAME);
|
||||
return (PyActorHandle) createActorImpl(functionDescriptor, args, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlacementGroup createPlacementGroup(String name,
|
||||
List<Map<String, Double>> bundles, PlacementStrategy strategy) {
|
||||
boolean bundleResourceValid = bundles.stream().allMatch(
|
||||
bundle -> bundle.values().stream().allMatch(resource -> resource > 0));
|
||||
public PlacementGroup createPlacementGroup(
|
||||
String name, List<Map<String, Double>> bundles, PlacementStrategy strategy) {
|
||||
boolean bundleResourceValid =
|
||||
bundles.stream()
|
||||
.allMatch(bundle -> bundle.values().stream().allMatch(resource -> resource > 0));
|
||||
|
||||
if (bundles.isEmpty() || !bundleResourceValid) {
|
||||
throw new IllegalArgumentException(
|
||||
|
@ -264,12 +262,13 @@ public abstract class AbstractRayRuntime implements RayRuntimeInternal {
|
|||
|
||||
private ObjectRef callNormalFunction(
|
||||
FunctionDescriptor functionDescriptor,
|
||||
Object[] args, Optional<Class<?>> returnType, CallOptions options) {
|
||||
Object[] args,
|
||||
Optional<Class<?>> returnType,
|
||||
CallOptions options) {
|
||||
int numReturns = returnType.isPresent() ? 1 : 0;
|
||||
List<FunctionArg> functionArgs = ArgumentsBuilder
|
||||
.wrap(args, functionDescriptor.getLanguage());
|
||||
List<ObjectId> returnIds = taskSubmitter.submitTask(functionDescriptor,
|
||||
functionArgs, numReturns, options);
|
||||
List<FunctionArg> functionArgs = ArgumentsBuilder.wrap(args, functionDescriptor.getLanguage());
|
||||
List<ObjectId> returnIds =
|
||||
taskSubmitter.submitTask(functionDescriptor, functionArgs, numReturns, options);
|
||||
Preconditions.checkState(returnIds.size() == numReturns);
|
||||
if (returnIds.isEmpty()) {
|
||||
return null;
|
||||
|
@ -284,10 +283,9 @@ public abstract class AbstractRayRuntime implements RayRuntimeInternal {
|
|||
Object[] args,
|
||||
Optional<Class<?>> returnType) {
|
||||
int numReturns = returnType.isPresent() ? 1 : 0;
|
||||
List<FunctionArg> functionArgs = ArgumentsBuilder
|
||||
.wrap(args, functionDescriptor.getLanguage());
|
||||
List<ObjectId> returnIds = taskSubmitter.submitActorTask(rayActor,
|
||||
functionDescriptor, functionArgs, numReturns, null);
|
||||
List<FunctionArg> functionArgs = ArgumentsBuilder.wrap(args, functionDescriptor.getLanguage());
|
||||
List<ObjectId> returnIds =
|
||||
taskSubmitter.submitActorTask(rayActor, functionDescriptor, functionArgs, numReturns, null);
|
||||
Preconditions.checkState(returnIds.size() == numReturns);
|
||||
if (returnIds.isEmpty()) {
|
||||
return null;
|
||||
|
@ -296,10 +294,9 @@ public abstract class AbstractRayRuntime implements RayRuntimeInternal {
|
|||
}
|
||||
}
|
||||
|
||||
private BaseActorHandle createActorImpl(FunctionDescriptor functionDescriptor,
|
||||
Object[] args, ActorCreationOptions options) {
|
||||
List<FunctionArg> functionArgs = ArgumentsBuilder
|
||||
.wrap(args, functionDescriptor.getLanguage());
|
||||
private BaseActorHandle createActorImpl(
|
||||
FunctionDescriptor functionDescriptor, Object[] args, ActorCreationOptions options) {
|
||||
List<FunctionArg> functionArgs = ArgumentsBuilder.wrap(args, functionDescriptor.getLanguage());
|
||||
if (functionDescriptor.getLanguage() != Language.JAVA && options != null) {
|
||||
Preconditions.checkState(Strings.isNullOrEmpty(options.jvmOptions));
|
||||
}
|
||||
|
|
|
@ -9,9 +9,7 @@ import io.ray.runtime.util.LoggingUtil;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The default Ray runtime factory. It produces an instance of RayRuntime.
|
||||
*/
|
||||
/** The default Ray runtime factory. It produces an instance of RayRuntime. */
|
||||
public class DefaultRayRuntimeFactory implements RayRuntimeFactory {
|
||||
|
||||
@Override
|
||||
|
@ -22,17 +20,20 @@ public class DefaultRayRuntimeFactory implements RayRuntimeFactory {
|
|||
|
||||
if (rayConfig.workerMode == WorkerType.WORKER) {
|
||||
// Handle the uncaught exceptions thrown from user-spawned threads.
|
||||
Thread.setDefaultUncaughtExceptionHandler((Thread t, Throwable e) -> {
|
||||
Thread.setDefaultUncaughtExceptionHandler(
|
||||
(Thread t, Throwable e) -> {
|
||||
logger.error(String.format("Uncaught worker exception in thread %s", t), e);
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
logger.debug("Initializing runtime with config: {}", rayConfig);
|
||||
AbstractRayRuntime innerRuntime = rayConfig.runMode == RunMode.SINGLE_PROCESS
|
||||
AbstractRayRuntime innerRuntime =
|
||||
rayConfig.runMode == RunMode.SINGLE_PROCESS
|
||||
? new RayDevRuntime(rayConfig)
|
||||
: new RayNativeRuntime(rayConfig);
|
||||
RayRuntimeInternal runtime = rayConfig.numWorkersPerProcess > 1
|
||||
RayRuntimeInternal runtime =
|
||||
rayConfig.numWorkersPerProcess > 1
|
||||
? RayRuntimeProxy.newInstance(innerRuntime)
|
||||
: innerRuntime;
|
||||
runtime.start();
|
||||
|
|
|
@ -35,9 +35,10 @@ public class RayDevRuntime extends AbstractRayRuntime {
|
|||
taskExecutor = new LocalModeTaskExecutor(this);
|
||||
workerContext = new LocalModeWorkerContext(rayConfig.getJobId());
|
||||
objectStore = new LocalModeObjectStore(workerContext);
|
||||
taskSubmitter = new LocalModeTaskSubmitter(this, taskExecutor,
|
||||
(LocalModeObjectStore) objectStore);
|
||||
((LocalModeObjectStore) objectStore).addObjectPutCallback(
|
||||
taskSubmitter =
|
||||
new LocalModeTaskSubmitter(this, taskExecutor, (LocalModeObjectStore) objectStore);
|
||||
((LocalModeObjectStore) objectStore)
|
||||
.addObjectPutCallback(
|
||||
objectId -> {
|
||||
if (taskSubmitter != null) {
|
||||
((LocalModeTaskSubmitter) taskSubmitter).onObjectPut(objectId);
|
||||
|
@ -72,7 +73,7 @@ public class RayDevRuntime extends AbstractRayRuntime {
|
|||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T extends BaseActorHandle> Optional<T> getActor(String name, boolean global) {
|
||||
return (Optional<T>) ((LocalModeTaskSubmitter)taskSubmitter).getActor(name, global);
|
||||
return (Optional<T>) ((LocalModeTaskSubmitter) taskSubmitter).getActor(name, global);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -87,24 +88,21 @@ public class RayDevRuntime extends AbstractRayRuntime {
|
|||
}
|
||||
|
||||
@Override
|
||||
public PlacementGroup getPlacementGroup(
|
||||
PlacementGroupId id) {
|
||||
//@TODO(clay4444): We need a LocalGcsClient before implements this.
|
||||
public PlacementGroup getPlacementGroup(PlacementGroupId id) {
|
||||
// @TODO(clay4444): We need a LocalGcsClient before implements this.
|
||||
throw new UnsupportedOperationException(
|
||||
"Ray doesn't support placement group operations in local mode.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PlacementGroup> getAllPlacementGroups() {
|
||||
//@TODO(clay4444): We need a LocalGcsClient before implements this.
|
||||
// @TODO(clay4444): We need a LocalGcsClient before implements this.
|
||||
throw new UnsupportedOperationException(
|
||||
"Ray doesn't support placement group operations in local mode.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exitActor() {
|
||||
|
||||
}
|
||||
public void exitActor() {}
|
||||
|
||||
private JobId nextJobId() {
|
||||
return JobId.fromInt(jobCounter.getAndIncrement());
|
||||
|
|
|
@ -29,9 +29,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Native runtime for cluster mode.
|
||||
*/
|
||||
/** Native runtime for cluster mode. */
|
||||
public final class RayNativeRuntime extends AbstractRayRuntime {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RayNativeRuntime.class);
|
||||
|
@ -39,10 +37,9 @@ public final class RayNativeRuntime extends AbstractRayRuntime {
|
|||
private boolean startRayHead = false;
|
||||
|
||||
/**
|
||||
* In Java, GC runs in a standalone thread, and we can't control the exact
|
||||
* timing of garbage collection. By using this lock, when
|
||||
* {@link NativeObjectStore#nativeRemoveLocalReference} is executing, the core
|
||||
* worker will not be shut down, therefore it guarantees some kind of
|
||||
* In Java, GC runs in a standalone thread, and we can't control the exact timing of garbage
|
||||
* collection. By using this lock, when {@link NativeObjectStore#nativeRemoveLocalReference} is
|
||||
* executing, the core worker will not be shut down, therefore it guarantees some kind of
|
||||
* thread-safety. Note that this guarantee only works for driver.
|
||||
*/
|
||||
private final ReadWriteLock shutdownLock = new ReentrantReadWriteLock();
|
||||
|
@ -117,21 +114,29 @@ public final class RayNativeRuntime extends AbstractRayRuntime {
|
|||
rayletConfigStringMap.put(entry.getKey(), entry.getValue().toString());
|
||||
}
|
||||
|
||||
nativeInitialize(rayConfig.workerMode.getNumber(),
|
||||
rayConfig.nodeIp, rayConfig.getNodeManagerPort(),
|
||||
nativeInitialize(
|
||||
rayConfig.workerMode.getNumber(),
|
||||
rayConfig.nodeIp,
|
||||
rayConfig.getNodeManagerPort(),
|
||||
rayConfig.workerMode == WorkerType.DRIVER ? System.getProperty("user.dir") : "",
|
||||
rayConfig.objectStoreSocketName, rayConfig.rayletSocketName,
|
||||
rayConfig.objectStoreSocketName,
|
||||
rayConfig.rayletSocketName,
|
||||
(rayConfig.workerMode == WorkerType.DRIVER ? rayConfig.getJobId() : JobId.NIL).getBytes(),
|
||||
new GcsClientOptions(rayConfig), numWorkersPerProcess,
|
||||
rayConfig.logDir, rayletConfigStringMap, serializedJobConfig);
|
||||
new GcsClientOptions(rayConfig),
|
||||
numWorkersPerProcess,
|
||||
rayConfig.logDir,
|
||||
rayletConfigStringMap,
|
||||
serializedJobConfig);
|
||||
|
||||
taskExecutor = new NativeTaskExecutor(this);
|
||||
workerContext = new NativeWorkerContext();
|
||||
objectStore = new NativeObjectStore(workerContext, shutdownLock);
|
||||
taskSubmitter = new NativeTaskSubmitter();
|
||||
|
||||
LOGGER.debug("RayNativeRuntime started with store {}, raylet {}",
|
||||
rayConfig.objectStoreSocketName, rayConfig.rayletSocketName);
|
||||
LOGGER.debug(
|
||||
"RayNativeRuntime started with store {}, raylet {}",
|
||||
rayConfig.objectStoreSocketName,
|
||||
rayConfig.rayletSocketName);
|
||||
} catch (Exception e) {
|
||||
if (startRayHead) {
|
||||
try {
|
||||
|
@ -201,8 +206,8 @@ public final class RayNativeRuntime extends AbstractRayRuntime {
|
|||
|
||||
@Override
|
||||
public Object getAsyncContext() {
|
||||
return new AsyncContext(workerContext.getCurrentWorkerId(),
|
||||
workerContext.getCurrentClassLoader());
|
||||
return new AsyncContext(
|
||||
workerContext.getCurrentWorkerId(), workerContext.getCurrentClassLoader());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -229,10 +234,18 @@ public final class RayNativeRuntime extends AbstractRayRuntime {
|
|||
}
|
||||
|
||||
private static native void nativeInitialize(
|
||||
int workerMode, String ndoeIpAddress,
|
||||
int nodeManagerPort, String driverName, String storeSocket, String rayletSocket,
|
||||
byte[] jobId, GcsClientOptions gcsClientOptions, int numWorkersPerProcess,
|
||||
String logDir, Map<String, String> rayletConfigParameters, byte[] serializedJobConfig);
|
||||
int workerMode,
|
||||
String ndoeIpAddress,
|
||||
int nodeManagerPort,
|
||||
String driverName,
|
||||
String storeSocket,
|
||||
String rayletSocket,
|
||||
byte[] jobId,
|
||||
GcsClientOptions gcsClientOptions,
|
||||
int numWorkersPerProcess,
|
||||
String logDir,
|
||||
Map<String, String> rayletConfigParameters,
|
||||
byte[] serializedJobConfig);
|
||||
|
||||
private static native void nativeRunTaskExecutor(TaskExecutor taskExecutor);
|
||||
|
||||
|
|
|
@ -8,14 +8,10 @@ import io.ray.runtime.gcs.GcsClient;
|
|||
import io.ray.runtime.object.ObjectStore;
|
||||
import io.ray.runtime.task.TaskExecutor;
|
||||
|
||||
/**
|
||||
* This interface is required to make {@link RayRuntimeProxy} work.
|
||||
*/
|
||||
/** This interface is required to make {@link RayRuntimeProxy} work. */
|
||||
public interface RayRuntimeInternal extends RayRuntime {
|
||||
|
||||
/**
|
||||
* Start runtime.
|
||||
*/
|
||||
/** Start runtime. */
|
||||
void start();
|
||||
|
||||
WorkerContext getWorkerContext();
|
||||
|
|
|
@ -13,9 +13,7 @@ import java.lang.reflect.Method;
|
|||
*/
|
||||
public class RayRuntimeProxy implements InvocationHandler {
|
||||
|
||||
/**
|
||||
* The original runtime.
|
||||
*/
|
||||
/** The original runtime. */
|
||||
private AbstractRayRuntime obj;
|
||||
|
||||
private RayRuntimeProxy(AbstractRayRuntime obj) {
|
||||
|
@ -26,19 +24,20 @@ public class RayRuntimeProxy implements InvocationHandler {
|
|||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a new instance of {@link RayRuntimeInternal} with additional context check.
|
||||
*/
|
||||
/** Generate a new instance of {@link RayRuntimeInternal} with additional context check. */
|
||||
static RayRuntimeInternal newInstance(AbstractRayRuntime obj) {
|
||||
return (RayRuntimeInternal) java.lang.reflect.Proxy
|
||||
.newProxyInstance(obj.getClass().getClassLoader(), new Class<?>[]{RayRuntimeInternal.class},
|
||||
return (RayRuntimeInternal)
|
||||
java.lang.reflect.Proxy.newProxyInstance(
|
||||
obj.getClass().getClassLoader(),
|
||||
new Class<?>[] {RayRuntimeInternal.class},
|
||||
new RayRuntimeProxy(obj));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
if (isInterfaceMethod(method) && !method.getName().equals("shutdown") && !method.getName()
|
||||
.equals("setAsyncContext")) {
|
||||
if (isInterfaceMethod(method)
|
||||
&& !method.getName().equals("shutdown")
|
||||
&& !method.getName().equals("setAsyncContext")) {
|
||||
checkIsContextSet();
|
||||
}
|
||||
try {
|
||||
|
@ -52,9 +51,7 @@ public class RayRuntimeProxy implements InvocationHandler {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the method is defined in the {@link RayRuntime} interface.
|
||||
*/
|
||||
/** Whether the method is defined in the {@link RayRuntime} interface. */
|
||||
private boolean isInterfaceMethod(Method method) {
|
||||
try {
|
||||
RayRuntime.class.getMethod(method.getName(), method.getParameterTypes());
|
||||
|
@ -66,8 +63,8 @@ public class RayRuntimeProxy implements InvocationHandler {
|
|||
|
||||
/**
|
||||
* Check if thread context is set.
|
||||
* <p/>
|
||||
* This method should be invoked at the beginning of most public methods of {@link RayRuntime},
|
||||
*
|
||||
* <p>This method should be invoked at the beginning of most public methods of {@link RayRuntime},
|
||||
* otherwise the native code might crash due to thread local core worker was not set. We check it
|
||||
* for {@link AbstractRayRuntime} instead of {@link RayNativeRuntime} because we want to catch the
|
||||
* error even if the application runs in {@link RunMode#SINGLE_PROCESS} mode.
|
||||
|
|
|
@ -9,9 +9,7 @@ import java.io.ObjectInput;
|
|||
import java.io.ObjectOutput;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* Implementation of actor handle for local mode.
|
||||
*/
|
||||
/** Implementation of actor handle for local mode. */
|
||||
public class LocalModeActorHandle implements ActorHandle, Externalizable {
|
||||
|
||||
private ActorId actorId;
|
||||
|
@ -23,11 +21,8 @@ public class LocalModeActorHandle implements ActorHandle, Externalizable {
|
|||
this.previousActorTaskDummyObjectId.set(previousActorTaskDummyObjectId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by FST
|
||||
*/
|
||||
public LocalModeActorHandle() {
|
||||
}
|
||||
/** Required by FST. */
|
||||
public LocalModeActorHandle() {}
|
||||
|
||||
@Override
|
||||
public ActorId getId() {
|
||||
|
|
|
@ -16,9 +16,7 @@ import java.util.List;
|
|||
*/
|
||||
public abstract class NativeActorHandle implements BaseActorHandle, Externalizable {
|
||||
|
||||
/**
|
||||
* ID of the actor.
|
||||
*/
|
||||
/** ID of the actor. */
|
||||
byte[] actorId;
|
||||
|
||||
private Language language;
|
||||
|
@ -29,11 +27,8 @@ public abstract class NativeActorHandle implements BaseActorHandle, Externalizab
|
|||
this.language = language;
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by FST
|
||||
*/
|
||||
NativeActorHandle() {
|
||||
}
|
||||
/** Required by FST. */
|
||||
NativeActorHandle() {}
|
||||
|
||||
public static NativeActorHandle create(byte[] actorId) {
|
||||
Language language = Language.forNumber(nativeGetLanguage(actorId));
|
||||
|
@ -76,7 +71,7 @@ public abstract class NativeActorHandle implements BaseActorHandle, Externalizab
|
|||
/**
|
||||
* Serialize this actor handle to bytes.
|
||||
*
|
||||
* @return the bytes of the actor handle
|
||||
* <p>Returns the bytes of the actor handle
|
||||
*/
|
||||
public byte[] toBytes() {
|
||||
return nativeSerialize(actorId);
|
||||
|
@ -85,7 +80,7 @@ public abstract class NativeActorHandle implements BaseActorHandle, Externalizab
|
|||
/**
|
||||
* Deserialize an actor handle from bytes.
|
||||
*
|
||||
* @return the bytes of an actor handle
|
||||
* <p>Returns the bytes of an actor handle
|
||||
*/
|
||||
public static NativeActorHandle fromBytes(byte[] bytes) {
|
||||
byte[] actorId = nativeDeserialize(bytes);
|
||||
|
|
|
@ -7,20 +7,24 @@ import org.nustaq.serialization.FSTClazzInfo.FSTFieldInfo;
|
|||
import org.nustaq.serialization.FSTObjectInput;
|
||||
import org.nustaq.serialization.FSTObjectOutput;
|
||||
|
||||
/**
|
||||
* To deal with serialization about {@link NativeActorHandle}.
|
||||
*/
|
||||
/** To deal with serialization about {@link NativeActorHandle}. */
|
||||
public class NativeActorHandleSerializer extends FSTBasicObjectSerializer {
|
||||
|
||||
@Override
|
||||
public void writeObject(FSTObjectOutput out, Object toWrite, FSTClazzInfo clzInfo,
|
||||
FSTClazzInfo.FSTFieldInfo referencedBy, int streamPosition) throws IOException {
|
||||
public void writeObject(
|
||||
FSTObjectOutput out,
|
||||
Object toWrite,
|
||||
FSTClazzInfo clzInfo,
|
||||
FSTClazzInfo.FSTFieldInfo referencedBy,
|
||||
int streamPosition)
|
||||
throws IOException {
|
||||
((NativeActorHandle) toWrite).writeExternal(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readObject(FSTObjectInput in, Object toRead, FSTClazzInfo clzInfo,
|
||||
FSTFieldInfo referencedBy) throws Exception {
|
||||
public void readObject(
|
||||
FSTObjectInput in, Object toRead, FSTClazzInfo clzInfo, FSTFieldInfo referencedBy)
|
||||
throws Exception {
|
||||
super.readObject(in, toRead, clzInfo, referencedBy);
|
||||
((NativeActorHandle) toRead).readExternal(in);
|
||||
}
|
||||
|
|
|
@ -6,18 +6,14 @@ import io.ray.runtime.generated.Common.Language;
|
|||
import java.io.IOException;
|
||||
import java.io.ObjectInput;
|
||||
|
||||
/**
|
||||
* Java implementation of actor handle for cluster mode.
|
||||
*/
|
||||
/** Java implementation of actor handle for cluster mode. */
|
||||
public class NativeJavaActorHandle extends NativeActorHandle implements ActorHandle {
|
||||
|
||||
NativeJavaActorHandle(byte[] actorId) {
|
||||
super(actorId, Language.JAVA);
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by FST
|
||||
*/
|
||||
/** Required by FST. */
|
||||
public NativeJavaActorHandle() {
|
||||
super();
|
||||
}
|
||||
|
|
|
@ -6,18 +6,14 @@ import io.ray.runtime.generated.Common.Language;
|
|||
import java.io.IOException;
|
||||
import java.io.ObjectInput;
|
||||
|
||||
/**
|
||||
* Python actor handle implementation for cluster mode.
|
||||
*/
|
||||
/** Python actor handle implementation for cluster mode. */
|
||||
public class NativePyActorHandle extends NativeActorHandle implements PyActorHandle {
|
||||
|
||||
NativePyActorHandle(byte[] actorId) {
|
||||
super(actorId, Language.PYTHON);
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by FST
|
||||
*/
|
||||
/** Required by FST. */
|
||||
public NativePyActorHandle() {
|
||||
super();
|
||||
}
|
||||
|
|
|
@ -20,10 +20,7 @@ import org.apache.commons.lang3.BooleanUtils;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
|
||||
/**
|
||||
* Configurations of Ray runtime.
|
||||
* See `ray.default.conf` for the meaning of each field.
|
||||
*/
|
||||
/** Configurations of Ray runtime. See `ray.default.conf` for the meaning of each field. */
|
||||
public class RayConfig {
|
||||
|
||||
public static final String DEFAULT_CONFIG_FILE = "ray.default.conf";
|
||||
|
@ -31,10 +28,9 @@ public class RayConfig {
|
|||
|
||||
private Config config;
|
||||
|
||||
/**
|
||||
* IP of this node. if not provided, IP will be automatically detected.
|
||||
*/
|
||||
/** IP of this node. if not provided, IP will be automatically detected. */
|
||||
public final String nodeIp;
|
||||
|
||||
public final WorkerType workerMode;
|
||||
public final RunMode runMode;
|
||||
private JobId jobId;
|
||||
|
@ -64,8 +60,8 @@ public class RayConfig {
|
|||
|
||||
private void validate() {
|
||||
if (workerMode == WorkerType.WORKER) {
|
||||
Preconditions.checkArgument(redisAddress != null,
|
||||
"Redis address must be set in worker mode.");
|
||||
Preconditions.checkArgument(
|
||||
redisAddress != null, "Redis address must be set in worker mode.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,7 +141,8 @@ public class RayConfig {
|
|||
if (config.hasPath("ray.raylet.node-manager-port")) {
|
||||
nodeManagerPort = config.getInt("ray.raylet.node-manager-port");
|
||||
} else {
|
||||
Preconditions.checkState(workerMode != WorkerType.WORKER,
|
||||
Preconditions.checkState(
|
||||
workerMode != WorkerType.WORKER,
|
||||
"Worker started by raylet should accept the node manager port from raylet.");
|
||||
}
|
||||
|
||||
|
@ -217,9 +214,7 @@ public class RayConfig {
|
|||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the config value as a HOCON string.
|
||||
*/
|
||||
/** Renders the config value as a HOCON string. */
|
||||
@Override
|
||||
public String toString() {
|
||||
// These items might be dynamically generated or mutated at runtime.
|
||||
|
@ -257,10 +252,8 @@ public class RayConfig {
|
|||
}
|
||||
|
||||
/**
|
||||
* Create a RayConfig by reading configuration in the following order:
|
||||
* 1. System properties.
|
||||
* 2. `ray.conf` file.
|
||||
* 3. `ray.default.conf` file.
|
||||
* Create a RayConfig by reading configuration in the following order: 1. System properties. 2.
|
||||
* `ray.conf` file. 3. `ray.default.conf` file.
|
||||
*/
|
||||
public static RayConfig create() {
|
||||
ConfigFactory.invalidateCaches();
|
||||
|
@ -274,5 +267,4 @@ public class RayConfig {
|
|||
config = config.withFallback(ConfigFactory.load(DEFAULT_CONFIG_FILE));
|
||||
return new RayConfig(config.withOnlyPath("ray"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,13 +3,11 @@ package io.ray.runtime.config;
|
|||
public enum RunMode {
|
||||
|
||||
/**
|
||||
* Ray is running in one single Java process, without Raylet backend, object store, and GCS.
|
||||
* It's useful for debug.
|
||||
* Ray is running in one single Java process, without Raylet backend, object store, and GCS. It's
|
||||
* useful for debug.
|
||||
*/
|
||||
SINGLE_PROCESS,
|
||||
|
||||
/**
|
||||
* Ray is running on one or more nodes, with multiple processes.
|
||||
*/
|
||||
/** Ray is running on one or more nodes, with multiple processes. */
|
||||
CLUSTER,
|
||||
}
|
||||
|
|
|
@ -10,9 +10,7 @@ import io.ray.runtime.generated.Common.TaskSpec;
|
|||
import io.ray.runtime.generated.Common.TaskType;
|
||||
import io.ray.runtime.task.LocalModeTaskSubmitter;
|
||||
|
||||
/**
|
||||
* Worker context for local mode.
|
||||
*/
|
||||
/** Worker context for local mode. */
|
||||
public class LocalModeWorkerContext implements WorkerContext {
|
||||
|
||||
private final JobId jobId;
|
||||
|
@ -52,8 +50,7 @@ public class LocalModeWorkerContext implements WorkerContext {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentClassLoader(ClassLoader currentClassLoader) {
|
||||
}
|
||||
public void setCurrentClassLoader(ClassLoader currentClassLoader) {}
|
||||
|
||||
@Override
|
||||
public TaskType getCurrentTaskType() {
|
||||
|
|
|
@ -9,9 +9,7 @@ import io.ray.runtime.generated.Common.Address;
|
|||
import io.ray.runtime.generated.Common.TaskType;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* Worker context for cluster mode. This is a wrapper class for worker context of core worker.
|
||||
*/
|
||||
/** Worker context for cluster mode. This is a wrapper class for worker context of core worker. */
|
||||
public class NativeWorkerContext implements WorkerContext {
|
||||
|
||||
private final ThreadLocal<ClassLoader> currentClassLoader = new ThreadLocal<>();
|
||||
|
|
|
@ -26,15 +26,16 @@ public class RuntimeContextImpl implements RuntimeContext {
|
|||
@Override
|
||||
public ActorId getCurrentActorId() {
|
||||
ActorId actorId = runtime.getWorkerContext().getCurrentActorId();
|
||||
Preconditions.checkState(actorId != null && !actorId.isNil(),
|
||||
"This method should only be called from an actor.");
|
||||
Preconditions.checkState(
|
||||
actorId != null && !actorId.isNil(), "This method should only be called from an actor.");
|
||||
return actorId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wasCurrentActorRestarted() {
|
||||
TaskType currentTaskType = runtime.getWorkerContext().getCurrentTaskType();
|
||||
Preconditions.checkState(currentTaskType == TaskType.ACTOR_CREATION_TASK,
|
||||
Preconditions.checkState(
|
||||
currentTaskType == TaskType.ACTOR_CREATION_TASK,
|
||||
"This method can only be called from an actor creation task.");
|
||||
if (isSingleProcess()) {
|
||||
return false;
|
||||
|
|
|
@ -7,24 +7,16 @@ import io.ray.api.id.UniqueId;
|
|||
import io.ray.runtime.generated.Common.Address;
|
||||
import io.ray.runtime.generated.Common.TaskType;
|
||||
|
||||
/**
|
||||
* The context of worker.
|
||||
*/
|
||||
/** The context of worker. */
|
||||
public interface WorkerContext {
|
||||
|
||||
/**
|
||||
* ID of the current worker.
|
||||
*/
|
||||
/** ID of the current worker. */
|
||||
UniqueId getCurrentWorkerId();
|
||||
|
||||
/**
|
||||
* ID of the current job.
|
||||
*/
|
||||
/** ID of the current job. */
|
||||
JobId getCurrentJobId();
|
||||
|
||||
/**
|
||||
* ID of the current actor.
|
||||
*/
|
||||
/** ID of the current actor. */
|
||||
ActorId getCurrentActorId();
|
||||
|
||||
/**
|
||||
|
@ -33,19 +25,13 @@ public interface WorkerContext {
|
|||
*/
|
||||
ClassLoader getCurrentClassLoader();
|
||||
|
||||
/**
|
||||
* Set the current class loader.
|
||||
*/
|
||||
/** Set the current class loader. */
|
||||
void setCurrentClassLoader(ClassLoader currentClassLoader);
|
||||
|
||||
/**
|
||||
* Type of the current task.
|
||||
*/
|
||||
/** Type of the current task. */
|
||||
TaskType getCurrentTaskType();
|
||||
|
||||
/**
|
||||
* ID of the current task.
|
||||
*/
|
||||
/** ID of the current task. */
|
||||
TaskId getCurrentTaskId();
|
||||
|
||||
Address getRpcAddress();
|
||||
|
|
|
@ -7,8 +7,10 @@ public class CrossLanguageException extends RayException {
|
|||
private Language language;
|
||||
|
||||
public CrossLanguageException(io.ray.runtime.generated.Common.RayException exception) {
|
||||
super(String.format("An exception raised from %s:\n%s", exception.getLanguage().name(),
|
||||
exception.getFormattedExceptionString()));
|
||||
super(
|
||||
String.format(
|
||||
"An exception raised from %s:\n%s",
|
||||
exception.getLanguage().name(), exception.getFormattedExceptionString()));
|
||||
this.language = exception.getLanguage();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import io.ray.api.id.ActorId;
|
|||
/**
|
||||
* Indicates that the actor died unexpectedly before finishing a task.
|
||||
*
|
||||
* This exception could happen either because the actor process dies while executing a task, or
|
||||
* <p>This exception could happen either because the actor process dies while executing a task, or
|
||||
* because a task is submitted to a dead actor.
|
||||
*/
|
||||
public class RayActorException extends RayException {
|
||||
|
@ -17,8 +17,7 @@ public class RayActorException extends RayException {
|
|||
}
|
||||
|
||||
public RayActorException(ActorId actorId) {
|
||||
super(String.format(
|
||||
"The actor %s died unexpectedly before finishing this task.", actorId));
|
||||
super(String.format("The actor %s died unexpectedly before finishing this task.", actorId));
|
||||
this.actorId = actorId;
|
||||
}
|
||||
|
||||
|
@ -29,5 +28,4 @@ public class RayActorException extends RayException {
|
|||
public RayActorException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,8 +16,8 @@ public class RayException extends RuntimeException {
|
|||
}
|
||||
|
||||
public byte[] toBytes() {
|
||||
String formattedException = org.apache.commons.lang3.exception.ExceptionUtils
|
||||
.getStackTrace(this);
|
||||
String formattedException =
|
||||
org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace(this);
|
||||
io.ray.runtime.generated.Common.RayException.Builder builder =
|
||||
io.ray.runtime.generated.Common.RayException.newBuilder();
|
||||
builder.setLanguage(Language.JAVA);
|
||||
|
@ -26,13 +26,12 @@ public class RayException extends RuntimeException {
|
|||
return builder.build().toByteArray();
|
||||
}
|
||||
|
||||
public static RayException fromBytes(byte[] serialized)
|
||||
throws InvalidProtocolBufferException {
|
||||
public static RayException fromBytes(byte[] serialized) throws InvalidProtocolBufferException {
|
||||
io.ray.runtime.generated.Common.RayException exception =
|
||||
io.ray.runtime.generated.Common.RayException.parseFrom(serialized);
|
||||
if (exception.getLanguage() == Language.JAVA) {
|
||||
return Serializer
|
||||
.decode(exception.getSerializedException().toByteArray(), RayException.class);
|
||||
return Serializer.decode(
|
||||
exception.getSerializedException().toByteArray(), RayException.class);
|
||||
} else {
|
||||
return new CrossLanguageException(exception);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package io.ray.runtime.exception;
|
||||
|
||||
/**
|
||||
* The exception represents that there is an intentional system exit.
|
||||
*/
|
||||
/** The exception represents that there is an intentional system exit. */
|
||||
public class RayIntentionalSystemExitException extends RuntimeException {
|
||||
|
||||
public RayIntentionalSystemExitException(String message) {
|
||||
|
|
|
@ -6,8 +6,9 @@ import io.ray.runtime.util.SystemUtil;
|
|||
public class RayTaskException extends RayException {
|
||||
|
||||
public RayTaskException(String message, Throwable cause) {
|
||||
super(String.format("(pid=%d, ip=%s) %s",
|
||||
SystemUtil.pid(), NetworkUtil.getIpAddress(null), message), cause);
|
||||
super(
|
||||
String.format(
|
||||
"(pid=%d, ip=%s) %s", SystemUtil.pid(), NetworkUtil.getIpAddress(null), message),
|
||||
cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package io.ray.runtime.exception;
|
||||
|
||||
/**
|
||||
* Indicates that the worker died unexpectedly while executing a task.
|
||||
*/
|
||||
/** Indicates that the worker died unexpectedly while executing a task. */
|
||||
public class RayWorkerException extends RayException {
|
||||
|
||||
public RayWorkerException() {
|
||||
|
@ -16,5 +14,4 @@ public class RayWorkerException extends RayException {
|
|||
public RayWorkerException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,18 +3,18 @@ package io.ray.runtime.exception;
|
|||
import io.ray.api.id.ObjectId;
|
||||
|
||||
/**
|
||||
* Indicates that an object is lost (either evicted or explicitly deleted) and cannot be
|
||||
* restarted.
|
||||
* Indicates that an object is lost (either evicted or explicitly deleted) and cannot be restarted.
|
||||
*
|
||||
* Note, this exception only happens for actor objects. If actor's current state is after object's
|
||||
* creating task, the actor cannot re-run the task to reconstruct the object.
|
||||
* <p>Note, this exception only happens for actor objects. If actor's current state is after
|
||||
* object's creating task, the actor cannot re-run the task to reconstruct the object.
|
||||
*/
|
||||
public class UnreconstructableException extends RayException {
|
||||
|
||||
public ObjectId objectId;
|
||||
|
||||
public UnreconstructableException(ObjectId objectId) {
|
||||
super(String.format(
|
||||
super(
|
||||
String.format(
|
||||
"Object %s is lost (either evicted or explicitly deleted) and cannot be reconstructed.",
|
||||
objectId));
|
||||
this.objectId = objectId;
|
||||
|
@ -27,5 +27,4 @@ public class UnreconstructableException extends RayException {
|
|||
public UnreconstructableException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,18 +6,14 @@ import java.util.List;
|
|||
/**
|
||||
* Base interface of a Ray task's function descriptor.
|
||||
*
|
||||
* A function descriptor is a list of strings that can uniquely describe a function. It's used to
|
||||
* <p>A function descriptor is a list of strings that can uniquely describe a function. It's used to
|
||||
* load a function in workers.
|
||||
*/
|
||||
public interface FunctionDescriptor {
|
||||
|
||||
/**
|
||||
* @return A list of strings represents the functions.
|
||||
*/
|
||||
/** Returns A list of strings represents the functions. */
|
||||
List<String> toList();
|
||||
|
||||
/**
|
||||
* @return The language of the function.
|
||||
*/
|
||||
/** Returns The language of the function. */
|
||||
Language getLanguage();
|
||||
}
|
||||
|
|
|
@ -34,9 +34,7 @@ import org.objectweb.asm.Type;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Manages functions by job id.
|
||||
*/
|
||||
/** Manages functions by job id. */
|
||||
public class FunctionManager {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(FunctionManager.class);
|
||||
|
@ -52,21 +50,16 @@ public class FunctionManager {
|
|||
private static final ThreadLocal<WeakHashMap<Class<? extends RayFunc>, JavaFunctionDescriptor>>
|
||||
RAY_FUNC_CACHE = ThreadLocal.withInitial(WeakHashMap::new);
|
||||
|
||||
/**
|
||||
* Mapping from the job id to the functions that belong to this job.
|
||||
*/
|
||||
/** Mapping from the job id to the functions that belong to this job. */
|
||||
private ConcurrentMap<JobId, JobFunctionTable> jobFunctionTables = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* The resource path which we can load the job's jar resources.
|
||||
*/
|
||||
/** The resource path which we can load the job's jar resources. */
|
||||
private final List<String> codeSearchPath;
|
||||
|
||||
/**
|
||||
* Construct a FunctionManager with the specified code search path.
|
||||
*
|
||||
* @param codeSearchPath The specified job resource that can store the job's
|
||||
* resources.
|
||||
* @param codeSearchPath The specified job resource that can store the job's resources.
|
||||
*/
|
||||
public FunctionManager(List<String> codeSearchPath) {
|
||||
this.codeSearchPath = codeSearchPath;
|
||||
|
@ -76,8 +69,7 @@ public class FunctionManager {
|
|||
* Get the RayFunction from a RayFunc instance (a lambda).
|
||||
*
|
||||
* @param jobId current job id.
|
||||
* @param func The lambda.
|
||||
* @return A RayFunction object.
|
||||
* @param func The lambda. Returns A RayFunction object.
|
||||
*/
|
||||
public RayFunction getFunction(JobId jobId, RayFunc func) {
|
||||
JavaFunctionDescriptor functionDescriptor = RAY_FUNC_CACHE.get().get(func.getClass());
|
||||
|
@ -98,11 +90,9 @@ public class FunctionManager {
|
|||
* Get the RayFunction from a function descriptor.
|
||||
*
|
||||
* @param jobId Current job id.
|
||||
* @param functionDescriptor The function descriptor.
|
||||
* @return A RayFunction object.
|
||||
* @param functionDescriptor The function descriptor. Returns A RayFunction object.
|
||||
*/
|
||||
public RayFunction getFunction(JobId jobId,
|
||||
JavaFunctionDescriptor functionDescriptor) {
|
||||
public RayFunction getFunction(JobId jobId, JavaFunctionDescriptor functionDescriptor) {
|
||||
JobFunctionTable jobFunctionTable = jobFunctionTables.get(jobId);
|
||||
if (jobFunctionTable == null) {
|
||||
synchronized (this) {
|
||||
|
@ -121,21 +111,27 @@ public class FunctionManager {
|
|||
if (codeSearchPath == null || codeSearchPath.isEmpty()) {
|
||||
classLoader = getClass().getClassLoader();
|
||||
} else {
|
||||
URL[] urls = codeSearchPath.stream()
|
||||
URL[] urls =
|
||||
codeSearchPath.stream()
|
||||
.filter(p -> StringUtils.isNotBlank(p) && Files.exists(Paths.get(p)))
|
||||
.flatMap(p -> {
|
||||
.flatMap(
|
||||
p -> {
|
||||
try {
|
||||
if (!Files.isDirectory(Paths.get(p))) {
|
||||
if (!p.endsWith(".jar")) {
|
||||
return Stream.of(Paths.get(p).getParent().toAbsolutePath().toUri().toURL());
|
||||
return Stream.of(
|
||||
Paths.get(p).getParent().toAbsolutePath().toUri().toURL());
|
||||
} else {
|
||||
return Stream.of(Paths.get(p).toAbsolutePath().toUri().toURL());
|
||||
}
|
||||
} else {
|
||||
List<URL> subUrls = new ArrayList<>();
|
||||
subUrls.add(Paths.get(p).toAbsolutePath().toUri().toURL());
|
||||
Collection<File> jars = FileUtils.listFiles(new File(p),
|
||||
new RegexFileFilter(".*\\.jar"), DirectoryFileFilter.DIRECTORY);
|
||||
Collection<File> jars =
|
||||
FileUtils.listFiles(
|
||||
new File(p),
|
||||
new RegexFileFilter(".*\\.jar"),
|
||||
DirectoryFileFilter.DIRECTORY);
|
||||
for (File jar : jars) {
|
||||
subUrls.add(jar.toPath().toUri().toURL());
|
||||
}
|
||||
|
@ -144,7 +140,8 @@ public class FunctionManager {
|
|||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException(String.format("Illegal %s resource path", p));
|
||||
}
|
||||
}).toArray(URL[]::new);
|
||||
})
|
||||
.toArray(URL[]::new);
|
||||
classLoader = new URLClassLoader(urls);
|
||||
LOGGER.debug("Resource loaded for job {} from path {}.", jobId, urls);
|
||||
}
|
||||
|
@ -152,18 +149,12 @@ public class FunctionManager {
|
|||
return new JobFunctionTable(classLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Manages all functions that belong to one job.
|
||||
*/
|
||||
/** Manages all functions that belong to one job. */
|
||||
static class JobFunctionTable {
|
||||
|
||||
/**
|
||||
* The job's corresponding class loader.
|
||||
*/
|
||||
/** The job's corresponding class loader. */
|
||||
final ClassLoader classLoader;
|
||||
/**
|
||||
* Functions per class, per function name + type descriptor.
|
||||
*/
|
||||
/** Functions per class, per function name + type descriptor. */
|
||||
ConcurrentMap<String, Map<Pair<String, String>, RayFunction>> functions;
|
||||
|
||||
JobFunctionTable(ClassLoader classLoader) {
|
||||
|
@ -187,7 +178,8 @@ public class FunctionManager {
|
|||
if (func == null) {
|
||||
if (classFunctions.containsKey(key)) {
|
||||
throw new RuntimeException(
|
||||
String.format("RayFunction %s is overloaded, the signature can't be empty.",
|
||||
String.format(
|
||||
"RayFunction %s is overloaded, the signature can't be empty.",
|
||||
descriptor.toString()));
|
||||
} else {
|
||||
throw new RuntimeException(
|
||||
|
@ -197,9 +189,7 @@ public class FunctionManager {
|
|||
return func;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all functions from a class.
|
||||
*/
|
||||
/** Load all functions from a class. */
|
||||
Map<Pair<String, String>, RayFunction> loadFunctionsForClass(String className) {
|
||||
// If RayFunction is null, the function is overloaded.
|
||||
Map<Pair<String, String>, RayFunction> map = new HashMap<>();
|
||||
|
@ -232,8 +222,9 @@ public class FunctionManager {
|
|||
final Type type =
|
||||
e instanceof Method ? Type.getType((Method) e) : Type.getType((Constructor) e);
|
||||
final String signature = type.getDescriptor();
|
||||
RayFunction rayFunction = new RayFunction(e, classLoader,
|
||||
new JavaFunctionDescriptor(className, methodName, signature));
|
||||
RayFunction rayFunction =
|
||||
new RayFunction(
|
||||
e, classLoader, new JavaFunctionDescriptor(className, methodName, signature));
|
||||
map.put(ImmutablePair.of(methodName, signature), rayFunction);
|
||||
// For cross language call java function without signature
|
||||
final Pair<String, String> emptyDescriptor = ImmutablePair.of(methodName, "");
|
||||
|
|
|
@ -5,22 +5,14 @@ import com.google.common.collect.ImmutableList;
|
|||
import io.ray.runtime.generated.Common.Language;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents metadata of Java function.
|
||||
*/
|
||||
/** Represents metadata of Java function. */
|
||||
public final class JavaFunctionDescriptor implements FunctionDescriptor {
|
||||
|
||||
/**
|
||||
* Function's class name.
|
||||
*/
|
||||
/** Function's class name. */
|
||||
public final String className;
|
||||
/**
|
||||
* Function's name.
|
||||
*/
|
||||
/** Function's name. */
|
||||
public final String name;
|
||||
/**
|
||||
* Function's signature.
|
||||
*/
|
||||
/** Function's signature. */
|
||||
public final String signature;
|
||||
|
||||
public JavaFunctionDescriptor(String className, String name, String signature) {
|
||||
|
@ -43,9 +35,9 @@ public final class JavaFunctionDescriptor implements FunctionDescriptor {
|
|||
return false;
|
||||
}
|
||||
JavaFunctionDescriptor that = (JavaFunctionDescriptor) o;
|
||||
return Objects.equal(className, that.className) &&
|
||||
Objects.equal(name, that.name) &&
|
||||
Objects.equal(signature, that.signature);
|
||||
return Objects.equal(className, that.className)
|
||||
&& Objects.equal(name, that.name)
|
||||
&& Objects.equal(signature, that.signature);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,9 +5,7 @@ import io.ray.runtime.generated.Common.Language;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents metadata of a Python function.
|
||||
*/
|
||||
/** Represents metadata of a Python function. */
|
||||
public class PyFunctionDescriptor implements FunctionDescriptor {
|
||||
|
||||
public String moduleName;
|
||||
|
@ -36,9 +34,9 @@ public class PyFunctionDescriptor implements FunctionDescriptor {
|
|||
return false;
|
||||
}
|
||||
PyFunctionDescriptor that = (PyFunctionDescriptor) o;
|
||||
return Objects.equal(moduleName, that.moduleName) &&
|
||||
Objects.equal(className, that.className) &&
|
||||
Objects.equal(functionName, that.functionName);
|
||||
return Objects.equal(moduleName, that.moduleName)
|
||||
&& Objects.equal(className, that.className)
|
||||
&& Objects.equal(functionName, that.functionName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,4 +54,3 @@ public class PyFunctionDescriptor implements FunctionDescriptor {
|
|||
return Language.PYTHON;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,50 +5,36 @@ import java.lang.reflect.Executable;
|
|||
import java.lang.reflect.Method;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Represents a Ray function (either a Method or a Constructor in Java) and its metadata.
|
||||
*/
|
||||
/** Represents a Ray function (either a Method or a Constructor in Java) and its metadata. */
|
||||
public class RayFunction {
|
||||
|
||||
/**
|
||||
* The executor object, can be either a Method or a Constructor.
|
||||
*/
|
||||
/** The executor object, can be either a Method or a Constructor. */
|
||||
public final Executable executable;
|
||||
|
||||
/**
|
||||
* This function's class loader.
|
||||
*/
|
||||
/** This function's class loader. */
|
||||
public final ClassLoader classLoader;
|
||||
|
||||
/**
|
||||
* Function's metadata.
|
||||
*/
|
||||
/** Function's metadata. */
|
||||
public final JavaFunctionDescriptor functionDescriptor;
|
||||
|
||||
public RayFunction(Executable executable, ClassLoader classLoader,
|
||||
JavaFunctionDescriptor functionDescriptor) {
|
||||
public RayFunction(
|
||||
Executable executable, ClassLoader classLoader, JavaFunctionDescriptor functionDescriptor) {
|
||||
this.executable = executable;
|
||||
this.classLoader = classLoader;
|
||||
this.functionDescriptor = functionDescriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return True if it's a constructor, otherwise it's a method.
|
||||
*/
|
||||
/** Returns True if it's a constructor, otherwise it's a method. */
|
||||
public boolean isConstructor() {
|
||||
return executable instanceof Constructor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The underlying constructor object.
|
||||
*/
|
||||
/** Returns The underlying constructor object. */
|
||||
public Constructor<?> getConstructor() {
|
||||
return (Constructor<?>) executable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The underlying method object.
|
||||
*/
|
||||
/** Returns The underlying method object. */
|
||||
public Method getMethod() {
|
||||
return (Method) executable;
|
||||
}
|
||||
|
@ -57,9 +43,7 @@ public class RayFunction {
|
|||
return functionDescriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether this function has a return value.
|
||||
*/
|
||||
/** Returns Whether this function has a return value. */
|
||||
public boolean hasReturn() {
|
||||
if (isConstructor()) {
|
||||
return true;
|
||||
|
@ -68,9 +52,7 @@ public class RayFunction {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Return type.
|
||||
*/
|
||||
/** Returns Return type. */
|
||||
public Optional<Class<?>> getReturnType() {
|
||||
if (hasReturn()) {
|
||||
return Optional.of(((Method) executable).getReturnType());
|
||||
|
|
|
@ -20,9 +20,7 @@ import org.apache.commons.lang3.ArrayUtils;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* An implementation of GcsClient.
|
||||
*/
|
||||
/** An implementation of GcsClient. */
|
||||
public class GcsClient {
|
||||
private static Logger LOGGER = LoggerFactory.getLogger(GcsClient.class);
|
||||
private RedisClient primary;
|
||||
|
@ -35,9 +33,9 @@ public class GcsClient {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get placement group by {@link PlacementGroupId}
|
||||
* @param placementGroupId Id of placement group.
|
||||
* @return The placement group.
|
||||
* Get placement group by {@link PlacementGroupId}.
|
||||
*
|
||||
* @param placementGroupId Id of placement group. Returns The placement group.
|
||||
*/
|
||||
public PlacementGroup getPlacementGroupInfo(PlacementGroupId placementGroupId) {
|
||||
byte[] result = globalStateAccessor.getPlacementGroupInfo(placementGroupId);
|
||||
|
@ -46,7 +44,8 @@ public class GcsClient {
|
|||
|
||||
/**
|
||||
* Get all placement groups in this cluster.
|
||||
* @return All placement groups.
|
||||
*
|
||||
* <p>Returns All placement groups.
|
||||
*/
|
||||
public List<PlacementGroup> getAllPlacementGroupInfo() {
|
||||
List<byte[]> results = globalStateAccessor.getAllPlacementGroupInfo();
|
||||
|
@ -71,15 +70,20 @@ public class GcsClient {
|
|||
} catch (InvalidProtocolBufferException e) {
|
||||
throw new RuntimeException("Received invalid protobuf data from GCS.");
|
||||
}
|
||||
final UniqueId nodeId = UniqueId
|
||||
.fromByteBuffer(data.getNodeId().asReadOnlyByteBuffer());
|
||||
final UniqueId nodeId = UniqueId.fromByteBuffer(data.getNodeId().asReadOnlyByteBuffer());
|
||||
|
||||
// NOTE(lingxuan.zlx): we assume no duplicated node id in fetched node list
|
||||
// and it's only one final state for each node in recorded table.
|
||||
NodeInfo nodeInfo = new NodeInfo(
|
||||
nodeId, data.getNodeManagerAddress(), data.getNodeManagerHostname(),
|
||||
data.getNodeManagerPort(), data.getObjectStoreSocketName(), data.getRayletSocketName(),
|
||||
data.getState() == GcsNodeInfo.GcsNodeState.ALIVE, new HashMap<>());
|
||||
NodeInfo nodeInfo =
|
||||
new NodeInfo(
|
||||
nodeId,
|
||||
data.getNodeManagerAddress(),
|
||||
data.getNodeManagerHostname(),
|
||||
data.getNodeManagerPort(),
|
||||
data.getObjectStoreSocketName(),
|
||||
data.getRayletSocketName(),
|
||||
data.getState() == GcsNodeInfo.GcsNodeState.ALIVE,
|
||||
new HashMap<>());
|
||||
nodes.put(nodeId, nodeInfo);
|
||||
}
|
||||
|
||||
|
@ -119,9 +123,7 @@ public class GcsClient {
|
|||
return resources;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the actor exists in GCS.
|
||||
*/
|
||||
/** If the actor exists in GCS. */
|
||||
public boolean actorExists(ActorId actorId) {
|
||||
byte[] result = globalStateAccessor.getActorInfo(actorId);
|
||||
return result != null;
|
||||
|
@ -149,9 +151,7 @@ public class GcsClient {
|
|||
return JobId.fromInt(jobCounter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy global state accessor when ray native runtime will be shutdown.
|
||||
*/
|
||||
/** Destroy global state accessor when ray native runtime will be shutdown. */
|
||||
public void destroy() {
|
||||
// Only ray shutdown should call gcs client destroy.
|
||||
LOGGER.debug("Destroying global state accessor.");
|
||||
|
|
|
@ -3,9 +3,7 @@ package io.ray.runtime.gcs;
|
|||
import com.google.common.base.Preconditions;
|
||||
import io.ray.runtime.config.RayConfig;
|
||||
|
||||
/**
|
||||
* Options to create GCS Client.
|
||||
*/
|
||||
/** Options to create GCS Client. */
|
||||
public class GcsClientOptions {
|
||||
public String ip;
|
||||
public int port;
|
||||
|
|
|
@ -6,18 +6,15 @@ import io.ray.api.id.PlacementGroupId;
|
|||
import io.ray.api.id.UniqueId;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* `GlobalStateAccessor` is used for accessing information from GCS.
|
||||
*
|
||||
**/
|
||||
/** `GlobalStateAccessor` is used for accessing information from GCS. */
|
||||
public class GlobalStateAccessor {
|
||||
// NOTE(lingxuan.zlx): this is a singleton, it can not be changed during a Ray session.
|
||||
// Native pointer to the C++ GcsStateAccessor.
|
||||
private Long globalStateAccessorNativePointer = 0L;
|
||||
private static GlobalStateAccessor globalStateAccessor;
|
||||
|
||||
public static synchronized GlobalStateAccessor getInstance(String redisAddress,
|
||||
String redisPassword) {
|
||||
public static synchronized GlobalStateAccessor getInstance(
|
||||
String redisAddress, String redisPassword) {
|
||||
if (null == globalStateAccessor) {
|
||||
globalStateAccessor = new GlobalStateAccessor(redisAddress, redisPassword);
|
||||
}
|
||||
|
@ -32,8 +29,7 @@ public class GlobalStateAccessor {
|
|||
}
|
||||
|
||||
private GlobalStateAccessor(String redisAddress, String redisPassword) {
|
||||
globalStateAccessorNativePointer =
|
||||
nativeCreateGlobalStateAccessor(redisAddress, redisPassword);
|
||||
globalStateAccessorNativePointer = nativeCreateGlobalStateAccessor(redisAddress, redisPassword);
|
||||
validateGlobalStateAccessorPointer();
|
||||
connect();
|
||||
}
|
||||
|
@ -43,13 +39,12 @@ public class GlobalStateAccessor {
|
|||
}
|
||||
|
||||
private void validateGlobalStateAccessorPointer() {
|
||||
Preconditions.checkState(globalStateAccessorNativePointer != 0,
|
||||
Preconditions.checkState(
|
||||
globalStateAccessorNativePointer != 0,
|
||||
"Global state accessor native pointer must not be 0.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A list of job info with JobInfo protobuf schema.
|
||||
*/
|
||||
/** Returns A list of job info with JobInfo protobuf schema. */
|
||||
public List<byte[]> getAllJobInfo() {
|
||||
// Fetch a job list with protobuf bytes format from GCS.
|
||||
synchronized (GlobalStateAccessor.class) {
|
||||
|
@ -58,9 +53,7 @@ public class GlobalStateAccessor {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A list of node info with GcsNodeInfo protobuf schema.
|
||||
*/
|
||||
/** Returns A list of node info with GcsNodeInfo protobuf schema. */
|
||||
public List<byte[]> getAllNodeInfo() {
|
||||
// Fetch a node list with protobuf bytes format from GCS.
|
||||
synchronized (GlobalStateAccessor.class) {
|
||||
|
@ -70,6 +63,8 @@ public class GlobalStateAccessor {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get node resource info.
|
||||
*
|
||||
* @param nodeId node unique id.
|
||||
* @return A map of node resource info in protobuf schema.
|
||||
*/
|
||||
|
@ -83,8 +78,8 @@ public class GlobalStateAccessor {
|
|||
public byte[] getPlacementGroupInfo(PlacementGroupId placementGroupId) {
|
||||
synchronized (GlobalStateAccessor.class) {
|
||||
validateGlobalStateAccessorPointer();
|
||||
return nativeGetPlacementGroupInfo(globalStateAccessorNativePointer,
|
||||
placementGroupId.getBytes());
|
||||
return nativeGetPlacementGroupInfo(
|
||||
globalStateAccessorNativePointer, placementGroupId.getBytes());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,9 +97,7 @@ public class GlobalStateAccessor {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A list of actor info with ActorInfo protobuf schema.
|
||||
*/
|
||||
/** Returns A list of actor info with ActorInfo protobuf schema. */
|
||||
public List<byte[]> getAllActorInfo() {
|
||||
// Fetch a actor list with protobuf bytes format from GCS.
|
||||
synchronized (GlobalStateAccessor.class) {
|
||||
|
@ -113,9 +106,7 @@ public class GlobalStateAccessor {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return An actor info with ActorInfo protobuf schema.
|
||||
*/
|
||||
/** Returns An actor info with ActorInfo protobuf schema. */
|
||||
public byte[] getActorInfo(ActorId actorId) {
|
||||
// Fetch an actor with protobuf bytes format from GCS.
|
||||
synchronized (GlobalStateAccessor.class) {
|
||||
|
@ -152,8 +143,7 @@ public class GlobalStateAccessor {
|
|||
|
||||
private native byte[] nativeGetActorInfo(long nativePtr, byte[] actorId);
|
||||
|
||||
private native byte[] nativeGetPlacementGroupInfo(long nativePtr,
|
||||
byte[] placementGroupId);
|
||||
private native byte[] nativeGetPlacementGroupInfo(long nativePtr, byte[] placementGroupId);
|
||||
|
||||
private native List<byte[]> nativeGetAllPlacementGroupInfo(long nativePtr);
|
||||
}
|
||||
|
|
|
@ -7,9 +7,7 @@ import redis.clients.jedis.Jedis;
|
|||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
|
||||
/**
|
||||
* Redis client class.
|
||||
*/
|
||||
/** Redis client class. */
|
||||
public class RedisClient {
|
||||
|
||||
private static final int JEDIS_POOL_SIZE = 1;
|
||||
|
@ -23,19 +21,20 @@ public class RedisClient {
|
|||
public RedisClient(String redisAddress, String password) {
|
||||
String[] ipAndPort = redisAddress.split(":");
|
||||
if (ipAndPort.length != 2) {
|
||||
throw new IllegalArgumentException("The argument redisAddress " +
|
||||
"should be formatted as ip:port.");
|
||||
throw new IllegalArgumentException(
|
||||
"The argument redisAddress " + "should be formatted as ip:port.");
|
||||
}
|
||||
|
||||
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
|
||||
jedisPoolConfig.setMaxTotal(JEDIS_POOL_SIZE);
|
||||
|
||||
if (Strings.isNullOrEmpty(password)) {
|
||||
jedisPool = new JedisPool(jedisPoolConfig,
|
||||
ipAndPort[0], Integer.parseInt(ipAndPort[1]), 30000);
|
||||
jedisPool =
|
||||
new JedisPool(jedisPoolConfig, ipAndPort[0], Integer.parseInt(ipAndPort[1]), 30000);
|
||||
} else {
|
||||
jedisPool = new JedisPool(jedisPoolConfig, ipAndPort[0],
|
||||
Integer.parseInt(ipAndPort[1]), 30000, password);
|
||||
jedisPool =
|
||||
new JedisPool(
|
||||
jedisPoolConfig, ipAndPort[0], Integer.parseInt(ipAndPort[1]), 30000, password);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,7 +88,7 @@ public class RedisClient {
|
|||
/**
|
||||
* Return the specified elements of the list stored at the specified key.
|
||||
*
|
||||
* @return Multi bulk reply, specifically a list of elements in the specified range.
|
||||
* <p>Returns Multi bulk reply, specifically a list of elements in the specified range.
|
||||
*/
|
||||
public List<byte[]> lrange(byte[] key, long start, long end) {
|
||||
try (Jedis jedis = jedisPool.getResource()) {
|
||||
|
@ -97,9 +96,7 @@ public class RedisClient {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the key exists in Redis.
|
||||
*/
|
||||
/** Whether the key exists in Redis. */
|
||||
public boolean exists(byte[] key) {
|
||||
try (Jedis jedis = jedisPool.getResource()) {
|
||||
return jedis.exists(key);
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
package io.ray.runtime.metric;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.DoubleAdder;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Count measurement is mapped to count object in stats and counts the number.
|
||||
*/
|
||||
/** Count measurement is mapped to count object in stats and counts the number. */
|
||||
public class Count extends Metric {
|
||||
|
||||
private DoubleAdder count;
|
||||
|
@ -16,7 +13,11 @@ public class Count extends Metric {
|
|||
public Count(String name, String description, String unit, Map<TagKey, String> tags) {
|
||||
super(name, tags);
|
||||
count = new DoubleAdder();
|
||||
metricNativePointer = NativeMetric.registerCountNative(name, description, unit,
|
||||
metricNativePointer =
|
||||
NativeMetric.registerCountNative(
|
||||
name,
|
||||
description,
|
||||
unit,
|
||||
tags.keySet().stream().map(TagKey::getTagKey).collect(Collectors.toList()));
|
||||
Preconditions.checkState(metricNativePointer != 0, "Count native pointer must not be 0.");
|
||||
}
|
||||
|
|
|
@ -4,15 +4,16 @@ import com.google.common.base.Preconditions;
|
|||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* Gauge measurement is mapped to gauge object in stats and is recording the last value.
|
||||
*/
|
||||
/** Gauge measurement is mapped to gauge object in stats and is recording the last value. */
|
||||
public class Gauge extends Metric {
|
||||
|
||||
public Gauge(String name, String description, String unit, Map<TagKey, String> tags) {
|
||||
super(name, tags);
|
||||
metricNativePointer = NativeMetric.registerGaugeNative(name, description, unit,
|
||||
metricNativePointer =
|
||||
NativeMetric.registerGaugeNative(
|
||||
name,
|
||||
description,
|
||||
unit,
|
||||
tags.keySet().stream().map(TagKey::getTagKey).collect(Collectors.toList()));
|
||||
Preconditions.checkState(metricNativePointer != 0, "Gauge native pointer must not be 0.");
|
||||
}
|
||||
|
@ -31,4 +32,3 @@ public class Gauge extends Metric {
|
|||
this.value.set(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package io.ray.runtime.metric;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -9,23 +8,30 @@ import java.util.Map;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Histogram measurement is mapped to histogram object in stats.
|
||||
* In order to reduce JNI calls overhead, a memory historical window is used
|
||||
* for storing transient value and we assume its max size is 100.
|
||||
* Histogram measurement is mapped to histogram object in stats. In order to reduce JNI calls
|
||||
* overhead, a memory historical window is used for storing transient value and we assume its max
|
||||
* size is 100.
|
||||
*/
|
||||
public class Histogram extends Metric {
|
||||
|
||||
private List<Double> histogramWindow;
|
||||
public static final int HISTOGRAM_WINDOW_SIZE = 100;
|
||||
|
||||
public Histogram(String name, String description, String unit, List<Double> boundaries,
|
||||
public Histogram(
|
||||
String name,
|
||||
String description,
|
||||
String unit,
|
||||
List<Double> boundaries,
|
||||
Map<TagKey, String> tags) {
|
||||
super(name, tags);
|
||||
metricNativePointer = NativeMetric.registerHistogramNative(name, description, unit,
|
||||
metricNativePointer =
|
||||
NativeMetric.registerHistogramNative(
|
||||
name,
|
||||
description,
|
||||
unit,
|
||||
boundaries.stream().mapToDouble(Double::doubleValue).toArray(),
|
||||
tags.keySet().stream().map(TagKey::getTagKey).collect(Collectors.toList()));
|
||||
Preconditions.checkState(metricNativePointer != 0,
|
||||
"Histogram native pointer must not be 0.");
|
||||
Preconditions.checkState(metricNativePointer != 0, "Histogram native pointer must not be 0.");
|
||||
histogramWindow = Collections.synchronizedList(new ArrayList<>());
|
||||
}
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@ import java.util.Map;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Class metric is mapped to stats metric object in core worker.
|
||||
* it must be in categories set [Gague, Count, Sum, Histogram].
|
||||
* Class metric is mapped to stats metric object in core worker. it must be in categories set
|
||||
* [Gague, Count, Sum, Histogram].
|
||||
*/
|
||||
public abstract class Metric {
|
||||
protected String name;
|
||||
|
@ -33,9 +33,7 @@ public abstract class Metric {
|
|||
// Metric data will be flushed into stats view data inside core worker immediately after
|
||||
// record is called.
|
||||
|
||||
/**
|
||||
* Flush records to stats in last aggregator.
|
||||
*/
|
||||
/** Flush records to stats in last aggregator. */
|
||||
public void record() {
|
||||
Preconditions.checkState(metricNativePointer != 0, "Metric native pointer must not be 0.");
|
||||
// Get tag key list from map;
|
||||
|
@ -46,20 +44,22 @@ public abstract class Metric {
|
|||
tagValues.add(entry.getValue());
|
||||
}
|
||||
// Get tag value list from map;
|
||||
NativeMetric.recordNative(metricNativePointer, getAndReset(), nativeTagKeyList.stream()
|
||||
.map(TagKey::getTagKey).collect(Collectors.toList()), tagValues);
|
||||
NativeMetric.recordNative(
|
||||
metricNativePointer,
|
||||
getAndReset(),
|
||||
nativeTagKeyList.stream().map(TagKey::getTagKey).collect(Collectors.toList()),
|
||||
tagValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value to record and then reset.
|
||||
*
|
||||
* @return latest updating value.
|
||||
* <p>Returns latest updating value.
|
||||
*/
|
||||
protected abstract double getAndReset();
|
||||
|
||||
/**
|
||||
* Update gauge value without tags.
|
||||
* Update metric info for user.
|
||||
* Update gauge value without tags. Update metric info for user.
|
||||
*
|
||||
* @param value latest value for updating
|
||||
*/
|
||||
|
@ -76,14 +76,11 @@ public abstract class Metric {
|
|||
this.tags = tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deallocate object from stats and reset native pointer in null.
|
||||
*/
|
||||
/** Deallocate object from stats and reset native pointer in null. */
|
||||
public void unregister() {
|
||||
if (0 != metricNativePointer) {
|
||||
NativeMetric.unregisterMetricNative(metricNativePointer);
|
||||
}
|
||||
metricNativePointer = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,17 +2,16 @@ package io.ray.runtime.metric;
|
|||
|
||||
import com.google.common.base.MoreObjects;
|
||||
|
||||
/**
|
||||
* Configurations of the metric.
|
||||
*/
|
||||
/** Configurations of the metric. */
|
||||
public class MetricConfig {
|
||||
|
||||
private static final long DEFAULT_TIME_INTERVAL_MS = 5000L;
|
||||
private static final int DEFAULT_THREAD_POLL_SIZE = 1;
|
||||
private static final long DEFAULT_SHUTDOWN_WAIT_TIME_MS = 3000L;
|
||||
|
||||
public static final MetricConfig DEFAULT_CONFIG = new MetricConfig(DEFAULT_TIME_INTERVAL_MS,
|
||||
DEFAULT_THREAD_POLL_SIZE, DEFAULT_SHUTDOWN_WAIT_TIME_MS);
|
||||
public static final MetricConfig DEFAULT_CONFIG =
|
||||
new MetricConfig(
|
||||
DEFAULT_TIME_INTERVAL_MS, DEFAULT_THREAD_POLL_SIZE, DEFAULT_SHUTDOWN_WAIT_TIME_MS);
|
||||
|
||||
private final long timeIntervalMs;
|
||||
private final int threadPoolSize;
|
||||
|
@ -73,6 +72,4 @@ public class MetricConfig {
|
|||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -5,10 +5,9 @@ import java.util.Map;
|
|||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* MetricId represents a metric with a given type, name and tags.
|
||||
* If two metrics have the same type and name but different tags(including key and value), they have
|
||||
* a different MetricId. And in this way, {@link MetricRegistry} can register two metrics with same
|
||||
* name but different tags.
|
||||
* MetricId represents a metric with a given type, name and tags. If two metrics have the same type
|
||||
* and name but different tags(including key and value), they have a different MetricId. And in this
|
||||
* way, {@link MetricRegistry} can register two metrics with same name but different tags.
|
||||
*/
|
||||
public class MetricId {
|
||||
|
||||
|
@ -31,9 +30,9 @@ public class MetricId {
|
|||
return false;
|
||||
}
|
||||
MetricId metricId = (MetricId) o;
|
||||
return type == metricId.type &&
|
||||
Objects.equals(name, metricId.name) &&
|
||||
Objects.equals(tags, metricId.tags);
|
||||
return type == metricId.type
|
||||
&& Objects.equals(name, metricId.name)
|
||||
&& Objects.equals(tags, metricId.tags);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -9,9 +9,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* MetricRegistry is a registry for metrics to be registered and updates metrics.
|
||||
*/
|
||||
/** MetricRegistry is a registry for metrics to be registered and updates metrics. */
|
||||
public class MetricRegistry {
|
||||
|
||||
public static final MetricRegistry DEFAULT_REGISTRY = new MetricRegistry();
|
||||
|
@ -32,10 +30,15 @@ public class MetricRegistry {
|
|||
synchronized (this) {
|
||||
if (!isRunning) {
|
||||
this.metricConfig = metricConfig;
|
||||
scheduledExecutorService = new ScheduledThreadPoolExecutor(metricConfig.threadPoolSize(),
|
||||
scheduledExecutorService =
|
||||
new ScheduledThreadPoolExecutor(
|
||||
metricConfig.threadPoolSize(),
|
||||
new ThreadFactoryBuilder().setNameFormat("metric-registry-%d").build());
|
||||
scheduledExecutorService.scheduleAtFixedRate(this::update, metricConfig.timeIntervalMs(),
|
||||
metricConfig.timeIntervalMs(), TimeUnit.MILLISECONDS);
|
||||
scheduledExecutorService.scheduleAtFixedRate(
|
||||
this::update,
|
||||
metricConfig.timeIntervalMs(),
|
||||
metricConfig.timeIntervalMs(),
|
||||
TimeUnit.MILLISECONDS);
|
||||
isRunning = true;
|
||||
LOG.info("Finished startup metric registry, metricConfig is {}.", metricConfig);
|
||||
}
|
||||
|
@ -47,15 +50,18 @@ public class MetricRegistry {
|
|||
if (isRunning && scheduledExecutorService != null) {
|
||||
try {
|
||||
scheduledExecutorService.shutdownNow();
|
||||
if (!scheduledExecutorService.awaitTermination(metricConfig.shutdownWaitTimeMs(),
|
||||
TimeUnit.MILLISECONDS)) {
|
||||
LOG.warn("Metric registry did not shut down in {}ms time, so try to shut down again.",
|
||||
if (!scheduledExecutorService.awaitTermination(
|
||||
metricConfig.shutdownWaitTimeMs(), TimeUnit.MILLISECONDS)) {
|
||||
LOG.warn(
|
||||
"Metric registry did not shut down in {}ms time, so try to shut down again.",
|
||||
metricConfig.shutdownWaitTimeMs());
|
||||
scheduledExecutorService.shutdownNow();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
LOG.warn("Interrupted when shutting down metric registry, so try to shut down again.",
|
||||
e.getMessage(), e);
|
||||
LOG.warn(
|
||||
"Interrupted when shutting down metric registry, so try to shut down again.",
|
||||
e.getMessage(),
|
||||
e);
|
||||
scheduledExecutorService.shutdownNow();
|
||||
}
|
||||
if (scheduledExecutorService.isShutdown()) {
|
||||
|
@ -106,7 +112,8 @@ public class MetricRegistry {
|
|||
}
|
||||
|
||||
private void update() {
|
||||
registeredMetrics.forEach((id, metric) -> {
|
||||
registeredMetrics.forEach(
|
||||
(id, metric) -> {
|
||||
metric.record();
|
||||
});
|
||||
}
|
||||
|
@ -131,5 +138,4 @@ public class MetricRegistry {
|
|||
private MetricId genMetricIdByMetric(Metric metric) {
|
||||
return new MetricId(getMetricType(metric), metric.name, metric.tags);
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue