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 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 DiscoveryService method getDiscoveryDocument.
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getDiscoveryDocument(@Context UriInfo uriInfo) throws URISyntaxException {
String managementUri = config.get(ServerSettings.management_api_path).getPath() + "/";
String dataUri = config.get(ServerSettings.rest_api_path).getPath() + "/";
Optional<AdvertisedSocketAddress> boltAddress = config.enabledBoltConnectors().stream().findFirst().map(boltConnector -> config.get(boltConnector.advertised_address));
if (boltAddress.isPresent()) {
AdvertisedSocketAddress advertisedSocketAddress = boltAddress.get();
if (advertisedSocketAddress.getHostname().equals("localhost")) {
// Use the port specified in the config, but not the host
return outputFormat.ok(new DiscoveryRepresentation(managementUri, dataUri, new AdvertisedSocketAddress(uriInfo.getBaseUri().getHost(), advertisedSocketAddress.getPort())));
} else {
// Use the config verbatim since it seems sane
return outputFormat.ok(new DiscoveryRepresentation(managementUri, dataUri, advertisedSocketAddress));
}
} else {
// There's no config, compute possible endpoint using host header and default bolt port.
return outputFormat.ok(new DiscoveryRepresentation(managementUri, dataUri, new AdvertisedSocketAddress(uriInfo.getBaseUri().getHost(), 7687)));
}
}
use of org.neo4j.helpers.AdvertisedSocketAddress in project neo4j by neo4j.
the class HazelcastClusterTopology method readReplicas.
private static Map<MemberId, ReadReplicaInfo> readReplicas(HazelcastInstance hazelcastInstance) {
IMap<String, String> /*boltAddress*/
clientAddressMap = hazelcastInstance.getMap(READ_REPLICA_BOLT_ADDRESS_MAP_NAME);
IMap<String, String> txServerMap = hazelcastInstance.getMap(READ_REPLICA_TRANSACTION_SERVER_ADDRESS_MAP_NAME);
IMap<String, String> memberIdMap = hazelcastInstance.getMap(READ_REPLICA_MEMBER_ID_MAP_NAME);
MultiMap<String, String> serverGroups = hazelcastInstance.getMultiMap(SERVER_GROUPS_MULTIMAP_NAME);
Map<MemberId, ReadReplicaInfo> result = new HashMap<>();
for (String hzUUID : clientAddressMap.keySet()) {
ClientConnectorAddresses clientConnectorAddresses = ClientConnectorAddresses.fromString(clientAddressMap.get(hzUUID));
AdvertisedSocketAddress catchupAddress = socketAddress(txServerMap.get(hzUUID), AdvertisedSocketAddress::new);
result.put(new MemberId(UUID.fromString(memberIdMap.get(hzUUID))), new ReadReplicaInfo(clientConnectorAddresses, catchupAddress, asSet(serverGroups.get(hzUUID))));
}
return result;
}
use of org.neo4j.helpers.AdvertisedSocketAddress in project neo4j by neo4j.
the class HazelcastClusterTopology method buildMemberAttributesForCore.
static MemberAttributeConfig buildMemberAttributesForCore(MemberId myself, Config config) {
MemberAttributeConfig memberAttributeConfig = new MemberAttributeConfig();
memberAttributeConfig.setStringAttribute(MEMBER_UUID, myself.getUuid().toString());
AdvertisedSocketAddress discoveryAddress = config.get(CausalClusteringSettings.discovery_advertised_address);
memberAttributeConfig.setStringAttribute(DISCOVERY_SERVER, discoveryAddress.toString());
AdvertisedSocketAddress transactionSource = config.get(CausalClusteringSettings.transaction_advertised_address);
memberAttributeConfig.setStringAttribute(TRANSACTION_SERVER, transactionSource.toString());
AdvertisedSocketAddress raftAddress = config.get(CausalClusteringSettings.raft_advertised_address);
memberAttributeConfig.setStringAttribute(RAFT_SERVER, raftAddress.toString());
ClientConnectorAddresses clientConnectorAddresses = ClientConnectorAddresses.extractFromConfig(config);
memberAttributeConfig.setStringAttribute(CLIENT_CONNECTOR_ADDRESSES, clientConnectorAddresses.toString());
memberAttributeConfig.setBooleanAttribute(REFUSE_TO_BE_LEADER_KEY, config.get(CausalClusteringSettings.refuse_to_be_leader));
return memberAttributeConfig;
}
Aggregations