Skip to content

Commit 3f46246

Browse files
authored
Merge branch 'master' into feature/improve-study-homepage
2 parents 70d309a + 1a71293 commit 3f46246

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1929
-70
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
paths:
2+
/resource-usage/containers:
3+
get:
4+
tags:
5+
- usage
6+
summary: Retrieve containers that were running for a user and product taken
7+
from context.
8+
operationId: list_resource_usage_containers
9+
parameters:
10+
- required: false
11+
schema:
12+
type: integer
13+
title: Limit
14+
default: 20
15+
name: limit
16+
in: query
17+
- required: false
18+
schema:
19+
type: integer
20+
minimum: 0
21+
title: Offset
22+
default: 0
23+
name: offset
24+
in: query
25+
responses:
26+
'200':
27+
description: Successful Response
28+
content:
29+
application/json:
30+
schema:
31+
$ref: '#/components/schemas/Envelope_list_models_library.api_schemas_webserver.resource_usage.ContainerGet__'
32+
components:
33+
schemas:
34+
ContainerGet:
35+
properties:
36+
project_uuid:
37+
type: string
38+
format: uuid
39+
title: Project Uuid
40+
project_name:
41+
type: string
42+
title: Project Name
43+
node_uuid:
44+
type: string
45+
format: uuid
46+
title: Node Uuid
47+
node_label:
48+
type: string
49+
title: Node Label
50+
service_key:
51+
type: string
52+
pattern: ^simcore/services/((comp|dynamic|frontend))/([a-z0-9][a-z0-9_.-]*/)*([a-z0-9-_]+[a-z0-9])$
53+
title: Service Key
54+
service_version:
55+
type: string
56+
pattern: ^(0|[1-9]\d*)(\.(0|[1-9]\d*)){2}(-(0|[1-9]\d*|\d*[-a-zA-Z][-\da-zA-Z]*)(\.(0|[1-9]\d*|\d*[-a-zA-Z][-\da-zA-Z]*))*)?(\+[-\da-zA-Z]+(\.[-\da-zA-Z-]+)*)?$
57+
title: Service Version
58+
start_time:
59+
type: string
60+
format: date-time
61+
title: Start Time
62+
duration:
63+
type: number
64+
title: Duration
65+
processors:
66+
type: number
67+
title: Processors
68+
core_hours:
69+
type: number
70+
title: Core Hours
71+
status:
72+
$ref: '#/components/schemas/ContainerStatus'
73+
type: object
74+
required:
75+
- project_uuid
76+
- node_uuid
77+
- service_key
78+
- service_version
79+
- start_time
80+
- duration
81+
- processors
82+
- core_hours
83+
- status
84+
title: ContainerGet
85+
ContainerStatus:
86+
type: string
87+
enum:
88+
- running
89+
- finished
90+
title: ContainerStatus
91+
description: An enumeration.
92+
Envelope_list_models_library.api_schemas_webserver.resource_usage.ContainerGet__:
93+
properties:
94+
data:
95+
items:
96+
$ref: '#/components/schemas/ContainerGet'
97+
type: array
98+
title: Data
99+
error:
100+
title: Error
101+
type: object
102+
title: Envelope[list[models_library.api_schemas_webserver.resource_usage.ContainerGet]]

api/specs/webserver/openapi.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,11 @@ paths:
306306
/tags/{tag_id}:
307307
$ref: "./openapi-tags.yaml#/paths/~1tags~1{tag_id}"
308308

