Skip to content

Commit

Permalink
feat: Add indicator to warn when most t4c licenses are being used
Browse files Browse the repository at this point in the history
Closes #1784
  • Loading branch information
zusorio committed Oct 23, 2024
1 parent 7963611 commit f94f671
Show file tree
Hide file tree
Showing 14 changed files with 407 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ class SimpleLicenseServer(T4CLicenseServerBase):
id: int


class PublicLicenseServerWithUsage(core_pydantic.BaseModel):
id: int
name: str
usage: interface.T4CLicenseServerUsage


class T4CLicenseServer(T4CLicenseServerBase):
id: int
license_server_version: str | None = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,33 @@ def delete_t4c_license_server(
crud.delete_t4c_license_server(db, license_server)


@router.get(
"/usage",
response_model=list[models.PublicLicenseServerWithUsage],
)
def get_t4c_license_servers_usage(
db: orm.Session = fastapi.Depends(database.get_db),
) -> list[models.PublicLicenseServerWithUsage]:
usages = []

Check warning on line 105 in backend/capellacollab/settings/modelsources/t4c/license_server/routes.py

View check run for this annotation

Codecov / codecov/patch

backend/capellacollab/settings/modelsources/t4c/license_server/routes.py#L105

Added line #L105 was not covered by tests
for license_server in crud.get_t4c_license_servers(db):
usage = interface.get_t4c_license_server_usage(

Check warning on line 107 in backend/capellacollab/settings/modelsources/t4c/license_server/routes.py

View check run for this annotation

Codecov / codecov/patch

backend/capellacollab/settings/modelsources/t4c/license_server/routes.py#L107

Added line #L107 was not covered by tests
license_server.usage_api
)
usages.append(

Check warning on line 110 in backend/capellacollab/settings/modelsources/t4c/license_server/routes.py

View check run for this annotation

Codecov / codecov/patch

backend/capellacollab/settings/modelsources/t4c/license_server/routes.py#L110

Added line #L110 was not covered by tests
models.PublicLicenseServerWithUsage(
id=license_server.id,
name=license_server.name,
usage=usage,
)
)
return usages

Check warning on line 117 in backend/capellacollab/settings/modelsources/t4c/license_server/routes.py

View check run for this annotation

Codecov / codecov/patch

backend/capellacollab/settings/modelsources/t4c/license_server/routes.py#L117

Added line #L117 was not covered by tests


@router.get(
"/{t4c_license_server_id}/usage",
response_model=interface.T4CLicenseServerUsage,
)
def fetch_t4c_license_server_licenses(
def get_t4c_license_server_usage(
license_server: models.DatabaseT4CLicenseServer = fastapi.Depends(
injectables.get_existing_license_server
),
Expand Down
5 changes: 3 additions & 2 deletions backend/capellacollab/settings/modelsources/t4c/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
)

router.include_router(
settings_t4c_license_server_routes.admin_router,
settings_t4c_license_server_routes.router,
prefix="/license-servers",
tags=["Settings - Modelsources - T4C - License Servers"],
)


router.include_router(
settings_t4c_license_server_routes.router,
settings_t4c_license_server_routes.admin_router,
prefix="/license-servers",
tags=["Settings - Modelsources - T4C - License Servers"],
)
1 change: 1 addition & 0 deletions frontend/src/app/openapi/.openapi-generator/FILES

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/src/app/openapi/model/models.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions frontend/src/app/openapi/model/public-license-server-with-usage.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!--
~ SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors
~ SPDX-License-Identifier: Apache-2.0
-->

@if ((licenseUsageWrapperService.licenseServerUsage$ | async) !== undefined) {
@for (
licenseServer of licenseUsageWrapperService.licenseServerUsage$ | async;
track licenseServer.id
) {
@if (licenseServer.usage.free === 0) {
<div
class="my-1 flex items-center gap-1.5 rounded border bg-red-500 p-1 text-sm text-white shadow"
>
<mat-icon class="shrink-0">error</mat-icon>
<span
>All TeamForCapella licenses are currently in use. You can start new
sessions, but may encounter the error "Invalid license" when trying to
use TeamForCapella. Please make sure to terminate your sessions after
use.
</span>
</div>
} @else if (licenseServer.usage.free / licenseServer.usage.total < 0.25) {
<div
class="my-1 flex items-center gap-1.5 rounded border bg-yellow-300 p-1 text-sm shadow"
>
<mat-icon class="shrink-0">warning</mat-icon>
<span
>Most TeamForCapella licenses are currently in use. Please make sure
to terminate your sessions after use.
</span>
</div>
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors
* SPDX-License-Identifier: Apache-2.0
*/
import { AsyncPipe } from '@angular/common';
import { Component } from '@angular/core';
import { MatIcon } from '@angular/material/icon';
import { LicenseUsageWrapperService } from './license-usage.service';

@Component({
selector: 'app-license-indicator',
standalone: true,
imports: [MatIcon, AsyncPipe],
templateUrl: './license-indicator.component.html',
})
export class LicenseIndicatorComponent {
constructor(public licenseUsageWrapperService: LicenseUsageWrapperService) {}
}
Loading

0 comments on commit f94f671

Please sign in to comment.