예제 #1
0
    def collect(self):
        master = AttrDict()
        try:
            m = self.args.master.split(':')
            # So that order of keys is not a factor
            for a in m:
                a = a.split('=')
                if a[0] == 'host': master.host = a[-1]
                elif a[0] == 'port': master.port = a[-1]
                elif a[0] == 'key': master.key = a[-1]
                elif a[0] == 'secret': master.secret = a[-1]
                else: raise ValueError

        except ValueError:
            raise InvalidArgument(self.args.master)

        # Create collector object
        collector = LogCollector(self.args.data_dir, self.args.logaggfs_dir,
                                 master, self.log)

        collector_api = CollectorService(collector, self.log)
        api = API()
        api.register(collector_api, 'v1')

        app = tornado.web.Application([
            (r'^/logagg/.*', RequestHandler, dict(api=api)),
        ])

        app.listen(self.args.port)
        tornado.ioloop.IOLoop.current().start()
예제 #2
0
class WordVecSpaceServer(object):
    N_TREES = 1
    METRIC = 'angular'

    def __init__(self,
                 _type,
                 input_dir,
                 port,
                 n_trees=N_TREES,
                 metric=METRIC,
                 index_fpath=None,
                 log=DUMMY_LOG):
        self._type = _type
        self.input_dir = input_dir
        self.port = port
        self.n_trees = n_trees
        self.metric = metric
        self.index_fpath = index_fpath
        self.log = log

    def start(self):
        self.api = API(log=self.log)
        self.api.register(
            APIFunctions(self._type, self.input_dir, self.n_trees, self.metric,
                         self.index_fpath), 'v1')

        app = self._make_app()
        app.listen(self.port)
        tornado.ioloop.IOLoop.current().start()

    def _make_app(self):
        return tornado.web.Application([
            (r'^/api/.*', RequestHandler, dict(api=self.api)),
        ])
예제 #3
0
    def collect(self):
        """
        Start collector service after parsing arguments
        """
        master = self.parse_master_args(self.args.master)
        # Create collector object
        collector = LogCollector(
            self.args.host,
            self.args.port,
            master,
            self.args.data_dir,
            self.args.logaggfs_dir,
            self.log,
        )
        # Request authentication master details
        register_response = collector.register_to_master()

        # Start server
        if register_response["result"]["success"]:
            collector_api = CollectorService(collector, self.log)
            api = API()
            api.register(collector_api, "v1")
            try:
                app = tornado.web.Application([
                    (r"^/collector/.*", RequestHandler, dict(api=api))
                ])
                app.listen(self.args.port)
                tornado.ioloop.IOLoop.current().start()
            except:
                self.log.info("exiting")
        else:
            err_msg = register_response["result"]["details"]
            raise Exception(err_msg)
    def collect(self):
        '''
        Start collector service after parsing arguments
        '''
        master = self.parse_master_args(self.args.master)
        # Create collector object
        collector = LogCollector(self.args.host, self.args.port, master,
                                 self.args.data_dir, self.args.logaggfs_dir,
                                 self.log)
        # Request authentication master details
        register_response = collector.register_to_master()

        # Start server
        if register_response['result']['success']:
            collector_api = CollectorService(collector, self.log)
            api = API()
            api.register(collector_api, 'v1')
            try:
                app = tornado.web.Application([
                    (r'^/collector/.*', RequestHandler, dict(api=api)),
                ])
                app.listen(self.args.port)
                tornado.ioloop.IOLoop.current().start()
            except:
                self.log.info('exiting')
        else:
            err_msg = register_response['result']['details']
            raise Exception(err_msg)
예제 #5
0
    def start(self):
        self.api = API(log=self.log)
        self.api.register(APIFunctions(self.input_dir), 'v1')

        app = self._make_app()
        app.listen(self.port)
        tornado.ioloop.IOLoop.current().start()
예제 #6
0
    def init_app(self):
         api = API(log=self.log)
         api.register(Sentence_highlight(self.log, self.args), 'Sentence_highlight', 'v1')
         return tornado.web.Application([
	        (r'^/api/.*', RequestHandler, dict(api=api, log=self.log)),
                (r'^/healthcheck', HealthCheck, dict(args=self.args)),
	 ])
예제 #7
0
    def start(self):
        self.api = API(log=self.log)
        self.api.register(
            APIFunctions(self._type, self.input_dir, self.n_trees, self.metric,
                         self.index_fpath), 'v1')

        app = self._make_app()
        app.listen(self.port)
        tornado.ioloop.IOLoop.current().start()
