Esempio n. 1
0
    def __init__(self,
                 logger,
                 handler,
                 socket_path,
                 platform_kind,
                 namespace=None,
                 worker_id=None,
                 trigger_kind=None,
                 trigger_name=None,
                 decode_event_strings=True):
        self._logger = logger
        self._socket_path = socket_path
        self._json_encoder = nuclio_sdk.json_encoder.Encoder()
        self._entrypoint = None
        self._processor_sock = None
        self._platform = nuclio_sdk.Platform(platform_kind,
                                             namespace=namespace)
        self._decode_event_strings = decode_event_strings

        # 1gb
        self._max_buffer_size = 1024 * 1024 * 1024

        # holds the function that will be called
        self._entrypoint = self._load_entrypoint_from_handler(handler)

        # connect to processor
        self._processor_sock = self._connect_to_processor()

        # make a writeable file from processor
        self._processor_sock_wfile = self._processor_sock.makefile('w')

        # create msgpack unpacker
        self._unpacker = self._resolve_unpacker()

        # event deserializer kind (e.g.: msgpack_raw / json)
        self._event_deserializer_kind = self._resolve_event_deserializer_kind()

        # get handler module
        entrypoint_module = sys.modules[self._entrypoint.__module__]

        # create a context with logger and platform
        self._context = nuclio_sdk.Context(
            self._logger, self._platform, worker_id,
            nuclio_sdk.TriggerInfo(trigger_kind, trigger_name))

        # replace the default output with the process socket
        self._logger.set_handler('default', self._processor_sock_wfile,
                                 nuclio_sdk.logger.JSONFormatter())

        # call init context
        if hasattr(entrypoint_module, 'init_context'):
            try:
                getattr(entrypoint_module, 'init_context')(self._context)
            except:
                self._logger.error(
                    'Exception raised while running init_context')
                raise

        # indicate that we're ready
        self._write_packet_to_processor('s')
Esempio n. 2
0
    def __init__(self,
                 logger,
                 handler,
                 socket_path,
                 platform_kind,
                 namespace=None,
                 worker_id=None,
                 trigger_kind=None,
                 trigger_name=None):
        self._logger = logger
        self._socket_path = socket_path
        self._json_encoder = nuclio_sdk.json_encoder.Encoder()
        self._entrypoint = None
        self._processor_sock = None
        self._platform = nuclio_sdk.Platform(platform_kind,
                                             namespace=namespace)

        # holds the function that will be called
        self._entrypoint = self._load_entrypoint_from_handler(handler)

        # connect to processor
        self._processor_sock = self._connect_to_processor()

        # make a writeable file from processor
        self._processor_sock_wfile = self._processor_sock.makefile('w')

        # create msgpack unpacker
        self._unpacker = self._resolve_unpacker()

        # get handler module
        entrypoint_module = sys.modules[self._entrypoint.__module__]

        # create a context with logger and platform
        self._context = nuclio_sdk.Context(
            self._logger, self._platform, worker_id,
            nuclio_sdk.TriggerInfo(trigger_kind, trigger_name))

        # call init context
        if hasattr(entrypoint_module, 'init_context'):
            try:
                getattr(entrypoint_module, 'init_context')(self._context)
            except:
                self._logger.error(
                    'Exception raised while running init_context')
                raise

        # replace the default output with the process socket
        self._logger.set_handler('default', self._processor_sock_wfile,
                                 nuclio_sdk.logger.JSONFormatter())

        # indicate that we're ready
        self._write_packet_to_processor('s')

        # log deprecation warning
        if nuclio_sdk.helpers.PYTHON2:
            self._logger.warn(
                'Python 2.7 runtime is deprecated. '
                'Nuclio will drop support for Python 2.7 runtime as of version 1.6.0. '
                'Please migrate your code to Python 3.6')
Esempio n. 3
0
    def __init__(self,
                 logger,
                 loop,
                 handler,
                 socket_path,
                 platform_kind,
                 namespace=None,
                 worker_id=None,
                 trigger_kind=None,
                 trigger_name=None,
                 decode_event_strings=True):
        self._logger = logger
        self._socket_path = socket_path
        self._json_encoder = nuclio_sdk.json_encoder.Encoder()
        self._entrypoint = None
        self._processor_sock = None
        self._platform = nuclio_sdk.Platform(platform_kind,
                                             namespace=namespace)
        self._decode_event_strings = decode_event_strings

        # 1gb
        self._max_buffer_size = 1024 * 1024 * 1024

        # holds the function that will be called
        self._entrypoint = self._load_entrypoint_from_handler(handler)

        self._is_entrypoint_coroutine = asyncio.iscoroutinefunction(
            self._entrypoint)

        # connect to processor
        self._processor_sock = self._connect_to_processor()

        # make a writeable file from processor
        self._processor_sock_wfile = self._processor_sock.makefile('w')

        # create msgpack unpacker
        self._unpacker = self._resolve_unpacker()

        # set event loop
        self._loop = loop

        # event deserializer kind (e.g.: msgpack_raw / json)
        self._event_deserializer_kind = self._resolve_event_deserializer_kind()

        # get handler module
        self._entrypoint_module = sys.modules[self._entrypoint.__module__]

        # create a context with logger and platform
        self._context = nuclio_sdk.Context(
            self._logger, self._platform, worker_id,
            nuclio_sdk.TriggerInfo(trigger_kind, trigger_name))

        # replace the default output with the process socket
        self._logger.set_handler('default', self._processor_sock_wfile,
                                 JSONFormatterOverSocket())
Esempio n. 4
0
    def __init__(self,
                 logger,
                 handler,
                 socket_path,
                 platform_kind,
                 namespace=None,
                 worker_id=None,
                 trigger_kind=None,
                 trigger_name=None):
        self._logger = logger
        self._socket_path = socket_path
        self._json_encoder = nuclio_sdk.json_encoder.Encoder()
        self._entrypoint = None
        self._processor_sock = None
        self._platform = nuclio_sdk.Platform(platform_kind, namespace=namespace)

        # holds the function that will be called
        self._entrypoint = self._load_entrypoint_from_handler(handler)

        # connect to processor
        self._processor_sock = self._connect_to_processor()

        # make a writeable file from processor
        self._processor_sock_wfile = self._processor_sock.makefile('w')

        # since this wrapper is behind the nuclio processor, in which pre-handle the traffic & request
        # it is not mandatory to provide security over max buffer size.
        # the request limit should be handled on the processor level.
        self._unpacker = msgpack.Unpacker(raw=False, max_buffer_size=2**32-1)

        # get handler module
        entrypoint_module = sys.modules[self._entrypoint.__module__]

        # create a context with logger and platform
        self._context = nuclio_sdk.Context(self._logger,
                                           self._platform,
                                           worker_id,
                                           nuclio_sdk.TriggerInfo(trigger_kind, trigger_name))

        # call init context
        if hasattr(entrypoint_module, 'init_context'):
            try:
                getattr(entrypoint_module, 'init_context')(self._context)
            except:
                self._logger.error('Exception raised while running init_context')
                raise

        # replace the default output with the process socket
        self._logger.set_handler('default', self._processor_sock_wfile, nuclio_sdk.logger.JSONFormatter())

        # indicate that we're ready
        self._write_packet_to_processor('s')