Skip to content

Object Document Mapper

Description

The module contains the object document map for the MongoDB collections and they python portion of the toolchain.

Documents

runner.odm

ODM for the RLITT generator.

StencilStateEnum

Bases: int, Enum

The enum for states a stencil can occupy.

Attributes:

Name Type Description
new

The stencil is new.

started

The stencil is being processed.

no_headroom

The stencil is fully processed but jobs are not yet created.

complete

The stencil is fully processed.

new class-attribute instance-attribute

new = 0

started class-attribute instance-attribute

started = 1

no_headroom class-attribute instance-attribute

no_headroom = 2

complete class-attribute instance-attribute

complete = 3

StencilCfg dataclass

StencilCfg(current_completed_tcn, max_tcn, _id)

The configuration document for the stencil store.

Attributes:

Name Type Description
current_completed_tcn int

The current largest TCN to be fully generated.

max_tcn int

The maximum TCN to process.

_id str

The ID for the document.

current_completed_tcn instance-attribute

current_completed_tcn

max_tcn instance-attribute

max_tcn

_id instance-attribute

_id

StencilDB dataclass

StencilDB(_id, rootstock_tcn, scion_tcn, state)

The shape of a stencil document.

Attributes:

Name Type Description
_id ObjectId

The ID for the document.

rootstock_tcn int

The TCN for the rootstock of the stencil.

scion_tcn int

The TCN for the scion of the stencil.

state int

The state of the stencil. This is in terms of StencilStateEnum.

cursor int

The current cursor, a pair of ObjectId for arborescent tangle documents.

_id instance-attribute

_id

rootstock_tcn instance-attribute

rootstock_tcn

scion_tcn instance-attribute

scion_tcn

state instance-attribute

state

get_db

get_db(url, port, username, password, database_name)

Get a connection to the mongodb.

Parameters:

Name Type Description Default
url str

The domain to connect to.

required
port int

The port to connect to.

required
username str

The username to use for the connection.

required
password str

The password to use for the connection.

required
database_name str

The name of the database to connect to.

required

Returns:

Type Description
Database

Returns one of a database connection or None.

Source code in runner/odm.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def get_db(url: str, port: int, username: str, password: str, database_name: str) -> Database:
    """Get a connection to the mongodb.

    Args:
        url: The domain to connect to.
        port: The port to connect to.
        username: The username to use for the connection.
        password: The password to use for the connection.
        database_name: The name of the database to connect to.

    Returns:
        Returns one of a database connection or None.
    """
    if url and port and username and password and database_name:
        username = urllib.parse.quote_plus(username)
        password = urllib.parse.quote_plus(password)
        client = MongoClient(
            f'mongodb://{username}:{password}@{url}:{port}/?authSource=admin&retryWrites=true&w=majority',
            connectTimeoutMS=0,
            # noqa: E501
        )
        return client[database_name]
    raise NameError(
        'DB load error'
    ) from None  # @@@IMPROVEMENT: needs to be updated to exception object

get_stencil_collection

get_stencil_collection(dbc)

Get the stencil collection.

Parameters:

Name Type Description Default
dbc Database

The mongodb to get the collection from.

required

Returns:

Type Description
Collection

A connection to the stencil collection.

Source code in runner/odm.py
42
43
44
45
46
47
48
49
50
51
def get_stencil_collection(dbc: Database) -> Collection:
    """Get the stencil collection.

    Args:
        dbc: The mongodb to get the collection from.

    Returns:
        A connection to the stencil collection.
    """
    return dbc[cfg.cfg_dict['tangle-collections']['stencil_col_name']]

get_arborescent_collection

get_arborescent_collection(dbc)

Get the arborescent tangle collection.

Parameters:

Name Type Description Default
dbc Database

The mongodb to get the collection from.

required

Returns:

Type Description
Collection

A connection to the arborescent collection.

Source code in runner/odm.py
54
55
56
57
58
59
60
61
62
63
def get_arborescent_collection(dbc: Database) -> Collection:
    """Get the arborescent tangle collection.

    Args:
        dbc: The mongodb to get the collection from.

    Returns:
        A connection to the arborescent collection.
    """
    return dbc[cfg.cfg_dict['tangle-collections']['col_name']]