Beispiel #1
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 #2
0
def loadCollection(path):
    Log.d(TAG, f"Getting a collection from {path}")
    try:
        return _pickle.load(open(path, 'rb'))
    except Exception as ex:
        Log.w(TAG, "Someone explicitly deleted the collection file from disk")
        Log.e(TAG, f"Collection is not exist on {path}. {ex}")
        return None
Beispiel #3
0
def renderRIDUProcess(parsed_data):
    Log.i(TAG, "Rendering Process...")
    if parsed_data.request_type == 'Read':
        return ReadProcess(parsed_data)
    elif parsed_data.request_type == 'Update':
        return UpdateProcess(parsed_data)
    elif parsed_data.request_type == 'Insert':
        return InsertProcess(parsed_data)
    elif parsed_data.request_type == 'Delete':
        return DeleteProcess(parsed_data)
    elif parsed_data.request_type == 'ReadById':
        return ReadByIdProcess(parsed_data)
    elif parsed_data.request_type == 'ReadOne':
        return ReadOneProcess(parsed_data)
    elif parsed_data.request_type == 'UpdateOne':
        return UpdateOneProcess(parsed_data)
    else:
        Log.e(TAG, "No compatible request_type found.")
        return None
Beispiel #4
0
def writer(collection):
    try:
        doctor()
        if collection is list:
            for col in collection:
                if col.col_name == config.DEFAULT_META_COLLECTION_NAME:
                    _pickle.dump(col, open(config.COLLECTION_PATH, "wb"))
                    Log.d(TAG, f"{collection.col_name} written on disk")
                else:
                    _pickle.dump(col, open(__getNewCollectionUri(col), "wb"))
                    Log.d(TAG, f"{collection.col_name} written on disk")
        else:
            if collection.col_name == config.DEFAULT_META_COLLECTION_NAME:
                _pickle.dump(collection, open(config.COLLECTION_PATH, "wb"))
                Log.d(TAG, f"{collection.col_name} written on disk")
            else:
                _pickle.dump(collection,
                             open(__getNewCollectionUri(collection), "wb"))
                Log.d(TAG, f"{collection.col_name} written on disk")
        return True
    except Exception as ex:
        Log.e(TAG, f"Unable to write {collection.col_name} collection on disk")
        return False
Beispiel #5
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