bexchange.server package

Submodules

bexchange.server.backend module

class bexchange.server.backend.HandledFiles(limit=500)[source]

Bases: object

Keeps track of recently handled files. Probably should be either a sqlite db or a dictionary variant with an aged limit.

add(bdbhash)[source]

Adds the hash to internal list. Will return True if hash added otherwise False.

handled(bdbhash)[source]
class bexchange.server.backend.SimpleBackend(confdirs, nodename, authmgr, db_uri, source_db_uri, odim_source_file, tmpfolder=None)[source]

Bases: Backend

A backend taking care of the exchange

Parameters:
  • engine_or_url – an SqlAlchemy engine or a database url

  • storage – a ~.storage.FileStorage instance to use.

add_configuration_file(f, runtime=False)[source]

Adds the configuration from a configuration file to the system. :param f: The filename containing the configuration in json format :param runtime: If the configuration is added at startup (False) or during operational run (True)

conf_file_removed(filename)[source]
conf_file_written(filename)[source]
classmethod from_conf(conf)[source]

create an instance from configuration parameters are looked up under ‘baltrad.exchange.server’.

get_auth_manager()[source]

:returns the authorization manager used

get_server_nodename()[source]
Returns:

the nodename of this server

get_server_publickey()[source]
Returns:

the public crypto key in PEM encoding that can be used by recipient to verify messages with

get_server_uptime()[source]
Returns:

the server uptime as a tuple of (days, hours, minutes, seconds)

get_statistics_manager()[source]

:returns the statistics manager

get_storage_manager()[source]

:returns the storage manager used

get_tmp_folder()[source]

Returns the global temporary folder name if defined :return the temporary folder name

initialize_configuration(confdirs)[source]

Initializes the configuration from each dir :param confdirs: a list of directories where the configuration (.json) files can be found

metadata_from_file(path)[source]

creates metadata from the file :param path: full path to the file :returns the metadata

metadata_from_file_bdb(path)[source]

creates metadata from the file by adding it to the bdb :param path: full path to the file :returns the metadata

metadata_from_file_internal(path)[source]

creates metadata from the file :param path: full path to the file :returns the metadata

post_message(json_message, nodename)[source]

ensures that a posted message arrives to interested parties :param json_message: The json message :type path: string :param nodename: The origin that sent the message

process_conf_dir(d)[source]

process one configuration dir. Will scan for all .json files in provided directory and determine if the files can be used for configuration or not. :param d: a directory containing configuration files

processor_modified(fname, o)[source]

Called when a processor configuration file is modified., :param fname: the filename affected :param o: the actual processor

processor_removed(fname, o)[source]

Called when removing a processor during runtime operation :param fname: the filename affected :param o: the actual processor

publication_modified(fname, o)[source]

Called when a publication configuration file is modified., :param fname: the filename affected :param o: the actual publication

publication_removed(fname, o)[source]

Called when removing a publication during runtime operation :param fname: the filename affected :param o: the actual publication

publish(sid, path, meta)[source]

publishes the file on each interested publisher :param sid: The subscription id if any :param path: full path to the file to be published :param meta: meta of file to be published

read_bdb_sources(odim_source_file)[source]

Reads and parses the odim sources :param odim_source_file: file containing the odim source definitions :returns a list of odim sources

runner_modified(fname, o)[source]

Called when a runner configuration file is modified., :param fname: the filename affected :param o: the actual runner

runner_removed(fname, o)[source]

Called when removing a runner during runtime operation :param fname: the filename affected :param o: the actual runner

storage_modified(fname, o)[source]

Called when a storage configuration file is modified., :param fname: the filename affected :param o: the actual storage

storage_removed(fname, o)[source]

Called when removing a storage during runtime operation :param fname: the filename affected :param o: the actual storage

store_file(path, nid)[source]

handles an incomming file and determines if it should be managed by the subscriptions or not. :param path: the full path to the file to be handled :param nodename: the name/id of the node that the file comes from :returns the metadata from the file

subscription_modified(fname, o)[source]

Called when a subscription configuration file is modified., :param fname: the filename affected :param o: the actual subscription

subscription_removed(fname, o)[source]

