use of org.neo4j.helpers.AdvertisedSocketAddress in project neo4j by neo4j.
the class Settings method advertisedAddress.
public static BaseSetting<AdvertisedSocketAddress> advertisedAddress(String name, Setting<ListenSocketAddress> listenAddressSetting) {
return new ScopeAwareSetting<AdvertisedSocketAddress>() {
@Override
protected String provideName() {
return name;
}
@Override
public String getDefaultValue() {
return default_advertised_address.getDefaultValue() + ":" + LISTEN_SOCKET_ADDRESS.apply(listenAddressSetting.getDefaultValue()).socketAddress().getPort();
}
@Override
public AdvertisedSocketAddress from(Configuration config) {
return config.get(this);
}
@Override
public AdvertisedSocketAddress apply(Function<String, String> config) {
ListenSocketAddress listenSocketAddress = listenAddressSetting.apply(config);
String hostname = default_advertised_address.apply(config);
int port = listenSocketAddress.socketAddress().getPort();
String name = name();
String value = config.apply(name);
return SocketAddressFormat.socketAddress(name, value, hostname, port, AdvertisedSocketAddress::new);
}
@Override
public void withScope(Function<String, String> scopingRule) {
super.withScope(scopingRule);
listenAddressSetting.withScope(scopingRule);
}
@Override
public String valueDescription() {
return ADVERTISED_SOCKET_ADDRESS.toString();
}
};
}
use of org.neo4j.helpers.AdvertisedSocketAddress in project neo4j by neo4j.
the class BoltKernelExtension method newInstance.
@Override
public Lifecycle newInstance(KernelContext context, Dependencies dependencies) throws Throwable {
Config config = dependencies.config();
GraphDatabaseService gdb = dependencies.db();
GraphDatabaseAPI api = (GraphDatabaseAPI) gdb;
LogService logService = dependencies.logService();
Clock clock = dependencies.clock();
Log log = logService.getInternalLog(WorkerFactory.class);
LifeSupport life = new LifeSupport();
JobScheduler scheduler = dependencies.scheduler();
InternalLoggerFactory.setDefaultFactory(new Netty4LoggerFactory(logService.getInternalLogProvider()));
Authentication authentication = authentication(dependencies.authManager(), dependencies.userManagerSupplier());
BoltFactory boltFactory = life.add(new BoltFactoryImpl(api, dependencies.usageData(), logService, dependencies.txBridge(), authentication, dependencies.sessionTracker(), config));
WorkerFactory workerFactory = createWorkerFactory(boltFactory, scheduler, dependencies, logService, clock);
List<ProtocolInitializer> connectors = config.enabledBoltConnectors().stream().map((connConfig) -> {
ListenSocketAddress listenAddress = config.get(connConfig.listen_address);
AdvertisedSocketAddress advertisedAddress = config.get(connConfig.advertised_address);
SslContext sslCtx;
boolean requireEncryption;
final BoltConnector.EncryptionLevel encryptionLevel = config.get(connConfig.encryption_level);
switch(encryptionLevel) {
case REQUIRED:
// Encrypted connections are mandatory, a self-signed certificate may be generated.
requireEncryption = true;
sslCtx = createSslContext(config, log, advertisedAddress);
break;
case OPTIONAL:
// Encrypted connections are optional, a self-signed certificate may be generated.
requireEncryption = false;
sslCtx = createSslContext(config, log, advertisedAddress);
break;
case DISABLED:
// Encryption is turned off, no self-signed certificate will be generated.
requireEncryption = false;
sslCtx = null;
break;
default:
// In the unlikely event that we happen to fall through to the default option here,
// there is a mismatch between the BoltConnector.EncryptionLevel enum and the options
// handled in this switch statement. In this case, we'll log a warning and default to
// disabling encryption, since this mirrors the functionality introduced in 3.0.
log.warn(format("Unhandled encryption level %s - assuming DISABLED.", encryptionLevel.name()));
requireEncryption = false;
sslCtx = null;
break;
}
final Map<Long, BiFunction<Channel, Boolean, BoltProtocol>> versions = newVersions(logService, workerFactory);
return new SocketTransport(listenAddress, sslCtx, requireEncryption, logService.getInternalLogProvider(), versions);
}).collect(toList());
if (connectors.size() > 0 && !config.get(GraphDatabaseSettings.disconnected)) {
life.add(new NettyServer(scheduler.threadFactory(boltNetworkIO), connectors));
log.info("Bolt Server extension loaded.");
for (ProtocolInitializer connector : connectors) {
logService.getUserLog(WorkerFactory.class).info("Bolt enabled on %s.", connector.address());
}
}
return life;
}
use of org.neo4j.helpers.AdvertisedSocketAddress in project neo4j by neo4j.
the class GraphDatabaseSettingsTest method groupToScopeSetting.
@Test
public void groupToScopeSetting() throws Exception {
// given
String hostname = "my_other_host";
int port = 9999;
String scoping = "bla";
Map<String, String> config = stringMap(GraphDatabaseSettings.default_advertised_address.name(), hostname, new BoltConnector(scoping).advertised_address.name(), ":" + port);
// when
BoltConnector boltConnector = new BoltConnector(scoping);
Setting<AdvertisedSocketAddress> advertised_address = boltConnector.advertised_address;
AdvertisedSocketAddress advertisedSocketAddress = advertised_address.apply(config::get);
// then
assertEquals(hostname, advertisedSocketAddress.getHostname());
assertEquals(port, advertisedSocketAddress.getPort());
}
use of org.neo4j.helpers.AdvertisedSocketAddress in project neo4j by neo4j.
the class AdvertisedAddressSettingsTest method shouldCombineDefaultHostnameWithExplicitPortWhenOnlyAPortProvided.
@Test
public void shouldCombineDefaultHostnameWithExplicitPortWhenOnlyAPortProvided() throws Exception {
// given
Map<String, String> config = stringMap(GraphDatabaseSettings.default_advertised_address.name(), "server1.example.com", advertised_address_setting.name(), ":4000");
// when
AdvertisedSocketAddress advertisedSocketAddress = advertised_address_setting.apply(config::get);
// then
assertEquals("server1.example.com", advertisedSocketAddress.getHostname());
assertEquals(4000, advertisedSocketAddress.getPort());
}
use of org.neo4j.helpers.AdvertisedSocketAddress in project neo4j by neo4j.
the class AnyGroupFilterTest method shouldReturnServersMatchingAnyGroup.
@Test
public void shouldReturnServersMatchingAnyGroup() throws Exception {
// given
AnyGroupFilter groupFilter = new AnyGroupFilter(asSet("china-west", "europe"));
ServerInfo serverA = new ServerInfo(new AdvertisedSocketAddress("bolt", 1), new MemberId(UUID.randomUUID()), asSet("china-west"));
ServerInfo serverB = new ServerInfo(new AdvertisedSocketAddress("bolt", 2), new MemberId(UUID.randomUUID()), asSet("europe"));
ServerInfo serverC = new ServerInfo(new AdvertisedSocketAddress("bolt", 3), new MemberId(UUID.randomUUID()), asSet("china", "china-west"));
ServerInfo serverD = new ServerInfo(new AdvertisedSocketAddress("bolt", 4), new MemberId(UUID.randomUUID()), asSet("china-west", "china"));
ServerInfo serverE = new ServerInfo(new AdvertisedSocketAddress("bolt", 5), new MemberId(UUID.randomUUID()), asSet("china-east", "asia"));
ServerInfo serverF = new ServerInfo(new AdvertisedSocketAddress("bolt", 6), new MemberId(UUID.randomUUID()), asSet("europe-west"));
ServerInfo serverG = new ServerInfo(new AdvertisedSocketAddress("bolt", 7), new MemberId(UUID.randomUUID()), asSet("china-west", "europe"));
ServerInfo serverH = new ServerInfo(new AdvertisedSocketAddress("bolt", 8), new MemberId(UUID.randomUUID()), asSet("africa"));
Set<ServerInfo> data = asSet(serverA, serverB, serverC, serverD, serverE, serverF, serverG, serverH);
// when
Set<ServerInfo> output = groupFilter.apply(data);
// then
Set<Integer> ports = new HashSet<>();
for (ServerInfo info : output) {
ports.add(info.boltAddress().getPort());
}
assertEquals(asSet(1, 2, 3, 4, 7), ports);
}
Aggregations