openquake.server package#
Subpackages#
- openquake.server.db package
- openquake.server.db.actions module
Listadd_tag_to_job()calc_info()check_outdated()create_job()create_outputs()create_tag()db_version()del_calc()delete_tag()delete_uncompleted_calculations()engine_version()find()finish()get_calc_ids()get_calcs()get_checksum_from_job()get_executing_jobs()get_job()get_job_from_checksum()get_job_id_from_checksum()get_job_stats()get_jobs()get_jobs_by_date()get_log()get_log_size()get_log_slice()get_longest_jobs()get_output()get_outputs()get_preferred_job_for_tag()get_result()get_results()get_running_jobs()get_traceback()get_uncompleted_jobs()get_weight()has_job_table()import_job()keep()list_calculations()list_outputs()list_tags()log()remove_tag_from_job()reset_is_running()set_aborted()set_preferred_job_for_tag()set_status()share_job()unset_preferred_job_for_tag()update_job()update_job_checksum()update_parent_child()upgrade_db()what_if_I_upgrade()
- openquake.server.db.upgrade_manager module
DuplicatedVersionUpgradeManagerUpgradeManager.ENGINE_URLUpgradeManager.UPGRADESUpgradeManager.check_versions()UpgradeManager.extract_upgrade_scripts()UpgradeManager.get_db_versions()UpgradeManager.init()UpgradeManager.install_versioning()UpgradeManager.instance()UpgradeManager.parse_script_name()UpgradeManager.read_scripts()UpgradeManager.upgrade()
VersionTooSmallVersioningNotInstalledWrappedConnectionapply_sql_script()check_script()db_version()upgrade_db()what_if_I_upgrade()
- Module contents
- openquake.server.db.actions module
- openquake.server.webui package
Submodules#
openquake.server.manage module#
openquake.server.middleware module#
- class openquake.server.middleware.LoginRequiredMiddleware(get_response)[source]#
Bases:
objectMiddleware that requires a user to be authenticated to view any page other than LOGIN_URL. Exemptions to this requirement can be specified in settings via a list of regular expressions in LOGIN_EXEMPT_URLS.
Requires authentication middleware and template context processors to be loaded. You’ll get an error if they aren’t.
openquake.server.settings module#
openquake.server.urls module#
openquake.server.utils module#
- openquake.server.utils.check_webserver_running(url='http://localhost:8800', max_retries=30, warn=True)[source]#
Returns True if a given URL is responding within a given timeout.
- openquake.server.utils.get_acl_on(request)[source]#
Returns True if ACL should be honorated, returns otherwise False.
- openquake.server.utils.get_username(request)[source]#
Returns the users from request if authentication is enabled, otherwise returns the default user (from settings, or as reported by the OS).
- openquake.server.utils.get_valid_users(request)[source]#
” Returns a list of users based on groups membership. Returns a list made of a single user when it is not member of any group.
- openquake.server.utils.is_superuser(request)[source]#
Without authentication (settings.LOCKDOW is false) every user is considered a superuser, otherwise look at the attribute request.user.is_superuser.
openquake.server.views module#
- openquake.server.views.build_impact_resources(request, calc_id, dstore)[source]#
Describe impact resources and their presentation URLs.
- openquake.server.views.determine_precision(weights)[source]#
Determine the minimum decimal places needed to represent the weights accurately
- openquake.server.views.get_impact_rupture_data(post, user, rupture_path)[source]#
Validate a rupture and build the data needed by the IMPACT UI.
- openquake.server.views.group_keys_by_value(d)[source]#
Groups keys from the input dictionary by their shared values. If a value is shared by multiple keys, those keys are grouped into a tuple. Otherwise, the key is kept as-is.
- Parameters:
d – a dictionary with hashable keys and values
- Returns:
a dictionary where keys are either individual keys or tuples of keys that shared the same value, and values are the original values
- Example:
>>> group_keys_by_value({0: 'a', 1: 'b', 2: 'a'}) {(0, 2): 'a', 1: 'b'}
- openquake.server.views.save_pik(job, dirname)[source]#
Save a LogContext object in pickled format; returns the path to it
- openquake.server.views.stream_response(fname, content_type, exportname='')[source]#
Stream a file stored in a temporary directory via Django
- openquake.server.views.submit_job(request_files, ini, username, hc_id, notify_to=None)[source]#
Create a job object from the given files and run it in a new process.
- Returns:
a job ID
- openquake.server.views.v1_calc_info(request, calc_id)[source]#
Return the information about a calculation.
openquake.server.internal_api module#
Internal API of the engine, i.e. the API used only by the processes of the
engine itself and protected by the key in the authkey of the
[webapi] section of openquake.cfg. It contains the machinery to write
the views checking the key (internal_view()), the database and worker
actions of the /v0 API and the plumbing of the other views.
This module does not import openquake.server.services nor the views,
which import it.
- exception openquake.server.internal_api.ApiError(status, detail=None, content=None)[source]#
Bases:
ExceptionError returned to the caller with the given HTTP status.
- openquake.server.internal_api.db_action(action, payload)[source]#
Execute an allowlisted database action.
- openquake.server.internal_api.has_api_key(request)[source]#
Return whether the request carries the internal API key.
- openquake.server.internal_api.internal_view(*methods, auth=True)[source]#
Turn a function of the request into a Django view accepting only the given HTTP methods. The view is exempt from CSRF checks, since the callers are programs, and it requires the internal API key unless
authis false.
- openquake.server.internal_api.json_response(data, status=200)[source]#
Return a JSON response, converting dates and numpy scalars.
- openquake.server.internal_api.make_form(*sources)[source]#
Merge plain fields (dictionaries or QueryDicts) and uploaded files into a single MultiValueDict, the form accepted by the internal functions.
- openquake.server.internal_api.run(func, *args, **kwargs)[source]#
Call an internal API function and return its response. The errors raised as
ApiErroror asdbapi.NotFoundbecome JSON error responses, while a returned HTTP response is passed unchanged.
- openquake.server.internal_api.v0_db_action(request, action)[source]#
Execute an allowlisted database action.
openquake.server.services module#
The logic of the WebUI, called in-process by openquake.server.views:
running, aborting and removing calculations, reading their logs and
exporting their results, the AELO and IMPACT runs and their notifications.
The functions raise openquake.server.internal_api.ApiError on
failure, which openquake.server.internal_api.run() turns into a JSON
response.
- openquake.server.services.DEFAULT_EXPORT_TYPE = 'xml'#
For exporting calculation outputs, the client can request a specific format (xml, geojson, csv, etc.). If the client does not specify, give them (NRML) XML by default.
- class openquake.server.services.ExportResponse(fname, **kwargs)[source]#
Bases:
FileResponseStream an exported file and remove its directory once closed.
- openquake.server.services.aelo_callback(job_id, job_owner_email, outputs_uri, inputs, exc=None, warnings=None, email_file_path=None)[source]#
- openquake.server.services.calc_list_count(params, valid_users, acl_on)[source]#
Count the calculations matching the filters of the list view.
- openquake.server.services.calc_log(calc_id, start, stop)[source]#
Return a slice of the log of a calculation.
- openquake.server.services.calc_log_size(calc_id)[source]#
Return the number of log lines of a calculation.
- openquake.server.services.calc_remove(calc_id, username)[source]#
Remove a calculation on behalf of its owner.
- openquake.server.services.calc_result(result_id, export_type=None)[source]#
Export a result in the requested format, as a downloadable file.
- openquake.server.services.calc_run(form)[source]#
Submit a calculation, using the archive in the form if present.
- openquake.server.services.create_impact_job(params, username, job_owner_email, build_urls, callback, email_file_path)[source]#
Create and start an IMPACT job using injected adapters.
- openquake.server.services.export_result(result_id, export_type=None)[source]#
Export a calculation result in the requested format.
- Parameters:
result_id – ID of the result to export
export_type – export format, NRML XML by default
- Returns:
a triple (fname, content_type, exportname) where fname is the path of a file inside a fresh temporary directory, or None if the result cannot be exported in the given format
- Raises:
DataStoreExportError if the export fails
- openquake.server.services.get_impact_resource_data(dstore)[source]#
Return available IMPACT resources without presentation URLs.
- openquake.server.services.get_impact_rupture_data(post, user, rupture_path)[source]#
Validate a rupture and build the data needed by the IMPACT UI.
- openquake.server.services.get_papers_job_ctx(papers, rup_id, form)[source]#
Build a PAPERS job context using an injected papers adapter.
- openquake.server.services.get_uploaded_file_path(files, filename)[source]#
Copy an uploaded file to a temporary path and return its location.
- openquake.server.services.impact_callback(job_id, params, job_owner_email, outputs_uri, exc=None, warnings=None, email_file_path=None)[source]#
- openquake.server.services.impact_get_rupture_data(form)[source]#
Build the rupture data of an IMPACT job from the given form.
- openquake.server.services.model_provenance(calc_id)[source]#
Return the model provenance of a calculation.
- openquake.server.services.remove_exported(fname)[source]#
Remove the temporary directory containing an exported file.
- openquake.server.services.run_aelo(lon, lat, site_name, asce_version, site_class, vs30, username, job_owner_email, build_urls, callback, email_file_path)[source]#
Create and start an AELO job using injected URL and callback helpers.
- openquake.server.services.run_scenario_calc_from_ses_rupture(rup_id, form)[source]#
Run a PAPERS scenario calculation for an SES rupture.
- openquake.server.services.save_pik(job, dirname)[source]#
Save a calculation job context for an external submit command.
- openquake.server.services.store(request_files, ini, calc_id)[source]#
Store the uploaded files in calc_dir and select the job file by looking at the .ini extension.
- Returns:
full path of the ini file
- openquake.server.services.submit_job(request_files, ini, username, hc_id, notify_to=None)[source]#
Create a calculation job and submit it without Django dependencies.
- openquake.server.services.validate_aelo_data(post, form_labels, max_site_name_length)[source]#
Validate AELO form data without depending on Django.