Called when removing a subscription during runtime operation :param fname: the filename affected :param o: the actual subscription

class bexchange.server.backend.config_handler(removed, modified, o)[source]

Bases: object

Helper class that is registered for all configuration files so that it is possible to handle runtime changes.

modified(fname)[source]
removed(fname)[source]
class bexchange.server.backend.monitor_conf_dir_inotify_handler(folders, fn_file_written, fn_file_removed)[source]

Bases: ProcessEvent

Helper class to monitor a list of folders containing configuration files. Only will process files ending with .json. Both added and removed events will be forwarded.

FILE_PATTERN = '.+.json$'
MASK = 712
match_file(filename)[source]

Matches the file so that it is following the wanted pattern. Typically *.json. :param filename: the filename that should be verified.

process_IN_CLOSE_WRITE(event)[source]

Will be called by the inotify notifier when file event occurs. :param event: The file event

process_IN_DELETE(event)[source]

Will be called by the inotify notifier when file event occurs. :param event: The file event

process_IN_MOVED_FROM(event)[source]

Will be called by the inotify notifier when file event occurs. :param event: The file event

process_IN_MOVED_TO(event)[source]

Will be called by the inotify notifier when file event occurs. :param event: The file event

run()[source]

The runner for the thread. Starts the inotify notifier loop

start()[source]

Starts the configuration file monitor

bexchange.server.sqlbackend module

class bexchange.server.sqlbackend.SqlAlchemySourceManager(uri='sqlite:///tmp/baltrad-exchange-source.db', poolsize=10)[source]

Bases: object

The DB manager providing source handling :param uri: The uri to database where sources are stored :param poolsize: the size of the db connection pool. In the case of sqlite, this will not be used

add_sources(srclist)[source]

Adds the sources to the source database :param srclist: a list of bdbcommon.oh5.Sources

property driver

database driver name

Type:

return

get_connection()[source]

get a context managed connection to the database

get_parent_source(parent)[source]
Parameters:

parent – The id of the parent.

Returns:

The parent source matching the string in parent.

get_source(meta, add_parent_object=False)[source]
Parameters:
  • meta – The metadata containing source

  • add_parent_object – This is adding a parent to the source. This will modify the bdb Source object by adding the member parent_object.

Returns:

A complete source from the metadata source identifier

init_tables()[source]

Initializes the database tables

insert_source_values(conn, source_id, source)[source]

Inserts kvs values :param conn: connection :param source_id: the unique source id :param source: the source

bexchange.server.sqlbackend.force_sqlite_foreign_keys(dbapi_con, con_record)[source]
bexchange.server.sqlbackend.get_parent_source_id(conn, parent)[source]
bexchange.server.sqlbackend.get_source_by_id(conn, source_id)[source]
bexchange.server.sqlbackend.get_source_id(conn, source)[source]

bexchange.server.subscription module

class bexchange.server.subscription.subscription(storages, subscription_id=None, active=True, ifilter=None, allow_duplicates=False, allowed_ids=[])[source]

Bases: object

allow_duplicates()[source]

:return if duplicates are handled by this subscription or not

allowed_ids()[source]

:return the nodenames

filter()[source]

:return the filter

filter_matching(meta)[source]

Matches the meta against the filter. :param meta: The metadata :return True if filter is None or if metadata matches the filter.

get_statistics_plugins()[source]

:returns the stat plugins belonging to this subscription

id()[source]

:return the subscription id (or None if there is none)

isactive()[source]

:return if this subscription is active or not

set_statistics_plugins(plugins)[source]
setactive(active)[source]

Sets this subscription active or not :param active: If subscription should be set to active or not

storages()[source]

:return the storage names

class bexchange.server.subscription.subscription_manager[source]

Bases: object

classmethod create_subscription(storages, subscription_id, active, ifilter, allow_duplicates, allowed_ids)[source]

Creates a subscription instance :param storages: List of storage names :param subscription_id: Subscription id :param active: If subscription should be set to active or not :param ifilter: A filter instances :param allow_duplicate: If duplicates should be allowed or not :param allowed_ids: A list of ids that should be allowed for this subscription

classmethod from_conf(config, backend)[source]

Module contents