Exemple #1
0
    def run(self, reload, logging, **kwargs):
        config = self._commandor_res

        if not config:
            self.error("You need specify --config\n")
            self.exit()

        configure_logging(logging)

        self.application = AggregatorApplication(config)
        ioloop = tornado.ioloop.IOLoop.instance()

        self.application.configure_app(ioloop)

        if reload:
            self.display("Autoreload enabled")
            autoreload.start(io_loop=ioloop, check_time=100)

        # Init signals handler
        signal.signal(signal.SIGTERM, self.sig_handler)

        # This will also catch KeyboardInterrupt exception
        signal.signal(signal.SIGINT, self.sig_handler)

        ioloop.start()
Exemple #2
0
class UDPBackendTestCase(AsyncBaseTestCase):
    def get_app(self):
        config = Config()
        config.from_module(gottwall.default_config)

        config.update({
            "BACKENDS": {
                "gottwall.backends.udp.UDPBackend": {
                    "PORT": get_unused_port()
                }
            },
            "STORAGE": "gottwall.storages.MemoryStorage",
            "PROJECTS": {
                "test_project": "secretkey"
            },
            "PRIVATE_KEY": "myprivatekey"
        })

        self.app = AggregatorApplication(config)
        self.app.configure_app(self.io_loop)

        return self.app

    def test_backend(self):
        print("Test UDP backend")
Exemple #3
0
    def get_app(self):
        config = Config()
        config.from_module(gottwall.default_config)
        config.update({"TASKS_CHUNK": 15,
                       "BACKENDS": {"gottwall.backends.tcpip.TCPIPBackend": {
                           "PORT": get_unused_port()}}})

        app = AggregatorApplication(config)
        app.configure_app(tornado.ioloop.IOLoop().instance())
        return app
    def get_app(self):
        config = Config()
        config.from_module(gottwall.default_config)

        config.update({"BACKENDS": {"gw_backend_redis.backend.RedisBackend": {"HOST": HOST}},
                       "STORAGE": "gottwall.storages.MemoryStorage",
                       "REDIS_HOST": HOST,
                       "PROJECTS": {"test_project": "secretkey2"},
                       "SECRET_KEY": "myprivatekey2"})
        app = AggregatorApplication(config)
        app.configure_app(self.io_loop)
        return app
Exemple #5
0
    def get_app(self):
        config = Config()
        config.from_module(gottwall.default_config)
        config.update({
            "TASKS_CHUNK": 15,
            "BACKENDS": {
                "gottwall.backends.tcpip.TCPIPBackend": {
                    "PORT": get_unused_port()
                }
            }
        })

        app = AggregatorApplication(config)
        app.configure_app(tornado.ioloop.IOLoop().instance())
        return app
Exemple #6
0
    def run(self, reload,  logging, **kwargs):
        config = self._commandor_res

        if not config:
            self.error("You need specify --config\n")
            self.exit()

        configure_logging(logging)

        self.application = AggregatorApplication(config)
        ioloop = tornado.ioloop.IOLoop.instance()

        self.application.configure_app(ioloop)

        if reload:
            self.display("Autoreload enabled")
            autoreload.start(io_loop=ioloop, check_time=100)

        # Init signals handler
        signal.signal(signal.SIGTERM, self.sig_handler)

        # This will also catch KeyboardInterrupt exception
        signal.signal(signal.SIGINT, self.sig_handler)

        ioloop.start()
Exemple #7
0
class TCPBackendTestCase(AsyncBaseTestCase):
    def get_app(self):
        config = Config()
        config.from_module(gottwall.default_config)

        config.update({"BACKENDS": {"gottwall.backends.tcpip.TCPIPBackend": {
            "PORT": get_unused_port()}},
            "STORAGE": "gottwall.storages.MemoryStorage",
            "PROJECTS": {"test_project": "secretkey"},
            "PRIVATE_KEY": "myprivatekey"})
        self.app = AggregatorApplication(config)
        self.app.configure_app(self.io_loop)

        return self.app


    def test_backend(self):
        print("Test TCP backend")
Exemple #8
0
    def get_app(self):
        config = Config()
        config.from_module(gottwall.default_config)
        config.update({
            "BACKENDS": {
                "gottwall.backends.http.HTTPBackend": {
                    "PORT": get_unused_port()
                }
            },
            "PROJECTS": {
                "test_project": "secretkey"
            },
            "SECRET_KEY": "myprivatekey"
        })

        self.aggregator = AggregatorApplication(config)
        self.aggregator.configure_app(self.io_loop)

        return self.aggregator.backends[0].web_application
Exemple #9
0
    def get_app(self):
        config = Config()
        config.from_module(gottwall.default_config)

        config.update({
            "BACKENDS": {
                "gottwall.backends.tcpip.TCPIPBackend": {
                    "PORT": get_unused_port()
                }
            },
            "STORAGE": "gottwall.storages.MemoryStorage",
            "PROJECTS": {
                "test_project": "secretkey"
            },
            "PRIVATE_KEY": "myprivatekey"
        })
        self.app = AggregatorApplication(config)
        self.app.configure_app(self.io_loop)

        return self.app
