Architecture
OPUS is two programs joined by one database. The import pipeline writes the database from
the PDS holdings; the Django application reads it and answers requests. Nothing flows the
other way – the web application never writes an obs_ table – and the two share only
opus_config, opus_support, and their understanding of what the tables mean.
This is the one-page map. Read it before either subsystem’s chapters: The Import Pipeline for the pipeline, The Web Application for the application.
flowchart LR
holdings[(PDS3 and PDS4 holdings)]
import[opus_import]
db[(MySQL: the OPUS database)]
app[opus_app]
user([A scientist, or a program using the API])
logs[(Apache access logs)]
analyzer[opus_log_analyzer]
holdings --> import
import --> db
db --> app
app --> user
user --> app
app --> logs
logs --> analyzer
The import pipeline
An import run turns one PDS index file into one row per observation in each of the tables that observation belongs to.
flowchart TD
A[A bundle descriptor on the command line] --> B[config_bundle_info:<br/>which index files and which obs class]
B --> C[pdstable / pdsfile:<br/>read the primary index and its supplements]
C --> D[One obs class instance for the bundle]
D --> E[For each index row:<br/>replace the metadata, then call one<br/>field_obs_table_column method per column]
E -->|each bundle deleted, then loaded:<br/>a fresh import or an append| G[(Observation tables: obs_*, mult, mult_field, mult_group)]
G -->|finalization| H[(Auxiliary tables:<br/>param_info, table_names, partables)]
There is one set of tables, and every import writes into it. An import into a schema
that is not served yet – one with no schema_version row – is a fresh import: the
observation tables are created with only the keys a load needs, and finalization adds the
remaining keys once at the end. An import into a finished schema is an append, into
the tables with their keys in place; it marks the schema appending first, so a web
application that loads it refuses to serve it until finalization has run again and the
schema is marked ready. On both paths each bundle is deleted before it is loaded, and a
bundle registry keeps a schema with an unfinished bundle from being finalized or marked
ready.
The two write paths is the whole of it.
A served schema is updated by generation: the bundles that changed are written into
it as a pending generation, which the obs_general view hides until a switch, while the
web service is stopped, serves it whole. The rows it replaced stay until a purge, so the
switch can be reverted until then (Generations: nothing is served until it is finished).
The auxiliary tables are built after the observation tables, but only param_info is
derived from what was imported. table_names lists the observation tables that
actually exist, while partables walks the configuration maps alone, so a mission that was never
imported still gets a partables row.
The Import Steps states the order the steps run in, what forces each part of it, and what each auxiliary table is built from.
The obs class hierarchy
The pipeline’s largest structure is the family of classes that computes a column’s value, and The Obs Class Hierarchy is where it is described. The family’s shape is five layers, root outward:
Layer |
Answers |
|---|---|
What every observation shares, plus the questions only a PDS version or an instrument can answer. |
|
The PDS-version bases |
What PDS3 and PDS4 decide. |
One module per OPUS table |
That table’s field methods. |
One module per mission |
What an instrument’s archives share. |
One module per bundle or volume set |
How one particular archive spells things. |
The Obs Class Hierarchy has the class diagram, the contracts and the method resolution order; The Obs Classes, Mission by Mission catalogs every mission and leaf class.
The web application
A request arrives at one of the routes opus_app.urls assembles, is answered by a
view, and – for anything that searches – reaches the database through the rows of
search_results stored once for each distinct search.
flowchart TD
R([HTTP request]) --> U[opus_app.urls:<br/>each app contributes its routes]
U --> V[The view, wrapped in api_view]
V --> P[url_to_search_params:<br/>the query string becomes<br/>selections and extras]
P --> Q[get_search_id:<br/>register the search, and write<br/>its results once]
Q --> S[sql_builder.Select:<br/>join the obs_ tables and mult]
S --> D[(MySQL)]
D --> F[Format as JSON, CSV or HTML]
F --> RESP([HTTP response])
V -.->|no search| F
Three parts of that flow are worth knowing before changing any of it, and each has a chapter of its own.
Every handler that answers an API call is wrapped in
api_view(). It records the call, turns an
Http400Error raised anywhere inside the handler
into an HTTP 400, turns any other unhandled exception into an HTTP 500 logged with its
traceback, and applies the fault-injection knobs the configuration file carries. The
exceptions Django answers specifically are re-raised rather than absorbed, so each keeps
the response and the logging Django gives it. Errors is the
detail.
A search becomes rows of search_results.
url_to_search_params() turns the query string into the
two dictionaries the rest of the search code works with, and
get_search_id() then registers the search in
user_searches and, the first time anyone makes it, writes the ids of the matching
observations into search_results in sort order. Every later query – a page of
results, a count, a set of file URLs – joins against those rows rather than re-running
the search. How a search becomes rows walks all four
steps.
The wide joins are assembled, not written.
opus_app.apps.tools.sql_builder builds the statements that join the obs_
tables to each other and to the mult table holding their enumerated values. Values
are always passed as parameters, and identifiers are validated before they are quoted.
opus_app.apps.tools.sql_builder says what that buys and where the two
exceptions are.
The Django apps are described across The Shared Machinery: the tools App, The search App, Reading a Search: the results, metadata and cart Apps and The Interface: the ui, help and paraminfo Apps.
The database
The Database Schema describes every table OPUS uses and what each column means. The two ideas to carry into any other chapter:
An
obs_*table corresponds one-for-one to a “Constraints” category in the user interface, and a row is one observation.obs_generalis the master table: every observation has a row there, and every other table’s rows hang off it. It is a view of the served generation’s rows of the base tableobs_general_rows.A field whose value comes from a fixed set stores the integer id of a row of the
multtable rather than the value itself, which is what makes the checkbox searches fast. Each such field’s values carry itsfield_idfrommult_field, andmult_groupholds its groups. Table Schemas describes how a column declares that.
What each subsystem owns
The division of responsibility, in one table, because several questions turn on it:
Thing |
Written by |
Read by |
|---|---|---|
The |
the import pipeline |
the web application |
|
the import pipeline |
the web application |
|
the import pipeline |
the web application |
|
the web application (created by the import) |
the web application |
|
the web application (created and reset by the import, pruned by
|
the web application |
Django’s contrib tables |
|
Django |
|
a script, from a populated database |
the web application |
Nothing in the pipeline imports opus_app, and nothing in the application imports
opus_import. The two shared packages are what they agree through:
opus_config for the installation’s settings, and opus_support for the unit,
time and angle conversions both have to perform identically. The Configuration File and
The opus_support Module describe them.