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

Hammer/generic alerts #948

Merged
merged 42 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4d75109
First iteration of generic alerts
aaronchongth May 23, 2024
d2a7d58
Route for unresponded alerts
aaronchongth May 23, 2024
907f739
Merge branch 'deploy/hammer' into hammer/generic-alerts
aaronchongth May 23, 2024
a18d89b
Basic location complete post route for task
aaronchongth May 23, 2024
3e4a4ef
Tests for alert routes
aaronchongth May 24, 2024
93467ca
Test for location complete route
aaronchongth May 24, 2024
c4a76d8
Lint and tests
aaronchongth May 27, 2024
f48bc5c
Basic implementation
aaronchongth May 28, 2024
6e2d54e
Basic task based alerts working as expected
aaronchongth May 28, 2024
e45452d
Only display and list alerts that have display true
aaronchongth May 28, 2024
deca732
Add doc to location_complete route about instability
aaronchongth May 28, 2024
b7c04a5
Refactored alert db interactions to repository, with lru cache for lo…
aaronchongth May 29, 2024
99855f8
Regenerated docs and return early on gateway last location checking
aaronchongth May 30, 2024
78f5e0b
Lint and better typing with static methods
aaronchongth May 30, 2024
cb1b563
Hammer/generic alerts without location (#951)
aaronchongth Jun 20, 2024
105628b
Hammer/demo tasks (#925)
aaronchongth Jun 26, 2024
4e93451
Merge branch 'deploy/hammer' into hammer/generic-alerts
aaronchongth Jun 26, 2024
37201c9
Update ros2 pydantic messages, fix tests
aaronchongth Jun 26, 2024
95ffb2c
Revert update of pnpm lock file
aaronchongth Jun 26, 2024
b413658
Lint
aaronchongth Jun 26, 2024
c5dc60b
Use specific exceptions and more clean up
aaronchongth Jul 1, 2024
5237e72
Merge branch 'deploy/hammer-humble' into hammer/generic-alerts
aaronchongth Jul 4, 2024
1fd22ee
Port CI fixes from #955 but targeting ubuntu 22 and ROS 2 Humble
aaronchongth Jul 4, 2024
01d68fe
Revert "Port CI fixes from #955 but targeting ubuntu 22 and ROS 2 Hum…
aaronchongth Jul 4, 2024
2b4c763
Update pnpm version
aaronchongth Jul 4, 2024
1771015
Setup pnpm and node manually
aaronchongth Jul 4, 2024
d51ef77
Using HOME env var of runner
aaronchongth Jul 4, 2024
0e8d7c4
workflow
aaronchongth Jul 4, 2024
18a075d
workflow
aaronchongth Jul 4, 2024
2b58f8e
Workflow
aaronchongth Jul 4, 2024
2bfd484
Address feedback on frontend
aaronchongth Jul 4, 2024
9434771
Address comments that don't break behavior
aaronchongth Jul 5, 2024
cc9a268
Started generic exceptions
aaronchongth Jul 5, 2024
06e5475
Proper db schema for alert request and response
aaronchongth Jul 5, 2024
ce5d761
Updated alerts model, frontend tweaks for subscription, using paginat…
aaronchongth Jul 5, 2024
a152639
Attempt to setup minimal RMF during bootstrap step
aaronchongth Jul 5, 2024
822a6b5
Fix mistake on ci path
aaronchongth Jul 5, 2024
7e94210
Fix workflow
aaronchongth Jul 5, 2024
2738146
Revert CI changes
aaronchongth Jul 5, 2024
ebca221
Merge branch 'deploy/hammer-humble' into hammer/generic-alerts
aaronchongth Jul 5, 2024
2e78fde
Merge branch 'deploy/hammer-humble' into hammer/generic-alerts
aaronchongth Jul 5, 2024
6494c01
Updated API, renamed event to pushAlert, filter before
aaronchongth Jul 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 49 additions & 4 deletions packages/api-client/lib/openapi/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1838,6 +1838,31 @@ export interface MutexGroups {
*/
requesting?: Array<string>;
}
/**
*
* @export
* @interface Pagination
*/
export interface Pagination {
/**
*
* @type {number}
* @memberof Pagination
*/
limit: number;
/**
*
* @type {number}
* @memberof Pagination
*/
offset: number;
/**
*
* @type {Array<string>}
* @memberof Pagination
*/
order_by: Array<string>;
}
/**
*
* @export
Expand Down Expand Up @@ -5033,10 +5058,12 @@ export const AlertsApiAxiosParamCreator = function (configuration?: Configuratio
/**
* Returns the list of alert IDs that have yet to be responded to, while a response was required.
* @summary Get Unresponded Alerts
* @param {Pagination} [pagination]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getUnrespondedAlertsAlertsUnrespondedRequestsGet: async (
pagination?: Pagination,
options: AxiosRequestConfig = {},
): Promise<RequestArgs> => {
const localVarPath = `/alerts/unresponded_requests`;
Expand All @@ -5051,13 +5078,20 @@ export const AlertsApiAxiosParamCreator = function (configuration?: Configuratio
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;

localVarHeaderParameter['Content-Type'] = 'application/json';

setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {
...localVarHeaderParameter,
...headersFromBaseOptions,
...options.headers,
};
localVarRequestOptions.data = serializeDataIfNeeded(
pagination,
localVarRequestOptions,
configuration,
);

return {
url: toPathString(localVarUrlObj),
Expand Down Expand Up @@ -5199,14 +5233,19 @@ export const AlertsApiFp = function (configuration?: Configuration) {
/**
* Returns the list of alert IDs that have yet to be responded to, while a response was required.
* @summary Get Unresponded Alerts
* @param {Pagination} [pagination]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async getUnrespondedAlertsAlertsUnrespondedRequestsGet(
pagination?: Pagination,
options?: AxiosRequestConfig,
): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Array<AlertRequest>>> {
const localVarAxiosArgs =
await localVarAxiosParamCreator.getUnrespondedAlertsAlertsUnrespondedRequestsGet(options);
await localVarAxiosParamCreator.getUnrespondedAlertsAlertsUnrespondedRequestsGet(
pagination,
options,
);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
Expand Down Expand Up @@ -5306,14 +5345,16 @@ export const AlertsApiFactory = function (
/**
* Returns the list of alert IDs that have yet to be responded to, while a response was required.
* @summary Get Unresponded Alerts
* @param {Pagination} [pagination]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getUnrespondedAlertsAlertsUnrespondedRequestsGet(
pagination?: Pagination,
options?: any,
): AxiosPromise<Array<AlertRequest>> {
return localVarFp
.getUnrespondedAlertsAlertsUnrespondedRequestsGet(options)
.getUnrespondedAlertsAlertsUnrespondedRequestsGet(pagination, options)
.then((request) => request(axios, basePath));
},
/**
Expand Down Expand Up @@ -5410,13 +5451,17 @@ export class AlertsApi extends BaseAPI {
/**
* Returns the list of alert IDs that have yet to be responded to, while a response was required.
* @summary Get Unresponded Alerts
* @param {Pagination} [pagination]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof AlertsApi
*/
public getUnrespondedAlertsAlertsUnrespondedRequestsGet(options?: AxiosRequestConfig) {
public getUnrespondedAlertsAlertsUnrespondedRequestsGet(
pagination?: Pagination,
options?: AxiosRequestConfig,
) {
return AlertsApiFp(this.configuration)
.getUnrespondedAlertsAlertsUnrespondedRequestsGet(options)
.getUnrespondedAlertsAlertsUnrespondedRequestsGet(pagination, options)
.then((request) => request(this.axios, this.basePath));
}

Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/lib/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { version as rmfModelVer } from 'rmf-models';

export const version = {
rmfModels: rmfModelVer,
rmfServer: 'cb1b563ab8f827756f9a453ec944362d92a3ab57',
rmfServer: '06e5475f096ec8f2eae05aae7c939a612aaa11e6',
openapiGenerator: '6.2.1',
};
19 changes: 19 additions & 0 deletions packages/api-client/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ export default {
description:
'Returns the list of alert IDs that have yet to be responded to, while a\nresponse was required.',
operationId: 'get_unresponded_alerts_alerts_unresponded_requests_get',
requestBody: {
content: { 'application/json': { schema: { $ref: '#/components/schemas/Pagination' } } },
},
responses: {
'200': {
description: 'Successful Response',
Expand All @@ -255,6 +258,12 @@ export default {
},
},
},
'422': {
description: 'Validation Error',
content: {
'application/json': { schema: { $ref: '#/components/schemas/HTTPValidationError' } },
},
},
},
},
},
Expand Down Expand Up @@ -3470,6 +3479,16 @@ export default {
},
},
},
Pagination: {
title: 'Pagination',
required: ['limit', 'offset', 'order_by'],
type: 'object',
properties: {
limit: { title: 'Limit', type: 'integer' },
offset: { title: 'Offset', type: 'integer' },
order_by: { title: 'Order By', type: 'array', items: { type: 'string' } },
},
},
Param: {
title: 'Param',
required: ['name', 'type', 'value_int', 'value_float', 'value_string', 'value_bool'],
Expand Down
16 changes: 16 additions & 0 deletions packages/api-server/api_server/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class AlreadyExistsError(Exception):
"""
Raised when an a resource already exists and there is a conflict.
"""


class NotFoundError(Exception):
"""
Raised when a resource is not found.
"""


class InvalidInputError(Exception):
"""
Raised when an input is invalid.
"""
6 changes: 2 additions & 4 deletions packages/api-server/api_server/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,7 @@ def convert_alert(alert: RmfAlert):
)

