Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APIs to support metadata object creation and querying #2049

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
27 changes: 27 additions & 0 deletions lib/pbench/server/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
from pbench.common.exceptions import BadConfig, ConfigFileNotSpecified
from pbench.server.api.resources.upload_api import Upload, HostInfo
from pbench.server.api.resources.graphql_api import GraphQL
from pbench.server.api.resources.metadata_api import (
CreateMetadata,
GetMetadata,
QueryMetadata,
PublishMetadata,
)
from pbench.common.logger import get_pbench_logger
from pbench.server.api.resources.query_apis.elasticsearch_api import Elasticsearch
from pbench.server.api.resources.query_apis.query_controllers import QueryControllers
Expand Down Expand Up @@ -84,6 +90,27 @@ def register_endpoints(api, app, config):
resource_class_args=(logger, token_auth),
)

api.add_resource(
CreateMetadata,
f"{base_uri}/metadata",
resource_class_args=(config, logger, token_auth),
)
api.add_resource(
GetMetadata,
f"{base_uri}/metadata/<string:key>",
npalaska marked this conversation as resolved.
Show resolved Hide resolved
resource_class_args=(config, logger, token_auth),
)
api.add_resource(
QueryMetadata,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering what's the difference between "GetMetadata" and "QueryMetadata"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GetMetadata returns all metadata values for the authorized user, while QueryMetadata specifies a metadata id and returns just that value.

Having two classes somewhat obscures the relationship, but if you look at the URI registration in __init__.py you'll see that they're both GET /metadata with effectively an optional id ... that is, GetMetadata maps to just GET /metadata while QueryMetadata maps to GET /metadata/<id>. I think Nikhil looked into combining those and found that Flask didn't provide a straightforward way to make the <id> parameter optional; the pattern wouldn't match if it was omitted, so he had to add the second class to make it work either way.

f"{base_uri}/metadata/<int:id>",
resource_class_args=(config, logger),
)
api.add_resource(
PublishMetadata,
f"{base_uri}/metadata/<int:id>/publish",
resource_class_args=(config, logger),
)


def get_server_config():
cfg_name = os.environ.get("_PBENCH_SERVER_CONFIG")
Expand Down
Loading