diff --git a/example/protobuf/eigr/functions/spawn/example/messages/messages_pb2.py b/example/protobuf/eigr/functions/spawn/example/messages/messages_pb2.py new file mode 100644 index 0000000..785b569 --- /dev/null +++ b/example/protobuf/eigr/functions/spawn/example/messages/messages_pb2.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: example/protobuf/eigr/functions/spawn/example/messages/messages.proto +"""Generated protocol buffer code.""" +from google.protobuf.internal import builder as _builder +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import symbol_database as _symbol_database +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\nEexample/protobuf/eigr/functions/spawn/example/messages/messages.proto\x12%eigr.functions.spawn.example.messages\"\x1b\n\x07Request\x12\x10\n\x08language\x18\x01 \x01(\t\"\x19\n\x05Reply\x12\x10\n\x08response\x18\x01 \x01(\tB8\n%eigr.functions.spawn.example.messagesB\rMessagesProtoP\x01\x62\x06proto3') + +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'example.protobuf.eigr.functions.spawn.example.messages.messages_pb2', globals()) +if _descriptor._USE_C_DESCRIPTORS == False: + + DESCRIPTOR._options = None + DESCRIPTOR._serialized_options = b'\n%eigr.functions.spawn.example.messagesB\rMessagesProtoP\001' + _REQUEST._serialized_start=112 + _REQUEST._serialized_end=139 + _REPLY._serialized_start=141 + _REPLY._serialized_end=166 +# @@protoc_insertion_point(module_scope) diff --git a/example/protobuf/eigr/functions/spawn/example/messages/messages_pb2_grpc.py b/example/protobuf/eigr/functions/spawn/example/messages/messages_pb2_grpc.py new file mode 100644 index 0000000..2daafff --- /dev/null +++ b/example/protobuf/eigr/functions/spawn/example/messages/messages_pb2_grpc.py @@ -0,0 +1,4 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +"""Client and server classes corresponding to protobuf-defined services.""" +import grpc + diff --git a/example/protobuf/eigr/functions/spawn/example/state/joe_pb2.py b/example/protobuf/eigr/functions/spawn/example/state/joe_pb2.py new file mode 100644 index 0000000..df3d672 --- /dev/null +++ b/example/protobuf/eigr/functions/spawn/example/state/joe_pb2.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: example/protobuf/eigr/functions/spawn/example/state/joe.proto +"""Generated protocol buffer code.""" +from google.protobuf.internal import builder as _builder +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import symbol_database as _symbol_database +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n=example/protobuf/eigr/functions/spawn/example/state/joe.proto\x12\"eigr.functions.spawn.example.state\"\x1d\n\x08JoeState\x12\x11\n\tlanguages\x18\x01 \x03(\tB:\n\"eigr.functions.spawn.example.stateB\x12JoeStateStateProtoP\x01\x62\x06proto3') + +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'example.protobuf.eigr.functions.spawn.example.state.joe_pb2', globals()) +if _descriptor._USE_C_DESCRIPTORS == False: + + DESCRIPTOR._options = None + DESCRIPTOR._serialized_options = b'\n\"eigr.functions.spawn.example.stateB\022JoeStateStateProtoP\001' + _JOESTATE._serialized_start=101 + _JOESTATE._serialized_end=130 +# @@protoc_insertion_point(module_scope) diff --git a/example/protobuf/eigr/functions/spawn/example/state/joe_pb2_grpc.py b/example/protobuf/eigr/functions/spawn/example/state/joe_pb2_grpc.py new file mode 100644 index 0000000..2daafff --- /dev/null +++ b/example/protobuf/eigr/functions/spawn/example/state/joe_pb2_grpc.py @@ -0,0 +1,4 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +"""Client and server classes corresponding to protobuf-defined services.""" +import grpc + diff --git a/protobuf/eigr/functions/protocol/actors/actor_pb2.py b/protobuf/eigr/functions/protocol/actors/actor_pb2.py new file mode 100644 index 0000000..803a25a --- /dev/null +++ b/protobuf/eigr/functions/protocol/actors/actor_pb2.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: protobuf/eigr/functions/protocol/actors/actor.proto +"""Generated protocol buffer code.""" +from google.protobuf.internal import builder as _builder +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import symbol_database as _symbol_database +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + +from google.protobuf import any_pb2 as google_dot_protobuf_dot_any__pb2 + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n3protobuf/eigr/functions/protocol/actors/actor.proto\x12\x1e\x65igr.functions.protocol.actors\x1a\x19google/protobuf/any.proto\"\xa6\x01\n\x08Registry\x12\x44\n\x06\x61\x63tors\x18\x01 \x03(\x0b\x32\x34.eigr.functions.protocol.actors.Registry.ActorsEntry\x1aT\n\x0b\x41\x63torsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\x34\n\x05value\x18\x02 \x01(\x0b\x32%.eigr.functions.protocol.actors.Actor:\x02\x38\x01\"W\n\x0b\x41\x63torSystem\x12\x0c\n\x04name\x18\x01 \x01(\t\x12:\n\x08registry\x18\x02 \x01(\x0b\x32(.eigr.functions.protocol.actors.Registry\"g\n\x15\x41\x63torSnapshotStrategy\x12\x42\n\x07timeout\x18\x01 \x01(\x0b\x32/.eigr.functions.protocol.actors.TimeoutStrategyH\x00\x42\n\n\x08strategy\"i\n\x17\x41\x63torDeactivateStrategy\x12\x42\n\x07timeout\x18\x01 \x01(\x0b\x32/.eigr.functions.protocol.actors.TimeoutStrategyH\x00\x42\n\n\x08strategy\"\"\n\x0fTimeoutStrategy\x12\x0f\n\x07timeout\x18\x01 \x01(\x03\"\xa2\x01\n\nActorState\x12\x42\n\x04tags\x18\x01 \x03(\x0b\x32\x34.eigr.functions.protocol.actors.ActorState.TagsEntry\x12#\n\x05state\x18\x02 \x01(\x0b\x32\x14.google.protobuf.Any\x1a+\n\tTagsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\x8c\x02\n\x05\x41\x63tor\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x12\n\npersistent\x18\x02 \x01(\x08\x12\x39\n\x05state\x18\x03 \x01(\x0b\x32*.eigr.functions.protocol.actors.ActorState\x12P\n\x11snapshot_strategy\x18\x04 \x01(\x0b\x32\x35.eigr.functions.protocol.actors.ActorSnapshotStrategy\x12T\n\x13\x64\x65\x61\x63tivate_strategy\x18\x05 \x01(\x0b\x32\x37.eigr.functions.protocol.actors.ActorDeactivateStrategyBR\n!io.eigr.functions.protocol.actorsZ-github.com/eigr/go-support/eigr/actors;actorsb\x06proto3') + +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'protobuf.eigr.functions.protocol.actors.actor_pb2', globals()) +if _descriptor._USE_C_DESCRIPTORS == False: + + DESCRIPTOR._options = None + DESCRIPTOR._serialized_options = b'\n!io.eigr.functions.protocol.actorsZ-github.com/eigr/go-support/eigr/actors;actors' + _REGISTRY_ACTORSENTRY._options = None + _REGISTRY_ACTORSENTRY._serialized_options = b'8\001' + _ACTORSTATE_TAGSENTRY._options = None + _ACTORSTATE_TAGSENTRY._serialized_options = b'8\001' + _REGISTRY._serialized_start=115 + _REGISTRY._serialized_end=281 + _REGISTRY_ACTORSENTRY._serialized_start=197 + _REGISTRY_ACTORSENTRY._serialized_end=281 + _ACTORSYSTEM._serialized_start=283 + _ACTORSYSTEM._serialized_end=370 + _ACTORSNAPSHOTSTRATEGY._serialized_start=372 + _ACTORSNAPSHOTSTRATEGY._serialized_end=475 + _ACTORDEACTIVATESTRATEGY._serialized_start=477 + _ACTORDEACTIVATESTRATEGY._serialized_end=582 + _TIMEOUTSTRATEGY._serialized_start=584 + _TIMEOUTSTRATEGY._serialized_end=618 + _ACTORSTATE._serialized_start=621 + _ACTORSTATE._serialized_end=783 + _ACTORSTATE_TAGSENTRY._serialized_start=740 + _ACTORSTATE_TAGSENTRY._serialized_end=783 + _ACTOR._serialized_start=786 + _ACTOR._serialized_end=1054 +# @@protoc_insertion_point(module_scope) diff --git a/protobuf/eigr/functions/protocol/actors/actor_pb2_grpc.py b/protobuf/eigr/functions/protocol/actors/actor_pb2_grpc.py new file mode 100644 index 0000000..2daafff --- /dev/null +++ b/protobuf/eigr/functions/protocol/actors/actor_pb2_grpc.py @@ -0,0 +1,4 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +"""Client and server classes corresponding to protobuf-defined services.""" +import grpc + diff --git a/protobuf/eigr/functions/protocol/actors/protocol_pb2.py b/protobuf/eigr/functions/protocol/actors/protocol_pb2.py new file mode 100644 index 0000000..3960139 --- /dev/null +++ b/protobuf/eigr/functions/protocol/actors/protocol_pb2.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: protobuf/eigr/functions/protocol/actors/protocol.proto +"""Generated protocol buffer code.""" +from google.protobuf.internal import builder as _builder +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import symbol_database as _symbol_database +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + +from eigr.functions.protocol.actors import actor_pb2 as eigr_dot_functions_dot_protocol_dot_actors_dot_actor__pb2 +from google.protobuf import any_pb2 as google_dot_protobuf_dot_any__pb2 + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n6protobuf/eigr/functions/protocol/actors/protocol.proto\x12\x17\x65igr.functions.protocol\x1a*eigr/functions/protocol/actors/actor.proto\x1a\x19google/protobuf/any.proto\"\x94\x01\n\x13RegistrationRequest\x12:\n\x0cservice_info\x18\x01 \x01(\x0b\x32$.eigr.functions.protocol.ServiceInfo\x12\x41\n\x0c\x61\x63tor_system\x18\x02 \x01(\x0b\x32+.eigr.functions.protocol.actors.ActorSystem\"\xd4\x01\n\x0bServiceInfo\x12\x14\n\x0cservice_name\x18\x01 \x01(\t\x12\x17\n\x0fservice_version\x18\x02 \x01(\t\x12\x17\n\x0fservice_runtime\x18\x03 \x01(\t\x12\x1c\n\x14support_library_name\x18\x04 \x01(\t\x12\x1f\n\x17support_library_version\x18\x05 \x01(\t\x12\x1e\n\x16protocol_major_version\x18\x06 \x01(\x05\x12\x1e\n\x16protocol_minor_version\x18\x07 \x01(\x05\"v\n\tProxyInfo\x12\x1e\n\x16protocol_major_version\x18\x01 \x01(\x05\x12\x1e\n\x16protocol_minor_version\x18\x02 \x01(\x05\x12\x12\n\nproxy_name\x18\x03 \x01(\t\x12\x15\n\rproxy_version\x18\x04 \x01(\t\"\x86\x01\n\x14RegistrationResponse\x12\x36\n\x06status\x18\x01 \x01(\x0b\x32&.eigr.functions.protocol.RequestStatus\x12\x36\n\nproxy_info\x18\x02 \x01(\x0b\x32\".eigr.functions.protocol.ProxyInfo\".\n\x07\x43ontext\x12#\n\x05state\x18\x01 \x01(\x0b\x32\x14.google.protobuf.Any\"\xd0\x01\n\x11InvocationRequest\x12;\n\x06system\x18\x01 \x01(\x0b\x32+.eigr.functions.protocol.actors.ActorSystem\x12\x34\n\x05\x61\x63tor\x18\x02 \x01(\x0b\x32%.eigr.functions.protocol.actors.Actor\x12\x14\n\x0c\x63ommand_name\x18\x03 \x01(\t\x12#\n\x05value\x18\x04 \x01(\x0b\x32\x14.google.protobuf.Any\x12\r\n\x05\x61sync\x18\x05 \x01(\x08\"\xb1\x01\n\x0f\x41\x63torInvocation\x12\x12\n\nactor_name\x18\x01 \x01(\t\x12\x14\n\x0c\x61\x63tor_system\x18\x02 \x01(\t\x12\x14\n\x0c\x63ommand_name\x18\x03 \x01(\t\x12\x39\n\x0f\x63urrent_context\x18\x04 \x01(\x0b\x32 .eigr.functions.protocol.Context\x12#\n\x05value\x18\x05 \x01(\x0b\x32\x14.google.protobuf.Any\"\xa3\x01\n\x17\x41\x63torInvocationResponse\x12\x12\n\nactor_name\x18\x01 \x01(\t\x12\x14\n\x0c\x61\x63tor_system\x18\x02 \x01(\t\x12\x39\n\x0fupdated_context\x18\x03 \x01(\x0b\x32 .eigr.functions.protocol.Context\x12#\n\x05value\x18\x04 \x01(\x0b\x32\x14.google.protobuf.Any\"\xe4\x01\n\x12InvocationResponse\x12\x36\n\x06status\x18\x01 \x01(\x0b\x32&.eigr.functions.protocol.RequestStatus\x12;\n\x06system\x18\x02 \x01(\x0b\x32+.eigr.functions.protocol.actors.ActorSystem\x12\x34\n\x05\x61\x63tor\x18\x03 \x01(\x0b\x32%.eigr.functions.protocol.actors.Actor\x12#\n\x05value\x18\x04 \x01(\x0b\x32\x14.google.protobuf.Any\"Q\n\rRequestStatus\x12/\n\x06status\x18\x01 \x01(\x0e\x32\x1f.eigr.functions.protocol.Status\x12\x0f\n\x07message\x18\x02 \x01(\t*=\n\x06Status\x12\x0b\n\x07UNKNOWN\x10\x00\x12\x06\n\x02OK\x10\x01\x12\x13\n\x0f\x41\x43TOR_NOT_FOUND\x10\x02\x12\t\n\x05\x45RROR\x10\x03\x42O\n\x1aio.eigr.functions.protocolZ1github.com/eigr/go-support/eigr/protocol;protocolb\x06proto3') + +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'protobuf.eigr.functions.protocol.actors.protocol_pb2', globals()) +if _descriptor._USE_C_DESCRIPTORS == False: + + DESCRIPTOR._options = None + DESCRIPTOR._serialized_options = b'\n\032io.eigr.functions.protocolZ1github.com/eigr/go-support/eigr/protocol;protocol' + _STATUS._serialized_start=1696 + _STATUS._serialized_end=1757 + _REGISTRATIONREQUEST._serialized_start=155 + _REGISTRATIONREQUEST._serialized_end=303 + _SERVICEINFO._serialized_start=306 + _SERVICEINFO._serialized_end=518 + _PROXYINFO._serialized_start=520 + _PROXYINFO._serialized_end=638 + _REGISTRATIONRESPONSE._serialized_start=641 + _REGISTRATIONRESPONSE._serialized_end=775 + _CONTEXT._serialized_start=777 + _CONTEXT._serialized_end=823 + _INVOCATIONREQUEST._serialized_start=826 + _INVOCATIONREQUEST._serialized_end=1034 + _ACTORINVOCATION._serialized_start=1037 + _ACTORINVOCATION._serialized_end=1214 + _ACTORINVOCATIONRESPONSE._serialized_start=1217 + _ACTORINVOCATIONRESPONSE._serialized_end=1380 + _INVOCATIONRESPONSE._serialized_start=1383 + _INVOCATIONRESPONSE._serialized_end=1611 + _REQUESTSTATUS._serialized_start=1613 + _REQUESTSTATUS._serialized_end=1694 +# @@protoc_insertion_point(module_scope) diff --git a/protobuf/eigr/functions/protocol/actors/protocol_pb2_grpc.py b/protobuf/eigr/functions/protocol/actors/protocol_pb2_grpc.py new file mode 100644 index 0000000..2daafff --- /dev/null +++ b/protobuf/eigr/functions/protocol/actors/protocol_pb2_grpc.py @@ -0,0 +1,4 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +"""Client and server classes corresponding to protobuf-defined services.""" +import grpc + diff --git a/protobuf/google/protobuf/any_pb2.py b/protobuf/google/protobuf/any_pb2.py new file mode 100644 index 0000000..5e11df7 --- /dev/null +++ b/protobuf/google/protobuf/any_pb2.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: protobuf/google/protobuf/any.proto +"""Generated protocol buffer code.""" +from google.protobuf.internal import builder as _builder +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import symbol_database as _symbol_database +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\"protobuf/google/protobuf/any.proto\x12\x0fgoogle.protobuf\"&\n\x03\x41ny\x12\x10\n\x08type_url\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\x0c\x42v\n\x13\x63om.google.protobufB\x08\x41nyProtoP\x01Z,google.golang.org/protobuf/types/known/anypb\xa2\x02\x03GPB\xaa\x02\x1eGoogle.Protobuf.WellKnownTypesb\x06proto3') + +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'protobuf.google.protobuf.any_pb2', globals()) +if _descriptor._USE_C_DESCRIPTORS == False: + + DESCRIPTOR._options = None + DESCRIPTOR._serialized_options = b'\n\023com.google.protobufB\010AnyProtoP\001Z,google.golang.org/protobuf/types/known/anypb\242\002\003GPB\252\002\036Google.Protobuf.WellKnownTypes' + _ANY._serialized_start=55 + _ANY._serialized_end=93 +# @@protoc_insertion_point(module_scope) diff --git a/protobuf/google/protobuf/any_pb2_grpc.py b/protobuf/google/protobuf/any_pb2_grpc.py new file mode 100644 index 0000000..2daafff --- /dev/null +++ b/protobuf/google/protobuf/any_pb2_grpc.py @@ -0,0 +1,4 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +"""Client and server classes corresponding to protobuf-defined services.""" +import grpc + diff --git a/spawn/sdk.py b/spawn/sdk.py index 90aeaf9..57afc70 100644 --- a/spawn/sdk.py +++ b/spawn/sdk.py @@ -6,7 +6,7 @@ from dataclasses import dataclass, field -from handler import action_handler +from spawn.handler import action_handler from internal.controller import SpawnActorController as ActorController from typing import List, Callable, Any, Mapping, MutableMapping @@ -32,8 +32,7 @@ def init(self) -> ActorParams: @dataclass class ActorEntity: init_state: Callable[[str], Any] - command_handlers: MutableMapping[str, - Callable] = field(default_factory=dict) + command_handlers: MutableMapping[str, Callable] = field(default_factory=dict) def command(self, name: str): def register_command_handler(function): @@ -41,12 +40,16 @@ def register_command_handler(function): Register the function to handle commands """ if name in self.command_handlers: - raise Exception("Command handler function {} already defined for command {}".format( - self.command_handlers[name], name)) + raise Exception( + "Command handler function {} already defined for command {}".format( + self.command_handlers[name], name + ) + ) if function.__code__.co_argcount > 2: raise Exception( - "At most two parameters, the command and the context, should be accepted by the command function") + "At most two parameters, the command and the context, should be accepted by the command function" + ) self.command_handlers[name] = function return function @@ -65,16 +68,18 @@ def init_actor(self): @dataclass class Spawn: actorController = ActorController( - os.environ.get('PROXY_HOST', 'localhost'), - os.environ.get('PROXY_PORT', '9001'), + os.environ.get("PROXY_HOST", "localhost"), + os.environ.get("PROXY_PORT", "9001"), ) logging.basicConfig( - format='%(asctime)s - %(filename)s - %(levelname)s: %(message)s', level=logging.INFO) + format="%(asctime)s - %(filename)s - %(levelname)s: %(message)s", + level=logging.INFO, + ) logging.root.setLevel(logging.NOTSET) - __host = '127.0.0.1' - __port = '8090' + __host = "127.0.0.1" + __port = "8090" __actors: List[ActorEntity] = field(default_factory=list) def host(self, address: str): @@ -94,20 +99,20 @@ def register_actor(self, entity: ActorEntity): def start(self): """Start the user function and HTTP Server.""" - address = '{}:{}'.format(os.environ.get( - 'HOST', self.__host), os.environ.get('PORT', self.__port)) + address = "{}:{}".format( + os.environ.get("HOST", self.__host), os.environ.get("PORT", self.__port) + ) - logging.info('Starting Spawn on address %s', address) + logging.info("Starting Spawn on address %s", address) try: app = Flask(__name__) app.register_blueprint(action_handler) - app.run(host=self.__host, port=self.__port, - threaded=True, debug=True) + app.run(host=self.__host, port=self.__port, threaded=True, debug=True) # Invoke proxy for register ActorsEntity using Spawn protobuf types self.__register(self.__actors) except IOError as e: - logging.error('Error on start Spawn %s', e.__cause__) + logging.error("Error on start Spawn %s", e.__cause__) def __register(self, actors: List[ActorEntity]): self.actorController.register(actors)