mirror of
https://github.com/wassname/ray.git
synced 2026-06-27 21:38:18 +08:00
[Java Worker]Add a resource checker for java worker creation (#10948)
Co-authored-by: Kai Yang <kfstorm@outlook.com>
This commit is contained in:
@@ -16,9 +16,17 @@ public abstract class BaseTaskOptions {
|
||||
|
||||
public BaseTaskOptions(Map<String, Double> resources) {
|
||||
for (Map.Entry<String, Double> entry : resources.entrySet()) {
|
||||
if (entry.getValue().compareTo(0.0) <= 0) {
|
||||
throw new IllegalArgumentException(String.format("Resource capacity should be " +
|
||||
"positive, but got resource %s = %f.", entry.getKey(), entry.getValue()));
|
||||
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()));
|
||||
}
|
||||
// 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 "
|
||||
+ "an integer if it is greater than 1.0. Specified resource: %s = %s.",
|
||||
entry.getKey(), entry.getValue()));
|
||||
}
|
||||
}
|
||||
this.resources = resources;
|
||||
|
||||
Reference in New Issue
Block a user