Skip to content
This repository has been archived by the owner on Jan 27, 2022. It is now read-only.

Abstract database calls from direct listener handlers #206

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rranjan3
Copy link
Contributor

Abstract out calls using database/table names in handlers for direct
mode listener. The segregated layer may contain some logic if it has
to deal only with lower/database calls for it. Hence abstracting some
deatils from the layer above. This thin layer can also be used in the
Proxy mode of operations.

Signed-off-by: Rajeev Ranjan [email protected]

Copy link
Contributor

@danintel danintel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with minor corrections and a question.

if (self.kv_helper.get("wo-receipts", wo_id) is not None):
self.kv_helper.remove("wo-receipts", wo_id)

# TODO: uncomment after fixing lmbd error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment still needed?

Copy link
Contributor Author

@rranjan3 rranjan3 Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to check the intent with initial committer. [email protected]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is not required any more. @Ram-srini ?

if update_to_receipt["updaterId"] != updater_id:
raise JSONRPCDispatchException(
JRPCErrorCodes.INVALID_PARAMETER_FORMAT_OR_VALUE,
"Update index and updater id doesn't match"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/match/match./

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

else:
raise JSONRPCDispatchException(
JRPCErrorCodes.INVALID_PARAMETER_FORMAT_OR_VALUE,
"There is no updates available to this receipt"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/receipt/receipt./

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -0,0 +1,15 @@
# Copyright 2020 Intel Corporation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move db_helper to examples/common/python.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helper module is assisting on the connector components(direct & proxy). Hence I have made it a module common to only both the type of connectors.

logger = logging.getLogger(__name__)


class WorkOrderLmdbHelper:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WorkOrderLmdbHelper -> WorkOrderKVHelper
work_order_lmdb_helper.py -> work_order_kv_helper.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all the name changes - I have deliberately named them as lmdb helper as I expect similar layers for other kind of databases that would handle the low level database calls.

# ---------------------------------------------------------------------------------------------
def submit_wo(self, wo_id, input_json_str):
"""
Function to submit a new work-order
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function to submit and store a new work-order to db

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

"""
Function to perform init activity
Parameters:
- kv_helper is a object of lmdb database
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kv_helper is a object of shared kv database

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

# ---------------------------------------------------------------------------------------------
def get_wo_result(self, wo_id):
"""
Function to get work-order result from lmdb
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function to get work-order result from shared kv database

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

logger = logging.getLogger(__name__)


class WorkerEncryptionKeyLmdbHelper:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WorkerEncryptionKeyLmdbHelper -> WorkerEncryptionKeyDbHelper

"""
WorkerEncryptionKeyDBHelper helps listener or other client
facing modules to interact with the kv storage for queries
related to encryption key. It implements all low level db
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any encryption key being passed as query parameter in below functions ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a place holder module where functions can be added later on. This module would also abstract any database helper calls from the module above.

logger = logging.getLogger(__name__)


class WorkerRegistryLmdbHelper:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WorkerRegistryLmdbHelper -> WorkerRegistryDbHelper

logger = logging.getLogger(__name__)


class WorkOrderReceiptLmdbHelper:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WorkOrderReceiptLmdbHelper -> WorkOrderReceiptDbHelper

@@ -1,4 +1,4 @@
# Copyright 2019 Intel Corporation
# Copyright 2020 Intel Corporation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file was created in 2019 I think. So no need to change the copyright

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Updated.


def clear_a_processed_wo(self):
"""
Function that clears one processed work-order from
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the comment that it will remove the least recently added entry from processed table.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -0,0 +1,164 @@
# Copyright 2020 Intel Corporation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where should we move this db helper modules? In common/python/database module?

Abstract out calls using database/table names in handlers for direct
mode listener. The segregated layer may contain some logic if it has
to deal only with lower/database calls for it. Hence abstracting some
deatils from the layer above. This thin layer can also be used in the
Proxy mode of operations.

Signed-off-by: Rajeev Ranjan <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants