Skip to content

Commit f417cc1

Browse files
authored
Implement POST /api/v1/relay (#3425)
* Implement POST /api/v1/relay PBENCH-1143 This API integrates with the file-relay server by assuming that the client (e.g., the `pbench-results-move` command) creates *two* separate files on the relay. The main artifact is the tarball, identified only by the tarball's computed SHA256 hash, as `http://relay.example.com/<name>/<sha256>`. However the Pbench Server needs the MD5 for the formal `resource_id` and a *name* for the dataset before we can begin "intake". We also want a mechanism to override the default "private" access level, and to set metadata, so by convention we add a second JSON file to which I'm referring as the "Relay configuration file". This provides the dataset "metadata" we require, including the tarball URI: ```json { "name": "tarball.tar.xz", "md5": "myMD5", "access": "private", "metadata": ["server.origin:relay", "global.server.relay:webb"], } ``` The Pbench Server will first `GET` the URI parameter, which it expects to be the Relay Configuration File. It will then `GET` the `"uri"` parameter in the configuration file. To accomplish this, the old `Upload` code has been refactored into a base class defining most of the logic, and two subclasses which provide "helper" methods called `_prepare` and `_access` to encapsulate the operational differences between the "push" and "pull" models. Essentially the `Upload` class `_prepare` processes the URI and query parameters while the `Relay` class `_prepare` does the first `GET` and processes the JSON configuration parameters. The `_access` helpers return the content length and an `IO[byte]` stream which is read and processed by the common code. This has been tested manually by standing up an instance of the `relay` server and I added unit tests to cover the distinct functions of the relay helper methods while not duplicating the `upload` unit test cases that cover the common code.
1 parent 6d766a7 commit f417cc1

File tree

8 files changed

+881
-251
lines changed

8 files changed

+881
-251
lines changed

lib/pbench/client/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class API(Enum):
4949
DATASETS_VALUES = "datasets_values"
5050
ENDPOINTS = "endpoints"
5151
KEY = "key"
52+
RELAY = "relay"
5253
SERVER_AUDIT = "server_audit"
5354
SERVER_SETTINGS = "server_settings"
5455
UPLOAD = "upload"

lib/pbench/server/api/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@
3333
SampleValues,
3434
)
3535
from pbench.server.api.resources.query_apis.datasets_search import DatasetsSearch
36+
from pbench.server.api.resources.relay import Relay
3637
from pbench.server.api.resources.server_audit import ServerAudit
3738
from pbench.server.api.resources.server_settings import ServerSettings
38-
from pbench.server.api.resources.upload_api import Upload
39+
from pbench.server.api.resources.upload import Upload
3940
import pbench.server.auth.auth as Auth
4041
from pbench.server.database import init_db
4142
from pbench.server.database.database import Database
@@ -146,6 +147,12 @@ def register_endpoints(api: Api, app: Flask, config: PbenchServerConfig):
146147
endpoint="server_settings",
147148
resource_class_args=(config,),
148149
)
150+
api.add_resource(
151+
Relay,
152+
f"{base_uri}/relay/<path:uri>",
153+
endpoint="relay",
154+
resource_class_args=(config,),
155+
)
149156
api.add_resource(
150157
Upload,
151158
f"{base_uri}/upload/<string:filename>",

0 commit comments

Comments
 (0)