Skip to content

Commit

Permalink
Actually register the requested settings
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <widdis@gmail.com>
  • Loading branch information
dbwiddis committed Sep 15, 2022
1 parent 86769fc commit 872209d
Showing 1 changed file with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

package org.opensearch.extensions.settings;

import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.SettingsModule;
import org.opensearch.extensions.DiscoveryExtension;
import org.opensearch.extensions.ExtensionStringResponse;
import org.opensearch.transport.TransportResponse;
import org.opensearch.transport.TransportService;

import java.util.Map;
import java.util.ArrayList;
import java.util.List;

/**
* Handles requests to register extension settings.
Expand All @@ -24,24 +24,14 @@
public class SettingsRequestHandler {

private final SettingsModule settingsModule;
private final Map<String, DiscoveryExtension> extensionIdMap;
private final TransportService transportService;

/**
* Instantiates a new Settings Request Handler using the Node's SettingsModule.
*
* @param settingsModule The Node's {@link SettingsModule}.
* @param extensionIdMap A map of extension uniqueId to DiscoveryExtension
* @param transportService The Node's transportService
*/
public SettingsRequestHandler(
SettingsModule settingsModule,
Map<String, DiscoveryExtension> extensionIdMap,
TransportService transportService
) {
public SettingsRequestHandler(SettingsModule settingsModule) {
this.settingsModule = settingsModule;
this.extensionIdMap = extensionIdMap;
this.transportService = transportService;
}

/**
Expand All @@ -52,10 +42,15 @@ public SettingsRequestHandler(
* @throws Exception if the request is not handled properly.
*/
public TransportResponse handleRegisterSettingsRequest(RegisterSettingsRequest settingsRequest) throws Exception {
DiscoveryExtension discoveryExtension = extensionIdMap.get(settingsRequest.getUniqueId());
settingsModule.registerDynamicSetting(null);
// TODO: we have settingsRequest.getUniqueId() available.
// How do we prevent key collisions in settings registration?
List<String> registeredSettings = new ArrayList<>();
for (Setting<?> setting : settingsRequest.getSettings()) {
settingsModule.registerDynamicSetting(setting);
registeredSettings.add(setting.getKey());
}
return new ExtensionStringResponse(
"Registered extension " + settingsRequest.getUniqueId() + " to handle settings " + settingsRequest.getSettings()
"Registered settings from extension " + settingsRequest.getUniqueId() + ": " + String.join(", ", registeredSettings)
);
}
}

0 comments on commit 872209d

Please sign in to comment.