Skip to content

Commit

Permalink
Guard the new behavior in a cluster feature
Browse files Browse the repository at this point in the history
  • Loading branch information
joegallo committed Oct 11, 2024
1 parent 04c029d commit f9fe6ef
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.Strings;
import org.elasticsearch.core.Tuple;
import org.elasticsearch.features.FeatureService;
import org.elasticsearch.ingest.geoip.IngestGeoIpMetadata;
import org.elasticsearch.ingest.geoip.direct.PutDatabaseConfigurationAction.Request;
import org.elasticsearch.injection.guice.Inject;
Expand All @@ -41,6 +42,8 @@
import java.util.Map;
import java.util.Optional;

import static org.elasticsearch.ingest.IngestGeoIpFeatures.PUT_DATABASE_CONFIGURATION_ACTION_IPINFO;

public class TransportPutDatabaseConfigurationAction extends TransportMasterNodeAction<Request, AcknowledgedResponse> {

private static final Logger logger = LogManager.getLogger(TransportPutDatabaseConfigurationAction.class);
Expand All @@ -58,6 +61,7 @@ public void taskSucceeded(UpdateDatabaseConfigurationTask task, Void unused) {
}
};

private final FeatureService featureService;
private final MasterServiceTaskQueue<UpdateDatabaseConfigurationTask> updateDatabaseConfigurationTaskQueue;

@Inject
Expand All @@ -66,7 +70,8 @@ public TransportPutDatabaseConfigurationAction(
ClusterService clusterService,
ThreadPool threadPool,
ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver
IndexNameExpressionResolver indexNameExpressionResolver,
FeatureService featureService
) {
super(
PutDatabaseConfigurationAction.NAME,
Expand All @@ -79,6 +84,7 @@ public TransportPutDatabaseConfigurationAction(
AcknowledgedResponse::readFrom,
EsExecutors.DIRECT_EXECUTOR_SERVICE
);
this.featureService = featureService;
this.updateDatabaseConfigurationTaskQueue = clusterService.createTaskQueue(
"update-geoip-database-configuration-state-update",
Priority.NORMAL,
Expand All @@ -89,6 +95,19 @@ public TransportPutDatabaseConfigurationAction(
@Override
protected void masterOperation(Task task, Request request, ClusterState state, ActionListener<AcknowledgedResponse> listener) {
final String id = request.getDatabase().id();

// if this is an ipinfo configuration, then make sure the whole cluster supports that feature
if (request.getDatabase().provider() instanceof DatabaseConfiguration.Ipinfo
&& featureService.clusterHasFeature(clusterService.state(), PUT_DATABASE_CONFIGURATION_ACTION_IPINFO) == false) {
listener.onFailure(
new IllegalArgumentException(
"Unable to use ipinfo database configurations in mixed-clusters with nodes that do not support feature "
+ PUT_DATABASE_CONFIGURATION_ACTION_IPINFO.id()
)
);
return;
}

updateDatabaseConfigurationTaskQueue.submitTask(
Strings.format("update-geoip-database-configuration-[%s]", id),
new UpdateDatabaseConfigurationTask(listener, request.getDatabase()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ public class IngestGeoIpFeatures implements FeatureSpecification {
"get_database_configuration_action.multi_node"
);

public static final NodeFeature PUT_DATABASE_CONFIGURATION_ACTION_IPINFO = new NodeFeature(
"put_database_configuration_action.ipinfo"
);

public Set<NodeFeature> getFeatures() {
return Set.of(GEOIP_DOWNLOADER_DATABASE_CONFIGURATION, GET_DATABASE_CONFIGURATION_ACTION_MULTI_NODE);
return Set.of(GEOIP_DOWNLOADER_DATABASE_CONFIGURATION, GET_DATABASE_CONFIGURATION_ACTION_MULTI_NODE, PUT_DATABASE_CONFIGURATION_ACTION_IPINFO);
}
}

0 comments on commit f9fe6ef

Please sign in to comment.