Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix the missing cluster_spec due to the null when getting clusterSpec… #663

Merged
merged 1 commit into from
Apr 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ public String getClusterSpec(String taskId) throws IOException {
if (amRuntimeAdapter.canStartTask(distributedMode, taskId)) {
return amRuntimeAdapter.constructClusterSpec(taskId);
}
return null;
return StringUtils.EMPTY;
}

@Override
Expand Down
8 changes: 7 additions & 1 deletion tony-core/src/main/java/com/linkedin/tony/TaskExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,13 @@ private String registerAndGetClusterSpec() throws IOException {
throw new IOException("Errors on registering to AM, maybe due to the network failure.");
}

return Utils.pollForeverTillNonNull(() -> proxy.getClusterSpec(taskId), DEFAULT_REQUEST_POLL_INTERVAL);
return Utils.pollTillConditionReached(
() -> proxy.getClusterSpec(taskId),
x -> StringUtils.isNotEmpty(x),
() -> null,
DEFAULT_REQUEST_POLL_INTERVAL,
0
);
}

public void callbackInfoToAM(String taskId, String callbackInfo) throws IOException {
Expand Down
10 changes: 3 additions & 7 deletions tony-core/src/main/java/com/linkedin/tony/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ public static <T> T pollTillNonNull(Callable<T> func, int interval, int timeout)
return pollTillConditionReached(func, Objects::nonNull, () -> null, interval, timeout);
}

public static <T> T pollForeverTillNonNull(Callable<T> func, int interval) {
return pollTillNonNull(func, interval, 0);
}

public static <T> T pollTillConditionReached(Callable<T> callFunc, Function<T, Boolean> conditionFunc,
CallableWithoutException<T> defaultReturnedFunc, int interval, int timeout) {
Preconditions.checkArgument(interval >= 0, "Interval must be non-negative.");
Expand All @@ -133,16 +129,16 @@ public static <T> T pollTillConditionReached(Callable<T> callFunc, Function<T, B
while (timeout == 0 || remainingTime >= 0) {
ret = callFunc.call();
if (conditionFunc.apply(ret)) {
LOG.info("pollTillNonNull function finished within " + timeout + " seconds");
LOG.info("pollTillConditionReached function finished within " + timeout + " seconds");
return ret;
}
Thread.sleep(interval * 1000);
remainingTime -= interval;
}
} catch (Exception e) {
LOG.error("pollTillNonNull function threw exception", e);
LOG.error("pollTillConditionReached function threw exception", e);
}
LOG.warn("Function didn't return non-null within " + timeout + " seconds.");
LOG.warn("Function didn't satisfy applied condition within " + timeout + " seconds.");
return defaultReturnedFunc.call();
}

Expand Down