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

Add Transform reset logic #2

Merged
Merged
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 @@ -10,11 +10,14 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.util.SetOnce;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.admin.cluster.snapshots.features.ResetFeatureStateResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodeRole;
import org.elasticsearch.cluster.node.DiscoveryNodes;
Expand Down Expand Up @@ -371,6 +374,35 @@ public Collection<SystemIndexDescriptor> getSystemIndexDescriptors(Settings sett
}
}

@Override
public void cleanUpFeature(
ClusterService clusterService,
Client client,
ActionListener<ResetFeatureStateResponse.ResetFeatureStateStatus> listener
) {
ActionListener<StopTransformAction.Response> afterStoppingTransforms = ActionListener.wrap(stopTransformsResponse -> {
if (stopTransformsResponse.isAcknowledged()
&& stopTransformsResponse.getTaskFailures().isEmpty()
&& stopTransformsResponse.getNodeFailures().isEmpty()) {

SystemIndexPlugin.super.cleanUpFeature(clusterService, client, listener);
} else {
String errMsg = "Failed to reset Transform: "
+ (stopTransformsResponse.isAcknowledged() ? "" : "not acknowledged ")
+ (stopTransformsResponse.getNodeFailures().isEmpty()
? ""
: "node failures: " + stopTransformsResponse.getNodeFailures() + " ")
+ (stopTransformsResponse.getTaskFailures().isEmpty()
? ""
: "task failures: " + stopTransformsResponse.getTaskFailures());
listener.onResponse(new ResetFeatureStateResponse.ResetFeatureStateStatus(this.getFeatureName(), errMsg));
}
}, listener::onFailure);

StopTransformAction.Request stopTransformsRequest = new StopTransformAction.Request(Metadata.ALL, true, true, null, true, false);
client.execute(StopTransformAction.INSTANCE, stopTransformsRequest, afterStoppingTransforms);
}

@Override
public String getFeatureName() {
return "transform";
Expand Down