Search in sources :

Example 1 with InvalidFilterSpecification

use of org.neo4j.causalclustering.load_balancing.plugins.server_policies.InvalidFilterSpecification in project neo4j by neo4j.

the class UserDefinedConfigurationStrategy method upstreamDatabase.

@Override
public Optional<MemberId> upstreamDatabase() throws UpstreamDatabaseSelectionException {
    try {
        Filter<ServerInfo> filters = FilterConfigParser.parse(config.get(CausalClusteringSettings.user_defined_upstream_selection_strategy));
        Set<ServerInfo> possibleReaders = topologyService.readReplicas().members().entrySet().stream().map(entry -> new ServerInfo(entry.getValue().connectors().boltAddress(), entry.getKey(), entry.getValue().groups())).collect(Collectors.toSet());
        CoreTopology coreTopology = topologyService.coreServers();
        for (MemberId validCore : coreTopology.members().keySet()) {
            Optional<CoreServerInfo> coreServerInfo = coreTopology.find(validCore);
            if (coreServerInfo.isPresent()) {
                CoreServerInfo serverInfo = coreServerInfo.get();
                possibleReaders.add(new ServerInfo(serverInfo.connectors().boltAddress(), validCore, serverInfo.groups()));
            }
        }
        return filters.apply(possibleReaders).stream().map(ServerInfo::memberId).findAny();
    } catch (InvalidFilterSpecification invalidFilterSpecification) {
        return Optional.empty();
    }
}
Also used : Service(org.neo4j.helpers.Service) InvalidFilterSpecification(org.neo4j.causalclustering.load_balancing.plugins.server_policies.InvalidFilterSpecification) CausalClusteringSettings(org.neo4j.causalclustering.core.CausalClusteringSettings) Optional(java.util.Optional) Set(java.util.Set) MemberId(org.neo4j.causalclustering.identity.MemberId) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) Filter(org.neo4j.causalclustering.load_balancing.filters.Filter) ServerInfo(org.neo4j.causalclustering.load_balancing.plugins.server_policies.ServerInfo) Collectors(java.util.stream.Collectors) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology) FilterConfigParser(org.neo4j.causalclustering.load_balancing.plugins.server_policies.FilterConfigParser) MemberId(org.neo4j.causalclustering.identity.MemberId) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) ServerInfo(org.neo4j.causalclustering.load_balancing.plugins.server_policies.ServerInfo) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) InvalidFilterSpecification(org.neo4j.causalclustering.load_balancing.plugins.server_policies.InvalidFilterSpecification) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology)

Aggregations

Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 CausalClusteringSettings (org.neo4j.causalclustering.core.CausalClusteringSettings)1 CoreServerInfo (org.neo4j.causalclustering.discovery.CoreServerInfo)1 CoreTopology (org.neo4j.causalclustering.discovery.CoreTopology)1 MemberId (org.neo4j.causalclustering.identity.MemberId)1 Filter (org.neo4j.causalclustering.load_balancing.filters.Filter)1 FilterConfigParser (org.neo4j.causalclustering.load_balancing.plugins.server_policies.FilterConfigParser)1 InvalidFilterSpecification (org.neo4j.causalclustering.load_balancing.plugins.server_policies.InvalidFilterSpecification)1 ServerInfo (org.neo4j.causalclustering.load_balancing.plugins.server_policies.ServerInfo)1 Service (org.neo4j.helpers.Service)1