Browse Source

DeliveryService测试

世祺 1 year ago
parent
commit
01e6c27037
8 changed files with 274 additions and 59 deletions
  1. 1 1
      proto
  2. 11 0
      src/gencode.py
  3. 37 0
      src/llnw_pb2.py
  4. 70 0
      src/llnw_pb2.pyi
  5. 66 0
      src/llnw_pb2_grpc.py
  6. 43 0
      src/main.py
  7. 14 5
      src/test.py
  8. 32 53
      测试.ipynb

+ 1 - 1
proto

@@ -1 +1 @@
-Subproject commit ce4ce8577ab5a94483758772c79cf112864265de
+Subproject commit a2247ceedd33eb1a301c4761303c98315de3ecb3

+ 11 - 0
src/gencode.py

@@ -0,0 +1,11 @@
+from grpc_tools import protoc
+
+if __name__ == '__main__':
+    protoc.main((
+        '',
+        '-I../proto',
+        '--python_out=.',
+        '--pyi_out=.',
+        '--grpc_python_out=.',
+        '../proto/*.proto',
+    ))

File diff suppressed because it is too large
+ 37 - 0
src/llnw_pb2.py


+ 70 - 0
src/llnw_pb2.pyi

@@ -0,0 +1,70 @@
+from google.protobuf.internal import containers as _containers
+from google.protobuf import descriptor as _descriptor
+from google.protobuf import message as _message
+from typing import ClassVar as _ClassVar, Iterable as _Iterable, Mapping as _Mapping, Optional as _Optional, Union as _Union
+
+DESCRIPTOR: _descriptor.FileDescriptor
+
+class Base(_message.Message):
+    __slots__ = ["key", "username"]
+    KEY_FIELD_NUMBER: _ClassVar[int]
+    USERNAME_FIELD_NUMBER: _ClassVar[int]
+    key: str
+    username: str
+    def __init__(self, username: _Optional[str] = ..., key: _Optional[str] = ...) -> None: ...
+
+class DeliveryEntity(_message.Message):
+    __slots__ = ["isEnabled", "protocolSets", "publishedHostname", "publishedUrlPath", "shortname", "sourceHostname", "sourceUrlPath", "status", "uuid"]
+    ISENABLED_FIELD_NUMBER: _ClassVar[int]
+    PROTOCOLSETS_FIELD_NUMBER: _ClassVar[int]
+    PUBLISHEDHOSTNAME_FIELD_NUMBER: _ClassVar[int]
+    PUBLISHEDURLPATH_FIELD_NUMBER: _ClassVar[int]
+    SHORTNAME_FIELD_NUMBER: _ClassVar[int]
+    SOURCEHOSTNAME_FIELD_NUMBER: _ClassVar[int]
+    SOURCEURLPATH_FIELD_NUMBER: _ClassVar[int]
+    STATUS_FIELD_NUMBER: _ClassVar[int]
+    UUID_FIELD_NUMBER: _ClassVar[int]
+    isEnabled: bool
+    protocolSets: _containers.RepeatedCompositeFieldContainer[ProtocolSet]
+    publishedHostname: str
+    publishedUrlPath: str
+    shortname: str
+    sourceHostname: str
+    sourceUrlPath: str
+    status: str
+    uuid: str
+    def __init__(self, uuid: _Optional[str] = ..., isEnabled: bool = ..., shortname: _Optional[str] = ..., status: _Optional[str] = ..., sourceHostname: _Optional[str] = ..., publishedHostname: _Optional[str] = ..., sourceUrlPath: _Optional[str] = ..., publishedUrlPath: _Optional[str] = ..., protocolSets: _Optional[_Iterable[_Union[ProtocolSet, _Mapping]]] = ...) -> None: ...
+
+class DeliveryList(_message.Message):
+    __slots__ = ["deliveries"]
+    DELIVERIES_FIELD_NUMBER: _ClassVar[int]
+    deliveries: _containers.RepeatedCompositeFieldContainer[DeliveryEntity]
+    def __init__(self, deliveries: _Optional[_Iterable[_Union[DeliveryEntity, _Mapping]]] = ...) -> None: ...
+
+class ProtocolSet(_message.Message):
+    __slots__ = ["options", "publishedProtocol", "sourceProtocol"]
+    OPTIONS_FIELD_NUMBER: _ClassVar[int]
+    PUBLISHEDPROTOCOL_FIELD_NUMBER: _ClassVar[int]
+    SOURCEPROTOCOL_FIELD_NUMBER: _ClassVar[int]
+    options: _containers.RepeatedCompositeFieldContainer[ProtocolSetOptions]
+    publishedProtocol: str
+    sourceProtocol: str
+    def __init__(self, sourceProtocol: _Optional[str] = ..., publishedProtocol: _Optional[str] = ..., options: _Optional[_Iterable[_Union[ProtocolSetOptions, _Mapping]]] = ...) -> None: ...
+
+class ProtocolSetOptions(_message.Message):
+    __slots__ = ["name", "parameters", "source"]
+    NAME_FIELD_NUMBER: _ClassVar[int]
+    PARAMETERS_FIELD_NUMBER: _ClassVar[int]
+    SOURCE_FIELD_NUMBER: _ClassVar[int]
+    name: str
+    parameters: _containers.RepeatedScalarFieldContainer[str]
+    source: str
+    def __init__(self, name: _Optional[str] = ..., parameters: _Optional[_Iterable[str]] = ..., source: _Optional[str] = ...) -> None: ...
+
+class ShortName(_message.Message):
+    __slots__ = ["base", "shortName"]
+    BASE_FIELD_NUMBER: _ClassVar[int]
+    SHORTNAME_FIELD_NUMBER: _ClassVar[int]
+    base: Base
+    shortName: str
+    def __init__(self, base: _Optional[_Union[Base, _Mapping]] = ..., shortName: _Optional[str] = ...) -> None: ...

