| 1 |
<resource resdir="__system" schema="dc"> |
| 2 |
<meta name="creationDate">2013-07-26T10:00:00</meta> |
| 3 |
<meta name="description">The datalink response structure, and |
| 4 |
the management table for async datalink jobs. For the STREAMs |
| 5 |
that have been here in previous DaCHS versions, see //soda. |
| 6 |
</meta> |
| 7 |
<meta name="subject">virtual-observatories</meta> |
| 8 |
|
| 9 |
<table id="dlresponse"> |
| 10 |
<meta name="description">Data links for data sets.</meta> |
| 11 |
<column name="ID" type="text" |
| 12 |
ucd="meta.id;meta.main" |
| 13 |
tablehead="PubDID" |
| 14 |
description="Publisher data set id; this is an identifier for |
| 15 |
the dataset in question and can be used to retrieve the data." |
| 16 |
verbLevel="1"/> |
| 17 |
<column name="access_url" type="text" |
| 18 |
ucd="meta.ref.url" |
| 19 |
tablehead="URL" |
| 20 |
description="URL to retrieve the data or access the service." |
| 21 |
verbLevel="1" displayHint="type=url"/> |
| 22 |
<column name="service_def" type="text" |
| 23 |
ucd="meta.ref" |
| 24 |
tablehead="Svc. Type" |
| 25 |
description="Identifier for the type of service if accessURL refers |
| 26 |
to a service." |
| 27 |
verbLevel="1"/> |
| 28 |
<column name="error_message" type="text" |
| 29 |
ucd="meta.code.error" |
| 30 |
tablehead="Why not?" |
| 31 |
description="If accessURL is empty, this column gives the reason why." |
| 32 |
verbLevel="20"/> |
| 33 |
<column name="description" type="text" |
| 34 |
ucd="meta.note" |
| 35 |
tablehead="Description" |
| 36 |
description="More information on this link" |
| 37 |
verbLevel="1"/> |
| 38 |
<column name="semantics" type="text" |
| 39 |
ucd="meta.code" |
| 40 |
tablehead="What?" |
| 41 |
description="What kind of data is linked here? Standard identifiers |
| 42 |
here include science, calibration, preview, info, auxiliary" |
| 43 |
verbLevel="1"/> |
| 44 |
<column name="content_type" type="text" |
| 45 |
ucd="meta.code.mime" |
| 46 |
tablehead="M. Type" |
| 47 |
description="Media type for the data returned." |
| 48 |
verbLevel="1"/> |
| 49 |
<column name="content_length" type="bigint" |
| 50 |
ucd="phys.size;meta.file" unit="byte" |
| 51 |
tablehead="Size" |
| 52 |
description="Size of the resource at access_url." |
| 53 |
verbLevel="1"> |
| 54 |
<values nullLiteral="-1"/> |
| 55 |
</column> |
| 56 |
<column name="local_semantics" type="text" |
| 57 |
ucd="meta.id.assoc" |
| 58 |
description="An identifier that allows clients to associate rows from |
| 59 |
different datalink documents on the same service with each other." |
| 60 |
verbLevel="1"/> |
| 61 |
<column name="content_qualifier" type="text" |
| 62 |
description="An identifier for the sort of content obtained by |
| 63 |
dereferencing the link (e.g., spectrum, image, or cube). Terms |
| 64 |
here are relative to http://www.ivoa.net/rdf/product-type" |
| 65 |
verbLevel="1"/> |
| 66 |
</table> |
| 67 |
|
| 68 |
<data id="make_response" auto="False"> |
| 69 |
<!-- this data build a datalink response table out of LinkDefs. |
| 70 |
The input parameters for the computational part are built in |
| 71 |
within datalink.getDatalinkDescriptionResource. --> |
| 72 |
<embeddedGrammar> |
| 73 |
<iterator> |
| 74 |
<code> |
| 75 |
for linkDef in self.sourceToken: |
| 76 |
yield linkDef.asDict() |
| 77 |
</code> |
| 78 |
</iterator> |
| 79 |
</embeddedGrammar> |
| 80 |
|
| 81 |
<make table="dlresponse"/> |
| 82 |
</data> |
| 83 |
|
| 84 |
<!-- ************************************* generic datalink objects --> |
| 85 |
<procDef type="descriptorGenerator" id="fromtable"> |
| 86 |
<doc>A descriptor generator simply pulling a row from a database |
| 87 |
table. This row is made available as the ``.metadata`` attribute. |
| 88 |
You also must give a field that the generator will pull a URL |
| 89 |
from; the generator arranges things so that the default dlget will |
| 90 |
simply redirect there. |
| 91 |
|
| 92 |
Note that the #this and #preview links DaCHS normally makes |
| 93 |
for descriptors from products are not added automatically here. Try |
| 94 |
to at least provide #this. |
| 95 |
|
| 96 |
See also `Non-Product descriptor Generators`_. |
| 97 |
|
| 98 |
Since DaCHS 2.13, you can define a function ``addExtras(descriptor)`` in |
| 99 |
a setup element and add attributes as necessary. |
| 100 |
|
| 101 |
*Since version 2.4.* |
| 102 |
</doc> |
| 103 |
|
| 104 |
<setup imports="inspect, contextlib, gavo.protocols.datalink, |
| 105 |
gavo.svcs"> |
| 106 |
<par key="tableName" description="The name of the table to pull the |
| 107 |
metadata row from (as a python value)." late="True"/> |
| 108 |
<par key="idColumn" description="The name of the table column to |
| 109 |
match the ID against (as a python value)." late="True"/> |
| 110 |
<par key="didPrefix" description="A URI to complete an identifier |
| 111 |
with with if it looks like a non-URI. Leave empty to |
| 112 |
not do pubDID completion." late="True">base.NotGiven</par> |
| 113 |
<code> |
| 114 |
class FromrowDescriptor(datalink.DatalinkDescriptorMixin): |
| 115 |
"""a datalink descriptor just encapsulating a row from |
| 116 |
an arbitrary table. |
| 117 |
|
| 118 |
These have, as usual, pubDID and data, where data by default |
| 119 |
is just something redirecting to dataURL (or does a 404 if |
| 120 |
dataURL is NotGiven). |
| 121 |
|
| 122 |
The row matched is available in the metadata attribute. |
| 123 |
|
| 124 |
You'll usually construct these through its fromDB class |
| 125 |
method. |
| 126 |
""" |
| 127 |
suppressAutoLinks = True |
| 128 |
data = None |
| 129 |
forSemantics = soda.DEFAULT_SEMANTICS |
| 130 |
|
| 131 |
def __init__(self, pubDID, metadataRow): |
| 132 |
self.pubDID, self.metadata = pubDID, metadataRow |
| 133 |
|
| 134 |
@classmethod |
| 135 |
def fromDB(cls, did, tableName, idColumn): |
| 136 |
if not re.match(r"[\\w_.]+$", tableName): |
| 137 |
raise base.StructError(f"Invalid table name {tableName}") |
| 138 |
if not re.match(r"[\\w_.]+$", idColumn): |
| 139 |
raise base.StructError(f"Invalid column name {idColumn}") |
| 140 |
|
| 141 |
with base.getTableConn() as conn: |
| 142 |
rows = list(conn.queryToDicts( |
| 143 |
f"select * from {tableName} where {idColumn}=%(did)s", |
| 144 |
locals())) |
| 145 |
|
| 146 |
if not rows: |
| 147 |
raise svcs.UnknownURI(f"No dataset with id {did} known here") |
| 148 |
if len(rows)>1: |
| 149 |
raise base.ReportableError( |
| 150 |
f"Multiple datasets matched for {did}. Bailing out.", |
| 151 |
hint="This is always an operator error – whatever is" |
| 152 |
" used as an ID in datalink must be a primary key" |
| 153 |
" in the managing table.") |
| 154 |
|
| 155 |
return cls(did, rows[0]) |
| 156 |
</code> |
| 157 |
</setup> |
| 158 |
<code> |
| 159 |
if didPrefix: |
| 160 |
if not "://" in pubDID: |
| 161 |
pubDID = didPrefix+pubDID |
| 162 |
|
| 163 |
desc = FromrowDescriptor.fromDB(pubDID, tableName, idColumn) |
| 164 |
if "addExtras" in globals(): |
| 165 |
addExtras(desc) |
| 166 |
|
| 167 |
return desc |
| 168 |
</code> |
| 169 |
</procDef> |
| 170 |
|
| 171 |
|
| 172 |
<!-- ************************************************ async support --> |
| 173 |
|
| 174 |
<table id="datalinkjobs" onDisk="True" system="True"> |
| 175 |
<meta name="description">A table managing datalink jobs submitted |
| 176 |
asynchronously (the dlasync renderer)</meta> |
| 177 |
|
| 178 |
<FEED source="//uws#uwsfields"/> |
| 179 |
<column name="pid" type="integer" |
| 180 |
description="A unix pid to kill to make the job stop"> |
| 181 |
<values nullLiteral="-1"/> |
| 182 |
</column> |
| 183 |
</table> |
| 184 |
|
| 185 |
<data id="import"> |
| 186 |
<make table="datalinkjobs"/> |
| 187 |
</data> |
| 188 |
|
| 189 |
</resource> |