Exemple #10
0
    def get_app(self):
        config = Config()
        config.from_module(gottwall.default_config)
        config.update({"BACKENDS": {
            "gottwall.backends.http.HTTPBackend": {
                "PORT": get_unused_port()}
            },
            "PROJECTS": {"test_project": "secretkey"},
            "SECRET_KEY": "myprivatekey"})
        self.app = AggregatorApplication(config)
        self.app.configure_app(self.io_loop)

        return self.app
Exemple #11
0
    def get_app(self):
        config = Config()
        config.from_module(gottwall.default_config)

        config.update({"BACKENDS": {"gottwall.backends.udp.UDPBackend": {
            "PORT": get_unused_port()}},
            "STORAGE": "gottwall.storages.MemoryStorage",
            "PROJECTS": {"test_project": "secretkey"},
            "PRIVATE_KEY": "myprivatekey"})

        self.app = AggregatorApplication(config)
        self.app.configure_app(self.io_loop)

        return self.app
Exemple #12
0
class Start(Command):
    """Aggregator starter
    """
    parent = Aggregator

    options = [
        Option("-r",
               "--reload",
               action="store_true",
               dest="reload",
               default=False,
               help="Auto realod source on changes"),
        Option("-l",
               "--logging",
               metavar="str",
               default="none",
               help="Log level")
    ]

    def run(self, reload, logging, **kwargs):
        config = self._commandor_res

        if not config:
            self.error("You need specify --config\n")
            self.exit()

        configure_logging(logging)

        self.application = AggregatorApplication(config)
        ioloop = tornado.ioloop.IOLoop.instance()

        self.application.configure_app(ioloop)

        if reload:
            self.display("Autoreload enabled")
            autoreload.start(io_loop=ioloop, check_time=100)

        # Init signals handler
        signal.signal(signal.SIGTERM, self.sig_handler)

        # This will also catch KeyboardInterrupt exception
        signal.signal(signal.SIGINT, self.sig_handler)

        ioloop.start()

    def sig_handler(self, sig, frame):
        """Catch signal and init callback
        """
        tornado.ioloop.IOLoop.instance().add_callback(self.shutdown)

    def shutdown(self):
        """Stop server and add callback to stop i/o loop"""
        self.display("Shutting down service")
        self.application.shutdown()
        self.application.check_ready_to_stop()
Exemple #13
0
class Start(Command):
    """Aggregator starter
    """
    parent = Aggregator

    options = [
        Option("-r", "--reload", action="store_true",dest="reload", default=False,
               help="Auto realod source on changes"),
        Option("-l", "--logging", metavar="str", default="none",
               help="Log level")]

    def run(self, reload,  logging, **kwargs):
        config = self._commandor_res

        if not config:
            self.error("You need specify --config\n")
            self.exit()

        configure_logging(logging)

        self.application = AggregatorApplication(config)
        ioloop = tornado.ioloop.IOLoop.instance()

        self.application.configure_app(ioloop)

        if reload:
            self.display("Autoreload enabled")
            autoreload.start(io_loop=ioloop, check_time=100)

        # Init signals handler
        signal.signal(signal.SIGTERM, self.sig_handler)

        # This will also catch KeyboardInterrupt exception
        signal.signal(signal.SIGINT, self.sig_handler)

        ioloop.start()

    def sig_handler(self, sig, frame):
        """Catch signal and init callback
        """
        tornado.ioloop.IOLoop.instance().add_callback(self.shutdown)

    def shutdown(self):
        """Stop server and add callback to stop i/o loop"""
        self.display("Shutting down service")
        self.application.shutdown()
        self.application.check_ready_to_stop()
