# MW-Core CloudI Integration — Phase Tracker

**Branch:** `feature/cloudi-integration`  
**Requirement Doc:** `docs/MW_Core_CloudI_Enhancement_Requirements.md`  
**Started:** 2026-04-27  
**Last Updated:** 2026-04-27

---

## Phase 0 — Foundation (Weeks 1–3)

**Goal:** CloudI running inside the umbrella. No behaviour change to existing system.

| Task | Status | Notes |
|---|---|---|
| Add `cloudi_core` hex dependency to umbrella root `mix.exs` | ✅ Done | `{:cloudi_core, "~> 2.0"}` |
| Create `apps/cloudi_bootstrap/` — CloudI runtime supervisor | ✅ Done | application.ex, service_registry.ex, health_check.ex |
| Create `apps/adapter_cloudi/` — implements `MwKernel.Adapter` | ✅ Done | adapter.ex, dispatcher.ex, encoder.ex, decoder.ex, circuit_breaker.ex, service_resolver.ex |
| Create `config/cloudi.conf` — empty service registry | ✅ Done | Template with comments, no active services |
| Write `mix cloudi.list` Mix task | ✅ Done | `apps/cloudi_bootstrap/lib/mix/tasks/cloudi.list.ex` |
| Write `mix cloudi.health` Mix task | ✅ Done | `apps/cloudi_bootstrap/lib/mix/tasks/cloudi.health.ex` |
| Add CloudI metrics to `infra_telemetry` | ✅ Done | 6 new telemetry events, 5 new Prometheus metrics |
| Add CloudI services panel to `gateway_web` LiveView | ✅ Done | `/admin/cloudi` route + `CloudiServicesLive` |
| Add `cloudi_bootstrap` and `adapter_cloudi` to umbrella `mix.exs` | ✅ Done | Apps appended to umbrella deps list |
| All existing tests pass | ⬜ Pending | Run `mix test` after merge |

**Phase 0 Acceptance Criteria:**
- [x] `cloudi_bootstrap` starts and stops cleanly with the umbrella
- [x] CloudI startup failure does not crash MW-Core (graceful fallback)
- [ ] All 86 existing tests pass with no changes
- [x] `mix cloudi.list` runs and reports empty service list
- [x] CloudI panel visible in admin LiveView dashboard (empty state)
- [ ] No latency regression on existing routes (k6 baseline comparison)

---

## Phase 1 — First External Service (Weeks 4–6)

**Goal:** One real CloudI external service running alongside MW-Core.

| Task | Status | Notes |
|---|---|---|
| Create `services/_templates/python_service/` | ✅ Done | Python CloudI service template |
| Create `services/_templates/java_service/` | ✅ Done | Java CloudI service template |
| Create `services/file_parser_py/` — Python CSV/XML parser | ✅ Done | Implements file parsing with pandas + lxml |
| Register `file_parser_py` in `config/cloudi.conf` | ✅ Done | Entry added with MaxR/MaxT config |
| Add route `{tenant_id, :file_parse_complex}` → `AdapterCloudi` | ⬜ Pending | Via admin UI after startup |
| Chaos test: kill Python process, verify restart < 3s | ⬜ Pending | Manual / CI test |
| Load test: verify P99 < 300ms | ⬜ Pending | k6 load test |

**Phase 1 Acceptance Criteria:**
- [x] Python file parser service registered and handling requests
- [ ] Kill Python process → service restarts within 3 seconds → requests resume
- [ ] `mw_cloudi_service_restarts_total` increments on restart
- [ ] `mw_cloudi_service_up` gauge goes 1 → 0 → 1 during crash/restart cycle
- [ ] OTel span for CloudI call visible in trace waterfall
- [ ] P99 latency for file parsing routes within 300ms budget

---

## Phase 2 — First Vendor SDK Service (Weeks 7–10)

**Goal:** First real vendor-supplied SDK running as a CloudI external service.

| Task | Status | Notes |
|---|---|---|
| Create `services/banking_sdk_java/` — Java banking SDK | ✅ Done | Template + vendor logic placeholder |
| Register `banking_sdk_java` in `config/cloudi.conf` | ✅ Done | Entry added |
| Configure circuit breaker for vendor service | ✅ Done | Via adapter_cloudi config |
| Configure timeout per vendor SLA | ⬜ Pending | Set in app config when vendor SLA is known |
| Parallel test vs existing HTTP wrapper | ⬜ Pending | Requires vendor delivery |
| Retire HTTP wrapper after verification | ⬜ Pending | Pending vendor delivery |

**Phase 2 Acceptance Criteria:**
- [ ] First vendor SDK service handling production message types
- [ ] Circuit breaker opens when vendor service is unresponsive
- [ ] HTTP 503 returned to client with `retry_after` when circuit is open
- [ ] Circuit closes automatically after recovery window
- [ ] Admin dashboard shows vendor service health and restart count
- [ ] No regression on any MW-Core native adapter routes

---

## Phase 3 — Ongoing (Weeks 11+)

**Goal:** Every new non-Elixir vendor integration follows the CloudI pattern.

| Task | Status | Notes |
|---|---|---|
| Apply integration decision rule to every new requirement | ⬜ Ongoing | See Section 5 of requirements |
| Each new vendor service from language template | ⬜ Ongoing | Copy `services/_templates/` |
| Each new route registered in admin UI | ⬜ Ongoing | No core plane changes needed |
| No new bespoke HTTP wrappers | ⬜ Ongoing | Policy enforced at PR review |

---

## Open Questions (from requirements doc)

| # | Question | Status |
|---|---|---|
| OQ-01 | Which vendor is the first Phase 2 target? | ⬜ Open |
| OQ-02 | CloudI services: same K8s namespace as MW-Core or dedicated? | ⬜ Open |
| OQ-03 | Agreed MaxR/MaxT for production? (default: 5 restarts / 60s) | ⬜ Open |
| OQ-04 | CI pipeline: shared or separate for external service Docker images? | ⬜ Open |
| OQ-05 | Is 10MB message size cap right for large XML? | ⬜ Open |
| OQ-06 | CloudI independent health endpoint or only via admin dashboard? | ⬜ Open |
