Package com.yahoo.vespa.config.protocol
Class JRTServerConfigRequestV3
- java.lang.Object
-
- com.yahoo.vespa.config.protocol.JRTServerConfigRequestV3
-
- All Implemented Interfaces:
GetConfigRequest
,JRTConfigRequest
,JRTServerConfigRequest
public class JRTServerConfigRequestV3 extends Object implements JRTServerConfigRequest
The V3 config protocol implemented on the server side. The V3 protocol uses 2 fields: * A metadata field containing json data describing config generation, md5 and compression info * A data field containing compressed or uncompressed json config payload The implementation of addOkResponse is optimized for doing as little copying of payload data as possible, ensuring that we get a lower memory footprint.- Author:
- Ulf Lilleengen
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
JRTServerConfigRequestV3(com.yahoo.jrt.Request request)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addCommonReturnValues(com.fasterxml.jackson.core.JsonGenerator jsonGenerator)
void
addErrorResponse(int errorCode, String name)
Signal error when handling this request.void
addOkResponse(Payload payload, long generation, boolean applyOnRestart, PayloadChecksums checksums)
Signal that the request was handled and provide return values typically needed by a client.boolean
applyOnRestart()
PayloadChecksums
configPayloadChecksums()
Returns the payload checksums from the config request.static JRTServerConfigRequestV3
createFromRequest(com.yahoo.jrt.Request req)
protected static com.fasterxml.jackson.core.JsonGenerator
createJsonGenerator(ByteArrayOutputStream byteArrayOutputStream)
protected static com.yahoo.jrt.Value
createResponseValue(ByteArrayOutputStream byteArrayOutputStream)
int
errorCode()
Returns the error code of this requestString
errorMessage()
Return the error message of this request, mostly corresponding to theErrorCode
.String
getClientHostName()
Returns the host name of the client that is requesting config.protected CompressionType
getCompressionType()
ConfigKey<?>
getConfigKey()
Returns the config key of the config request.DefContent
getDefContent()
The def file contents in the request, or empty array if not sent/not supportedlong
getProtocolVersion()
Returns the config protocol versioncom.yahoo.jrt.Request
getRequest()
Returns the JRT request object for this config request.PayloadChecksums
getRequestConfigChecksums()
Returns the generation of the requested config.String
getRequestDefMd5()
Returns the md5 of the config definition in the request.long
getRequestGeneration()
Get the current config generation of the client config.Trace
getRequestTrace()
Get the request trace for this request.String
getShortDescription()
Returns a short hand description of this request.long
getTimeout()
Returns the server timeout of this request.Optional<VespaVersion>
getVespaVersion()
Returns the Vespa version of the client that initiated the requestboolean
isDelayedResponse()
Check whether or not this request is delayed.boolean
noCache()
Whether or not the config can be retrieved from or stored in a cache.Payload
payloadFromResponse(ConfigResponse response)
Extract the appropriate payload for this request type for a given config response.void
setDelayedResponse(boolean delayedResponse)
Notify this request that its delayed due to no new config being available at this point.protected static void
setResponseField(com.fasterxml.jackson.core.JsonGenerator jsonGenerator, String fieldName, boolean value)
protected static void
setResponseField(com.fasterxml.jackson.core.JsonGenerator jsonGenerator, String fieldName, long value)
protected static void
setResponseField(com.fasterxml.jackson.core.JsonGenerator jsonGenerator, String fieldName, String value)
String
toString()
boolean
validateParameters()
Performs request parameter validation of this config request.
-
-
-
Field Detail
-
log
protected static final Logger log
-
request
protected final com.yahoo.jrt.Request request
-
-
Method Detail
-
createJsonGenerator
protected static com.fasterxml.jackson.core.JsonGenerator createJsonGenerator(ByteArrayOutputStream byteArrayOutputStream) throws IOException
- Throws:
IOException
-
createResponseValue
protected static com.yahoo.jrt.Value createResponseValue(ByteArrayOutputStream byteArrayOutputStream)
-
setResponseField
protected static void setResponseField(com.fasterxml.jackson.core.JsonGenerator jsonGenerator, String fieldName, String value) throws IOException
- Throws:
IOException
-
setResponseField
protected static void setResponseField(com.fasterxml.jackson.core.JsonGenerator jsonGenerator, String fieldName, long value) throws IOException
- Throws:
IOException
-
setResponseField
protected static void setResponseField(com.fasterxml.jackson.core.JsonGenerator jsonGenerator, String fieldName, boolean value) throws IOException
- Throws:
IOException
-
addOkResponse
public void addOkResponse(Payload payload, long generation, boolean applyOnRestart, PayloadChecksums checksums)
Description copied from interface:JRTServerConfigRequest
Signal that the request was handled and provide return values typically needed by a client.- Specified by:
addOkResponse
in interfaceJRTServerConfigRequest
- Parameters:
payload
- The config payload that the client should receive.generation
- The config generation of the given payload.applyOnRestart
- true if this config should only be applied on the next restart, false if it should be applied right awaychecksums
- checksums of the given payload.
-
getProtocolVersion
public long getProtocolVersion()
Description copied from interface:JRTConfigRequest
Returns the config protocol version- Specified by:
getProtocolVersion
in interfaceJRTConfigRequest
- Returns:
- a protocol version number.
-
applyOnRestart
public boolean applyOnRestart()
- Specified by:
applyOnRestart
in interfaceJRTServerConfigRequest
-
createFromRequest
public static JRTServerConfigRequestV3 createFromRequest(com.yahoo.jrt.Request req)
-
getConfigKey
public ConfigKey<?> getConfigKey()
Description copied from interface:JRTConfigRequest
Returns the config key of the config request.- Specified by:
getConfigKey
in interfaceGetConfigRequest
- Specified by:
getConfigKey
in interfaceJRTConfigRequest
- Returns:
- a
ConfigKey
.
-
getDefContent
public DefContent getDefContent()
Description copied from interface:GetConfigRequest
The def file contents in the request, or empty array if not sent/not supported- Specified by:
getDefContent
in interfaceGetConfigRequest
- Returns:
- the contents (payload) of the def schema
-
noCache
public boolean noCache()
Description copied from interface:GetConfigRequest
Whether or not the config can be retrieved from or stored in a cache.- Specified by:
noCache
in interfaceGetConfigRequest
- Returns:
- true if content should _not_ be cached, false if it should.
-
payloadFromResponse
public Payload payloadFromResponse(ConfigResponse response)
Description copied from interface:JRTServerConfigRequest
Extract the appropriate payload for this request type for a given config response.- Specified by:
payloadFromResponse
in interfaceJRTServerConfigRequest
- Parameters:
response
-ConfigResponse
to get payload from.- Returns:
- A
Payload
that satisfies this request format.
-
getClientHostName
public String getClientHostName()
Description copied from interface:JRTConfigRequest
Returns the host name of the client that is requesting config.- Specified by:
getClientHostName
in interfaceJRTConfigRequest
- Returns:
- hostname of the client.
-
getRequestTrace
public Trace getRequestTrace()
Description copied from interface:JRTServerConfigRequest
Get the request trace for this request. The trace can be used to trace config execution to provide useful debug info in production environments.- Specified by:
getRequestTrace
in interfaceJRTServerConfigRequest
- Returns:
- a
Trace
instance.
-
getRequest
public com.yahoo.jrt.Request getRequest()
Description copied from interface:JRTConfigRequest
Returns the JRT request object for this config request. TODO: This method leaks the internal jrt stuff :(- Specified by:
getRequest
in interfaceJRTConfigRequest
- Returns:
- a
Request
object.
-
validateParameters
public boolean validateParameters()
Description copied from interface:JRTConfigRequest
Performs request parameter validation of this config request. This method should be called before fetching any kind of config protocol-specific parameter.- Specified by:
validateParameters
in interfaceJRTConfigRequest
- Returns:
- true if valid, false if not.
-
getRequestDefMd5
public String getRequestDefMd5()
Description copied from interface:JRTServerConfigRequest
Returns the md5 of the config definition in the request.- Specified by:
getRequestDefMd5
in interfaceGetConfigRequest
- Specified by:
getRequestDefMd5
in interfaceJRTConfigRequest
- Specified by:
getRequestDefMd5
in interfaceJRTServerConfigRequest
- Returns:
- an md5 of config definition in request.
-
getRequestConfigChecksums
public PayloadChecksums getRequestConfigChecksums()
Description copied from interface:JRTConfigRequest
Returns the generation of the requested config. If none has been given, 0 should be returned. Returns the checksum of the config request. Return an empty string if no response has been returned.- Specified by:
getRequestConfigChecksums
in interfaceJRTConfigRequest
- Returns:
- a config checksum.
-
setDelayedResponse
public void setDelayedResponse(boolean delayedResponse)
Description copied from interface:JRTServerConfigRequest
Notify this request that its delayed due to no new config being available at this point. The value provided in this function should be returned when callingJRTServerConfigRequest.isDelayedResponse()
.- Specified by:
setDelayedResponse
in interfaceJRTServerConfigRequest
- Parameters:
delayedResponse
- true if response is delayed, false if not.
-
addErrorResponse
public void addErrorResponse(int errorCode, String name)
Description copied from interface:JRTServerConfigRequest
Signal error when handling this request. The error should be reflected in the request state and propagated back to the client.- Specified by:
addErrorResponse
in interfaceJRTServerConfigRequest
- Parameters:
errorCode
- error code, as described inErrorCode
.name
- message to display for this error, typically printed by client.
-
addCommonReturnValues
protected void addCommonReturnValues(com.fasterxml.jackson.core.JsonGenerator jsonGenerator) throws IOException
- Throws:
IOException
-
getRequestGeneration
public long getRequestGeneration()
Description copied from interface:JRTServerConfigRequest
Get the current config generation of the client config.- Specified by:
getRequestGeneration
in interfaceJRTConfigRequest
- Specified by:
getRequestGeneration
in interfaceJRTServerConfigRequest
- Returns:
- the current config generation.
-
isDelayedResponse
public boolean isDelayedResponse()
Description copied from interface:JRTServerConfigRequest
Check whether or not this request is delayed.- Specified by:
isDelayedResponse
in interfaceJRTServerConfigRequest
- Returns:
- true if delayed, false if not.
-
errorCode
public int errorCode()
Description copied from interface:JRTConfigRequest
Returns the error code of this request- Specified by:
errorCode
in interfaceJRTConfigRequest
- Returns:
- the error code as defined in
ErrorCode
.
-
errorMessage
public String errorMessage()
Description copied from interface:JRTConfigRequest
Return the error message of this request, mostly corresponding to theErrorCode
.- Specified by:
errorMessage
in interfaceJRTConfigRequest
- Returns:
- the error message.
-
getShortDescription
public String getShortDescription()
Description copied from interface:JRTConfigRequest
Returns a short hand description of this request.- Specified by:
getShortDescription
in interfaceJRTConfigRequest
- Returns:
- a short description
-
getCompressionType
protected CompressionType getCompressionType()
-
getTimeout
public long getTimeout()
Description copied from interface:JRTConfigRequest
Returns the server timeout of this request.- Specified by:
getTimeout
in interfaceJRTConfigRequest
- Returns:
- the timeout given to the server
-
getVespaVersion
public Optional<VespaVersion> getVespaVersion()
Description copied from interface:JRTConfigRequest
Returns the Vespa version of the client that initiated the request- Specified by:
getVespaVersion
in interfaceGetConfigRequest
- Specified by:
getVespaVersion
in interfaceJRTConfigRequest
- Returns:
- Vespa version of the client
-
configPayloadChecksums
public PayloadChecksums configPayloadChecksums()
Description copied from interface:JRTServerConfigRequest
Returns the payload checksums from the config request.- Specified by:
configPayloadChecksums
in interfaceGetConfigRequest
- Specified by:
configPayloadChecksums
in interfaceJRTServerConfigRequest
- Returns:
- the payload checksumss from request.
-
-