Class 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
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static java.util.logging.Logger log  
      protected com.yahoo.jrt.Request request  
    • 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 request
      java.lang.String errorMessage()
      Return the error message of this request, mostly corresponding to the ErrorCode.
      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 supported
      long getProtocolVersion()
      Get the config protocol version
      com.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 request
      boolean 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 change
      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, 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • log

        protected static final java.util.logging.Logger log
      • request

        protected final com.yahoo.jrt.Request request
    • Constructor Detail

      • JRTServerConfigRequestV3

        protected JRTServerConfigRequestV3​(com.yahoo.jrt.Request 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 interface JRTServerConfigRequest
        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 change
        configMd5 - The md5sum of the given payload.
      • 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 interface GetConfigRequest
        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 interface GetConfigRequest
        Returns:
        true if content should _not_ be cached, false if it should.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • 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 interface JRTConfigRequest
        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 interface JRTServerConfigRequest
        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 interface JRTConfigRequest
        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 interface JRTConfigRequest
        Returns:
        true if valid, 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 interface JRTServerConfigRequest
        Parameters:
        errorCode - error code, as described in ErrorCode.
        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
      • errorMessage

        public java.lang.String errorMessage()
        Description copied from interface: JRTConfigRequest
        Return the error message of this request, mostly corresponding to the ErrorCode.
        Specified by:
        errorMessage in interface JRTConfigRequest
        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 interface JRTConfigRequest
        Returns:
        a short description
      • getTimeout

        public long getTimeout()
        Description copied from interface: JRTConfigRequest
        Get the server timeout of this request.
        Specified by:
        getTimeout in interface JRTConfigRequest
        Returns:
        the timeout given to the server