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 java.lang.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. This field can be empty if the payload has not changed since last request, triggering an optimization at the client where the previous payload is used instead. 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, java.lang.String name)
Signal error when handling this request.void
addOkResponse(Payload payload, long generation, boolean internalRedeploy, java.lang.String configMd5)
Signal that the request was handled and provide return values typically needed by a client.static JRTServerConfigRequestV3
createFromRequest(com.yahoo.jrt.Request req)
protected static com.fasterxml.jackson.core.JsonGenerator
createJsonGenerator(java.io.ByteArrayOutputStream byteArrayOutputStream)
protected static com.yahoo.jrt.Value
createResponseValue(java.io.ByteArrayOutputStream byteArrayOutputStream)
int
errorCode()
Get the error code of this requestjava.lang.String
errorMessage()
Return the error message of this request, mostly corresponding to theErrorCode
.java.lang.String
getClientHostName()
Get the host name of the client that is requesting config.protected CompressionType
getCompressionType()
ConfigKey<?>
getConfigKey()
Get 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()
Get the config protocol versioncom.yahoo.jrt.Request
getRequest()
Get the JRT request object for this config request.java.lang.String
getRequestConfigMd5()
Get the current config md5 of the client config.long
getRequestGeneration()
Get the current config generation of the client config.Trace
getRequestTrace()
Get the request trace for this request.java.lang.String
getShortDescription()
Get a short hand description of this request.long
getTimeout()
Get the server timeout of this request.java.util.Optional<VespaVersion>
getVespaVersion()
Get the Vespa version of the client that initiated the requestboolean
isDelayedResponse()
Check whether or not this request is delayed.boolean
isInternalRedeploy()
Returns whether the response config was created by a system internal redeploy, not an application package changeboolean
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, java.lang.String fieldName, boolean value)
protected static void
setResponseField(com.fasterxml.jackson.core.JsonGenerator jsonGenerator, java.lang.String fieldName, long value)
protected static void
setResponseField(com.fasterxml.jackson.core.JsonGenerator jsonGenerator, java.lang.String fieldName, java.lang.String value)
java.lang.String
toString()
boolean
validateParameters()
Perform request parameter validation of this config request.
-
-
-
Method Detail
-
createJsonGenerator
protected static com.fasterxml.jackson.core.JsonGenerator createJsonGenerator(java.io.ByteArrayOutputStream byteArrayOutputStream) throws java.io.IOException
- Throws:
java.io.IOException
-
createResponseValue
protected static com.yahoo.jrt.Value createResponseValue(java.io.ByteArrayOutputStream byteArrayOutputStream)
-
setResponseField
protected static void setResponseField(com.fasterxml.jackson.core.JsonGenerator jsonGenerator, java.lang.String fieldName, java.lang.String value) throws java.io.IOException
- Throws:
java.io.IOException
-
setResponseField
protected static void setResponseField(com.fasterxml.jackson.core.JsonGenerator jsonGenerator, java.lang.String fieldName, long value) throws java.io.IOException
- Throws:
java.io.IOException
-
setResponseField
protected static void setResponseField(com.fasterxml.jackson.core.JsonGenerator jsonGenerator, java.lang.String fieldName, boolean value) throws java.io.IOException
- Throws:
java.io.IOException
-
addOkResponse
public void addOkResponse(Payload payload, long generation, boolean internalRedeploy, java.lang.String configMd5)
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.internalRedeploy
- whether this payload was generated from an internal redeployment not an application package changeconfigMd5
- The md5sum of the given payload.
-
getProtocolVersion
public long getProtocolVersion()
Description copied from interface:JRTConfigRequest
Get the config protocol version- Specified by:
getProtocolVersion
in interfaceJRTConfigRequest
- Returns:
- a protocol version number.
-
isInternalRedeploy
public boolean isInternalRedeploy()
Description copied from interface:JRTServerConfigRequest
Returns whether the response config was created by a system internal redeploy, not an application package change- Specified by:
isInternalRedeploy
in interfaceJRTServerConfigRequest
-
createFromRequest
public static JRTServerConfigRequestV3 createFromRequest(com.yahoo.jrt.Request req)
-
getConfigKey
public ConfigKey<?> getConfigKey()
Description copied from interface:JRTConfigRequest
Get 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.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
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 java.lang.String getClientHostName()
Description copied from interface:JRTConfigRequest
Get 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
Get 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
Perform 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.
-
getRequestConfigMd5
public java.lang.String getRequestConfigMd5()
Description copied from interface:JRTServerConfigRequest
Get the current config md5 of the client config.- Specified by:
getRequestConfigMd5
in interfaceJRTConfigRequest
- Specified by:
getRequestConfigMd5
in interfaceJRTServerConfigRequest
- Returns:
- a config md5.
-
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, java.lang.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 java.io.IOException
- Throws:
java.io.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
Get the error code of this request- Specified by:
errorCode
in interfaceJRTConfigRequest
- Returns:
- the error code as defined in
ErrorCode
.
-
errorMessage
public java.lang.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 java.lang.String getShortDescription()
Description copied from interface:JRTConfigRequest
Get 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
Get the server timeout of this request.- Specified by:
getTimeout
in interfaceJRTConfigRequest
- Returns:
- the timeout given to the server
-
getVespaVersion
public java.util.Optional<VespaVersion> getVespaVersion()
Description copied from interface:JRTConfigRequest
Get 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
-
-