Search in sources :

Example 1 with SettingValidator

use of org.neo4j.graphdb.config.SettingValidator in project neo4j by neo4j.

the class ServerConfigurationValidator method validate.

/**
     * Verifies that at least one http connector is specified and enabled.
     */
@Override
@Nonnull
public Map<String, String> validate(@Nonnull Collection<SettingValidator> settingValidators, @Nonnull Map<String, String> rawConfig, @Nonnull Log log, boolean parsingFile) throws InvalidSettingException {
    Pattern pattern = Pattern.compile(Pattern.quote("dbms.connector.") + "([^\\.]+)\\.(.+)");
    List<Connector> connectors = rawConfig.keySet().stream().map(pattern::matcher).filter(Matcher::matches).map(match -> match.group(1)).distinct().map(Connector::new).collect(Collectors.toList());
    Map<String, String> validSettings = new HashMap<>(rawConfig);
    // Add missing type info -- validation has succeeded so we can do this with confidence
    connectors.stream().filter(connector -> connector.type.apply(rawConfig::get) == null).forEach(connector -> {
        if ("http".equalsIgnoreCase(connector.group.groupKey) || "https".equalsIgnoreCase(connector.group.groupKey)) {
            validSettings.put(connector.type.name(), HTTP.name());
        } else {
            validSettings.put(connector.type.name(), BOLT.name());
        }
    });
    if (connectors.stream().filter(connector -> connector.type.apply(validSettings::get).equals(HTTP)).noneMatch(connector -> connector.enabled.apply(validSettings::get))) {
        throw new InvalidSettingException(String.format("Missing mandatory enabled connector of type '%s'", HTTP));
    }
    return validSettings;
}
Also used : HTTP(org.neo4j.kernel.configuration.Connector.ConnectorType.HTTP) Log(org.neo4j.logging.Log) Collection(java.util.Collection) SettingValidator(org.neo4j.graphdb.config.SettingValidator) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) List(java.util.List) Matcher(java.util.regex.Matcher) BOLT(org.neo4j.kernel.configuration.Connector.ConnectorType.BOLT) Map(java.util.Map) Pattern(java.util.regex.Pattern) Nonnull(javax.annotation.Nonnull) InvalidSettingException(org.neo4j.graphdb.config.InvalidSettingException) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) InvalidSettingException(org.neo4j.graphdb.config.InvalidSettingException) Nonnull(javax.annotation.Nonnull)

Example 2 with SettingValidator

use of org.neo4j.graphdb.config.SettingValidator in project neo4j by neo4j.

the class ConfigTest method shouldPassOnValidatorsOnWithMethods.

@Test
public void shouldPassOnValidatorsOnWithMethods() throws Exception {
    // Given
    ConfigurationValidator validator = spy(new ConfigurationValidator() {

        @Nonnull
        @Override
        public Map<String, String> validate(@Nonnull Collection<SettingValidator> settingValidators, @Nonnull Map<String, String> rawConfig, @Nonnull Log log, boolean parsingFile) throws InvalidSettingException {
            return rawConfig;
        }
    });
    Config first = Config.embeddedDefaults(stringMap("first.jibberish", "bah"), Collections.singleton(validator));
    // When
    Config second = first.withDefaults(stringMap("second.jibberish", "baah"));
    second.with(stringMap("third.jibberish", "baah"));
    // Then
    verify(validator, times(3)).validate(any(), any(), any(), anyBoolean());
}
Also used : Nonnull(javax.annotation.Nonnull) Log(org.neo4j.logging.Log) SettingValidator(org.neo4j.graphdb.config.SettingValidator) LoadableConfig(org.neo4j.configuration.LoadableConfig) InvalidSettingException(org.neo4j.graphdb.config.InvalidSettingException) Map(java.util.Map) MapUtil.stringMap(org.neo4j.helpers.collection.MapUtil.stringMap) Test(org.junit.Test)

Aggregations

Map (java.util.Map)2 Nonnull (javax.annotation.Nonnull)2 InvalidSettingException (org.neo4j.graphdb.config.InvalidSettingException)2 SettingValidator (org.neo4j.graphdb.config.SettingValidator)2 Log (org.neo4j.logging.Log)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Test (org.junit.Test)1 LoadableConfig (org.neo4j.configuration.LoadableConfig)1 MapUtil.stringMap (org.neo4j.helpers.collection.MapUtil.stringMap)1 BOLT (org.neo4j.kernel.configuration.Connector.ConnectorType.BOLT)1 HTTP (org.neo4j.kernel.configuration.Connector.ConnectorType.HTTP)1