Commit 28afdd25 authored by Christos Tranoris's avatar Christos Tranoris
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading
Loading
+17
Changes for .changelog/20261002_2115_controller-test-harness-design.md: 17 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Controller test harness — high-level design

**Date:** 2026-10-02 21:15

## What was done
Added `README.md` with the high-level design of the OSL Controller Test Harness. It is a standalone
Spring Boot + Camel service that emulates the OpenSlice side (TMF catalog/inventory and OSOM) over
ActiveMQ, so controller developers can test without an OpenSlice instance.

## Covered
- Purpose, scope (no JUnit/Testcontainers integration), and architecture/components.
- Models: the TMF classes reused from `org.etsi.osl.model.tmf`, plus the harness's own models.
- The JMS interface: queues served, queues driven, and the header catalogue.
- The REST API, the UI pages, contract checks, the scenario format, phased delivery, and how to try it with `gcontroller`.

## Status
Design only. No code yet.
+38
Changes for .changelog/20261002_2242_phase1-mvp.md: 38 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Phase 1 (MVP) of the controller test harness

Date: 2026-10-02 22:42

## What was done

Implemented tasks 1.1 to 8.2 of `docs/Implementation Plan OSL Controller Test Harness.md` and ticked them in the plan.

- **Foundation (1.x):** Maven module `osl-controller-testharness` (Java 17, Spring Boot 3.2.2, Camel 4.4.0, embedded Artemis), shared TMF `ObjectMapper`, harness models.
- **Broker and wire (2.x):** embedded Artemis (CORE and OpenWire) with an external-broker switch, in-memory `WireLog`, route-side capture, and a broker plugin that records unconsumed messages.
- **Stores (3.x):** spec store, production and planning inventories, health transitions from `Resource.deriveHealth()`.
- **CatalogEmulator (4.x):** resource-spec and resource catalog queues; writes to placeholder ids are marked.
- **OsomDriver (5.x):** controller and consumer detection (`ControllerRegistry`), production and planning CREATE/UPDATE/DELETE with OSOM's headers, a `dryRun` preview, and `NO_CONSUMER` fail-fast. The request timeout goes on the endpoint URI because the camel-jms starter overrides the component setting.
- **PlanningEmulator (6.x):** `PLANNING.RESOURCE.CREATEORUPDATE` following OSOM's handler, `HealthResolver` (headers, then body, then status), `EstimateParser` (absent vs zero, invalid values kept raw), and `WaitLoopService` (`RUNNING` / `CONVERGED` / `TIMED_OUT`).
- **REST API (7.x):** `ReadApi`, `WriteApi`, typed errors `{code, message}` via `ApiErrors`, and case-insensitive enum parameters.
- **Validation (8.x):**
  - `EndToEndIT` runs through REST against `StubGController`.
  - `scripts/walkthrough.sh` runs design §10 steps 1 to 6 using only curl.

## Verification

- `mvn -o test`: 104 tests, all passing.
- Live run against the unchanged `gcontroller`, started from its classes with `java @argfile` because its Spring Boot 4.2.0-M2 Maven plugin can't be resolved offline. `scripts/walkthrough.sh` printed **PASS**:
  - 10 specs registered, with consumers on all six queues.
  - Production create reached UP with 6 `status.*` characteristics.
  - Planning create went HELD → UP about 220 ms apart, with creation and operation estimates, and there was no catalog write for the placeholder.
  - Planning delete reached GONE with a teardown estimate.

## Decisions

The seven open points are now settled in the plan:
- The model jar is 1.5.0-SNAPSHOT.
- Unconsumed-message detection works with the embedded broker only.
- Side-effect attribution uses the "between request and reply, or targets a placeholder" rule.
- The preview is the `dryRun` flag.
- `initialCharacteristics` holds the "before" values.
- `triggerServiceActionQueue` is recorded only.
- Defaults: 250 ms poll interval, `TIMED_OUT`, 10 s write-back timeout, plain-JS UI.
+34
Changes for .changelog/20261002_2254_contract-checker.md: 34 added lines, 0 removed lines.
Original line number Diff line number Diff line
# ContractChecker and contract rules (Phase 2, tasks 9.1–9.4)

## What was done

- **Framework** (`checks/`): `Rule`, `RuleContext`, `ContractChecker`, `ViolationStore`, and the `model/Violation` class.
  - The checker subscribes to the EventBus and sends each wire message to the rules once, even when it is merged again later. It also forwards health transitions, wait-loop outcomes and spec writes.
  - Time-based rules run on a timer, `harness.checks.tick-interval` (default 250 ms).
  - A rule that throws an exception is logged and skipped; the others keep running.
  - Each violation links to the wire message that caused it and is published as a `violation` event. Identical findings are recorded only once.