Exemple #14
0
class HTTPBackendTestCase(AsyncHTTPBaseTestCase):
    def get_app(self):
        config = Config()
        config.from_module(gottwall.default_config)
        config.update({
            "BACKENDS": {
                "gottwall.backends.http.HTTPBackend": {
                    "PORT": get_unused_port()
                }
            },
            "PROJECTS": {
                "test_project": "secretkey"
            },
            "SECRET_KEY": "myprivatekey"
        })

        self.aggregator = AggregatorApplication(config)
        self.aggregator.configure_app(self.io_loop)

        return self.aggregator.backends[0].web_application

    def test_handler(self):
        app = self.get_app()
        aggregator = self.aggregator

        metric_data = {
            "name": "my_metric_name",
            "timestamp":
            datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S"),
            "filters": {
                "views": "registered",
                "clicks": "anonymouse"
            },
            "action": "incr",
            "value": 2
        }

        auth_value = "GottWall private_key={0}, public_key={1}".format(
            aggregator.config['SECRET_KEY'],
            aggregator.config['PROJECTS']['test_project'])

        authorization = "{0}:{1}".format(
            aggregator.config['PROJECTS']['test_project'],
            aggregator.config['SECRET_KEY'])

        response = self.fetch("/gottwall/api/v1/test_projfewfweect/incr",
                              method="POST",
                              body=json.dumps(metric_data),
                              headers={
                                  "content-type": "application/json",
                                  "Authorization": b64encode(authorization)
                              })

        self.assertEquals(response.code, 404)

        response = self.fetch("/gottwall/api/v1/test_project/infdsfcr",
                              method="POST",
                              body=json.dumps(metric_data),
                              headers={
                                  "content-type": "application/json",
                                  "Authorization": b64encode(authorization)
                              })

        self.assertEquals(response.code, 404)

        ts = int(time.mktime(datetime.datetime.utcnow().timetuple()))
        auth_value = "GottWallS1 {0} {1} {2}".format(
            ts,
            make_sign(ts, aggregator.config['SECRET_KEY'],
                      aggregator.config['PROJECTS']['test_project'], 1000),
            1000)

        response = self.fetch("/gottwall/api/v1/test_project/incr",
                              method="POST",
                              body=json.dumps(metric_data),
                              headers={
                                  "content-type": "application/json",
                                  "X-GottWall-Auth": auth_value
                              })

        self.assertEquals(response.body, "OK")
        self.assertEquals(response.code, 200)

        # Test without authorization

        response = self.fetch("/gottwall/api/v1/test_project/incr",
                              method="POST",
                              body=json.dumps(metric_data),
                              headers={"content-type": "application/json"})

        self.assertEquals(response.code, 403)

        response = self.fetch("/gottwall/api/v1/test_project/incr",
                              method="POST",
                              body=json.dumps(metric_data),
                              headers={
                                  "content-type":
                                  "application/json",
                                  "Authorization":
                                  "Basic " + b64encode(authorization)
                              })

        self.assertEquals(response.body, "OK")
        self.assertEquals(response.code, 200)
Exemple #15
0
class HTTPBackendTestCase(AsyncHTTPBaseTestCase):

    def get_app(self):
        config = Config()
        config.from_module(gottwall.default_config)
        config.update({"BACKENDS": {
            "gottwall.backends.http.HTTPBackend": {
                "PORT": get_unused_port()}
            },
            "PROJECTS": {"test_project": "secretkey"},
            "SECRET_KEY": "myprivatekey"})

        self.aggregator = AggregatorApplication(config)
        self.aggregator.configure_app(self.io_loop)

        return self.aggregator.backends[0].web_application

    def test_handler(self):
        app = self.get_app()
        aggregator = self.aggregator

        metric_data = {"name": "my_metric_name",
                       "timestamp": datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S"),
                       "filters": {"views": "registered",
                                   "clicks": "anonymouse"},
                       "action": "incr",
                       "value": 2}

        auth_value = "GottWall private_key={0}, public_key={1}".format(
            aggregator.config['SECRET_KEY'],
            aggregator.config['PROJECTS']['test_project'])

        authorization = "{0}:{1}".format(aggregator.config['PROJECTS']['test_project'],
                                         aggregator.config['SECRET_KEY'])


        response = self.fetch("/gottwall/api/v1/test_projfewfweect/incr", method="POST",
                              body=json.dumps(metric_data),
                              headers={"content-type": "application/json",
                                       "Authorization": b64encode(authorization)})

        self.assertEquals(response.code, 404)

        response = self.fetch("/gottwall/api/v1/test_project/infdsfcr", method="POST",
                              body=json.dumps(metric_data),
                              headers={"content-type": "application/json",
                                       "Authorization": b64encode(authorization)})

        self.assertEquals(response.code, 404)

        ts = int(time.mktime(datetime.datetime.utcnow().timetuple()))
        auth_value = "GottWallS1 {0} {1} {2}".format(
            ts, make_sign(ts, aggregator.config['SECRET_KEY'],
                          aggregator.config['PROJECTS']['test_project'], 1000), 1000)

        response = self.fetch("/gottwall/api/v1/test_project/incr", method="POST",
                              body=json.dumps(metric_data),
                              headers={"content-type": "application/json",
                                       "X-GottWall-Auth": auth_value})


        self.assertEquals(response.body, "OK")
        self.assertEquals(response.code, 200)

        # Test without authorization

        response = self.fetch("/gottwall/api/v1/test_project/incr", method="POST",
                              body=json.dumps(metric_data),
                              headers={"content-type": "application/json"})

        self.assertEquals(response.code, 403)

        response = self.fetch("/gottwall/api/v1/test_project/incr", method="POST",
                              body=json.dumps(metric_data),
                              headers={"content-type": "application/json",
                                       "Authorization": "Basic " + b64encode(authorization)})


        self.assertEquals(response.body, "OK")
        self.assertEquals(response.code, 200)