Skip to content

Deprecated and replaced ServerInfo.version() #878

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion driver/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
<differences>
<!--4.0 drivers is not API compatible with 1.0 drivers, as a result we reset API differences from 4.0.0-->
<!--4.0 drivers is not API compatible with 1.0 drivers, as a result we reset API differences from 4.0.0-->

<difference>
<className>org/neo4j/driver/summary/ServerInfo</className>
<differenceType>7007</differenceType>
<method>java.lang.String version()</method>
</difference>

<difference>
<className>org/neo4j/driver/summary/ServerInfo</className>
<differenceType>7012</differenceType>
<method>java.lang.String protocolVersion()</method>
</difference>

<difference>
<className>org/neo4j/driver/summary/ServerInfo</className>
<differenceType>7012</differenceType>
<method>java.lang.String agent()</method>
</difference>

</differences>
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class NetworkConnection implements Connection
{
private final Channel channel;
private final InboundMessageDispatcher messageDispatcher;
private final String serverAgent;
private final BoltServerAddress serverAddress;
private final ServerVersion serverVersion;
private final BoltProtocol protocol;
Expand All @@ -69,6 +70,7 @@ public NetworkConnection( Channel channel, ExtendedChannelPool channelPool, Cloc
{
this.channel = channel;
this.messageDispatcher = ChannelAttributes.messageDispatcher( channel );
this.serverAgent = ChannelAttributes.serverAgent( channel );
this.serverAddress = ChannelAttributes.serverAddress( channel );
this.serverVersion = ChannelAttributes.serverVersion( channel );
this.protocol = BoltProtocol.forChannel( channel );
Expand Down Expand Up @@ -185,6 +187,12 @@ public void terminateAndRelease( String reason )
}
}

@Override
public String serverAgent()
{
return serverAgent;
}

@Override
public BoltServerAddress serverAddress()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public final class ChannelAttributes
private static final AttributeKey<String> CONNECTION_ID = newInstance( "connectionId" );
private static final AttributeKey<String> POOL_ID = newInstance( "poolId" );
private static final AttributeKey<BoltProtocolVersion> PROTOCOL_VERSION = newInstance( "protocolVersion" );
private static final AttributeKey<String> SERVER_AGENT = newInstance( "serverAgent" );
private static final AttributeKey<BoltServerAddress> ADDRESS = newInstance( "serverAddress" );
private static final AttributeKey<ServerVersion> SERVER_VERSION = newInstance( "serverVersion" );
private static final AttributeKey<Long> CREATION_TIMESTAMP = newInstance( "creationTimestamp" );
Expand Down Expand Up @@ -74,6 +75,16 @@ public static void setProtocolVersion( Channel channel, BoltProtocolVersion vers
setOnce( channel, PROTOCOL_VERSION, version );
}

public static void setServerAgent( Channel channel, String serverAgent )
{
setOnce( channel, SERVER_AGENT, serverAgent );
}

public static String serverAgent( Channel channel )
{
return get( channel, SERVER_AGENT );
}

public static BoltServerAddress serverAddress( Channel channel )
{
return get( channel, ADDRESS );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.concurrent.CompletionStage;

import org.neo4j.driver.AccessMode;
import org.neo4j.driver.internal.BoltServerAddress;
import org.neo4j.driver.internal.DatabaseName;
import org.neo4j.driver.internal.DirectConnectionProvider;
Expand All @@ -28,7 +29,6 @@
import org.neo4j.driver.internal.spi.Connection;
import org.neo4j.driver.internal.spi.ResponseHandler;
import org.neo4j.driver.internal.util.ServerVersion;
import org.neo4j.driver.AccessMode;

/**
* This is a connection used by {@link DirectConnectionProvider} to connect to a remote database.
Expand Down Expand Up @@ -111,6 +111,12 @@ public void terminateAndRelease( String reason )
delegate.terminateAndRelease( reason );
}

@Override
public String serverAgent()
{
return delegate.serverAgent();
}

@Override
public BoltServerAddress serverAddress()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.concurrent.CompletionStage;

import org.neo4j.driver.AccessMode;
import org.neo4j.driver.internal.BoltServerAddress;
import org.neo4j.driver.internal.DatabaseName;
import org.neo4j.driver.internal.RoutingErrorHandler;
Expand All @@ -29,7 +30,6 @@
import org.neo4j.driver.internal.spi.Connection;
import org.neo4j.driver.internal.spi.ResponseHandler;
import org.neo4j.driver.internal.util.ServerVersion;
import org.neo4j.driver.AccessMode;

/**
* A connection used by the routing driver.
Expand Down Expand Up @@ -109,6 +109,12 @@ public void terminateAndRelease( String reason )
delegate.terminateAndRelease( reason );
}

@Override
public String serverAgent()
{
return delegate.serverAgent();
}

@Override
public BoltServerAddress serverAddress()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@

import java.util.Map;

import org.neo4j.driver.Value;
import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
import org.neo4j.driver.internal.messaging.v3.BoltProtocolV3;
import org.neo4j.driver.internal.spi.ResponseHandler;
import org.neo4j.driver.Value;

import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setConnectionId;
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setServerAgent;
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setServerVersion;
import static org.neo4j.driver.internal.util.MetadataExtractor.extractNeo4jServerVersion;
import static org.neo4j.driver.internal.util.MetadataExtractor.extractServer;
import static org.neo4j.driver.internal.util.ServerVersion.fromBoltProtocolVersion;

public class HelloResponseHandler implements ResponseHandler
Expand All @@ -53,6 +55,9 @@ public void onSuccess( Map<String,Value> metadata )
{
try
{
Value serverValue = extractServer( metadata );
setServerAgent( channel, serverValue.asString() );

// From Server V4 extracting server from metadata in the success message is unreliable
// so we fix the Server version against the Bolt Protocol version for Server V4 and above.
if ( BoltProtocolV3.VERSION.equals( protocolVersion ) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public interface Connection

void terminateAndRelease( String reason );

String serverAgent();

BoltServerAddress serverAddress();

ServerVersion serverVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,29 @@
import java.util.Objects;

import org.neo4j.driver.internal.BoltServerAddress;
import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
import org.neo4j.driver.internal.util.ServerVersion;
import org.neo4j.driver.summary.ServerInfo;

public class InternalServerInfo implements ServerInfo
{
private final String agent;
private final String address;
private final String version;
private final String protocolVersion;

public InternalServerInfo( BoltServerAddress address, ServerVersion version )
public InternalServerInfo( String agent, BoltServerAddress address, ServerVersion version, BoltProtocolVersion protocolVersion )
{
this.agent = agent;
this.address = address.toString();
this.version = version.toString();
this.protocolVersion = protocolVersion.toString();
}

@Override
public String agent()
{
return agent;
}

@Override
Expand All @@ -47,6 +58,12 @@ public String version()
return version;
}

@Override
public String protocolVersion()
{
return protocolVersion;
}

@Override
public boolean equals( Object o )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ public long extractResultAvailableAfter( Map<String,Value> metadata )

public ResultSummary extractSummary(Query query, Connection connection, long resultAvailableAfter, Map<String,Value> metadata )
{
ServerInfo serverInfo = new InternalServerInfo( connection.serverAddress(), connection.serverVersion() );
ServerInfo serverInfo =
new InternalServerInfo( connection.serverAgent(), connection.serverAddress(), connection.serverVersion(), connection.protocol().version() );
DatabaseInfo dbInfo = extractDatabaseInfo( metadata );
return new InternalResultSummary(query, serverInfo, dbInfo, extractQueryType( metadata ), extractCounters( metadata ), extractPlan( metadata ),
extractProfiledPlan( metadata ), extractNotifications( metadata ), resultAvailableAfter,
Expand Down Expand Up @@ -132,26 +133,29 @@ public static Bookmark extractBookmarks( Map<String,Value> metadata )

public static ServerVersion extractNeo4jServerVersion( Map<String,Value> metadata )
{
Value versionValue = metadata.get( "server" );
if ( versionValue == null || versionValue.isNull() )
Value serverValue = extractServer( metadata );
ServerVersion server = ServerVersion.version( serverValue.asString() );
if ( ServerVersion.NEO4J_PRODUCT.equalsIgnoreCase( server.product() ) )
{
throw new UntrustedServerException( "Server provides no product identifier" );
return server;
}
else
{
ServerVersion server = ServerVersion.version( versionValue.asString() );
if ( ServerVersion.NEO4J_PRODUCT.equalsIgnoreCase( server.product() ) )
{
return server;
}
else
{
throw new UntrustedServerException( "Server does not identify as a genuine Neo4j instance: '" + server.product() + "'" );
}
throw new UntrustedServerException( "Server does not identify as a genuine Neo4j instance: '" + server.product() + "'" );
}
}

public static Value extractServer( Map<String,Value> metadata )
{
Value versionValue = metadata.get( "server" );
if ( versionValue == null || versionValue.isNull() )
{
throw new UntrustedServerException( "Server provides no product identifier" );
}
return versionValue;
}

private static QueryType extractQueryType(Map<String,Value> metadata )
private static QueryType extractQueryType( Map<String,Value> metadata )
{
Value typeValue = metadata.get( "type" );
if ( typeValue != null )
Expand Down
22 changes: 20 additions & 2 deletions driver/src/main/java/org/neo4j/driver/summary/ServerInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,27 @@ public interface ServerInfo
String address();

/**
* Returns a string telling which version of the server the query was executed.
* Supported since neo4j 3.1.
* Returns a string telling which version of the server the query was executed. Supported since neo4j 3.1.
*
* @return The server version.
* @deprecated in 4.3, please use {@link ServerInfo#agent()}, {@link ServerInfo#protocolVersion()}, or call the <i>dbms.components</i> procedure instead.
* <b>Method might be removed in the next major release.</b>
*/
@Deprecated
String version();

/**
* Returns Bolt protocol version with which the remote server communicates. This is returned as a string in format X.Y where X is the major version and Y is
* the minor version.
*
* @return The Bolt protocol version.
*/
String protocolVersion();

/**
* Returns server agent string by which the remote server identifies itself.
*
* @return The agent string.
*/
String agent();
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.neo4j.driver.internal.handlers.PullResponseCompletionListener;
import org.neo4j.driver.internal.handlers.RunResponseHandler;
import org.neo4j.driver.internal.messaging.v3.BoltProtocolV3;
import org.neo4j.driver.internal.messaging.v43.BoltProtocolV43;
import org.neo4j.driver.internal.spi.Connection;
import org.neo4j.driver.internal.value.NullValue;
import org.neo4j.driver.util.Pair;
Expand Down Expand Up @@ -360,6 +361,8 @@ private Result createResult(int numberOfRecords )
Connection connection = mock( Connection.class );
when( connection.serverAddress() ).thenReturn( LOCAL_DEFAULT );
when( connection.serverVersion() ).thenReturn( anyServerVersion() );
when( connection.protocol() ).thenReturn( BoltProtocolV43.INSTANCE );
when( connection.serverAgent() ).thenReturn( "Neo4j/4.2.5" );
PullAllResponseHandler pullAllHandler =
new LegacyPullAllResponseHandler( query, runHandler, connection, BoltProtocolV3.METADATA_EXTRACTOR,
mock( PullResponseCompletionListener.class ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.neo4j.driver.internal.handlers.PullAllResponseHandler;
import org.neo4j.driver.internal.handlers.RunResponseHandler;
import org.neo4j.driver.internal.messaging.v3.BoltProtocolV3;
import org.neo4j.driver.internal.messaging.v43.BoltProtocolV43;
import org.neo4j.driver.internal.summary.InternalResultSummary;
import org.neo4j.driver.internal.summary.InternalServerInfo;
import org.neo4j.driver.internal.summary.InternalSummaryCounters;
Expand Down Expand Up @@ -86,10 +87,13 @@ void shouldReturnSummary()
{
PullAllResponseHandler pullAllHandler = mock( PullAllResponseHandler.class );

ResultSummary summary = new InternalResultSummary( new Query( "RETURN 42" ),
new InternalServerInfo( BoltServerAddress.LOCAL_DEFAULT, anyServerVersion() ), DEFAULT_DATABASE_INFO, QueryType.SCHEMA_WRITE,
ResultSummary summary = new InternalResultSummary(
new Query( "RETURN 42" ),
new InternalServerInfo( "Neo4j/4.2.5", BoltServerAddress.LOCAL_DEFAULT, anyServerVersion(), BoltProtocolV43.VERSION ),
DEFAULT_DATABASE_INFO, QueryType.SCHEMA_WRITE,
new InternalSummaryCounters( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0 ),
null, null, emptyList(), 42, 42 );
null, null, emptyList(), 42, 42
);
when( pullAllHandler.consumeAsync() ).thenReturn( completedFuture( summary ) );

AsyncResultCursorImpl cursor = newCursor( pullAllHandler );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,31 @@ void shouldNotWriteAndFlushMultipleMessagesWhenTerminated()
assertConnectionTerminatedError( failureCaptor.getValue() );
}

@Test
void shouldReturnServerAgentWhenCreated()
{
EmbeddedChannel channel = newChannel();
String agent = "Neo4j/4.2.5";
ChannelAttributes.setServerAgent( channel, agent );

NetworkConnection connection = newConnection( channel );

assertEquals( agent, connection.serverAgent() );
}

@Test
void shouldReturnServerAgentWhenReleased()
{
EmbeddedChannel channel = newChannel();
String agent = "Neo4j/4.2.5";
ChannelAttributes.setServerAgent( channel, agent );

NetworkConnection connection = newConnection( channel );
connection.release();

assertEquals( agent, connection.serverAgent() );
}

@Test
void shouldReturnServerAddressWhenReleased()
{
Expand Down
Loading