services
Package¶
This module contains the ‘services’ layer in TVB application.
Most of the business logic happens here; which is agnostic of the UI.
algorithm_service
¶
Service layer, for executing computational steps in the application. Code related to launching/duplicating operations is placed here.
- class tvb.core.services.algorithm_service.AlgorithmService[source]¶
Bases:
object
Service Layer for Algorithms manipulation (e.g. find all Uploaders, Filter algo by category, etc)
- static create_link(data_id, project_id)[source]¶
For a list of dataType IDs and a project id create all the required links.
- fill_adapter_form(adapter_instance: ABCAdapter, post_data: dict, project_id: int, user: User) ABCAdapterForm [source]¶
- fill_selectfield_with_datatypes(field: TraitDataTypeSelectField, project_id: int, extra_conditions: list | None = None) None [source]¶
- static get_algorithm_by_identifier(ident)[source]¶
Retrieve Algorithm entity by ID. Return None, if ID is not found in DB.
- static get_algorithm_by_module_and_class(module, classname)[source]¶
Get the db entry from the algorithm table for the given module and class.
- static get_category_by_id(identifier)[source]¶
Pass to DAO the retrieve of category by ID operation.
- get_launchable_algorithms(datatype_gid)[source]¶
- Parameters:
datatype_gid – Filter only algorithms compatible with this GUID
- Returns:
dict(category_name: List AlgorithmTransientGroup)
- static get_operation_numbers(proj_id)[source]¶
Count total number of operations started for current project.
- static get_raw_categories()[source]¶
- Returns:
AlgorithmCategory list of entities that have results in RAW state (Creators/Uploaders)
- static get_selections_for_project(project_id, datatype_gid)[source]¶
Retrieved from DB saved selections for current project. If a certain selection doesn’t have all the labels between the labels of the given connectivity than this selection will not be returned. :returns: List of ConnectivitySelection entities.
- static get_visualisers_category()[source]¶
Retrieve all Algorithm categories, with display capability
- prepare_adapter_form(adapter_instance: ABCAdapter = None, form_instance: ABCAdapterForm = None, project_id: int = None, user: User = None, extra_conditions: [] = None) ABCAdapterForm [source]¶
- static remove_link(dt_id, project_id)[source]¶
Remove the link from the datatype given by dt_id to project given by project_id.
backend_client_factory
¶
burst_config_serialization
¶
Service for serializing a Burst (Simulator) configuration.
- class tvb.core.services.burst_config_serialization.SerializationManager(conf)[source]¶
Bases:
object
Constructs data types based on a burst configuration. Updates the burst configuration.
- static group_parameter_values_by_name(model_parameters_list)[source]¶
- @:param model_parameters_list: Given a list of model parameters like this:
- [{“a”: 2.0, ‘b’: 1.0},
{“a”: 3.0, ‘b’: 7.0}])
- @:return: This method will group them by param name to get:
{‘a’: [2.0, 3.0], ‘b’: [1.0, 7.0]}
burst_service
¶
- class tvb.core.services.burst_service.BurstService[source]¶
Bases:
object
- LAUNCH_BRANCH = 'branch'¶
- LAUNCH_NEW = 'new'¶
- static load_burst_configuration(burst_config_id: int) BurstConfiguration [source]¶
- mark_burst_finished(burst_entity, burst_status=None, error_message=None, store_h5_file=True)[source]¶
Mark Burst status field. Also compute ‘weight’ for current burst: no of operations inside, estimate time on disk…
- Parameters:
burst_entity – BurstConfiguration to be updated, at finish time.
burst_status – BurstConfiguration status. By default BURST_FINISHED
error_message – If given, set the status to error and perpetuate the message.
- persist_operation_state(operation, operation_status, message=None)[source]¶
Update Operation instance state. Store it in DB and on HDD/ :param operation: Operation instance :param operation_status: new status :param message: message in case of error :return: operation instance changed
- static populate_burst_disk_usage(bursts)[source]¶
Adds a disk_usage field to each burst object. The disk usage is computed as the sum of the datatypes generated by a burst
- static prepare_burst_for_pse(burst_config: BurstConfiguration) BurstConfiguration [source]¶
- rename_burst(burst_id, new_name)[source]¶
Rename the burst given by burst_id, setting it’s new name to burst_name.
email_sender
¶
exceptions
¶
Exceptions for services layer of the application.
- exception tvb.core.services.exceptions.BurstServiceException(message, parent_exception=None)[source]¶
Bases:
ServicesBaseException
Exception to be thrown in case of a problem at project import.
- exception tvb.core.services.exceptions.DatatypeGroupImportException(message, parent_exception=None)[source]¶
Bases:
ImportException
Exception to be thrown in case there are issues when importing a datatype group.
- exception tvb.core.services.exceptions.ImportException(message, parent_exception=None)[source]¶
Bases:
ServicesBaseException
Exception to be thrown in case of a problem at project import.
- exception tvb.core.services.exceptions.InvalidSettingsException(message, parent_exception=None)[source]¶
Bases:
ServicesBaseException
Exception to be thrown in case of a problem at project import.
- exception tvb.core.services.exceptions.MissingReferenceException(message, parent_exception=None)[source]¶
Bases:
ImportException
Exception to be thrown in case there are missing references when importing a H5 file.
- exception tvb.core.services.exceptions.OperationException(message, parent_exception=None)[source]¶
Bases:
ServicesBaseException
Exception to be thrown in case of a problem related to Launching and Executing TVB specific Operations.
- exception tvb.core.services.exceptions.ProjectServiceException(message, parent_exception=None)[source]¶
Bases:
ServicesBaseException
Exception to be thrown in case of a problem in the projectservice module.
- exception tvb.core.services.exceptions.RemoveDataTypeException(message, parent_exception=None)[source]¶
Bases:
ServicesBaseException
Exception to be thrown in case some one tries to remove an entity that is used by other entities.
- exception tvb.core.services.exceptions.ServicesBaseException(message, parent_exception=None)[source]¶
Bases:
TVBException
Base Exception class for Services layer in the application.
- exception tvb.core.services.exceptions.StructureException(message, parent_exception=None)[source]¶
Bases:
ServicesBaseException
Exception to be thrown in case of a problem related to Structure Storage.
- exception tvb.core.services.exceptions.UsernameException(message, parent_exception=None)[source]¶
Bases:
ServicesBaseException
Exception to be thrown in case of a problem related to creating or managing a user.
figure_service
¶
Service layer, for storing/retrieving Resulting Figures in TVB.
- class tvb.core.services.figure_service.FigureService[source]¶
Bases:
object
Service layer for Figure entities.
hpc_operation_service
¶
import_service
¶
- class tvb.core.services.import_service.ImportService[source]¶
Bases:
object
Service for importing TVB entities into system. It supports TVB exported H5 files as input, but it should also handle H5 files generated outside of TVB, as long as they respect the same structure.
- build_operation_from_file(project, operation_file)[source]¶
Create Operation entity from metadata file.
- create_view_model(operation_entity, operation_data, new_op_folder, generic_attributes=None, add_params=None)[source]¶
- import_list_of_operations(project, import_path, is_group=False, importer_operation_id=None)[source]¶
This method scans provided folder and identify all operations that needs to be imported
- import_project_structure(uploaded, user_id)[source]¶
Execute import operations:
check if ZIP or folder
find all project nodes
- for each project node:
create project
create all operations and groups
import all images
create all dataTypes
- load_datatype_from_file(current_file: str, op_id: int, datatype_group: DataTypeGroup | None = None, current_project_id: int | None = None) HasTraitsIndex [source]¶
Creates an instance of datatype from storage / H5 file :returns: DatatypeIndex
operation_service
¶
Module in charge with Launching an operation (creating the Operation entity as well, based on gathered parameters).
- class tvb.core.services.operation_service.OperationService[source]¶
Bases:
object
Class responsible for preparing an operation launch. It will prepare parameters, and decide if the operation is to be executed immediately, or to be sent on the cluster.
- ATT_UID = 'uid'¶
- fire_operation(adapter_instance, current_user, project_id, visible=True, view_model=None)[source]¶
Launch an operation, specified by AdapterInstance, for current_user and project with project_id.
- group_operation_launch(user_id, project, algorithm_id, category_id)[source]¶
Create and prepare the launch of a group of operations.
- initiate_operation(current_user, project, adapter_instance, visible=True, model_view=None)[source]¶
Gets the parameters of the computation from the previous inputs form, and launches a computation (on the cluster or locally).
Invoke custom method on an Adapter Instance. Make sure when the operation has finished that the correct results are stored into DB.
- initiate_prelaunch(operation, adapter_instance)[source]¶
Public method. This should be the common point in calling an adapter- method.
- launch_operation(operation_id, send_to_cluster=False, adapter_instance=None)[source]¶
Method exposed for Burst-Workflow related calls. It is used for cascading operation in the same workflow.
- static load_operation(operation_id)[source]¶
Retrieve previously stored Operation from DB, and load operation.burst attribute
- static prepare_metadata(algo_category, burst=None, current_ga=<tvb.core.entities.generic_attributes.GenericAttributes object>)[source]¶
Gather generic_metadata from submitted fields and current to be execute algorithm. Will populate STATE, GROUP, etc in generic_metadata
- prepare_operation(user_id, project, algorithm, visible=True, view_model=None, ranges=None, burst_gid=None, op_group_id=None)[source]¶
Do all the necessary preparations for storing an operation. If it’s the case of a range of values create an operation group and multiple operations for each possible instance from the range.
- static stop_operation(operation_id: int, is_group: bool = False, remove_after_stop: bool = False) bool [source]¶
Stop (also named Cancel) the operation given by operation_id, and potentially also remove it after (with all linked data). In case the Operation has a linked Burst, remove that too. :param operation_id: ID for Operation (or OperationGroup) to be canceled/removed :param is_group: When true stop all the operations from that group. :param remove_after_stop: if True, also remove the operation(s) after stopping :returns True if the stop step was successfully
project_service
¶
Service Layer for the Project entity.
- class tvb.core.services.project_service.ProjectService[source]¶
Bases:
object
Services layer for Project entities.
- static count_filtered_operations(project_id, filters=None)[source]¶
Pass to DAO counters for filtered operations
- static get_all_datatypes_from_data(data)[source]¶
This method builds an array with all data types to be processed later. - If current data is a simple data type is added to an array. - If it is an data type group all its children are loaded and added to array.
- static get_all_operations_for_uploaders(project_id)[source]¶
Returns all finished upload operations.
- static get_datatype_details(datatype_gid)[source]¶
- Returns:
an array. First entry in array is an instance of DataTypeOverlayDetails The second one contains all the possible states for the specified dataType.
- static get_datatype_in_group(group)[source]¶
Return all dataTypes that are the result of the same DTgroup.
- static get_datatypegroup_by_gid(datatypegroup_gid)[source]¶
Returns the DataTypeGroup with the specified gid.
- static get_datatypegroup_by_op_group_id(operation_group_id)[source]¶
Returns the DataTypeGroup with the specified id.
- static get_datatypes_from_datatype_group(datatype_group_id)[source]¶
Retrieve all dataType which are part from the given dataType group.
- static get_filterable_meta()[source]¶
Contains all the attributes by which the user can structure the tree of DataTypes
- static get_linkable_projects_for_user(user_id, data_id)[source]¶
Find projects with are visible for current user, and in which current datatype hasn’t been linked yet.
- get_linked_datatypes_storage_path(project)[source]¶
- Returns:
the file paths to the datatypes that are linked in project
- get_operation_details(operation_gid, is_group)[source]¶
- Returns:
an entity OperationOverlayDetails filled with all information for current operation details.
- static get_operations_in_group(operation_group)[source]¶
Return all the operations from an operation group.
- get_project_structure(project, visibility_filter, first_level, second_level, filter_value)[source]¶
Find all DataTypes (including the linked ones and the groups) relevant for the current project. In case of a problem, will return an empty list.
- static get_results_for_operation(operation_id)[source]¶
Retrieve the DataTypes entities resulted after the execution of the given operation.
- static is_datatype_group(datatype_gid)[source]¶
Used to check if the dataType with the specified GID is a DataTypeGroup.
- static is_upload_operation(operation_gid)[source]¶
Returns True only if the operation with the given GID is an upload operation.
- remove_datatype(project_id, datatype_gid, skip_validation=False, existing_dt_links=None)[source]¶
Method used for removing a dataType. If the given dataType is a DatatypeGroup or a dataType from a DataTypeGroup than this method will remove the entire group. The operation(s) used for creating the dataType(s) will also be removed.
- remove_member_from_project(proj_id, user_id)[source]¶
remove a user from the list of members of that project
- static retrieve_all_user_projects(user_id, page_start=0, page_size=20)[source]¶
Return a list with all projects visible for current user, without pagination.
- retrieve_project_full(project_id, applied_filters=None, current_page=1)[source]¶
Return a Tuple with Project entity and Operations for current Project. :param project_id: Current Project Identifier :param applied_filters: Filters to apply on Operations :param current_page: Number for current page in operations
- retrieve_projects_for_user(user_id, current_page=1)[source]¶
Return a list with all Projects visible for current user.
- static set_datatype_visibility(datatype_gid, is_visible)[source]¶
Sets the dataType visibility. If the given dataType is a dataType group or it is part of a dataType group than this method will set the visibility for each dataType from this group.
- set_operation_and_group_visibility(entity_gid, is_visible, is_operation_group=False)[source]¶
Sets the operation visibility.
If ‘is_operation_group’ is True than this method will change the visibility for all the operation from the OperationGroup with the GID field equal to ‘entity_gid’.
settings_service
¶
Service layer for saving/editing TVB settings.
- class tvb.core.services.settings_service.SettingsService[source]¶
Bases:
object
Handle all TVB Setting related problems, at the service level.
- KEYS_DISPLAY_ORDER = ['ADMINISTRATOR_DISPLAY_NAME', 'ADMINISTRATOR_NAME', 'ADMINISTRATOR_PASSWORD', 'ADMINISTRATOR_EMAIL', None, 'KEYCLOAK_CONFIGURATION', 'ENABLE_KEYCLOAK_LOGIN', 'KEYCLOAK_WEB_CONFIGURATION', None, 'TVB_STORAGE', 'USR_DISK_SPACE', 'SELECTED_DB', 'URL_VALUE', None, 'WEB_SERVER_PORT', None, 'DEPLOY_CLUSTER', 'CLUSTER_SCHEDULER', 'MAXIMUM_NR_OF_THREADS', 'MAXIMUM_NR_OF_OPS_IN_RANGE', 'MAXIMUM_NR_OF_VERTICES_ON_SURFACE']¶
- KEY_ADMIN_DISPLAY_NAME = 'ADMINISTRATOR_DISPLAY_NAME'¶
- KEY_ADMIN_EMAIL = 'ADMINISTRATOR_EMAIL'¶
- KEY_ADMIN_NAME = 'ADMINISTRATOR_NAME'¶
- KEY_ADMIN_PWD = 'ADMINISTRATOR_PASSWORD'¶
- KEY_CLUSTER = 'DEPLOY_CLUSTER'¶
- KEY_CLUSTER_SCHEDULER = 'CLUSTER_SCHEDULER'¶
- KEY_DB_URL = 'URL_VALUE'¶
- KEY_ENABLE_KC_LOGIN = 'ENABLE_KEYCLOAK_LOGIN'¶
- KEY_KC_CONFIG = 'KEYCLOAK_CONFIGURATION'¶
- KEY_KC_WEB_CONFIG = 'KEYCLOAK_WEB_CONFIGURATION'¶
- KEY_MAX_DISK_SPACE_USR = 'USR_DISK_SPACE'¶
- KEY_MAX_NR_SURFACE_VERTEX = 'MAXIMUM_NR_OF_VERTICES_ON_SURFACE'¶
- KEY_MAX_NR_THREADS = 'MAXIMUM_NR_OF_THREADS'¶
- KEY_MAX_RANGE = 'MAXIMUM_NR_OF_OPS_IN_RANGE'¶
- KEY_PORT = 'WEB_SERVER_PORT'¶
- KEY_SELECTED_DB = 'SELECTED_DB'¶
- KEY_STORAGE = 'TVB_STORAGE'¶
simulator_service
¶
- class tvb.core.services.simulator_service.SimulatorService[source]¶
Bases:
object
- async_launch_and_prepare_pse(burst_config, user, project, simulator_algo, range_param1, range_param2, session_stored_simulator)[source]¶
- async_launch_and_prepare_simulation(burst_config, user, project, simulator_algo, simulator)[source]¶
- reset_at_connectivity_change(is_simulator_copy, form, session_stored_simulator)[source]¶
In case the user copies a simulation and changes the Connectivity, we want to reset the Model and Noise parameters because they might not fit to the new Connectivity’s nr of regions.
texture_to_json
¶
Converts a color scheme texture image to json arrays
- tvb.core.services.texture_to_json.color_texture_to_list(img_pth, img_width, band_height)[source]¶
- Parameters:
img_pth – Path to the texure
img_width – Texture width
band_height – Height of a color scheme band
- Returns:
A list of img_width/band_height color schemes. A scheme is a list of img_width colors
user_service
¶
Service layer for USER entities.
- class tvb.core.services.user_service.UserService[source]¶
Bases:
object
CRUD methods for USER entities are here.
- USER_ROLES = ['ADMINISTRATOR', 'CLINICIAN', 'RESEARCHER']¶
- static check_login(username, password)[source]¶
Service layer to check if given UserName and Password are according to DB.
- create_user(username=None, display_name=None, password=None, password2=None, role=None, email=None, comment=None, email_msg=None, validated=False, skip_import=False, gid=None, skip_sending_email=False)[source]¶
Service Layer for creating a new user.
- delete_user(user_id)[source]¶
Delete a user with a given ID. Return True when successfully, or False.
- edit_user(edited_user, old_password=None)[source]¶
Retrieve a user by and id, then modify it’s role and validate status.
- static get_administrators()[source]¶
Retrieve system administrators. Will be used for sending emails, for example.
- get_users_for_project(user_name, project_id, page=1)[source]¶
Return tuple: (All Users except the project administrator, Project Members). Parameter “user_name” is the current user. Parameter “user_name” is used for new projects (project_id is None). When “project_id” not None, parameter “user_name” is ignored.
- static is_username_valid(name)[source]¶
Service layer for checking if a given UserName is unique or not.
- static retrieve_users_except(usernames: list, current_page: int, page_size: int)[source]¶
Return all users from the database except the given users
Subpackages¶
backend_clients
Packagebackend_client
cluster_scheduler_client
hpc_scheduler_client
HPCJobStatus
HPCOperationThread
HPCSchedulerClient
HPCSchedulerClient.CONTAINER_INPUT_FOLDER
HPCSchedulerClient.CSCS_DATA_FOLDER
HPCSchedulerClient.CSCS_LOGIN_TOKEN_ENV_KEY
HPCSchedulerClient.CSCS_PROJECT
HPCSchedulerClient.HOME_FOLDER_MOUNT
HPCSchedulerClient.OUTPUT_FOLDER
HPCSchedulerClient.TVB_BIN_ENV_KEY
HPCSchedulerClient.compute_available_disk_space()
HPCSchedulerClient.execute()
HPCSchedulerClient.stage_out_to_operation_folder()
HPCSchedulerClient.stop_operation()
HPCSchedulerClient.storage_interface
HPCSchedulerClient.update_datatype_groups()
HPCSchedulerClient.update_db_with_results()
get_op_thread()
standalone_client