[Notes] [Git][BuildGrid/buildgrid][mablanch/161-advertise-REAPI-version] 3 commits: capabilities/service.py: Log debug message on request



Title: GitLab

Martin Blanchard pushed to branch mablanch/161-advertise-REAPI-version at BuildGrid / buildgrid

Commits:

3 changed files:

Changes:

  • buildgrid/server/capabilities/instance.py
    ... ... @@ -16,6 +16,8 @@
    16 16
     import logging
    
    17 17
     
    
    18 18
     from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2
    
    19
    +from buildgrid._protos.build.bazel.semver import semver_pb2
    
    20
    +from buildgrid.settings import HIGH_REAPI_VERSION, LOW_REAPI_VERSION
    
    19 21
     
    
    20 22
     
    
    21 23
     class CapabilitiesInstance:
    
    ... ... @@ -29,6 +31,9 @@ class CapabilitiesInstance:
    29 31
             self.__action_cache_instance = action_cache_instance
    
    30 32
             self.__execution_instance = execution_instance
    
    31 33
     
    
    34
    +        self.__high_api_version = None
    
    35
    +        self.__low_api_version = None
    
    36
    +
    
    32 37
         # --- Public API ---
    
    33 38
     
    
    34 39
         @property
    
    ... ... @@ -55,15 +60,20 @@ class CapabilitiesInstance:
    55 60
             self.__execution_instance = execution_instance
    
    56 61
     
    
    57 62
         def get_capabilities(self):
    
    63
    +        cache_capabilities = self._get_cache_capabilities()
    
    64
    +        execution_capabilities = self._get_capabilities_execution()
    
    65
    +
    
    66
    +        if self.__high_api_version is None:
    
    67
    +            self.__high_api_version = self._split_semantic_version(HIGH_REAPI_VERSION)
    
    68
    +        if self.__low_api_version is None:
    
    69
    +            self.__low_api_version = self._split_semantic_version(LOW_REAPI_VERSION)
    
    70
    +
    
    58 71
             server_capabilities = remote_execution_pb2.ServerCapabilities()
    
    59
    -        server_capabilities.cache_capabilities.CopyFrom(self._get_cache_capabilities())
    
    60
    -        server_capabilities.execution_capabilities.CopyFrom(self._get_capabilities_execution())
    
    61
    -        # TODO
    
    62
    -        # When API is stable, fill out SemVer values
    
    63
    -        # server_capabilities.deprecated_api_version =
    
    64
    -        # server_capabilities.low_api_version =
    
    65
    -        # server_capabilities.low_api_version =
    
    66
    -        # server_capabilities.hig_api_version =
    
    72
    +        server_capabilities.cache_capabilities.CopyFrom(cache_capabilities)
    
    73
    +        server_capabilities.execution_capabilities.CopyFrom(execution_capabilities)
    
    74
    +        server_capabilities.low_api_version.CopyFrom(self.__low_api_version)
    
    75
    +        server_capabilities.high_api_version.CopyFrom(self.__high_api_version)
    
    76
    +
    
    67 77
             return server_capabilities
    
    68 78
     
    
    69 79
         # --- Private API ---
    
    ... ... @@ -97,3 +107,13 @@ class CapabilitiesInstance:
    97 107
                 capabilities.exec_enabled = False
    
    98 108
     
    
    99 109
             return capabilities
    
    110
    +
    
    111
    +    def _split_semantic_version(self, version_string):
    
    112
    +        major_version, minor_version, patch_version = version_string.split('.')
    
    113
    +
    
    114
    +        semantic_version = semver_pb2.SemVer()
    
    115
    +        semantic_version.major = major_version
    
    116
    +        semantic_version.minor = minor_version
    
    117
    +        semantic_version.patch = patch_version
    
    118
    +
    
    119
    +        return semantic_version

  • buildgrid/server/capabilities/service.py
    ... ... @@ -49,8 +49,17 @@ class CapabilitiesService(remote_execution_pb2_grpc.CapabilitiesServicer):
    49 49
     
    
    50 50
         @authorize(AuthContext)
    
    51 51
         def GetCapabilities(self, request, context):
    
    52
    +        """Handles GetCapabilitiesRequest messages.
    
    53
    +
    
    54
    +        Args:
    
    55
    +            request (GetCapabilitiesRequest): The incoming RPC request.
    
    56
    +            context (grpc.ServicerContext): Context for the RPC call.
    
    57
    +        """
    
    58
    +        self.__logger.debug("GetCapabilities request from [%s]", context.peer())
    
    59
    +
    
    52 60
             try:
    
    53 61
                 instance = self._get_instance(request.instance_name)
    
    62
    +
    
    54 63
                 return instance.get_capabilities()
    
    55 64
     
    
    56 65
             except InvalidArgumentError as e:
    

  • buildgrid/settings.py
    ... ... @@ -16,6 +16,12 @@
    16 16
     import hashlib
    
    17 17
     
    
    18 18
     
    
    19
    +# Latest REAPI version supported:
    
    20
    +HIGH_REAPI_VERSION = '2.0.0'
    
    21
    +
    
    22
    +# Earliest non-deprecated REAPI version supported:
    
    23
    +LOW_REAPI_VERSION = '2.0.0'
    
    24
    +
    
    19 25
     # Hash function used for computing digests:
    
    20 26
     HASH = hashlib.sha256
    
    21 27
     
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]