blob: 06046e7550d954cab0f753f0cd1eca06e81df77c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.core.rpc;
import com.yahoo.jrt.ErrorCode;
import com.yahoo.jrt.Request;
import com.yahoo.jrt.RequestWaiter;
import com.yahoo.vespa.clustercontroller.core.Communicator;
import com.yahoo.vespa.clustercontroller.core.GetNodeStateRequest;
import com.yahoo.vespa.clustercontroller.core.Timer;
/**
* Handles the reply to a get node state request to a node.
*/
public class RPCGetNodeStateWaiter implements RequestWaiter {
private final RPCGetNodeStateRequest request;
private final Communicator.Waiter<GetNodeStateRequest> waiter;
private final Timer timer;
public RPCGetNodeStateWaiter(RPCGetNodeStateRequest request,
Communicator.Waiter<GetNodeStateRequest> waiter, Timer timer) {
this.request = request;
this.waiter = waiter;
this.timer = timer;
}
private GetNodeStateRequest.Reply convertToReply(Request req) {
if (req.errorCode() == ErrorCode.NO_SUCH_METHOD) {
// If we get no such method error, and we downgrade version, we must retry. May be ok that it doesn't exist
if (request.getNodeInfo().notifyNoSuchMethodError(req.methodName(), timer)) {
return new GetNodeStateRequest.Reply(Communicator.TRANSIENT_ERROR, "Downgrading version");
}
}
if (req.isError()) {
return new GetNodeStateRequest.Reply(req.errorCode(), req.errorMessage());
}
if (req.methodName().equals("getnodestate3")) {
String stateStr = "";
String hostInfo = "";
if (req.returnValues().satisfies("s*")) {
stateStr = req.returnValues().get(0).asString();
}
if (req.returnValues().satisfies("ss*")) {
hostInfo = req.returnValues().get(1).asString();
}
return new GetNodeStateRequest.Reply(stateStr, hostInfo);
} else {
return new GetNodeStateRequest.Reply(ErrorCode.BAD_REPLY, "Unknown method name " + req.methodName());
}
}
@Override
public void handleRequestDone(Request req) {
request.setReply(convertToReply(req));
waiter.done(request);
}
}
|