|
| 1 | +# Data Directory and Filepath Lookup |
| 2 | + |
| 3 | +Service to provide consistent file numbering and naming for unrelated data |
| 4 | +acquisition applications. |
| 5 | + |
| 6 | +## Running Locally |
| 7 | + |
| 8 | +The service is written in rust and requires the default toolchain and recent |
| 9 | +version of the compiler (1.81+). This is available from [rustup.rs][_rustup]. |
| 10 | + |
| 11 | +[_rustup]:https://rustup.rs |
| 12 | + |
| 13 | +1. Clone this repository |
| 14 | + |
| 15 | + ``` |
| 16 | + $ git clone [email protected]:DiamondLightSource/data-endpoint-lookup.git |
| 17 | + Cloning into 'data-endpoint-lookup'... |
| 18 | + ... |
| 19 | + $ cd data-endpoint-lookup |
| 20 | + ``` |
| 21 | +
|
| 22 | +2. Build the project |
| 23 | +
|
| 24 | + ``` |
| 25 | + $ cargo build |
| 26 | + Compiling numtracker v0.1.0 (./path/to/data-endpoint-lookup) |
| 27 | + ... |
| 28 | + Finished 'dev' profile [unoptimized + debuginfo] target(s) in 11.56s |
| 29 | + ``` |
| 30 | +3. Run the service |
| 31 | +
|
| 32 | + ``` |
| 33 | + $ cargo run serve |
| 34 | + 2024-11-04T11:29:05.887214Z INFO connect{filename="numtracker.db"}: numtracker::db_service: Connecting to SQLite DB |
| 35 | + ``` |
| 36 | +
|
| 37 | +At this point the service is running and can be queried via the graphQL |
| 38 | +endpoints (see [the graphiql][_graphiql] front-end available at |
| 39 | +`localhost:8000/graphiql` by default) but there are no beamlines configured. |
| 40 | +
|
| 41 | +Additional logging output is available via `-v` verbose flags. |
| 42 | +
|
| 43 | +|Flags |Level| |
| 44 | +|--------|-----| |
| 45 | +| `-q` |None | |
| 46 | +| |Error| |
| 47 | +| `-v` |Info | |
| 48 | +| `-vv` |Debug| |
| 49 | +| `-vvv` |Trace| |
| 50 | +
|
| 51 | +## Schema |
| 52 | +
|
| 53 | +The schema is available via the `schema` command. This is also available via the |
| 54 | +graphiql interface. |
| 55 | +```bash |
| 56 | +cargo run schema |
| 57 | +``` |
| 58 | + |
| 59 | +## Queries |
| 60 | + |
| 61 | +<details> |
| 62 | +<summary>Testing queries from terminal</summary> |
| 63 | + |
| 64 | +While the graphiql front-end can be useful for exploring the API schema, running |
| 65 | +from the terminal is sometimes quicker/easier. This only requires `curl` |
| 66 | +although <a href="https://jqlang.github.io/jq/">jq</a> can make it |
| 67 | +easier to parse output. |
| 68 | + |
| 69 | +The query to run should be made as a POST request to `/graphql` wrapped in a |
| 70 | +JSON object as `{"query": "<query-string>"}` taking care to escape quotes as |
| 71 | +required. Using `curl` and a basic visit directory query (see below), this |
| 72 | +looks something like |
| 73 | +```bash |
| 74 | +echo '{ 17:15:56 |
| 75 | + "query": "{ |
| 76 | + paths(beamline: \"i22\", visit: \"cm37278-5\") { |
| 77 | + directory |
| 78 | + } |
| 79 | + }" |
| 80 | + }'| curl -s -X POST 127.0.0.1:8000/graphql -H "Content-Type: application/json" -d @- | jq |
| 81 | +``` |
| 82 | + |
| 83 | +</details> |
| 84 | + |
| 85 | +### Queries (read-only) |
| 86 | +There are two read only queries, one to get the visit directory for a given |
| 87 | +visit and beamline and one to get the current configuration for a given |
| 88 | +beamline. |
| 89 | + |
| 90 | +#### paths |
| 91 | +Get the visit directory for a beamline and visit |
| 92 | + |
| 93 | +##### Query |
| 94 | +```json |
| 95 | +{ |
| 96 | + paths(beamline: "i22", visit: "cm12345-6") { |
| 97 | + directory |
| 98 | + visit |
| 99 | + } |
| 100 | +} |
| 101 | +``` |
| 102 | +##### Response |
| 103 | +```json |
| 104 | +{ |
| 105 | + "paths": { |
| 106 | + "directory": "/data/i22/data/2024/cm37278-5", |
| 107 | + "visit": "cm37278-5" |
| 108 | + } |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +#### configuration |
| 113 | +Get the current configuration values for the given beamline |
| 114 | + |
| 115 | +##### Query |
| 116 | +```graphql |
| 117 | +{ |
| 118 | + configuration(beamline: "i22") { |
| 119 | + visitTemplate |
| 120 | + scanTemplate |
| 121 | + detectorTemplate |
| 122 | + latestScanNumber |
| 123 | + } |
| 124 | +} |
| 125 | +``` |
| 126 | + |
| 127 | +##### Response |
| 128 | +```json |
| 129 | +{ |
| 130 | + "configuration": { |
| 131 | + "visitTemplate": "/data/{instrument}/data/{year}/{visit}", |
| 132 | + "scanTemplate": "{subdirectory}/{instrument}-{scan_number}", |
| 133 | + "detectorTemplate": "{subdirectory}/{instrument}-{scan_number}-{detector}", |
| 134 | + "latestScanNumber": 20839 |
| 135 | + } |
| 136 | +} |
| 137 | +``` |
| 138 | + |
| 139 | +## Mutations (read-write) |
| 140 | + |
| 141 | +#### scan |
| 142 | + |
| 143 | +##### Query |
| 144 | + |
| 145 | +``` |
| 146 | +mutation { |
| 147 | + scan(beamline: "i22", visit: "cm12345-2", subdirectory: "sub/tree") { |
| 148 | + scanFile |
| 149 | + scanNumber |
| 150 | + detectors(names: ["det1", "det2"] ) { |
| 151 | + name |
| 152 | + path |
| 153 | + } |
| 154 | + } |
| 155 | +} |
| 156 | +``` |
| 157 | + |
| 158 | +##### Response |
| 159 | +```json |
| 160 | +{ |
| 161 | + "scan": { |
| 162 | + "scanFile": "sub/tree/i22-20840", |
| 163 | + "scanNumber": 20840, |
| 164 | + "detectors": [ |
| 165 | + { |
| 166 | + "name": "det1", |
| 167 | + "path": "sub/tree/i22-20840-det1" |
| 168 | + }, |
| 169 | + { |
| 170 | + "name": "det2", |
| 171 | + "path": "sub/tree/i22-20840-det2" |
| 172 | + } |
| 173 | + ]" |
| 174 | + } |
| 175 | +} |
| 176 | +``` |
| 177 | + |
| 178 | +#### configure |
| 179 | +##### Query |
| 180 | +``` |
| 181 | +mutation { |
| 182 | + configure(beamline: "i11", config: { |
| 183 | + visit:"/tmp/{instrument}/data/{year}/{visit}" |
| 184 | + scan:"{subdirectory}/{instrument}-{scan_number}" |
| 185 | + detector:"{subdirectory}/{instrument}-{scan_number}-{detector}" |
| 186 | + scanNumber: 12345 |
| 187 | + }) { |
| 188 | + visitTemplate |
| 189 | + scanTemplate |
| 190 | + detectorTemplate |
| 191 | + latestScanNumber |
| 192 | + } |
| 193 | + } |
| 194 | +} |
| 195 | +``` |
| 196 | +##### Response |
| 197 | +```json |
| 198 | +{ |
| 199 | + "configure": { |
| 200 | + "visitTemplate": "/tmp/{instrument}/data/{year}/{visit}", |
| 201 | + "scanTemplate": "{subdirectory}/{instrument}-{scan_number}", |
| 202 | + "detectorTemplate": "{subdirectory}/{instrument}-{scan_number}-{detector}", |
| 203 | + "latestScanNumber": 12345 |
| 204 | + }`` |
| 205 | +} |
| 206 | +``` |
| 207 | + |
| 208 | +[_graphiql]:https://github.com/graphql/graphiql/ |
| 209 | +[_jq]:https://jqlang.github.io/jq/ |
0 commit comments