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

Enable Setting Master Node Timeout in Watcher Start/Stop Requests (#70425) #70434

Merged
merged 1 commit into from
Mar 16, 2021
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
9 changes: 7 additions & 2 deletions x-pack/docs/en/rest-api/watcher/start.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ information, see <<security-privileges>>.
//[[watcher-api-start-path-params]]
//==== {api-path-parms-title}

//[[watcher-api-start-query-params]]
//==== {api-query-parms-title}
[[watcher-api-start-query-params]]
==== {api-query-parms-title}

`master_timeout`::
(Optional, <<time-units, time units>>) Specifies the period of time to wait for
a connection to the master node. If no response is received before the timeout
expires, the request fails and returns an error. Defaults to `30s`.

//[[watcher-api-start-request-body]]
//==== {api-request-body-title}
Expand Down
9 changes: 7 additions & 2 deletions x-pack/docs/en/rest-api/watcher/stop.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ information, see <<security-privileges>>.
//[[watcher-api-stop-path-params]]
//==== {api-path-parms-title}

//[[watcher-api-stop-query-params]]
//==== {api-query-parms-title}
[[watcher-api-stop-query-params]]
==== {api-query-parms-title}

`master_timeout`::
(Optional, <<time-units, time units>>) Specifies the period of time to wait for
a connection to the master node. If no response is received before the timeout
expires, the request fails and returns an error. Defaults to `30s`.

//[[watcher-api-stop-request-body]]
//==== {api-request-body-title}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ public String getName() {
}

@Override
public RestChannelConsumer doPrepareRequest(RestRequest request, WatcherClient client) {
return channel -> client.watcherService(new WatcherServiceRequest().stop(), new RestToXContentListener<>(channel));
public RestChannelConsumer doPrepareRequest(RestRequest restRequest, WatcherClient client) {
final WatcherServiceRequest request = new WatcherServiceRequest().stop();
request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout()));
return channel -> client.watcherService(request, new RestToXContentListener<>(channel));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,6 @@ public class TransportWatcherServiceAction extends AcknowledgedTransportMasterNo

private static final Logger logger = LogManager.getLogger(TransportWatcherServiceAction.class);

private static final AckedRequest ackedRequest = new AckedRequest() {
@Override
public TimeValue ackTimeout() {
return AcknowledgedRequest.DEFAULT_ACK_TIMEOUT;
}

@Override
public TimeValue masterNodeTimeout() {
return AcknowledgedRequest.DEFAULT_ACK_TIMEOUT;
}
};

@Inject
public TransportWatcherServiceAction(TransportService transportService, ClusterService clusterService,
ThreadPool threadPool, ActionFilters actionFilters,
Expand All @@ -58,20 +46,22 @@ public TransportWatcherServiceAction(TransportService transportService, ClusterS
@Override
protected void masterOperation(WatcherServiceRequest request, ClusterState state,
ActionListener<AcknowledgedResponse> listener) {
switch (request.getCommand()) {
case STOP:
setWatcherMetadataAndWait(true, listener);
break;
case START:
setWatcherMetadataAndWait(false, listener);
break;
}
}
final boolean manuallyStopped = request.getCommand() == WatcherServiceRequest.Command.STOP;
final String source = manuallyStopped ? "update_watcher_manually_stopped" : "update_watcher_manually_started";

private void setWatcherMetadataAndWait(boolean manuallyStopped, final ActionListener<AcknowledgedResponse> listener) {
String source = manuallyStopped ? "update_watcher_manually_stopped" : "update_watcher_manually_started";
// TODO: make WatcherServiceRequest a real AckedRequest so that we have both a configurable timeout and master node timeout like
// we do elsewhere
clusterService.submitStateUpdateTask(source, new AckedClusterStateUpdateTask(new AckedRequest() {
@Override
public TimeValue ackTimeout() {
return AcknowledgedRequest.DEFAULT_ACK_TIMEOUT;
}

clusterService.submitStateUpdateTask(source, new AckedClusterStateUpdateTask(ackedRequest, listener) {
@Override
public TimeValue masterNodeTimeout() {
return request.masterNodeTimeout();
}
}, listener) {
@Override
public ClusterState execute(ClusterState clusterState) {
XPackPlugin.checkReadyForXPackCustomMetadata(clusterState);
Expand Down