Skip to content

Commit

Permalink
Adding a transport action to get cluster formation info (#87306)
Browse files Browse the repository at this point in the history
This commit exposes ClusterFormationFailureHelper.ClusterFormationState in a transport action (ClusterFormationInfoAction), with the intention that it be used as part of the master stability health check.
  • Loading branch information
masseyke committed Jun 20, 2022
1 parent 0c074b3 commit 5061f90
Show file tree
Hide file tree
Showing 12 changed files with 771 additions and 43 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/87306.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 87306
summary: Adding a transport action to get cluster formation info
area: Health
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.elasticsearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsAction;
import org.elasticsearch.action.admin.cluster.configuration.TransportAddVotingConfigExclusionsAction;
import org.elasticsearch.action.admin.cluster.configuration.TransportClearVotingConfigExclusionsAction;
import org.elasticsearch.action.admin.cluster.coordination.ClusterFormationInfoAction;
import org.elasticsearch.action.admin.cluster.coordination.MasterHistoryAction;
import org.elasticsearch.action.admin.cluster.desirednodes.DeleteDesiredNodesAction;
import org.elasticsearch.action.admin.cluster.desirednodes.GetDesiredNodesAction;
Expand Down Expand Up @@ -555,6 +556,7 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg
actions.register(ClusterGetSettingsAction.INSTANCE, TransportClusterGetSettingsAction.class);
actions.register(ClusterRerouteAction.INSTANCE, TransportClusterRerouteAction.class);
actions.register(ClusterSearchShardsAction.INSTANCE, TransportClusterSearchShardsAction.class);
actions.register(ClusterFormationInfoAction.INSTANCE, ClusterFormationInfoAction.TransportAction.class);
actions.register(PendingClusterTasksAction.INSTANCE, TransportPendingClusterTasksAction.class);
actions.register(PutRepositoryAction.INSTANCE, TransportPutRepositoryAction.class);
actions.register(GetRepositoriesAction.INSTANCE, TransportGetRepositoriesAction.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.action.admin.cluster.coordination;

import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.HandledTransportAction;
import org.elasticsearch.cluster.coordination.ClusterFormationFailureHelper;
import org.elasticsearch.cluster.coordination.Coordinator;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.transport.TransportService;

import java.io.IOException;
import java.util.Objects;

/**
* This class is used to fetch the ClusterFormationState from another node. The ClusterFormationState provides information about why that
* node thinks that cluster formation has failed.
*/
public class ClusterFormationInfoAction extends ActionType<ClusterFormationInfoAction.Response> {

public static final ClusterFormationInfoAction INSTANCE = new ClusterFormationInfoAction();
public static final String NAME = "cluster:internal/formation/info";

private ClusterFormationInfoAction() {
super(NAME, ClusterFormationInfoAction.Response::new);
}

public static class Request extends ActionRequest {

public Request() {}

@Override
public ActionRequestValidationException validate() {
return null;
}

public Request(StreamInput in) throws IOException {
super(in);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
}

@Override
public boolean equals(Object o) {
// There are no parameters, so all instances of this class are equal
if (this == o) {
return true;
}
return o != null && getClass() == o.getClass();
}

@Override
public int hashCode() {
// There are no parameters, so all instances of this class are equal
return 1;
}

}

public static class Response extends ActionResponse {

private final ClusterFormationFailureHelper.ClusterFormationState clusterFormationState;

public Response(StreamInput in) throws IOException {
super(in);
clusterFormationState = new ClusterFormationFailureHelper.ClusterFormationState(in);
}

public Response(ClusterFormationFailureHelper.ClusterFormationState clusterFormationState) {
this.clusterFormationState = clusterFormationState;
}

public ClusterFormationFailureHelper.ClusterFormationState getClusterFormationState() {
return clusterFormationState;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
clusterFormationState.writeTo(out);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ClusterFormationInfoAction.Response response = (ClusterFormationInfoAction.Response) o;
return clusterFormationState.equals(response.clusterFormationState);
}

@Override
public int hashCode() {
return Objects.hash(clusterFormationState);
}
}

/**
* This transport action fetches the ClusterFormationState from a remote node.
*/
public static class TransportAction extends HandledTransportAction<
ClusterFormationInfoAction.Request,
ClusterFormationInfoAction.Response> {
private final Coordinator coordinator;

@Inject
public TransportAction(TransportService transportService, ActionFilters actionFilters, Coordinator coordinator) {
super(ClusterFormationInfoAction.NAME, transportService, actionFilters, ClusterFormationInfoAction.Request::new);
this.coordinator = coordinator;
}

@Override
protected void doExecute(
Task task,
ClusterFormationInfoAction.Request request,
ActionListener<ClusterFormationInfoAction.Response> listener
) {
listener.onResponse(new ClusterFormationInfoAction.Response(coordinator.getClusterFormationState()));
}
}

}

0 comments on commit 5061f90

Please sign in to comment.