Beispiel #1
0
def showCollections(database: str):
    reqSchema = {
        "type": "Provider",
        "show": "Collections",
        "of": database
    }
    Event.emmit("request", json.dumps(reqSchema))
Beispiel #2
0
 def create_new_collection(cls, col_name, db_name):
     new_collection = Collection(col_name, db_name)
     Provider.add_collection(new_collection)
     Provider.meta_collection.insert({
         "db_name": db_name,
         "col_name": col_name,
         "time_stamp": parserTimeStamp(str(time.time())),  # its helps to find this collection on disk
         "user": "******"
     })
     Event.emmit('col-change', Provider.meta_collection)
     return new_collection
Beispiel #3
0
    def listen(self, **kwargs):
        super().bind((self.host, self.port))
        Log.i(TAG, f"Server is listening on port {self.port}")
        Event.on('on_task_complete', self.send_ack)
        while True:
            super().listen(1)
            client, addr = super().accept()
            Log.d(TAG, f"Client connected with {addr}")
            self.clients.append({
                "client": client,
                "addr": addr
            })
            while True:
                try:
                    raw_query = str(client.recv(1024).decode("UTF-8"))
                    Log.d(TAG, f"Received data from client {addr}")
                    Log.d(TAG, f"Data -> {raw_query}")
                    if raw_query.lower() == 'exit':
                        client.close()
                        break
                    json_query = json.loads(raw_query)
                    json_query['addr'] = str(addr)
                    if json_query['type'] is not None and json_query['type'] == 'Request':
                        Event.emmit('request', json.dumps(json_query))
                        Log.d(TAG, f"Client is requesting for RIDU operation")
                    elif json_query['type'] is not None and json_query['type'] == 'Subscription':
                        Log.d(TAG, f"Client is requesting for subscription")
                        Event.emmit('req_sub', json.dumps(json_query))

                    # code to communicate with hyperlite engine
                except Exception as err:
                    Log.e(TAG, f"Connection broken -> {err}")
                    client.close()
                    break
Beispiel #4
0
 def manage_loop_status():
     if not loop_runner.isRunning:
         Log.i(TAG, "EventLoop is stopped, Rerunning EventLoop...")
         Event.emmit('loop-rerun')
Beispiel #5
0
    # server_process = threading.Thread(target=listenForConnection)
    loop_runner = event_loop.LoopRunner()
    loop_runner.run()

    def manage_loop_status():
        if not loop_runner.isRunning:
            Log.i(TAG, "EventLoop is stopped, Rerunning EventLoop...")
            Event.emmit('loop-rerun')

    def onRequest(data):
        Log.d(TAG, f"New request - {data}")
        loop_runner.loop.query_processes.put(
            renderRIDUProcess(parsed_data=Parser.parse(data)))
        manage_loop_status()

    def onSubscription(data):
        Log.d(TAG, f"New subscription request - {data}")
        # TODO: Adding subscription plan
        loop_runner.loop.subscriptions.put()

    def onCollectionChange(collection: Collection):
        Log.i(TAG, "Event -> Collection Changed")
        for proc in renderProcess(collection):
            loop_runner.loop.system_process.put(proc)
        manage_loop_status()

    Event.on('request', onRequest)
    Event.on('col-change', onCollectionChange)
    Event.on('req_sub', onSubscription)
    listenForConnection()
Beispiel #6
0
 def __init__(self, host, port):
     super().__init__(socket.AF_INET, socket.SOCK_STREAM)
     self.host = host
     self.port = port
     Event.on('request', self.sendRequest)
Beispiel #7
0
def showDatabases():
    reqSchema = {
        "type": "Provider",
        "show": "Databases"
    }
    Event.emmit("request", json.dumps(reqSchema))
Beispiel #8
0
 def sendRequest(self, data):
     super().send(str(data).encode("UTF-8"))
     response = super().recv(1024*1024*1024).decode('UTF-8')
     Event.emmit("response", response)
Beispiel #9
0
connection = None
console = InteractiveConsole(globals())


def onResponse(response: str):
    print(response)


def onRequest(request: str):
    if connection is not None:
        connection.sendRequest(request)


