コード例 #1
0
ファイル: xos_dynamicload_api.py プロジェクト: ican2002/xos
    def UnloadModels(self, request, context):
        try:
            builder = DynamicBuilder()
            result = builder.handle_unloadmodels_request(request)

            if (result == builder.SOMETHING_CHANGED):
                self.server.delayed_shutdown(5)

            response = dynamicload_pb2.LoadModelsReply()
            response.status = response.SUCCESS

            return response
        except Exception, e:
            import traceback; traceback.print_exc()
            raise e
コード例 #2
0
    def UnloadModels(self, request, context):
        try:
            builder = DynamicBuilder()
            result = builder.handle_unloadmodels_request(
                request,
                self.django_app_models.get("services." + request.name, {}))

            if result == builder.SUCCESS:
                self.server.delayed_shutdown(5)

            self.map_error_code(result, context)

            response = dynamicload_pb2.LoadModelsReply()
            response.status = result
            REQUEST_COUNT.labels("xos-core", "DynamicLoad", "UnloadModels",
                                 grpc.StatusCode.OK).inc()
            return response
        except Exception as e:
            import traceback

            traceback.print_exc()
            REQUEST_COUNT.labels("xos-core", "DynamicLoad", "UnloadModels",
                                 grpc.StatusCode.INTERNAL).inc()
            raise e
コード例 #3
0
    def LoadModels(self, request, context):
        try:
            core_version = self.get_core_version()
            requested_core_version = request.core_version
            log.info("Loading service models",
                     service=request.name,
                     service_version=request.version,
                     requested_core_version=requested_core_version)

            if not requested_core_version:
                requested_core_version = ">=2.2.1"

            if "~" in requested_core_version:
                [min_requested,
                 max_requested] = requested_core_version.split("~")

                match_min_version = semver.match(core_version,
                                                 min_requested.strip())
                match_max_version = semver.match(core_version,
                                                 max_requested.strip())

                if not match_min_version or not match_max_version:
                    log.error(
                        "Not loading service because of mismatching versions",
                        service=request.name,
                        core_version=core_version,
                        requested_min_core_version=min_requested,
                        requested_max_core_version=max_requested)
                    context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
                    msg = "Service %s is requesting core version between %s and %s but actual version is %s" % (
                        request.name, min_requested, max_requested,
                        core_version)
                    context.set_details(msg)
                    raise Exception(msg)

            else:
                match_version = semver.match(core_version,
                                             requested_core_version.strip())
                if not match_version:
                    log.error(
                        "Not loading service because of mismatching versions",
                        service=request.name,
                        core_version=core_version,
                        requested_core_version=requested_core_version)
                    context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
                    msg = "Service %s is requesting core version %s but actual version is %s" % (
                        request.name, requested_core_version, core_version)
                    context.set_details(msg)
                    raise Exception(msg)

            builder = DynamicBuilder()
            result = builder.handle_loadmodels_request(request)

            if result == builder.SUCCESS:
                self.server.delayed_shutdown(5)

            response = dynamicload_pb2.LoadModelsReply()
            response.status = result
            REQUEST_COUNT.labels("xos-core", "DynamicLoad", "LoadModels",
                                 grpc.StatusCode.OK).inc()
            return response
        except Exception as e:
            import traceback

            traceback.print_exc()
            REQUEST_COUNT.labels("xos-core", "DynamicLoad", "LoadModels",
                                 grpc.StatusCode.INTERNAL).inc()
            raise e