+ 66 - 0
src/llnw_pb2_grpc.py

@@ -0,0 +1,66 @@
+# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
+"""Client and server classes corresponding to protobuf-defined services."""
+import grpc
+
+import llnw_pb2 as llnw__pb2
+
+
+class DeliveryServiceStub(object):
+    """Missing associated documentation comment in .proto file."""
+
+    def __init__(self, channel):
+        """Constructor.
+
+        Args:
+            channel: A grpc.Channel.
+        """
+        self.ListDeliveryServiceInstances = channel.unary_unary(
+                '/llnwApi.Delivery.DeliveryService/ListDeliveryServiceInstances',
+                request_serializer=llnw__pb2.ShortName.SerializeToString,
+                response_deserializer=llnw__pb2.DeliveryList.FromString,
+                )
+
+
+class DeliveryServiceServicer(object):
+    """Missing associated documentation comment in .proto file."""
+
+    def ListDeliveryServiceInstances(self, request, context):
+        """Missing associated documentation comment in .proto file."""
+        context.set_code(grpc.StatusCode.UNIMPLEMENTED)
+        context.set_details('Method not implemented!')
+        raise NotImplementedError('Method not implemented!')
+
+
+def add_DeliveryServiceServicer_to_server(servicer, server):
+    rpc_method_handlers = {
+            'ListDeliveryServiceInstances': grpc.unary_unary_rpc_method_handler(
+                    servicer.ListDeliveryServiceInstances,
+                    request_deserializer=llnw__pb2.ShortName.FromString,
+                    response_serializer=llnw__pb2.DeliveryList.SerializeToString,
+            ),
+    }
+    generic_handler = grpc.method_handlers_generic_handler(
+            'llnwApi.Delivery.DeliveryService', rpc_method_handlers)
+    server.add_generic_rpc_handlers((generic_handler,))
+
+
+ # This class is part of an EXPERIMENTAL API.
+class DeliveryService(object):
+    """Missing associated documentation comment in .proto file."""
+
+    @staticmethod
+    def ListDeliveryServiceInstances(request,
+            target,
+            options=(),
+            channel_credentials=None,
+            call_credentials=None,
+            insecure=False,
+            compression=None,
+            wait_for_ready=None,
+            timeout=None,
+            metadata=None):
+        return grpc.experimental.unary_unary(request, target, '/llnwApi.Delivery.DeliveryService/ListDeliveryServiceInstances',
+            llnw__pb2.ShortName.SerializeToString,
+            llnw__pb2.DeliveryList.FromString,
+            options, channel_credentials,
+            insecure, call_credentials, compression, wait_for_ready, timeout, metadata)

