blob: 96a776a65b8da2b938aab9401207e4f24565ee13 (
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
|
// 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.NodeInfo;
import com.yahoo.vespa.clustercontroller.core.SetClusterStateRequest;
import com.yahoo.vespa.clustercontroller.core.Timer;
/**
* Waiter class for set cluster state RPC commands.
*/
public class RPCSetClusterStateWaiter implements RequestWaiter {
SetClusterStateRequest request;
Timer timer;
Communicator.Waiter<SetClusterStateRequest> waiter;
public RPCSetClusterStateWaiter(Communicator.Waiter<SetClusterStateRequest> waiter, Timer timer) {
this.timer = timer;
this.waiter = waiter;
}
public void setRequest(RPCSetClusterStateRequest request) {
this.request = request;
}
public SetClusterStateRequest.Reply getReply(Request req) {
NodeInfo info = request.getNodeInfo();
if (req.methodName().equals(RPCCommunicator.SET_DISTRIBUTION_STATES_RPC_METHOD_NAME)
|| req.methodName().equals(RPCCommunicator.LEGACY_SET_SYSTEM_STATE2_RPC_METHOD_NAME)) {
if (req.isError() && req.errorCode() == ErrorCode.NO_SUCH_METHOD) {
if (info.notifyNoSuchMethodError(req.methodName(), timer)) {
return new SetClusterStateRequest.Reply(Communicator.TRANSIENT_ERROR, "Trying lower version");
}
}
if (req.isError()) {
return new SetClusterStateRequest.Reply(req.errorCode(), req.errorMessage());
} else if (!req.checkReturnTypes("")) {
return new SetClusterStateRequest.Reply(ErrorCode.BAD_REPLY, "Got RPC response with invalid return types from " + info);
}
} else {
return new SetClusterStateRequest.Reply(ErrorCode.BAD_REPLY, "Unknown method " + req.methodName());
}
return new SetClusterStateRequest.Reply();
}
@Override
public void handleRequestDone(Request request) {
SetClusterStateRequest.Reply reply = getReply(request);
this.request.setReply(reply);
waiter.done(this.request);
}
}
|