Skip to content

Commit

Permalink
Updated fleet route with new API
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Chong <aaronchongth@gmail.com>
  • Loading branch information
aaronchongth committed Mar 27, 2024
1 parent d9e4dd6 commit b287ac3
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 19 deletions.
2 changes: 2 additions & 0 deletions packages/api-server/api_server/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
from .rmf_api.resume_task_response import TaskResumeResponse
from .rmf_api.rewind_task_request import TaskRewindRequest
from .rmf_api.rewind_task_response import TaskRewindResponse
from .rmf_api.robot_commission_request import *
from .rmf_api.robot_commission_response import *
from .rmf_api.robot_state import RobotState
from .rmf_api.robot_state import Status as Status2
from .rmf_api.robot_task_request import RobotTaskRequest
Expand Down
76 changes: 57 additions & 19 deletions packages/api-server/api_server/routes/fleets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@
from api_server.fast_io import FastIORouter, SubscriptionRequest
from api_server.gateway import rmf_gateway
from api_server.logger import logger
from api_server.models import FleetLog, FleetState, User
from api_server.models import (
Commission,
FleetLog,
FleetState,
RobotCommissionRequest,
RobotCommissionResponse,
RobotCommissionResponseItem1,
User,
)
from api_server.repositories import FleetRepository, fleet_repo_dep
from api_server.rmf_io import fleet_events
from api_server.rmf_io import fleet_events, robots_service

router = FastIORouter(tags=["Fleets"])

Expand Down Expand Up @@ -68,11 +76,14 @@ async def sub_fleet_log(_req: SubscriptionRequest, name: str):
)


@router.post("/{name}/decommission")
@router.post(
"/{name}/decommission",
response_model=RobotCommissionResponse,
responses={400: {"model": RobotCommissionResponseItem1}},
)
async def decommission_robot(
name: str,
robot_name: str,
request_id: str,
repo: FleetRepository = Depends(fleet_repo_dep),
user: User = Depends(user_dep),
):
Expand All @@ -82,20 +93,36 @@ async def decommission_robot(
if fleet_state.robots is None or robot_name not in fleet_state.robots:
raise HTTPException(404, f"Robot {robot_name} not found in fleet {name}")

logger.info(f"Decommissioning {robot_name} of {name} called by {user.username}")
rmf_gateway().decommission_robot(
fleet_name=name,
robot_name=robot_name,
request_id=request_id,
labels=[user.username],
commission = Commission(
dispatch_tasks=False, direct_tasks=False, idle_behavior=False
)
request = RobotCommissionRequest(
type="",
robot=robot_name,
fleet=name,
commission=commission,
reassign_tasks=True,
)


@router.post("/{name}/recommission")
logger.info(f"Decommissioning {robot_name} of {name} called by {user.username}")
resp = RobotCommissionResponse.parse_raw(
await robots_service().call(request.json(exclude_none=True))
)
logger.info(resp)
if not resp.__root__.success:
logger.error(f"Failed to decommission {robot_name} of {name}")
return RobotCommissionResponseItem1(resp.json(), 400)
return resp.__root__


@router.post(
"/{name}/recommission",
response_model=RobotCommissionResponse,
responses={400: {"model": RobotCommissionResponseItem1}},
)
async def recommission_robot(
name: str,
robot_name: str,
request_id: str,
repo: FleetRepository = Depends(fleet_repo_dep),
user: User = Depends(user_dep),
):
Expand All @@ -105,10 +132,21 @@ async def recommission_robot(
if fleet_state.robots is None or robot_name not in fleet_state.robots:
raise HTTPException(404, f"Robot {robot_name} not found in fleet {name}")

logger.info(f"Recommissioning {robot_name} of {name} called by ${user.username}")
rmf_gateway().recommission_robot(
fleet_name=name,
robot_name=robot_name,
request_id=request_id,
labels=[user.username],
commission = Commission(dispatch_tasks=True, direct_tasks=True, idle_behavior=True)
request = RobotCommissionRequest(
type="",
robot=robot_name,
fleet=name,
commission=commission,
reassign_tasks=None,
)

logger.info(f"Recommissioning {robot_name} of {name} called by {user.username}")
resp = RobotCommissionResponse.parse_raw(
await robots_service().call(request.json(exclude_none=True))
)
logger.info(resp)
if not resp.__root__.success:
logger.error(f"Failed to recommission {robot_name} of {name}")
return RobotCommissionResponseItem1(resp.json(), 400)
return resp.__root__

0 comments on commit b287ac3

Please sign in to comment.