- **Rules** (`checks/rules/`):

  | Rule | What it checks |
  |---|---|
  | `HEALTH_DECLARED` | Every production or planning report carries operationalState and administrativeState, as a header or in the body. `estimateOnly` callbacks are exempt. |
  | `REPLY_WELLFORMED` | Replies to CREATE/UPDATE/DELETE are a `Resource` JSON object or null. |
  | `SPEC_COMPLETE` | Each spec has a name, category and version, and every characteristic has a valueType. |
  | `PLANNING_PROGRESSION` | A planning request that runs out its wait budget is flagged. A create that converged without reporting HELD before UP is flagged. |
  | `PLANNING_NO_SIDE_EFFECTS` | No catalog write targets a placeholder id. No catalog write happens while a simulation request is still open (until its reply arrives or the request times out). |
  | `ACK_UUID_TARGETED` | Follow-up callbacks for the same service order and resource name use the uuid the harness acknowledged. |
  | `ESTIMATE_SHAPE` | Estimate values parse as numbers. Each estimate's phase fits the request (create: creation and operation; update: operation; delete: teardown). No operation estimate is sent unless the request gave an operation window. |
  | `PRODUCTION_WRITEBACK` | After a production request, a `CATALOG.*.RESOURCE` write arrives within `checks.writeback-timeout` and the resource ends at UP, UP or GONE. |

- **API changes:**
  - New `GET /api/violations?rule=&resourceId=` endpoint (`ChecksApi`).
  - `/api/status` now includes `counts.violations`.
  - `POST /api/reset` now also clears the checker.

## Verification

- `ContractCheckerTest` (4 tests): a violation is recorded once and linked to its message, duplicates are dropped, filters work, a failing rule does not stop the checker, and reset clears everything.
- `RulesTest` (10 tests): a passing and a failing case for each rule, including the write-back timeout.
- `EndToEndIT`: the production and planning flows against the stub controller now also assert that `/api/violations` is empty.
- Full suite: **118 tests, 0 failures**.
- Plan tasks 9.1–9.4 are ticked.
+42
Changes for .changelog/20261002_2306_sse-and-faults.md: 42 added lines, 0 removed lines.
Original line number Diff line number Diff line
# SSE event stream and fault injection (tasks 10.1, 11.1, 11.2)

## Event stream (10.1)
- `events/EventStream`: one bounded queue (`harness.events.client-queue-size`) and one sender thread per client. A heartbeat is sent first and then every `harness.events.heartbeat` (default 15s). A client that falls behind is sent an `overflow` event (`{dropped, queueSize}`) and disconnected; it never blocks the publisher.
- `GET /api/events?types=a,b` (`api/EventsApi`): `text/event-stream`. The event name is the event type, the id is the event's seq, and the data is the whole `HarnessEvent` as JSON. Heartbeats are sent as the comment `hb`.
- Tests:
  - `EventStreamTest`: order, type filter, heartbeats, overflow, close.
  - `EventsApiIT`: during a planning create, events arrive in order (PENDING → HELD → UP), the wait loop converges, and the controller queue comes before the callback queue.

## Fault injection (11.x)
- `model/FaultRule`:
  - `queue`, `type` (DELAY, ERROR_REPLY, MALFORMED_REPLY, NO_REPLY; parsing ignores case and accepts `-`), `delayMs`, `probability`, `remaining`.
  - Read-only `id`, `createdAt`, `hits`.
- `faults/FaultStore`: validates rules and picks one per request.
  - Each served route registers its queue, and a rule for any other queue is rejected with `UNKNOWN_QUEUE`.
  - Other bad values are rejected with `INVALID_FAULT`.
  - The first matching rule that wins its probability roll is applied, and `remaining` is decremented. The rule is removed when `remaining` reaches 0.
- `wire/ServedRouteBuilder` applies the fault before the handler, so faulted requests have no side effects:
  - `delayMs` is applied first, if set.
  - DELAY: the request is then served normally.
  - ERROR_REPLY: the body is `null` and the `X-Harness-Error` header is set.
  - MALFORMED_REPLY: the body is truncated JSON.
  - NO_REPLY: the exchange is switched to InOnly, so Camel sends no reply and the caller times out.
  - The request's wire message gets `fault` = the type (`WireLog.markFault(id, fault)`).
