[Java Worker]Add a resource checker for java worker creation (#10948)

Co-authored-by: Kai Yang <kfstorm@outlook.com>
This commit is contained in:
bermaker
2020-09-22 22:00:28 +08:00
committed by GitHub
parent e3b4850224
commit 273015814d
2 changed files with 60 additions and 3 deletions
@@ -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;