Search in sources :

Example 1 with AbstractScopedSettings

use of org.opensearch.common.settings.AbstractScopedSettings in project OpenSearch by opensearch-project.

the class ProxyConnectionStrategyTests method testModeSettingsCannotBeUsedWhenInDifferentMode.

public void testModeSettingsCannotBeUsedWhenInDifferentMode() {
    List<Tuple<Setting.AffixSetting<?>, String>> restrictedSettings = Arrays.asList(new Tuple<>(ProxyConnectionStrategy.PROXY_ADDRESS, "192.168.0.1:8080"), new Tuple<>(ProxyConnectionStrategy.REMOTE_SOCKET_CONNECTIONS, "3"));
    RemoteConnectionStrategy.ConnectionStrategy sniff = RemoteConnectionStrategy.ConnectionStrategy.SNIFF;
    String clusterName = "cluster_name";
    Settings settings = Settings.builder().put(RemoteConnectionStrategy.REMOTE_CONNECTION_MODE.getConcreteSettingForNamespace(clusterName).getKey(), sniff.name()).build();
    Set<Setting<?>> clusterSettings = new HashSet<>();
    clusterSettings.add(RemoteConnectionStrategy.REMOTE_CONNECTION_MODE);
    clusterSettings.addAll(restrictedSettings.stream().map(Tuple::v1).collect(Collectors.toList()));
    AbstractScopedSettings service = new ClusterSettings(Settings.EMPTY, clusterSettings);
    // Should validate successfully
    service.validate(settings, true);
    for (Tuple<Setting.AffixSetting<?>, String> restrictedSetting : restrictedSettings) {
        Setting<?> concreteSetting = restrictedSetting.v1().getConcreteSettingForNamespace(clusterName);
        Settings invalid = Settings.builder().put(settings).put(concreteSetting.getKey(), restrictedSetting.v2()).build();
        IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> service.validate(invalid, true));
        String expected = "Setting \"" + concreteSetting.getKey() + "\" cannot be used with the configured " + "\"cluster.remote.cluster_name.mode\" [required=PROXY, configured=SNIFF]";
        assertEquals(expected, iae.getMessage());
    }
}
Also used : ClusterSettings(org.opensearch.common.settings.ClusterSettings) Setting(org.opensearch.common.settings.Setting) AbstractScopedSettings(org.opensearch.common.settings.AbstractScopedSettings) Tuple(org.opensearch.common.collect.Tuple) AbstractScopedSettings(org.opensearch.common.settings.AbstractScopedSettings) Settings(org.opensearch.common.settings.Settings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) HashSet(java.util.HashSet)

Example 2 with AbstractScopedSettings

use of org.opensearch.common.settings.AbstractScopedSettings in project OpenSearch by opensearch-project.

the class SniffConnectionStrategyTests method testModeSettingsCannotBeUsedWhenInDifferentMode.

public void testModeSettingsCannotBeUsedWhenInDifferentMode() {
    List<Tuple<Setting.AffixSetting<?>, String>> restrictedSettings = Arrays.asList(new Tuple<>(SniffConnectionStrategy.REMOTE_CLUSTER_SEEDS, "192.168.0.1:8080"), new Tuple<>(SniffConnectionStrategy.REMOTE_NODE_CONNECTIONS, "2"));
    RemoteConnectionStrategy.ConnectionStrategy proxy = RemoteConnectionStrategy.ConnectionStrategy.PROXY;
    String clusterName = "cluster_name";
    Settings settings = Settings.builder().put(RemoteConnectionStrategy.REMOTE_CONNECTION_MODE.getConcreteSettingForNamespace(clusterName).getKey(), proxy.name()).build();
    Set<Setting<?>> clusterSettings = new HashSet<>();
    clusterSettings.add(RemoteConnectionStrategy.REMOTE_CONNECTION_MODE);
    clusterSettings.addAll(restrictedSettings.stream().map(Tuple::v1).collect(Collectors.toList()));
    AbstractScopedSettings service = new ClusterSettings(Settings.EMPTY, clusterSettings);
    // Should validate successfully
    service.validate(settings, true);
    for (Tuple<Setting.AffixSetting<?>, String> restrictedSetting : restrictedSettings) {
        Setting<?> concreteSetting = restrictedSetting.v1().getConcreteSettingForNamespace(clusterName);
        Settings invalid = Settings.builder().put(settings).put(concreteSetting.getKey(), restrictedSetting.v2()).build();
        IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> service.validate(invalid, true));
        String expected = "Setting \"" + concreteSetting.getKey() + "\" cannot be used with the configured " + "\"cluster.remote.cluster_name.mode\" [required=SNIFF, configured=PROXY]";
        assertEquals(expected, iae.getMessage());
    }
}
Also used : ClusterSettings(org.opensearch.common.settings.ClusterSettings) Setting(org.opensearch.common.settings.Setting) AbstractScopedSettings(org.opensearch.common.settings.AbstractScopedSettings) Tuple(org.opensearch.common.collect.Tuple) AbstractScopedSettings(org.opensearch.common.settings.AbstractScopedSettings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Settings(org.opensearch.common.settings.Settings) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)2 Tuple (org.opensearch.common.collect.Tuple)2 AbstractScopedSettings (org.opensearch.common.settings.AbstractScopedSettings)2 ClusterSettings (org.opensearch.common.settings.ClusterSettings)2 Setting (org.opensearch.common.settings.Setting)2 Settings (org.opensearch.common.settings.Settings)2