309+
# RESOURCE USAGE ------------------------------------------------------------------
310+
311+
/resource-usage/containers:
312+
$ref: "./openapi-resource-usage.yaml#/paths/~1resource-usage~1containers"
313+
309314
# PUBLICATIONS -------------------------------------------------------------------------
310315
/publications/service-submission:
311316
$ref: "./openapi-publications.yaml#/paths/~1publications~1service-submission"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
""" Helper script to automatically generate OAS
2+
3+
This OAS are the source of truth
4+
"""
5+
6+
# pylint: disable=redefined-outer-name
7+
# pylint: disable=unused-argument
8+
# pylint: disable=unused-variable
9+
# pylint: disable=too-many-arguments
10+
11+
12+
from enum import Enum
13+
14+
from _common import (
15+
CURRENT_DIR,
16+
assert_handler_signature_against_model,
17+
create_openapi_specs,
18+
)
19+
from fastapi import FastAPI
20+
from models_library.api_schemas_webserver.resource_usage import ContainerGet
21+
from models_library.generics import Envelope
22+
from models_library.rest_pagination import DEFAULT_NUMBER_OF_ITEMS_PER_PAGE
23+
from pydantic import NonNegativeInt
24+
from simcore_service_webserver.resource_usage._containers_handlers import (
25+
_ListContainersPathParams,
26+
)
27+
28+
app = FastAPI(redoc_url=None)
29+
30+
TAGS: list[str | Enum] = ["usage"]
31+
32+
33+
#
34+
# API entrypoints
35+
#
36+
37+
38+
@app.get(
39+
"/resource-usage/containers",
40+
response_model=Envelope[list[ContainerGet]],
41+
tags=TAGS,
42+
operation_id="list_resource_usage_containers",
43+
summary="Retrieve containers that were running for a user and product taken from context.",
44+
)
45+
async def list_resource_usage_containers(
46+
limit: int = DEFAULT_NUMBER_OF_ITEMS_PER_PAGE, offset: NonNegativeInt = 0
47+
):
48+
...
49+
50+
51+
assert_handler_signature_against_model(
52+
list_resource_usage_containers, _ListContainersPathParams
53+
)
54+
55+
56+
if __name__ == "__main__":
57+
58+
create_openapi_specs(app, CURRENT_DIR.parent / "openapi-resource-usage.yaml")
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from datetime import datetime
2+
from enum import Enum
3+
4+
from models_library.projects import ProjectID
5+
from models_library.projects_nodes_io import NodeID
6+
from models_library.services import ServiceKey, ServiceVersion
7+
from pydantic import BaseModel
8+
9+
# Frontend API
10+
11+
12+
class ContainerStatus(str, Enum):
13+
RUNNING = "running"
14+
FINISHED = "finished"
15+
16+
17+
class ContainerGet(BaseModel):
18+
project_uuid: ProjectID
19+
project_name: str | None
20+
node_uuid: NodeID
21+
node_label: str | None
22+
service_key: ServiceKey
23+
service_version: ServiceVersion
24+
start_time: datetime
25+
duration: float
26+
processors: float
27+
core_hours: float
28+
status: ContainerStatus
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
"""adding node_uuid, instance, cpu/memory limits and indexes to resource tracker container table
2+
3+
Revision ID: 0cdf095b10fe
4+
Revises: 52b5c2466605
5+
Create Date: 2023-07-03 14:55:20.464906+00:00
6+
7+
"""
8+
import sqlalchemy as sa
9+
from alembic import op
10+
11+
# revision identifiers, used by Alembic.
12+
revision = "0cdf095b10fe"
13+
down_revision = "52b5c2466605"
14+
branch_labels = None
15+
depends_on = None
16+
17+
18+
def upgrade():
19+
# ### commands auto generated by Alembic - please adjust! ###
20+
op.add_column(
21+
"resource_tracker_container",
22+
sa.Column("node_uuid", sa.String(), nullable=False),
23+
)
24+
op.add_column(
25+
"resource_tracker_container",
26+
sa.Column("node_label", sa.String(), nullable=True),
27+
)
28+
op.add_column(
29+
"resource_tracker_container", sa.Column("instance", sa.String(), nullable=True)
30+
)
31+
op.add_column(
32+
"resource_tracker_container",
33+
sa.Column("service_settings_limit_nano_cpus", sa.BigInteger(), nullable=True),
34+
)
35+
op.add_column(
36+
"resource_tracker_container",
37+
sa.Column(
38+
"service_settings_limit_memory_bytes", sa.BigInteger(), nullable=True
39+
),
40+
)
41+
op.add_column(
42+
"resource_tracker_container",
43+
sa.Column("project_name", sa.String(), nullable=True),
44+
)
45+
op.add_column(
46+
"resource_tracker_container",
47+
sa.Column("user_email", sa.String(), nullable=True),
48+
)
49+
op.add_column(
50+
"resource_tracker_container",
51+
sa.Column("service_key", sa.String(), nullable=False),
52+
)
53+
op.add_column(
54+
"resource_tracker_container",
55+
sa.Column("service_version", sa.String(), nullable=False),
56+
)
57+
op.create_index(
58+
op.f("ix_resource_tracker_container_product_name"),
59+
"resource_tracker_container",
60+
["product_name"],
61+
unique=False,
62+
)
63+
op.create_index(
64+
op.f("ix_resource_tracker_container_prometheus_last_scraped"),
65+
"resource_tracker_container",
66+
["prometheus_last_scraped"],
67+
unique=False,
68+
)
69+
op.create_index(
70+
op.f("ix_resource_tracker_container_user_id"),
71+
"resource_tracker_container",
72+
["user_id"],
73+
unique=False,
74+
)
75+
op.drop_column("resource_tracker_container", "image")
76+
# ### end Alembic commands ###
77+
78+
79+
def downgrade():
80+
# ### commands auto generated by Alembic - please adjust! ###
81+
op.add_column(
82+
"resource_tracker_container",
83+
sa.Column("image", sa.VARCHAR(), autoincrement=False, nullable=True),
84+
)
85+
op.drop_index(
86+
op.f("ix_resource_tracker_container_user_id"),
87+
table_name="resource_tracker_container",
88+
)
89+
op.drop_index(
90+
op.f("ix_resource_tracker_container_prometheus_last_scraped"),
91+
table_name="resource_tracker_container",
92+
)
93+
op.drop_index(
94+
op.f("ix_resource_tracker_container_product_name"),
95+
table_name="resource_tracker_container",
96+
)
97+
op.drop_column("resource_tracker_container", "service_version")
98+
op.drop_column("resource_tracker_container", "service_key")
99+
op.drop_column("resource_tracker_container", "user_email")
100+
op.drop_column("resource_tracker_container", "project_name")
101+
op.drop_column("resource_tracker_container", "service_settings_limit_memory_bytes")
102+
op.drop_column("resource_tracker_container", "service_settings_limit_nano_cpus")
103+
op.drop_column("resource_tracker_container", "instance")
104+
op.drop_column("resource_tracker_container", "node_label")
105+
op.drop_column("resource_tracker_container", "node_uuid")
106+
# ### end Alembic commands ###

0 commit comments

Comments
 (0)