예제 #8
0
    def run(self):

        port = self.args.port
        host = self.args.host 

        auth = AttrDict()
        try:
            m = self.args.auth.split(':')
            # So that order of keys is not a factor
            for a in m:
                a = a.split('=')
                if a[0] == 'key': auth.key = a[-1]
                elif a[0] == 'secret': auth.secret = a[-1]
                else: raise ValueError

        except ValueError:
            raise InvalidArgument(self.args.auth)

        mongodb = AttrDict()
        try:
            m = self.args.mongodb.split(':')
            for a in m:
                a = a.split('=')
                if a[0] == 'host': mongodb.host = a[-1]
                elif a[0] == 'port': mongodb.port = a[-1]
                elif a[0] == 'user': mongodb.user = a[-1]
                elif a[0] == 'passwd': mongodb.passwd = a[-1]
                elif a[0] == 'db': mongodb.name = a[-1]
                else: raise ValueError

        except ValueError:
            raise InvalidArgument(self.args.mongodb)

        # Create LogaggService object
        ls = Master(host,
                port,
                mongodb,
                auth,
                self.log)

        master_api = MasterService(ls, self.log)
        api = API()
        api.register(master_api, 'v1')

        app = tornado.web.Application([
            (r'^/logagg/.*', RequestHandler, dict(api=api)),
                ])

        app.listen(self.args.port)
        tornado.ioloop.IOLoop.current().start()
예제 #9
0
class WordVecSpaceServer(object):
    def __init__(self, input_dir, port, log=Logger):
        self.input_dir = input_dir
        self.port = port
        self.log = log

    def start(self):
        self.api = API(log=self.log)
        self.api.register(APIFunctions(self.input_dir), 'v1')

        app = self._make_app()
        app.listen(self.port)
        tornado.ioloop.IOLoop.current().start()

    def _make_app(self):
        return tornado.web.Application([
            (r'^/api/.*', RequestHandler, dict(api=self.api)),
        ])
예제 #10
0
# Core logic that you want to expose as a service
class Calc(object):
    def add(self, a: int, b: int) -> int:
        return a + b

    def subtract(self, a: int, b: int) -> int:
        return a - b


# Standard boilerplate code to define the service. This
# code will remain more or less the same size regardless
# of how big the code/complexity of `BaseCalc` above is.

# Register BaseCalc with KwikAPI
api = API()
api.register(Calc(), 'v1')


# Passing RequestHandler to the KwikAPI
def make_app():
    return tornado.web.Application([
        (r'^/api/.*', RequestHandler, dict(api=api)),
    ])


# Starting the application
if __name__ == "__main__":
    app = make_app()
    app.listen(9988)
    tornado.ioloop.IOLoop.current().start()
예제 #11
0
            metric = 'cosine'

        dist = distance.cdist(vec, vecs, metric)

        dist = pd.Series(dist[0])
        res = dist.nsmallest(k).keys()
        trans_results = self.wvspace.get_word_at_indices(list(res))

        recall = len(set(actual_results) & set(trans_results)) / k

        data = dict(vspace_results=actual_results,
                    T_vspace_results=trans_results,
                    recall=recall)
        return data


def make_app():
    return tornado.web.Application([
        (r'^/api/.*', RequestHandler, dict(api=api)),
    ])


if __name__ == "__main__":
    api = API()
    api.register(KNearestService(A[1], A[2]), 'v1')

    app = make_app()
    app.listen(A[3])

    tornado.ioloop.IOLoop.current().start()
예제 #12
0
           task: new/declined/accepted

        '''

        if not kwargs:
            raise Exception(
                'Atleast one argument should be passed to perform an update operation'
            )

        food_obj = Food.objects.filter(order_no=order_no)

        if not food_obj:
            raise Exception('order does not exists')

        collection_fields = [f.name for f in Food._meta.fields]
        invalid_fields = list(
            set([x.lower() for x in kwargs.keys()]) - set(collection_fields))

        if invalid_fields:
            raise Exception('invalid_fields: {}'.format(invalid_fields))

        try:
            food_obj.update(**kwargs, dt_updated=CURRENT_TIMESTAMP)
            return "Updated record with the given parameters."
        except:
            raise Exception('Failed to update !!')


api = API(Logger)
api.register(FoodApp(), 'v1')