Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose all connector addresses in dbms.cluster.overview
- Loading branch information
Showing
25 changed files
with
519 additions
and
184 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
community/dbms/src/main/java/org/neo4j/server/configuration/ClientConnectorSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
177 changes: 177 additions & 0 deletions
177
...rprise/core-edge/src/main/java/org/neo4j/coreedge/discovery/ClientConnectorAddresses.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.coreedge.discovery; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import org.neo4j.helpers.AdvertisedSocketAddress; | ||
import org.neo4j.kernel.configuration.Config; | ||
import org.neo4j.server.configuration.ClientConnectorSettings.HttpConnector.Encryption; | ||
|
||
import static org.neo4j.coreedge.discovery.ClientConnectorAddresses.Scheme.bolt; | ||
import static org.neo4j.coreedge.discovery.ClientConnectorAddresses.Scheme.http; | ||
import static org.neo4j.coreedge.discovery.ClientConnectorAddresses.Scheme.https; | ||
import static org.neo4j.graphdb.factory.GraphDatabaseSettings.boltConnectors; | ||
import static org.neo4j.server.configuration.ClientConnectorSettings.httpConnector; | ||
|
||
public class ClientConnectorAddresses | ||
{ | ||
private final List<ConnectorUri> connectorUris; | ||
|
||
public ClientConnectorAddresses( List<ConnectorUri> connectorUris ) | ||
{ | ||
this.connectorUris = connectorUris; | ||
} | ||
|
||
static ClientConnectorAddresses extractFromConfig( Config config ) | ||
{ | ||
List<ConnectorUri> connectorUris = new ArrayList<>(); | ||
|
||
connectorUris.add( new ConnectorUri( bolt, boltConnectors( config ).stream().findFirst() | ||
.map( boltConnector -> config.get( boltConnector.advertised_address ) ).orElseThrow( () -> | ||
new IllegalArgumentException( "A Bolt connector must be configured to run a cluster" ) ) ) ); | ||
|
||
connectorUris.add( new ConnectorUri( http, config.get( httpConnector( config, Encryption.NONE ).orElseThrow( | ||
() -> new IllegalArgumentException( "An HTTP connector must be configured to run the server" ) ) | ||
.advertised_address ) ) ); | ||
|
||
httpConnector( config, Encryption.TLS ) | ||
.map( ( connector ) -> config.get( connector.advertised_address ) ) | ||
.ifPresent( httpsAddress -> connectorUris.add( new ConnectorUri( https, httpsAddress ) ) ); | ||
|
||
return new ClientConnectorAddresses( connectorUris ); | ||
} | ||
|
||
public AdvertisedSocketAddress getBoltAddress() | ||
{ | ||
return connectorUris.stream().filter( connectorUri -> connectorUri.scheme == bolt ).findFirst().orElseThrow( | ||
() -> new IllegalArgumentException( "A Bolt connector must be configured to run a cluster" ) ) | ||
.socketAddress; | ||
} | ||
|
||
public List<URI> uriList() | ||
{ | ||
return connectorUris.stream().map( ConnectorUri::toUri ).collect( Collectors.toList() ); | ||
} | ||
|
||
@Override | ||
public boolean equals( Object o ) | ||
{ | ||
if ( this == o ) | ||
{ | ||
return true; | ||
} | ||
if ( o == null || getClass() != o.getClass() ) | ||
{ | ||
return false; | ||
} | ||
ClientConnectorAddresses that = (ClientConnectorAddresses) o; | ||
return Objects.equals( connectorUris, that.connectorUris ); | ||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
return Objects.hash( connectorUris ); | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return connectorUris.stream().map( ConnectorUri::toString ).collect( Collectors.joining( "," ) ); | ||
} | ||
|
||
static ClientConnectorAddresses fromString( String value ) | ||
{ | ||
return new ClientConnectorAddresses( Stream.of( value.split( "," ) ) | ||
.map( ConnectorUri::fromString ).collect( Collectors.toList() ) ); | ||
} | ||
|
||
public enum Scheme | ||
{ | ||
bolt, http, https | ||
} | ||
|
||
public static class ConnectorUri | ||
{ | ||
private final Scheme scheme; | ||
private final AdvertisedSocketAddress socketAddress; | ||
|
||
public ConnectorUri( Scheme scheme, AdvertisedSocketAddress socketAddress ) | ||
{ | ||
this.scheme = scheme; | ||
this.socketAddress = socketAddress; | ||
} | ||
|
||
private URI toUri() | ||
{ | ||
try | ||
{ | ||
return new URI( scheme.name().toLowerCase(), null, socketAddress.getHostname(), socketAddress.getPort(), | ||
null, null, null ); | ||
} | ||
catch ( URISyntaxException e ) | ||
{ | ||
throw new IllegalArgumentException( e ); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return toUri().toString(); | ||
} | ||
|
||
private static ConnectorUri fromString( String string ) | ||
{ | ||
URI uri = URI.create( string ); | ||
return new ConnectorUri( Scheme.valueOf( uri.getScheme() ), | ||
new AdvertisedSocketAddress( uri.getHost(), uri.getPort() ) ); | ||
} | ||
|
||
@Override | ||
public boolean equals( Object o ) | ||
{ | ||
if ( this == o ) | ||
{ | ||
return true; | ||
} | ||
if ( o == null || getClass() != o.getClass() ) | ||
{ | ||
return false; | ||
} | ||
ConnectorUri that = (ConnectorUri) o; | ||
return scheme == that.scheme && | ||
Objects.equals( socketAddress, that.socketAddress ); | ||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
return Objects.hash( scheme, socketAddress ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.