Rename orchestration, splice and routes: a Renamer runs one rename at a time, closing the gate, taking the controller lock and holding the engine, each waiting without a limit and saying what it waits for (summary rename status, rename_waiting); DELETE on the pending request or a closed connection calls it off until the journal begins (409 aborted); then journal, steps and audit, retried in the background on failure (503 completing); splice_renamed rebuilds the affected flows under the held lock keeping stopped, paused and parked work, history limits and device wiring refreshed before activation; AlertManager.rename and EventBus.rename/settle follow the names; flow and dashboard rename routes answer by code and repeat stored results; renamed, dashboard_changed and pipeline_rebuilt after release; fluksio serve reads flow files without building a FlowStore
This commit is contained in:
@@ -21,6 +21,7 @@ from fluksio.flow.controller import FlowController
|
||||
from fluksio.flow.dashboards import DashboardDef, DashboardStore
|
||||
from fluksio.flow.devices import DeviceDef, DeviceStore, DeviceUnavailable, presence
|
||||
from fluksio.flow.events import event_bus
|
||||
from fluksio.flow.rename import Renamer
|
||||
from fluksio.flow.workers import PythonWorkerPool
|
||||
from fluksio.models import OAuthClient, TokenPayload, User, WorkerToken
|
||||
|
||||
@@ -583,6 +584,16 @@ def get_device_store(request: Request) -> DeviceStore:
|
||||
DeviceStoreDep = Annotated[DeviceStore, Depends(get_device_store)]
|
||||
|
||||
|
||||
def get_renamer(request: Request) -> Renamer:
|
||||
renamer: Renamer | None = getattr(request.app.state, "renamer", None)
|
||||
if renamer is None:
|
||||
raise HTTPException(status_code=503, detail="The flow engine is not running")
|
||||
return renamer
|
||||
|
||||
|
||||
RenamerDep = Annotated[Renamer, Depends(get_renamer)]
|
||||
|
||||
|
||||
def get_worker_pool(request: Request) -> PythonWorkerPool:
|
||||
pool: PythonWorkerPool | None = getattr(request.app.state, "worker_pool", None)
|
||||
if pool is None:
|
||||
|
||||
@@ -7,7 +7,7 @@ label unique among dashboards and what ``GET /dashboards?name=`` looks up.
|
||||
import time
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request
|
||||
from fastapi.concurrency import run_in_threadpool
|
||||
from pydantic import BaseModel
|
||||
|
||||
@@ -15,6 +15,7 @@ from fluksio.api.deps import (
|
||||
CurrentUser,
|
||||
DashboardStoreDep,
|
||||
FlowControllerDep,
|
||||
RenamerDep,
|
||||
check_pin,
|
||||
get_current_active_superuser,
|
||||
get_current_user,
|
||||
@@ -30,7 +31,13 @@ from fluksio.flow.dashboards import (
|
||||
results_dashboard,
|
||||
)
|
||||
from fluksio.flow.events import event_bus
|
||||
from fluksio.flow.rename import RenamePlan, RenamePlanRequest, plan_rename
|
||||
from fluksio.flow.rename import (
|
||||
RenamePlan,
|
||||
RenamePlanRequest,
|
||||
RenameRequest,
|
||||
RenameResult,
|
||||
plan_rename,
|
||||
)
|
||||
from fluksio.flow.store import FlowNotFound, IdTaken, StaleVersion
|
||||
from fluksio.models import Message
|
||||
|
||||
@@ -279,3 +286,29 @@ async def plan_dashboard_rename(
|
||||
)
|
||||
except DashboardNotFound:
|
||||
raise _missing(dashboard_id)
|
||||
|
||||
|
||||
@router.post(
|
||||
"/{dashboard_id}/rename",
|
||||
response_model=RenameResult,
|
||||
dependencies=[Depends(get_current_active_superuser)],
|
||||
)
|
||||
async def rename_dashboard(
|
||||
dashboard_id: str,
|
||||
body: RenameRequest,
|
||||
request: Request,
|
||||
renamer: RenamerDep,
|
||||
user: CurrentUser,
|
||||
) -> Any:
|
||||
"""Rename this dashboard's key, as its plan described it.
|
||||
|
||||
Its two documents and nothing else: devices list it by id, and nothing
|
||||
binds to it by key. The same ``request_id`` again gets the same answer;
|
||||
refusals are as for a flow.
|
||||
"""
|
||||
try:
|
||||
return await renamer.rename(
|
||||
"dashboard", dashboard_id, body, user.email, request.is_disconnected
|
||||
)
|
||||
except DashboardNotFound:
|
||||
raise _missing(dashboard_id)
|
||||
|
||||
@@ -35,6 +35,7 @@ from fluksio.api.deps import (
|
||||
DashboardStoreDep,
|
||||
FlowControllerDep,
|
||||
HiddenDep,
|
||||
RenamerDep,
|
||||
SessionDep,
|
||||
TokenDep,
|
||||
check_pin,
|
||||
@@ -69,7 +70,13 @@ from fluksio.flow.events import event_bus
|
||||
from fluksio.flow.messages import MEDIA_FAMILIES, DType, flow_of, qualify
|
||||
from fluksio.flow.nodes.wren import TRAIN_FLOW, WrenNode, pack_meta
|
||||
from fluksio.flow.pipeline import EngineHeld, ValidationIssue
|
||||
from fluksio.flow.rename import RenamePlan, RenamePlanRequest, plan_rename
|
||||
from fluksio.flow.rename import (
|
||||
RenamePlan,
|
||||
RenamePlanRequest,
|
||||
RenameRequest,
|
||||
RenameResult,
|
||||
plan_rename,
|
||||
)
|
||||
from fluksio.flow.runs import RunRejected
|
||||
from fluksio.flow.schemas import (
|
||||
NAME_PATTERN,
|
||||
@@ -776,6 +783,60 @@ async def plan_flow_rename(
|
||||
raise _missing(flow_id)
|
||||
|
||||
|
||||
@router.post(
|
||||
"/{flow_id}/rename",
|
||||
response_model=RenameResult,
|
||||
dependencies=[Depends(get_current_active_superuser)],
|
||||
)
|
||||
async def rename_flow(
|
||||
flow_id: str,
|
||||
body: RenameRequest,
|
||||
request: Request,
|
||||
renamer: RenamerDep,
|
||||
user: CurrentUser,
|
||||
) -> Any:
|
||||
"""Rename this flow's key, as its plan described it.
|
||||
|
||||
Everything named under the key moves: every flow and dashboard binding
|
||||
one of its messages, its history, live state and queued work. The engine
|
||||
waits meanwhile, for as long as the work running when it was asked takes
|
||||
to finish. Until then it can be called off, with ``DELETE`` on the
|
||||
request or by closing the connection, and nothing changes (409
|
||||
``aborted``); ``GET /observability/summary`` says what it waits for.
|
||||
|
||||
The same ``request_id`` again gets the same answer. A rename that
|
||||
could not finish yet answers 503 ``completing`` and is finished in the
|
||||
background. Refusals are the plan's codes (409, 422 for a key that is no
|
||||
key), ``stale`` and ``plan_changed`` (409).
|
||||
"""
|
||||
try:
|
||||
return await renamer.rename(
|
||||
"flow", flow_id, body, user.email, request.is_disconnected
|
||||
)
|
||||
except FlowNotFound:
|
||||
raise _missing(flow_id)
|
||||
|
||||
|
||||
@router.delete(
|
||||
"/{flow_id}/rename/{request_id}",
|
||||
response_model=Message,
|
||||
dependencies=[Depends(get_current_active_superuser)],
|
||||
)
|
||||
async def cancel_flow_rename(flow_id: str, request_id: str, renamer: RenamerDep) -> Any:
|
||||
"""Call off a rename still waiting for the engine. It answers 409
|
||||
``aborted`` once everything is as it was, and one that has begun to
|
||||
change things refuses this with 409 ``too_late``."""
|
||||
# Async, so on the event loop, where the rename decides when it is past
|
||||
# calling off.
|
||||
try:
|
||||
renamer.cancel(flow_id, request_id)
|
||||
except KeyError:
|
||||
raise HTTPException(
|
||||
status_code=404, detail=f"No rename '{request_id}' of '{flow_id}' waits"
|
||||
)
|
||||
return Message(message=f"Calling off rename '{request_id}'")
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Node source
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
@@ -28,6 +28,7 @@ from fluksio.api.deps import (
|
||||
from fluksio.api.routes.runs import elapsed_ms
|
||||
from fluksio.core.config import settings
|
||||
from fluksio.flow.controller import NodeStatus
|
||||
from fluksio.flow.rename import RenameStatus
|
||||
from fluksio.flow.tombstones import names_of, shown_nodes, stored_node
|
||||
from fluksio.models import EngineEvent, FlowRun, Message, MetricBucket
|
||||
|
||||
@@ -65,6 +66,9 @@ class HealthSummary(BaseModel):
|
||||
#: route the client knows and the engine does not answers a flat 404. This
|
||||
#: is what turns that into a sentence. Absent means older than this field.
|
||||
version: str = ""
|
||||
#: A key rename under way: what it waits for while it can still be
|
||||
#: called off, and why a step failed while it is retried.
|
||||
rename: RenameStatus | None = None
|
||||
|
||||
|
||||
class SeriesPoint(BaseModel):
|
||||
@@ -285,6 +289,7 @@ async def read_summary(request: Request, controller: FlowControllerDep) -> Any:
|
||||
f"{', '.join(sorted(e.id for e in failed_once))}"
|
||||
)
|
||||
|
||||
renamer = getattr(request.app.state, "renamer", None)
|
||||
return HealthSummary(
|
||||
status="degraded" if problems else "ok",
|
||||
problems=problems,
|
||||
@@ -322,6 +327,7 @@ async def read_summary(request: Request, controller: FlowControllerDep) -> Any:
|
||||
else {"ewma": 0.0, "max_60s": 0.0}
|
||||
),
|
||||
version=__version__,
|
||||
rename=renamer.pending if renamer is not None else None,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user