if __name__ == '__main__':
    connection = Connection(host='localhost', port=9898)
    Event.on('response', onResponse)
    data = {
        "name": "Anikesh patel",
        "email": "*****@*****.**",
        "password": "******"
    }
    connection.connect()
    col = Collection('users')
    col.insert(data)
    # col.readById('cfc21e92fde3418791eafbbb3038b363')
    query = """
            name,
            email &eq "*****@*****.**",
            password &eq "123123"
            """
    col.execHyperQl(query)
Beispiel #10
0
    def listen(self, **kwargs):
        super().bind((self.host, self.port))
        Log.i(TAG, f"Server is listening on port {self.port}")
        Event.on('on_task_complete', self.send_ack)
        while True:
            super().listen(1)
            client, addr = super().accept()
            Log.d(TAG, f"Client connected with {addr}")
            clientObj = {"client": client, "addr": addr}
            self.clients.append(clientObj)
            while True:
                try:
                    raw_query = str(
                        client.recv(1024 * 1024 * 1024).decode("UTF-8"))
                    Log.d(TAG, f"Received data from client {addr}")
                    if raw_query.lower() == 'exit':
                        client.close()
                        break
                    json_query = json.loads(raw_query)
                    json_query['addr'] = str(addr)
                    if json_query['type'] is not None and json_query[
                            'type'] == 'Request':
                        Event.emmit('request', json.dumps(json_query))
                        Log.d(TAG, f"Client is requesting for RIDU operation")
                    elif json_query['type'] is not None and json_query[
                            'type'] == 'Subscription':
                        Log.d(TAG, f"Client is requesting for subscription")
                        Event.emmit('req_sub', json.dumps(json_query))
                    elif json_query['type'] is not None and json_query[
                            'type'] == 'Pipeline':
                        Log.d(TAG, f"Client is requesting for Data Pipeline")
                        Event.emmit('req_pipe', json_query)
                    elif json_query['type'] is not None and json_query[
                            'type'] == 'Provider':
                        Log.d(TAG,
                              f"Client is requesting for Provider Component")
                        Event.emmit('req_provider', json_query)

                    # code to communicate with hyperlite engine
                except ConnectionResetError as err:
                    Log.e(TAG, f"Connection Reset -> {err}")
                    client.close()
                    Log.d(TAG, f"{self.clients}")
                    self.clients.remove(clientObj)
                    Log.i(TAG, "Client removed from Clients list")
                    Log.d(
                        TAG,
                        f"Connected clients -> {self.clients if len(self.clients) != 0 else 'No Clients'}"
                    )
                    break
                except Exception as err:
                    Log.e(TAG, f"Connection broken -> {err}")
                    # errorSchema = """
                    # {
                    #     "type": "Error",
                    #     "message": "{}"
                    # }
                    # """.format(err)
                    # Log.d(TAG, errorSchema)
                    # client.send(errorSchema.encode('UTF-8'))
                    # client.close()
                    break
Beispiel #11
0
    def onSubscription(data):
        Log.d(TAG, f"New subscription request - {data}")
        # TODO: Adding subscription plan
        loop_runner.loop.subscriptions.put()

    def onPipeline(data):
        Log.d(TAG, f"New data pipeline request - {data}")
        loop_runner.loop.query_processes.put(DataPipelineProcess(data))
        manage_loop_status()

    def onProviderRequest(data):
        Log.d(TAG, f"New provider request - {data}")
        loop_runner.loop.query_processes.put(renderProviderProcess(data))
        manage_loop_status()

    def onCollectionChange(collection: Collection):
        Log.i(TAG, "Event -> Collection Changed")
        for proc in renderProcess(collection):
            loop_runner.loop.system_process.put(proc)
        for proc in renderProcess(Provider.meta_collection):
            loop_runner.loop.system_process.put(proc)
        manage_loop_status()

    Event.on('request', onRequest)
    Event.on('col-change', onCollectionChange)
    Event.on('req_sub', onSubscription)
    Event.on('req_pipe', onPipeline)
    Event.on('req_provider', onProviderRequest)
    listenForConnection()