def handle_alert(alert: AlertRequest):
logging.info("Received alert:")
logging.info(alert)
logging.info(f"Received alert: {alert}")
alert_events.alert_requests.on_next(alert)

alert_sub = ros_node().create_subscription(
Expand All @@ -314,8 +313,7 @@ def convert_alert_response(alert_response: RmfAlertResponse):
)

def handle_alert_response(alert_response: AlertResponse):
logging.info("Received alert response:")
logging.info(alert_response)
logging.info(f"Received alert response: {alert_response}")
alert_events.alert_responses.on_next(alert_response)

alert_response_sub = ros_node().create_subscription(
Expand Down
4 changes: 3 additions & 1 deletion packages/api-server/api_server/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
from .rmf_api.task_log_response import TaskLogResponse
from .rmf_api.task_log_update import TaskEventLogUpdate
from .rmf_api.task_request import TaskRequest
from .rmf_api.task_state import Status, Status1, TaskState
from .rmf_api.task_state import Status
from .rmf_api.task_state import Status1 as DispatchStatus
from .rmf_api.task_state import TaskState
from .rmf_api.task_state_update import TaskStateUpdate
from .rmf_api.undo_skip_phase_request import UndoPhaseSkipRequest
from .rmf_api.undo_skip_phase_response import UndoPhaseSkipResponse
Expand Down
10 changes: 9 additions & 1 deletion packages/api-server/api_server/models/alerts.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from enum import Enum
from typing import List, Optional

Expand All @@ -23,6 +24,10 @@ def from_tortoise(tortoise: ttm.AlertResponse) -> "AlertResponse":
async def save(self) -> None:
await ttm.AlertResponse.update_or_create(
{
"response_time": datetime.fromtimestamp(
self.unix_millis_response_time / 1000
),
"response": self.response,
"data": self.json(),
aaronchongth marked this conversation as resolved.
Show resolved Hide resolved
},
id=self.id,
Expand Down Expand Up @@ -53,9 +58,12 @@ def from_tortoise(tortoise: ttm.AlertRequest) -> "AlertRequest":
async def save(self) -> None:
await ttm.AlertRequest.update_or_create(
{
"data": self.json(),
"request_time": datetime.fromtimestamp(
self.unix_millis_alert_time / 1000
),
"response_expected": (len(self.responses_available) > 0),
"task_id": self.task_id,
"data": self.json(),
},
id=self.id,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from tortoise.fields import (
BooleanField,
CharField,
DatetimeField,
JSONField,
OneToOneField,
ReverseRelation,
Expand All @@ -10,15 +11,18 @@

class AlertResponse(Model):
aaronchongth marked this conversation as resolved.
Show resolved Hide resolved
id = CharField(255, pk=True)
response_time = DatetimeField(null=False, index=True)
response = CharField(255, null=False, index=True)
data = JSONField()
alert_request = OneToOneField(
"models.AlertRequest", null=False, related_name="alert_response"
)
data = JSONField()


class AlertRequest(Model):
id = CharField(255, pk=True)
data = JSONField()
request_time = DatetimeField(null=False, index=True)
response_expected = BooleanField(null=False, index=True)
task_id = CharField(255, null=True, index=True)
data = JSONField()
alert_response = ReverseRelation["AlertResponse"]
aaronchongth marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 1 addition & 7 deletions packages/api-server/api_server/repositories/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
from .alerts import (
AlertAlreadyExistsError,
AlertNotFoundError,
AlertRepository,
AlertResponseNotFoundError,
InvalidAlertResponseError,
)
from .alerts import AlertRepository
from .cached_files import CachedFilesRepository, cached_files_repo
from .fleets import FleetRepository
from .rmf import RmfRepository
Expand Down
Loading
Loading