+ 43 - 0
src/main.py

@@ -0,0 +1,43 @@
+from concurrent import futures
+
+import grpc
+
+from ll_sdk.config_api import ConfigApiClient
+import llnw_pb2_grpc
+from llnw_pb2 import *
+
+
+def getCl(base):
+    return ConfigApiClient('apis.llnw.com', base.username, base.key)
+
+
+class DeliveryServiceServicer(llnw_pb2_grpc.DeliveryServiceServicer):
+
+    def ListDeliveryServiceInstances(self, request, context):
+        return DeliveryList(deliveries=[DeliveryEntity(
+            uuid=results['uuid'],
+            isEnabled=results['isEnabled'],
+            shortname=results['shortname'],
+            status=results['status']['state'],
+            sourceHostname=results['body']['sourceHostname'],
+            publishedHostname=results['body']['publishedHostname'],
+            sourceUrlPath=results['body']['sourceUrlPath'],
+            publishedUrlPath=results['body']['publishedUrlPath'],
+            protocolSets=[ProtocolSet(
+                sourceProtocol=protocolSets['sourceProtocol'],
+                publishedProtocol=protocolSets['publishedProtocol'],
+                options=[ProtocolSetOptions(
+                    name=options['name'],
+                    parameters=options['parameters'],
+                    source=options['source'],
+                ) for options in protocolSets['options']]
+            ) for protocolSets in results['body']['protocolSets']]
+        ) for results in getCl(request.base).list_delivery_service_instances(request.shortName).json()['results']])
+
+
+if __name__ == '__main__':
+    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
+    llnw_pb2_grpc.add_DeliveryServiceServicer_to_server(DeliveryServiceServicer(), server)
+    server.add_insecure_port('[::]:50052')
+    server.start()
+    server.wait_for_termination()

+ 14 - 5
src/test.py

@@ -1,12 +1,21 @@
 from ll_sdk.config_api import ConfigApiClient
+import grpc
+import llnw_pb2_grpc
+from llnw_pb2 import Base, ShortName
 
+username = "chl20000826@163.com"
+shared_key = "0f4912881c27a33dcfcf2ab6e2dc286c065a559000926bc9d1fc25d4228bb5cd"
+short_name = "centtest"
 if __name__ == '__main__':
-    username = "chl20000826@163.com"
-    shared_key = "0f4912881c27a33dcfcf2ab6e2dc286c065a559000926bc9d1fc25d4228bb5cd"
+    channel = grpc.insecure_channel('localhost:50052')
+    stub = llnw_pb2_grpc.DeliveryServiceStub(channel)
+    e = stub.ListDeliveryServiceInstances(ShortName(base=Base(username=username, key=shared_key), shortName=short_name))
+    print(str(e))
 
-    cl = ConfigApiClient('apis.llnw.com', username, shared_key)
-    res = cl.list_delivery_service_instances("centtest")
-    print(res.json())
+    #
+    # cl = ConfigApiClient('apis.llnw.com', username, shared_key)
+    # res = cl.list_delivery_service_instances("centtest")
+    # print(res.json())
     # print(cl.get_status().json())
     # print(cl.get_health_check().json())
     # exit(0)

File diff suppressed because it is too large
+ 32 - 53
测试.ipynb