Problem/Motivation
Currently, the Search API Server Task Manager assumes that it can add, update, and remove Indexes on its own (see \Drupal\search_api\Task\ServerTaskManager::getSupportedTypes()
). But, it may not be possible (or cost-effective) to grant Search API permission to do all of those things on a Server.
For example, suppose an organization wants to connect Search API to an Index on a Server that they are already using for something else. They don't want to risk a Drupal mis-configuration breaking their existing Indexes, so they only grant the Drupal team credentials to update the index, i.e.: not add or remove the index.
While the backend-specific code can simply choose not to send certain commands (see the merge request in [#3522107], specifically the code paths where self_manage_indexes
is disabled), the backend-specific code has no control over what Server Tasks that Search API queues up for that Server: if, for example, addIndex
or removeIndex
Server Tasks are added to that Server's queue, the index will be unusable until they complete successfully, which will never happen.
(note that [#3529273] has a patch to show the Server Tasks that are queued for a particular Search API Server)
Steps to reproduce
- Sign up for a trial of Elastic Cloud Serverless
- Create an Elasticsearch Index from
/app/elasticsearch/content/search_indices/new_index/api
, I called mine mparker17_test_index
(if you choose a different name, only use underscores in the index name). Note the Elasticsearch Endpoint (which looks like a URL) from the Index's Overview page.
- Create an access key from
/app/management/security/api_keys/create
, and note the key. Grant it the following permissions...
{
"role-a": {
"cluster": [ "all" ],
"indices": [
{ "names": [ "mparker17_test_index" ], "privileges": [ "all" ], "allow_restricted_indices": false }
],
"applications": [],
"run_as": [],
"metadata": {},
"transient_metadata": { "enabled": true }
}
}
- Set up a Drupal site with elasticsearch_connector-8.0.x, and apply the patch from
✨
Connect to an Elastic Cloud Hosted Deployment acting as a Search API Server by entering a Cloud ID and API key
Active
to elasticsearch_connector. Elasticsearch Connector 8.0.x will automatically install search_api. Optionally, apply the patch from
✨
Show which Server Tasks are pending on Server view page
Active
to search_api. Also install
key-8.x-1.20 →
.
- Set up a new Authentication key, whose value is the access key you created in step 3.
- Create a new Search API Server whose Backend is ElasticSearch, and whose ElasticSearch Connector is either Elastic Cloud Endpoint. Enter the Elasticsearch Endpoint from the Index you created in step 2, and select the Authentication key you set up in the previous step. Make sure that "Mange indexes on this server" is unchecked. Click "Save".
- Create a new Search API Index with the same machine name as the Index you created in step 2; and whose Server is the one you set up in the previous step.
- Go back to the Server's "View" page. Note that there is 1 pending server task (if you installed the patch from 3529273, it will tell you that it's a task of type
addIndex
).
- Try clicking "Execute tasks now". Note you get an error.
Proposed resolution
Allow Servers to say which kinds of Server Tasks they support.
Don't queue Server Tasks that aren't supported by the server.
Remaining tasks
- Write a patch
- Review and feedback
- RTBC and feedback
- Commit
- Release