Exemple #1
0
    def handler(self, metadata, body):
        """Default handler we override from BaseChunkHandler.

        Args:
            metadata (dict): metadata information
            body (str): data payload from CEXC

        Returns:
            (dict): metadata to be sent back to CEXC
            body (str): data payload to be sent back to CEXC
        """
        if command_util.is_invalid_chunk(metadata):
            logger.debug('Not running without session key.')
            return {'finished': True}

        if command_util.is_getinfo_chunk(metadata):
            return self.setup()

        # Don't run in preview.
        if self.getinfo.get('preview', False):
            logger.debug('Not running in preview')
            return {'finished': True}

        self.controller.execute()
        body = self.controller.output_results()

        # Final farewell
        return ({'finished': True}, body)
Exemple #2
0
    def handler(self, metadata, body):
        """Default handler we override from BaseChunkHandler.

        Args:
            metadata (dict): metadata information
            body (str): data payload from CEXC

        Returns:
            (dict): metadata to be sent back to Splunk
        """
        if command_util.is_getinfo_chunk(metadata):
            return self.setup()

        self.controller.execute()
        return {'finished': True}
Exemple #3
0
    def handler(self, metadata, body):
        """Main handler we override from BaseChunkHandler.

        Args:
            metadata (dict): metadata information
            body (str): data payload from CEXC

        Returns:
            (dict): metadata to be sent back to CEXC
            output_body (str): data payload to be sent back to CEXC
        """
        if command_util.is_invalid_chunk(metadata):
            logger.debug('Not running without session key.')
            return {'finished': True}

        if command_util.is_getinfo_chunk(metadata):
            return self.setup()

        if self.getinfo.get('preview', False):
            logger.debug('Not running in preview.')
            return {'finished': True}

        if not self.watchdog.started:
            self.watchdog.start()

        finished_flag = metadata.get('finished', False)

        self.controller.load_data(body)

        # Partial fit should *always* execute on every chunk.
        # Non partial fit will execute on the last chunk.
        if self.partial_fit or finished_flag:
            self.controller.execute()
            output_body = self.get_output_body()
        else:
            output_body = None

        if finished_flag:
            self.controller.finalize()
            # Gracefully terminate watchdog
            if self.watchdog.started:
                self.watchdog.join()

        # Our final farewell
        self.log_performance_timers()
        return ({'finished': finished_flag}, output_body)
Exemple #4
0
    def handler(self, metadata, body):
        """Main handler we override from BaseChunkHandler.

        Args:
            metadata (dict): metadata information
            body (str): data payload from CEXC

        Returns:
            (dict): metadata to be sent back to CEXC
            body (str): data payload to be sent back to CEXC
        """
        if command_util.is_getinfo_chunk(metadata):
            return self.setup()

        self.controller.execute()
        body = self.controller.output_results()

        return ({'finished': True}, body)
Exemple #5
0
    def handler(self, metadata, body):
        """Main handler we override from BaseChunkHandler.

        Handles the reading and writing of data to the CEXC process, and
        finishes negotiation of the termination of the process.

        Args:
            metadata (dict): metadata information
            body (str): data payload from CEXC

        Returns:
            (dict): metadata to be sent back to CEXC
            output_body (str): data payload to be sent back to CEXC
        """
        if command_util.is_invalid_chunk(metadata):
            logger.debug('Not running without session key.')
            return {'finished': True}

        if command_util.is_getinfo_chunk(metadata):
            return self.setup()

        finished_flag = metadata.get('finished', False)

        if not self.watchdog.started:
            self.watchdog.start()

        # Load data
        self.controller.load_data(body)

        # score will execute on the last chunk.
        if finished_flag:
            self.controller.execute()
            output_body = self.controller.output_results()
        else:
            output_body = None

        if finished_flag:
            if self.watchdog.started:
                self.watchdog.join()

        # Our final farewell
        return ({'finished': finished_flag}, output_body)
Exemple #6
0
    def handler(self, metadata, body):
        """Main handler we override from BaseChunkHandler.

        Handles the reading and writing of data to the CEXC process, and
        finishes negotiation of the termination of the process.

        Args:
            metadata (dict): metadata information
            body (str): data payload from CEXC

        Returns:
            (dict): metadata to be sent back to CEXC
            output_body (str): data payload to be sent back to CEXC
        """
        # Get info exchange an initialize controller, processor, algorithm
        if command_util.is_getinfo_chunk(metadata):
            return self.setup()

        finished_flag = metadata.get('finished', False)

        if not self.watchdog.started:
            self.watchdog.start()

        # Skip to next chunk if this chunk is empty
        if len(body) == 0:
            return {}

        # Load data, execute and collect results.
        self.controller.load_data(body)
        self.controller.execute()
        output_body = self.controller.output_results()

        if finished_flag:
            # Gracefully terminate watchdog
            if self.watchdog.started:
                self.watchdog.join()

        # Our final farewell
        return ({'finished': finished_flag}, output_body)