Skip to content

Commit

Permalink
Merge branch 'si/reset-transforms' into si/reset-features-api
Browse files Browse the repository at this point in the history
  • Loading branch information
gwbrown committed Mar 2, 2021
2 parents 6544c25 + 5ea27d6 commit a61cf38
Showing 1 changed file with 32 additions and 0 deletions.
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 @@ -377,6 +380,35 @@ public Collection<SystemIndexDescriptor> getSystemIndexDescriptors(Settings sett
return List.of(AUDIT_INDEX_PATTERN);
}

@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

0 comments on commit a61cf38

Please sign in to comment.