Skip to content

Commit

Permalink
s/Settings/CustomSettings/g
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis committed Sep 19, 2022
1 parent 806c04d commit a019a9d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
import org.opensearch.extensions.ExtensionsSettings.Extension;
import org.opensearch.extensions.rest.RegisterRestActionsRequest;
import org.opensearch.extensions.rest.RestActionsRequestHandler;
import org.opensearch.extensions.settings.RegisterSettingsRequest;
import org.opensearch.extensions.settings.SettingsRequestHandler;
import org.opensearch.extensions.settings.CustomSettingsRequestHandler;
import org.opensearch.extensions.settings.RegisterCustomSettingsRequest;
import org.opensearch.index.IndexModule;
import org.opensearch.index.IndexService;
import org.opensearch.index.IndicesModuleRequest;
Expand Down Expand Up @@ -73,8 +73,8 @@ public class ExtensionsOrchestrator implements ReportingService<PluginsAndModule
public static final String REQUEST_EXTENSION_CLUSTER_STATE = "internal:discovery/clusterstate";
public static final String REQUEST_EXTENSION_LOCAL_NODE = "internal:discovery/localnode";
public static final String REQUEST_EXTENSION_CLUSTER_SETTINGS = "internal:discovery/clustersettings";
public static final String REQUEST_EXTENSION_REGISTER_CUSTOM_SETTINGS = "internal:discovery/registercustomsettings";
public static final String REQUEST_EXTENSION_REGISTER_REST_ACTIONS = "internal:discovery/registerrestactions";
public static final String REQUEST_EXTENSION_REGISTER_SETTINGS = "internal:discovery/registersettings";
public static final String REQUEST_EXTENSION_REGISTER_TRANSPORT_ACTIONS = "internal:discovery/registertransportactions";
public static final String REQUEST_OPENSEARCH_NAMED_WRITEABLE_REGISTRY = "internal:discovery/namedwriteableregistry";
public static final String REQUEST_OPENSEARCH_PARSE_NAMED_WRITEABLE = "internal:discovery/parsenamedwriteable";
Expand Down Expand Up @@ -115,7 +115,7 @@ public static enum OpenSearchRequestType {
// A map of extension uniqueId to full extension details used for node transport here and in the RestActionsRequestHandler
Map<String, DiscoveryExtension> extensionIdMap;
RestActionsRequestHandler restActionsRequestHandler;
SettingsRequestHandler settingsRequestHandler;
CustomSettingsRequestHandler customSettingsRequestHandler;
TransportService transportService;
ClusterService clusterService;
ExtensionNamedWriteableRegistry namedWriteableRegistry;
Expand Down Expand Up @@ -161,7 +161,7 @@ public void initializeServicesAndRestHandler(
ClusterService clusterService
) {
this.restActionsRequestHandler = new RestActionsRequestHandler(restController, extensionIdMap, transportService);
this.settingsRequestHandler = new SettingsRequestHandler(settingsModule);
this.customSettingsRequestHandler = new CustomSettingsRequestHandler(settingsModule);
this.transportService = transportService;
this.clusterService = clusterService;
registerRequestHandler();
Expand All @@ -177,12 +177,12 @@ private void registerRequestHandler() {
((request, channel, task) -> channel.sendResponse(restActionsRequestHandler.handleRegisterRestActionsRequest(request)))
);
transportService.registerRequestHandler(
REQUEST_EXTENSION_REGISTER_SETTINGS,
REQUEST_EXTENSION_REGISTER_CUSTOM_SETTINGS,
ThreadPool.Names.GENERIC,
false,
false,
RegisterSettingsRequest::new,
((request, channel, task) -> channel.sendResponse(settingsRequestHandler.handleRegisterSettingsRequest(request)))
RegisterCustomSettingsRequest::new,
((request, channel, task) -> channel.sendResponse(customSettingsRequestHandler.handleRegisterCustomSettingsRequest(request)))
);
transportService.registerRequestHandler(
REQUEST_EXTENSION_CLUSTER_STATE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @opensearch.internal
*/
public class SettingsRequestHandler {
public class CustomSettingsRequestHandler {

private final SettingsModule settingsModule;

Expand All @@ -30,28 +30,28 @@ public class SettingsRequestHandler {
*
* @param settingsModule The Node's {@link SettingsModule}.
*/
public SettingsRequestHandler(SettingsModule settingsModule) {
public CustomSettingsRequestHandler(SettingsModule settingsModule) {
this.settingsModule = settingsModule;
}

/**
* Handles a {@link RegisterSettingsRequest}.
* Handles a {@link RegisterCustomSettingsRequest}.
*
* @param settingsRequest The request to handle.
* @param customSettingsRequest The request to handle.
* @return A {@link ExtensionStringResponse} indicating success.
* @throws Exception if the request is not handled properly.
*/
public TransportResponse handleRegisterSettingsRequest(RegisterSettingsRequest settingsRequest) throws Exception {
public TransportResponse handleRegisterCustomSettingsRequest(RegisterCustomSettingsRequest customSettingsRequest) throws Exception {
// TODO: How do we prevent key collisions in settings registration?
// we have settingsRequest.getUniqueId() available or could enforce reverse DNS naming
// See https:/opensearch-project/opensearch-sdk-java/issues/142
List<String> registeredSettings = new ArrayList<>();
for (Setting<?> setting : settingsRequest.getSettings()) {
List<String> registeredCustomSettings = new ArrayList<>();
for (Setting<?> setting : customSettingsRequest.getSettings()) {
settingsModule.registerDynamicSetting(setting);
registeredSettings.add(setting.getKey());
registeredCustomSettings.add(setting.getKey());
}
return new ExtensionStringResponse(
"Registered settings from extension " + settingsRequest.getUniqueId() + ": " + String.join(", ", registeredSettings)
"Registered settings from extension " + customSettingsRequest.getUniqueId() + ": " + String.join(", ", registeredCustomSettings)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@
*
* @opensearch.internal
*/
public class RegisterSettingsRequest extends TransportRequest {
public class RegisterCustomSettingsRequest extends TransportRequest {
private String uniqueId;
private List<Setting<?>> settings;

public RegisterSettingsRequest(String uniqueId, List<Setting<?>> settings) {
public RegisterCustomSettingsRequest(String uniqueId, List<Setting<?>> settings) {
this.uniqueId = uniqueId;
this.settings = new ArrayList<>(settings);
}

public RegisterSettingsRequest(StreamInput in) throws IOException {
public RegisterCustomSettingsRequest(StreamInput in) throws IOException {
super(in);
this.uniqueId = in.readString();
int size = in.readVInt();
Expand Down Expand Up @@ -72,7 +72,7 @@ public String toString() {
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
RegisterSettingsRequest that = (RegisterSettingsRequest) obj;
RegisterCustomSettingsRequest that = (RegisterCustomSettingsRequest) obj;
return Objects.equals(uniqueId, that.uniqueId) && Objects.equals(settings, that.settings);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
import org.opensearch.env.Environment;
import org.opensearch.env.TestEnvironment;
import org.opensearch.extensions.rest.RegisterRestActionsRequest;
import org.opensearch.extensions.settings.RegisterSettingsRequest;
import org.opensearch.extensions.settings.RegisterCustomSettingsRequest;
import org.opensearch.index.IndexModule;
import org.opensearch.index.IndexSettings;
import org.opensearch.index.analysis.AnalysisRegistry;
Expand Down Expand Up @@ -392,8 +392,10 @@ public void testHandleRegisterSettingsRequest() throws Exception {
Setting.boolSetting("index.falseSetting", false, Property.IndexScope, Property.Dynamic),
Setting.simpleString("fooSetting", "foo", Property.NodeScope, Property.Final)
);
RegisterSettingsRequest registerSettingsRequest = new RegisterSettingsRequest(uniqueIdStr, settingsList);
TransportResponse response = extensionsOrchestrator.settingsRequestHandler.handleRegisterSettingsRequest(registerSettingsRequest);
RegisterCustomSettingsRequest registerCustomSettingsRequest = new RegisterCustomSettingsRequest(uniqueIdStr, settingsList);
TransportResponse response = extensionsOrchestrator.customSettingsRequestHandler.handleRegisterCustomSettingsRequest(
registerCustomSettingsRequest
);
assertEquals(ExtensionStringResponse.class, response.getClass());
assertTrue(((ExtensionStringResponse) response).getResponse().contains(uniqueIdStr));
assertTrue(((ExtensionStringResponse) response).getResponse().contains("falseSetting"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,32 @@
import org.opensearch.common.unit.TimeValue;
import org.opensearch.test.OpenSearchTestCase;

public class RegisterSettingsTests extends OpenSearchTestCase {
public class RegisterCustomSettingsTests extends OpenSearchTestCase {

public void testRegisterSettingsRequest() throws Exception {
public void testRegisterCustomSettingsRequest() throws Exception {
String uniqueIdStr = "uniqueid1";
List<Setting<?>> expected = List.of(
Setting.boolSetting("falseSetting", false, Property.IndexScope, Property.NodeScope),
Setting.simpleString("fooSetting", "foo", Property.Dynamic),
Setting.timeSetting("timeSetting", new TimeValue(5, TimeUnit.MILLISECONDS), Property.Dynamic),
Setting.byteSizeSetting("byteSizeSetting", new ByteSizeValue(10, ByteSizeUnit.KB), Property.Dynamic)
);
RegisterSettingsRequest registerSettingsRequest = new RegisterSettingsRequest(uniqueIdStr, expected);
RegisterCustomSettingsRequest registerCustomSettingsRequest = new RegisterCustomSettingsRequest(uniqueIdStr, expected);

assertEquals(uniqueIdStr, registerSettingsRequest.getUniqueId());
List<Setting<?>> settings = registerSettingsRequest.getSettings();
assertEquals(uniqueIdStr, registerCustomSettingsRequest.getUniqueId());
List<Setting<?>> settings = registerCustomSettingsRequest.getSettings();
assertEquals(expected.size(), settings.size());
assertTrue(settings.containsAll(expected));
assertTrue(expected.containsAll(settings));

try (BytesStreamOutput out = new BytesStreamOutput()) {
registerSettingsRequest.writeTo(out);
registerCustomSettingsRequest.writeTo(out);
out.flush();
try (BytesStreamInput in = new BytesStreamInput(BytesReference.toBytes(out.bytes()))) {
registerSettingsRequest = new RegisterSettingsRequest(in);
registerCustomSettingsRequest = new RegisterCustomSettingsRequest(in);

assertEquals(uniqueIdStr, registerSettingsRequest.getUniqueId());
settings = registerSettingsRequest.getSettings();
assertEquals(uniqueIdStr, registerCustomSettingsRequest.getUniqueId());
settings = registerCustomSettingsRequest.getSettings();
assertEquals(expected.size(), settings.size());
assertTrue(settings.containsAll(expected));
assertTrue(expected.containsAll(settings));
Expand Down

0 comments on commit a019a9d

Please sign in to comment.