- `api/FaultsApi` endpoints:
  - `GET /api/faults`
  - `GET /api/faults/queues`
  - `POST /api/faults`
  - `DELETE /api/faults/{id}` (404 `FAULT_NOT_FOUND`)
  - `DELETE /api/faults`
- `POST /api/reset` also clears fault rules, and `/api/status` reports `counts.faults`.
- Tests:
  - `FaultStoreTest`: validation, remaining, seeded probability.
  - `FaultInjectionIT`: REST CRUD and validation (unknown queue gives 400 UNKNOWN_QUEUE; unknown type gives 400 BAD_REQUEST). Each fault type is tested on `CATALOG.GET.RESOURCESPEC_BY_ID` through an OpenWire client:
    - DELAY: the reply comes back at least 650 ms late.
    - ERROR_REPLY: the body is `null`.
    - MALFORMED_REPLY: the body is not valid JSON.
    - NO_REPLY: the client times out.
    - Each test checks the wire `fault` field and that the rule stops after `remaining` uses.

## Result
Full suite: 134 tests, all green.
+60
Changes for .changelog/20261002_2320_scenario-runner.md: 60 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Scenario runner (tasks 12.1–12.5)

## Summary
Scenarios (design §8) can now be written in YAML or JSON, validated, run against a controller, and reported on through `/api/scenarios`.

## Added
- `scenario/Durations`: parses `500ms`, `20s`, `2m`, `1h`, `PT5S`, or plain seconds.
- `scenario/StepType`: lists the 12 step types, with each type's required and optional fields.
- `scenario/Scenario`, `Step`, `ScenarioException` (`INVALID_SCENARIO`, 400).
- `scenario/ScenarioParser`:
  - Uses YAMLMapper, so it accepts JSON too.
  - Validation errors name the step and field, e.g. `steps[2] (expectHealth): field 'final' has 'UPP'; expected one of [...]`.
  - Rejects unknown fields and duplicate create ids.
- `scenario/ScenarioRunner`:
  - Runs scenarios one at a time on a single thread and keeps the last 100 runs.
  - Scenario-local aliases (`k8s`) resolve to real resource ids.
  - Action steps: `waitForSpec`, `create`, `update`, `delete`, `sleep`, `fault`.
  - Expectation steps:
    - `expectHealth` (`sequence` as an ordered subsequence, or `final`);
    - `expectEstimate`, `expectCharacteristic`;
    - `expectMessage`, `expectNoMessage`;
    - `expectNoViolations`.
  - Polling steps honour `within`, falling back to `settings.within`.
  - `stopOnFailure` skips the remaining steps.
  - Publishes `scenario` events.
- `scenario/RunReport`:
  - Per-step status, timings, message and detail.
  - The alias→id map.
  - The wire slice and the violations since the run started.
- `api/ScenariosApi`:
  - `POST /api/scenarios/run[?wait=true]` (202 with a snapshot, or 200 with the finished report).
  - `POST /api/scenarios/validate`.
  - `GET /api/scenarios`, `GET /api/scenarios/{runId}` (404 `RUN_NOT_FOUND`).
- `DeploymentRequest.waitBudget`: a per-request override of `harness.planning.wait-budget`, used by `settings.waitBudget`.

## Changed
- `EventBus`:
  - Every listener now gets events in `seq` order. Events are numbered and queued under a short lock, and one thread drains the queue without holding a lock.
  - This fixes intermittent out-of-order ids on the SSE stream seen in `EventsApiIT`.
  - Holding a lock while listeners ran would have risked a deadlock with `ContractChecker.tick()`; the drainer avoids that.
- Test `StubGController`:
  - New `omitHealthHeaders` switch for the negative path.
  - Planning creates now echo `status.nodeCount`.

## Tests
- `ScenarioParserTest` (4 tests):
  - The §8 example parses.
  - JSON input and durations.
  - 19 malformed cases.
- `ScenarioRunnerIT` (6 tests):
  - The §8 scenario passes against the stub (regression for 12.4).
  - Production action and message steps.
  - Failing expectations, each with its message, including a `within` timeout.
  - `stopOnFailure` and `fault` steps.
  - Async run API, `scenario` events, 404 and 400.
  - **12.5 negative path:** with no health headers, the run reports `HEALTH_DECLARED` and `PLANNING_PROGRESSION` violations, the wait loop ends `TIMED_OUT`, and the RunReport is `FAILED`.
- Full suite: 144 tests, 0 failures.

## Not done
- 12.5 asks for one manual repeat against `gcontroller` with `ResourceRepoService.putHealth` disabled. It needs a modified gcontroller build and has not been done.
Loading