Beispiel #1
0
    def setup_method(self, method):
        imp.reload(configreader)
        imp.reload(test.unit.agent.common.config.app)

        context.setup(
            app='test',
            app_config=test.unit.agent.common.config.app.TestingConfig()
        )
        context.setup_thread_id()

        context.default_log.info(
            '%s %s::%s %s' % ('=' * 20, self.__class__.__name__, self._testMethodName, '=' * 20)
        )

        # modify http client to store http requests
        from amplify.agent.common.util.http import HTTPClient
        self.http_requests = []

        original_get = HTTPClient.get
        original_post = HTTPClient.post

        def fake_get(obj, url, *args, **kwargs):
            self.http_requests.append(url)
            return original_get(obj, url, *args, **kwargs)

        def fake_post(obj, url, *args, **kwargs):
            self.http_requests.append(url)
            return original_post(obj, url, *args, **kwargs)

        HTTPClient.get = fake_get
        HTTPClient.post = fake_post

        import amplify.agent.pipelines.file
        amplify.agent.pipelines.file.OFFSET_CACHE = {}
Beispiel #2
0
    def run(self):
        """
        Common collector cycle

        1. Collect data
        2. Sleep
        3. Stop if object stopped
        """
        # TODO: Standardize this with Managers.
        current_thread().name = self.short_name
        context.setup_thread_id()

        try:
            while True:
                context.inc_action_id()
                if self.object.running:
                    self._collect()
                    self._sleep()
                else:
                    break

            raise GreenletExit  # Since kill signals won't work, we raise it ourselves.
        except GreenletExit:
            context.log.debug(
                '%s collector for %s received exit signal' % (self.__class__.__name__, self.object.definition_hash)
            )
        except:
            context.log.error(
                '%s collector run failed' % self.object.definition_hash,
                exc_info=True
            )
            raise
Beispiel #3
0
    def run(self):
        """
        Common collector cycle

        1. Collect data
        2. Sleep
        3. Stop if object stopped
        """
        # TODO: Standardize this with Managers.
        current_thread().name = self.short_name
        context.setup_thread_id()

        try:
            while True:
                context.inc_action_id()
                if self.object.running:
                    self._collect()
                    self._sleep()
                else:
                    break

            raise GreenletExit  # Since kill signals won't work, we raise it ourselves.
        except GreenletExit:
            context.log.debug(
                '%s collector for %s received exit signal' %
                (self.__class__.__name__, self.object.definition_hash))
        except:
            context.log.error('%s collector run failed' %
                              self.object.definition_hash,
                              exc_info=True)
            raise
    def start(self):
        """
        Execution entry point.  Does some setup and then runs the _run routine.
        """
        # TODO: Standardize this with collectors and managers.
        current_thread().name = self.name
        context.setup_thread_id()

        self.running = True

        context.inc_action_id()
        start = time.time()
        try:
            self._setup()
            self._run()
        except Exception as e:
            context.default_log.error(
                '"%s" critical exception "%s" caught during run' %
                (self.__class__.__name__, e.__class__.__name__))
            context.default_log.debug('additional info:', exc_info=True)
        finally:
            try:
                self._teardown()
            finally:
                end = time.time()
                context.default_log.debug(
                    '%s (%s) run complete in %0.2f' %
                    (self.__class__.__name__, id(self), end - start))

        self.stop()
Beispiel #5
0
    def start(self):
        current_thread().name = self.name
        context.setup_thread_id()

        self.running = True

        while self.running:
            self._wait(0.1)
            # This means that we don't increment every time a UDP message is handled, but rather every listen "period"
            context.inc_action_id()
            asyncore.loop(timeout=self.interval, count=10)
Beispiel #6
0
    def start(self):
        current_thread().name = self.name
        context.setup_thread_id()

        self.running = True

        while self.running:
            self._wait(0.1)
            # This means that we don't increment every time a UDP message is handled, but rather every listen "period"
            context.inc_action_id()
            asyncore.loop(timeout=self.interval, count=10)
    def start(self):
        """
        Primary execution loop.  Follows the pattern: wait, increment action id, call manager run method.
        """
        # TODO: Standardize this with collectors.
        current_thread().name = self.name
        context.setup_thread_id()

        self.running = True

        while self.running:
            self._wait(self.interval)
            context.inc_action_id()
            self._run()
Beispiel #8
0
    def start(self):
        """
        Primary execution loop.  Follows the pattern: wait, increment action id, call manager run method.
        """
        # TODO: Standardize this with collectors.
        current_thread().name = self.name
        context.setup_thread_id()

        self.running = True

        while self.running:
            self._wait(self.interval)
            context.inc_action_id()
            self._run()
Beispiel #9
0
    def start(self):
        """
        Primary execution loop.  Follows the pattern: wait, increment action id, call manager run method.
        """
        # TODO: Standardize this with collectors.
        current_thread().name = self.name
        context.setup_thread_id()

        self.running = True

        try:
            while self.running:
                self._wait(self.interval)
                context.inc_action_id()
                self._run()
        except Exception as e:
            context.log.error('manager execution failed due to "%s"' % e.__class__.__name__)
            context.log.debug('additional info:', exc_info=True)
            raise e