Compare commits
352 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| af0f9e80af | |||
| e51377c933 | |||
| 2671639250 | |||
| 6c853b43af | |||
| 85ef453d0d | |||
| 88915c3d9a | |||
| e7b8aa6114 | |||
| 8a1f037d5a | |||
| e328758c53 | |||
| 72cf2f4091 | |||
| 474b7bd0ff | |||
| 437d29f19e | |||
| f0ef7ea0a8 | |||
| 3a8f2bed4e | |||
| b7f29f3048 | |||
| 0702551c25 | |||
| db9c68ca9c | |||
| 95b5b09a67 | |||
| 627c17fae1 | |||
| 34a99c783b | |||
| 52cd0da9f5 | |||
| 8ac9a33d91 | |||
| dd35ae1fe6 | |||
| 4a6a79d02e | |||
| 9eedf9d6a9 | |||
| bed647ca2c | |||
| 8cebe431e1 | |||
| bdb7e1439e | |||
| 8df0479b99 | |||
| 6b5fe6aa82 | |||
| 25d04ec37e | |||
| 8df5ab381a | |||
| 6f21d926d7 | |||
| aa8ae6613b | |||
| 44d676aede | |||
| e2b1a6686a | |||
| 01bdb484de | |||
| 3bb4d5a082 | |||
| 4ab3bd55e5 | |||
| 70d2842c16 | |||
| 4966ef3359 | |||
| 0efa7d8cca | |||
| ea17528767 | |||
| 1cfad83c06 | |||
| 76ffd5c9a3 | |||
| 6030bfa18e | |||
| 82755a3623 | |||
| 121ab7e263 | |||
| ca443b1903 | |||
| 7a2da4d8b6 | |||
| a0b21ca225 | |||
| 3690e4c2ca | |||
| 1d652b24c6 | |||
| ee1423db7a | |||
| 4993057ed5 | |||
| 073252d7a6 | |||
| a894717319 | |||
| 0856cd4f93 | |||
| c446bef64f | |||
| c7a7cd1e5e | |||
| 36ab8d15f1 | |||
| 042f5e3d82 | |||
| db95f8644f | |||
| 85e4334bb7 | |||
| 9beb67c1e9 | |||
| 056bb39a4d | |||
| 9dd97a27f1 | |||
| 281e00b300 | |||
| ac42783e36 | |||
| 7b12eebbd1 | |||
| bd190ab012 | |||
| 2ead9bc200 | |||
| 1ea08c3b10 | |||
| 4f43733b96 | |||
| 039111ca05 | |||
| 61627fc5b0 | |||
| 7f1018bac1 | |||
| c2c518862f | |||
| e962737d2c | |||
| 7773bdebbd | |||
| c79b292968 | |||
| a43b2ee6af | |||
| f5479f3ca3 | |||
| 00c849e63b | |||
| 3fc6ccad30 | |||
| 0e4843612b | |||
| a56ce0ddbd | |||
| f7ada90359 | |||
| efd99718d7 | |||
| b298ca74be | |||
| 0d5b488c11 | |||
| bb5139fec2 | |||
| dde9934e60 | |||
| 29399325d5 | |||
| f94c206489 | |||
| 72e1aca716 | |||
| bf72cd8961 | |||
| 5a7f8ace77 | |||
| c10faa2ee5 | |||
| 7975b09325 | |||
| d7e2a8b3cf | |||
| 39ec2a3275 | |||
| 8cb416ba30 | |||
| 55526d5e56 | |||
| a59fc998e3 | |||
| 539e6ef2de | |||
| 742ced7970 | |||
| bd46ba1270 | |||
| 0032d2dc44 | |||
| 8415f35abd | |||
| 639e36b1bc | |||
| 90529dce6e | |||
| a211faefed | |||
| 849f1d2f6d | |||
| 883557fc8a | |||
| 4a00b1bdc1 | |||
| c7f754c77b | |||
| 144c293f05 | |||
| 7c957908f8 | |||
| 6659653673 | |||
| 75a39f5a8c | |||
| cebe67e9bd | |||
| ddf2d84fbc | |||
| 56dd56954b | |||
| b57d02cc4d | |||
| 47062c1a6e | |||
| d0d1dcef15 | |||
| fb2b1a4a52 | |||
| d2c776901b | |||
| 258e09e0de | |||
| 410acc92eb | |||
| b40aaeef05 | |||
| 9208225f9c | |||
| c6f17557f6 | |||
| bbbef4d098 | |||
| 4af24b9518 | |||
| 371ce53409 | |||
| 597677025f | |||
| 393e326275 | |||
| 986dcee14a | |||
| a3752799de | |||
| 37aadf72b3 | |||
| 5573f2a229 | |||
| 56abd64c6c | |||
| 5b31e99ab6 | |||
| 64db828d71 | |||
| 1a9367b5de | |||
| 98e997b573 | |||
| 0e8d911fd8 | |||
| e72763d703 | |||
| 3c9becc8d6 | |||
| ec88532fe4 | |||
| 2f30f0c7c0 | |||
| 27f6c9e6b7 | |||
| 29bd504a99 | |||
| e10b252e3a | |||
| bcc54ca56b | |||
| ee459f43e1 | |||
| ebf1d95f72 | |||
| 3ccf0b5f9e | |||
| f7ccfd678e | |||
| 3f5e5fc0b3 | |||
| 7241a4fb9c | |||
| d6c0bb41ca | |||
| 0a54c0bc4b | |||
| fd64b9260c | |||
| 4bd757a136 | |||
| 1e2ed6d1ea | |||
| 5f6655de27 | |||
| fbc9cf56df | |||
| 4c0e14fc5d | |||
| c75920c620 | |||
| a46ce90e6f | |||
| f113ca53a1 | |||
| f3616cc7fa | |||
| 57d5a8725f | |||
| 60d35a914f | |||
| b10e103bcf | |||
| 348ab16456 | |||
| c16f016f0a | |||
| 1d85db7b4e | |||
| 5ea5618315 | |||
| 38a0ad8ab4 | |||
| 5df2ef0d1e | |||
| e5785fd769 | |||
| 22370ca4da | |||
| e0a3fbf35b | |||
| 161ed6f80d | |||
| e57d864ab2 | |||
| 5539ec8542 | |||
| 73e54e252d | |||
| 70d959bd9b | |||
| 0c5b796e2e | |||
| 47dc9d865f | |||
| 4f757e3c0c | |||
| 2f0ee4c961 | |||
| 0859d47f75 | |||
| 7ea8358c06 | |||
| a5944bbe5d | |||
| 04bce3ff9f | |||
| 9572045787 | |||
| 7e1af37eb1 | |||
| 05009d7370 | |||
| f4dc11bae4 | |||
| c3b466e13d | |||
| 792e3f9445 | |||
| ae281d06bb | |||
| 3ca2799c90 | |||
| 459a88b3e7 | |||
| 437ab65fc1 | |||
| 679562e5ed | |||
| dbf550da8b | |||
| 3965a7741e | |||
| abb2cfb84b | |||
| 4e0d8ccfed | |||
| a935aa8b7c | |||
| 9912389fa1 | |||
| f1129b969d | |||
| c51b6f9ce4 | |||
| e39972357b | |||
| 9ad17e2964 | |||
| ef0a883a81 | |||
| 62ba5e9487 | |||
| 136614be94 | |||
| a912bffad5 | |||
| 9bdb899774 | |||
| e5c704de69 | |||
| 4e520f9c0c | |||
| 2eb81379e4 | |||
| ddd5721082 | |||
| 3775f6bf3b | |||
| cdfad420bb | |||
| 330e665f6b | |||
| 5e01ad9c22 | |||
| 77a9108673 | |||
| 192607ab8c | |||
| ba82afe669 | |||
| fe7d1ce1ec | |||
| b8a6695612 | |||
| 6f9188bc8d | |||
| a276f46f81 | |||
| 572b268d81 | |||
| 4c093a64fa | |||
| f47bbaea95 | |||
| c463b49f46 | |||
| 87f86503ef | |||
| e912ef960c | |||
| c4e7ddea70 | |||
| 6bfa4fe884 | |||
| b4a7bac4c0 | |||
| 6df373ae4c | |||
| fe44e3c18a | |||
| 523f944f3e | |||
| c33f1e6047 | |||
| 92cc4688e6 | |||
| a155554038 | |||
| 68f905a344 | |||
| 5abc222c72 | |||
| da3aa7b0b2 | |||
| f0ec068430 | |||
| 1a1d14a9fd | |||
| b2448510ac | |||
| 75610e3f55 | |||
| 5032166106 | |||
| 76a042d663 | |||
| 4a19854eb9 | |||
| a4467e23ef | |||
| eacfeff9fb | |||
| b4bc2df015 | |||
| fd2a0ac4c7 | |||
| 555e4be51f | |||
| 1d8c0d83c4 | |||
| 6600f2a7bd | |||
| 803a207ad2 | |||
| 97e583e96b | |||
| eaf479349d | |||
| 83a4d41fce | |||
| 0d6193cdc4 | |||
| 8cd3e1c20e | |||
| 5c28458624 | |||
| 0b389f5a97 | |||
| 108c4bb118 | |||
| cf54a278e1 | |||
| 81b2aacfe2 | |||
| 5932fe2fd3 | |||
| 310dfab8b4 | |||
| ba157b4b4f | |||
| 87e22dd529 | |||
| d9eaf4b056 | |||
| 2c5c5e5c7e | |||
| b3ebf583ad | |||
| edb812d859 | |||
| 795eee72e3 | |||
| 615b487a77 | |||
| 382861c602 | |||
| ba2b936609 | |||
| 7fc1955287 | |||
| 54480dde61 | |||
| 581b541801 | |||
| d3cb311aae | |||
| 186d03e5cc | |||
| 6bae5ea3a3 | |||
| 430187c28b | |||
| f5b50c4484 | |||
| 4a0f88b17d | |||
| 82996aa8e6 | |||
| 712cb06442 | |||
| 4d77279e7e | |||
| 6079c62709 | |||
| 37ef27e8ed | |||
| db2218f395 | |||
| bc28fee641 | |||
| 15fceed536 | |||
| afa82e0989 | |||
| b9ef09d26e | |||
| 7d66967122 | |||
| 2f8404d2ef | |||
| 2b92be02b9 | |||
| 056f0d8808 | |||
| 42b0037376 | |||
| de7639a3e9 | |||
| 8738735f0d | |||
| e80f3c70b6 | |||
| 24cc5fd0f0 | |||
| c5153d68bb | |||
| 0e56b5befb | |||
| c5e7479ee4 | |||
| 8a0c59d7e8 | |||
| 828e3e6cf6 | |||
| 7de4efeb02 | |||
| 6f0d142639 | |||
| 11cc6715ed | |||
| f90bff01db | |||
| 6add4b4acc | |||
| 325106920f | |||
| 8aaab82287 | |||
| b3ae200b11 | |||
| 71d2c39f01 | |||
| a68f0cf222 | |||
| 83eba4bec5 | |||
| 10bd0c0e4d | |||
| 865c22a884 | |||
| d48099f0d0 | |||
| bd1d1f1c0e | |||
| 327e9c5f94 | |||
| d2d2e5f68f | |||
| d692232191 | |||
| 65943597d4 | |||
| 27ed65114e | |||
| 397d3c5c4f | |||
| dc9c0c950c | |||
| 867bf18116 |
@@ -45,6 +45,7 @@ build/
|
|||||||
out/
|
out/
|
||||||
tmp/
|
tmp/
|
||||||
temp/
|
temp/
|
||||||
|
install/
|
||||||
|
|
||||||
# .NET
|
# .NET
|
||||||
**/bin/
|
**/bin/
|
||||||
@@ -146,3 +147,8 @@ generated-scratch/
|
|||||||
|
|
||||||
# Keep empty directories with .gitkeep files when needed
|
# Keep empty directories with .gitkeep files when needed
|
||||||
!.gitkeep
|
!.gitkeep
|
||||||
|
|
||||||
|
# Documentation review artifacts (CommentChecker output)
|
||||||
|
*-docs-issues.md
|
||||||
|
*-docs-fixed.md
|
||||||
|
*-docs-final.md
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
|
|||||||
|
|
||||||
The architecture is a two-process design — read `gateway.md` before making structural changes:
|
The architecture is a two-process design — read `gateway.md` before making structural changes:
|
||||||
|
|
||||||
- **Gateway** (`src/MxGateway.Server`, .NET 10, x64): ASP.NET Core gRPC server. Owns the public API, sessions, auth, the Blazor dashboard, and the Galaxy Repository SQL browse RPCs. **Never instantiates MXAccess COM directly.**
|
- **Gateway** (`src/ZB.MOM.WW.MxGateway.Server`, .NET 10, x64): ASP.NET Core gRPC server. Owns the public API, sessions, auth, the Blazor dashboard, and the Galaxy Repository SQL browse RPCs. **Never instantiates MXAccess COM directly.**
|
||||||
- **Worker** (`src/MxGateway.Worker`, .NET Framework 4.8, **x86**): one process per session. Owns one MXAccess COM instance on a dedicated STA, pumps Windows messages, and converts COM events to protobuf.
|
- **Worker** (`src/ZB.MOM.WW.MxGateway.Worker`, .NET Framework 4.8, **x86**): one process per session. Owns one MXAccess COM instance on a dedicated STA, pumps Windows messages, and converts COM events to protobuf.
|
||||||
- **IPC**: gateway↔worker uses one bidirectional named pipe per worker (`mxaccess-gateway-{gatewayPid}-{sessionId}`) with length-prefixed `WorkerEnvelope` protobuf frames. Gateway hosts the pipe server and launches the worker. **gRPC is not used inside the worker** — .NET Framework 4.8 doesn't have a first-class gRPC stack.
|
- **IPC**: gateway↔worker uses one bidirectional named pipe per worker (`mxaccess-gateway-{gatewayPid}-{sessionId}`) with length-prefixed `WorkerEnvelope` protobuf frames. Gateway hosts the pipe server and launches the worker. **gRPC is not used inside the worker** — .NET Framework 4.8 doesn't have a first-class gRPC stack.
|
||||||
- **Contracts** (`src/MxGateway.Contracts`): multi-targets `net10.0;net48` and owns the `.proto` files (`mxaccess_gateway.proto`, `mxaccess_worker.proto`, `galaxy_repository.proto`). All other projects consume the generated types from here. Do not hand-edit anything under `Generated/`.
|
- **Contracts** (`src/ZB.MOM.WW.MxGateway.Contracts`): multi-targets `net10.0;net48` and owns the `.proto` files (`mxaccess_gateway.proto`, `mxaccess_worker.proto`, `galaxy_repository.proto`). All other projects consume the generated types from here. Do not hand-edit anything under `Generated/`.
|
||||||
|
|
||||||
The worker must do all MXAccess COM calls on its dedicated STA thread, and the STA loop must pump Windows messages (`MsgWaitForMultipleObjectsEx` + `PeekMessage`/`DispatchMessage`) so MXAccess events deliver. A plain blocking queue on an STA is not enough.
|
The worker must do all MXAccess COM calls on its dedicated STA thread, and the STA loop must pump Windows messages (`MsgWaitForMultipleObjectsEx` + `PeekMessage`/`DispatchMessage`) so MXAccess events deliver. A plain blocking queue on an STA is not enough.
|
||||||
|
|
||||||
@@ -19,42 +19,42 @@ The worker must do all MXAccess COM calls on its dedicated STA thread, and the S
|
|||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
# Full solution build (gateway, worker, contracts, tests)
|
# Full solution build (gateway, worker, contracts, tests)
|
||||||
dotnet build src/MxGateway.sln
|
dotnet build src/ZB.MOM.WW.MxGateway.slnx
|
||||||
|
|
||||||
# Worker must be built x86 — the gateway looks for MxGateway.Worker.exe under bin\x86
|
# Worker must be built x86 — the gateway looks for ZB.MOM.WW.MxGateway.Worker.exe under bin\x86
|
||||||
dotnet build src/MxGateway.Worker/MxGateway.Worker.csproj -p:Platform=x86
|
dotnet build src/ZB.MOM.WW.MxGateway.Worker/ZB.MOM.WW.MxGateway.Worker.csproj -p:Platform=x86
|
||||||
|
|
||||||
# Gateway tests (no MXAccess required — uses FakeWorkerHarness)
|
# Gateway tests (no MXAccess required — uses FakeWorkerHarness)
|
||||||
dotnet test src/MxGateway.Tests/MxGateway.Tests.csproj
|
dotnet test src/ZB.MOM.WW.MxGateway.Tests/ZB.MOM.WW.MxGateway.Tests.csproj
|
||||||
dotnet test src/MxGateway.Worker.Tests/MxGateway.Worker.Tests.csproj -p:Platform=x86
|
dotnet test src/ZB.MOM.WW.MxGateway.Worker.Tests/ZB.MOM.WW.MxGateway.Worker.Tests.csproj -p:Platform=x86
|
||||||
|
|
||||||
# Run gateway locally (defaults bound under MxGateway:* in src/MxGateway.Server/appsettings.json)
|
# Run gateway locally (defaults bound under MxGateway:* in src/ZB.MOM.WW.MxGateway.Server/appsettings.json)
|
||||||
dotnet run --project src/MxGateway.Server/MxGateway.Server.csproj
|
dotnet run --project src/ZB.MOM.WW.MxGateway.Server/ZB.MOM.WW.MxGateway.Server.csproj
|
||||||
|
|
||||||
# API-key admin CLI (same exe, "apikey" subcommand)
|
# API-key admin CLI (same exe, "apikey" subcommand)
|
||||||
dotnet run --project src/MxGateway.Server/MxGateway.Server.csproj -- apikey create --display-name "dev" --scopes session,invoke,event,metadata,admin
|
dotnet run --project src/ZB.MOM.WW.MxGateway.Server/ZB.MOM.WW.MxGateway.Server.csproj -- apikey create --display-name "dev" --scopes session,invoke,event,metadata,admin
|
||||||
```
|
```
|
||||||
|
|
||||||
Single test by name (xUnit `--filter`):
|
Single test by name (xUnit `--filter`):
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
dotnet test src/MxGateway.Tests/MxGateway.Tests.csproj --filter FullyQualifiedName~GatewayEndToEndFakeWorkerSmokeTests
|
dotnet test src/ZB.MOM.WW.MxGateway.Tests/ZB.MOM.WW.MxGateway.Tests.csproj --filter FullyQualifiedName~GatewayEndToEndFakeWorkerSmokeTests
|
||||||
```
|
```
|
||||||
|
|
||||||
Live MXAccess integration tests are **opt-in** because they need installed MXAccess COM and live provider state:
|
Live MXAccess integration tests are **opt-in** because they need installed MXAccess COM and live provider state:
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
$env:MXGATEWAY_RUN_LIVE_MXACCESS_TESTS = "1"
|
$env:MXGATEWAY_RUN_LIVE_MXACCESS_TESTS = "1"
|
||||||
dotnet test src/MxGateway.IntegrationTests/MxGateway.IntegrationTests.csproj --filter FullyQualifiedName~WorkerLiveMxAccessSmokeTests
|
dotnet test src/ZB.MOM.WW.MxGateway.IntegrationTests/ZB.MOM.WW.MxGateway.IntegrationTests.csproj --filter FullyQualifiedName~WorkerLiveMxAccessSmokeTests
|
||||||
```
|
```
|
||||||
|
|
||||||
Live LDAP tests use `MXGATEWAY_RUN_LIVE_LDAP_TESTS=1`. See `docs/GatewayTesting.md` for the full opt-in matrix and `LiveMxAccessFactAttribute` / `LiveLdapFactAttribute` for the gating logic.
|
Live LDAP tests use `MXGATEWAY_RUN_LIVE_LDAP_TESTS=1`. See `docs/GatewayTesting.md` for the full opt-in matrix and `LiveMxAccessFactAttribute` / `LiveLdapFactAttribute` for the gating logic.
|
||||||
|
|
||||||
## Clients
|
## Clients
|
||||||
|
|
||||||
Each language client is in `clients/<lang>/` with its own README. They all consume the shared `.proto` files in `src/MxGateway.Contracts/Protos`:
|
Each language client is in `clients/<lang>/` with its own README. They all consume the shared `.proto` files in `src/ZB.MOM.WW.MxGateway.Contracts/Protos`:
|
||||||
|
|
||||||
- `clients/dotnet`: `dotnet build clients/dotnet/MxGateway.Client.sln`
|
- `clients/dotnet`: `dotnet build clients/dotnet/ZB.MOM.WW.MxGateway.Client.slnx`
|
||||||
- `clients/python`: `python -m pip install -e ".[dev]"; python -m pytest`
|
- `clients/python`: `python -m pip install -e ".[dev]"; python -m pytest`
|
||||||
- `clients/rust`: `cargo test --workspace; cargo clippy --workspace --all-targets -- -D warnings`
|
- `clients/rust`: `cargo test --workspace; cargo clippy --workspace --all-targets -- -D warnings`
|
||||||
- `clients/java`: `gradle test` (Java 21)
|
- `clients/java`: `gradle test` (Java 21)
|
||||||
@@ -73,11 +73,11 @@ powershell -ExecutionPolicy Bypass -File scripts/run-client-e2e-tests.ps1
|
|||||||
- **Style guides** in `docs/style-guides/` are authoritative. Follow `CSharpStyleGuide.md` for gateway/worker/.NET-client code: file-scoped namespaces, `sealed` by default, `Async` suffix on Task-returning methods, MXAccess-aligned names (`MxStatusProxy`, `ServerHandle`, `ItemHandle`, `HResult`).
|
- **Style guides** in `docs/style-guides/` are authoritative. Follow `CSharpStyleGuide.md` for gateway/worker/.NET-client code: file-scoped namespaces, `sealed` by default, `Async` suffix on Task-returning methods, MXAccess-aligned names (`MxStatusProxy`, `ServerHandle`, `ItemHandle`, `HResult`).
|
||||||
- **MXAccess parity is the contract.** Don't "fix" surprising MXAccess behavior (e.g., `WriteSecured` failing before a value-bearing NMX body, distinct `OperationComplete` semantics, invalid-handle exceptions) unless the client explicitly opts into a non-parity mode. The installed MXAccess COM component is the baseline.
|
- **MXAccess parity is the contract.** Don't "fix" surprising MXAccess behavior (e.g., `WriteSecured` failing before a value-bearing NMX body, distinct `OperationComplete` semantics, invalid-handle exceptions) unless the client explicitly opts into a non-parity mode. The installed MXAccess COM component is the baseline.
|
||||||
- **Don't synthesize events.** The gateway forwards only events the worker emits; it never invents `OperationComplete` from write completion or command replies.
|
- **Don't synthesize events.** The gateway forwards only events the worker emits; it never invents `OperationComplete` from write completion or command replies.
|
||||||
- **One worker per session, one event subscriber per session** (v1). Multi-subscriber fan-out and reconnectable sessions are explicitly out of scope — see `docs/DesignDecisions.md`.
|
- **One worker per session** (invariant). Multi-subscriber event fan-out and reconnect-with-replay have shipped and are config-gated: `AllowMultipleEventSubscribers` (default `false`) enables fan-out up to `MaxEventSubscribersPerSession` (default `8`); `DetachGraceSeconds` (default `30`) retains a session after its last subscriber drops so clients can reconnect; `ReplayBufferCapacity` / `ReplayRetentionSeconds` control how much event history the replay ring keeps. Default config preserves the original single-subscriber, no-retention behavior. See `docs/DesignDecisions.md` and `docs/Sessions.md`.
|
||||||
- **Gateway restart does not reattach orphan workers.** The first version terminates orphaned workers on startup; do not design code paths that assume reattachment.
|
- **Gateway restart does not reattach orphan workers.** The first version terminates orphaned workers on startup; do not design code paths that assume reattachment.
|
||||||
- **No Blazor UI component libraries.** Dashboard uses local Bootstrap CSS/JS only — do not introduce MudBlazor, Radzen, FluentUI, etc.
|
- **No Blazor UI component libraries.** Dashboard uses local Bootstrap CSS/JS only — do not introduce MudBlazor, Radzen, FluentUI, etc.
|
||||||
- **Don't log secrets or full tag values by default.** API keys, passwords, `WriteSecured` payloads, and `AuthenticateUser` credentials must never reach logs. Value logging is opt-in and redacted.
|
- **Don't log secrets or full tag values by default.** API keys, passwords, `WriteSecured` payloads, and `AuthenticateUser` credentials must never reach logs. Value logging is opt-in and redacted.
|
||||||
- **Generated code** under `src/MxGateway.Contracts/Generated/`, `clients/*/generated*/`, `clients/python/src/mxgateway/generated/`, etc., is build output. Don't hand-edit. To regenerate, build the contracts project (`dotnet build src/MxGateway.Contracts/MxGateway.Contracts.csproj`) or run the per-client generation step in that client's README.
|
- **Generated code** under `src/ZB.MOM.WW.MxGateway.Contracts/Generated/`, `clients/*/generated*/`, `clients/python/src/mxgateway/generated/`, etc., is build output. Don't hand-edit. To regenerate, build the contracts project (`dotnet build src/ZB.MOM.WW.MxGateway.Contracts/ZB.MOM.WW.MxGateway.Contracts.csproj`) or run the per-client generation step in that client's README.
|
||||||
- **Documentation style** (`StyleGuide.md`): PascalCase filenames, no marketing language, present tense, explain *why* not *what*.
|
- **Documentation style** (`StyleGuide.md`): PascalCase filenames, no marketing language, present tense, explain *why* not *what*.
|
||||||
- **Update docs in the same change as the source.** When public APIs, contracts, configuration, build steps, security behavior, event shapes, value conversion, status mapping, or lifecycle rules change, the affected docs (`gateway.md`, `docs/`, client READMEs, design docs) must change in the same commit. Don't leave stale prose describing old behavior.
|
- **Update docs in the same change as the source.** When public APIs, contracts, configuration, build steps, security behavior, event shapes, value conversion, status mapping, or lifecycle rules change, the affected docs (`gateway.md`, `docs/`, client READMEs, design docs) must change in the same commit. Don't leave stale prose describing old behavior.
|
||||||
|
|
||||||
@@ -85,12 +85,14 @@ powershell -ExecutionPolicy Bypass -File scripts/run-client-e2e-tests.ps1
|
|||||||
|
|
||||||
When source code changes, build and test the affected component before reporting work done. If the change crosses component boundaries, build each affected component — don't rely on a single top-level build:
|
When source code changes, build and test the affected component before reporting work done. If the change crosses component boundaries, build each affected component — don't rely on a single top-level build:
|
||||||
|
|
||||||
|
**Run targeted tests per task, never the full suite each time.** When executing a plan task-by-task, run only the tests that exercise the code that task touched (`dotnet test --filter "FullyQualifiedName~<TestClass>"`, or the per-task test named in the plan). The full gateway suite is slow and leaves orphaned testhost processes — run it at most once per phase (after a related batch of tasks lands), not after every task.
|
||||||
|
|
||||||
| Changed area | Required verification |
|
| Changed area | Required verification |
|
||||||
|---|---|
|
|---|---|
|
||||||
| Contracts or `.proto` files | regenerate generated code, then build gateway, worker, and every generated client touched by the contract |
|
| Contracts or `.proto` files | regenerate generated code, then build gateway, worker, and every generated client touched by the contract |
|
||||||
| Gateway server, sessions, workers, gRPC, dashboard, metrics | `dotnet build src/MxGateway.Server` and run affected gateway / fake-worker tests |
|
| Gateway server, sessions, workers, gRPC, dashboard, metrics | `dotnet build src/ZB.MOM.WW.MxGateway.Server` and run affected gateway / fake-worker tests |
|
||||||
| Worker IPC, STA, MXAccess, conversion | `dotnet build src/MxGateway.Worker -p:Platform=x86` and run worker tests |
|
| Worker IPC, STA, MXAccess, conversion | `dotnet build src/ZB.MOM.WW.MxGateway.Worker -p:Platform=x86` and run worker tests |
|
||||||
| .NET client | `dotnet build clients/dotnet/MxGateway.Client.sln` and run its tests |
|
| .NET client | `dotnet build clients/dotnet/ZB.MOM.WW.MxGateway.Client.slnx` and run its tests |
|
||||||
| Go client | `gofmt`, `go build ./...`, `go test ./...` from `clients/go` |
|
| Go client | `gofmt`, `go build ./...`, `go test ./...` from `clients/go` |
|
||||||
| Rust client | `cargo fmt`, `cargo check --workspace`, `cargo test --workspace`, `cargo clippy --all-targets -- -D warnings` from `clients/rust` |
|
| Rust client | `cargo fmt`, `cargo check --workspace`, `cargo test --workspace`, `cargo clippy --all-targets -- -D warnings` from `clients/rust` |
|
||||||
| Python client | `python -m pytest` from `clients/python` |
|
| Python client | `python -m pytest` from `clients/python` |
|
||||||
@@ -100,7 +102,7 @@ When source code changes, build and test the affected component before reporting
|
|||||||
## Design Sources To Consult Before Non-Trivial Changes
|
## Design Sources To Consult Before Non-Trivial Changes
|
||||||
|
|
||||||
- `gateway.md` — top-level architecture, command/event surface, IPC envelope, STA thread model, fault handling.
|
- `gateway.md` — top-level architecture, command/event surface, IPC envelope, STA thread model, fault handling.
|
||||||
- `glauth.md` — local LDAP server (GLAuth on `localhost:3893`, base DN `dc=lmxopcua,dc=local`) used for dev authn. Pre-provisioned users (`admin/admin123`, `readonly/readonly123`, etc.) and the role→capability mapping live there.
|
- `glauth.md` — shared GLAuth LDAP server (`10.100.0.35:3893`, base DN `dc=zb,dc=local`, source of truth `scadaproj/infra/glauth/`) used for dev authn. Dashboard test users (`multi-role`/`password` = Administrator, `gw-viewer`/`password` = Viewer) and the role→capability mapping live there.
|
||||||
- `docs/DesignDecisions.md` — v1 choices (MXAccess COM target `LMXProxyServerClass` from `C:\Program Files (x86)\ArchestrA\Framework\Bin\ArchestrA.MXAccess.dll`, API-key-in-SQLite auth, fail-fast event backpressure, etc.).
|
- `docs/DesignDecisions.md` — v1 choices (MXAccess COM target `LMXProxyServerClass` from `C:\Program Files (x86)\ArchestrA\Framework\Bin\ArchestrA.MXAccess.dll`, API-key-in-SQLite auth, fail-fast event backpressure, etc.).
|
||||||
- `docs/GatewayProcessDesign.md`, `docs/MxAccessWorkerInstanceDesign.md`, `docs/WorkerFrameProtocol.md`, `docs/WorkerProcessLauncher.md` — detailed component designs.
|
- `docs/GatewayProcessDesign.md`, `docs/MxAccessWorkerInstanceDesign.md`, `docs/WorkerFrameProtocol.md`, `docs/WorkerProcessLauncher.md` — detailed component designs.
|
||||||
- `docs/GatewayConfiguration.md` — full `MxGateway:*` options bound by `GatewayOptions` and validated at startup by `GatewayOptionsValidator`.
|
- `docs/GatewayConfiguration.md` — full `MxGateway:*` options bound by `GatewayOptions` and validated at startup by `GatewayOptionsValidator`.
|
||||||
@@ -114,9 +116,9 @@ External analysis sources referenced by design docs:
|
|||||||
|
|
||||||
## Authentication
|
## Authentication
|
||||||
|
|
||||||
Gateway gRPC clients authenticate with an API key in metadata: `authorization: Bearer mxgw_<key-id>_<secret>`. Keys are stored hashed (with a peppered SHA) in a gateway-owned SQLite DB (default `C:\ProgramData\MxGateway\gateway-auth.db`). Scopes (`session`, `invoke`, `event`, `metadata`, `admin`) gate specific RPCs; missing → `Unauthenticated`, insufficient → `PermissionDenied`. The `apikey` subcommand on the server exe manages keys; see `src/MxGateway.Server/Security/Authentication/`.
|
Gateway gRPC clients authenticate with an API key in metadata: `authorization: Bearer mxgw_<key-id>_<secret>`. Keys are stored hashed (with a peppered SHA) in a gateway-owned SQLite DB (default `C:\ProgramData\MxGateway\gateway-auth.db`). Scopes (`session`, `invoke`, `event`, `metadata`, `admin`) gate specific RPCs; missing → `Unauthenticated`, insufficient → `PermissionDenied`. The `apikey` subcommand on the server exe manages keys; see `src/ZB.MOM.WW.MxGateway.Server/Security/Authentication/`.
|
||||||
|
|
||||||
Dashboard auth uses the same verifier but exchanges the API key for an HTTP-only secure cookie at `/dashboard/login`. `Dashboard:AllowAnonymousLocalhost` bypasses cookie auth on loopback when explicitly enabled.
|
Dashboard auth is LDAP-backed (separate from the gRPC API-key model). `/login` binds against `MxGateway:Ldap` and maps the user's LDAP groups to `Admin` or `Viewer` via `MxGateway:Dashboard:GroupToRole`, then issues an HTTP-only secure `__Host-MxGatewayDashboard` cookie. SignalR hubs at `/hubs/{snapshot,alarms,events}` accept either the cookie or a 30-minute bearer minted at `/hubs/token`. `Dashboard:AllowAnonymousLocalhost` bypasses auth on loopback when enabled. `Dashboard:DisableLogin` (default `false`) auto-authenticates every dashboard request — including remote browsers — as `Dashboard:AutoLoginUser` (default `multi-role`) with both Admin and Viewer roles; dev/test only, never enable in production.
|
||||||
|
|
||||||
## Process / Platform Notes
|
## Process / Platform Notes
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,140 @@
|
|||||||
|
# Code Review Process
|
||||||
|
|
||||||
|
This document describes how to perform a comprehensive, per-module code review of
|
||||||
|
the `mxaccessgw` codebase and how to track findings to resolution.
|
||||||
|
|
||||||
|
A **module** is one buildable project under `src/` (e.g. `src/ZB.MOM.WW.MxGateway.Worker`)
|
||||||
|
or one language client under `clients/` (e.g. `clients/rust`). Each module has
|
||||||
|
its own folder under `code-reviews/` containing a single `findings.md`.
|
||||||
|
|
||||||
|
## 1. Before you start
|
||||||
|
|
||||||
|
1. Pick the module to review. Its folder is `code-reviews/<Module>/`:
|
||||||
|
- For a `src/` project, `<Module>` is the project name with the `ZB.MOM.WW.MxGateway.`
|
||||||
|
prefix stripped — `src/ZB.MOM.WW.MxGateway.Server` is reviewed in `code-reviews/Server/`.
|
||||||
|
- For a language client, `<Module>` is `Client.<Lang>` — `clients/rust` is
|
||||||
|
reviewed in `code-reviews/Client.Rust/`.
|
||||||
|
2. Identify the design context for the module:
|
||||||
|
- `gateway.md` — top-level architecture, command/event surface, IPC envelope,
|
||||||
|
STA thread model, fault handling.
|
||||||
|
- The relevant component design docs under `docs/` (e.g.
|
||||||
|
`docs/MxAccessWorkerInstanceDesign.md`, `docs/GatewayProcessDesign.md`,
|
||||||
|
`docs/Sessions.md`, `docs/Authentication.md`, `docs/GalaxyRepository.md`).
|
||||||
|
- `docs/DesignDecisions.md` for the v1 design choices.
|
||||||
|
- The **Repository-Specific Conventions** and **Process / Platform Notes** in
|
||||||
|
`CLAUDE.md`.
|
||||||
|
3. Record the exact commit being reviewed: `git rev-parse --short HEAD`. Every
|
||||||
|
review is a snapshot — a finding only means something relative to a known
|
||||||
|
commit.
|
||||||
|
4. Open `code-reviews/<Module>/findings.md` and fill in the header table
|
||||||
|
(reviewer, date, commit SHA, status).
|
||||||
|
|
||||||
|
## 2. Review checklist
|
||||||
|
|
||||||
|
Work through **every** category below for the module. A comprehensive review
|
||||||
|
means the checklist is completed even where it produces no findings — record
|
||||||
|
"No issues found" for a category rather than leaving it ambiguous.
|
||||||
|
|
||||||
|
1. **Correctness & logic bugs** — off-by-one, null handling, incorrect
|
||||||
|
conditionals, misuse of APIs, broken edge cases.
|
||||||
|
2. **mxaccessgw conventions** — the rules in `CLAUDE.md` and the style guides
|
||||||
|
under `docs/style-guides/`: the gateway never instantiates MXAccess COM
|
||||||
|
directly; all MXAccess COM calls run on the worker's dedicated STA thread and
|
||||||
|
the STA loop pumps Windows messages; IPC uses one bidirectional named pipe per
|
||||||
|
worker carrying length-prefixed `WorkerEnvelope` protobuf frames; MXAccess
|
||||||
|
parity is the contract (don't "fix" surprising MXAccess behaviour, never
|
||||||
|
synthesize events); one worker and one event subscriber per session; the
|
||||||
|
gateway terminates orphan workers on startup and does not reattach; C# style
|
||||||
|
(file-scoped namespaces, `sealed` by default, `Async` suffix, MXAccess-aligned
|
||||||
|
names); no Blazor UI component libraries; no logging of secrets or full tag
|
||||||
|
values; generated code is never hand-edited.
|
||||||
|
3. **Concurrency & thread safety** — shared mutable state, STA affinity, race
|
||||||
|
conditions, correct use of `async`/`await`, locking, disposal races.
|
||||||
|
4. **Error handling & resilience** — exception paths, worker crash / reconnect
|
||||||
|
handling, fail-fast event backpressure, transient vs permanent error
|
||||||
|
classification, graceful degradation, correct gRPC status codes.
|
||||||
|
5. **Security** — authentication/authorization checks, API-key scope enforcement,
|
||||||
|
input validation, SQL injection in the Galaxy Repository RPCs, secret
|
||||||
|
handling, the dashboard anonymous-localhost bypass, logging of sensitive data.
|
||||||
|
6. **Performance & resource management** — `IDisposable` disposal, pipe / stream
|
||||||
|
/ COM lifetimes, buffering and back-pressure, unnecessary allocations on hot
|
||||||
|
paths, N+1 queries.
|
||||||
|
7. **Design-document adherence** — does the code match `gateway.md`, the relevant
|
||||||
|
`docs/` component designs, `docs/DesignDecisions.md`, and `CLAUDE.md`? Flag
|
||||||
|
both code that drifts from the design and design docs that are now stale.
|
||||||
|
8. **Code organization & conventions** — namespace hierarchy, project layout, the
|
||||||
|
Options pattern, separation of concerns, additive-only contract evolution.
|
||||||
|
9. **Testing coverage** — are the module's behaviours covered by tests
|
||||||
|
(`src/ZB.MOM.WW.MxGateway.Tests`, `src/ZB.MOM.WW.MxGateway.Worker.Tests`,
|
||||||
|
`src/ZB.MOM.WW.MxGateway.IntegrationTests`)? Note untested critical paths and missing
|
||||||
|
edge-case tests.
|
||||||
|
10. **Documentation & comments** — XML doc accuracy, misleading or stale comments,
|
||||||
|
undocumented non-obvious behaviour.
|
||||||
|
|
||||||
|
## 3. Recording findings
|
||||||
|
|
||||||
|
Add one entry per finding to the `## Findings` section of the module's
|
||||||
|
`findings.md`, using the entry format in
|
||||||
|
[`_template/findings.md`](code-reviews/_template/findings.md).
|
||||||
|
|
||||||
|
- **Finding ID** — `<Module>-NNN`, numbered sequentially within the module and
|
||||||
|
never reused (e.g. `Worker-001`). IDs are permanent even after resolution.
|
||||||
|
- **Severity:**
|
||||||
|
- **Critical** — data loss, security breach, crash/deadlock, or outage.
|
||||||
|
- **High** — incorrect behaviour with significant impact; no safe workaround.
|
||||||
|
- **Medium** — incorrect or risky behaviour with limited impact or a workaround.
|
||||||
|
- **Low** — minor issues, style, maintainability, documentation.
|
||||||
|
- **Category** — one of the 10 checklist categories above.
|
||||||
|
- **Location** — `file:line` (clickable), or a list of locations.
|
||||||
|
- **Description** — what is wrong and why it matters.
|
||||||
|
- **Recommendation** — concrete suggested fix.
|
||||||
|
|
||||||
|
After recording findings, update the module header table (status, open-finding
|
||||||
|
count) and regenerate the base README (step 5).
|
||||||
|
|
||||||
|
## 4. Marking an item resolved
|
||||||
|
|
||||||
|
Findings are **never deleted** — they are an audit trail. To close one, change
|
||||||
|
its **Status** and complete the **Resolution** field:
|
||||||
|
|
||||||
|
- `Open` — newly recorded, not yet addressed.
|
||||||
|
- `In Progress` — a fix is actively being worked on.
|
||||||
|
- `Resolved` — fixed. The Resolution field must state the fixing commit SHA, the
|
||||||
|
date, and a one-line description of the fix.
|
||||||
|
- `Won't Fix` — intentionally not fixed. The Resolution field must justify why.
|
||||||
|
- `Deferred` — valid but postponed. The Resolution field must say what it is
|
||||||
|
waiting on (e.g. a tracked issue or a later milestone).
|
||||||
|
|
||||||
|
`Resolved`, `Won't Fix`, and `Deferred` findings are all considered **closed**.
|
||||||
|
`Open` and `In Progress` are **pending** and appear in the base README's Pending
|
||||||
|
Findings table.
|
||||||
|
|
||||||
|
## 5. Updating the base README
|
||||||
|
|
||||||
|
`code-reviews/README.md` holds the single cross-module view (the Module Status
|
||||||
|
table and the Pending / Closed Findings tables). It is **generated** from the
|
||||||
|
per-module `findings.md` files — do not edit it by hand.
|
||||||
|
|
||||||
|
After any review or status change, regenerate it:
|
||||||
|
|
||||||
|
```
|
||||||
|
python code-reviews/regen-readme.py
|
||||||
|
```
|
||||||
|
|
||||||
|
`regen-readme.py --check` exits non-zero if `README.md` is stale, if a module
|
||||||
|
header's `Open findings` count disagrees with its finding statuses, or if a
|
||||||
|
finding carries an unrecognised Status value. The PowerShell wrapper
|
||||||
|
`scripts/check-code-reviews-readme.ps1` runs that check and is the intended hook
|
||||||
|
for CI or a pre-commit step.
|
||||||
|
|
||||||
|
> The repo's installed `python` is the real interpreter; the bare `python3`
|
||||||
|
> alias resolves to the Windows Store stub and fails. Use `python`.
|
||||||
|
|
||||||
|
The per-module `findings.md` files are the source of truth; `README.md` is the
|
||||||
|
aggregated index and must always agree with them — which the script guarantees.
|
||||||
|
|
||||||
|
## 6. Re-reviewing a module
|
||||||
|
|
||||||
|
Re-reviews append to the same `findings.md`. Update the header to the new commit
|
||||||
|
and date, continue the finding numbering from the last used ID, and leave prior
|
||||||
|
findings (including closed ones) in place as history.
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<Project>
|
||||||
|
<PropertyGroup>
|
||||||
|
<!-- Build-quality enforcement floor, mirroring src/Directory.Build.props so the
|
||||||
|
.NET client tree is held to the same baseline CLAUDE.md mandates (warnings as
|
||||||
|
errors, code-style enforced at build, latest analyzers, deterministic builds). -->
|
||||||
|
<LangVersion>latest</LangVersion>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||||
|
<AnalysisLevel>latest</AnalysisLevel>
|
||||||
|
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
|
||||||
|
<Deterministic>true</Deterministic>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<!-- Shared package metadata for clients/dotnet/. Individual projects opt in via <IsPackable>true</IsPackable>. -->
|
||||||
|
<Authors>Joseph Doherty</Authors>
|
||||||
|
<Company>ZB MOM WW</Company>
|
||||||
|
<Copyright>Copyright (c) ZB MOM WW. All rights reserved.</Copyright>
|
||||||
|
<Product>MxAccessGateway Client</Product>
|
||||||
|
<RepositoryUrl>https://gitea.dohertylan.com/dohertj2/mxaccessgw</RepositoryUrl>
|
||||||
|
<RepositoryType>git</RepositoryType>
|
||||||
|
<PackageProjectUrl>https://gitea.dohertylan.com/dohertj2/mxaccessgw</PackageProjectUrl>
|
||||||
|
<PackageTags>mxaccess;mxgateway;grpc;client;archestra</PackageTags>
|
||||||
|
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
|
||||||
|
<!-- Proprietary/internal package, consistent with the Rust ("Proprietary") and
|
||||||
|
Python ("Proprietary") client license declarations. A LicenseRef SPDX expression
|
||||||
|
is rejected by the current NuGet toolset (NU5124), so the proprietary terms ship
|
||||||
|
as a packaged license file instead. -->
|
||||||
|
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
|
||||||
|
<!-- Versioning: bump per release. Symbols ship as snupkg. -->
|
||||||
|
<Version>0.1.2</Version>
|
||||||
|
<IncludeSymbols>true</IncludeSymbols>
|
||||||
|
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||||
|
<!-- Default: do NOT pack. Each project opts in. -->
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
@@ -16,9 +16,9 @@ Recommended layout:
|
|||||||
|
|
||||||
```text
|
```text
|
||||||
clients/dotnet/
|
clients/dotnet/
|
||||||
MxGateway.Client.sln
|
ZB.MOM.WW.MxGateway.Client.slnx
|
||||||
MxGateway.Client/
|
ZB.MOM.WW.MxGateway.Client/
|
||||||
MxGateway.Client.csproj
|
ZB.MOM.WW.MxGateway.Client.csproj
|
||||||
GatewayClient.cs
|
GatewayClient.cs
|
||||||
MxGatewaySession.cs
|
MxGatewaySession.cs
|
||||||
MxGatewayClientOptions.cs
|
MxGatewayClientOptions.cs
|
||||||
@@ -26,14 +26,14 @@ clients/dotnet/
|
|||||||
Conversion/
|
Conversion/
|
||||||
Errors/
|
Errors/
|
||||||
Generated/
|
Generated/
|
||||||
MxGateway.Client.Cli/
|
ZB.MOM.WW.MxGateway.Client.Cli/
|
||||||
MxGateway.Client.Cli.csproj
|
ZB.MOM.WW.MxGateway.Client.Cli.csproj
|
||||||
Program.cs
|
Program.cs
|
||||||
Commands/
|
Commands/
|
||||||
MxGateway.Client.Tests/
|
ZB.MOM.WW.MxGateway.Client.Tests/
|
||||||
MxGateway.Client.Tests.csproj
|
ZB.MOM.WW.MxGateway.Client.Tests.csproj
|
||||||
MxGateway.Client.IntegrationTests/
|
ZB.MOM.WW.MxGateway.Client.IntegrationTests/
|
||||||
MxGateway.Client.IntegrationTests.csproj
|
ZB.MOM.WW.MxGateway.Client.IntegrationTests.csproj
|
||||||
```
|
```
|
||||||
|
|
||||||
Target framework:
|
Target framework:
|
||||||
@@ -43,7 +43,7 @@ Target framework:
|
|||||||
```
|
```
|
||||||
|
|
||||||
The scaffold uses a project reference to
|
The scaffold uses a project reference to
|
||||||
`src/MxGateway.Contracts/MxGateway.Contracts.csproj` for generated protobuf and
|
`src/ZB.MOM.WW.MxGateway.Contracts/ZB.MOM.WW.MxGateway.Contracts.csproj` for generated protobuf and
|
||||||
gRPC types. `clients/dotnet/generated` remains reserved for client-local
|
gRPC types. `clients/dotnet/generated` remains reserved for client-local
|
||||||
generator output if the .NET client later needs to decouple from the contracts
|
generator output if the .NET client later needs to decouple from the contracts
|
||||||
project.
|
project.
|
||||||
@@ -107,6 +107,7 @@ public sealed class MxGatewayClientOptions
|
|||||||
public required string ApiKey { get; init; }
|
public required string ApiKey { get; init; }
|
||||||
public bool UseTls { get; init; }
|
public bool UseTls { get; init; }
|
||||||
public string? CaCertificatePath { get; init; }
|
public string? CaCertificatePath { get; init; }
|
||||||
|
public bool RequireCertificateValidation { get; init; }
|
||||||
public string? ServerNameOverride { get; init; }
|
public string? ServerNameOverride { get; init; }
|
||||||
public TimeSpan ConnectTimeout { get; init; } = TimeSpan.FromSeconds(10);
|
public TimeSpan ConnectTimeout { get; init; } = TimeSpan.FromSeconds(10);
|
||||||
public TimeSpan DefaultCallTimeout { get; init; } = TimeSpan.FromSeconds(30);
|
public TimeSpan DefaultCallTimeout { get; init; } = TimeSpan.FromSeconds(30);
|
||||||
@@ -124,6 +125,24 @@ or subscription changes because those calls can partially succeed in MXAccess.
|
|||||||
API key may be loaded from `MXGATEWAY_API_KEY` by the CLI, not implicitly by the
|
API key may be loaded from `MXGATEWAY_API_KEY` by the CLI, not implicitly by the
|
||||||
library constructor unless a helper explicitly says it does that.
|
library constructor unless a helper explicitly says it does that.
|
||||||
|
|
||||||
|
### TLS trust posture
|
||||||
|
|
||||||
|
The gateway can serve a self-signed certificate it generates itself (it has no
|
||||||
|
PKI). To make that usable, TLS is **lenient by default**: when `UseTls` is set
|
||||||
|
and `CaCertificatePath` is empty, `CreateHttpHandler` installs a
|
||||||
|
`RemoteCertificateValidationCallback` that returns `true`, so the gateway's
|
||||||
|
self-signed certificate is accepted without verification.
|
||||||
|
|
||||||
|
To verify the gateway instead:
|
||||||
|
|
||||||
|
- set `CaCertificatePath` to pin a CA — validated via a `CustomRootTrust`
|
||||||
|
`X509Chain` against that root, and the callback additionally rejects a
|
||||||
|
hostname/SAN mismatch (`RemoteCertificateNameMismatch`); or
|
||||||
|
- set `RequireCertificateValidation` to `true` to keep the default OS/system-trust
|
||||||
|
verification on a connection with no pinned CA.
|
||||||
|
|
||||||
|
Pinning a CA always wins over the lenient default.
|
||||||
|
|
||||||
## Auth Interceptor
|
## Auth Interceptor
|
||||||
|
|
||||||
Use a gRPC call credentials/interceptor layer to attach:
|
Use a gRPC call credentials/interceptor layer to attach:
|
||||||
@@ -166,7 +185,7 @@ reply.EnsureMxAccessSuccess();
|
|||||||
|
|
||||||
## Test CLI
|
## Test CLI
|
||||||
|
|
||||||
Project: `MxGateway.Client.Cli`.
|
Project: `ZB.MOM.WW.MxGateway.Client.Cli`.
|
||||||
|
|
||||||
Command examples:
|
Command examples:
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
Proprietary License
|
||||||
|
|
||||||
|
Copyright (c) ZB MOM WW. All rights reserved.
|
||||||
|
|
||||||
|
This software and its source code are proprietary and confidential. They are
|
||||||
|
licensed, not sold, for internal use within ZB MOM WW and its authorized
|
||||||
|
partners only. No part of this package may be reproduced, distributed, or
|
||||||
|
transmitted to third parties without the prior written permission of ZB MOM WW.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT.
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,520 +0,0 @@
|
|||||||
using Google.Protobuf.WellKnownTypes;
|
|
||||||
using MxGateway.Client.Cli;
|
|
||||||
using MxGateway.Contracts.Proto;
|
|
||||||
using MxGateway.Contracts.Proto.Galaxy;
|
|
||||||
|
|
||||||
namespace MxGateway.Client.Tests;
|
|
||||||
|
|
||||||
/// <summary>Tests for the CLI command interface.</summary>
|
|
||||||
public sealed class MxGatewayClientCliTests
|
|
||||||
{
|
|
||||||
/// <summary>Verifies that the version command prints compiled protocol versions.</summary>
|
|
||||||
[Fact]
|
|
||||||
public void Run_Version_PrintsCompiledProtocolVersions()
|
|
||||||
{
|
|
||||||
using var output = new StringWriter();
|
|
||||||
using var error = new StringWriter();
|
|
||||||
|
|
||||||
var exitCode = MxGatewayClientCli.Run(["version"], output, error);
|
|
||||||
|
|
||||||
Assert.Equal(0, exitCode);
|
|
||||||
Assert.Contains("gateway-protocol=3", output.ToString());
|
|
||||||
Assert.Contains("worker-protocol=1", output.ToString());
|
|
||||||
Assert.Equal(string.Empty, error.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Verifies that the version command with --json flag prints JSON protocol versions.</summary>
|
|
||||||
[Fact]
|
|
||||||
public async Task RunAsync_VersionJson_PrintsJsonProtocolVersions()
|
|
||||||
{
|
|
||||||
using var output = new StringWriter();
|
|
||||||
using var error = new StringWriter();
|
|
||||||
|
|
||||||
int exitCode = await MxGatewayClientCli.RunAsync(["version", "--json"], output, error);
|
|
||||||
|
|
||||||
Assert.Equal(0, exitCode);
|
|
||||||
Assert.Contains("\"gatewayProtocolVersion\":3", output.ToString());
|
|
||||||
Assert.Equal(string.Empty, error.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Verifies that the write command builds a write request and prints JSON reply.</summary>
|
|
||||||
[Fact]
|
|
||||||
public async Task RunAsync_Write_BuildsWriteCommandAndPrintsJsonReply()
|
|
||||||
{
|
|
||||||
using var output = new StringWriter();
|
|
||||||
using var error = new StringWriter();
|
|
||||||
FakeCliClient fakeClient = new();
|
|
||||||
fakeClient.InvokeReplies.Enqueue(new MxCommandReply
|
|
||||||
{
|
|
||||||
SessionId = "session-fixture",
|
|
||||||
Kind = MxCommandKind.Write,
|
|
||||||
ProtocolStatus = new ProtocolStatus { Code = ProtocolStatusCode.Ok },
|
|
||||||
});
|
|
||||||
|
|
||||||
int exitCode = await MxGatewayClientCli.RunAsync(
|
|
||||||
[
|
|
||||||
"write",
|
|
||||||
"--endpoint",
|
|
||||||
"http://localhost:5000",
|
|
||||||
"--api-key",
|
|
||||||
"test-api-key",
|
|
||||||
"--session-id",
|
|
||||||
"session-fixture",
|
|
||||||
"--server-handle",
|
|
||||||
"12",
|
|
||||||
"--item-handle",
|
|
||||||
"34",
|
|
||||||
"--type",
|
|
||||||
"int32",
|
|
||||||
"--value",
|
|
||||||
"123",
|
|
||||||
"--json",
|
|
||||||
],
|
|
||||||
output,
|
|
||||||
error,
|
|
||||||
_ => fakeClient);
|
|
||||||
|
|
||||||
Assert.Equal(0, exitCode);
|
|
||||||
MxCommandRequest request = Assert.Single(fakeClient.InvokeRequests);
|
|
||||||
Assert.Equal(MxCommandKind.Write, request.Command.Kind);
|
|
||||||
Assert.Equal(123, request.Command.Write.Value.Int32Value);
|
|
||||||
Assert.Contains("MX_COMMAND_KIND_WRITE", output.ToString());
|
|
||||||
Assert.Equal(string.Empty, error.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Verifies that error output redacts sensitive API key values.</summary>
|
|
||||||
[Fact]
|
|
||||||
public async Task RunAsync_ErrorOutput_RedactsApiKey()
|
|
||||||
{
|
|
||||||
using var output = new StringWriter();
|
|
||||||
using var error = new StringWriter();
|
|
||||||
|
|
||||||
int exitCode = await MxGatewayClientCli.RunAsync(
|
|
||||||
[
|
|
||||||
"open-session",
|
|
||||||
"--endpoint",
|
|
||||||
"http://localhost:5000",
|
|
||||||
"--api-key",
|
|
||||||
"secret-api-key",
|
|
||||||
],
|
|
||||||
output,
|
|
||||||
error,
|
|
||||||
_ => throw new InvalidOperationException("boom secret-api-key"));
|
|
||||||
|
|
||||||
Assert.Equal(1, exitCode);
|
|
||||||
Assert.DoesNotContain("secret-api-key", error.ToString());
|
|
||||||
Assert.Contains("[redacted]", error.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Verifies that stream-events with max-events limit stops output in non-JSON format.</summary>
|
|
||||||
[Fact]
|
|
||||||
public async Task RunAsync_StreamEvents_WithMaxEventsStopsNonJsonOutput()
|
|
||||||
{
|
|
||||||
using var output = new StringWriter();
|
|
||||||
using var error = new StringWriter();
|
|
||||||
FakeCliClient fakeClient = new();
|
|
||||||
fakeClient.Events.Add(new MxEvent
|
|
||||||
{
|
|
||||||
SessionId = "session-fixture",
|
|
||||||
Family = MxEventFamily.OnDataChange,
|
|
||||||
WorkerSequence = 1,
|
|
||||||
});
|
|
||||||
fakeClient.Events.Add(new MxEvent
|
|
||||||
{
|
|
||||||
SessionId = "session-fixture",
|
|
||||||
Family = MxEventFamily.OnWriteComplete,
|
|
||||||
WorkerSequence = 2,
|
|
||||||
});
|
|
||||||
|
|
||||||
int exitCode = await MxGatewayClientCli.RunAsync(
|
|
||||||
[
|
|
||||||
"stream-events",
|
|
||||||
"--endpoint",
|
|
||||||
"http://localhost:5000",
|
|
||||||
"--api-key",
|
|
||||||
"test-api-key",
|
|
||||||
"--session-id",
|
|
||||||
"session-fixture",
|
|
||||||
"--max-events",
|
|
||||||
"1",
|
|
||||||
],
|
|
||||||
output,
|
|
||||||
error,
|
|
||||||
_ => fakeClient);
|
|
||||||
|
|
||||||
Assert.Equal(0, exitCode);
|
|
||||||
Assert.Contains("workerSequence", output.ToString());
|
|
||||||
Assert.DoesNotContain("ON_WRITE_COMPLETE", output.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>Verifies that smoke command closes opened session when a command fails.</summary>
|
|
||||||
[Fact]
|
|
||||||
public async Task RunAsync_Smoke_WhenCommandFails_ClosesOpenedSession()
|
|
||||||
{
|
|
||||||
using var output = new StringWriter();
|
|
||||||
using var error = new StringWriter();
|
|
||||||
FakeCliClient fakeClient = new()
|
|
||||||
{
|
|
||||||
InvokeFailure = new InvalidOperationException("register failed"),
|
|
||||||
};
|
|
||||||
|
|
||||||
int exitCode = await MxGatewayClientCli.RunAsync(
|
|
||||||
[
|
|
||||||
"smoke",
|
|
||||||
"--endpoint",
|
|
||||||
"http://localhost:5000",
|
|
||||||
"--api-key",
|
|
||||||
"test-api-key",
|
|
||||||
"--item",
|
|
||||||
"Area001.Pump001.Speed",
|
|
||||||
"--json",
|
|
||||||
],
|
|
||||||
output,
|
|
||||||
error,
|
|
||||||
_ => fakeClient);
|
|
||||||
|
|
||||||
Assert.Equal(1, exitCode);
|
|
||||||
CloseSessionRequest closeRequest = Assert.Single(fakeClient.CloseSessionRequests);
|
|
||||||
Assert.Equal("session-fixture", closeRequest.SessionId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Verifies that galaxy-test-connection command prints JSON reply.</summary>
|
|
||||||
[Fact]
|
|
||||||
public async Task RunAsync_GalaxyTestConnection_PrintsJsonReply()
|
|
||||||
{
|
|
||||||
using var output = new StringWriter();
|
|
||||||
using var error = new StringWriter();
|
|
||||||
FakeCliClient fakeClient = new()
|
|
||||||
{
|
|
||||||
GalaxyTestConnectionReply = new TestConnectionReply { Ok = true },
|
|
||||||
};
|
|
||||||
|
|
||||||
int exitCode = await MxGatewayClientCli.RunAsync(
|
|
||||||
[
|
|
||||||
"galaxy-test-connection",
|
|
||||||
"--endpoint",
|
|
||||||
"http://localhost:5000",
|
|
||||||
"--api-key",
|
|
||||||
"test-api-key",
|
|
||||||
"--json",
|
|
||||||
],
|
|
||||||
output,
|
|
||||||
error,
|
|
||||||
_ => fakeClient);
|
|
||||||
|
|
||||||
Assert.Equal(0, exitCode);
|
|
||||||
Assert.Single(fakeClient.GalaxyTestConnectionRequests);
|
|
||||||
Assert.Contains("\"ok\": true", output.ToString());
|
|
||||||
Assert.Equal(string.Empty, error.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Verifies that galaxy-discover command prints hierarchy summary.</summary>
|
|
||||||
[Fact]
|
|
||||||
public async Task RunAsync_GalaxyDiscover_PrintsHierarchySummary()
|
|
||||||
{
|
|
||||||
using var output = new StringWriter();
|
|
||||||
using var error = new StringWriter();
|
|
||||||
FakeCliClient fakeClient = new();
|
|
||||||
fakeClient.GalaxyDiscoverHierarchyReplies.Enqueue(new DiscoverHierarchyReply
|
|
||||||
{
|
|
||||||
NextPageToken = "7:1",
|
|
||||||
TotalObjectCount = 2,
|
|
||||||
Objects =
|
|
||||||
{
|
|
||||||
new GalaxyObject
|
|
||||||
{
|
|
||||||
GobjectId = 7,
|
|
||||||
TagName = "DelmiaReceiver_001",
|
|
||||||
ContainedName = "DelmiaReceiver",
|
|
||||||
ParentGobjectId = 1,
|
|
||||||
Attributes =
|
|
||||||
{
|
|
||||||
new GalaxyAttribute
|
|
||||||
{
|
|
||||||
AttributeName = "DownloadPath",
|
|
||||||
FullTagReference = "DelmiaReceiver_001.DownloadPath",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
fakeClient.GalaxyDiscoverHierarchyReplies.Enqueue(new DiscoverHierarchyReply
|
|
||||||
{
|
|
||||||
TotalObjectCount = 2,
|
|
||||||
Objects =
|
|
||||||
{
|
|
||||||
new GalaxyObject
|
|
||||||
{
|
|
||||||
GobjectId = 8,
|
|
||||||
TagName = "DelmiaReceiver_002",
|
|
||||||
ContainedName = "DelmiaReceiver",
|
|
||||||
ParentGobjectId = 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
int exitCode = await MxGatewayClientCli.RunAsync(
|
|
||||||
[
|
|
||||||
"galaxy-discover",
|
|
||||||
"--endpoint",
|
|
||||||
"http://localhost:5000",
|
|
||||||
"--api-key",
|
|
||||||
"test-api-key",
|
|
||||||
],
|
|
||||||
output,
|
|
||||||
error,
|
|
||||||
_ => fakeClient);
|
|
||||||
|
|
||||||
Assert.Equal(0, exitCode);
|
|
||||||
Assert.Equal(2, fakeClient.GalaxyDiscoverHierarchyRequests.Count);
|
|
||||||
Assert.Equal(5000, fakeClient.GalaxyDiscoverHierarchyRequests[0].PageSize);
|
|
||||||
Assert.Equal("", fakeClient.GalaxyDiscoverHierarchyRequests[0].PageToken);
|
|
||||||
Assert.Equal("7:1", fakeClient.GalaxyDiscoverHierarchyRequests[1].PageToken);
|
|
||||||
string text = output.ToString();
|
|
||||||
Assert.Contains("objects=2", text);
|
|
||||||
Assert.Contains("DelmiaReceiver_001", text);
|
|
||||||
Assert.Contains("DelmiaReceiver_002", text);
|
|
||||||
Assert.Contains("attributes=1", text);
|
|
||||||
Assert.Equal(string.Empty, error.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Verifies that galaxy-watch command prints text output for deploy events.</summary>
|
|
||||||
[Fact]
|
|
||||||
public async Task RunAsync_GalaxyWatch_PrintsTextOutputForEvents()
|
|
||||||
{
|
|
||||||
using var output = new StringWriter();
|
|
||||||
using var error = new StringWriter();
|
|
||||||
FakeCliClient fakeClient = new();
|
|
||||||
DateTime deploy = new(2026, 4, 28, 14, 30, 0, DateTimeKind.Utc);
|
|
||||||
fakeClient.GalaxyDeployEvents.Add(new DeployEvent
|
|
||||||
{
|
|
||||||
Sequence = 1,
|
|
||||||
ObservedAt = Timestamp.FromDateTime(deploy),
|
|
||||||
TimeOfLastDeploy = Timestamp.FromDateTime(deploy),
|
|
||||||
TimeOfLastDeployPresent = true,
|
|
||||||
ObjectCount = 5,
|
|
||||||
AttributeCount = 17,
|
|
||||||
});
|
|
||||||
fakeClient.GalaxyDeployEvents.Add(new DeployEvent
|
|
||||||
{
|
|
||||||
Sequence = 2,
|
|
||||||
ObservedAt = Timestamp.FromDateTime(deploy.AddSeconds(30)),
|
|
||||||
TimeOfLastDeploy = Timestamp.FromDateTime(deploy.AddSeconds(30)),
|
|
||||||
TimeOfLastDeployPresent = true,
|
|
||||||
ObjectCount = 6,
|
|
||||||
AttributeCount = 18,
|
|
||||||
});
|
|
||||||
|
|
||||||
int exitCode = await MxGatewayClientCli.RunAsync(
|
|
||||||
[
|
|
||||||
"galaxy-watch",
|
|
||||||
"--endpoint",
|
|
||||||
"http://localhost:5000",
|
|
||||||
"--api-key",
|
|
||||||
"test-api-key",
|
|
||||||
"--last-seen-deploy-time",
|
|
||||||
"2026-04-28T14:00:00Z",
|
|
||||||
"--max-events",
|
|
||||||
"2",
|
|
||||||
],
|
|
||||||
output,
|
|
||||||
error,
|
|
||||||
_ => fakeClient);
|
|
||||||
|
|
||||||
Assert.Equal(0, exitCode);
|
|
||||||
WatchDeployEventsRequest request = Assert.Single(fakeClient.GalaxyWatchDeployEventsRequests);
|
|
||||||
Assert.NotNull(request.LastSeenDeployTime);
|
|
||||||
string text = output.ToString();
|
|
||||||
Assert.Contains("sequence=1", text);
|
|
||||||
Assert.Contains("sequence=2", text);
|
|
||||||
Assert.Contains("objects=5", text);
|
|
||||||
Assert.Contains("attributes=18", text);
|
|
||||||
Assert.Equal(string.Empty, error.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Verifies that galaxy-watch with --json emits one JSON object per event.</summary>
|
|
||||||
[Fact]
|
|
||||||
public async Task RunAsync_GalaxyWatch_JsonEmitsOneObjectPerEvent()
|
|
||||||
{
|
|
||||||
using var output = new StringWriter();
|
|
||||||
using var error = new StringWriter();
|
|
||||||
FakeCliClient fakeClient = new();
|
|
||||||
fakeClient.GalaxyDeployEvents.Add(new DeployEvent
|
|
||||||
{
|
|
||||||
Sequence = 42,
|
|
||||||
ObjectCount = 99,
|
|
||||||
AttributeCount = 1024,
|
|
||||||
});
|
|
||||||
|
|
||||||
int exitCode = await MxGatewayClientCli.RunAsync(
|
|
||||||
[
|
|
||||||
"galaxy-watch",
|
|
||||||
"--endpoint",
|
|
||||||
"http://localhost:5000",
|
|
||||||
"--api-key",
|
|
||||||
"test-api-key",
|
|
||||||
"--max-events",
|
|
||||||
"1",
|
|
||||||
"--json",
|
|
||||||
],
|
|
||||||
output,
|
|
||||||
error,
|
|
||||||
_ => fakeClient);
|
|
||||||
|
|
||||||
Assert.Equal(0, exitCode);
|
|
||||||
string text = output.ToString();
|
|
||||||
Assert.Contains("\"sequence\": \"42\"", text);
|
|
||||||
Assert.Contains("\"objectCount\": 99", text);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Fake CLI client for testing.</summary>
|
|
||||||
private sealed class FakeCliClient : IMxGatewayCliClient
|
|
||||||
{
|
|
||||||
/// <summary>Queue of invoke replies to return.</summary>
|
|
||||||
public Queue<MxCommandReply> InvokeReplies { get; } = new();
|
|
||||||
|
|
||||||
/// <summary>List of received invoke requests.</summary>
|
|
||||||
public List<MxCommandRequest> InvokeRequests { get; } = [];
|
|
||||||
|
|
||||||
/// <summary>List of received close session requests.</summary>
|
|
||||||
public List<CloseSessionRequest> CloseSessionRequests { get; } = [];
|
|
||||||
|
|
||||||
/// <summary>List of events to yield when streaming.</summary>
|
|
||||||
public List<MxEvent> Events { get; } = [];
|
|
||||||
|
|
||||||
/// <summary>Exception to throw on invoke, if any.</summary>
|
|
||||||
public Exception? InvokeFailure { get; init; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public ValueTask DisposeAsync()
|
|
||||||
{
|
|
||||||
return ValueTask.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public Task<OpenSessionReply> OpenSessionAsync(
|
|
||||||
OpenSessionRequest request,
|
|
||||||
CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
return Task.FromResult(new OpenSessionReply
|
|
||||||
{
|
|
||||||
SessionId = "session-fixture",
|
|
||||||
ProtocolStatus = new ProtocolStatus { Code = ProtocolStatusCode.Ok },
|
|
||||||
GatewayProtocolVersion = 1,
|
|
||||||
WorkerProtocolVersion = 1,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public Task<CloseSessionReply> CloseSessionAsync(
|
|
||||||
CloseSessionRequest request,
|
|
||||||
CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
CloseSessionRequests.Add(request);
|
|
||||||
return Task.FromResult(new CloseSessionReply
|
|
||||||
{
|
|
||||||
SessionId = request.SessionId,
|
|
||||||
ProtocolStatus = new ProtocolStatus { Code = ProtocolStatusCode.Ok },
|
|
||||||
FinalState = SessionState.Closed,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public Task<MxCommandReply> InvokeAsync(
|
|
||||||
MxCommandRequest request,
|
|
||||||
CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
InvokeRequests.Add(request);
|
|
||||||
if (InvokeFailure is not null)
|
|
||||||
{
|
|
||||||
throw InvokeFailure;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Task.FromResult(InvokeReplies.Dequeue());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public async IAsyncEnumerable<MxEvent> StreamEventsAsync(
|
|
||||||
StreamEventsRequest request,
|
|
||||||
[System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
foreach (MxEvent gatewayEvent in Events)
|
|
||||||
{
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
await Task.Yield();
|
|
||||||
yield return gatewayEvent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Galaxy test connection reply to return.</summary>
|
|
||||||
public TestConnectionReply GalaxyTestConnectionReply { get; set; } = new() { Ok = true };
|
|
||||||
|
|
||||||
/// <summary>Galaxy get last deploy time reply to return.</summary>
|
|
||||||
public GetLastDeployTimeReply GalaxyGetLastDeployTimeReply { get; set; } = new() { Present = false };
|
|
||||||
|
|
||||||
/// <summary>Galaxy discover hierarchy reply to return.</summary>
|
|
||||||
public DiscoverHierarchyReply GalaxyDiscoverHierarchyReply { get; set; } = new();
|
|
||||||
|
|
||||||
public Queue<DiscoverHierarchyReply> GalaxyDiscoverHierarchyReplies { get; } = new();
|
|
||||||
|
|
||||||
/// <summary>List of received galaxy test connection requests.</summary>
|
|
||||||
public List<TestConnectionRequest> GalaxyTestConnectionRequests { get; } = [];
|
|
||||||
|
|
||||||
/// <summary>List of received galaxy get last deploy time requests.</summary>
|
|
||||||
public List<GetLastDeployTimeRequest> GalaxyGetLastDeployTimeRequests { get; } = [];
|
|
||||||
|
|
||||||
/// <summary>List of received galaxy discover hierarchy requests.</summary>
|
|
||||||
public List<DiscoverHierarchyRequest> GalaxyDiscoverHierarchyRequests { get; } = [];
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public Task<TestConnectionReply> GalaxyTestConnectionAsync(
|
|
||||||
TestConnectionRequest request,
|
|
||||||
CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
GalaxyTestConnectionRequests.Add(request);
|
|
||||||
return Task.FromResult(GalaxyTestConnectionReply);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public Task<GetLastDeployTimeReply> GalaxyGetLastDeployTimeAsync(
|
|
||||||
GetLastDeployTimeRequest request,
|
|
||||||
CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
GalaxyGetLastDeployTimeRequests.Add(request);
|
|
||||||
return Task.FromResult(GalaxyGetLastDeployTimeReply);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public Task<DiscoverHierarchyReply> GalaxyDiscoverHierarchyAsync(
|
|
||||||
DiscoverHierarchyRequest request,
|
|
||||||
CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
GalaxyDiscoverHierarchyRequests.Add(request);
|
|
||||||
return Task.FromResult(
|
|
||||||
GalaxyDiscoverHierarchyReplies.TryDequeue(out DiscoverHierarchyReply? reply)
|
|
||||||
? reply
|
|
||||||
: GalaxyDiscoverHierarchyReply);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>List of received galaxy watch deploy events requests.</summary>
|
|
||||||
public List<WatchDeployEventsRequest> GalaxyWatchDeployEventsRequests { get; } = [];
|
|
||||||
|
|
||||||
/// <summary>List of deploy events to yield when watching.</summary>
|
|
||||||
public List<DeployEvent> GalaxyDeployEvents { get; } = [];
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public async IAsyncEnumerable<DeployEvent> GalaxyWatchDeployEventsAsync(
|
|
||||||
WatchDeployEventsRequest request,
|
|
||||||
[System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
GalaxyWatchDeployEventsRequests.Add(request);
|
|
||||||
foreach (DeployEvent deployEvent in GalaxyDeployEvents)
|
|
||||||
{
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
await Task.Yield();
|
|
||||||
yield return deployEvent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
|
||||||
# Visual Studio Version 17
|
|
||||||
VisualStudioVersion = 17.0.31903.59
|
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MxGateway.Client", "MxGateway.Client\MxGateway.Client.csproj", "{7CF9ED88-1F32-4040-BEB1-D0902E304C70}"
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MxGateway.Contracts", "..\..\src\MxGateway.Contracts\MxGateway.Contracts.csproj", "{9AB807A8-0469-40F7-A000-D240F36B6E5D}"
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MxGateway.Client.Cli", "MxGateway.Client.Cli\MxGateway.Client.Cli.csproj", "{EB061E77-2475-4322-9257-3F2456DD141C}"
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MxGateway.Client.Tests", "MxGateway.Client.Tests\MxGateway.Client.Tests.csproj", "{B77B5A8E-0C53-4419-9BCD-227C9753A074}"
|
|
||||||
EndProject
|
|
||||||
Global
|
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
||||||
Debug|Any CPU = Debug|Any CPU
|
|
||||||
Debug|x64 = Debug|x64
|
|
||||||
Debug|x86 = Debug|x86
|
|
||||||
Release|Any CPU = Release|Any CPU
|
|
||||||
Release|x64 = Release|x64
|
|
||||||
Release|x86 = Release|x86
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
||||||
{7CF9ED88-1F32-4040-BEB1-D0902E304C70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{7CF9ED88-1F32-4040-BEB1-D0902E304C70}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{7CF9ED88-1F32-4040-BEB1-D0902E304C70}.Debug|x64.ActiveCfg = Debug|Any CPU
|
|
||||||
{7CF9ED88-1F32-4040-BEB1-D0902E304C70}.Debug|x64.Build.0 = Debug|Any CPU
|
|
||||||
{7CF9ED88-1F32-4040-BEB1-D0902E304C70}.Debug|x86.ActiveCfg = Debug|Any CPU
|
|
||||||
{7CF9ED88-1F32-4040-BEB1-D0902E304C70}.Debug|x86.Build.0 = Debug|Any CPU
|
|
||||||
{7CF9ED88-1F32-4040-BEB1-D0902E304C70}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{7CF9ED88-1F32-4040-BEB1-D0902E304C70}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{7CF9ED88-1F32-4040-BEB1-D0902E304C70}.Release|x64.ActiveCfg = Release|Any CPU
|
|
||||||
{7CF9ED88-1F32-4040-BEB1-D0902E304C70}.Release|x64.Build.0 = Release|Any CPU
|
|
||||||
{7CF9ED88-1F32-4040-BEB1-D0902E304C70}.Release|x86.ActiveCfg = Release|Any CPU
|
|
||||||
{7CF9ED88-1F32-4040-BEB1-D0902E304C70}.Release|x86.Build.0 = Release|Any CPU
|
|
||||||
{9AB807A8-0469-40F7-A000-D240F36B6E5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{9AB807A8-0469-40F7-A000-D240F36B6E5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{9AB807A8-0469-40F7-A000-D240F36B6E5D}.Debug|x64.ActiveCfg = Debug|Any CPU
|
|
||||||
{9AB807A8-0469-40F7-A000-D240F36B6E5D}.Debug|x64.Build.0 = Debug|Any CPU
|
|
||||||
{9AB807A8-0469-40F7-A000-D240F36B6E5D}.Debug|x86.ActiveCfg = Debug|Any CPU
|
|
||||||
{9AB807A8-0469-40F7-A000-D240F36B6E5D}.Debug|x86.Build.0 = Debug|Any CPU
|
|
||||||
{9AB807A8-0469-40F7-A000-D240F36B6E5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{9AB807A8-0469-40F7-A000-D240F36B6E5D}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{9AB807A8-0469-40F7-A000-D240F36B6E5D}.Release|x64.ActiveCfg = Release|Any CPU
|
|
||||||
{9AB807A8-0469-40F7-A000-D240F36B6E5D}.Release|x64.Build.0 = Release|Any CPU
|
|
||||||
{9AB807A8-0469-40F7-A000-D240F36B6E5D}.Release|x86.ActiveCfg = Release|Any CPU
|
|
||||||
{9AB807A8-0469-40F7-A000-D240F36B6E5D}.Release|x86.Build.0 = Release|Any CPU
|
|
||||||
{EB061E77-2475-4322-9257-3F2456DD141C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{EB061E77-2475-4322-9257-3F2456DD141C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{EB061E77-2475-4322-9257-3F2456DD141C}.Debug|x64.ActiveCfg = Debug|Any CPU
|
|
||||||
{EB061E77-2475-4322-9257-3F2456DD141C}.Debug|x64.Build.0 = Debug|Any CPU
|
|
||||||
{EB061E77-2475-4322-9257-3F2456DD141C}.Debug|x86.ActiveCfg = Debug|Any CPU
|
|
||||||
{EB061E77-2475-4322-9257-3F2456DD141C}.Debug|x86.Build.0 = Debug|Any CPU
|
|
||||||
{EB061E77-2475-4322-9257-3F2456DD141C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{EB061E77-2475-4322-9257-3F2456DD141C}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{EB061E77-2475-4322-9257-3F2456DD141C}.Release|x64.ActiveCfg = Release|Any CPU
|
|
||||||
{EB061E77-2475-4322-9257-3F2456DD141C}.Release|x64.Build.0 = Release|Any CPU
|
|
||||||
{EB061E77-2475-4322-9257-3F2456DD141C}.Release|x86.ActiveCfg = Release|Any CPU
|
|
||||||
{EB061E77-2475-4322-9257-3F2456DD141C}.Release|x86.Build.0 = Release|Any CPU
|
|
||||||
{B77B5A8E-0C53-4419-9BCD-227C9753A074}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{B77B5A8E-0C53-4419-9BCD-227C9753A074}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{B77B5A8E-0C53-4419-9BCD-227C9753A074}.Debug|x64.ActiveCfg = Debug|Any CPU
|
|
||||||
{B77B5A8E-0C53-4419-9BCD-227C9753A074}.Debug|x64.Build.0 = Debug|Any CPU
|
|
||||||
{B77B5A8E-0C53-4419-9BCD-227C9753A074}.Debug|x86.ActiveCfg = Debug|Any CPU
|
|
||||||
{B77B5A8E-0C53-4419-9BCD-227C9753A074}.Debug|x86.Build.0 = Debug|Any CPU
|
|
||||||
{B77B5A8E-0C53-4419-9BCD-227C9753A074}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{B77B5A8E-0C53-4419-9BCD-227C9753A074}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{B77B5A8E-0C53-4419-9BCD-227C9753A074}.Release|x64.ActiveCfg = Release|Any CPU
|
|
||||||
{B77B5A8E-0C53-4419-9BCD-227C9753A074}.Release|x64.Build.0 = Release|Any CPU
|
|
||||||
{B77B5A8E-0C53-4419-9BCD-227C9753A074}.Release|x86.ActiveCfg = Release|Any CPU
|
|
||||||
{B77B5A8E-0C53-4419-9BCD-227C9753A074}.Release|x86.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
|
||||||
HideSolutionNode = FALSE
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\..\src\MxGateway.Contracts\MxGateway.Contracts.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Grpc.Net.Client" Version="2.76.0" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.7" />
|
|
||||||
<PackageReference Include="Polly.Core" Version="8.6.6" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
using System.Runtime.CompilerServices;
|
|
||||||
|
|
||||||
[assembly: InternalsVisibleTo("MxGateway.Client.Tests")]
|
|
||||||
+205
-27
@@ -7,11 +7,11 @@ CLI, and unit tests.
|
|||||||
|
|
||||||
| Project | Purpose |
|
| Project | Purpose |
|
||||||
|---------|---------|
|
|---------|---------|
|
||||||
| `MxGateway.Client` | .NET 10 library entry point, raw gRPC calls, and session helpers. |
|
| `ZB.MOM.WW.MxGateway.Client` | .NET 10 library entry point, raw gRPC calls, and session helpers. |
|
||||||
| `MxGateway.Client.Cli` | Test CLI for smoke and diagnostic commands. |
|
| `ZB.MOM.WW.MxGateway.Client.Cli` | Test CLI for smoke and diagnostic commands. |
|
||||||
| `MxGateway.Client.Tests` | Unit tests for client options, generated contract wiring, auth metadata, session helpers, cancellation, and event streaming. |
|
| `ZB.MOM.WW.MxGateway.Client.Tests` | Unit tests for client options, generated contract wiring, auth metadata, session helpers, cancellation, and event streaming. |
|
||||||
|
|
||||||
The projects reference `src/MxGateway.Contracts/MxGateway.Contracts.csproj` so
|
The projects reference `src/ZB.MOM.WW.MxGateway.Contracts/ZB.MOM.WW.MxGateway.Contracts.csproj` so
|
||||||
the client compiles against the same generated protobuf and gRPC types as the
|
the client compiles against the same generated protobuf and gRPC types as the
|
||||||
gateway. `clients/dotnet/generated` remains reserved for generator output if a
|
gateway. `clients/dotnet/generated` remains reserved for generator output if a
|
||||||
future client build switches to client-local `Grpc.Tools` generation.
|
future client build switches to client-local `Grpc.Tools` generation.
|
||||||
@@ -19,8 +19,8 @@ future client build switches to client-local `Grpc.Tools` generation.
|
|||||||
## Build And Test
|
## Build And Test
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
dotnet build clients/dotnet/MxGateway.Client.sln
|
dotnet build clients/dotnet/ZB.MOM.WW.MxGateway.Client.slnx
|
||||||
dotnet test clients/dotnet/MxGateway.Client.sln --no-build
|
dotnet test clients/dotnet/ZB.MOM.WW.MxGateway.Client.slnx --no-build
|
||||||
```
|
```
|
||||||
|
|
||||||
## Packaging
|
## Packaging
|
||||||
@@ -29,8 +29,8 @@ Create local library and CLI artifacts from the repository root:
|
|||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
$dotnetPackageOutput = Join-Path (Get-Location) 'artifacts/clients/dotnet'
|
$dotnetPackageOutput = Join-Path (Get-Location) 'artifacts/clients/dotnet'
|
||||||
dotnet pack clients/dotnet/MxGateway.Client/MxGateway.Client.csproj -c Release -p:PackageOutputPath="$dotnetPackageOutput"
|
dotnet pack clients/dotnet/ZB.MOM.WW.MxGateway.Client/ZB.MOM.WW.MxGateway.Client.csproj -c Release -p:PackageOutputPath="$dotnetPackageOutput"
|
||||||
dotnet publish clients/dotnet/MxGateway.Client.Cli/MxGateway.Client.Cli.csproj -c Release -o artifacts/clients/dotnet/mxgw-dotnet
|
dotnet publish clients/dotnet/ZB.MOM.WW.MxGateway.Client.Cli/ZB.MOM.WW.MxGateway.Client.Cli.csproj -c Release -o artifacts/clients/dotnet/mxgw-dotnet
|
||||||
```
|
```
|
||||||
|
|
||||||
The library package references the shared contracts project at build time. The
|
The library package references the shared contracts project at build time. The
|
||||||
@@ -39,11 +39,11 @@ published CLI runs from `artifacts/clients/dotnet/mxgw-dotnet`.
|
|||||||
## Regenerating Protobuf Bindings
|
## Regenerating Protobuf Bindings
|
||||||
|
|
||||||
The .NET client uses the generated C# types from
|
The .NET client uses the generated C# types from
|
||||||
`src/MxGateway.Contracts/Generated`. Regenerate those files through the
|
`src/ZB.MOM.WW.MxGateway.Contracts/Generated`. Regenerate those files through the
|
||||||
contracts project:
|
contracts project:
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
dotnet build src/MxGateway.Contracts/MxGateway.Contracts.csproj
|
dotnet build src/ZB.MOM.WW.MxGateway.Contracts/ZB.MOM.WW.MxGateway.Contracts.csproj
|
||||||
```
|
```
|
||||||
|
|
||||||
## Client Usage
|
## Client Usage
|
||||||
@@ -84,6 +84,15 @@ messages. `MxGatewaySession.OpenSessionReply` keeps the raw session-open reply
|
|||||||
available, and command helpers have `*RawAsync` variants when callers need the
|
available, and command helpers have `*RawAsync` variants when callers need the
|
||||||
complete `MxCommandReply`.
|
complete `MxCommandReply`.
|
||||||
|
|
||||||
|
For alarms, the client exposes `QueryActiveAlarmsAsync` (one-shot snapshot of
|
||||||
|
the active alarms the gateway's central monitor currently holds),
|
||||||
|
`StreamAlarmsAsync` (server-streaming feed of alarm-state-change messages
|
||||||
|
keyed by the same monitor), and `AcknowledgeAlarmAsync` (ack by alarm
|
||||||
|
reference, optional comment, ack target). All three accept a cancellation
|
||||||
|
token and pass through the `MxGateway:Alarms` configuration on the
|
||||||
|
server — when alarms are disabled, the gateway returns an empty list / empty
|
||||||
|
stream rather than failing.
|
||||||
|
|
||||||
`MxGatewaySession.CloseAsync` is explicit and idempotent. Repeated calls return
|
`MxGatewaySession.CloseAsync` is explicit and idempotent. Repeated calls return
|
||||||
the first `CloseSessionReply` instead of sending another close request.
|
the first `CloseSessionReply` instead of sending another close request.
|
||||||
|
|
||||||
@@ -112,20 +121,94 @@ can keep the full `MxCommandReply`, HRESULT, and status array when MXAccess
|
|||||||
itself rejects a command. `MxAccessException.Reply` contains the raw generated
|
itself rejects a command. `MxAccessException.Reply` contains the raw generated
|
||||||
reply.
|
reply.
|
||||||
|
|
||||||
|
## Write Semantics And Common Pitfalls
|
||||||
|
|
||||||
|
These are MXAccess parity behaviors that surprise new callers. The gateway
|
||||||
|
forwards them unchanged — it does not paper over them.
|
||||||
|
|
||||||
|
### Attributing a write to a user without `AuthenticateUser`
|
||||||
|
|
||||||
|
MXAccess only stamps a plain `Write`/`Write2` with a Galaxy user id when the
|
||||||
|
item carries an active *supervisory* advise. If you are **not** using the
|
||||||
|
verified/secured path (`AuthenticateUser` → `WriteSecured`/`WriteSecured2`) but
|
||||||
|
still need the write attributed to a user id, you must first advise the item
|
||||||
|
supervisory and then pass that user id on the write. Without the supervisory
|
||||||
|
advise the `userId` on a plain write is ignored.
|
||||||
|
|
||||||
|
The library exposes `Advise`/`UnAdvise` as named helpers but not supervisory
|
||||||
|
advise, so send it through the generic command channel:
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
await session.InvokeAsync(new MxCommandRequest
|
||||||
|
{
|
||||||
|
SessionId = session.SessionId,
|
||||||
|
Command = new MxCommand
|
||||||
|
{
|
||||||
|
Kind = MxCommandKind.AdviseSupervisory,
|
||||||
|
AdviseSupervisory = new AdviseSupervisoryCommand
|
||||||
|
{
|
||||||
|
ServerHandle = serverHandle,
|
||||||
|
ItemHandle = itemHandle,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await session.WriteAsync(serverHandle, itemHandle, value.ToMxValue(), userId);
|
||||||
|
```
|
||||||
|
|
||||||
|
The CLI exposes the same command as `advise-supervisory`, and `write` /
|
||||||
|
`write2` take `--user-id`.
|
||||||
|
|
||||||
|
### Array writes replace the whole array
|
||||||
|
|
||||||
|
A write to an array attribute **replaces the entire array**; it is not an
|
||||||
|
element-wise patch. To change a subset of elements, send the full array with
|
||||||
|
the unchanged elements included. For example, to change 2 elements of a
|
||||||
|
20-element array, build the `MxValue` from all 20 values (the 18 unchanged plus
|
||||||
|
the 2 new ones). Sending only the 2 changed values overwrites the attribute
|
||||||
|
with a 2-element array.
|
||||||
|
|
||||||
|
When only a few indices need changing and the rest should be reset to the
|
||||||
|
element type's default, use `WriteArrayElementsAsync` instead of building the
|
||||||
|
full array manually:
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
await session.WriteArrayElementsAsync(
|
||||||
|
serverHandle, itemHandle,
|
||||||
|
elementDataType: MxDataType.Integer,
|
||||||
|
totalLength: 20,
|
||||||
|
elements: new Dictionary<uint, MxValue>
|
||||||
|
{
|
||||||
|
[2] = 42.ToMxValue(),
|
||||||
|
[7] = 99.ToMxValue(),
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
The gateway expands the sparse descriptor into a full `totalLength`-element
|
||||||
|
array before forwarding to the worker. Indices not listed in `elements` are
|
||||||
|
written as the element type's default — this is a **reset**, not a preserve;
|
||||||
|
current values at those positions are discarded. `totalLength` is required and
|
||||||
|
must match the declared length of the array attribute. Bare-name array items
|
||||||
|
(`Area001.Pump001.Speed`) are auto-normalized to the `[]` form across the whole
|
||||||
|
add family — `AddItem`, `AddItem2`, `AddItemBulk`, and `AddBufferedItem` — so the
|
||||||
|
array attribute accepts the write.
|
||||||
|
|
||||||
## CLI Usage
|
## CLI Usage
|
||||||
|
|
||||||
The test CLI supports deterministic JSON output for automation:
|
The test CLI supports deterministic JSON output for automation:
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
dotnet run --project clients/dotnet/MxGateway.Client.Cli -- version --json
|
dotnet run --project clients/dotnet/ZB.MOM.WW.MxGateway.Client.Cli -- version --json
|
||||||
dotnet run --project clients/dotnet/MxGateway.Client.Cli -- open-session --endpoint http://localhost:5000 --api-key-env MXGATEWAY_API_KEY --json
|
dotnet run --project clients/dotnet/ZB.MOM.WW.MxGateway.Client.Cli -- open-session --endpoint http://localhost:5000 --api-key-env MXGATEWAY_API_KEY --json
|
||||||
dotnet run --project clients/dotnet/MxGateway.Client.Cli -- register --session-id <id> --client-name mxgw-dotnet-cli --json
|
dotnet run --project clients/dotnet/ZB.MOM.WW.MxGateway.Client.Cli -- register --session-id <id> --client-name mxgw-dotnet-cli --json
|
||||||
dotnet run --project clients/dotnet/MxGateway.Client.Cli -- add-item --session-id <id> --server-handle 1 --item Area001.Pump001.Speed --json
|
dotnet run --project clients/dotnet/ZB.MOM.WW.MxGateway.Client.Cli -- add-item --session-id <id> --server-handle 1 --item Area001.Pump001.Speed --json
|
||||||
dotnet run --project clients/dotnet/MxGateway.Client.Cli -- advise --session-id <id> --server-handle 1 --item-handle 1 --json
|
dotnet run --project clients/dotnet/ZB.MOM.WW.MxGateway.Client.Cli -- advise --session-id <id> --server-handle 1 --item-handle 1 --json
|
||||||
dotnet run --project clients/dotnet/MxGateway.Client.Cli -- write --session-id <id> --server-handle 1 --item-handle 1 --type int32 --value 123 --json
|
dotnet run --project clients/dotnet/ZB.MOM.WW.MxGateway.Client.Cli -- write --session-id <id> --server-handle 1 --item-handle 1 --type int32 --value 123 --json
|
||||||
dotnet run --project clients/dotnet/MxGateway.Client.Cli -- write2 --session-id <id> --server-handle 1 --item-handle 1 --type int32 --value 123 --timestamp 2026-01-01T00:00:00Z --json
|
dotnet run --project clients/dotnet/ZB.MOM.WW.MxGateway.Client.Cli -- write2 --session-id <id> --server-handle 1 --item-handle 1 --type int32 --value 123 --timestamp 2026-01-01T00:00:00Z --json
|
||||||
dotnet run --project clients/dotnet/MxGateway.Client.Cli -- stream-events --session-id <id> --max-events 1 --json
|
dotnet run --project clients/dotnet/ZB.MOM.WW.MxGateway.Client.Cli -- stream-events --session-id <id> --max-events 1 --json
|
||||||
dotnet run --project clients/dotnet/MxGateway.Client.Cli -- smoke --endpoint http://localhost:5000 --api-key-env MXGATEWAY_API_KEY --item Area001.Pump001.Speed --json
|
dotnet run --project clients/dotnet/ZB.MOM.WW.MxGateway.Client.Cli -- stream-alarms --filter-prefix Area001 --max-events 1 --json
|
||||||
|
dotnet run --project clients/dotnet/ZB.MOM.WW.MxGateway.Client.Cli -- acknowledge-alarm --reference "\\Galaxy\Area001.Pump001.PumpFault" --comment "ack from cli" --operator operator1 --json
|
||||||
|
dotnet run --project clients/dotnet/ZB.MOM.WW.MxGateway.Client.Cli -- smoke --endpoint http://localhost:5000 --api-key-env MXGATEWAY_API_KEY --item Area001.Pump001.Speed --json
|
||||||
```
|
```
|
||||||
|
|
||||||
`smoke` opens a session, registers a client, adds one item, advises it,
|
`smoke` opens a session, registers a client, adds one item, advises it,
|
||||||
@@ -180,9 +263,70 @@ IReadOnlyList<GalaxyObject> pumps = await repository.DiscoverHierarchyAsync(
|
|||||||
The CLI exposes the same operations:
|
The CLI exposes the same operations:
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
dotnet run --project clients/dotnet/MxGateway.Client.Cli -- galaxy-test-connection --endpoint http://localhost:5000 --api-key-env MXGATEWAY_API_KEY --json
|
dotnet run --project clients/dotnet/ZB.MOM.WW.MxGateway.Client.Cli -- galaxy-test-connection --endpoint http://localhost:5000 --api-key-env MXGATEWAY_API_KEY --json
|
||||||
dotnet run --project clients/dotnet/MxGateway.Client.Cli -- galaxy-last-deploy --endpoint http://localhost:5000 --api-key-env MXGATEWAY_API_KEY --json
|
dotnet run --project clients/dotnet/ZB.MOM.WW.MxGateway.Client.Cli -- galaxy-last-deploy --endpoint http://localhost:5000 --api-key-env MXGATEWAY_API_KEY --json
|
||||||
dotnet run --project clients/dotnet/MxGateway.Client.Cli -- galaxy-discover --endpoint http://localhost:5000 --api-key-env MXGATEWAY_API_KEY
|
dotnet run --project clients/dotnet/ZB.MOM.WW.MxGateway.Client.Cli -- galaxy-discover --endpoint http://localhost:5000 --api-key-env MXGATEWAY_API_KEY
|
||||||
|
```
|
||||||
|
|
||||||
|
### Browsing lazily
|
||||||
|
|
||||||
|
For UI trees or OPC UA bridges, use `BrowseChildrenAsync` to walk one level at a
|
||||||
|
time instead of paging the full hierarchy. Pass an empty request for root objects;
|
||||||
|
subsequent calls supply `ParentGobjectId`, `ParentTagName`, or
|
||||||
|
`ParentContainedPath`. Each child's `ChildHasChildren[i]` tells you whether to
|
||||||
|
draw an expand triangle. Filter fields match `DiscoverHierarchy`. See
|
||||||
|
[Galaxy Repository](../../docs/GalaxyRepository.md#browsechildren) for full
|
||||||
|
request and filter semantics.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
BrowseChildrenReply roots = await repository.BrowseChildrenAsync(
|
||||||
|
new BrowseChildrenRequest());
|
||||||
|
|
||||||
|
for (int i = 0; i < roots.Children.Count; i++)
|
||||||
|
{
|
||||||
|
GalaxyObject child = roots.Children[i];
|
||||||
|
bool hasChildren = roots.ChildHasChildren[i];
|
||||||
|
Console.WriteLine($"{child.TagName} expand={hasChildren}");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### High-level walker
|
||||||
|
|
||||||
|
For UI trees, the client provides a `LazyBrowseNode` walker that handles
|
||||||
|
sibling pagination and the `child_has_children` hint for you:
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
await using GalaxyRepositoryClient repository = GalaxyRepositoryClient.Create(
|
||||||
|
new MxGatewayClientOptions { Endpoint = new Uri("http://localhost:5000"), ApiKey = apiKey });
|
||||||
|
IReadOnlyList<LazyBrowseNode> roots = await repository.BrowseAsync();
|
||||||
|
foreach (LazyBrowseNode root in roots)
|
||||||
|
{
|
||||||
|
if (root.HasChildrenHint)
|
||||||
|
{
|
||||||
|
await root.ExpandAsync();
|
||||||
|
}
|
||||||
|
foreach (LazyBrowseNode child in root.Children)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{child.Object.TagName} ({(child.HasChildrenHint ? "has children" : "leaf")})");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`ExpandAsync` is idempotent — calling it twice fires only one RPC,
|
||||||
|
and is safe under concurrent callers. To refresh after a Galaxy redeploy, call
|
||||||
|
`BrowseAsync` again from the root.
|
||||||
|
|
||||||
|
The CLI counterpart is `galaxy-browse`. Without `--parent` it walks the root
|
||||||
|
objects and eagerly expands `--depth` further levels into an indented tree; with
|
||||||
|
`--parent <gobject-id>` it fetches exactly one level of children for that object
|
||||||
|
(`--depth` is ignored there). Filter flags map onto `BrowseChildrenOptions`:
|
||||||
|
`--category-ids` and `--template-contains` are comma-separated lists,
|
||||||
|
`--tag-name-glob` / `--alarm-bearing-only` / `--historized-only` are scalar, and
|
||||||
|
`--include-attributes` overrides the server default for attribute population.
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
dotnet run --project clients/dotnet/ZB.MOM.WW.MxGateway.Client.Cli -- galaxy-browse --endpoint http://localhost:5000 --api-key-env MXGATEWAY_API_KEY --depth 1
|
||||||
|
dotnet run --project clients/dotnet/ZB.MOM.WW.MxGateway.Client.Cli -- galaxy-browse --endpoint http://localhost:5000 --api-key-env MXGATEWAY_API_KEY --parent 42 --json
|
||||||
```
|
```
|
||||||
|
|
||||||
### Watching deploy events
|
### Watching deploy events
|
||||||
@@ -217,17 +361,28 @@ await foreach (DeployEvent evt in repository.WatchDeployEventsAsync(
|
|||||||
The CLI counterpart streams events until Ctrl+C (or `--max-events`):
|
The CLI counterpart streams events until Ctrl+C (or `--max-events`):
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
dotnet run --project clients/dotnet/MxGateway.Client.Cli -- galaxy-watch --endpoint http://localhost:5000 --api-key-env MXGATEWAY_API_KEY
|
dotnet run --project clients/dotnet/ZB.MOM.WW.MxGateway.Client.Cli -- galaxy-watch --endpoint http://localhost:5000 --api-key-env MXGATEWAY_API_KEY
|
||||||
dotnet run --project clients/dotnet/MxGateway.Client.Cli -- galaxy-watch --endpoint http://localhost:5000 --api-key-env MXGATEWAY_API_KEY --last-seen-deploy-time 2026-04-28T14:30:00Z --json
|
dotnet run --project clients/dotnet/ZB.MOM.WW.MxGateway.Client.Cli -- galaxy-watch --endpoint http://localhost:5000 --api-key-env MXGATEWAY_API_KEY --last-seen-deploy-time 2026-04-28T14:30:00Z --json
|
||||||
dotnet run --project clients/dotnet/MxGateway.Client.Cli -- galaxy-watch --endpoint http://localhost:5000 --api-key-env MXGATEWAY_API_KEY --max-events 5 --json
|
dotnet run --project clients/dotnet/ZB.MOM.WW.MxGateway.Client.Cli -- galaxy-watch --endpoint http://localhost:5000 --api-key-env MXGATEWAY_API_KEY --max-events 5 --json
|
||||||
```
|
```
|
||||||
|
|
||||||
Use TLS options for a secured gateway:
|
Use TLS options for a secured gateway:
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
dotnet run --project clients/dotnet/MxGateway.Client.Cli -- smoke --endpoint https://mxgateway.example.local:5001 --tls --ca-file C:\certs\mxgateway-ca.pem --server-name mxgateway.example.local --api-key-env MXGATEWAY_API_KEY --item Area001.Pump001.Speed --json
|
dotnet run --project clients/dotnet/ZB.MOM.WW.MxGateway.Client.Cli -- smoke --endpoint https://ZB.MOM.WW.MxGateway.example.local:5001 --tls --ca-file C:\certs\mxgateway-ca.pem --server-name ZB.MOM.WW.MxGateway.example.local --api-key-env MXGATEWAY_API_KEY --item Area001.Pump001.Speed --json
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### TLS trust
|
||||||
|
|
||||||
|
The gateway can auto-generate its own self-signed certificate (it has no PKI), so
|
||||||
|
the client is **lenient by default**: a TLS connection (`UseTls` / `--tls`) with
|
||||||
|
no pinned CA accepts whatever certificate the gateway presents. To verify
|
||||||
|
instead, pin a CA with `CaCertificatePath` / `--ca-file` (this path also enforces
|
||||||
|
the certificate hostname/SAN match), or set `RequireCertificateValidation` to
|
||||||
|
force OS/system-trust verification without pinning. Use `ServerNameOverride` /
|
||||||
|
`--server-name` when the dialed host differs from the certificate SAN. See
|
||||||
|
[Gateway Configuration](../../docs/GatewayConfiguration.md#automatic-self-signed-certificate).
|
||||||
|
|
||||||
## Integration Checks
|
## Integration Checks
|
||||||
|
|
||||||
Run live checks only when a gateway and MXAccess-backed worker are available:
|
Run live checks only when a gateway and MXAccess-backed worker are available:
|
||||||
@@ -237,9 +392,32 @@ $env:MXGATEWAY_INTEGRATION = '1'
|
|||||||
$env:MXGATEWAY_ENDPOINT = 'http://localhost:5000'
|
$env:MXGATEWAY_ENDPOINT = 'http://localhost:5000'
|
||||||
$env:MXGATEWAY_API_KEY = '<gateway-api-key>'
|
$env:MXGATEWAY_API_KEY = '<gateway-api-key>'
|
||||||
$env:MXGATEWAY_TEST_ITEM = 'Area001.Pump001.Speed'
|
$env:MXGATEWAY_TEST_ITEM = 'Area001.Pump001.Speed'
|
||||||
dotnet run --project clients/dotnet/MxGateway.Client.Cli -- smoke --endpoint $env:MXGATEWAY_ENDPOINT --api-key-env MXGATEWAY_API_KEY --item $env:MXGATEWAY_TEST_ITEM --json
|
dotnet run --project clients/dotnet/ZB.MOM.WW.MxGateway.Client.Cli -- smoke --endpoint $env:MXGATEWAY_ENDPOINT --api-key-env MXGATEWAY_API_KEY --item $env:MXGATEWAY_TEST_ITEM --json
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Installing as a NuGet Package
|
||||||
|
|
||||||
|
The client publishes to the internal Gitea NuGet feed at
|
||||||
|
`https://gitea.dohertylan.com/api/packages/dohertj2/nuget/index.json`.
|
||||||
|
|
||||||
|
Add the feed once:
|
||||||
|
|
||||||
|
````bash
|
||||||
|
dotnet nuget add source https://gitea.dohertylan.com/api/packages/dohertj2/nuget/index.json \
|
||||||
|
--name dohertj2-gitea \
|
||||||
|
--username <gitea-username> \
|
||||||
|
--password <gitea-token-or-password> \
|
||||||
|
--store-password-in-clear-text
|
||||||
|
````
|
||||||
|
|
||||||
|
Then add the package to your project:
|
||||||
|
|
||||||
|
````bash
|
||||||
|
dotnet add package ZB.MOM.WW.MxGateway.Client --version 0.1.1
|
||||||
|
````
|
||||||
|
|
||||||
|
The `ZB.MOM.WW.MxGateway.Contracts` package is pulled in transitively.
|
||||||
|
|
||||||
## Related Documentation
|
## Related Documentation
|
||||||
|
|
||||||
- [Client Packaging](../../docs/ClientPackaging.md)
|
- [Client Packaging](../../docs/ClientPackaging.md)
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
|
||||||
namespace MxGateway.Client.Cli;
|
namespace ZB.MOM.WW.MxGateway.Client.Cli;
|
||||||
|
|
||||||
/// <summary>Parses command-line arguments into flags and named values.</summary>
|
/// <summary>Parses command-line arguments into flags and named values.</summary>
|
||||||
internal sealed class CliArguments
|
internal sealed class CliArguments
|
||||||
+43
-3
@@ -1,8 +1,15 @@
|
|||||||
using MxGateway.Contracts.Proto;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||||
using MxGateway.Contracts.Proto.Galaxy;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto.Galaxy;
|
||||||
|
|
||||||
namespace MxGateway.Client.Cli;
|
namespace ZB.MOM.WW.MxGateway.Client.Cli;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Transport seam used by the CLI to drive gateway and Galaxy Repository
|
||||||
|
/// RPCs, exposing only the operations the command surface needs. The
|
||||||
|
/// production binding is <see cref="MxGatewayCliClientAdapter"/> (wrapping a
|
||||||
|
/// real <c>MxGatewayClient</c>); tests substitute an in-memory fake so the
|
||||||
|
/// command routing can be exercised without a live gateway.
|
||||||
|
/// </summary>
|
||||||
public interface IMxGatewayCliClient : IAsyncDisposable
|
public interface IMxGatewayCliClient : IAsyncDisposable
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -45,6 +52,27 @@ public interface IMxGatewayCliClient : IAsyncDisposable
|
|||||||
StreamEventsRequest request,
|
StreamEventsRequest request,
|
||||||
CancellationToken cancellationToken);
|
CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Acknowledges an active MXAccess alarm condition through the gateway.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request">The acknowledge request — alarm reference, comment, operator user.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation token for the operation.</param>
|
||||||
|
/// <returns>The acknowledge reply with protocol + native MxStatus.</returns>
|
||||||
|
Task<AcknowledgeAlarmReply> AcknowledgeAlarmAsync(
|
||||||
|
AcknowledgeAlarmRequest request,
|
||||||
|
CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attaches to the gateway's central alarm feed — the current active-alarm
|
||||||
|
/// snapshot followed by live transitions.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request">The stream request, optionally scoped by alarm-reference prefix.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation token for the operation.</param>
|
||||||
|
/// <returns>An async enumerable of alarm feed messages.</returns>
|
||||||
|
IAsyncEnumerable<AlarmFeedMessage> StreamAlarmsAsync(
|
||||||
|
StreamAlarmsRequest request,
|
||||||
|
CancellationToken cancellationToken);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tests connection to the Galaxy Repository.
|
/// Tests connection to the Galaxy Repository.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -84,4 +112,16 @@ public interface IMxGatewayCliClient : IAsyncDisposable
|
|||||||
IAsyncEnumerable<DeployEvent> GalaxyWatchDeployEventsAsync(
|
IAsyncEnumerable<DeployEvent> GalaxyWatchDeployEventsAsync(
|
||||||
WatchDeployEventsRequest request,
|
WatchDeployEventsRequest request,
|
||||||
CancellationToken cancellationToken);
|
CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fetches one page of direct children of a Galaxy parent (or the root
|
||||||
|
/// objects when the parent selector is unset), the primitive that backs the
|
||||||
|
/// lazy-browse helper.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request">The browse-children request.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation token for the operation.</param>
|
||||||
|
/// <returns>The browse-children reply.</returns>
|
||||||
|
Task<BrowseChildrenReply> GalaxyBrowseChildrenAsync(
|
||||||
|
BrowseChildrenRequest request,
|
||||||
|
CancellationToken cancellationToken);
|
||||||
}
|
}
|
||||||
+28
-4
@@ -1,8 +1,8 @@
|
|||||||
using MxGateway.Client;
|
using ZB.MOM.WW.MxGateway.Client;
|
||||||
using MxGateway.Contracts.Proto;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||||
using MxGateway.Contracts.Proto.Galaxy;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto.Galaxy;
|
||||||
|
|
||||||
namespace MxGateway.Client.Cli;
|
namespace ZB.MOM.WW.MxGateway.Client.Cli;
|
||||||
|
|
||||||
internal sealed class MxGatewayCliClientAdapter : IMxGatewayCliClient
|
internal sealed class MxGatewayCliClientAdapter : IMxGatewayCliClient
|
||||||
{
|
{
|
||||||
@@ -52,6 +52,22 @@ internal sealed class MxGatewayCliClientAdapter : IMxGatewayCliClient
|
|||||||
return _client.StreamEventsAsync(request, cancellationToken);
|
return _client.StreamEventsAsync(request, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Task<AcknowledgeAlarmReply> AcknowledgeAlarmAsync(
|
||||||
|
AcknowledgeAlarmRequest request,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return _client.AcknowledgeAlarmAsync(request, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IAsyncEnumerable<AlarmFeedMessage> StreamAlarmsAsync(
|
||||||
|
StreamAlarmsRequest request,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return _client.StreamAlarmsAsync(request, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Task<TestConnectionReply> GalaxyTestConnectionAsync(
|
public Task<TestConnectionReply> GalaxyTestConnectionAsync(
|
||||||
TestConnectionRequest request,
|
TestConnectionRequest request,
|
||||||
@@ -84,6 +100,14 @@ internal sealed class MxGatewayCliClientAdapter : IMxGatewayCliClient
|
|||||||
return _galaxyClient.Value.WatchDeployEventsRawAsync(request, cancellationToken);
|
return _galaxyClient.Value.WatchDeployEventsRawAsync(request, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Task<BrowseChildrenReply> GalaxyBrowseChildrenAsync(
|
||||||
|
BrowseChildrenRequest request,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return _galaxyClient.Value.BrowseChildrenRawAsync(request, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async ValueTask DisposeAsync()
|
public async ValueTask DisposeAsync()
|
||||||
{
|
{
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
namespace MxGateway.Client.Cli;
|
namespace ZB.MOM.WW.MxGateway.Client.Cli;
|
||||||
|
|
||||||
/// <summary>Utility to redact API keys from error messages for safe output.</summary>
|
/// <summary>Utility to redact API keys from error messages for safe output.</summary>
|
||||||
internal static class MxGatewayCliSecretRedactor
|
internal static class MxGatewayCliSecretRedactor
|
||||||
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
using MxGateway.Client.Cli;
|
using ZB.MOM.WW.MxGateway.Client.Cli;
|
||||||
|
|
||||||
return await MxGatewayClientCli.RunAsync(args, Console.Out, Console.Error);
|
return await MxGatewayClientCli.RunAsync(args, Console.Out, Console.Error);
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\MxGateway.Client\MxGateway.Client.csproj" />
|
<ProjectReference Include="..\ZB.MOM.WW.MxGateway.Client\ZB.MOM.WW.MxGateway.Client.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
using Grpc.Core;
|
||||||
|
using Grpc.Net.Client;
|
||||||
|
using ZB.MOM.WW.MxGateway.Contracts.Proto.Galaxy;
|
||||||
|
|
||||||
|
namespace ZB.MOM.WW.MxGateway.Client.Tests;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Live smoke tests for the BrowseChildren RPC. Skipped by default; set
|
||||||
|
/// MXGATEWAY_API_KEY and MXGATEWAY_ENDPOINT to run against a real gateway.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class BrowseChildrenSmokeTests
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Verifies that BrowseChildren returns a non-zero cache sequence and
|
||||||
|
/// a consistent children/child-has-children count from a live gateway.
|
||||||
|
/// </summary>
|
||||||
|
[Fact(Skip = "Set MXGATEWAY_API_KEY and MXGATEWAY_ENDPOINT to enable.")]
|
||||||
|
public async Task BrowseChildren_LiveGateway_ReturnsRootsWithCacheSequence()
|
||||||
|
{
|
||||||
|
string? apiKey = Environment.GetEnvironmentVariable("MXGATEWAY_API_KEY");
|
||||||
|
string endpoint = Environment.GetEnvironmentVariable("MXGATEWAY_ENDPOINT") ?? "http://localhost:5120";
|
||||||
|
|
||||||
|
Assert.False(string.IsNullOrEmpty(apiKey), "MXGATEWAY_API_KEY must be set.");
|
||||||
|
|
||||||
|
using GrpcChannel channel = GrpcChannel.ForAddress(endpoint);
|
||||||
|
GalaxyRepository.GalaxyRepositoryClient client = new(channel);
|
||||||
|
|
||||||
|
Metadata headers = new() { { "authorization", $"Bearer {apiKey}" } };
|
||||||
|
BrowseChildrenReply reply = await client.BrowseChildrenAsync(new BrowseChildrenRequest(), headers);
|
||||||
|
|
||||||
|
Assert.True(reply.CacheSequence > 0UL);
|
||||||
|
Assert.Equal(reply.Children.Count, reply.ChildHasChildren.Count);
|
||||||
|
}
|
||||||
|
}
|
||||||
+46
-2
@@ -1,7 +1,7 @@
|
|||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
using MxGateway.Contracts.Proto.Galaxy;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto.Galaxy;
|
||||||
|
|
||||||
namespace MxGateway.Client.Tests;
|
namespace ZB.MOM.WW.MxGateway.Client.Tests;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fake Galaxy Repository client transport for testing.
|
/// Fake Galaxy Repository client transport for testing.
|
||||||
@@ -48,6 +48,7 @@ internal sealed class FakeGalaxyRepositoryTransport(MxGatewayClientOptions optio
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public DiscoverHierarchyReply DiscoverHierarchyReply { get; set; } = new();
|
public DiscoverHierarchyReply DiscoverHierarchyReply { get; set; } = new();
|
||||||
|
|
||||||
|
/// <summary>Gets the queue of discover hierarchy replies; dequeued in FIFO order.</summary>
|
||||||
public Queue<DiscoverHierarchyReply> DiscoverHierarchyReplies { get; } = new();
|
public Queue<DiscoverHierarchyReply> DiscoverHierarchyReplies { get; } = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -122,6 +123,49 @@ internal sealed class FakeGalaxyRepositoryTransport(MxGatewayClientOptions optio
|
|||||||
: DiscoverHierarchyReply);
|
: DiscoverHierarchyReply);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Records BrowseChildren RPC calls made by the client.</summary>
|
||||||
|
public List<(BrowseChildrenRequest Request, CallOptions CallOptions)> BrowseChildrenCalls { get; } = [];
|
||||||
|
|
||||||
|
/// <summary>Default reply returned from BrowseChildren when the queue is empty.</summary>
|
||||||
|
public BrowseChildrenReply BrowseChildrenReply { get; set; } = new();
|
||||||
|
|
||||||
|
/// <summary>Queue of replies returned from BrowseChildren; dequeued in FIFO order.</summary>
|
||||||
|
public Queue<BrowseChildrenReply> BrowseChildrenReplies { get; } = new();
|
||||||
|
|
||||||
|
/// <summary>Queue of exceptions to throw from BrowseChildren; dequeued in FIFO order.</summary>
|
||||||
|
public Queue<Exception> BrowseChildrenExceptions { get; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Optional hook awaited inside BrowseChildren before the reply is produced. Lets a
|
||||||
|
/// test hold an RPC mid-flight to exercise concurrent reads of the in-progress node.
|
||||||
|
/// </summary>
|
||||||
|
public Func<Task>? BrowseChildrenGate { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Records the request and either throws a queued exception or returns the configured reply.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request">The BrowseChildrenRequest to process.</param>
|
||||||
|
/// <param name="callOptions">Call options specifying RPC behavior.</param>
|
||||||
|
public async Task<BrowseChildrenReply> BrowseChildrenAsync(
|
||||||
|
BrowseChildrenRequest request,
|
||||||
|
CallOptions callOptions)
|
||||||
|
{
|
||||||
|
BrowseChildrenCalls.Add((request, callOptions));
|
||||||
|
if (BrowseChildrenExceptions.TryDequeue(out Exception? exception))
|
||||||
|
{
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BrowseChildrenGate is { } gate)
|
||||||
|
{
|
||||||
|
await gate().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return BrowseChildrenReplies.TryDequeue(out BrowseChildrenReply? reply)
|
||||||
|
? reply
|
||||||
|
: BrowseChildrenReply;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the list of WatchDeployEvents RPC calls made by the client.
|
/// Gets the list of WatchDeployEvents RPC calls made by the client.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
+40
-3
@@ -1,7 +1,7 @@
|
|||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
using MxGateway.Contracts.Proto;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||||
|
|
||||||
namespace MxGateway.Client.Tests;
|
namespace ZB.MOM.WW.MxGateway.Client.Tests;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fake implementation of IMxGatewayClientTransport for testing.
|
/// Fake implementation of IMxGatewayClientTransport for testing.
|
||||||
@@ -51,6 +51,11 @@ internal sealed class FakeGatewayTransport(MxGatewayClientOptions options) : IMx
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public List<(QueryActiveAlarmsRequest Request, CallOptions CallOptions)> QueryActiveAlarmsCalls { get; } = [];
|
public List<(QueryActiveAlarmsRequest Request, CallOptions CallOptions)> QueryActiveAlarmsCalls { get; } = [];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the list of captured StreamAlarmsAsync calls.
|
||||||
|
/// </summary>
|
||||||
|
public List<(StreamAlarmsRequest Request, CallOptions CallOptions)> StreamAlarmsCalls { get; } = [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the queue of exceptions to throw from AcknowledgeAlarmAsync.
|
/// Gets the queue of exceptions to throw from AcknowledgeAlarmAsync.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -58,6 +63,7 @@ internal sealed class FakeGatewayTransport(MxGatewayClientOptions options) : IMx
|
|||||||
|
|
||||||
private readonly Queue<AcknowledgeAlarmReply> _acknowledgeReplies = new();
|
private readonly Queue<AcknowledgeAlarmReply> _acknowledgeReplies = new();
|
||||||
private readonly List<ActiveAlarmSnapshot> _activeAlarmSnapshots = [];
|
private readonly List<ActiveAlarmSnapshot> _activeAlarmSnapshots = [];
|
||||||
|
private readonly List<AlarmFeedMessage> _alarmFeedMessages = [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the reply to return from OpenSessionAsync.
|
/// Gets or sets the reply to return from OpenSessionAsync.
|
||||||
@@ -190,6 +196,8 @@ internal sealed class FakeGatewayTransport(MxGatewayClientOptions options) : IMx
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Records the acknowledge call and returns the next enqueued reply (or default).
|
/// Records the acknowledge call and returns the next enqueued reply (or default).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="request">The acknowledge alarm request.</param>
|
||||||
|
/// <param name="callOptions">Call options specifying RPC behavior.</param>
|
||||||
public Task<AcknowledgeAlarmReply> AcknowledgeAlarmAsync(
|
public Task<AcknowledgeAlarmReply> AcknowledgeAlarmAsync(
|
||||||
AcknowledgeAlarmRequest request,
|
AcknowledgeAlarmRequest request,
|
||||||
CallOptions callOptions)
|
CallOptions callOptions)
|
||||||
@@ -204,7 +212,6 @@ internal sealed class FakeGatewayTransport(MxGatewayClientOptions options) : IMx
|
|||||||
? _acknowledgeReplies.Dequeue()
|
? _acknowledgeReplies.Dequeue()
|
||||||
: new AcknowledgeAlarmReply
|
: new AcknowledgeAlarmReply
|
||||||
{
|
{
|
||||||
SessionId = request.SessionId,
|
|
||||||
CorrelationId = request.ClientCorrelationId,
|
CorrelationId = request.ClientCorrelationId,
|
||||||
ProtocolStatus = new ProtocolStatus { Code = ProtocolStatusCode.Ok },
|
ProtocolStatus = new ProtocolStatus { Code = ProtocolStatusCode.Ok },
|
||||||
Status = new MxStatusProxy { Success = 1, Category = MxStatusCategory.Ok },
|
Status = new MxStatusProxy { Success = 1, Category = MxStatusCategory.Ok },
|
||||||
@@ -214,6 +221,8 @@ internal sealed class FakeGatewayTransport(MxGatewayClientOptions options) : IMx
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Records the query call and yields each enqueued snapshot.
|
/// Records the query call and yields each enqueued snapshot.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="request">The query active alarms request.</param>
|
||||||
|
/// <param name="callOptions">Call options specifying RPC behavior.</param>
|
||||||
public async IAsyncEnumerable<ActiveAlarmSnapshot> QueryActiveAlarmsAsync(
|
public async IAsyncEnumerable<ActiveAlarmSnapshot> QueryActiveAlarmsAsync(
|
||||||
QueryActiveAlarmsRequest request,
|
QueryActiveAlarmsRequest request,
|
||||||
CallOptions callOptions)
|
CallOptions callOptions)
|
||||||
@@ -229,14 +238,42 @@ internal sealed class FakeGatewayTransport(MxGatewayClientOptions options) : IMx
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Enqueues an acknowledge reply.</summary>
|
/// <summary>Enqueues an acknowledge reply.</summary>
|
||||||
|
/// <param name="reply">The acknowledge reply to enqueue.</param>
|
||||||
public void AddAcknowledgeReply(AcknowledgeAlarmReply reply)
|
public void AddAcknowledgeReply(AcknowledgeAlarmReply reply)
|
||||||
{
|
{
|
||||||
_acknowledgeReplies.Enqueue(reply);
|
_acknowledgeReplies.Enqueue(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Enqueues a snapshot to be yielded from QueryActiveAlarmsAsync.</summary>
|
/// <summary>Enqueues a snapshot to be yielded from QueryActiveAlarmsAsync.</summary>
|
||||||
|
/// <param name="snapshot">The snapshot to enqueue.</param>
|
||||||
public void AddActiveAlarmSnapshot(ActiveAlarmSnapshot snapshot)
|
public void AddActiveAlarmSnapshot(ActiveAlarmSnapshot snapshot)
|
||||||
{
|
{
|
||||||
_activeAlarmSnapshots.Add(snapshot);
|
_activeAlarmSnapshots.Add(snapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Records the stream-alarms call and yields each enqueued feed message.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request">The stream alarms request.</param>
|
||||||
|
/// <param name="callOptions">Call options specifying RPC behavior.</param>
|
||||||
|
public async IAsyncEnumerable<AlarmFeedMessage> StreamAlarmsAsync(
|
||||||
|
StreamAlarmsRequest request,
|
||||||
|
CallOptions callOptions)
|
||||||
|
{
|
||||||
|
StreamAlarmsCalls.Add((request, callOptions));
|
||||||
|
|
||||||
|
foreach (AlarmFeedMessage message in _alarmFeedMessages)
|
||||||
|
{
|
||||||
|
callOptions.CancellationToken.ThrowIfCancellationRequested();
|
||||||
|
await Task.Yield();
|
||||||
|
yield return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Enqueues an alarm feed message to be yielded from StreamAlarmsAsync.</summary>
|
||||||
|
/// <param name="message">The alarm feed message to enqueue.</param>
|
||||||
|
public void AddAlarmFeedMessage(AlarmFeedMessage message)
|
||||||
|
{
|
||||||
|
_alarmFeedMessages.Add(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+8
-2
@@ -1,8 +1,8 @@
|
|||||||
using Google.Protobuf.WellKnownTypes;
|
using Google.Protobuf.WellKnownTypes;
|
||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
using MxGateway.Contracts.Proto.Galaxy;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto.Galaxy;
|
||||||
|
|
||||||
namespace MxGateway.Client.Tests;
|
namespace ZB.MOM.WW.MxGateway.Client.Tests;
|
||||||
|
|
||||||
public sealed class GalaxyRepositoryClientTests
|
public sealed class GalaxyRepositoryClientTests
|
||||||
{
|
{
|
||||||
@@ -181,6 +181,9 @@ public sealed class GalaxyRepositoryClientTests
|
|||||||
Assert.Contains("repeated page token", exception.Message, StringComparison.Ordinal);
|
Assert.Contains("repeated page token", exception.Message, StringComparison.Ordinal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verifies that DiscoverHierarchyAsync maps typed filter options correctly to the request.
|
||||||
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task DiscoverHierarchyAsync_WithOptions_MapsTypedFilters()
|
public async Task DiscoverHierarchyAsync_WithOptions_MapsTypedFilters()
|
||||||
{
|
{
|
||||||
@@ -212,6 +215,9 @@ public sealed class GalaxyRepositoryClientTests
|
|||||||
Assert.True(request.HistorizedOnly);
|
Assert.True(request.HistorizedOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verifies that TestConnectionAsync retries on transient gRPC failures.
|
||||||
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task TestConnectionAsync_RetriesOnTransientGrpcFailure()
|
public async Task TestConnectionAsync_RetriesOnTransientGrpcFailure()
|
||||||
{
|
{
|
||||||
@@ -0,0 +1,311 @@
|
|||||||
|
using Grpc.Core;
|
||||||
|
using ZB.MOM.WW.MxGateway.Contracts.Proto.Galaxy;
|
||||||
|
|
||||||
|
namespace ZB.MOM.WW.MxGateway.Client.Tests;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests for the <see cref="LazyBrowseNode"/> walker over the BrowseChildren RPC.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class LazyBrowseNodeTests
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Verifies that calling BrowseAsync with no parent returns the root nodes
|
||||||
|
/// from the first BrowseChildren reply and surfaces the per-child has-children hint.
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public async Task Browse_NoParent_ReturnsRoots()
|
||||||
|
{
|
||||||
|
FakeGalaxyRepositoryTransport transport = CreateTransport();
|
||||||
|
transport.BrowseChildrenReplies.Enqueue(BuildReply(
|
||||||
|
children: [BuildObject(1, "Plant", isArea: true), BuildObject(2, "Other")],
|
||||||
|
childHasChildren: [true, false],
|
||||||
|
cacheSequence: 1));
|
||||||
|
await using GalaxyRepositoryClient client = CreateClient(transport);
|
||||||
|
|
||||||
|
IReadOnlyList<LazyBrowseNode> roots = await client.BrowseAsync();
|
||||||
|
|
||||||
|
Assert.Equal(2, roots.Count);
|
||||||
|
Assert.Equal("Plant", roots[0].Object.TagName);
|
||||||
|
Assert.True(roots[0].HasChildrenHint);
|
||||||
|
Assert.False(roots[0].IsExpanded);
|
||||||
|
Assert.Equal("Other", roots[1].Object.TagName);
|
||||||
|
Assert.False(roots[1].HasChildrenHint);
|
||||||
|
Assert.False(roots[1].IsExpanded);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verifies that ExpandAsync populates Children and marks the node expanded after one RPC.
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public async Task Expand_PopulatesChildrenAndMarksExpanded()
|
||||||
|
{
|
||||||
|
FakeGalaxyRepositoryTransport transport = CreateTransport();
|
||||||
|
transport.BrowseChildrenReplies.Enqueue(BuildReply(
|
||||||
|
children: [BuildObject(1, "Plant", isArea: true)],
|
||||||
|
childHasChildren: [true],
|
||||||
|
cacheSequence: 1));
|
||||||
|
transport.BrowseChildrenReplies.Enqueue(BuildReply(
|
||||||
|
children: [BuildObject(10, "Line1")],
|
||||||
|
childHasChildren: [false],
|
||||||
|
cacheSequence: 1));
|
||||||
|
await using GalaxyRepositoryClient client = CreateClient(transport);
|
||||||
|
|
||||||
|
IReadOnlyList<LazyBrowseNode> roots = await client.BrowseAsync();
|
||||||
|
await roots[0].ExpandAsync();
|
||||||
|
|
||||||
|
Assert.True(roots[0].IsExpanded);
|
||||||
|
Assert.Single(roots[0].Children);
|
||||||
|
Assert.Equal("Line1", roots[0].Children[0].Object.TagName);
|
||||||
|
Assert.Equal(2, transport.BrowseChildrenCalls.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verifies that a second ExpandAsync call is a no-op and issues no additional RPC.
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public async Task Expand_CalledTwice_NoSecondRpc()
|
||||||
|
{
|
||||||
|
FakeGalaxyRepositoryTransport transport = CreateTransport();
|
||||||
|
transport.BrowseChildrenReplies.Enqueue(BuildReply(
|
||||||
|
children: [BuildObject(1, "Plant", isArea: true)],
|
||||||
|
childHasChildren: [true],
|
||||||
|
cacheSequence: 1));
|
||||||
|
transport.BrowseChildrenReplies.Enqueue(BuildReply(
|
||||||
|
children: [BuildObject(10, "Line1")],
|
||||||
|
childHasChildren: [false],
|
||||||
|
cacheSequence: 1));
|
||||||
|
await using GalaxyRepositoryClient client = CreateClient(transport);
|
||||||
|
|
||||||
|
IReadOnlyList<LazyBrowseNode> roots = await client.BrowseAsync();
|
||||||
|
await roots[0].ExpandAsync();
|
||||||
|
await roots[0].ExpandAsync();
|
||||||
|
|
||||||
|
Assert.Equal(2, transport.BrowseChildrenCalls.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verifies that an RPC failure (NotFound) during expand is wrapped in MxGatewayException.
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public async Task Expand_UnknownParent_ThrowsMxGatewayException()
|
||||||
|
{
|
||||||
|
FakeGalaxyRepositoryTransport transport = CreateTransport();
|
||||||
|
transport.BrowseChildrenReplies.Enqueue(BuildReply(
|
||||||
|
children: [BuildObject(1, "Plant", isArea: true)],
|
||||||
|
childHasChildren: [true],
|
||||||
|
cacheSequence: 1));
|
||||||
|
await using GalaxyRepositoryClient client = CreateClient(transport);
|
||||||
|
|
||||||
|
IReadOnlyList<LazyBrowseNode> roots = await client.BrowseAsync();
|
||||||
|
|
||||||
|
// Queue the failure for the upcoming ExpandAsync call so it consumes
|
||||||
|
// the exception on its first RPC rather than the BrowseAsync above.
|
||||||
|
transport.BrowseChildrenExceptions.Enqueue(
|
||||||
|
new MxGatewayException(
|
||||||
|
"Parent not found",
|
||||||
|
new RpcException(new Status(StatusCode.NotFound, "Parent not found"))));
|
||||||
|
|
||||||
|
await Assert.ThrowsAsync<MxGatewayException>(async () => await roots[0].ExpandAsync());
|
||||||
|
Assert.False(roots[0].IsExpanded);
|
||||||
|
Assert.Empty(roots[0].Children);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verifies that ExpandAsync drains multi-page sibling replies and forwards the page token.
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public async Task Expand_MultiPageSiblings_GathersAllPages()
|
||||||
|
{
|
||||||
|
FakeGalaxyRepositoryTransport transport = CreateTransport();
|
||||||
|
// Roots
|
||||||
|
transport.BrowseChildrenReplies.Enqueue(BuildReply(
|
||||||
|
children: [BuildObject(7, "Plant", isArea: true)],
|
||||||
|
childHasChildren: [true],
|
||||||
|
cacheSequence: 1));
|
||||||
|
// First child page (2 children) with a next token
|
||||||
|
BrowseChildrenReply childPage1 = BuildReply(
|
||||||
|
children: [BuildObject(70, "ChildA"), BuildObject(71, "ChildB")],
|
||||||
|
childHasChildren: [false, false],
|
||||||
|
cacheSequence: 1);
|
||||||
|
childPage1.NextPageToken = "7:abc:2";
|
||||||
|
transport.BrowseChildrenReplies.Enqueue(childPage1);
|
||||||
|
// Second child page (1 child) with no next token
|
||||||
|
transport.BrowseChildrenReplies.Enqueue(BuildReply(
|
||||||
|
children: [BuildObject(72, "ChildC")],
|
||||||
|
childHasChildren: [false],
|
||||||
|
cacheSequence: 1));
|
||||||
|
await using GalaxyRepositoryClient client = CreateClient(transport);
|
||||||
|
|
||||||
|
IReadOnlyList<LazyBrowseNode> roots = await client.BrowseAsync();
|
||||||
|
await roots[0].ExpandAsync();
|
||||||
|
|
||||||
|
Assert.Equal(3, roots[0].Children.Count);
|
||||||
|
Assert.Equal(3, transport.BrowseChildrenCalls.Count);
|
||||||
|
Assert.Equal("7:abc:2", transport.BrowseChildrenCalls[2].Request.PageToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verifies that ten concurrent ExpandAsync calls issue exactly one RPC, not ten.
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public async Task Expand_CalledConcurrently_OnlyFiresOneRpc()
|
||||||
|
{
|
||||||
|
FakeGalaxyRepositoryTransport transport = CreateTransport();
|
||||||
|
transport.BrowseChildrenReplies.Enqueue(BuildReply(
|
||||||
|
children: [BuildObject(1, "Plant", isArea: true)],
|
||||||
|
childHasChildren: [true],
|
||||||
|
cacheSequence: 7));
|
||||||
|
transport.BrowseChildrenReplies.Enqueue(BuildReply(
|
||||||
|
children: [BuildObject(2, "Mixer_001")],
|
||||||
|
childHasChildren: [false],
|
||||||
|
cacheSequence: 7));
|
||||||
|
|
||||||
|
await using GalaxyRepositoryClient client = CreateClient(transport);
|
||||||
|
IReadOnlyList<LazyBrowseNode> roots = await client.BrowseAsync();
|
||||||
|
|
||||||
|
// Fire ten concurrent expands of the same node.
|
||||||
|
Task[] tasks = Enumerable.Range(0, 10)
|
||||||
|
.Select(_ => roots[0].ExpandAsync())
|
||||||
|
.ToArray();
|
||||||
|
await Task.WhenAll(tasks);
|
||||||
|
|
||||||
|
Assert.True(roots[0].IsExpanded);
|
||||||
|
Assert.Single(roots[0].Children);
|
||||||
|
// 1 roots fetch + exactly 1 expand fetch = 2 total
|
||||||
|
Assert.Equal(2, transport.BrowseChildrenCalls.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verifies that reading Children/IsExpanded concurrently with an in-flight ExpandAsync
|
||||||
|
/// never throws (no torn enumeration of a mid-append list) and, once IsExpanded flips to
|
||||||
|
/// true, the published Children snapshot is fully populated. Pins the safe-publication
|
||||||
|
/// contract on the lock-free readers (Client.Dotnet-025).
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public async Task Expand_ConcurrentReadOfChildren_NeverTearsAndPublishesAtomically()
|
||||||
|
{
|
||||||
|
FakeGalaxyRepositoryTransport transport = CreateTransport();
|
||||||
|
transport.BrowseChildrenReplies.Enqueue(BuildReply(
|
||||||
|
children: [BuildObject(1, "Plant", isArea: true)],
|
||||||
|
childHasChildren: [true],
|
||||||
|
cacheSequence: 1));
|
||||||
|
|
||||||
|
// Multi-page child set so the expand loop spends meaningful time appending,
|
||||||
|
// widening the window for a concurrent reader to observe a torn list.
|
||||||
|
BrowseChildrenReply childPage1 = BuildReply(
|
||||||
|
children: [BuildObject(10, "A"), BuildObject(11, "B"), BuildObject(12, "C")],
|
||||||
|
childHasChildren: [false, false, false],
|
||||||
|
cacheSequence: 1);
|
||||||
|
childPage1.NextPageToken = "1:p:3";
|
||||||
|
transport.BrowseChildrenReplies.Enqueue(childPage1);
|
||||||
|
transport.BrowseChildrenReplies.Enqueue(BuildReply(
|
||||||
|
children: [BuildObject(13, "D"), BuildObject(14, "E")],
|
||||||
|
childHasChildren: [false, false],
|
||||||
|
cacheSequence: 1));
|
||||||
|
|
||||||
|
await using GalaxyRepositoryClient client = CreateClient(transport);
|
||||||
|
IReadOnlyList<LazyBrowseNode> roots = await client.BrowseAsync();
|
||||||
|
LazyBrowseNode node = roots[0];
|
||||||
|
|
||||||
|
// Gate the child-page RPCs so the expand stays mid-flight while the reader spins.
|
||||||
|
using SemaphoreSlim release = new(0, 1);
|
||||||
|
bool firstChildCall = true;
|
||||||
|
transport.BrowseChildrenGate = async () =>
|
||||||
|
{
|
||||||
|
if (firstChildCall)
|
||||||
|
{
|
||||||
|
firstChildCall = false;
|
||||||
|
await release.WaitAsync().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
using CancellationTokenSource readerStop = new();
|
||||||
|
Exception? readerFailure = null;
|
||||||
|
Task reader = Task.Run(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
while (!readerStop.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
bool expanded = node.IsExpanded;
|
||||||
|
|
||||||
|
// Enumerate the snapshot; a torn/mid-append list would throw here.
|
||||||
|
int count = 0;
|
||||||
|
foreach (LazyBrowseNode _ in node.Children)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the node reports expanded, the published snapshot must be complete.
|
||||||
|
if (expanded)
|
||||||
|
{
|
||||||
|
Assert.Equal(5, count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
readerFailure = ex;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Task expand = node.ExpandAsync();
|
||||||
|
// Let the reader spin against the empty pre-publication snapshot for a moment.
|
||||||
|
await Task.Delay(50);
|
||||||
|
release.Release();
|
||||||
|
await expand;
|
||||||
|
|
||||||
|
// Let the reader observe the post-publication state, then stop it.
|
||||||
|
await Task.Delay(50);
|
||||||
|
readerStop.Cancel();
|
||||||
|
await reader;
|
||||||
|
|
||||||
|
Assert.Null(readerFailure);
|
||||||
|
Assert.True(node.IsExpanded);
|
||||||
|
Assert.Equal(5, node.Children.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verifies that BrowseChildrenOptions filter fields are forwarded to the BrowseChildren request.
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public async Task Browse_WithFilter_ForwardsToRequest()
|
||||||
|
{
|
||||||
|
FakeGalaxyRepositoryTransport transport = CreateTransport();
|
||||||
|
await using GalaxyRepositoryClient client = CreateClient(transport);
|
||||||
|
|
||||||
|
await client.BrowseAsync(new BrowseChildrenOptions
|
||||||
|
{
|
||||||
|
TagNameGlob = "Mixer*",
|
||||||
|
AlarmBearingOnly = true,
|
||||||
|
});
|
||||||
|
|
||||||
|
BrowseChildrenRequest request = Assert.Single(transport.BrowseChildrenCalls).Request;
|
||||||
|
Assert.Equal("Mixer*", request.TagNameGlob);
|
||||||
|
Assert.True(request.AlarmBearingOnly);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GalaxyObject BuildObject(int id, string tag, bool isArea = false)
|
||||||
|
=> new() { GobjectId = id, TagName = tag, BrowseName = tag, IsArea = isArea };
|
||||||
|
|
||||||
|
private static BrowseChildrenReply BuildReply(
|
||||||
|
IReadOnlyList<GalaxyObject> children,
|
||||||
|
IReadOnlyList<bool> childHasChildren,
|
||||||
|
ulong cacheSequence)
|
||||||
|
{
|
||||||
|
BrowseChildrenReply reply = new() { TotalChildCount = children.Count, CacheSequence = cacheSequence };
|
||||||
|
reply.Children.AddRange(children);
|
||||||
|
reply.ChildHasChildren.AddRange(childHasChildren);
|
||||||
|
return reply;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GalaxyRepositoryClient CreateClient(FakeGalaxyRepositoryTransport transport)
|
||||||
|
=> new(transport.Options, transport);
|
||||||
|
|
||||||
|
private static FakeGalaxyRepositoryTransport CreateTransport()
|
||||||
|
=> new(new MxGatewayClientOptions
|
||||||
|
{
|
||||||
|
Endpoint = new Uri("http://localhost:5000"),
|
||||||
|
ApiKey = "test-api-key",
|
||||||
|
});
|
||||||
|
}
|
||||||
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
using Google.Protobuf;
|
using Google.Protobuf;
|
||||||
using MxGateway.Client;
|
using ZB.MOM.WW.MxGateway.Client;
|
||||||
using MxGateway.Contracts.Proto;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||||
|
|
||||||
namespace MxGateway.Client.Tests;
|
namespace ZB.MOM.WW.MxGateway.Client.Tests;
|
||||||
|
|
||||||
public sealed class MxCommandReplyExtensionsTests
|
public sealed class MxCommandReplyExtensionsTests
|
||||||
{
|
{
|
||||||
+8
-6
@@ -1,8 +1,8 @@
|
|||||||
using Google.Protobuf.WellKnownTypes;
|
using Google.Protobuf.WellKnownTypes;
|
||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
using MxGateway.Contracts.Proto;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||||
|
|
||||||
namespace MxGateway.Client.Tests;
|
namespace ZB.MOM.WW.MxGateway.Client.Tests;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// PR E.2 — pins the .NET SDK surface for the new alarm RPCs:
|
/// PR E.2 — pins the .NET SDK surface for the new alarm RPCs:
|
||||||
@@ -11,13 +11,13 @@ namespace MxGateway.Client.Tests;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class MxGatewayClientAlarmsTests
|
public sealed class MxGatewayClientAlarmsTests
|
||||||
{
|
{
|
||||||
|
/// <summary>AcknowledgeAlarmAsync records request and returns reply.</summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task AcknowledgeAlarmAsync_RecordsRequestShapeAndReturnsReply()
|
public async Task AcknowledgeAlarmAsync_RecordsRequestShapeAndReturnsReply()
|
||||||
{
|
{
|
||||||
FakeGatewayTransport transport = CreateTransport();
|
FakeGatewayTransport transport = CreateTransport();
|
||||||
transport.AddAcknowledgeReply(new AcknowledgeAlarmReply
|
transport.AddAcknowledgeReply(new AcknowledgeAlarmReply
|
||||||
{
|
{
|
||||||
SessionId = "session-fixture",
|
|
||||||
CorrelationId = "corr-1",
|
CorrelationId = "corr-1",
|
||||||
ProtocolStatus = new ProtocolStatus { Code = ProtocolStatusCode.Ok },
|
ProtocolStatus = new ProtocolStatus { Code = ProtocolStatusCode.Ok },
|
||||||
Status = new MxStatusProxy
|
Status = new MxStatusProxy
|
||||||
@@ -31,7 +31,6 @@ public sealed class MxGatewayClientAlarmsTests
|
|||||||
|
|
||||||
AcknowledgeAlarmReply reply = await client.AcknowledgeAlarmAsync(new AcknowledgeAlarmRequest
|
AcknowledgeAlarmReply reply = await client.AcknowledgeAlarmAsync(new AcknowledgeAlarmRequest
|
||||||
{
|
{
|
||||||
SessionId = "session-fixture",
|
|
||||||
ClientCorrelationId = "corr-1",
|
ClientCorrelationId = "corr-1",
|
||||||
AlarmFullReference = "Tank01.Level.HiHi",
|
AlarmFullReference = "Tank01.Level.HiHi",
|
||||||
Comment = "investigating",
|
Comment = "investigating",
|
||||||
@@ -48,6 +47,7 @@ public sealed class MxGatewayClientAlarmsTests
|
|||||||
Assert.Equal("Bearer test-api-key", call.CallOptions.Headers?.GetValue("authorization"));
|
Assert.Equal("Bearer test-api-key", call.CallOptions.Headers?.GetValue("authorization"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>AcknowledgeAlarmAsync honors cancellation.</summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task AcknowledgeAlarmAsync_HonorsCancellation()
|
public async Task AcknowledgeAlarmAsync_HonorsCancellation()
|
||||||
{
|
{
|
||||||
@@ -64,7 +64,6 @@ public sealed class MxGatewayClientAlarmsTests
|
|||||||
client.AcknowledgeAlarmAsync(
|
client.AcknowledgeAlarmAsync(
|
||||||
new AcknowledgeAlarmRequest
|
new AcknowledgeAlarmRequest
|
||||||
{
|
{
|
||||||
SessionId = "session-fixture",
|
|
||||||
AlarmFullReference = "Tank01.Level.HiHi",
|
AlarmFullReference = "Tank01.Level.HiHi",
|
||||||
Comment = string.Empty,
|
Comment = string.Empty,
|
||||||
OperatorUser = "alice",
|
OperatorUser = "alice",
|
||||||
@@ -72,6 +71,7 @@ public sealed class MxGatewayClientAlarmsTests
|
|||||||
cancellation.Token));
|
cancellation.Token));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>AcknowledgeAlarmAsync maps unauthenticated RPC exception to typed exception.</summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task AcknowledgeAlarmAsync_MapsUnauthenticated_RpcException_ToTypedException()
|
public async Task AcknowledgeAlarmAsync_MapsUnauthenticated_RpcException_ToTypedException()
|
||||||
{
|
{
|
||||||
@@ -89,7 +89,6 @@ public sealed class MxGatewayClientAlarmsTests
|
|||||||
var ex = await Assert.ThrowsAsync<RpcException>(
|
var ex = await Assert.ThrowsAsync<RpcException>(
|
||||||
() => client.AcknowledgeAlarmAsync(new AcknowledgeAlarmRequest
|
() => client.AcknowledgeAlarmAsync(new AcknowledgeAlarmRequest
|
||||||
{
|
{
|
||||||
SessionId = "session-fixture",
|
|
||||||
AlarmFullReference = "Tank01.Level.HiHi",
|
AlarmFullReference = "Tank01.Level.HiHi",
|
||||||
Comment = string.Empty,
|
Comment = string.Empty,
|
||||||
OperatorUser = "alice",
|
OperatorUser = "alice",
|
||||||
@@ -97,6 +96,7 @@ public sealed class MxGatewayClientAlarmsTests
|
|||||||
Assert.Equal(StatusCode.Unauthenticated, ex.StatusCode);
|
Assert.Equal(StatusCode.Unauthenticated, ex.StatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>QueryActiveAlarmsAsync streams enqueued snapshots.</summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task QueryActiveAlarmsAsync_StreamsEnqueuedSnapshots()
|
public async Task QueryActiveAlarmsAsync_StreamsEnqueuedSnapshots()
|
||||||
{
|
{
|
||||||
@@ -121,6 +121,7 @@ public sealed class MxGatewayClientAlarmsTests
|
|||||||
Assert.Single(transport.QueryActiveAlarmsCalls);
|
Assert.Single(transport.QueryActiveAlarmsCalls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>QueryActiveAlarmsAsync passes filter prefix.</summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task QueryActiveAlarmsAsync_PassesFilterPrefix()
|
public async Task QueryActiveAlarmsAsync_PassesFilterPrefix()
|
||||||
{
|
{
|
||||||
@@ -140,6 +141,7 @@ public sealed class MxGatewayClientAlarmsTests
|
|||||||
Assert.Equal("Tank01.", call.Request.AlarmFilterPrefix);
|
Assert.Equal("Tank01.", call.Request.AlarmFilterPrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>QueryActiveAlarmsAsync honors cancellation during enumeration.</summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task QueryActiveAlarmsAsync_HonorsCancellationDuringEnumeration()
|
public async Task QueryActiveAlarmsAsync_HonorsCancellationDuringEnumeration()
|
||||||
{
|
{
|
||||||
File diff suppressed because it is too large
Load Diff
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
using MxGateway.Contracts;
|
using ZB.MOM.WW.MxGateway.Contracts;
|
||||||
|
|
||||||
namespace MxGateway.Client.Tests;
|
namespace ZB.MOM.WW.MxGateway.Client.Tests;
|
||||||
|
|
||||||
public sealed class MxGatewayClientContractInfoTests
|
public sealed class MxGatewayClientContractInfoTests
|
||||||
{
|
{
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
namespace MxGateway.Client.Tests;
|
namespace ZB.MOM.WW.MxGateway.Client.Tests;
|
||||||
|
|
||||||
public sealed class MxGatewayClientOptionsTests
|
public sealed class MxGatewayClientOptionsTests
|
||||||
{
|
{
|
||||||
+65
-2
@@ -1,7 +1,7 @@
|
|||||||
using MxGateway.Contracts.Proto;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
|
|
||||||
namespace MxGateway.Client.Tests;
|
namespace ZB.MOM.WW.MxGateway.Client.Tests;
|
||||||
|
|
||||||
/// <summary>Tests for MxGatewaySession and client command behavior.</summary>
|
/// <summary>Tests for MxGatewaySession and client command behavior.</summary>
|
||||||
public sealed class MxGatewayClientSessionTests
|
public sealed class MxGatewayClientSessionTests
|
||||||
@@ -303,6 +303,69 @@ public sealed class MxGatewayClientSessionTests
|
|||||||
Assert.Equal(cancellation.Token, Assert.Single(transport.InvokeCalls).CallOptions.CancellationToken);
|
Assert.Equal(cancellation.Token, Assert.Single(transport.InvokeCalls).CallOptions.CancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Verifies that BuildSparseArray produces a SparseArrayValue MxValue with the correct total length and elements.</summary>
|
||||||
|
[Fact]
|
||||||
|
public void BuildSparseArray_ProducesSparseArrayValueWithCorrectTotalLengthAndElements()
|
||||||
|
{
|
||||||
|
MxValue element0 = 42.ToMxValue();
|
||||||
|
MxValue element3 = 99.ToMxValue();
|
||||||
|
Dictionary<uint, MxValue> elements = new()
|
||||||
|
{
|
||||||
|
[0u] = element0,
|
||||||
|
[3u] = element3,
|
||||||
|
};
|
||||||
|
|
||||||
|
MxValue result = MxGatewaySession.BuildSparseArray(MxDataType.Integer, totalLength: 10, elements);
|
||||||
|
|
||||||
|
Assert.Equal(MxValue.KindOneofCase.SparseArrayValue, result.KindCase);
|
||||||
|
Assert.Equal(10u, result.SparseArrayValue.TotalLength);
|
||||||
|
Assert.Equal(MxDataType.Integer, result.SparseArrayValue.ElementDataType);
|
||||||
|
Assert.Equal(2, result.SparseArrayValue.Elements.Count);
|
||||||
|
|
||||||
|
MxSparseElement el0 = Assert.Single(result.SparseArrayValue.Elements, e => e.Index == 0u);
|
||||||
|
Assert.Same(element0, el0.Value);
|
||||||
|
|
||||||
|
MxSparseElement el3 = Assert.Single(result.SparseArrayValue.Elements, e => e.Index == 3u);
|
||||||
|
Assert.Same(element3, el3.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Verifies that WriteArrayElementsAsync builds a write command whose value is a SparseArrayValue.</summary>
|
||||||
|
[Fact]
|
||||||
|
public async Task WriteArrayElementsAsync_BuildsWriteCommandWithSparseArrayValue()
|
||||||
|
{
|
||||||
|
FakeGatewayTransport transport = CreateTransport();
|
||||||
|
transport.AddInvokeReply(new MxCommandReply
|
||||||
|
{
|
||||||
|
SessionId = "session-fixture",
|
||||||
|
Kind = MxCommandKind.Write,
|
||||||
|
ProtocolStatus = new ProtocolStatus { Code = ProtocolStatusCode.Ok },
|
||||||
|
});
|
||||||
|
await using MxGatewayClient client = CreateClient(transport);
|
||||||
|
MxGatewaySession session = await client.OpenSessionAsync();
|
||||||
|
Dictionary<uint, MxValue> elements = new() { [1u] = 7.ToMxValue() };
|
||||||
|
|
||||||
|
await session.WriteArrayElementsAsync(
|
||||||
|
serverHandle: 12,
|
||||||
|
itemHandle: 34,
|
||||||
|
elementDataType: MxDataType.Integer,
|
||||||
|
totalLength: 5,
|
||||||
|
elements: elements,
|
||||||
|
userId: 56);
|
||||||
|
|
||||||
|
MxCommandRequest request = Assert.Single(transport.InvokeCalls).Request;
|
||||||
|
Assert.Equal(MxCommandKind.Write, request.Command.Kind);
|
||||||
|
Assert.Equal(12, request.Command.Write.ServerHandle);
|
||||||
|
Assert.Equal(34, request.Command.Write.ItemHandle);
|
||||||
|
Assert.Equal(56, request.Command.Write.UserId);
|
||||||
|
MxValue written = request.Command.Write.Value;
|
||||||
|
Assert.Equal(MxValue.KindOneofCase.SparseArrayValue, written.KindCase);
|
||||||
|
Assert.Equal(5u, written.SparseArrayValue.TotalLength);
|
||||||
|
Assert.Equal(MxDataType.Integer, written.SparseArrayValue.ElementDataType);
|
||||||
|
MxSparseElement el = Assert.Single(written.SparseArrayValue.Elements);
|
||||||
|
Assert.Equal(1u, el.Index);
|
||||||
|
Assert.Equal(7, el.Value.Int32Value);
|
||||||
|
}
|
||||||
|
|
||||||
private static MxGatewayClient CreateClient(FakeGatewayTransport transport)
|
private static MxGatewayClient CreateClient(FakeGatewayTransport transport)
|
||||||
{
|
{
|
||||||
return new MxGatewayClient(transport.Options, transport);
|
return new MxGatewayClient(transport.Options, transport);
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Security;
|
||||||
|
using ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
|
namespace ZB.MOM.WW.MxGateway.Client.Tests;
|
||||||
|
|
||||||
|
public sealed class MxGatewayClientTlsHandlerTests
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Verifies that when TLS is used with no pinned CA and RequireCertificateValidation is false (default),
|
||||||
|
/// the handler installs an accept-all callback so the gateway's self-signed cert is trusted.
|
||||||
|
/// The callback must return true regardless of chain errors.
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void Handler_SkipsVerification_WhenTlsAndNoCaPinned()
|
||||||
|
{
|
||||||
|
MxGatewayClientOptions options = new()
|
||||||
|
{
|
||||||
|
Endpoint = new Uri("https://localhost:5120"),
|
||||||
|
ApiKey = "k",
|
||||||
|
UseTls = true,
|
||||||
|
};
|
||||||
|
using SocketsHttpHandler handler = MxGatewayClient.CreateHttpHandlerForTests(options);
|
||||||
|
Assert.NotNull(handler.SslOptions.RemoteCertificateValidationCallback);
|
||||||
|
Assert.True(handler.SslOptions.RemoteCertificateValidationCallback!(null!, null!, null, SslPolicyErrors.RemoteCertificateChainErrors));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verifies that when RequireCertificateValidation is true, the callback is left null
|
||||||
|
/// so the OS trust store performs validation.
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void Handler_KeepsDefaultVerification_WhenRequireCertificateValidation()
|
||||||
|
{
|
||||||
|
MxGatewayClientOptions options = new()
|
||||||
|
{
|
||||||
|
Endpoint = new Uri("https://localhost:5120"),
|
||||||
|
ApiKey = "k",
|
||||||
|
UseTls = true,
|
||||||
|
RequireCertificateValidation = true,
|
||||||
|
};
|
||||||
|
using SocketsHttpHandler handler = MxGatewayClient.CreateHttpHandlerForTests(options);
|
||||||
|
Assert.Null(handler.SslOptions.RemoteCertificateValidationCallback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class GalaxyRepositoryClientTlsHandlerTests
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Verifies that when TLS is used with no pinned CA and RequireCertificateValidation is false (default),
|
||||||
|
/// the Galaxy client handler installs an accept-all callback so the gateway's self-signed cert is trusted.
|
||||||
|
/// The callback must return true regardless of chain errors.
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void Handler_SkipsVerification_WhenTlsAndNoCaPinned()
|
||||||
|
{
|
||||||
|
MxGatewayClientOptions options = new()
|
||||||
|
{
|
||||||
|
Endpoint = new Uri("https://localhost:5120"),
|
||||||
|
ApiKey = "k",
|
||||||
|
UseTls = true,
|
||||||
|
};
|
||||||
|
using SocketsHttpHandler handler = GalaxyRepositoryClient.CreateHttpHandlerForTests(options);
|
||||||
|
Assert.NotNull(handler.SslOptions.RemoteCertificateValidationCallback);
|
||||||
|
Assert.True(handler.SslOptions.RemoteCertificateValidationCallback!(null!, null!, null, SslPolicyErrors.RemoteCertificateChainErrors));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verifies that when RequireCertificateValidation is true, the Galaxy client callback is left null
|
||||||
|
/// so the OS trust store performs validation.
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void Handler_KeepsDefaultVerification_WhenRequireCertificateValidation()
|
||||||
|
{
|
||||||
|
MxGatewayClientOptions options = new()
|
||||||
|
{
|
||||||
|
Endpoint = new Uri("https://localhost:5120"),
|
||||||
|
ApiKey = "k",
|
||||||
|
UseTls = true,
|
||||||
|
RequireCertificateValidation = true,
|
||||||
|
};
|
||||||
|
using SocketsHttpHandler handler = GalaxyRepositoryClient.CreateHttpHandlerForTests(options);
|
||||||
|
Assert.Null(handler.SslOptions.RemoteCertificateValidationCallback);
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
namespace MxGateway.Client.Tests;
|
namespace ZB.MOM.WW.MxGateway.Client.Tests;
|
||||||
|
|
||||||
public sealed class MxGatewayGeneratedContractTests
|
public sealed class MxGatewayGeneratedContractTests
|
||||||
{
|
{
|
||||||
+3
-3
@@ -1,9 +1,9 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Google.Protobuf;
|
using Google.Protobuf;
|
||||||
using MxGateway.Client;
|
using ZB.MOM.WW.MxGateway.Client;
|
||||||
using MxGateway.Contracts.Proto;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||||
|
|
||||||
namespace MxGateway.Client.Tests;
|
namespace ZB.MOM.WW.MxGateway.Client.Tests;
|
||||||
|
|
||||||
public sealed class MxStatusProxyExtensionsTests
|
public sealed class MxStatusProxyExtensionsTests
|
||||||
{
|
{
|
||||||
+3
-3
@@ -1,9 +1,9 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Google.Protobuf;
|
using Google.Protobuf;
|
||||||
using MxGateway.Client;
|
using ZB.MOM.WW.MxGateway.Client;
|
||||||
using MxGateway.Contracts.Proto;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||||
|
|
||||||
namespace MxGateway.Client.Tests;
|
namespace ZB.MOM.WW.MxGateway.Client.Tests;
|
||||||
|
|
||||||
public sealed class MxValueExtensionsTests
|
public sealed class MxValueExtensionsTests
|
||||||
{
|
{
|
||||||
+2
-2
@@ -19,8 +19,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\MxGateway.Client\MxGateway.Client.csproj" />
|
<ProjectReference Include="..\ZB.MOM.WW.MxGateway.Client\ZB.MOM.WW.MxGateway.Client.csproj" />
|
||||||
<ProjectReference Include="..\MxGateway.Client.Cli\MxGateway.Client.Cli.csproj" />
|
<ProjectReference Include="..\ZB.MOM.WW.MxGateway.Client.Cli\ZB.MOM.WW.MxGateway.Client.Cli.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<Solution>
|
||||||
|
<Configurations>
|
||||||
|
<Platform Name="Any CPU" />
|
||||||
|
<Platform Name="x64" />
|
||||||
|
<Platform Name="x86" />
|
||||||
|
</Configurations>
|
||||||
|
<Project Path="../../src/ZB.MOM.WW.MxGateway.Contracts/ZB.MOM.WW.MxGateway.Contracts.csproj" />
|
||||||
|
<Project Path="ZB.MOM.WW.MxGateway.Client.Cli/ZB.MOM.WW.MxGateway.Client.Cli.csproj" />
|
||||||
|
<Project Path="ZB.MOM.WW.MxGateway.Client.Tests/ZB.MOM.WW.MxGateway.Client.Tests.csproj" />
|
||||||
|
<Project Path="ZB.MOM.WW.MxGateway.Client/ZB.MOM.WW.MxGateway.Client.csproj" />
|
||||||
|
</Solution>
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
namespace ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Filters and shape options for <see cref="GalaxyRepositoryClient.BrowseAsync(BrowseChildrenOptions, System.Threading.CancellationToken)"/>.
|
||||||
|
/// Mirror of <see cref="DiscoverHierarchyOptions"/> for the lazy-browse path.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class BrowseChildrenOptions
|
||||||
|
{
|
||||||
|
/// <summary>Restrict to children whose Galaxy category is in this set.</summary>
|
||||||
|
public IReadOnlyList<int> CategoryIds { get; init; } = [];
|
||||||
|
|
||||||
|
/// <summary>Restrict to children whose template chain contains any of these tokens.</summary>
|
||||||
|
public IReadOnlyList<string> TemplateChainContains { get; init; } = [];
|
||||||
|
|
||||||
|
/// <summary>Optional glob-style filter on <c>tag_name</c>.</summary>
|
||||||
|
public string? TagNameGlob { get; init; }
|
||||||
|
|
||||||
|
/// <summary>Whether to populate each <c>GalaxyObject.Attributes</c>. Null leaves the server default.</summary>
|
||||||
|
public bool? IncludeAttributes { get; init; }
|
||||||
|
|
||||||
|
/// <summary>Restrict to children that bear at least one alarm attribute.</summary>
|
||||||
|
public bool AlarmBearingOnly { get; init; }
|
||||||
|
|
||||||
|
/// <summary>Restrict to children that have at least one historized attribute.</summary>
|
||||||
|
public bool HistorizedOnly { get; init; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
namespace ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Filters and shape options for <see cref="GalaxyRepositoryClient.DiscoverHierarchyAsync(DiscoverHierarchyOptions, System.Threading.CancellationToken)"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Hand-written ergonomic wrapper around the generated
|
||||||
|
/// <c>DiscoverHierarchyRequest</c>: lets callers express a Galaxy-browse
|
||||||
|
/// slice with .NET-friendly nullable scalars and collection initializers,
|
||||||
|
/// without touching the protobuf message's <c>oneof root</c> directly.
|
||||||
|
/// </remarks>
|
||||||
|
public sealed class DiscoverHierarchyOptions
|
||||||
|
{
|
||||||
|
/// <summary>Restrict to the subtree rooted at this Galaxy <c>gobject_id</c>.</summary>
|
||||||
|
public int? RootGobjectId { get; init; }
|
||||||
|
|
||||||
|
/// <summary>Restrict to the subtree rooted at the object with this tag name.</summary>
|
||||||
|
public string? RootTagName { get; init; }
|
||||||
|
|
||||||
|
/// <summary>Restrict to the subtree rooted at this <c>contained_name</c> path.</summary>
|
||||||
|
public string? RootContainedPath { get; init; }
|
||||||
|
|
||||||
|
/// <summary>Maximum traversal depth, measured from the chosen root.</summary>
|
||||||
|
public int? MaxDepth { get; init; }
|
||||||
|
|
||||||
|
/// <summary>Restrict to objects whose Galaxy category is in this set.</summary>
|
||||||
|
public IReadOnlyList<int> CategoryIds { get; init; } = [];
|
||||||
|
|
||||||
|
/// <summary>Restrict to objects whose template chain contains any of these tokens.</summary>
|
||||||
|
public IReadOnlyList<string> TemplateChainContains { get; init; } = [];
|
||||||
|
|
||||||
|
/// <summary>Optional glob-style filter on <c>tag_name</c>.</summary>
|
||||||
|
public string? TagNameGlob { get; init; }
|
||||||
|
|
||||||
|
/// <summary>Whether to populate each <c>GalaxyObject.Attributes</c>. Null leaves the server default.</summary>
|
||||||
|
public bool? IncludeAttributes { get; init; }
|
||||||
|
|
||||||
|
/// <summary>Restrict to objects that bear at least one alarm attribute.</summary>
|
||||||
|
public bool AlarmBearingOnly { get; init; }
|
||||||
|
|
||||||
|
/// <summary>Restrict to objects that have at least one historized attribute.</summary>
|
||||||
|
public bool HistorizedOnly { get; init; }
|
||||||
|
}
|
||||||
+103
-3
@@ -2,14 +2,14 @@ using Google.Protobuf.WellKnownTypes;
|
|||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
using Grpc.Net.Client;
|
using Grpc.Net.Client;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using MxGateway.Contracts.Proto.Galaxy;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto.Galaxy;
|
||||||
using Polly;
|
using Polly;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.Security;
|
using System.Net.Security;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
|
||||||
namespace MxGateway.Client;
|
namespace ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides the .NET client entry point for the public Galaxy Repository gRPC API.
|
/// Provides the .NET client entry point for the public Galaxy Repository gRPC API.
|
||||||
@@ -19,6 +19,7 @@ namespace MxGateway.Client;
|
|||||||
public sealed class GalaxyRepositoryClient : IAsyncDisposable
|
public sealed class GalaxyRepositoryClient : IAsyncDisposable
|
||||||
{
|
{
|
||||||
private const int DiscoverHierarchyPageSize = 5000;
|
private const int DiscoverHierarchyPageSize = 5000;
|
||||||
|
private const int BrowseChildrenPageSize = 500;
|
||||||
|
|
||||||
private readonly GrpcChannel? _channel;
|
private readonly GrpcChannel? _channel;
|
||||||
private readonly IGalaxyRepositoryClientTransport _transport;
|
private readonly IGalaxyRepositoryClientTransport _transport;
|
||||||
@@ -182,6 +183,10 @@ public sealed class GalaxyRepositoryClient : IAsyncDisposable
|
|||||||
return await DiscoverHierarchyAsync(new DiscoverHierarchyOptions(), cancellationToken).ConfigureAwait(false);
|
return await DiscoverHierarchyAsync(new DiscoverHierarchyOptions(), cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Discovers the Galaxy object hierarchy.</summary>
|
||||||
|
/// <param name="options">Client configuration options.</param>
|
||||||
|
/// <param name="cancellationToken">Token to observe for cancellation.</param>
|
||||||
|
/// <returns>The collection of Galaxy objects in the hierarchy.</returns>
|
||||||
public async Task<IReadOnlyList<GalaxyObject>> DiscoverHierarchyAsync(
|
public async Task<IReadOnlyList<GalaxyObject>> DiscoverHierarchyAsync(
|
||||||
DiscoverHierarchyOptions options,
|
DiscoverHierarchyOptions options,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
@@ -274,6 +279,89 @@ public sealed class GalaxyRepositoryClient : IAsyncDisposable
|
|||||||
cancellationToken);
|
cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Returns root-level browse nodes (objects with no parent).</summary>
|
||||||
|
/// <param name="cancellationToken">Cancellation token.</param>
|
||||||
|
/// <returns>The list of root <see cref="LazyBrowseNode"/> instances.</returns>
|
||||||
|
public Task<IReadOnlyList<LazyBrowseNode>> BrowseAsync(CancellationToken cancellationToken = default)
|
||||||
|
=> BrowseAsync(null, cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>Returns root-level browse nodes filtered by the given options.</summary>
|
||||||
|
/// <param name="options">Browse filter options. Null applies no filter.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation token.</param>
|
||||||
|
/// <returns>The list of root <see cref="LazyBrowseNode"/> instances.</returns>
|
||||||
|
public async Task<IReadOnlyList<LazyBrowseNode>> BrowseAsync(
|
||||||
|
BrowseChildrenOptions? options,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
BrowseChildrenOptions effective = options ?? new BrowseChildrenOptions();
|
||||||
|
List<LazyBrowseNode> roots = [];
|
||||||
|
string pageToken = string.Empty;
|
||||||
|
HashSet<string> seenPageTokens = new(StringComparer.Ordinal);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
BrowseChildrenRequest request = BuildBrowseChildrenRequest(effective);
|
||||||
|
request.PageToken = pageToken;
|
||||||
|
BrowseChildrenReply reply = await BrowseChildrenRawAsync(request, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
for (int i = 0; i < reply.Children.Count; i++)
|
||||||
|
{
|
||||||
|
bool hint = i < reply.ChildHasChildren.Count && reply.ChildHasChildren[i];
|
||||||
|
roots.Add(new LazyBrowseNode(this, reply.Children[i], hint, effective));
|
||||||
|
}
|
||||||
|
|
||||||
|
pageToken = reply.NextPageToken;
|
||||||
|
if (!string.IsNullOrWhiteSpace(pageToken) && !seenPageTokens.Add(pageToken))
|
||||||
|
{
|
||||||
|
throw new MxGatewayException(
|
||||||
|
$"Galaxy BrowseChildren returned a repeated page token '{pageToken}'.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (!string.IsNullOrWhiteSpace(pageToken));
|
||||||
|
|
||||||
|
return roots;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Issues a raw BrowseChildren RPC without result wrapping.</summary>
|
||||||
|
/// <param name="request">The browse-children request.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation token.</param>
|
||||||
|
/// <returns>The raw server reply.</returns>
|
||||||
|
public Task<BrowseChildrenReply> BrowseChildrenRawAsync(
|
||||||
|
BrowseChildrenRequest request,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(request);
|
||||||
|
ThrowIfDisposed();
|
||||||
|
|
||||||
|
return ExecuteSafeUnaryAsync(
|
||||||
|
token => _transport.BrowseChildrenAsync(request, CreateCallOptions(token)),
|
||||||
|
cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static BrowseChildrenRequest BuildBrowseChildrenRequest(BrowseChildrenOptions options)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(options);
|
||||||
|
|
||||||
|
BrowseChildrenRequest request = new()
|
||||||
|
{
|
||||||
|
PageSize = BrowseChildrenPageSize,
|
||||||
|
AlarmBearingOnly = options.AlarmBearingOnly,
|
||||||
|
HistorizedOnly = options.HistorizedOnly,
|
||||||
|
};
|
||||||
|
request.CategoryIds.Add(options.CategoryIds);
|
||||||
|
request.TemplateChainContains.Add(options.TemplateChainContains);
|
||||||
|
if (!string.IsNullOrWhiteSpace(options.TagNameGlob))
|
||||||
|
{
|
||||||
|
request.TagNameGlob = options.TagNameGlob;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.IncludeAttributes.HasValue)
|
||||||
|
{
|
||||||
|
request.IncludeAttributes = options.IncludeAttributes.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Subscribes to Galaxy deploy events. The server emits a bootstrap event with the
|
/// Subscribes to Galaxy deploy events. The server emits a bootstrap event with the
|
||||||
/// current state on subscribe so callers can prime their cache, then emits one event
|
/// current state on subscribe so callers can prime their cache, then emits one event
|
||||||
@@ -402,7 +490,10 @@ public sealed class GalaxyRepositoryClient : IAsyncDisposable
|
|||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HttpMessageHandler CreateHttpHandler(MxGatewayClientOptions options)
|
private static HttpMessageHandler CreateHttpHandler(MxGatewayClientOptions options) =>
|
||||||
|
CreateHttpHandlerForTests(options);
|
||||||
|
|
||||||
|
internal static SocketsHttpHandler CreateHttpHandlerForTests(MxGatewayClientOptions options)
|
||||||
{
|
{
|
||||||
SocketsHttpHandler handler = new()
|
SocketsHttpHandler handler = new()
|
||||||
{
|
{
|
||||||
@@ -422,6 +513,11 @@ public sealed class GalaxyRepositoryClient : IAsyncDisposable
|
|||||||
X509Certificate2 trustedRoot = X509CertificateLoader.LoadCertificateFromFile(options.CaCertificatePath);
|
X509Certificate2 trustedRoot = X509CertificateLoader.LoadCertificateFromFile(options.CaCertificatePath);
|
||||||
handler.SslOptions.RemoteCertificateValidationCallback = (_, certificate, chain, errors) =>
|
handler.SslOptions.RemoteCertificateValidationCallback = (_, certificate, chain, errors) =>
|
||||||
{
|
{
|
||||||
|
if ((errors & System.Net.Security.SslPolicyErrors.RemoteCertificateNameMismatch) != 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (certificate is null)
|
if (certificate is null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -437,6 +533,10 @@ public sealed class GalaxyRepositoryClient : IAsyncDisposable
|
|||||||
return customChain.Build(certificateToValidate);
|
return customChain.Build(certificateToValidate);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
else if (!options.RequireCertificateValidation)
|
||||||
|
{
|
||||||
|
handler.SslOptions.RemoteCertificateValidationCallback = (_, _, _, _) => true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return handler;
|
return handler;
|
||||||
+19
-2
@@ -1,7 +1,7 @@
|
|||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
using MxGateway.Contracts.Proto.Galaxy;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto.Galaxy;
|
||||||
|
|
||||||
namespace MxGateway.Client;
|
namespace ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// gRPC implementation of IGalaxyRepositoryClientTransport.
|
/// gRPC implementation of IGalaxyRepositoryClientTransport.
|
||||||
@@ -74,6 +74,23 @@ internal sealed class GrpcGalaxyRepositoryClientTransport(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<BrowseChildrenReply> BrowseChildrenAsync(
|
||||||
|
BrowseChildrenRequest request,
|
||||||
|
CallOptions callOptions)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await RawClient.BrowseChildrenAsync(request, callOptions)
|
||||||
|
.ResponseAsync
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch (RpcException exception)
|
||||||
|
{
|
||||||
|
throw MapRpcException(exception, callOptions.CancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async IAsyncEnumerable<DeployEvent> WatchDeployEventsAsync(
|
public async IAsyncEnumerable<DeployEvent> WatchDeployEventsAsync(
|
||||||
WatchDeployEventsRequest request,
|
WatchDeployEventsRequest request,
|
||||||
+44
-2
@@ -1,7 +1,7 @@
|
|||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
using MxGateway.Contracts.Proto;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||||
|
|
||||||
namespace MxGateway.Client;
|
namespace ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// gRPC implementation of IMxGatewayClientTransport.
|
/// gRPC implementation of IMxGatewayClientTransport.
|
||||||
@@ -175,6 +175,48 @@ internal sealed class GrpcMxGatewayClientTransport(
|
|||||||
return QueryActiveAlarmsAsync(request, callOptions);
|
return QueryActiveAlarmsAsync(request, callOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async IAsyncEnumerable<AlarmFeedMessage> StreamAlarmsAsync(
|
||||||
|
StreamAlarmsRequest request,
|
||||||
|
CallOptions callOptions,
|
||||||
|
[System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
CancellationToken effectiveCancellationToken = cancellationToken.CanBeCanceled
|
||||||
|
? cancellationToken
|
||||||
|
: callOptions.CancellationToken;
|
||||||
|
|
||||||
|
using AsyncServerStreamingCall<AlarmFeedMessage> call = RawClient.StreamAlarms(request, callOptions);
|
||||||
|
|
||||||
|
IAsyncStreamReader<AlarmFeedMessage> responseStream = call.ResponseStream;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
AlarmFeedMessage? message;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!await responseStream.MoveNext(effectiveCancellationToken).ConfigureAwait(false))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
message = responseStream.Current;
|
||||||
|
}
|
||||||
|
catch (RpcException exception)
|
||||||
|
{
|
||||||
|
throw MapRpcException(exception, effectiveCancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
yield return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
IAsyncEnumerable<AlarmFeedMessage> IMxGatewayClientTransport.StreamAlarmsAsync(
|
||||||
|
StreamAlarmsRequest request,
|
||||||
|
CallOptions callOptions)
|
||||||
|
{
|
||||||
|
return StreamAlarmsAsync(request, callOptions);
|
||||||
|
}
|
||||||
|
|
||||||
private static Exception MapRpcException(
|
private static Exception MapRpcException(
|
||||||
RpcException exception,
|
RpcException exception,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
+9
-2
@@ -1,7 +1,7 @@
|
|||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
using MxGateway.Contracts.Proto.Galaxy;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto.Galaxy;
|
||||||
|
|
||||||
namespace MxGateway.Client;
|
namespace ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
/// <summary>Transport layer for Galaxy Repository gRPC operations.</summary>
|
/// <summary>Transport layer for Galaxy Repository gRPC operations.</summary>
|
||||||
internal interface IGalaxyRepositoryClientTransport
|
internal interface IGalaxyRepositoryClientTransport
|
||||||
@@ -33,6 +33,13 @@ internal interface IGalaxyRepositoryClientTransport
|
|||||||
DiscoverHierarchyRequest request,
|
DiscoverHierarchyRequest request,
|
||||||
CallOptions callOptions);
|
CallOptions callOptions);
|
||||||
|
|
||||||
|
/// <summary>Returns direct children of a parent in the Galaxy hierarchy.</summary>
|
||||||
|
/// <param name="request">The browse children request.</param>
|
||||||
|
/// <param name="callOptions">gRPC call options (timeout, cancellation, etc.).</param>
|
||||||
|
Task<BrowseChildrenReply> BrowseChildrenAsync(
|
||||||
|
BrowseChildrenRequest request,
|
||||||
|
CallOptions callOptions);
|
||||||
|
|
||||||
/// <summary>Watches for deployment events from the Galaxy Repository server.</summary>
|
/// <summary>Watches for deployment events from the Galaxy Repository server.</summary>
|
||||||
/// <param name="request">The watch deploy events request.</param>
|
/// <param name="request">The watch deploy events request.</param>
|
||||||
/// <param name="callOptions">gRPC call options (timeout, cancellation, etc.).</param>
|
/// <param name="callOptions">gRPC call options (timeout, cancellation, etc.).</param>
|
||||||
+13
-2
@@ -1,7 +1,7 @@
|
|||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
using MxGateway.Contracts.Proto;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||||
|
|
||||||
namespace MxGateway.Client;
|
namespace ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
internal interface IMxGatewayClientTransport
|
internal interface IMxGatewayClientTransport
|
||||||
{
|
{
|
||||||
@@ -75,4 +75,15 @@ internal interface IMxGatewayClientTransport
|
|||||||
IAsyncEnumerable<ActiveAlarmSnapshot> QueryActiveAlarmsAsync(
|
IAsyncEnumerable<ActiveAlarmSnapshot> QueryActiveAlarmsAsync(
|
||||||
QueryActiveAlarmsRequest request,
|
QueryActiveAlarmsRequest request,
|
||||||
CallOptions callOptions);
|
CallOptions callOptions);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attaches to the gateway's central alarm feed — the current active-alarm
|
||||||
|
/// snapshot followed by live transitions.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request">The stream request, optionally scoped by alarm-reference prefix.</param>
|
||||||
|
/// <param name="callOptions">gRPC call options.</param>
|
||||||
|
/// <returns>An async enumerable of alarm feed messages.</returns>
|
||||||
|
IAsyncEnumerable<AlarmFeedMessage> StreamAlarmsAsync(
|
||||||
|
StreamAlarmsRequest request,
|
||||||
|
CallOptions callOptions);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
using ZB.MOM.WW.MxGateway.Contracts.Proto.Galaxy;
|
||||||
|
|
||||||
|
namespace ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// One node in a lazy-loaded Galaxy browse tree. Holds the underlying
|
||||||
|
/// <see cref="GalaxyObject"/> and exposes <see cref="ExpandAsync"/> to fetch
|
||||||
|
/// its direct children on demand. Expansion is one-shot: a second call is a
|
||||||
|
/// no-op. Pagination of large sibling sets is handled internally.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class LazyBrowseNode
|
||||||
|
{
|
||||||
|
private readonly GalaxyRepositoryClient _client;
|
||||||
|
private readonly BrowseChildrenOptions _options;
|
||||||
|
// Client.Dotnet-027 (Won't Fix): this gate is used only via WaitAsync/Release and
|
||||||
|
// never via AvailableWaitHandle, so SemaphoreSlim allocates no kernel wait handle —
|
||||||
|
// it holds no unmanaged/OS handle to leak. It is pure managed memory whose lifetime
|
||||||
|
// is the node's, so the type is intentionally not IDisposable: making it disposable
|
||||||
|
// would push per-node disposal onto every tree consumer (thousands of nodes) for no
|
||||||
|
// resource benefit.
|
||||||
|
private readonly SemaphoreSlim _expandLock = new(1, 1);
|
||||||
|
|
||||||
|
// Published once, under _expandLock, when expansion completes. Lock-free readers
|
||||||
|
// see either the empty pre-expansion snapshot or the fully-populated post-expansion
|
||||||
|
// snapshot — never a partially-filled list — because the snapshot is built in a local
|
||||||
|
// and handed off via Volatile.Write (release) paired with Volatile.Read (acquire).
|
||||||
|
private IReadOnlyList<LazyBrowseNode> _children = [];
|
||||||
|
private volatile bool _isExpanded;
|
||||||
|
|
||||||
|
internal LazyBrowseNode(
|
||||||
|
GalaxyRepositoryClient client,
|
||||||
|
GalaxyObject @object,
|
||||||
|
bool hasChildrenHint,
|
||||||
|
BrowseChildrenOptions options)
|
||||||
|
{
|
||||||
|
_client = client;
|
||||||
|
Object = @object;
|
||||||
|
HasChildrenHint = hasChildrenHint;
|
||||||
|
_options = options;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>The underlying Galaxy object for this node.</summary>
|
||||||
|
public GalaxyObject Object { get; }
|
||||||
|
|
||||||
|
/// <summary>True when the server reports this node has at least one matching descendant.</summary>
|
||||||
|
public bool HasChildrenHint { get; }
|
||||||
|
|
||||||
|
/// <summary>Direct children loaded by <see cref="ExpandAsync"/>; empty until then.</summary>
|
||||||
|
public IReadOnlyList<LazyBrowseNode> Children => Volatile.Read(ref _children);
|
||||||
|
|
||||||
|
/// <summary>True after the first <see cref="ExpandAsync"/> call completes.</summary>
|
||||||
|
public bool IsExpanded => _isExpanded;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fetches direct children from the gateway and populates <see cref="Children"/>.
|
||||||
|
/// Idempotent: subsequent calls are no-ops.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Thread-safe: concurrent callers see exactly one fetch; subsequent callers
|
||||||
|
/// (after the first completes) return immediately. <see cref="Children"/> and
|
||||||
|
/// <see cref="IsExpanded"/> may be read concurrently with an in-flight
|
||||||
|
/// <see cref="ExpandAsync"/> on another thread; the populated children are
|
||||||
|
/// published as an immutable snapshot under a release barrier, so a reader that
|
||||||
|
/// observes <see cref="IsExpanded"/> as <see langword="true"/> always sees the
|
||||||
|
/// fully-populated <see cref="Children"/>, and a reader never enumerates a
|
||||||
|
/// partially-built list.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="cancellationToken">Token to observe for cancellation.</param>
|
||||||
|
public async Task ExpandAsync(CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
if (_isExpanded)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await _expandLock.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_isExpanded)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Accumulate into a local list, never the published field, so a lock-free
|
||||||
|
// reader can never observe a half-populated collection or enumerate a list
|
||||||
|
// that is being mutated mid-append.
|
||||||
|
List<LazyBrowseNode> children = [];
|
||||||
|
string pageToken = string.Empty;
|
||||||
|
HashSet<string> seenPageTokens = new(StringComparer.Ordinal);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
BrowseChildrenRequest request = GalaxyRepositoryClient.BuildBrowseChildrenRequest(_options);
|
||||||
|
request.ParentGobjectId = Object.GobjectId;
|
||||||
|
request.PageToken = pageToken;
|
||||||
|
|
||||||
|
BrowseChildrenReply reply = await _client
|
||||||
|
.BrowseChildrenRawAsync(request, cancellationToken)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
|
for (int i = 0; i < reply.Children.Count; i++)
|
||||||
|
{
|
||||||
|
bool hint = i < reply.ChildHasChildren.Count && reply.ChildHasChildren[i];
|
||||||
|
children.Add(new LazyBrowseNode(_client, reply.Children[i], hint, _options));
|
||||||
|
}
|
||||||
|
|
||||||
|
pageToken = reply.NextPageToken;
|
||||||
|
if (!string.IsNullOrWhiteSpace(pageToken) && !seenPageTokens.Add(pageToken))
|
||||||
|
{
|
||||||
|
throw new MxGatewayException(
|
||||||
|
$"Galaxy BrowseChildren returned a repeated page token '{pageToken}'.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (!string.IsNullOrWhiteSpace(pageToken));
|
||||||
|
|
||||||
|
// Publish the completed, immutable snapshot (release) before marking the node
|
||||||
|
// expanded (the volatile write below). A reader that observes IsExpanded == true
|
||||||
|
// is guaranteed to also observe the fully-populated Children.
|
||||||
|
Volatile.Write(ref _children, children);
|
||||||
|
_isExpanded = true;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_expandLock.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
using MxGateway.Contracts.Proto;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||||
|
|
||||||
namespace MxGateway.Client;
|
namespace ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
/// <summary>Exception thrown when an MXAccess command fails with a non-zero HResult or failing status.</summary>
|
/// <summary>Exception thrown when an MXAccess command fails with a non-zero HResult or failing status.</summary>
|
||||||
public sealed class MxAccessException : MxGatewayCommandException
|
public sealed class MxAccessException : MxGatewayCommandException
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
using MxGateway.Contracts.Proto;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||||
|
|
||||||
namespace MxGateway.Client;
|
namespace ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
/// <summary>Extension methods for checking MxCommandReply success conditions.</summary>
|
/// <summary>Extension methods for checking MxCommandReply success conditions.</summary>
|
||||||
public static class MxCommandReplyExtensions
|
public static class MxCommandReplyExtensions
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
using MxGateway.Contracts.Proto;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||||
|
|
||||||
namespace MxGateway.Client;
|
namespace ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
/// <summary>Exception thrown when an API key is invalid, expired, or malformed.</summary>
|
/// <summary>Exception thrown when an API key is invalid, expired, or malformed.</summary>
|
||||||
public sealed class MxGatewayAuthenticationException : MxGatewayException
|
public sealed class MxGatewayAuthenticationException : MxGatewayException
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
using MxGateway.Contracts.Proto;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||||
|
|
||||||
namespace MxGateway.Client;
|
namespace ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
/// <summary>Exception thrown when the API key lacks required scopes for an operation.</summary>
|
/// <summary>Exception thrown when the API key lacks required scopes for an operation.</summary>
|
||||||
public sealed class MxGatewayAuthorizationException : MxGatewayException
|
public sealed class MxGatewayAuthorizationException : MxGatewayException
|
||||||
+37
-3
@@ -1,13 +1,13 @@
|
|||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
using Grpc.Net.Client;
|
using Grpc.Net.Client;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using MxGateway.Contracts.Proto;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||||
using Polly;
|
using Polly;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.Security;
|
using System.Net.Security;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
|
||||||
namespace MxGateway.Client;
|
namespace ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides the .NET client entry point for the public MXAccess Gateway gRPC API.
|
/// Provides the .NET client entry point for the public MXAccess Gateway gRPC API.
|
||||||
@@ -224,6 +224,28 @@ public sealed class MxGatewayClient : IAsyncDisposable
|
|||||||
return _transport.QueryActiveAlarmsAsync(request, CreateStreamCallOptions(cancellationToken));
|
return _transport.QueryActiveAlarmsAsync(request, CreateStreamCallOptions(cancellationToken));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attaches to the gateway's central alarm feed. The stream opens with one
|
||||||
|
/// <see cref="AlarmFeedMessage"/> per currently-active alarm (the
|
||||||
|
/// ConditionRefresh snapshot), then a single <c>snapshot_complete</c>, then a
|
||||||
|
/// <c>transition</c> for every subsequent raise / acknowledge / clear. Served
|
||||||
|
/// by the gateway's always-on alarm monitor — no worker session is opened, so
|
||||||
|
/// any number of clients may attach. Optionally scoped by alarm-reference
|
||||||
|
/// prefix (<see cref="StreamAlarmsRequest.AlarmFilterPrefix"/>).
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request">The stream request, optionally scoped by alarm-reference prefix.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation token for the stream.</param>
|
||||||
|
/// <returns>An async enumerable of alarm feed messages.</returns>
|
||||||
|
public IAsyncEnumerable<AlarmFeedMessage> StreamAlarmsAsync(
|
||||||
|
StreamAlarmsRequest request,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(request);
|
||||||
|
ThrowIfDisposed();
|
||||||
|
|
||||||
|
return _transport.StreamAlarmsAsync(request, CreateStreamCallOptions(cancellationToken));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Disposes the client and releases all resources.
|
/// Disposes the client and releases all resources.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -293,7 +315,10 @@ public sealed class MxGatewayClient : IAsyncDisposable
|
|||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HttpMessageHandler CreateHttpHandler(MxGatewayClientOptions options)
|
private static HttpMessageHandler CreateHttpHandler(MxGatewayClientOptions options) =>
|
||||||
|
CreateHttpHandlerForTests(options);
|
||||||
|
|
||||||
|
internal static SocketsHttpHandler CreateHttpHandlerForTests(MxGatewayClientOptions options)
|
||||||
{
|
{
|
||||||
SocketsHttpHandler handler = new()
|
SocketsHttpHandler handler = new()
|
||||||
{
|
{
|
||||||
@@ -313,6 +338,11 @@ public sealed class MxGatewayClient : IAsyncDisposable
|
|||||||
X509Certificate2 trustedRoot = X509CertificateLoader.LoadCertificateFromFile(options.CaCertificatePath);
|
X509Certificate2 trustedRoot = X509CertificateLoader.LoadCertificateFromFile(options.CaCertificatePath);
|
||||||
handler.SslOptions.RemoteCertificateValidationCallback = (_, certificate, chain, errors) =>
|
handler.SslOptions.RemoteCertificateValidationCallback = (_, certificate, chain, errors) =>
|
||||||
{
|
{
|
||||||
|
if ((errors & System.Net.Security.SslPolicyErrors.RemoteCertificateNameMismatch) != 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (certificate is null)
|
if (certificate is null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -328,6 +358,10 @@ public sealed class MxGatewayClient : IAsyncDisposable
|
|||||||
return customChain.Build(certificateToValidate);
|
return customChain.Build(certificateToValidate);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
else if (!options.RequireCertificateValidation)
|
||||||
|
{
|
||||||
|
handler.SslOptions.RemoteCertificateValidationCallback = (_, _, _, _) => true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return handler;
|
return handler;
|
||||||
+4
-2
@@ -1,15 +1,17 @@
|
|||||||
using MxGateway.Contracts;
|
using ZB.MOM.WW.MxGateway.Contracts;
|
||||||
|
|
||||||
namespace MxGateway.Client;
|
namespace ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Exposes the protocol versions compiled into this client package.
|
/// Exposes the protocol versions compiled into this client package.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class MxGatewayClientContractInfo
|
public static class MxGatewayClientContractInfo
|
||||||
{
|
{
|
||||||
|
/// <inheritdoc cref="GatewayContractInfo.GatewayProtocolVersion"/>
|
||||||
public const uint GatewayProtocolVersion =
|
public const uint GatewayProtocolVersion =
|
||||||
GatewayContractInfo.GatewayProtocolVersion;
|
GatewayContractInfo.GatewayProtocolVersion;
|
||||||
|
|
||||||
|
/// <inheritdoc cref="GatewayContractInfo.WorkerProtocolVersion"/>
|
||||||
public const uint WorkerProtocolVersion =
|
public const uint WorkerProtocolVersion =
|
||||||
GatewayContractInfo.WorkerProtocolVersion;
|
GatewayContractInfo.WorkerProtocolVersion;
|
||||||
}
|
}
|
||||||
+12
-1
@@ -1,6 +1,6 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace MxGateway.Client;
|
namespace ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Configures the gRPC channel used by the .NET MXAccess Gateway client.
|
/// Configures the gRPC channel used by the .NET MXAccess Gateway client.
|
||||||
@@ -27,6 +27,14 @@ public sealed class MxGatewayClientOptions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string? CaCertificatePath { get; init; }
|
public string? CaCertificatePath { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// When true, TLS connections without a pinned <see cref="CaCertificatePath"/>
|
||||||
|
/// use the OS trust store. When false (default), the gateway certificate is
|
||||||
|
/// accepted without verification — appropriate for this internal tool's
|
||||||
|
/// auto-generated self-signed certificate. Pinning a CA always verifies.
|
||||||
|
/// </summary>
|
||||||
|
public bool RequireCertificateValidation { get; init; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the server name override for SNI during TLS handshake.
|
/// Gets the server name override for SNI during TLS handshake.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -47,6 +55,9 @@ public sealed class MxGatewayClientOptions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public TimeSpan? StreamTimeout { get; init; }
|
public TimeSpan? StreamTimeout { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the maximum size in bytes for gRPC messages.
|
||||||
|
/// </summary>
|
||||||
public int MaxGrpcMessageBytes { get; init; } = 16 * 1024 * 1024;
|
public int MaxGrpcMessageBytes { get; init; } = 16 * 1024 * 1024;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
namespace MxGateway.Client;
|
namespace ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
/// <summary>Configuration for automatic retry behavior on transient gRPC call failures.</summary>
|
/// <summary>Configuration for automatic retry behavior on transient gRPC call failures.</summary>
|
||||||
public sealed class MxGatewayClientRetryOptions
|
public sealed class MxGatewayClientRetryOptions
|
||||||
+2
-2
@@ -1,10 +1,10 @@
|
|||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using MxGateway.Contracts.Proto;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||||
using Polly;
|
using Polly;
|
||||||
using Polly.Retry;
|
using Polly.Retry;
|
||||||
|
|
||||||
namespace MxGateway.Client;
|
namespace ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
/// <summary>Factory and helpers for exponential-backoff retry policies on transient gRPC failures.</summary>
|
/// <summary>Factory and helpers for exponential-backoff retry policies on transient gRPC failures.</summary>
|
||||||
internal static class MxGatewayClientRetryPolicy
|
internal static class MxGatewayClientRetryPolicy
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
using MxGateway.Contracts.Proto;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||||
|
|
||||||
namespace MxGateway.Client;
|
namespace ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
/// <summary>Exception thrown when a gateway command fails due to an unclassified protocol error.</summary>
|
/// <summary>Exception thrown when a gateway command fails due to an unclassified protocol error.</summary>
|
||||||
public class MxGatewayCommandException : MxGatewayException
|
public class MxGatewayCommandException : MxGatewayException
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
using MxGateway.Contracts.Proto;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||||
|
|
||||||
namespace MxGateway.Client;
|
namespace ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Exception thrown when a gateway RPC call fails or returns an error status.
|
/// Exception thrown when a gateway RPC call fails or returns an error status.
|
||||||
+224
-2
@@ -1,6 +1,6 @@
|
|||||||
using MxGateway.Contracts.Proto;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||||
|
|
||||||
namespace MxGateway.Client;
|
namespace ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents one gateway-backed MXAccess session.
|
/// Represents one gateway-backed MXAccess session.
|
||||||
@@ -502,6 +502,171 @@ public sealed class MxGatewaySession : IAsyncDisposable
|
|||||||
return reply.UnsubscribeBulk?.Results.ToArray() ?? [];
|
return reply.UnsubscribeBulk?.Results.ToArray() ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Bulk Write — sequential MXAccess Write per entry on the worker's STA.
|
||||||
|
/// Per-item failures appear as <see cref="BulkWriteResult"/> entries with
|
||||||
|
/// <c>WasSuccessful = false</c>; the call never throws on per-item errors.
|
||||||
|
/// Protocol-level failures still throw via EnsureProtocolSuccess.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serverHandle">The ServerHandle from register.</param>
|
||||||
|
/// <param name="entries">Per-item write entries; each carries the item handle, value, and user id.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation token.</param>
|
||||||
|
/// <returns>One <see cref="BulkWriteResult"/> per requested entry, in request order.</returns>
|
||||||
|
public async Task<IReadOnlyList<BulkWriteResult>> WriteBulkAsync(
|
||||||
|
int serverHandle,
|
||||||
|
IReadOnlyList<WriteBulkEntry> entries,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(entries);
|
||||||
|
|
||||||
|
WriteBulkCommand command = new() { ServerHandle = serverHandle };
|
||||||
|
command.Entries.Add(entries);
|
||||||
|
|
||||||
|
MxCommandReply reply = await InvokeCommandAsync(
|
||||||
|
new MxCommand
|
||||||
|
{
|
||||||
|
Kind = MxCommandKind.WriteBulk,
|
||||||
|
WriteBulk = command,
|
||||||
|
},
|
||||||
|
cancellationToken)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
reply.EnsureProtocolSuccess().EnsureMxAccessSuccess();
|
||||||
|
return reply.WriteBulk?.Results.ToArray() ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Bulk Write2 — sequential MXAccess Write2 (timestamped) per entry.
|
||||||
|
/// Per-item failures appear as <see cref="BulkWriteResult"/> entries with
|
||||||
|
/// <c>WasSuccessful = false</c>; the call never throws on per-item errors.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serverHandle">The ServerHandle from register.</param>
|
||||||
|
/// <param name="entries">Per-item write entries; each carries the item handle, value, timestamp, and user id.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation token.</param>
|
||||||
|
/// <returns>One <see cref="BulkWriteResult"/> per requested entry, in request order.</returns>
|
||||||
|
public async Task<IReadOnlyList<BulkWriteResult>> Write2BulkAsync(
|
||||||
|
int serverHandle,
|
||||||
|
IReadOnlyList<Write2BulkEntry> entries,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(entries);
|
||||||
|
|
||||||
|
Write2BulkCommand command = new() { ServerHandle = serverHandle };
|
||||||
|
command.Entries.Add(entries);
|
||||||
|
|
||||||
|
MxCommandReply reply = await InvokeCommandAsync(
|
||||||
|
new MxCommand
|
||||||
|
{
|
||||||
|
Kind = MxCommandKind.Write2Bulk,
|
||||||
|
Write2Bulk = command,
|
||||||
|
},
|
||||||
|
cancellationToken)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
reply.EnsureProtocolSuccess().EnsureMxAccessSuccess();
|
||||||
|
return reply.Write2Bulk?.Results.ToArray() ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Bulk WriteSecured — sequential MXAccess WriteSecured per entry.
|
||||||
|
/// Credential-sensitive values must never reach logs; the client mirrors
|
||||||
|
/// the single-item WriteSecured redaction contract.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serverHandle">The ServerHandle from register.</param>
|
||||||
|
/// <param name="entries">Per-item write entries; each carries the item handle, value, current user id, and verifier user id.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation token.</param>
|
||||||
|
/// <returns>One <see cref="BulkWriteResult"/> per requested entry, in request order.</returns>
|
||||||
|
public async Task<IReadOnlyList<BulkWriteResult>> WriteSecuredBulkAsync(
|
||||||
|
int serverHandle,
|
||||||
|
IReadOnlyList<WriteSecuredBulkEntry> entries,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(entries);
|
||||||
|
|
||||||
|
WriteSecuredBulkCommand command = new() { ServerHandle = serverHandle };
|
||||||
|
command.Entries.Add(entries);
|
||||||
|
|
||||||
|
MxCommandReply reply = await InvokeCommandAsync(
|
||||||
|
new MxCommand
|
||||||
|
{
|
||||||
|
Kind = MxCommandKind.WriteSecuredBulk,
|
||||||
|
WriteSecuredBulk = command,
|
||||||
|
},
|
||||||
|
cancellationToken)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
reply.EnsureProtocolSuccess().EnsureMxAccessSuccess();
|
||||||
|
return reply.WriteSecuredBulk?.Results.ToArray() ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Bulk WriteSecured2 — sequential MXAccess WriteSecured2 (timestamped) per entry.
|
||||||
|
/// Same redaction rules as <see cref="WriteSecuredBulkAsync"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serverHandle">The ServerHandle from register.</param>
|
||||||
|
/// <param name="entries">Per-item write entries; each carries the item handle, value, timestamp, current user id, and verifier user id.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation token.</param>
|
||||||
|
/// <returns>One <see cref="BulkWriteResult"/> per requested entry, in request order.</returns>
|
||||||
|
public async Task<IReadOnlyList<BulkWriteResult>> WriteSecured2BulkAsync(
|
||||||
|
int serverHandle,
|
||||||
|
IReadOnlyList<WriteSecured2BulkEntry> entries,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(entries);
|
||||||
|
|
||||||
|
WriteSecured2BulkCommand command = new() { ServerHandle = serverHandle };
|
||||||
|
command.Entries.Add(entries);
|
||||||
|
|
||||||
|
MxCommandReply reply = await InvokeCommandAsync(
|
||||||
|
new MxCommand
|
||||||
|
{
|
||||||
|
Kind = MxCommandKind.WriteSecured2Bulk,
|
||||||
|
WriteSecured2Bulk = command,
|
||||||
|
},
|
||||||
|
cancellationToken)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
reply.EnsureProtocolSuccess().EnsureMxAccessSuccess();
|
||||||
|
return reply.WriteSecured2Bulk?.Results.ToArray() ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Bulk Read — snapshot the current value for each requested tag.
|
||||||
|
/// Returns the cached OnDataChange value when the tag is already advised
|
||||||
|
/// (<c>WasCached = true</c>), otherwise the worker takes the full AddItem +
|
||||||
|
/// Advise + wait + UnAdvise + RemoveItem snapshot lifecycle. Per-tag
|
||||||
|
/// failures (timeout, invalid tag) appear as <see cref="BulkReadResult"/>
|
||||||
|
/// entries with <c>WasSuccessful = false</c>; the call never throws on
|
||||||
|
/// per-tag errors.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serverHandle">The ServerHandle from register.</param>
|
||||||
|
/// <param name="tagAddresses">Tag addresses to read (one per result).</param>
|
||||||
|
/// <param name="timeout">Per-call timeout for the snapshot lifecycle path; <see cref="TimeSpan.Zero"/> uses the gateway default.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation token.</param>
|
||||||
|
/// <returns>One <see cref="BulkReadResult"/> per requested tag, in request order.</returns>
|
||||||
|
public async Task<IReadOnlyList<BulkReadResult>> ReadBulkAsync(
|
||||||
|
int serverHandle,
|
||||||
|
IReadOnlyList<string> tagAddresses,
|
||||||
|
TimeSpan timeout,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(tagAddresses);
|
||||||
|
|
||||||
|
ReadBulkCommand command = new()
|
||||||
|
{
|
||||||
|
ServerHandle = serverHandle,
|
||||||
|
TimeoutMs = timeout <= TimeSpan.Zero ? 0u : (uint)Math.Min(timeout.TotalMilliseconds, uint.MaxValue),
|
||||||
|
};
|
||||||
|
command.TagAddresses.Add(tagAddresses);
|
||||||
|
|
||||||
|
MxCommandReply reply = await InvokeCommandAsync(
|
||||||
|
new MxCommand
|
||||||
|
{
|
||||||
|
Kind = MxCommandKind.ReadBulk,
|
||||||
|
ReadBulk = command,
|
||||||
|
},
|
||||||
|
cancellationToken)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
reply.EnsureProtocolSuccess().EnsureMxAccessSuccess();
|
||||||
|
return reply.ReadBulk?.Results.ToArray() ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes a value to an item on the MXAccess server.
|
/// Writes a value to an item on the MXAccess server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -522,6 +687,63 @@ public sealed class MxGatewaySession : IAsyncDisposable
|
|||||||
reply.EnsureProtocolSuccess().EnsureMxAccessSuccess();
|
reply.EnsureProtocolSuccess().EnsureMxAccessSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes specific array indices to an item using default-fill semantics.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// The gateway expands the sparse descriptor into a full <c>totalLength</c>-element array
|
||||||
|
/// before forwarding to the worker. Indices not listed in <paramref name="elements"/> are
|
||||||
|
/// written as the element type's default value — this is a RESET, not a preserve. The
|
||||||
|
/// current values at those positions are discarded. <paramref name="totalLength"/> is
|
||||||
|
/// required and must match the declared length of the array attribute.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="serverHandle">The ServerHandle from register.</param>
|
||||||
|
/// <param name="itemHandle">The ItemHandle from add-item.</param>
|
||||||
|
/// <param name="elementDataType">The MXAccess data type of each element.</param>
|
||||||
|
/// <param name="totalLength">The total declared length of the target array attribute.</param>
|
||||||
|
/// <param name="elements">Map of zero-based array index to scalar <see cref="MxValue"/>.</param>
|
||||||
|
/// <param name="userId">User ID context for the write.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation token.</param>
|
||||||
|
public Task WriteArrayElementsAsync(
|
||||||
|
int serverHandle,
|
||||||
|
int itemHandle,
|
||||||
|
MxDataType elementDataType,
|
||||||
|
uint totalLength,
|
||||||
|
IReadOnlyDictionary<uint, MxValue> elements,
|
||||||
|
int userId = 0,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(elements);
|
||||||
|
MxValue value = BuildSparseArray(elementDataType, totalLength, elements);
|
||||||
|
return WriteAsync(serverHandle, itemHandle, value, userId, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Builds an <see cref="MxValue"/> whose <see cref="MxValue.SparseArrayValue"/> describes a
|
||||||
|
/// default-fill partial array write.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="elementDataType">The MXAccess data type of each element.</param>
|
||||||
|
/// <param name="totalLength">The total declared length of the target array attribute.</param>
|
||||||
|
/// <param name="elements">Map of zero-based array index to scalar <see cref="MxValue"/>.</param>
|
||||||
|
/// <returns>An <see cref="MxValue"/> with <see cref="MxValue.KindOneofCase.SparseArrayValue"/> set.</returns>
|
||||||
|
internal static MxValue BuildSparseArray(
|
||||||
|
MxDataType elementDataType,
|
||||||
|
uint totalLength,
|
||||||
|
IReadOnlyDictionary<uint, MxValue> elements)
|
||||||
|
{
|
||||||
|
MxSparseArray sparse = new()
|
||||||
|
{
|
||||||
|
ElementDataType = elementDataType,
|
||||||
|
TotalLength = totalLength,
|
||||||
|
};
|
||||||
|
foreach (KeyValuePair<uint, MxValue> kv in elements)
|
||||||
|
{
|
||||||
|
sparse.Elements.Add(new MxSparseElement { Index = kv.Key, Value = kv.Value });
|
||||||
|
}
|
||||||
|
|
||||||
|
return new MxValue { SparseArrayValue = sparse };
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes a value to an item on the MXAccess server without error checking.
|
/// Writes a value to an item on the MXAccess server without error checking.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
using MxGateway.Contracts.Proto;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||||
|
|
||||||
namespace MxGateway.Client;
|
namespace ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
/// <summary>Exception thrown when a session is not found, not ready, or invalid.</summary>
|
/// <summary>Exception thrown when a session is not found, not ready, or invalid.</summary>
|
||||||
public sealed class MxGatewaySessionException : MxGatewayException
|
public sealed class MxGatewaySessionException : MxGatewayException
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
using MxGateway.Contracts.Proto;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||||
|
|
||||||
namespace MxGateway.Client;
|
namespace ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
/// <summary>Exception thrown when the worker process is unavailable or fails to process a command.</summary>
|
/// <summary>Exception thrown when the worker process is unavailable or fails to process a command.</summary>
|
||||||
public sealed class MxGatewayWorkerException : MxGatewayException
|
public sealed class MxGatewayWorkerException : MxGatewayException
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
using MxGateway.Contracts.Proto;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||||
|
|
||||||
namespace MxGateway.Client;
|
namespace ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
/// <summary>Extension methods for MxStatusProxy values.</summary>
|
/// <summary>Extension methods for MxStatusProxy values.</summary>
|
||||||
public static class MxStatusProxyExtensions
|
public static class MxStatusProxyExtensions
|
||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
using Google.Protobuf;
|
using Google.Protobuf;
|
||||||
using Google.Protobuf.WellKnownTypes;
|
using Google.Protobuf.WellKnownTypes;
|
||||||
using MxGateway.Contracts.Proto;
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||||
|
|
||||||
namespace MxGateway.Client;
|
namespace ZB.MOM.WW.MxGateway.Client;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates and projects gateway MXAccess values without hiding the raw
|
/// Creates and projects gateway MXAccess values without hiding the raw
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
[assembly: InternalsVisibleTo("ZB.MOM.WW.MxGateway.Client.Tests")]
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\..\src\ZB.MOM.WW.MxGateway.Contracts\ZB.MOM.WW.MxGateway.Contracts.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Grpc.Net.Client" Version="2.76.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.7" />
|
||||||
|
<PackageReference Include="Polly.Core" Version="8.6.6" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<IsPackable>true</IsPackable>
|
||||||
|
<PackageId>ZB.MOM.WW.MxGateway.Client</PackageId>
|
||||||
|
<Description>.NET 10 gRPC client for the MxAccessGateway service. Provides typed wrappers, retry, and a lazy-browse walker over the Galaxy Repository hierarchy.</Description>
|
||||||
|
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||||
|
<!-- Only the shipped library generates XML docs (matching src/Contracts). The Cli and
|
||||||
|
Tests projects are not packable and do not document their public surface, so this
|
||||||
|
stays out of the shared Directory.Build.props to avoid CS1591 on test classes. -->
|
||||||
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
||||||
|
<None Include="..\LICENSE.txt" Pack="true" PackagePath="\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
|
||||||
|
<_Parameter1>ZB.MOM.WW.MxGateway.Client.Tests</_Parameter1>
|
||||||
|
</AssemblyAttribute>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -104,6 +104,23 @@ Support:
|
|||||||
- `credentials.NewClientTLSFromFile`,
|
- `credentials.NewClientTLSFromFile`,
|
||||||
- custom `tls.Config` for advanced callers.
|
- custom `tls.Config` for advanced callers.
|
||||||
|
|
||||||
|
### Trust posture
|
||||||
|
|
||||||
|
The gateway can serve a self-signed certificate it generates itself (it has no
|
||||||
|
PKI). To make that usable, TLS is **lenient by default**: when `Plaintext` is
|
||||||
|
`false` and no `CACertFile`/`TLSConfig`/`TransportCredentials` is supplied,
|
||||||
|
`buildCredentials` dials with `tls.Config{InsecureSkipVerify: true}` (carrying
|
||||||
|
`ServerNameOverride` as the SNI when set), so the gateway's self-signed
|
||||||
|
certificate is accepted without verification.
|
||||||
|
|
||||||
|
To verify the gateway instead:
|
||||||
|
|
||||||
|
- set `CACertFile` to pin a CA (full verification against that root), or
|
||||||
|
- set `RequireCertificateValidation: true` to verify against the OS/system trust
|
||||||
|
roots without pinning.
|
||||||
|
|
||||||
|
Pinning a CA always wins over the lenient default.
|
||||||
|
|
||||||
## Streaming
|
## Streaming
|
||||||
|
|
||||||
`Events(ctx)` should return a receive channel of:
|
`Events(ctx)` should return a receive channel of:
|
||||||
|
|||||||
@@ -75,6 +75,14 @@ client, err := mxgateway.Dial(ctx, mxgateway.Options{
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The gateway can auto-generate its own self-signed certificate (it has no PKI), so
|
||||||
|
the client is **lenient by default**: a TLS connection (`Plaintext: false`) with
|
||||||
|
no `CACertFile`/`TLSConfig` accepts whatever certificate the gateway presents
|
||||||
|
(`InsecureSkipVerify`, with `ServerNameOverride` as the SNI when set). To verify
|
||||||
|
instead, set `CACertFile` to pin a CA, or set `RequireCertificateValidation:
|
||||||
|
true` to verify against the OS/system trust roots without pinning. See
|
||||||
|
[Gateway Configuration](../../docs/GatewayConfiguration.md#automatic-self-signed-certificate).
|
||||||
|
|
||||||
`Client.OpenSession` returns a `Session` with helpers for `Register`,
|
`Client.OpenSession` returns a `Session` with helpers for `Register`,
|
||||||
`AddItem`, `AddItem2`, `Advise`, `Write`, `Events`, and `Close`. Prefer
|
`AddItem`, `AddItem2`, `Advise`, `Write`, `Events`, and `Close`. Prefer
|
||||||
`SubscribeEvents` or `SubscribeEventsAfter` for long-running streams because the
|
`SubscribeEvents` or `SubscribeEventsAfter` for long-running streams because the
|
||||||
@@ -84,6 +92,86 @@ goroutine cleanup. Raw protobuf messages remain available through the
|
|||||||
`errors.As` for `GatewayError`, `CommandError`, and `MxAccessError`; command
|
`errors.As` for `GatewayError`, `CommandError`, and `MxAccessError`; command
|
||||||
errors preserve the raw reply.
|
errors preserve the raw reply.
|
||||||
|
|
||||||
|
For alarms, the package exposes `Client.QueryActiveAlarms` for one-shot
|
||||||
|
snapshots, `Client.StreamAlarms` for the server-streaming feed, and
|
||||||
|
`Client.AcknowledgeAlarm` to ack an alarm by full reference. The streaming
|
||||||
|
call returns a `StreamAlarmsClient`; cancel its context to terminate the
|
||||||
|
stream. All three pass straight through to the gateway's central alarm
|
||||||
|
monitor.
|
||||||
|
|
||||||
|
## Write Semantics And Common Pitfalls
|
||||||
|
|
||||||
|
These are MXAccess parity behaviors that surprise new callers. The gateway
|
||||||
|
forwards them unchanged — it does not paper over them.
|
||||||
|
|
||||||
|
### Attributing a write to a user without `AuthenticateUser`
|
||||||
|
|
||||||
|
MXAccess only stamps a plain `Write`/`Write2` with a Galaxy user id when the
|
||||||
|
item carries an active *supervisory* advise. If you are **not** using the
|
||||||
|
verified/secured path (`AuthenticateUser` → `WriteSecured`/`WriteSecured2`) but
|
||||||
|
still need the write attributed to a user id, you must first advise the item
|
||||||
|
supervisory and then pass that user id on the write. Without the supervisory
|
||||||
|
advise the `userID` on a plain write is ignored.
|
||||||
|
|
||||||
|
The session exposes `Advise`/`UnAdvise` but not supervisory advise, so send it
|
||||||
|
through the generic command channel:
|
||||||
|
|
||||||
|
```go
|
||||||
|
_, err := client.Invoke(ctx, &pb.MxCommandRequest{
|
||||||
|
SessionId: session.ID(),
|
||||||
|
Command: &pb.MxCommand{
|
||||||
|
Kind: pb.MxCommandKind_MX_COMMAND_KIND_ADVISE_SUPERVISORY,
|
||||||
|
Payload: &pb.MxCommand_AdviseSupervisory{
|
||||||
|
AdviseSupervisory: &pb.AdviseSupervisoryCommand{
|
||||||
|
ServerHandle: serverHandle,
|
||||||
|
ItemHandle: itemHandle,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
err = session.Write(ctx, serverHandle, itemHandle, value, userID)
|
||||||
|
```
|
||||||
|
|
||||||
|
The CLI exposes the same command as `advise-supervisory`, and `write`
|
||||||
|
takes `-user-id`.
|
||||||
|
|
||||||
|
### Array writes replace the whole array
|
||||||
|
|
||||||
|
A write to an array attribute **replaces the entire array**; it is not an
|
||||||
|
element-wise patch. To change a subset of elements, send the full array with
|
||||||
|
the unchanged elements included. For example, to change 2 elements of a
|
||||||
|
20-element array, build the `MxValue` from all 20 values (the 18 unchanged plus
|
||||||
|
the 2 new ones). Sending only the 2 changed values overwrites the attribute
|
||||||
|
with a 2-element array.
|
||||||
|
|
||||||
|
`Session.WriteArrayElements` offers a default-fill shorthand: pass only the
|
||||||
|
indices you want to set along with a `totalLength`. The gateway expands the
|
||||||
|
sparse representation into a full array before forwarding to MXAccess — every
|
||||||
|
unmentioned index receives the element type's zero value (boolean `false`,
|
||||||
|
integer `0`, float `0.0`, string `""`, time = Unix epoch). This is a **RESET**
|
||||||
|
of unmentioned indices, not a preserve of existing values. Use the full-array
|
||||||
|
form (read-modify-write) when existing element values must be preserved.
|
||||||
|
|
||||||
|
```go
|
||||||
|
// Set element [3] of a 10-element float array; all other indices reset to 0.0.
|
||||||
|
err = session.WriteArrayElements(
|
||||||
|
ctx,
|
||||||
|
serverHandle, itemHandle,
|
||||||
|
mxgateway.DataTypeFloat,
|
||||||
|
10, // totalLength
|
||||||
|
map[uint32]*mxgateway.MxValue{
|
||||||
|
3: mxgateway.FloatValue(1.5),
|
||||||
|
},
|
||||||
|
userID,
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
`AddItem`, `AddItem2`, `AddItemBulk`, and `AddBufferedItem` auto-normalize a
|
||||||
|
bare array attribute name to the `[]` array address form expected by MXAccess,
|
||||||
|
so callers do not need to append `[]` themselves. Both forms are accepted;
|
||||||
|
duplicates are deduplicated by the gateway.
|
||||||
|
|
||||||
## Galaxy Repository browse
|
## Galaxy Repository browse
|
||||||
|
|
||||||
The `GalaxyRepository` service (proto package `galaxy_repository.v1`) is a
|
The `GalaxyRepository` service (proto package `galaxy_repository.v1`) is a
|
||||||
@@ -114,6 +202,68 @@ reports `present=false` (no deploy recorded). `DiscoverHierarchy` returns
|
|||||||
the generated `*GalaxyObject` slice with each object's dynamic attributes
|
the generated `*GalaxyObject` slice with each object's dynamic attributes
|
||||||
populated for direct contract access.
|
populated for direct contract access.
|
||||||
|
|
||||||
|
### Browsing lazily
|
||||||
|
|
||||||
|
For UI trees or OPC UA bridges, use `BrowseChildren` to walk one level at a
|
||||||
|
time instead of loading the full hierarchy. Pass an empty request for root
|
||||||
|
objects; subsequent calls set `ParentGobjectId`, `ParentTagName`, or
|
||||||
|
`ParentContainedPath`. Filter fields match `DiscoverHierarchy`. Each response
|
||||||
|
pairs `Children` with `ChildHasChildren` so you know which nodes to expand. See
|
||||||
|
[Galaxy Repository](../../docs/GalaxyRepository.md#browsechildren) for full
|
||||||
|
request and filter semantics.
|
||||||
|
|
||||||
|
```go
|
||||||
|
import pb "gitea.dohertylan.com/dohertj2/mxaccessgw/clients/go/internal/generated/galaxy_repository/v1"
|
||||||
|
|
||||||
|
reply, err := galaxy.BrowseChildren(ctx, &pb.BrowseChildrenRequest{})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for i, child := range reply.GetChildren() {
|
||||||
|
fmt.Printf("%s expand=%v\n", child.GetTagName(), reply.GetChildHasChildren()[i])
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### High-level walker
|
||||||
|
|
||||||
|
For UI trees, the client provides a `LazyBrowseNode` walker that handles
|
||||||
|
sibling pagination and the `child_has_children` hint for you:
|
||||||
|
|
||||||
|
```go
|
||||||
|
galaxy, err := mxgateway.DialGalaxy(ctx, mxgateway.Options{
|
||||||
|
Endpoint: "localhost:5000",
|
||||||
|
APIKey: os.Getenv("MXGATEWAY_API_KEY"),
|
||||||
|
Plaintext: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
defer galaxy.Close()
|
||||||
|
|
||||||
|
roots, err := galaxy.Browse(ctx, nil)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
for _, root := range roots {
|
||||||
|
if root.HasChildrenHint() {
|
||||||
|
if err := root.Expand(ctx); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, child := range root.Children() {
|
||||||
|
kind := "leaf"
|
||||||
|
if child.HasChildrenHint() {
|
||||||
|
kind = "has children"
|
||||||
|
}
|
||||||
|
fmt.Printf("%s (%s)\n", child.Object().GetTagName(), kind)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`Expand` is idempotent — calling it twice fires only one RPC,
|
||||||
|
and is safe under concurrent callers. To refresh after a Galaxy redeploy, call
|
||||||
|
`Browse` again from the root.
|
||||||
|
|
||||||
### Watching deploy events
|
### Watching deploy events
|
||||||
|
|
||||||
`WatchDeployEvents` opens a server-streaming subscription. The server emits a
|
`WatchDeployEvents` opens a server-streaming subscription. The server emits a
|
||||||
@@ -170,24 +320,79 @@ one line per event in text mode or one JSON object per event with `-json`.
|
|||||||
The `mxgw-go` CLI emits JSON with redacted API keys for commands that connect to
|
The `mxgw-go` CLI emits JSON with redacted API keys for commands that connect to
|
||||||
the gateway:
|
the gateway:
|
||||||
|
|
||||||
|
### Subcommand reference
|
||||||
|
|
||||||
|
Every subcommand wired into the CLI. All accept the common flags
|
||||||
|
(`-endpoint`, `-plaintext`, `-api-key` / `-api-key-env`, `-ca-cert`,
|
||||||
|
`-server-name-override`, `-call-timeout`) and most accept `-json`.
|
||||||
|
|
||||||
|
| Command | Purpose |
|
||||||
|
|---|---|
|
||||||
|
| `version` | Print client/contract versions. |
|
||||||
|
| `open-session` | Open a gateway session and print its id. |
|
||||||
|
| `close-session` | Close a session by id. |
|
||||||
|
| `ping` | Round-trip a `PING` command (`-session-id`, `-message`). |
|
||||||
|
| `register` | Register a client name on a session (`-session-id`, `-client-name`). |
|
||||||
|
| `add-item` | Add an item handle (`-session-id`, `-server-handle`, `-item`). |
|
||||||
|
| `advise` | Advise (subscribe) one item (`-session-id`, `-server-handle`, `-item-handle`). |
|
||||||
|
| `advise-supervisory` | Advise one item supervisory — required before a user-id-attributed plain `write`. |
|
||||||
|
| `subscribe-bulk` | Advise many items in one call. |
|
||||||
|
| `unsubscribe-bulk` | Unadvise many item handles in one call. |
|
||||||
|
| `read-bulk` | Read snapshots for many item handles in one call. |
|
||||||
|
| `write` | Write one value (`-type`, `-value`). |
|
||||||
|
| `write-bulk` | Write many values (`-item-handles`, `-values`, counts must match). |
|
||||||
|
| `write2-bulk` | `write-bulk` with a shared `-timestamp-value` (RFC 3339). |
|
||||||
|
| `write-secured-bulk` | Secured bulk write (`-current-user-id`, `-verifier-user-id`). |
|
||||||
|
| `write-secured2-bulk` | Secured bulk write with a shared timestamp. |
|
||||||
|
| `bench-read-bulk` | Throughput benchmark (`-duration-seconds`, `-warmup-seconds`, `-bulk-size`). |
|
||||||
|
| `stream-events` | Stream item-value events for a session (`-session-id`, `-limit`). |
|
||||||
|
| `stream-alarms` | Stream the alarm feed (`-filter-prefix`, `-limit`). |
|
||||||
|
| `acknowledge-alarm` | Acknowledge an alarm reference. |
|
||||||
|
| `smoke` | End-to-end smoke workflow against one item. |
|
||||||
|
| `galaxy-test-connection` | Probe the Galaxy Repository RPC connection. |
|
||||||
|
| `galaxy-last-deploy` | Print the most recent deploy event. |
|
||||||
|
| `galaxy-discover` | Discover deployed objects. |
|
||||||
|
| `galaxy-watch` | Stream deploy events until Ctrl+C or `-limit`. |
|
||||||
|
| `galaxy-browse` | Lazy/eager browse of the Galaxy object tree. |
|
||||||
|
| `batch` | Read commands from stdin (see below). |
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
go run ./cmd/mxgw-go version -json
|
go run ./cmd/mxgw-go version -json
|
||||||
go run ./cmd/mxgw-go open-session -endpoint localhost:5000 -plaintext -json
|
go run ./cmd/mxgw-go open-session -endpoint localhost:5000 -plaintext -json
|
||||||
|
go run ./cmd/mxgw-go ping -session-id <id> -plaintext -json
|
||||||
go run ./cmd/mxgw-go register -session-id <id> -client-name mxgw-go -plaintext -json
|
go run ./cmd/mxgw-go register -session-id <id> -client-name mxgw-go -plaintext -json
|
||||||
go run ./cmd/mxgw-go add-item -session-id <id> -server-handle 1 -item Area001.Tag.Value -plaintext -json
|
go run ./cmd/mxgw-go add-item -session-id <id> -server-handle 1 -item Area001.Tag.Value -plaintext -json
|
||||||
go run ./cmd/mxgw-go advise -session-id <id> -server-handle 1 -item-handle 1 -plaintext -json
|
go run ./cmd/mxgw-go advise -session-id <id> -server-handle 1 -item-handle 1 -plaintext -json
|
||||||
go run ./cmd/mxgw-go write -session-id <id> -server-handle 1 -item-handle 1 -type int32 -value 123 -plaintext -json
|
go run ./cmd/mxgw-go write -session-id <id> -server-handle 1 -item-handle 1 -type int32 -value 123 -plaintext -json
|
||||||
|
go run ./cmd/mxgw-go write-bulk -session-id <id> -server-handle 1 -item-handles 1,2 -values 10,20 -type int32 -plaintext -json
|
||||||
|
go run ./cmd/mxgw-go read-bulk -session-id <id> -item-handles 1,2 -plaintext -json
|
||||||
go run ./cmd/mxgw-go stream-events -session-id <id> -plaintext -json
|
go run ./cmd/mxgw-go stream-events -session-id <id> -plaintext -json
|
||||||
|
go run ./cmd/mxgw-go stream-alarms -plaintext -json
|
||||||
go run ./cmd/mxgw-go smoke -item Area001.Tag.Value -plaintext -json
|
go run ./cmd/mxgw-go smoke -item Area001.Tag.Value -plaintext -json
|
||||||
go run ./cmd/mxgw-go galaxy-test-connection -plaintext -json
|
go run ./cmd/mxgw-go galaxy-test-connection -plaintext -json
|
||||||
go run ./cmd/mxgw-go galaxy-last-deploy -plaintext -json
|
go run ./cmd/mxgw-go galaxy-last-deploy -plaintext -json
|
||||||
go run ./cmd/mxgw-go galaxy-discover -plaintext -json
|
go run ./cmd/mxgw-go galaxy-discover -plaintext -json
|
||||||
go run ./cmd/mxgw-go galaxy-watch -plaintext -json
|
go run ./cmd/mxgw-go galaxy-watch -plaintext -json
|
||||||
|
go run ./cmd/mxgw-go galaxy-browse -plaintext -json
|
||||||
```
|
```
|
||||||
|
|
||||||
Use `-api-key-env MXGATEWAY_API_KEY` or `-api-key <key>` when authentication is
|
Use `-api-key-env MXGATEWAY_API_KEY` or `-api-key <key>` when authentication is
|
||||||
enabled. CLI output redacts the key value and never writes the raw secret.
|
enabled. CLI output redacts the key value and never writes the raw secret.
|
||||||
|
|
||||||
|
### `batch` mode
|
||||||
|
|
||||||
|
`batch` reads one command line at a time from stdin and dispatches each through
|
||||||
|
the same routing as the standalone subcommands; it is the interface the
|
||||||
|
cross-language E2E harness drives. After every command's output it writes the
|
||||||
|
end-of-result sentinel line `__MXGW_BATCH_EOR__` to stdout and flushes, so the
|
||||||
|
harness can frame each result. Blank/whitespace-only lines are skipped; only
|
||||||
|
stdin EOF ends the session. Command errors are serialised as a JSON object
|
||||||
|
(`{"error":...,"type":"error"}`) to stdout (not stderr) and still followed by the
|
||||||
|
sentinel, so a failing command does not abort the batch. The input scanner
|
||||||
|
buffer is widened to 16 MiB so a single long command line (e.g. a bulk write with
|
||||||
|
thousands of handles) does not trip bufio's default 64 KiB token-too-long limit;
|
||||||
|
a line that still exceeds 16 MiB surfaces as a framed error and ends the session.
|
||||||
|
|
||||||
Use TLS options for a secured gateway:
|
Use TLS options for a secured gateway:
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
@@ -206,6 +411,41 @@ $env:MXGATEWAY_TEST_ITEM = 'Area001.Tag.Value'
|
|||||||
go run ./cmd/mxgw-go smoke -endpoint $env:MXGATEWAY_ENDPOINT -plaintext -api-key-env MXGATEWAY_API_KEY -item $env:MXGATEWAY_TEST_ITEM -json
|
go run ./cmd/mxgw-go smoke -endpoint $env:MXGATEWAY_ENDPOINT -plaintext -api-key-env MXGATEWAY_API_KEY -item $env:MXGATEWAY_TEST_ITEM -json
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Installing the Go client
|
||||||
|
|
||||||
|
The module is resolved directly from the git repo — no package registry:
|
||||||
|
|
||||||
|
````bash
|
||||||
|
go get gitea.dohertylan.com/dohertj2/mxaccessgw/clients/go@v0.1.1
|
||||||
|
````
|
||||||
|
|
||||||
|
Then import:
|
||||||
|
|
||||||
|
````go
|
||||||
|
import "gitea.dohertylan.com/dohertj2/mxaccessgw/clients/go/mxgateway"
|
||||||
|
````
|
||||||
|
|
||||||
|
If your build environment cannot reach `gitea.dohertylan.com` directly,
|
||||||
|
configure `GOPROXY` to point at an internal proxy that fronts the Gitea
|
||||||
|
repo, or set `GOPRIVATE=gitea.dohertylan.com/*` to fetch the module
|
||||||
|
straight from the VCS — this both bypasses the public module proxy and
|
||||||
|
disables checksum-database (`sum.golang.org`) verification for that path.
|
||||||
|
Add `GOINSECURE=gitea.dohertylan.com/*` if the host serves the module over
|
||||||
|
plain HTTP rather than HTTPS.
|
||||||
|
|
||||||
|
## Releasing a new version
|
||||||
|
|
||||||
|
Go modules in monorepo subdirectories use prefixed tags. To tag a release
|
||||||
|
from this repo:
|
||||||
|
|
||||||
|
````bash
|
||||||
|
pwsh scripts/tag-go-module.ps1 -Version v0.1.1 -Push
|
||||||
|
````
|
||||||
|
|
||||||
|
The script validates semver, refuses to tag with uncommitted tracked
|
||||||
|
changes, creates an annotated tag `clients/go/v0.1.1`, and (with `-Push`)
|
||||||
|
pushes it to origin.
|
||||||
|
|
||||||
## Related Documentation
|
## Related Documentation
|
||||||
|
|
||||||
- [Client Packaging](../../docs/ClientPackaging.md)
|
- [Client Packaging](../../docs/ClientPackaging.md)
|
||||||
|
|||||||
+935
-12
File diff suppressed because it is too large
Load Diff
@@ -2,9 +2,15 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
pb "gitea.dohertylan.com/dohertj2/mxaccessgw/clients/go/internal/generated"
|
||||||
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRunVersionJSON(t *testing.T) {
|
func TestRunVersionJSON(t *testing.T) {
|
||||||
@@ -47,6 +53,34 @@ func TestCommonOptionsRedactsAPIKey(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRunBatchEmitsEORAfterVersion(t *testing.T) {
|
||||||
|
var stdout bytes.Buffer
|
||||||
|
var stderr bytes.Buffer
|
||||||
|
|
||||||
|
in := strings.NewReader("version --json\n")
|
||||||
|
if err := runBatch(t.Context(), in, &stdout, &stderr); err != nil {
|
||||||
|
t.Fatalf("runBatch() error = %v; stderr = %s", err, stderr.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
out := stdout.String()
|
||||||
|
if !strings.Contains(out, "\n"+batchEOR+"\n") && !strings.HasSuffix(out, batchEOR+"\n") {
|
||||||
|
t.Fatalf("expected EOR marker %q in stdout; got: %q", batchEOR, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
idx := strings.Index(out, batchEOR)
|
||||||
|
if idx <= 0 {
|
||||||
|
t.Fatalf("EOR marker not found or appeared before any output: %q", out)
|
||||||
|
}
|
||||||
|
payload := out[:idx]
|
||||||
|
var output versionOutput
|
||||||
|
if err := json.Unmarshal([]byte(payload), &output); err != nil {
|
||||||
|
t.Fatalf("parse JSON block before EOR: %v (payload=%q)", err, payload)
|
||||||
|
}
|
||||||
|
if output.GatewayProtocolVersion == 0 || output.WorkerProtocolVersion == 0 {
|
||||||
|
t.Fatalf("protocol versions were not populated: %+v", output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestParseValueBuildsTypedValue(t *testing.T) {
|
func TestParseValueBuildsTypedValue(t *testing.T) {
|
||||||
value, err := parseValue("int32", "123")
|
value, err := parseValue("int32", "123")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -56,3 +90,500 @@ func TestParseValueBuildsTypedValue(t *testing.T) {
|
|||||||
t.Fatalf("int32 value = %d, want 123", got)
|
t.Fatalf("int32 value = %d, want 123", got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestRunWriteBulkVariantGatesSecuredFlags pins the Client.Go-022 fix:
|
||||||
|
// secured-only flags must be unavailable on non-secured variants, and
|
||||||
|
// vice-versa, so a wrong-variant flag fails with a clean "flag provided
|
||||||
|
// but not defined" error instead of silently no-op'ing.
|
||||||
|
func TestRunWriteBulkVariantGatesSecuredFlags(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
name string
|
||||||
|
args []string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "write-bulk-rejects-current-user-id",
|
||||||
|
args: []string{"write-bulk", "-current-user-id", "5", "-item-handles", "1", "-values", "1"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "write-bulk-rejects-verifier-user-id",
|
||||||
|
args: []string{"write-bulk", "-verifier-user-id", "5", "-item-handles", "1", "-values", "1"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "write2-bulk-rejects-current-user-id",
|
||||||
|
args: []string{"write2-bulk", "-current-user-id", "5", "-item-handles", "1", "-values", "1"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "write-secured-bulk-rejects-user-id",
|
||||||
|
args: []string{"write-secured-bulk", "-user-id", "5", "-item-handles", "1", "-values", "1"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "write-secured2-bulk-rejects-user-id",
|
||||||
|
args: []string{"write-secured2-bulk", "-user-id", "5", "-item-handles", "1", "-values", "1"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tc := range cases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
err := runWithIO(t.Context(), tc.args, &stdout, &stderr)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("runWithIO(%v) returned no error", tc.args)
|
||||||
|
}
|
||||||
|
if !strings.Contains(err.Error(), "flag provided but not defined") {
|
||||||
|
t.Fatalf("runWithIO(%v) error = %v; want 'flag provided but not defined'", tc.args, err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestRunBenchReadBulkRespectsContextCancellation pins the Client.Go-023
|
||||||
|
// fix: the warm-up and steady-state wall-clock loops must honour ctx.Err()
|
||||||
|
// so an external cancel (Ctrl+C, parent-cancel from a cross-language bench
|
||||||
|
// driver) short-circuits the bench instead of spinning failing ReadBulk
|
||||||
|
// calls until the wall-clock deadline elapses.
|
||||||
|
func TestRunBenchReadBulkRespectsContextCancellation(t *testing.T) {
|
||||||
|
listener, err := net.Listen("tcp", "127.0.0.1:0")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("listen: %v", err)
|
||||||
|
}
|
||||||
|
server := grpc.NewServer()
|
||||||
|
fake := &benchFakeGateway{}
|
||||||
|
pb.RegisterMxAccessGatewayServer(server, fake)
|
||||||
|
go func() {
|
||||||
|
_ = server.Serve(listener)
|
||||||
|
}()
|
||||||
|
defer server.Stop()
|
||||||
|
defer listener.Close()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
// Long warm-up + duration, so if the ctx.Err() guard were missing the
|
||||||
|
// loops would run for ~10s. With the guard, the cancel below short-
|
||||||
|
// circuits both loops within ~one ReadBulk iteration.
|
||||||
|
args := []string{
|
||||||
|
"bench-read-bulk",
|
||||||
|
"-endpoint", listener.Addr().String(),
|
||||||
|
"-plaintext",
|
||||||
|
"-api-key", "test",
|
||||||
|
"-warmup-seconds", "5",
|
||||||
|
"-duration-seconds", "5",
|
||||||
|
"-bulk-size", "1",
|
||||||
|
"-timeout-ms", "100",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel after a brief delay — far less than warmup+duration (10s).
|
||||||
|
go func() {
|
||||||
|
time.Sleep(150 * time.Millisecond)
|
||||||
|
cancel()
|
||||||
|
}()
|
||||||
|
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
start := time.Now()
|
||||||
|
err = runWithIO(ctx, args, &stdout, &stderr)
|
||||||
|
elapsed := time.Since(start)
|
||||||
|
|
||||||
|
// With the ctx.Err() guard, the loops exit well before the wall-clock
|
||||||
|
// deadlines (warmup=5s + duration=5s = 10s). Allow generous slack for
|
||||||
|
// CI noise but assert clearly less than the un-guarded worst case.
|
||||||
|
if elapsed > 4*time.Second {
|
||||||
|
t.Fatalf("bench-read-bulk took %s after ctx cancel; want <4s (ctx.Err() guard missing?). err=%v stderr=%s", elapsed, err, stderr.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestRunPingPlainText verifies the ping subcommand round-trips through the
|
||||||
|
// fake gateway and prints the echo (diagnostic_message) in plain-text mode.
|
||||||
|
func TestRunPingPlainText(t *testing.T) {
|
||||||
|
listener, err := net.Listen("tcp", "127.0.0.1:0")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("listen: %v", err)
|
||||||
|
}
|
||||||
|
server := grpc.NewServer()
|
||||||
|
fake := &pingFakeGateway{}
|
||||||
|
pb.RegisterMxAccessGatewayServer(server, fake)
|
||||||
|
go func() { _ = server.Serve(listener) }()
|
||||||
|
defer server.Stop()
|
||||||
|
defer listener.Close()
|
||||||
|
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
args := []string{
|
||||||
|
"ping",
|
||||||
|
"-endpoint", listener.Addr().String(),
|
||||||
|
"-plaintext",
|
||||||
|
"-api-key", "test",
|
||||||
|
"-session-id", "test-session",
|
||||||
|
"-message", "hello",
|
||||||
|
}
|
||||||
|
if err := runWithIO(t.Context(), args, &stdout, &stderr); err != nil {
|
||||||
|
t.Fatalf("runWithIO() error = %v; stderr = %s", err, stderr.String())
|
||||||
|
}
|
||||||
|
got := strings.TrimSpace(stdout.String())
|
||||||
|
if got != "pong:hello" {
|
||||||
|
t.Fatalf("ping plain-text output = %q, want %q", got, "pong:hello")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestRunPingJSON verifies the ping subcommand emits valid JSON in --json mode.
|
||||||
|
func TestRunPingJSON(t *testing.T) {
|
||||||
|
listener, err := net.Listen("tcp", "127.0.0.1:0")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("listen: %v", err)
|
||||||
|
}
|
||||||
|
server := grpc.NewServer()
|
||||||
|
fake := &pingFakeGateway{}
|
||||||
|
pb.RegisterMxAccessGatewayServer(server, fake)
|
||||||
|
go func() { _ = server.Serve(listener) }()
|
||||||
|
defer server.Stop()
|
||||||
|
defer listener.Close()
|
||||||
|
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
args := []string{
|
||||||
|
"ping",
|
||||||
|
"-endpoint", listener.Addr().String(),
|
||||||
|
"-plaintext",
|
||||||
|
"-api-key", "test",
|
||||||
|
"-session-id", "test-session",
|
||||||
|
"-message", "hello",
|
||||||
|
"-json",
|
||||||
|
}
|
||||||
|
if err := runWithIO(t.Context(), args, &stdout, &stderr); err != nil {
|
||||||
|
t.Fatalf("runWithIO() error = %v; stderr = %s", err, stderr.String())
|
||||||
|
}
|
||||||
|
var out commandReplyOutput
|
||||||
|
if err := json.Unmarshal(stdout.Bytes(), &out); err != nil {
|
||||||
|
t.Fatalf("parse JSON: %v\noutput: %s", err, stdout.String())
|
||||||
|
}
|
||||||
|
if out.Command != "ping" {
|
||||||
|
t.Fatalf("command = %q, want %q", out.Command, "ping")
|
||||||
|
}
|
||||||
|
// The fake gateway echoes "pong:<message>" in diagnostic_message; verify the
|
||||||
|
// echo appears in the serialised reply so a future regression that wired
|
||||||
|
// PingRaw to the wrong proto field would be caught here.
|
||||||
|
replyStr := string(out.Reply)
|
||||||
|
if !strings.Contains(replyStr, "pong:hello") {
|
||||||
|
t.Fatalf("ping JSON reply missing echoed message %q; reply = %s", "pong:hello", replyStr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestRunPingRequiresSessionID verifies the ping subcommand rejects missing session-id.
|
||||||
|
func TestRunPingRequiresSessionID(t *testing.T) {
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
err := runWithIO(t.Context(), []string{"ping", "-plaintext", "-api-key", "test"}, &stdout, &stderr)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("runWithIO(ping without --session-id) returned no error")
|
||||||
|
}
|
||||||
|
if !strings.Contains(err.Error(), "session-id is required") {
|
||||||
|
t.Fatalf("error = %v; want 'session-id is required'", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// pingFakeGateway handles Invoke for MX_COMMAND_KIND_PING by echoing the
|
||||||
|
// message back in the diagnostic_message field so the CLI plain-text path
|
||||||
|
// has a deterministic, non-empty string to assert on.
|
||||||
|
type pingFakeGateway struct {
|
||||||
|
pb.UnimplementedMxAccessGatewayServer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *pingFakeGateway) Invoke(_ context.Context, req *pb.MxCommandRequest) (*pb.MxCommandReply, error) {
|
||||||
|
echo := "pong:" + req.GetCommand().GetPing().GetMessage()
|
||||||
|
return &pb.MxCommandReply{
|
||||||
|
SessionId: req.GetSessionId(),
|
||||||
|
Kind: pb.MxCommandKind_MX_COMMAND_KIND_PING,
|
||||||
|
DiagnosticMessage: echo,
|
||||||
|
ProtocolStatus: &pb.ProtocolStatus{Code: pb.ProtocolStatusCode_PROTOCOL_STATUS_CODE_OK},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// benchFakeGateway is a minimal MxAccessGatewayServer that satisfies the
|
||||||
|
// bench-read-bulk session-setup sequence (OpenSession + Invoke for Register
|
||||||
|
// / SubscribeBulk / ReadBulk / UnsubscribeBulk / CloseSession).
|
||||||
|
type benchFakeGateway struct {
|
||||||
|
pb.UnimplementedMxAccessGatewayServer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *benchFakeGateway) OpenSession(_ context.Context, _ *pb.OpenSessionRequest) (*pb.OpenSessionReply, error) {
|
||||||
|
return &pb.OpenSessionReply{
|
||||||
|
SessionId: "bench-session",
|
||||||
|
ProtocolStatus: &pb.ProtocolStatus{Code: pb.ProtocolStatusCode_PROTOCOL_STATUS_CODE_OK},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *benchFakeGateway) CloseSession(_ context.Context, req *pb.CloseSessionRequest) (*pb.CloseSessionReply, error) {
|
||||||
|
return &pb.CloseSessionReply{
|
||||||
|
SessionId: req.GetSessionId(),
|
||||||
|
ProtocolStatus: &pb.ProtocolStatus{Code: pb.ProtocolStatusCode_PROTOCOL_STATUS_CODE_OK},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *benchFakeGateway) Invoke(_ context.Context, req *pb.MxCommandRequest) (*pb.MxCommandReply, error) {
|
||||||
|
kind := req.GetCommand().GetKind()
|
||||||
|
reply := &pb.MxCommandReply{
|
||||||
|
SessionId: req.GetSessionId(),
|
||||||
|
Kind: kind,
|
||||||
|
ProtocolStatus: &pb.ProtocolStatus{Code: pb.ProtocolStatusCode_PROTOCOL_STATUS_CODE_OK},
|
||||||
|
}
|
||||||
|
switch kind {
|
||||||
|
case pb.MxCommandKind_MX_COMMAND_KIND_REGISTER:
|
||||||
|
reply.Payload = &pb.MxCommandReply_Register{Register: &pb.RegisterReply{ServerHandle: 1}}
|
||||||
|
case pb.MxCommandKind_MX_COMMAND_KIND_SUBSCRIBE_BULK:
|
||||||
|
reply.Payload = &pb.MxCommandReply_SubscribeBulk{SubscribeBulk: &pb.BulkSubscribeReply{
|
||||||
|
Results: []*pb.SubscribeResult{{ServerHandle: 1, ItemHandle: 1, WasSuccessful: true}},
|
||||||
|
}}
|
||||||
|
case pb.MxCommandKind_MX_COMMAND_KIND_READ_BULK:
|
||||||
|
reply.Payload = &pb.MxCommandReply_ReadBulk{ReadBulk: &pb.BulkReadReply{
|
||||||
|
Results: []*pb.BulkReadResult{{ItemHandle: 1, WasSuccessful: true, WasCached: true}},
|
||||||
|
}}
|
||||||
|
case pb.MxCommandKind_MX_COMMAND_KIND_UNSUBSCRIBE_BULK:
|
||||||
|
reply.Payload = &pb.MxCommandReply_UnsubscribeBulk{UnsubscribeBulk: &pb.BulkSubscribeReply{}}
|
||||||
|
}
|
||||||
|
return reply, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestRunBenchReadBulkRejectsNonPositiveBulkSize pins the Client.Go-023-adjacent
|
||||||
|
// positivity checks so they cannot drift while resolving the cancellation finding.
|
||||||
|
func TestRunBenchReadBulkRejectsNonPositiveBulkSize(t *testing.T) {
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
err := runWithIO(t.Context(), []string{"bench-read-bulk", "-bulk-size", "0"}, &stdout, &stderr)
|
||||||
|
if err == nil || !strings.Contains(err.Error(), "bulk-size must be positive") {
|
||||||
|
t.Fatalf("bench-read-bulk -bulk-size 0 error = %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// browseFakeGalaxy implements BrowseChildren for the galaxy-browse subcommand
|
||||||
|
// tests. It returns two root objects when no parent is supplied (the first
|
||||||
|
// flagged as having children), and one child when the first root's gobject id
|
||||||
|
// is supplied as the parent. The recorded last request lets a test assert the
|
||||||
|
// CLI forwarded the parent and filter fields onto the wire.
|
||||||
|
type browseFakeGalaxy struct {
|
||||||
|
pb.UnimplementedGalaxyRepositoryServer
|
||||||
|
lastRequest *pb.BrowseChildrenRequest
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *browseFakeGalaxy) BrowseChildren(_ context.Context, req *pb.BrowseChildrenRequest) (*pb.BrowseChildrenReply, error) {
|
||||||
|
g.lastRequest = req
|
||||||
|
if req.GetParentGobjectId() == 10 {
|
||||||
|
return &pb.BrowseChildrenReply{
|
||||||
|
Children: []*pb.GalaxyObject{
|
||||||
|
{GobjectId: 11, TagName: "Area1.Tank", BrowseName: "Tank"},
|
||||||
|
},
|
||||||
|
ChildHasChildren: []bool{false},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
return &pb.BrowseChildrenReply{
|
||||||
|
Children: []*pb.GalaxyObject{
|
||||||
|
{GobjectId: 10, TagName: "Area1", BrowseName: "Area1"},
|
||||||
|
{GobjectId: 20, TagName: "Area2", BrowseName: "Area2"},
|
||||||
|
},
|
||||||
|
ChildHasChildren: []bool{true, false},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func startBrowseFakeGalaxy(t *testing.T) (addr string, fake *browseFakeGalaxy) {
|
||||||
|
t.Helper()
|
||||||
|
listener, err := net.Listen("tcp", "127.0.0.1:0")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("listen: %v", err)
|
||||||
|
}
|
||||||
|
server := grpc.NewServer()
|
||||||
|
fake = &browseFakeGalaxy{}
|
||||||
|
pb.RegisterGalaxyRepositoryServer(server, fake)
|
||||||
|
go func() { _ = server.Serve(listener) }()
|
||||||
|
t.Cleanup(func() {
|
||||||
|
server.Stop()
|
||||||
|
_ = listener.Close()
|
||||||
|
})
|
||||||
|
return listener.Addr().String(), fake
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestRunGalaxyBrowseTextTree verifies the galaxy-browse subcommand issues
|
||||||
|
// BrowseChildren for the root walk, eagerly expands one level when --depth is
|
||||||
|
// set, and renders an indented tree.
|
||||||
|
func TestRunGalaxyBrowseTextTree(t *testing.T) {
|
||||||
|
addr, _ := startBrowseFakeGalaxy(t)
|
||||||
|
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
args := []string{
|
||||||
|
"galaxy-browse",
|
||||||
|
"-endpoint", addr,
|
||||||
|
"-plaintext",
|
||||||
|
"-api-key", "test",
|
||||||
|
"-depth", "1",
|
||||||
|
}
|
||||||
|
if err := runWithIO(t.Context(), args, &stdout, &stderr); err != nil {
|
||||||
|
t.Fatalf("runWithIO() error = %v; stderr = %s", err, stderr.String())
|
||||||
|
}
|
||||||
|
out := stdout.String()
|
||||||
|
// Both roots present; the first root's eagerly-expanded child appears
|
||||||
|
// indented beneath it.
|
||||||
|
for _, want := range []string{"Area1", "Area2", "Tank"} {
|
||||||
|
if !strings.Contains(out, want) {
|
||||||
|
t.Fatalf("galaxy-browse text output missing %q; got:\n%s", want, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !strings.Contains(out, " ") {
|
||||||
|
t.Fatalf("galaxy-browse text output not indented for children; got:\n%s", out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestRunGalaxyBrowseJSON verifies the galaxy-browse subcommand emits valid
|
||||||
|
// nested JSON and forwards filter options onto the BrowseChildren request.
|
||||||
|
func TestRunGalaxyBrowseJSON(t *testing.T) {
|
||||||
|
addr, fake := startBrowseFakeGalaxy(t)
|
||||||
|
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
args := []string{
|
||||||
|
"galaxy-browse",
|
||||||
|
"-endpoint", addr,
|
||||||
|
"-plaintext",
|
||||||
|
"-api-key", "test",
|
||||||
|
"-depth", "1",
|
||||||
|
"-tag-name-glob", "Area%",
|
||||||
|
"-alarm-bearing-only",
|
||||||
|
"-json",
|
||||||
|
}
|
||||||
|
if err := runWithIO(t.Context(), args, &stdout, &stderr); err != nil {
|
||||||
|
t.Fatalf("runWithIO() error = %v; stderr = %s", err, stderr.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
var payload map[string]any
|
||||||
|
if err := json.Unmarshal(stdout.Bytes(), &payload); err != nil {
|
||||||
|
t.Fatalf("parse JSON: %v\noutput: %s", err, stdout.String())
|
||||||
|
}
|
||||||
|
if payload["command"] != "galaxy-browse" {
|
||||||
|
t.Fatalf("command = %v, want galaxy-browse", payload["command"])
|
||||||
|
}
|
||||||
|
nodes, ok := payload["nodes"].([]any)
|
||||||
|
if !ok || len(nodes) != 2 {
|
||||||
|
t.Fatalf("nodes = %v, want 2 root nodes", payload["nodes"])
|
||||||
|
}
|
||||||
|
// Filter fields must have reached the wire.
|
||||||
|
if got := fake.lastRequest.GetTagNameGlob(); got != "Area%" {
|
||||||
|
t.Fatalf("BrowseChildren TagNameGlob = %q, want %q", got, "Area%")
|
||||||
|
}
|
||||||
|
if !fake.lastRequest.GetAlarmBearingOnly() {
|
||||||
|
t.Fatalf("BrowseChildren AlarmBearingOnly = false, want true")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestRunGalaxyBrowseParentSingleLevel verifies that passing --parent fetches a
|
||||||
|
// single level of children for that parent via the parent-scoped request.
|
||||||
|
func TestRunGalaxyBrowseParentSingleLevel(t *testing.T) {
|
||||||
|
addr, fake := startBrowseFakeGalaxy(t)
|
||||||
|
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
args := []string{
|
||||||
|
"galaxy-browse",
|
||||||
|
"-endpoint", addr,
|
||||||
|
"-plaintext",
|
||||||
|
"-api-key", "test",
|
||||||
|
"-parent", "10",
|
||||||
|
}
|
||||||
|
if err := runWithIO(t.Context(), args, &stdout, &stderr); err != nil {
|
||||||
|
t.Fatalf("runWithIO() error = %v; stderr = %s", err, stderr.String())
|
||||||
|
}
|
||||||
|
if !strings.Contains(stdout.String(), "Tank") {
|
||||||
|
t.Fatalf("galaxy-browse -parent output missing child %q; got:\n%s", "Tank", stdout.String())
|
||||||
|
}
|
||||||
|
if got := fake.lastRequest.GetParentGobjectId(); got != 10 {
|
||||||
|
t.Fatalf("BrowseChildren ParentGobjectId = %d, want 10", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestRunBatchSkipsBlankLinesAndContinuesUntilEOF pins the Client.Go-027 fix:
|
||||||
|
// a blank line in the middle of a batch session must NOT terminate the loop —
|
||||||
|
// only stdin EOF ends the session.
|
||||||
|
func TestRunBatchSkipsBlankLinesAndContinuesUntilEOF(t *testing.T) {
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
|
||||||
|
// version -> blank -> version (a stray blank line in the middle of a
|
||||||
|
// programmatic session).
|
||||||
|
in := strings.NewReader("version --json\n\nversion --json\n")
|
||||||
|
if err := runBatch(t.Context(), in, &stdout, &stderr); err != nil {
|
||||||
|
t.Fatalf("runBatch() error = %v; stderr = %s", err, stderr.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
out := stdout.String()
|
||||||
|
// Both version commands must have produced a result before the EOR sentinel.
|
||||||
|
if count := strings.Count(out, batchEOR); count != 2 {
|
||||||
|
t.Fatalf("EOR sentinel count = %d, want 2 (one per command, blank line skipped); out = %q", count, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestRunBatchHandlesLongCommandLine pins the Client.Go-026 fix: a command
|
||||||
|
// line longer than the default bufio.Scanner token size (64 KiB) must not
|
||||||
|
// abort the batch session.
|
||||||
|
func TestRunBatchHandlesLongCommandLine(t *testing.T) {
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
|
||||||
|
// Build a single command line larger than 64 KiB. The command itself is
|
||||||
|
// invalid (no real session) but runBatch must still emit an EOR sentinel
|
||||||
|
// and continue to the next command rather than dropping the line on the
|
||||||
|
// floor with a bufio.ErrTooLong from the outer return.
|
||||||
|
huge := strings.Repeat("tag-with-a-reasonably-long-name-and-suffix,", 2000) + "trailing"
|
||||||
|
line := "subscribe-bulk -session-id none -items " + huge
|
||||||
|
if len(line) <= 64*1024 {
|
||||||
|
t.Fatalf("test setup error: long line length = %d, want > 64KiB", len(line))
|
||||||
|
}
|
||||||
|
in := strings.NewReader(line + "\nversion --json\n")
|
||||||
|
|
||||||
|
if err := runBatch(t.Context(), in, &stdout, &stderr); err != nil {
|
||||||
|
t.Fatalf("runBatch() error = %v; stderr = %s", err, stderr.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
out := stdout.String()
|
||||||
|
// Both commands must produce an EOR sentinel — the long line should be a
|
||||||
|
// per-command error (still emitted with EOR), then the version command
|
||||||
|
// should run normally.
|
||||||
|
if count := strings.Count(out, batchEOR); count != 2 {
|
||||||
|
t.Fatalf("EOR sentinel count = %d, want 2 (one per command, even when first is too long); out length = %d", count, len(out))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestRunBenchReadBulkRejectsNonPositiveDuration pins the -duration-seconds
|
||||||
|
// positivity guard so the bench window cannot be configured to zero/negative.
|
||||||
|
func TestRunBenchReadBulkRejectsNonPositiveDuration(t *testing.T) {
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
err := runWithIO(t.Context(), []string{"bench-read-bulk", "-duration-seconds", "0"}, &stdout, &stderr)
|
||||||
|
if err == nil || !strings.Contains(err.Error(), "duration-seconds must be positive") {
|
||||||
|
t.Fatalf("bench-read-bulk -duration-seconds 0 error = %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestRunStreamEventsRequiresSessionID pins the session-id guard so stream-events
|
||||||
|
// fails fast before dialing when no session id is supplied.
|
||||||
|
func TestRunStreamEventsRequiresSessionID(t *testing.T) {
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
err := runWithIO(t.Context(), []string{"stream-events", "-plaintext", "-api-key", "test"}, &stdout, &stderr)
|
||||||
|
if err == nil || !strings.Contains(err.Error(), "session-id is required") {
|
||||||
|
t.Fatalf("stream-events without -session-id error = %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestRunAdviseSupervisoryRequiresSessionID pins the session-id guard so
|
||||||
|
// advise-supervisory fails fast before dialing when no session id is supplied.
|
||||||
|
func TestRunAdviseSupervisoryRequiresSessionID(t *testing.T) {
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
err := runWithIO(t.Context(), []string{"advise-supervisory", "-plaintext", "-api-key", "test"}, &stdout, &stderr)
|
||||||
|
if err == nil || !strings.Contains(err.Error(), "session-id is required") {
|
||||||
|
t.Fatalf("advise-supervisory without -session-id error = %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestRunWriteBulkVariantRejectsMismatchedHandlesAndValues pins the len-mismatch
|
||||||
|
// guard so a write-bulk with unequal item-handles / values counts fails fast
|
||||||
|
// before any dial.
|
||||||
|
func TestRunWriteBulkVariantRejectsMismatchedHandlesAndValues(t *testing.T) {
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
err := runWithIO(t.Context(), []string{
|
||||||
|
"write-bulk",
|
||||||
|
"-session-id", "s1",
|
||||||
|
"-server-handle", "1",
|
||||||
|
"-item-handles", "1,2",
|
||||||
|
"-values", "10",
|
||||||
|
"-type", "int32",
|
||||||
|
"-plaintext",
|
||||||
|
"-api-key", "test",
|
||||||
|
}, &stdout, &stderr)
|
||||||
|
if err == nil || !strings.Contains(err.Error(), "does not match values count") {
|
||||||
|
t.Fatalf("write-bulk mismatched handles/values error = %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ Set-StrictMode -Version Latest
|
|||||||
$ErrorActionPreference = 'Stop'
|
$ErrorActionPreference = 'Stop'
|
||||||
|
|
||||||
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot '..\..')
|
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot '..\..')
|
||||||
$protoRoot = Join-Path $repoRoot 'src\MxGateway.Contracts\Protos'
|
$protoRoot = Join-Path $repoRoot 'src\ZB.MOM.WW.MxGateway.Contracts\Protos'
|
||||||
$outputRoot = Join-Path $PSScriptRoot 'internal\generated'
|
$outputRoot = Join-Path $PSScriptRoot 'internal\generated'
|
||||||
$modulePath = 'gitea.dohertylan.com/dohertj2/mxaccessgw/clients/go/internal/generated'
|
$modulePath = 'gitea.dohertylan.com/dohertj2/mxaccessgw/clients/go/internal/generated'
|
||||||
$protoc = 'C:\Users\dohertj2\AppData\Local\Microsoft\WinGet\Packages\Google.Protobuf_Microsoft.Winget.Source_8wekyb3d8bbwe\bin\protoc.exe'
|
$protoc = 'C:\Users\dohertj2\AppData\Local\Microsoft\WinGet\Packages\Google.Protobuf_Microsoft.Winget.Source_8wekyb3d8bbwe\bin\protoc.exe'
|
||||||
|
|||||||
@@ -687,18 +687,32 @@ func (x *GalaxyObject) GetAttributes() []*GalaxyAttribute {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GalaxyAttribute struct {
|
type GalaxyAttribute struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
AttributeName string `protobuf:"bytes,1,opt,name=attribute_name,json=attributeName,proto3" json:"attribute_name,omitempty"`
|
AttributeName string `protobuf:"bytes,1,opt,name=attribute_name,json=attributeName,proto3" json:"attribute_name,omitempty"`
|
||||||
FullTagReference string `protobuf:"bytes,2,opt,name=full_tag_reference,json=fullTagReference,proto3" json:"full_tag_reference,omitempty"`
|
FullTagReference string `protobuf:"bytes,2,opt,name=full_tag_reference,json=fullTagReference,proto3" json:"full_tag_reference,omitempty"`
|
||||||
MxDataType int32 `protobuf:"varint,3,opt,name=mx_data_type,json=mxDataType,proto3" json:"mx_data_type,omitempty"`
|
// Raw Galaxy SQL `dbo.data_type` identifier, passed through unchanged.
|
||||||
DataTypeName string `protobuf:"bytes,4,opt,name=data_type_name,json=dataTypeName,proto3" json:"data_type_name,omitempty"`
|
// This is NOT a member of `mxaccess_gateway.v1.MxDataType` — Galaxy's
|
||||||
IsArray bool `protobuf:"varint,5,opt,name=is_array,json=isArray,proto3" json:"is_array,omitempty"`
|
// type enumeration is distinct from MXAccess's wire data-type enum and
|
||||||
ArrayDimension int32 `protobuf:"varint,6,opt,name=array_dimension,json=arrayDimension,proto3" json:"array_dimension,omitempty"`
|
// the two must not be cast or compared. The GalaxyRepository service is
|
||||||
ArrayDimensionPresent bool `protobuf:"varint,7,opt,name=array_dimension_present,json=arrayDimensionPresent,proto3" json:"array_dimension_present,omitempty"`
|
// metadata-only and deliberately does not share types with
|
||||||
MxAttributeCategory int32 `protobuf:"varint,8,opt,name=mx_attribute_category,json=mxAttributeCategory,proto3" json:"mx_attribute_category,omitempty"`
|
// mxaccess_gateway.proto. See docs/GalaxyRepository.md.
|
||||||
SecurityClassification int32 `protobuf:"varint,9,opt,name=security_classification,json=securityClassification,proto3" json:"security_classification,omitempty"`
|
MxDataType int32 `protobuf:"varint,3,opt,name=mx_data_type,json=mxDataType,proto3" json:"mx_data_type,omitempty"`
|
||||||
IsHistorized bool `protobuf:"varint,10,opt,name=is_historized,json=isHistorized,proto3" json:"is_historized,omitempty"`
|
// Human-readable name from Galaxy's `dbo.data_type` table (e.g. "Float",
|
||||||
IsAlarm bool `protobuf:"varint,11,opt,name=is_alarm,json=isAlarm,proto3" json:"is_alarm,omitempty"`
|
// "Integer", "Boolean"). Free-form Galaxy text; not a stable enum.
|
||||||
|
DataTypeName string `protobuf:"bytes,4,opt,name=data_type_name,json=dataTypeName,proto3" json:"data_type_name,omitempty"`
|
||||||
|
IsArray bool `protobuf:"varint,5,opt,name=is_array,json=isArray,proto3" json:"is_array,omitempty"`
|
||||||
|
ArrayDimension int32 `protobuf:"varint,6,opt,name=array_dimension,json=arrayDimension,proto3" json:"array_dimension,omitempty"`
|
||||||
|
ArrayDimensionPresent bool `protobuf:"varint,7,opt,name=array_dimension_present,json=arrayDimensionPresent,proto3" json:"array_dimension_present,omitempty"`
|
||||||
|
// Raw Galaxy SQL attribute-category identifier, passed through unchanged.
|
||||||
|
// Galaxy-specific; not mapped to any gateway enum. See
|
||||||
|
// docs/GalaxyRepository.md.
|
||||||
|
MxAttributeCategory int32 `protobuf:"varint,8,opt,name=mx_attribute_category,json=mxAttributeCategory,proto3" json:"mx_attribute_category,omitempty"`
|
||||||
|
// Raw Galaxy SQL security-classification identifier, passed through
|
||||||
|
// unchanged. Galaxy-specific; not mapped to any gateway enum. See
|
||||||
|
// docs/GalaxyRepository.md.
|
||||||
|
SecurityClassification int32 `protobuf:"varint,9,opt,name=security_classification,json=securityClassification,proto3" json:"security_classification,omitempty"`
|
||||||
|
IsHistorized bool `protobuf:"varint,10,opt,name=is_historized,json=isHistorized,proto3" json:"is_historized,omitempty"`
|
||||||
|
IsAlarm bool `protobuf:"varint,11,opt,name=is_alarm,json=isAlarm,proto3" json:"is_alarm,omitempty"`
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
}
|
}
|
||||||
@@ -810,6 +824,260 @@ func (x *GalaxyAttribute) GetIsAlarm() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BrowseChildrenRequest struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
// Parent selector. Empty oneof returns root objects (parent_gobject_id == 0).
|
||||||
|
//
|
||||||
|
// Types that are valid to be assigned to Parent:
|
||||||
|
//
|
||||||
|
// *BrowseChildrenRequest_ParentGobjectId
|
||||||
|
// *BrowseChildrenRequest_ParentTagName
|
||||||
|
// *BrowseChildrenRequest_ParentContainedPath
|
||||||
|
Parent isBrowseChildrenRequest_Parent `protobuf_oneof:"parent"`
|
||||||
|
// Maximum number of direct children to return. Server default 500; cap 5000.
|
||||||
|
PageSize int32 `protobuf:"varint,4,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"`
|
||||||
|
// Opaque token returned by a previous BrowseChildren response. Bound to the
|
||||||
|
// cache sequence, parent selector, and the filter set; a mismatch returns
|
||||||
|
// InvalidArgument.
|
||||||
|
PageToken string `protobuf:"bytes,5,opt,name=page_token,json=pageToken,proto3" json:"page_token,omitempty"`
|
||||||
|
// --- Filter parity with DiscoverHierarchy. AND-combined. ---
|
||||||
|
CategoryIds []int32 `protobuf:"varint,6,rep,packed,name=category_ids,json=categoryIds,proto3" json:"category_ids,omitempty"`
|
||||||
|
TemplateChainContains []string `protobuf:"bytes,7,rep,name=template_chain_contains,json=templateChainContains,proto3" json:"template_chain_contains,omitempty"`
|
||||||
|
TagNameGlob string `protobuf:"bytes,8,opt,name=tag_name_glob,json=tagNameGlob,proto3" json:"tag_name_glob,omitempty"`
|
||||||
|
IncludeAttributes *bool `protobuf:"varint,9,opt,name=include_attributes,json=includeAttributes,proto3,oneof" json:"include_attributes,omitempty"`
|
||||||
|
AlarmBearingOnly bool `protobuf:"varint,10,opt,name=alarm_bearing_only,json=alarmBearingOnly,proto3" json:"alarm_bearing_only,omitempty"`
|
||||||
|
HistorizedOnly bool `protobuf:"varint,11,opt,name=historized_only,json=historizedOnly,proto3" json:"historized_only,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *BrowseChildrenRequest) Reset() {
|
||||||
|
*x = BrowseChildrenRequest{}
|
||||||
|
mi := &file_galaxy_repository_proto_msgTypes[10]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *BrowseChildrenRequest) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*BrowseChildrenRequest) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *BrowseChildrenRequest) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_galaxy_repository_proto_msgTypes[10]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use BrowseChildrenRequest.ProtoReflect.Descriptor instead.
|
||||||
|
func (*BrowseChildrenRequest) Descriptor() ([]byte, []int) {
|
||||||
|
return file_galaxy_repository_proto_rawDescGZIP(), []int{10}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *BrowseChildrenRequest) GetParent() isBrowseChildrenRequest_Parent {
|
||||||
|
if x != nil {
|
||||||
|
return x.Parent
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *BrowseChildrenRequest) GetParentGobjectId() int32 {
|
||||||
|
if x != nil {
|
||||||
|
if x, ok := x.Parent.(*BrowseChildrenRequest_ParentGobjectId); ok {
|
||||||
|
return x.ParentGobjectId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *BrowseChildrenRequest) GetParentTagName() string {
|
||||||
|
if x != nil {
|
||||||
|
if x, ok := x.Parent.(*BrowseChildrenRequest_ParentTagName); ok {
|
||||||
|
return x.ParentTagName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *BrowseChildrenRequest) GetParentContainedPath() string {
|
||||||
|
if x != nil {
|
||||||
|
if x, ok := x.Parent.(*BrowseChildrenRequest_ParentContainedPath); ok {
|
||||||
|
return x.ParentContainedPath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *BrowseChildrenRequest) GetPageSize() int32 {
|
||||||
|
if x != nil {
|
||||||
|
return x.PageSize
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *BrowseChildrenRequest) GetPageToken() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.PageToken
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *BrowseChildrenRequest) GetCategoryIds() []int32 {
|
||||||
|
if x != nil {
|
||||||
|
return x.CategoryIds
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *BrowseChildrenRequest) GetTemplateChainContains() []string {
|
||||||
|
if x != nil {
|
||||||
|
return x.TemplateChainContains
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *BrowseChildrenRequest) GetTagNameGlob() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.TagNameGlob
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *BrowseChildrenRequest) GetIncludeAttributes() bool {
|
||||||
|
if x != nil && x.IncludeAttributes != nil {
|
||||||
|
return *x.IncludeAttributes
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *BrowseChildrenRequest) GetAlarmBearingOnly() bool {
|
||||||
|
if x != nil {
|
||||||
|
return x.AlarmBearingOnly
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *BrowseChildrenRequest) GetHistorizedOnly() bool {
|
||||||
|
if x != nil {
|
||||||
|
return x.HistorizedOnly
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
type isBrowseChildrenRequest_Parent interface {
|
||||||
|
isBrowseChildrenRequest_Parent()
|
||||||
|
}
|
||||||
|
|
||||||
|
type BrowseChildrenRequest_ParentGobjectId struct {
|
||||||
|
ParentGobjectId int32 `protobuf:"varint,1,opt,name=parent_gobject_id,json=parentGobjectId,proto3,oneof"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type BrowseChildrenRequest_ParentTagName struct {
|
||||||
|
ParentTagName string `protobuf:"bytes,2,opt,name=parent_tag_name,json=parentTagName,proto3,oneof"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type BrowseChildrenRequest_ParentContainedPath struct {
|
||||||
|
ParentContainedPath string `protobuf:"bytes,3,opt,name=parent_contained_path,json=parentContainedPath,proto3,oneof"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*BrowseChildrenRequest_ParentGobjectId) isBrowseChildrenRequest_Parent() {}
|
||||||
|
|
||||||
|
func (*BrowseChildrenRequest_ParentTagName) isBrowseChildrenRequest_Parent() {}
|
||||||
|
|
||||||
|
func (*BrowseChildrenRequest_ParentContainedPath) isBrowseChildrenRequest_Parent() {}
|
||||||
|
|
||||||
|
type BrowseChildrenReply struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
// Direct children matching the filter, sorted areas-first then by
|
||||||
|
// case-insensitive display name (same order as the dashboard tree).
|
||||||
|
Children []*GalaxyObject `protobuf:"bytes,1,rep,name=children,proto3" json:"children,omitempty"`
|
||||||
|
// Non-empty when another page of siblings is available.
|
||||||
|
NextPageToken string `protobuf:"bytes,2,opt,name=next_page_token,json=nextPageToken,proto3" json:"next_page_token,omitempty"`
|
||||||
|
// Total matching direct children of the parent (post-filter).
|
||||||
|
TotalChildCount int32 `protobuf:"varint,3,opt,name=total_child_count,json=totalChildCount,proto3" json:"total_child_count,omitempty"`
|
||||||
|
// Parallel array, indexed with `children`. True when the child has at least
|
||||||
|
// one matching descendant under the same filter set. Lets a UI choose
|
||||||
|
// whether to draw an expand triangle without an extra round trip.
|
||||||
|
ChildHasChildren []bool `protobuf:"varint,4,rep,packed,name=child_has_children,json=childHasChildren,proto3" json:"child_has_children,omitempty"`
|
||||||
|
// Cache sequence this reply was projected from. Clients may pass it back as
|
||||||
|
// part of the page_token contract. Mismatch on the next page -> InvalidArgument.
|
||||||
|
CacheSequence uint64 `protobuf:"varint,5,opt,name=cache_sequence,json=cacheSequence,proto3" json:"cache_sequence,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *BrowseChildrenReply) Reset() {
|
||||||
|
*x = BrowseChildrenReply{}
|
||||||
|
mi := &file_galaxy_repository_proto_msgTypes[11]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *BrowseChildrenReply) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*BrowseChildrenReply) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *BrowseChildrenReply) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_galaxy_repository_proto_msgTypes[11]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use BrowseChildrenReply.ProtoReflect.Descriptor instead.
|
||||||
|
func (*BrowseChildrenReply) Descriptor() ([]byte, []int) {
|
||||||
|
return file_galaxy_repository_proto_rawDescGZIP(), []int{11}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *BrowseChildrenReply) GetChildren() []*GalaxyObject {
|
||||||
|
if x != nil {
|
||||||
|
return x.Children
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *BrowseChildrenReply) GetNextPageToken() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.NextPageToken
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *BrowseChildrenReply) GetTotalChildCount() int32 {
|
||||||
|
if x != nil {
|
||||||
|
return x.TotalChildCount
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *BrowseChildrenReply) GetChildHasChildren() []bool {
|
||||||
|
if x != nil {
|
||||||
|
return x.ChildHasChildren
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *BrowseChildrenReply) GetCacheSequence() uint64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.CacheSequence
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
var File_galaxy_repository_proto protoreflect.FileDescriptor
|
var File_galaxy_repository_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
const file_galaxy_repository_proto_rawDesc = "" +
|
const file_galaxy_repository_proto_rawDesc = "" +
|
||||||
@@ -883,12 +1151,35 @@ const file_galaxy_repository_proto_rawDesc = "" +
|
|||||||
"\x17security_classification\x18\t \x01(\x05R\x16securityClassification\x12#\n" +
|
"\x17security_classification\x18\t \x01(\x05R\x16securityClassification\x12#\n" +
|
||||||
"\ris_historized\x18\n" +
|
"\ris_historized\x18\n" +
|
||||||
" \x01(\bR\fisHistorized\x12\x19\n" +
|
" \x01(\bR\fisHistorized\x12\x19\n" +
|
||||||
"\bis_alarm\x18\v \x01(\bR\aisAlarm2\xcc\x03\n" +
|
"\bis_alarm\x18\v \x01(\bR\aisAlarm\"\x8c\x04\n" +
|
||||||
|
"\x15BrowseChildrenRequest\x12,\n" +
|
||||||
|
"\x11parent_gobject_id\x18\x01 \x01(\x05H\x00R\x0fparentGobjectId\x12(\n" +
|
||||||
|
"\x0fparent_tag_name\x18\x02 \x01(\tH\x00R\rparentTagName\x124\n" +
|
||||||
|
"\x15parent_contained_path\x18\x03 \x01(\tH\x00R\x13parentContainedPath\x12\x1b\n" +
|
||||||
|
"\tpage_size\x18\x04 \x01(\x05R\bpageSize\x12\x1d\n" +
|
||||||
|
"\n" +
|
||||||
|
"page_token\x18\x05 \x01(\tR\tpageToken\x12!\n" +
|
||||||
|
"\fcategory_ids\x18\x06 \x03(\x05R\vcategoryIds\x126\n" +
|
||||||
|
"\x17template_chain_contains\x18\a \x03(\tR\x15templateChainContains\x12\"\n" +
|
||||||
|
"\rtag_name_glob\x18\b \x01(\tR\vtagNameGlob\x122\n" +
|
||||||
|
"\x12include_attributes\x18\t \x01(\bH\x01R\x11includeAttributes\x88\x01\x01\x12,\n" +
|
||||||
|
"\x12alarm_bearing_only\x18\n" +
|
||||||
|
" \x01(\bR\x10alarmBearingOnly\x12'\n" +
|
||||||
|
"\x0fhistorized_only\x18\v \x01(\bR\x0ehistorizedOnlyB\b\n" +
|
||||||
|
"\x06parentB\x15\n" +
|
||||||
|
"\x13_include_attributes\"\xfe\x01\n" +
|
||||||
|
"\x13BrowseChildrenReply\x12>\n" +
|
||||||
|
"\bchildren\x18\x01 \x03(\v2\".galaxy_repository.v1.GalaxyObjectR\bchildren\x12&\n" +
|
||||||
|
"\x0fnext_page_token\x18\x02 \x01(\tR\rnextPageToken\x12*\n" +
|
||||||
|
"\x11total_child_count\x18\x03 \x01(\x05R\x0ftotalChildCount\x12,\n" +
|
||||||
|
"\x12child_has_children\x18\x04 \x03(\bR\x10childHasChildren\x12%\n" +
|
||||||
|
"\x0ecache_sequence\x18\x05 \x01(\x04R\rcacheSequence2\xb6\x04\n" +
|
||||||
"\x10GalaxyRepository\x12h\n" +
|
"\x10GalaxyRepository\x12h\n" +
|
||||||
"\x0eTestConnection\x12+.galaxy_repository.v1.TestConnectionRequest\x1a).galaxy_repository.v1.TestConnectionReply\x12q\n" +
|
"\x0eTestConnection\x12+.galaxy_repository.v1.TestConnectionRequest\x1a).galaxy_repository.v1.TestConnectionReply\x12q\n" +
|
||||||
"\x11GetLastDeployTime\x12..galaxy_repository.v1.GetLastDeployTimeRequest\x1a,.galaxy_repository.v1.GetLastDeployTimeReply\x12q\n" +
|
"\x11GetLastDeployTime\x12..galaxy_repository.v1.GetLastDeployTimeRequest\x1a,.galaxy_repository.v1.GetLastDeployTimeReply\x12q\n" +
|
||||||
"\x11DiscoverHierarchy\x12..galaxy_repository.v1.DiscoverHierarchyRequest\x1a,.galaxy_repository.v1.DiscoverHierarchyReply\x12h\n" +
|
"\x11DiscoverHierarchy\x12..galaxy_repository.v1.DiscoverHierarchyRequest\x1a,.galaxy_repository.v1.DiscoverHierarchyReply\x12h\n" +
|
||||||
"\x11WatchDeployEvents\x12..galaxy_repository.v1.WatchDeployEventsRequest\x1a!.galaxy_repository.v1.DeployEvent0\x01B#\xaa\x02 MxGateway.Contracts.Proto.Galaxyb\x06proto3"
|
"\x11WatchDeployEvents\x12..galaxy_repository.v1.WatchDeployEventsRequest\x1a!.galaxy_repository.v1.DeployEvent0\x01\x12h\n" +
|
||||||
|
"\x0eBrowseChildren\x12+.galaxy_repository.v1.BrowseChildrenRequest\x1a).galaxy_repository.v1.BrowseChildrenReplyB-\xaa\x02*ZB.MOM.WW.MxGateway.Contracts.Proto.Galaxyb\x06proto3"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
file_galaxy_repository_proto_rawDescOnce sync.Once
|
file_galaxy_repository_proto_rawDescOnce sync.Once
|
||||||
@@ -902,7 +1193,7 @@ func file_galaxy_repository_proto_rawDescGZIP() []byte {
|
|||||||
return file_galaxy_repository_proto_rawDescData
|
return file_galaxy_repository_proto_rawDescData
|
||||||
}
|
}
|
||||||
|
|
||||||
var file_galaxy_repository_proto_msgTypes = make([]protoimpl.MessageInfo, 10)
|
var file_galaxy_repository_proto_msgTypes = make([]protoimpl.MessageInfo, 12)
|
||||||
var file_galaxy_repository_proto_goTypes = []any{
|
var file_galaxy_repository_proto_goTypes = []any{
|
||||||
(*TestConnectionRequest)(nil), // 0: galaxy_repository.v1.TestConnectionRequest
|
(*TestConnectionRequest)(nil), // 0: galaxy_repository.v1.TestConnectionRequest
|
||||||
(*TestConnectionReply)(nil), // 1: galaxy_repository.v1.TestConnectionReply
|
(*TestConnectionReply)(nil), // 1: galaxy_repository.v1.TestConnectionReply
|
||||||
@@ -914,30 +1205,35 @@ var file_galaxy_repository_proto_goTypes = []any{
|
|||||||
(*DeployEvent)(nil), // 7: galaxy_repository.v1.DeployEvent
|
(*DeployEvent)(nil), // 7: galaxy_repository.v1.DeployEvent
|
||||||
(*GalaxyObject)(nil), // 8: galaxy_repository.v1.GalaxyObject
|
(*GalaxyObject)(nil), // 8: galaxy_repository.v1.GalaxyObject
|
||||||
(*GalaxyAttribute)(nil), // 9: galaxy_repository.v1.GalaxyAttribute
|
(*GalaxyAttribute)(nil), // 9: galaxy_repository.v1.GalaxyAttribute
|
||||||
(*timestamppb.Timestamp)(nil), // 10: google.protobuf.Timestamp
|
(*BrowseChildrenRequest)(nil), // 10: galaxy_repository.v1.BrowseChildrenRequest
|
||||||
(*wrapperspb.Int32Value)(nil), // 11: google.protobuf.Int32Value
|
(*BrowseChildrenReply)(nil), // 11: galaxy_repository.v1.BrowseChildrenReply
|
||||||
|
(*timestamppb.Timestamp)(nil), // 12: google.protobuf.Timestamp
|
||||||
|
(*wrapperspb.Int32Value)(nil), // 13: google.protobuf.Int32Value
|
||||||
}
|
}
|
||||||
var file_galaxy_repository_proto_depIdxs = []int32{
|
var file_galaxy_repository_proto_depIdxs = []int32{
|
||||||
10, // 0: galaxy_repository.v1.GetLastDeployTimeReply.time_of_last_deploy:type_name -> google.protobuf.Timestamp
|
12, // 0: galaxy_repository.v1.GetLastDeployTimeReply.time_of_last_deploy:type_name -> google.protobuf.Timestamp
|
||||||
11, // 1: galaxy_repository.v1.DiscoverHierarchyRequest.max_depth:type_name -> google.protobuf.Int32Value
|
13, // 1: galaxy_repository.v1.DiscoverHierarchyRequest.max_depth:type_name -> google.protobuf.Int32Value
|
||||||
8, // 2: galaxy_repository.v1.DiscoverHierarchyReply.objects:type_name -> galaxy_repository.v1.GalaxyObject
|
8, // 2: galaxy_repository.v1.DiscoverHierarchyReply.objects:type_name -> galaxy_repository.v1.GalaxyObject
|
||||||
10, // 3: galaxy_repository.v1.WatchDeployEventsRequest.last_seen_deploy_time:type_name -> google.protobuf.Timestamp
|
12, // 3: galaxy_repository.v1.WatchDeployEventsRequest.last_seen_deploy_time:type_name -> google.protobuf.Timestamp
|
||||||
10, // 4: galaxy_repository.v1.DeployEvent.observed_at:type_name -> google.protobuf.Timestamp
|
12, // 4: galaxy_repository.v1.DeployEvent.observed_at:type_name -> google.protobuf.Timestamp
|
||||||
10, // 5: galaxy_repository.v1.DeployEvent.time_of_last_deploy:type_name -> google.protobuf.Timestamp
|
12, // 5: galaxy_repository.v1.DeployEvent.time_of_last_deploy:type_name -> google.protobuf.Timestamp
|
||||||
9, // 6: galaxy_repository.v1.GalaxyObject.attributes:type_name -> galaxy_repository.v1.GalaxyAttribute
|
9, // 6: galaxy_repository.v1.GalaxyObject.attributes:type_name -> galaxy_repository.v1.GalaxyAttribute
|
||||||
0, // 7: galaxy_repository.v1.GalaxyRepository.TestConnection:input_type -> galaxy_repository.v1.TestConnectionRequest
|
8, // 7: galaxy_repository.v1.BrowseChildrenReply.children:type_name -> galaxy_repository.v1.GalaxyObject
|
||||||
2, // 8: galaxy_repository.v1.GalaxyRepository.GetLastDeployTime:input_type -> galaxy_repository.v1.GetLastDeployTimeRequest
|
0, // 8: galaxy_repository.v1.GalaxyRepository.TestConnection:input_type -> galaxy_repository.v1.TestConnectionRequest
|
||||||
4, // 9: galaxy_repository.v1.GalaxyRepository.DiscoverHierarchy:input_type -> galaxy_repository.v1.DiscoverHierarchyRequest
|
2, // 9: galaxy_repository.v1.GalaxyRepository.GetLastDeployTime:input_type -> galaxy_repository.v1.GetLastDeployTimeRequest
|
||||||
6, // 10: galaxy_repository.v1.GalaxyRepository.WatchDeployEvents:input_type -> galaxy_repository.v1.WatchDeployEventsRequest
|
4, // 10: galaxy_repository.v1.GalaxyRepository.DiscoverHierarchy:input_type -> galaxy_repository.v1.DiscoverHierarchyRequest
|
||||||
1, // 11: galaxy_repository.v1.GalaxyRepository.TestConnection:output_type -> galaxy_repository.v1.TestConnectionReply
|
6, // 11: galaxy_repository.v1.GalaxyRepository.WatchDeployEvents:input_type -> galaxy_repository.v1.WatchDeployEventsRequest
|
||||||
3, // 12: galaxy_repository.v1.GalaxyRepository.GetLastDeployTime:output_type -> galaxy_repository.v1.GetLastDeployTimeReply
|
10, // 12: galaxy_repository.v1.GalaxyRepository.BrowseChildren:input_type -> galaxy_repository.v1.BrowseChildrenRequest
|
||||||
5, // 13: galaxy_repository.v1.GalaxyRepository.DiscoverHierarchy:output_type -> galaxy_repository.v1.DiscoverHierarchyReply
|
1, // 13: galaxy_repository.v1.GalaxyRepository.TestConnection:output_type -> galaxy_repository.v1.TestConnectionReply
|
||||||
7, // 14: galaxy_repository.v1.GalaxyRepository.WatchDeployEvents:output_type -> galaxy_repository.v1.DeployEvent
|
3, // 14: galaxy_repository.v1.GalaxyRepository.GetLastDeployTime:output_type -> galaxy_repository.v1.GetLastDeployTimeReply
|
||||||
11, // [11:15] is the sub-list for method output_type
|
5, // 15: galaxy_repository.v1.GalaxyRepository.DiscoverHierarchy:output_type -> galaxy_repository.v1.DiscoverHierarchyReply
|
||||||
7, // [7:11] is the sub-list for method input_type
|
7, // 16: galaxy_repository.v1.GalaxyRepository.WatchDeployEvents:output_type -> galaxy_repository.v1.DeployEvent
|
||||||
7, // [7:7] is the sub-list for extension type_name
|
11, // 17: galaxy_repository.v1.GalaxyRepository.BrowseChildren:output_type -> galaxy_repository.v1.BrowseChildrenReply
|
||||||
7, // [7:7] is the sub-list for extension extendee
|
13, // [13:18] is the sub-list for method output_type
|
||||||
0, // [0:7] is the sub-list for field type_name
|
8, // [8:13] is the sub-list for method input_type
|
||||||
|
8, // [8:8] is the sub-list for extension type_name
|
||||||
|
8, // [8:8] is the sub-list for extension extendee
|
||||||
|
0, // [0:8] is the sub-list for field type_name
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { file_galaxy_repository_proto_init() }
|
func init() { file_galaxy_repository_proto_init() }
|
||||||
@@ -950,13 +1246,18 @@ func file_galaxy_repository_proto_init() {
|
|||||||
(*DiscoverHierarchyRequest_RootTagName)(nil),
|
(*DiscoverHierarchyRequest_RootTagName)(nil),
|
||||||
(*DiscoverHierarchyRequest_RootContainedPath)(nil),
|
(*DiscoverHierarchyRequest_RootContainedPath)(nil),
|
||||||
}
|
}
|
||||||
|
file_galaxy_repository_proto_msgTypes[10].OneofWrappers = []any{
|
||||||
|
(*BrowseChildrenRequest_ParentGobjectId)(nil),
|
||||||
|
(*BrowseChildrenRequest_ParentTagName)(nil),
|
||||||
|
(*BrowseChildrenRequest_ParentContainedPath)(nil),
|
||||||
|
}
|
||||||
type x struct{}
|
type x struct{}
|
||||||
out := protoimpl.TypeBuilder{
|
out := protoimpl.TypeBuilder{
|
||||||
File: protoimpl.DescBuilder{
|
File: protoimpl.DescBuilder{
|
||||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||||
RawDescriptor: unsafe.Slice(unsafe.StringData(file_galaxy_repository_proto_rawDesc), len(file_galaxy_repository_proto_rawDesc)),
|
RawDescriptor: unsafe.Slice(unsafe.StringData(file_galaxy_repository_proto_rawDesc), len(file_galaxy_repository_proto_rawDesc)),
|
||||||
NumEnums: 0,
|
NumEnums: 0,
|
||||||
NumMessages: 10,
|
NumMessages: 12,
|
||||||
NumExtensions: 0,
|
NumExtensions: 0,
|
||||||
NumServices: 1,
|
NumServices: 1,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// - protoc-gen-go-grpc v1.6.1
|
// - protoc-gen-go-grpc v1.6.2
|
||||||
// - protoc v7.34.1
|
// - protoc v7.34.1
|
||||||
// source: galaxy_repository.proto
|
// source: galaxy_repository.proto
|
||||||
|
|
||||||
@@ -23,6 +23,7 @@ const (
|
|||||||
GalaxyRepository_GetLastDeployTime_FullMethodName = "/galaxy_repository.v1.GalaxyRepository/GetLastDeployTime"
|
GalaxyRepository_GetLastDeployTime_FullMethodName = "/galaxy_repository.v1.GalaxyRepository/GetLastDeployTime"
|
||||||
GalaxyRepository_DiscoverHierarchy_FullMethodName = "/galaxy_repository.v1.GalaxyRepository/DiscoverHierarchy"
|
GalaxyRepository_DiscoverHierarchy_FullMethodName = "/galaxy_repository.v1.GalaxyRepository/DiscoverHierarchy"
|
||||||
GalaxyRepository_WatchDeployEvents_FullMethodName = "/galaxy_repository.v1.GalaxyRepository/WatchDeployEvents"
|
GalaxyRepository_WatchDeployEvents_FullMethodName = "/galaxy_repository.v1.GalaxyRepository/WatchDeployEvents"
|
||||||
|
GalaxyRepository_BrowseChildren_FullMethodName = "/galaxy_repository.v1.GalaxyRepository/BrowseChildren"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GalaxyRepositoryClient is the client API for GalaxyRepository service.
|
// GalaxyRepositoryClient is the client API for GalaxyRepository service.
|
||||||
@@ -44,6 +45,11 @@ type GalaxyRepositoryClient interface {
|
|||||||
// increasing per server start; gaps indicate the per-subscriber buffer dropped
|
// increasing per server start; gaps indicate the per-subscriber buffer dropped
|
||||||
// older events because the client was too slow.
|
// older events because the client was too slow.
|
||||||
WatchDeployEvents(ctx context.Context, in *WatchDeployEventsRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[DeployEvent], error)
|
WatchDeployEvents(ctx context.Context, in *WatchDeployEventsRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[DeployEvent], error)
|
||||||
|
// Returns the direct children of a parent object (or the root objects when
|
||||||
|
// `parent` is unset). Designed for OPC UA-style lazy expand: clients walk
|
||||||
|
// one level at a time instead of paging the full hierarchy. Filters mirror
|
||||||
|
// DiscoverHierarchy exactly. Backed by the same shared hierarchy cache.
|
||||||
|
BrowseChildren(ctx context.Context, in *BrowseChildrenRequest, opts ...grpc.CallOption) (*BrowseChildrenReply, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type galaxyRepositoryClient struct {
|
type galaxyRepositoryClient struct {
|
||||||
@@ -103,6 +109,16 @@ func (c *galaxyRepositoryClient) WatchDeployEvents(ctx context.Context, in *Watc
|
|||||||
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
|
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
|
||||||
type GalaxyRepository_WatchDeployEventsClient = grpc.ServerStreamingClient[DeployEvent]
|
type GalaxyRepository_WatchDeployEventsClient = grpc.ServerStreamingClient[DeployEvent]
|
||||||
|
|
||||||
|
func (c *galaxyRepositoryClient) BrowseChildren(ctx context.Context, in *BrowseChildrenRequest, opts ...grpc.CallOption) (*BrowseChildrenReply, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(BrowseChildrenReply)
|
||||||
|
err := c.cc.Invoke(ctx, GalaxyRepository_BrowseChildren_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GalaxyRepositoryServer is the server API for GalaxyRepository service.
|
// GalaxyRepositoryServer is the server API for GalaxyRepository service.
|
||||||
// All implementations must embed UnimplementedGalaxyRepositoryServer
|
// All implementations must embed UnimplementedGalaxyRepositoryServer
|
||||||
// for forward compatibility.
|
// for forward compatibility.
|
||||||
@@ -122,6 +138,11 @@ type GalaxyRepositoryServer interface {
|
|||||||
// increasing per server start; gaps indicate the per-subscriber buffer dropped
|
// increasing per server start; gaps indicate the per-subscriber buffer dropped
|
||||||
// older events because the client was too slow.
|
// older events because the client was too slow.
|
||||||
WatchDeployEvents(*WatchDeployEventsRequest, grpc.ServerStreamingServer[DeployEvent]) error
|
WatchDeployEvents(*WatchDeployEventsRequest, grpc.ServerStreamingServer[DeployEvent]) error
|
||||||
|
// Returns the direct children of a parent object (or the root objects when
|
||||||
|
// `parent` is unset). Designed for OPC UA-style lazy expand: clients walk
|
||||||
|
// one level at a time instead of paging the full hierarchy. Filters mirror
|
||||||
|
// DiscoverHierarchy exactly. Backed by the same shared hierarchy cache.
|
||||||
|
BrowseChildren(context.Context, *BrowseChildrenRequest) (*BrowseChildrenReply, error)
|
||||||
mustEmbedUnimplementedGalaxyRepositoryServer()
|
mustEmbedUnimplementedGalaxyRepositoryServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,6 +165,9 @@ func (UnimplementedGalaxyRepositoryServer) DiscoverHierarchy(context.Context, *D
|
|||||||
func (UnimplementedGalaxyRepositoryServer) WatchDeployEvents(*WatchDeployEventsRequest, grpc.ServerStreamingServer[DeployEvent]) error {
|
func (UnimplementedGalaxyRepositoryServer) WatchDeployEvents(*WatchDeployEventsRequest, grpc.ServerStreamingServer[DeployEvent]) error {
|
||||||
return status.Error(codes.Unimplemented, "method WatchDeployEvents not implemented")
|
return status.Error(codes.Unimplemented, "method WatchDeployEvents not implemented")
|
||||||
}
|
}
|
||||||
|
func (UnimplementedGalaxyRepositoryServer) BrowseChildren(context.Context, *BrowseChildrenRequest) (*BrowseChildrenReply, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method BrowseChildren not implemented")
|
||||||
|
}
|
||||||
func (UnimplementedGalaxyRepositoryServer) mustEmbedUnimplementedGalaxyRepositoryServer() {}
|
func (UnimplementedGalaxyRepositoryServer) mustEmbedUnimplementedGalaxyRepositoryServer() {}
|
||||||
func (UnimplementedGalaxyRepositoryServer) testEmbeddedByValue() {}
|
func (UnimplementedGalaxyRepositoryServer) testEmbeddedByValue() {}
|
||||||
|
|
||||||
@@ -230,6 +254,24 @@ func _GalaxyRepository_WatchDeployEvents_Handler(srv interface{}, stream grpc.Se
|
|||||||
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
|
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
|
||||||
type GalaxyRepository_WatchDeployEventsServer = grpc.ServerStreamingServer[DeployEvent]
|
type GalaxyRepository_WatchDeployEventsServer = grpc.ServerStreamingServer[DeployEvent]
|
||||||
|
|
||||||
|
func _GalaxyRepository_BrowseChildren_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(BrowseChildrenRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(GalaxyRepositoryServer).BrowseChildren(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: GalaxyRepository_BrowseChildren_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(GalaxyRepositoryServer).BrowseChildren(ctx, req.(*BrowseChildrenRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
// GalaxyRepository_ServiceDesc is the grpc.ServiceDesc for GalaxyRepository service.
|
// GalaxyRepository_ServiceDesc is the grpc.ServiceDesc for GalaxyRepository service.
|
||||||
// It's only intended for direct use with grpc.RegisterService,
|
// It's only intended for direct use with grpc.RegisterService,
|
||||||
// and not to be introspected or modified (even as a copy)
|
// and not to be introspected or modified (even as a copy)
|
||||||
@@ -249,6 +291,10 @@ var GalaxyRepository_ServiceDesc = grpc.ServiceDesc{
|
|||||||
MethodName: "DiscoverHierarchy",
|
MethodName: "DiscoverHierarchy",
|
||||||
Handler: _GalaxyRepository_DiscoverHierarchy_Handler,
|
Handler: _GalaxyRepository_DiscoverHierarchy_Handler,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
MethodName: "BrowseChildren",
|
||||||
|
Handler: _GalaxyRepository_BrowseChildren_Handler,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Streams: []grpc.StreamDesc{
|
Streams: []grpc.StreamDesc{
|
||||||
{
|
{
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// - protoc-gen-go-grpc v1.6.1
|
// - protoc-gen-go-grpc v1.6.2
|
||||||
// - protoc v7.34.1
|
// - protoc v7.34.1
|
||||||
// source: mxaccess_gateway.proto
|
// source: mxaccess_gateway.proto
|
||||||
|
|
||||||
@@ -24,6 +24,7 @@ const (
|
|||||||
MxAccessGateway_Invoke_FullMethodName = "/mxaccess_gateway.v1.MxAccessGateway/Invoke"
|
MxAccessGateway_Invoke_FullMethodName = "/mxaccess_gateway.v1.MxAccessGateway/Invoke"
|
||||||
MxAccessGateway_StreamEvents_FullMethodName = "/mxaccess_gateway.v1.MxAccessGateway/StreamEvents"
|
MxAccessGateway_StreamEvents_FullMethodName = "/mxaccess_gateway.v1.MxAccessGateway/StreamEvents"
|
||||||
MxAccessGateway_AcknowledgeAlarm_FullMethodName = "/mxaccess_gateway.v1.MxAccessGateway/AcknowledgeAlarm"
|
MxAccessGateway_AcknowledgeAlarm_FullMethodName = "/mxaccess_gateway.v1.MxAccessGateway/AcknowledgeAlarm"
|
||||||
|
MxAccessGateway_StreamAlarms_FullMethodName = "/mxaccess_gateway.v1.MxAccessGateway/StreamAlarms"
|
||||||
MxAccessGateway_QueryActiveAlarms_FullMethodName = "/mxaccess_gateway.v1.MxAccessGateway/QueryActiveAlarms"
|
MxAccessGateway_QueryActiveAlarms_FullMethodName = "/mxaccess_gateway.v1.MxAccessGateway/QueryActiveAlarms"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -38,6 +39,20 @@ type MxAccessGatewayClient interface {
|
|||||||
Invoke(ctx context.Context, in *MxCommandRequest, opts ...grpc.CallOption) (*MxCommandReply, error)
|
Invoke(ctx context.Context, in *MxCommandRequest, opts ...grpc.CallOption) (*MxCommandReply, error)
|
||||||
StreamEvents(ctx context.Context, in *StreamEventsRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[MxEvent], error)
|
StreamEvents(ctx context.Context, in *StreamEventsRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[MxEvent], error)
|
||||||
AcknowledgeAlarm(ctx context.Context, in *AcknowledgeAlarmRequest, opts ...grpc.CallOption) (*AcknowledgeAlarmReply, error)
|
AcknowledgeAlarm(ctx context.Context, in *AcknowledgeAlarmRequest, opts ...grpc.CallOption) (*AcknowledgeAlarmReply, error)
|
||||||
|
// Session-less central alarm feed. The stream opens with the current
|
||||||
|
// active-alarm snapshot (one `active_alarm` per alarm), then a single
|
||||||
|
// `snapshot_complete`, then a `transition` for every subsequent change.
|
||||||
|
// Served by the gateway's always-on alarm monitor; any number of clients
|
||||||
|
// fan out from the single monitor without opening a worker session.
|
||||||
|
StreamAlarms(ctx context.Context, in *StreamAlarmsRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[AlarmFeedMessage], error)
|
||||||
|
// Point-in-time snapshot of the currently-active alarm set served from the
|
||||||
|
// gateway's always-on alarm monitor cache (session-less). Used after a
|
||||||
|
// reconnect to seed Part 9 client state, or to reconcile alarms that may
|
||||||
|
// have been missed during a transport blip. Streamed so callers can
|
||||||
|
// begin processing without buffering the full set.
|
||||||
|
// `QueryActiveAlarmsRequest.alarm_filter_prefix` optionally narrows the
|
||||||
|
// snapshot to alarms whose `alarm_full_reference` starts with the given
|
||||||
|
// prefix; an empty prefix returns the full set.
|
||||||
QueryActiveAlarms(ctx context.Context, in *QueryActiveAlarmsRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[ActiveAlarmSnapshot], error)
|
QueryActiveAlarms(ctx context.Context, in *QueryActiveAlarmsRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[ActiveAlarmSnapshot], error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,9 +123,28 @@ func (c *mxAccessGatewayClient) AcknowledgeAlarm(ctx context.Context, in *Acknow
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *mxAccessGatewayClient) StreamAlarms(ctx context.Context, in *StreamAlarmsRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[AlarmFeedMessage], error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
stream, err := c.cc.NewStream(ctx, &MxAccessGateway_ServiceDesc.Streams[1], MxAccessGateway_StreamAlarms_FullMethodName, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
x := &grpc.GenericClientStream[StreamAlarmsRequest, AlarmFeedMessage]{ClientStream: stream}
|
||||||
|
if err := x.ClientStream.SendMsg(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := x.ClientStream.CloseSend(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return x, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
|
||||||
|
type MxAccessGateway_StreamAlarmsClient = grpc.ServerStreamingClient[AlarmFeedMessage]
|
||||||
|
|
||||||
func (c *mxAccessGatewayClient) QueryActiveAlarms(ctx context.Context, in *QueryActiveAlarmsRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[ActiveAlarmSnapshot], error) {
|
func (c *mxAccessGatewayClient) QueryActiveAlarms(ctx context.Context, in *QueryActiveAlarmsRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[ActiveAlarmSnapshot], error) {
|
||||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
stream, err := c.cc.NewStream(ctx, &MxAccessGateway_ServiceDesc.Streams[1], MxAccessGateway_QueryActiveAlarms_FullMethodName, cOpts...)
|
stream, err := c.cc.NewStream(ctx, &MxAccessGateway_ServiceDesc.Streams[2], MxAccessGateway_QueryActiveAlarms_FullMethodName, cOpts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -138,6 +172,20 @@ type MxAccessGatewayServer interface {
|
|||||||
Invoke(context.Context, *MxCommandRequest) (*MxCommandReply, error)
|
Invoke(context.Context, *MxCommandRequest) (*MxCommandReply, error)
|
||||||
StreamEvents(*StreamEventsRequest, grpc.ServerStreamingServer[MxEvent]) error
|
StreamEvents(*StreamEventsRequest, grpc.ServerStreamingServer[MxEvent]) error
|
||||||
AcknowledgeAlarm(context.Context, *AcknowledgeAlarmRequest) (*AcknowledgeAlarmReply, error)
|
AcknowledgeAlarm(context.Context, *AcknowledgeAlarmRequest) (*AcknowledgeAlarmReply, error)
|
||||||
|
// Session-less central alarm feed. The stream opens with the current
|
||||||
|
// active-alarm snapshot (one `active_alarm` per alarm), then a single
|
||||||
|
// `snapshot_complete`, then a `transition` for every subsequent change.
|
||||||
|
// Served by the gateway's always-on alarm monitor; any number of clients
|
||||||
|
// fan out from the single monitor without opening a worker session.
|
||||||
|
StreamAlarms(*StreamAlarmsRequest, grpc.ServerStreamingServer[AlarmFeedMessage]) error
|
||||||
|
// Point-in-time snapshot of the currently-active alarm set served from the
|
||||||
|
// gateway's always-on alarm monitor cache (session-less). Used after a
|
||||||
|
// reconnect to seed Part 9 client state, or to reconcile alarms that may
|
||||||
|
// have been missed during a transport blip. Streamed so callers can
|
||||||
|
// begin processing without buffering the full set.
|
||||||
|
// `QueryActiveAlarmsRequest.alarm_filter_prefix` optionally narrows the
|
||||||
|
// snapshot to alarms whose `alarm_full_reference` starts with the given
|
||||||
|
// prefix; an empty prefix returns the full set.
|
||||||
QueryActiveAlarms(*QueryActiveAlarmsRequest, grpc.ServerStreamingServer[ActiveAlarmSnapshot]) error
|
QueryActiveAlarms(*QueryActiveAlarmsRequest, grpc.ServerStreamingServer[ActiveAlarmSnapshot]) error
|
||||||
mustEmbedUnimplementedMxAccessGatewayServer()
|
mustEmbedUnimplementedMxAccessGatewayServer()
|
||||||
}
|
}
|
||||||
@@ -164,6 +212,9 @@ func (UnimplementedMxAccessGatewayServer) StreamEvents(*StreamEventsRequest, grp
|
|||||||
func (UnimplementedMxAccessGatewayServer) AcknowledgeAlarm(context.Context, *AcknowledgeAlarmRequest) (*AcknowledgeAlarmReply, error) {
|
func (UnimplementedMxAccessGatewayServer) AcknowledgeAlarm(context.Context, *AcknowledgeAlarmRequest) (*AcknowledgeAlarmReply, error) {
|
||||||
return nil, status.Error(codes.Unimplemented, "method AcknowledgeAlarm not implemented")
|
return nil, status.Error(codes.Unimplemented, "method AcknowledgeAlarm not implemented")
|
||||||
}
|
}
|
||||||
|
func (UnimplementedMxAccessGatewayServer) StreamAlarms(*StreamAlarmsRequest, grpc.ServerStreamingServer[AlarmFeedMessage]) error {
|
||||||
|
return status.Error(codes.Unimplemented, "method StreamAlarms not implemented")
|
||||||
|
}
|
||||||
func (UnimplementedMxAccessGatewayServer) QueryActiveAlarms(*QueryActiveAlarmsRequest, grpc.ServerStreamingServer[ActiveAlarmSnapshot]) error {
|
func (UnimplementedMxAccessGatewayServer) QueryActiveAlarms(*QueryActiveAlarmsRequest, grpc.ServerStreamingServer[ActiveAlarmSnapshot]) error {
|
||||||
return status.Error(codes.Unimplemented, "method QueryActiveAlarms not implemented")
|
return status.Error(codes.Unimplemented, "method QueryActiveAlarms not implemented")
|
||||||
}
|
}
|
||||||
@@ -271,6 +322,17 @@ func _MxAccessGateway_AcknowledgeAlarm_Handler(srv interface{}, ctx context.Cont
|
|||||||
return interceptor(ctx, in, info, handler)
|
return interceptor(ctx, in, info, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func _MxAccessGateway_StreamAlarms_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
|
m := new(StreamAlarmsRequest)
|
||||||
|
if err := stream.RecvMsg(m); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return srv.(MxAccessGatewayServer).StreamAlarms(m, &grpc.GenericServerStream[StreamAlarmsRequest, AlarmFeedMessage]{ServerStream: stream})
|
||||||
|
}
|
||||||
|
|
||||||
|
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
|
||||||
|
type MxAccessGateway_StreamAlarmsServer = grpc.ServerStreamingServer[AlarmFeedMessage]
|
||||||
|
|
||||||
func _MxAccessGateway_QueryActiveAlarms_Handler(srv interface{}, stream grpc.ServerStream) error {
|
func _MxAccessGateway_QueryActiveAlarms_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
m := new(QueryActiveAlarmsRequest)
|
m := new(QueryActiveAlarmsRequest)
|
||||||
if err := stream.RecvMsg(m); err != nil {
|
if err := stream.RecvMsg(m); err != nil {
|
||||||
@@ -312,6 +374,11 @@ var MxAccessGateway_ServiceDesc = grpc.ServiceDesc{
|
|||||||
Handler: _MxAccessGateway_StreamEvents_Handler,
|
Handler: _MxAccessGateway_StreamEvents_Handler,
|
||||||
ServerStreams: true,
|
ServerStreams: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
StreamName: "StreamAlarms",
|
||||||
|
Handler: _MxAccessGateway_StreamAlarms_Handler,
|
||||||
|
ServerStreams: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
StreamName: "QueryActiveAlarms",
|
StreamName: "QueryActiveAlarms",
|
||||||
Handler: _MxAccessGateway_QueryActiveAlarms_Handler,
|
Handler: _MxAccessGateway_QueryActiveAlarms_Handler,
|
||||||
|
|||||||
@@ -1179,7 +1179,7 @@ const file_mxaccess_worker_proto_rawDesc = "" +
|
|||||||
"\x1eWORKER_FAULT_CATEGORY_STA_HUNG\x10\t\x12(\n" +
|
"\x1eWORKER_FAULT_CATEGORY_STA_HUNG\x10\t\x12(\n" +
|
||||||
"$WORKER_FAULT_CATEGORY_QUEUE_OVERFLOW\x10\n" +
|
"$WORKER_FAULT_CATEGORY_QUEUE_OVERFLOW\x10\n" +
|
||||||
"\x12*\n" +
|
"\x12*\n" +
|
||||||
"&WORKER_FAULT_CATEGORY_SHUTDOWN_TIMEOUT\x10\vB\x1c\xaa\x02\x19MxGateway.Contracts.Protob\x06proto3"
|
"&WORKER_FAULT_CATEGORY_SHUTDOWN_TIMEOUT\x10\vB&\xaa\x02#ZB.MOM.WW.MxGateway.Contracts.Protob\x06proto3"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
file_mxaccess_worker_proto_rawDescOnce sync.Once
|
file_mxaccess_worker_proto_rawDescOnce sync.Once
|
||||||
|
|||||||
@@ -51,3 +51,26 @@ func (c *Client) QueryActiveAlarms(ctx context.Context, req *QueryActiveAlarmsRe
|
|||||||
|
|
||||||
return stream, nil
|
return stream, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StreamAlarms attaches to the gateway's central alarm feed. The stream opens
|
||||||
|
// with one AlarmFeedMessage per currently-active alarm (the ConditionRefresh
|
||||||
|
// snapshot), then a single snapshot-complete sentinel, then a transition for
|
||||||
|
// every subsequent raise / acknowledge / clear. It is served by the gateway's
|
||||||
|
// always-on alarm monitor — no worker session is opened — so any number of
|
||||||
|
// clients may attach.
|
||||||
|
//
|
||||||
|
// The returned stream is owned by the caller; cancel ctx to release it.
|
||||||
|
// Optional alarm-reference prefix scoping (req.AlarmFilterPrefix) limits the
|
||||||
|
// stream to a sub-tree.
|
||||||
|
func (c *Client) StreamAlarms(ctx context.Context, req *StreamAlarmsRequest) (StreamAlarmsClient, error) {
|
||||||
|
if req == nil {
|
||||||
|
return nil, errors.New("mxgateway: stream alarms request is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
stream, err := c.raw.StreamAlarms(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, &GatewayError{Op: "stream alarms", Err: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
return stream, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import (
|
|||||||
func TestAcknowledgeAlarmSendsRequestAndReturnsReply(t *testing.T) {
|
func TestAcknowledgeAlarmSendsRequestAndReturnsReply(t *testing.T) {
|
||||||
fake := &fakeGatewayWithAlarms{
|
fake := &fakeGatewayWithAlarms{
|
||||||
acknowledgeReply: &pb.AcknowledgeAlarmReply{
|
acknowledgeReply: &pb.AcknowledgeAlarmReply{
|
||||||
SessionId: "session-1",
|
|
||||||
CorrelationId: "corr-1",
|
CorrelationId: "corr-1",
|
||||||
ProtocolStatus: &pb.ProtocolStatus{
|
ProtocolStatus: &pb.ProtocolStatus{
|
||||||
Code: pb.ProtocolStatusCode_PROTOCOL_STATUS_CODE_OK,
|
Code: pb.ProtocolStatusCode_PROTOCOL_STATUS_CODE_OK,
|
||||||
@@ -35,7 +34,6 @@ func TestAcknowledgeAlarmSendsRequestAndReturnsReply(t *testing.T) {
|
|||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
reply, err := client.AcknowledgeAlarm(context.Background(), &pb.AcknowledgeAlarmRequest{
|
reply, err := client.AcknowledgeAlarm(context.Background(), &pb.AcknowledgeAlarmRequest{
|
||||||
SessionId: "session-1",
|
|
||||||
ClientCorrelationId: "corr-1",
|
ClientCorrelationId: "corr-1",
|
||||||
AlarmFullReference: "Tank01.Level.HiHi",
|
AlarmFullReference: "Tank01.Level.HiHi",
|
||||||
Comment: "investigating",
|
Comment: "investigating",
|
||||||
@@ -81,7 +79,6 @@ func TestAcknowledgeAlarmMapsUnauthenticated(t *testing.T) {
|
|||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
_, err := client.AcknowledgeAlarm(context.Background(), &pb.AcknowledgeAlarmRequest{
|
_, err := client.AcknowledgeAlarm(context.Background(), &pb.AcknowledgeAlarmRequest{
|
||||||
SessionId: "session-1",
|
|
||||||
AlarmFullReference: "Tank01.Level.HiHi",
|
AlarmFullReference: "Tank01.Level.HiHi",
|
||||||
OperatorUser: "alice",
|
OperatorUser: "alice",
|
||||||
})
|
})
|
||||||
@@ -150,8 +147,8 @@ func TestQueryActiveAlarmsPassesFilterPrefix(t *testing.T) {
|
|||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
stream, err := client.QueryActiveAlarms(context.Background(), &pb.QueryActiveAlarmsRequest{
|
stream, err := client.QueryActiveAlarms(context.Background(), &pb.QueryActiveAlarmsRequest{
|
||||||
SessionId: "session-1",
|
SessionId: "session-1",
|
||||||
AlarmFilterPrefix: "Tank01.",
|
AlarmFilterPrefix: "Tank01.",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("QueryActiveAlarms() error = %v", err)
|
t.Fatalf("QueryActiveAlarms() error = %v", err)
|
||||||
@@ -171,6 +168,66 @@ func TestQueryActiveAlarmsPassesFilterPrefix(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStreamAlarmsPassesFilterPrefixAndReceivesFeedMessages(t *testing.T) {
|
||||||
|
fake := &fakeGatewayWithAlarms{
|
||||||
|
feedMessages: []*pb.AlarmFeedMessage{
|
||||||
|
{
|
||||||
|
Payload: &pb.AlarmFeedMessage_ActiveAlarm{
|
||||||
|
ActiveAlarm: &pb.ActiveAlarmSnapshot{
|
||||||
|
AlarmFullReference: "Tank01.Level.HiHi",
|
||||||
|
CurrentState: pb.AlarmConditionState_ALARM_CONDITION_STATE_ACTIVE,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Payload: &pb.AlarmFeedMessage_SnapshotComplete{
|
||||||
|
SnapshotComplete: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
client, cleanup := newBufconnClientWithAlarms(t, fake)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
stream, err := client.StreamAlarms(context.Background(), &pb.StreamAlarmsRequest{
|
||||||
|
AlarmFilterPrefix: "Tank01.",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("StreamAlarms() error = %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var received []*pb.AlarmFeedMessage
|
||||||
|
for {
|
||||||
|
msg, err := stream.Recv()
|
||||||
|
if errors.Is(err, io.EOF) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("stream.Recv() error = %v", err)
|
||||||
|
}
|
||||||
|
received = append(received, msg)
|
||||||
|
}
|
||||||
|
if len(received) != 2 {
|
||||||
|
t.Fatalf("received count = %d, want 2", len(received))
|
||||||
|
}
|
||||||
|
if got := fake.streamRequest.GetAlarmFilterPrefix(); got != "Tank01." {
|
||||||
|
t.Fatalf("captured filter prefix = %q", got)
|
||||||
|
}
|
||||||
|
if got := fake.streamAuth; got != "Bearer test-api-key" {
|
||||||
|
t.Fatalf("stream authorization metadata = %q", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStreamAlarmsRejectsNilRequest(t *testing.T) {
|
||||||
|
fake := &fakeGatewayWithAlarms{}
|
||||||
|
client, cleanup := newBufconnClientWithAlarms(t, fake)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
if _, err := client.StreamAlarms(context.Background(), nil); err == nil {
|
||||||
|
t.Fatal("StreamAlarms(nil) returned no error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type fakeGatewayWithAlarms struct {
|
type fakeGatewayWithAlarms struct {
|
||||||
pb.UnimplementedMxAccessGatewayServer
|
pb.UnimplementedMxAccessGatewayServer
|
||||||
|
|
||||||
@@ -181,6 +238,10 @@ type fakeGatewayWithAlarms struct {
|
|||||||
|
|
||||||
queryRequest *pb.QueryActiveAlarmsRequest
|
queryRequest *pb.QueryActiveAlarmsRequest
|
||||||
activeSnapshots []*pb.ActiveAlarmSnapshot
|
activeSnapshots []*pb.ActiveAlarmSnapshot
|
||||||
|
|
||||||
|
streamRequest *pb.StreamAlarmsRequest
|
||||||
|
feedMessages []*pb.AlarmFeedMessage
|
||||||
|
streamAuth string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *fakeGatewayWithAlarms) AcknowledgeAlarm(ctx context.Context, req *pb.AcknowledgeAlarmRequest) (*pb.AcknowledgeAlarmReply, error) {
|
func (s *fakeGatewayWithAlarms) AcknowledgeAlarm(ctx context.Context, req *pb.AcknowledgeAlarmRequest) (*pb.AcknowledgeAlarmReply, error) {
|
||||||
@@ -193,7 +254,7 @@ func (s *fakeGatewayWithAlarms) AcknowledgeAlarm(ctx context.Context, req *pb.Ac
|
|||||||
return s.acknowledgeReply, nil
|
return s.acknowledgeReply, nil
|
||||||
}
|
}
|
||||||
return &pb.AcknowledgeAlarmReply{
|
return &pb.AcknowledgeAlarmReply{
|
||||||
SessionId: req.GetSessionId(),
|
CorrelationId: req.GetClientCorrelationId(),
|
||||||
ProtocolStatus: &pb.ProtocolStatus{
|
ProtocolStatus: &pb.ProtocolStatus{
|
||||||
Code: pb.ProtocolStatusCode_PROTOCOL_STATUS_CODE_OK,
|
Code: pb.ProtocolStatusCode_PROTOCOL_STATUS_CODE_OK,
|
||||||
},
|
},
|
||||||
@@ -210,6 +271,17 @@ func (s *fakeGatewayWithAlarms) QueryActiveAlarms(req *pb.QueryActiveAlarmsReque
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *fakeGatewayWithAlarms) StreamAlarms(req *pb.StreamAlarmsRequest, stream grpc.ServerStreamingServer[pb.AlarmFeedMessage]) error {
|
||||||
|
s.streamRequest = req
|
||||||
|
s.streamAuth = authorizationFromContext(stream.Context())
|
||||||
|
for _, msg := range s.feedMessages {
|
||||||
|
if err := stream.Send(msg); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func newBufconnClientWithAlarms(t *testing.T, fake *fakeGatewayWithAlarms) (*Client, func()) {
|
func newBufconnClientWithAlarms(t *testing.T, fake *fakeGatewayWithAlarms) (*Client, func()) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
listener := bufconn.Listen(bufSize)
|
listener := bufconn.Listen(bufSize)
|
||||||
|
|||||||
@@ -222,10 +222,22 @@ func resolveTransportCredentials(opts Options) (credentials.TransportCredentials
|
|||||||
return credentials.NewTLS(cfg), nil
|
return credentials.NewTLS(cfg), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return credentials.NewTLS(&tls.Config{
|
return credentials.NewTLS(tlsConfigForOptions(opts)), nil
|
||||||
MinVersion: tls.VersionTLS12,
|
}
|
||||||
ServerName: opts.ServerNameOverride,
|
|
||||||
}), nil
|
// tlsConfigForOptions returns the *tls.Config for the no-CA, no-custom-config TLS path.
|
||||||
|
// It returns nil when the caller should use a different credentials path (CA file or custom TLSConfig).
|
||||||
|
// Exposed as an internal helper so unit tests can assert the InsecureSkipVerify posture.
|
||||||
|
func tlsConfigForOptions(opts Options) *tls.Config {
|
||||||
|
// CA file and custom TLSConfig take their own paths in resolveTransportCredentials.
|
||||||
|
if opts.CACertFile != "" || opts.TLSConfig != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &tls.Config{
|
||||||
|
MinVersion: tls.VersionTLS12,
|
||||||
|
ServerName: opts.ServerNameOverride,
|
||||||
|
InsecureSkipVerify: !opts.RequireCertificateValidation, //nolint:gosec // internal tool; self-signed gateway cert expected; opt-in strict via RequireCertificateValidation
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenSessionOptions describes fields used to create an OpenSessionRequest.
|
// OpenSessionOptions describes fields used to create an OpenSessionRequest.
|
||||||
|
|||||||
@@ -230,6 +230,289 @@ func TestSubscribeBulkBuildsOneBulkCommandAndReturnsResults(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWriteBulkBuildsOneBulkCommandAndReturnsPerEntryResults(t *testing.T) {
|
||||||
|
fake := &fakeGatewayServer{
|
||||||
|
invokeReply: &pb.MxCommandReply{
|
||||||
|
SessionId: "session-1",
|
||||||
|
Kind: pb.MxCommandKind_MX_COMMAND_KIND_WRITE_BULK,
|
||||||
|
ProtocolStatus: &pb.ProtocolStatus{
|
||||||
|
Code: pb.ProtocolStatusCode_PROTOCOL_STATUS_CODE_OK,
|
||||||
|
},
|
||||||
|
Payload: &pb.MxCommandReply_WriteBulk{
|
||||||
|
WriteBulk: &pb.BulkWriteReply{
|
||||||
|
Results: []*pb.BulkWriteResult{
|
||||||
|
{ItemHandle: 10, WasSuccessful: true},
|
||||||
|
{ItemHandle: 11, WasSuccessful: true},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
client, cleanup := newBufconnClient(t, fake)
|
||||||
|
defer cleanup()
|
||||||
|
session := NewSessionForID(client, "session-1")
|
||||||
|
|
||||||
|
entries := []*WriteBulkEntry{
|
||||||
|
{ItemHandle: 10, Value: Int32Value(7), UserId: 100},
|
||||||
|
{ItemHandle: 11, Value: Int32Value(8), UserId: 100},
|
||||||
|
}
|
||||||
|
results, err := session.WriteBulk(context.Background(), 12, entries)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("WriteBulk() error = %v", err)
|
||||||
|
}
|
||||||
|
if len(results) != 2 {
|
||||||
|
t.Fatalf("results len = %d, want 2", len(results))
|
||||||
|
}
|
||||||
|
req := fake.invokeRequest
|
||||||
|
if req.GetCommand().GetKind() != pb.MxCommandKind_MX_COMMAND_KIND_WRITE_BULK {
|
||||||
|
t.Fatalf("command kind = %s", req.GetCommand().GetKind())
|
||||||
|
}
|
||||||
|
if got := req.GetCommand().GetWriteBulk().GetEntries(); len(got) != 2 {
|
||||||
|
t.Fatalf("entry count = %d, want 2", len(got))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWriteBulkRejectsNilEntries(t *testing.T) {
|
||||||
|
fake := &fakeGatewayServer{}
|
||||||
|
client, cleanup := newBufconnClient(t, fake)
|
||||||
|
defer cleanup()
|
||||||
|
session := NewSessionForID(client, "session-1")
|
||||||
|
|
||||||
|
if _, err := session.WriteBulk(context.Background(), 12, nil); err == nil {
|
||||||
|
t.Fatal("WriteBulk(nil) returned no error")
|
||||||
|
}
|
||||||
|
if _, err := session.Write2Bulk(context.Background(), 12, nil); err == nil {
|
||||||
|
t.Fatal("Write2Bulk(nil) returned no error")
|
||||||
|
}
|
||||||
|
if _, err := session.WriteSecuredBulk(context.Background(), 12, nil); err == nil {
|
||||||
|
t.Fatal("WriteSecuredBulk(nil) returned no error")
|
||||||
|
}
|
||||||
|
if _, err := session.WriteSecured2Bulk(context.Background(), 12, nil); err == nil {
|
||||||
|
t.Fatal("WriteSecured2Bulk(nil) returned no error")
|
||||||
|
}
|
||||||
|
if _, err := session.ReadBulk(context.Background(), 12, nil, 0); err == nil {
|
||||||
|
t.Fatal("ReadBulk(nil) returned no error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBulkMethodsShortCircuitOnEmptySliceWithoutRoundTrip(t *testing.T) {
|
||||||
|
fake := &fakeGatewayServer{
|
||||||
|
invokeReply: &pb.MxCommandReply{
|
||||||
|
ProtocolStatus: &pb.ProtocolStatus{
|
||||||
|
Code: pb.ProtocolStatusCode_PROTOCOL_STATUS_CODE_OK,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
client, cleanup := newBufconnClient(t, fake)
|
||||||
|
defer cleanup()
|
||||||
|
session := NewSessionForID(client, "session-1")
|
||||||
|
|
||||||
|
results, err := session.WriteBulk(context.Background(), 12, []*WriteBulkEntry{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("WriteBulk(empty) error = %v", err)
|
||||||
|
}
|
||||||
|
if len(results) != 0 {
|
||||||
|
t.Fatalf("WriteBulk(empty) results len = %d, want 0", len(results))
|
||||||
|
}
|
||||||
|
if fake.invokeRequest != nil {
|
||||||
|
t.Fatal("WriteBulk(empty) sent a round trip; expected short-circuit")
|
||||||
|
}
|
||||||
|
|
||||||
|
results2, err := session.Write2Bulk(context.Background(), 12, []*Write2BulkEntry{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Write2Bulk(empty) error = %v", err)
|
||||||
|
}
|
||||||
|
if len(results2) != 0 {
|
||||||
|
t.Fatalf("Write2Bulk(empty) results len = %d, want 0", len(results2))
|
||||||
|
}
|
||||||
|
if fake.invokeRequest != nil {
|
||||||
|
t.Fatal("Write2Bulk(empty) sent a round trip; expected short-circuit")
|
||||||
|
}
|
||||||
|
|
||||||
|
results3, err := session.WriteSecuredBulk(context.Background(), 12, []*WriteSecuredBulkEntry{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("WriteSecuredBulk(empty) error = %v", err)
|
||||||
|
}
|
||||||
|
if len(results3) != 0 {
|
||||||
|
t.Fatalf("WriteSecuredBulk(empty) results len = %d, want 0", len(results3))
|
||||||
|
}
|
||||||
|
if fake.invokeRequest != nil {
|
||||||
|
t.Fatal("WriteSecuredBulk(empty) sent a round trip; expected short-circuit")
|
||||||
|
}
|
||||||
|
|
||||||
|
results4, err := session.WriteSecured2Bulk(context.Background(), 12, []*WriteSecured2BulkEntry{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("WriteSecured2Bulk(empty) error = %v", err)
|
||||||
|
}
|
||||||
|
if len(results4) != 0 {
|
||||||
|
t.Fatalf("WriteSecured2Bulk(empty) results len = %d, want 0", len(results4))
|
||||||
|
}
|
||||||
|
if fake.invokeRequest != nil {
|
||||||
|
t.Fatal("WriteSecured2Bulk(empty) sent a round trip; expected short-circuit")
|
||||||
|
}
|
||||||
|
|
||||||
|
readResults, err := session.ReadBulk(context.Background(), 12, []string{}, 0)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ReadBulk(empty) error = %v", err)
|
||||||
|
}
|
||||||
|
if len(readResults) != 0 {
|
||||||
|
t.Fatalf("ReadBulk(empty) results len = %d, want 0", len(readResults))
|
||||||
|
}
|
||||||
|
if fake.invokeRequest != nil {
|
||||||
|
t.Fatal("ReadBulk(empty) sent a round trip; expected short-circuit")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWrite2BuildsCommandWithTimestampAndReturnsNoError(t *testing.T) {
|
||||||
|
fake := &fakeGatewayServer{
|
||||||
|
invokeReply: &pb.MxCommandReply{
|
||||||
|
SessionId: "session-1",
|
||||||
|
Kind: pb.MxCommandKind_MX_COMMAND_KIND_WRITE2,
|
||||||
|
ProtocolStatus: &pb.ProtocolStatus{
|
||||||
|
Code: pb.ProtocolStatusCode_PROTOCOL_STATUS_CODE_OK,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
client, cleanup := newBufconnClient(t, fake)
|
||||||
|
defer cleanup()
|
||||||
|
session := NewSessionForID(client, "session-1")
|
||||||
|
|
||||||
|
val := Int32Value(99)
|
||||||
|
ts := Int32Value(77)
|
||||||
|
err := session.Write2(context.Background(), 12, 34, val, ts, 100)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Write2() error = %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
req := fake.invokeRequest
|
||||||
|
if req.GetCommand().GetKind() != pb.MxCommandKind_MX_COMMAND_KIND_WRITE2 {
|
||||||
|
t.Fatalf("command kind = %s, want WRITE2", req.GetCommand().GetKind())
|
||||||
|
}
|
||||||
|
w2 := req.GetCommand().GetWrite2()
|
||||||
|
if w2.GetServerHandle() != 12 {
|
||||||
|
t.Fatalf("server handle = %d, want 12", w2.GetServerHandle())
|
||||||
|
}
|
||||||
|
if w2.GetItemHandle() != 34 {
|
||||||
|
t.Fatalf("item handle = %d, want 34", w2.GetItemHandle())
|
||||||
|
}
|
||||||
|
if w2.GetValue().GetInt32Value() != 99 {
|
||||||
|
t.Fatalf("value int32 = %d, want 99", w2.GetValue().GetInt32Value())
|
||||||
|
}
|
||||||
|
if w2.GetTimestampValue().GetInt32Value() != 77 {
|
||||||
|
t.Fatalf("timestamp value int32 = %d, want 77", w2.GetTimestampValue().GetInt32Value())
|
||||||
|
}
|
||||||
|
if w2.GetUserId() != 100 {
|
||||||
|
t.Fatalf("user id = %d, want 100", w2.GetUserId())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWrite2RawReturnsRawReply(t *testing.T) {
|
||||||
|
fake := &fakeGatewayServer{
|
||||||
|
invokeReply: &pb.MxCommandReply{
|
||||||
|
SessionId: "session-1",
|
||||||
|
Kind: pb.MxCommandKind_MX_COMMAND_KIND_WRITE2,
|
||||||
|
ProtocolStatus: &pb.ProtocolStatus{
|
||||||
|
Code: pb.ProtocolStatusCode_PROTOCOL_STATUS_CODE_OK,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
client, cleanup := newBufconnClient(t, fake)
|
||||||
|
defer cleanup()
|
||||||
|
session := NewSessionForID(client, "session-1")
|
||||||
|
|
||||||
|
reply, err := session.Write2Raw(context.Background(), 12, 34, Int32Value(1), Int32Value(0), 0)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Write2Raw() error = %v", err)
|
||||||
|
}
|
||||||
|
if reply == nil {
|
||||||
|
t.Fatal("Write2Raw() returned nil reply")
|
||||||
|
}
|
||||||
|
if reply.GetKind() != pb.MxCommandKind_MX_COMMAND_KIND_WRITE2 {
|
||||||
|
t.Fatalf("reply kind = %s, want WRITE2", reply.GetKind())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWrite2RejectsNilValue(t *testing.T) {
|
||||||
|
fake := &fakeGatewayServer{}
|
||||||
|
client, cleanup := newBufconnClient(t, fake)
|
||||||
|
defer cleanup()
|
||||||
|
session := NewSessionForID(client, "session-1")
|
||||||
|
|
||||||
|
if err := session.Write2(context.Background(), 12, 34, nil, Int32Value(0), 0); err == nil {
|
||||||
|
t.Fatal("Write2(nil value) returned no error")
|
||||||
|
}
|
||||||
|
if err := session.Write2(context.Background(), 12, 34, Int32Value(1), nil, 0); err == nil {
|
||||||
|
t.Fatal("Write2(nil timestampValue) returned no error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestReadBulkForwardsTimeoutAndUnpacksCachedFlag(t *testing.T) {
|
||||||
|
fake := &fakeGatewayServer{
|
||||||
|
invokeReply: &pb.MxCommandReply{
|
||||||
|
SessionId: "session-1",
|
||||||
|
Kind: pb.MxCommandKind_MX_COMMAND_KIND_READ_BULK,
|
||||||
|
ProtocolStatus: &pb.ProtocolStatus{
|
||||||
|
Code: pb.ProtocolStatusCode_PROTOCOL_STATUS_CODE_OK,
|
||||||
|
},
|
||||||
|
Payload: &pb.MxCommandReply_ReadBulk{
|
||||||
|
ReadBulk: &pb.BulkReadReply{
|
||||||
|
Results: []*pb.BulkReadResult{
|
||||||
|
{TagAddress: "Tank01.Level", WasSuccessful: true, WasCached: true},
|
||||||
|
{TagAddress: "Tank02.Level", WasSuccessful: true, WasCached: false},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
client, cleanup := newBufconnClient(t, fake)
|
||||||
|
defer cleanup()
|
||||||
|
session := NewSessionForID(client, "session-1")
|
||||||
|
|
||||||
|
results, err := session.ReadBulk(context.Background(), 12, []string{"Tank01.Level", "Tank02.Level"}, 250*time.Millisecond)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ReadBulk() error = %v", err)
|
||||||
|
}
|
||||||
|
if len(results) != 2 {
|
||||||
|
t.Fatalf("results len = %d, want 2", len(results))
|
||||||
|
}
|
||||||
|
if !results[0].GetWasCached() || results[1].GetWasCached() {
|
||||||
|
t.Fatalf("WasCached flags = [%v %v], want [true false]", results[0].GetWasCached(), results[1].GetWasCached())
|
||||||
|
}
|
||||||
|
req := fake.invokeRequest
|
||||||
|
if req.GetCommand().GetKind() != pb.MxCommandKind_MX_COMMAND_KIND_READ_BULK {
|
||||||
|
t.Fatalf("command kind = %s", req.GetCommand().GetKind())
|
||||||
|
}
|
||||||
|
if got := req.GetCommand().GetReadBulk().GetTimeoutMs(); got != 250 {
|
||||||
|
t.Fatalf("timeout ms = %d, want 250", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestReadBulkSaturatesTimeoutAboveMaxUint32(t *testing.T) {
|
||||||
|
fake := &fakeGatewayServer{
|
||||||
|
invokeReply: &pb.MxCommandReply{
|
||||||
|
SessionId: "session-1",
|
||||||
|
Kind: pb.MxCommandKind_MX_COMMAND_KIND_READ_BULK,
|
||||||
|
ProtocolStatus: &pb.ProtocolStatus{
|
||||||
|
Code: pb.ProtocolStatusCode_PROTOCOL_STATUS_CODE_OK,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
client, cleanup := newBufconnClient(t, fake)
|
||||||
|
defer cleanup()
|
||||||
|
session := NewSessionForID(client, "session-1")
|
||||||
|
|
||||||
|
// 100 days in milliseconds exceeds MaxUint32 (~49.7 days).
|
||||||
|
hugeTimeout := 100 * 24 * time.Hour
|
||||||
|
_, err := session.ReadBulk(context.Background(), 12, []string{"Tank01.Level"}, hugeTimeout)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ReadBulk() error = %v", err)
|
||||||
|
}
|
||||||
|
got := fake.invokeRequest.GetCommand().GetReadBulk().GetTimeoutMs()
|
||||||
|
if got != ^uint32(0) {
|
||||||
|
t.Fatalf("timeout ms = %d, want %d (MaxUint32)", got, ^uint32(0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestInvokeReturnsTypedMxAccessErrorWithRawReply(t *testing.T) {
|
func TestInvokeReturnsTypedMxAccessErrorWithRawReply(t *testing.T) {
|
||||||
hresult := int32(-2147467259)
|
hresult := int32(-2147467259)
|
||||||
fake := &fakeGatewayServer{
|
fake := &fakeGatewayServer{
|
||||||
@@ -383,3 +666,124 @@ func authorizationFromContext(ctx context.Context) string {
|
|||||||
}
|
}
|
||||||
return values[0]
|
return values[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// WriteArrayElements / buildSparseArrayValue unit tests
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
func TestBuildSparseArrayValueSetsSparseOneof(t *testing.T) {
|
||||||
|
elements := map[uint32]*MxValue{
|
||||||
|
2: Int32Value(99),
|
||||||
|
0: Int32Value(10),
|
||||||
|
}
|
||||||
|
v := buildSparseArrayValue(DataTypeInteger, 5, elements)
|
||||||
|
|
||||||
|
sa, ok := v.Kind.(*pb.MxValue_SparseArrayValue)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("Kind is %T, want *pb.MxValue_SparseArrayValue", v.Kind)
|
||||||
|
}
|
||||||
|
got := sa.SparseArrayValue
|
||||||
|
if got.GetElementDataType() != DataTypeInteger {
|
||||||
|
t.Errorf("ElementDataType = %v, want DataTypeInteger", got.GetElementDataType())
|
||||||
|
}
|
||||||
|
if got.GetTotalLength() != 5 {
|
||||||
|
t.Errorf("TotalLength = %d, want 5", got.GetTotalLength())
|
||||||
|
}
|
||||||
|
if len(got.GetElements()) != 2 {
|
||||||
|
t.Fatalf("len(Elements) = %d, want 2", len(got.GetElements()))
|
||||||
|
}
|
||||||
|
// Elements must be sorted by index (ascending).
|
||||||
|
if got.GetElements()[0].GetIndex() != 0 {
|
||||||
|
t.Errorf("Elements[0].Index = %d, want 0", got.GetElements()[0].GetIndex())
|
||||||
|
}
|
||||||
|
if got.GetElements()[0].GetValue().GetInt32Value() != 10 {
|
||||||
|
t.Errorf("Elements[0].Value = %v, want 10", got.GetElements()[0].GetValue())
|
||||||
|
}
|
||||||
|
if got.GetElements()[1].GetIndex() != 2 {
|
||||||
|
t.Errorf("Elements[1].Index = %d, want 2", got.GetElements()[1].GetIndex())
|
||||||
|
}
|
||||||
|
if got.GetElements()[1].GetValue().GetInt32Value() != 99 {
|
||||||
|
t.Errorf("Elements[1].Value = %v, want 99", got.GetElements()[1].GetValue())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildSparseArrayValueEmptyMapProducesEmptyElements(t *testing.T) {
|
||||||
|
v := buildSparseArrayValue(DataTypeBoolean, 4, map[uint32]*MxValue{})
|
||||||
|
|
||||||
|
sa, ok := v.Kind.(*pb.MxValue_SparseArrayValue)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("Kind is %T, want *pb.MxValue_SparseArrayValue", v.Kind)
|
||||||
|
}
|
||||||
|
if len(sa.SparseArrayValue.GetElements()) != 0 {
|
||||||
|
t.Errorf("len(Elements) = %d, want 0", len(sa.SparseArrayValue.GetElements()))
|
||||||
|
}
|
||||||
|
if sa.SparseArrayValue.GetTotalLength() != 4 {
|
||||||
|
t.Errorf("TotalLength = %d, want 4", sa.SparseArrayValue.GetTotalLength())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWriteArrayElementsSendsWriteCommandWithSparseOneof(t *testing.T) {
|
||||||
|
fake := &fakeGatewayServer{
|
||||||
|
invokeReply: &pb.MxCommandReply{
|
||||||
|
SessionId: "session-1",
|
||||||
|
Kind: pb.MxCommandKind_MX_COMMAND_KIND_WRITE,
|
||||||
|
ProtocolStatus: &pb.ProtocolStatus{
|
||||||
|
Code: pb.ProtocolStatusCode_PROTOCOL_STATUS_CODE_OK,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
client, cleanup := newBufconnClient(t, fake)
|
||||||
|
defer cleanup()
|
||||||
|
session := NewSessionForID(client, "session-1")
|
||||||
|
|
||||||
|
err := session.WriteArrayElements(
|
||||||
|
context.Background(),
|
||||||
|
1, 2,
|
||||||
|
DataTypeFloat,
|
||||||
|
10,
|
||||||
|
map[uint32]*MxValue{3: FloatValue(1.5)},
|
||||||
|
42,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("WriteArrayElements() error = %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := fake.invokeRequest.GetCommand()
|
||||||
|
if cmd.GetKind() != pb.MxCommandKind_MX_COMMAND_KIND_WRITE {
|
||||||
|
t.Fatalf("command kind = %s, want WRITE", cmd.GetKind())
|
||||||
|
}
|
||||||
|
w := cmd.GetWrite()
|
||||||
|
if w.GetServerHandle() != 1 {
|
||||||
|
t.Fatalf("server handle = %d, want 1", w.GetServerHandle())
|
||||||
|
}
|
||||||
|
if w.GetItemHandle() != 2 {
|
||||||
|
t.Fatalf("item handle = %d, want 2", w.GetItemHandle())
|
||||||
|
}
|
||||||
|
if w.GetUserId() == 0 {
|
||||||
|
t.Fatal("user id = 0, want non-zero")
|
||||||
|
}
|
||||||
|
if w.GetUserId() != 42 {
|
||||||
|
t.Fatalf("user id = %d, want 42", w.GetUserId())
|
||||||
|
}
|
||||||
|
val := w.GetValue()
|
||||||
|
sa, ok := val.Kind.(*pb.MxValue_SparseArrayValue)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("value kind is %T, want *pb.MxValue_SparseArrayValue", val.Kind)
|
||||||
|
}
|
||||||
|
if sa.SparseArrayValue.GetTotalLength() != 10 {
|
||||||
|
t.Errorf("TotalLength = %d, want 10", sa.SparseArrayValue.GetTotalLength())
|
||||||
|
}
|
||||||
|
if sa.SparseArrayValue.GetElementDataType() != DataTypeFloat {
|
||||||
|
t.Errorf("ElementDataType = %v, want DataTypeFloat", sa.SparseArrayValue.GetElementDataType())
|
||||||
|
}
|
||||||
|
if len(sa.SparseArrayValue.GetElements()) != 1 {
|
||||||
|
t.Fatalf("len(Elements) = %d, want 1", len(sa.SparseArrayValue.GetElements()))
|
||||||
|
}
|
||||||
|
elem := sa.SparseArrayValue.GetElements()[0]
|
||||||
|
if elem.GetIndex() != 3 {
|
||||||
|
t.Errorf("element index = %d, want 3", elem.GetIndex())
|
||||||
|
}
|
||||||
|
if elem.GetValue().GetFloatValue() != 1.5 {
|
||||||
|
t.Errorf("element float value = %v, want 1.5", elem.GetValue().GetFloatValue())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package mxgateway
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// tlsConfigFromOptions is the internal helper under test.
|
||||||
|
// It extracts the *tls.Config from the no-CA TLS path of resolveTransportCredentials.
|
||||||
|
// We exercise it directly to avoid needing a real dial target.
|
||||||
|
|
||||||
|
func TestTLSInsecureSkipVerify_DefaultTrue(t *testing.T) {
|
||||||
|
cfg := tlsConfigForOptions(Options{
|
||||||
|
Endpoint: "localhost:5120",
|
||||||
|
})
|
||||||
|
if cfg == nil {
|
||||||
|
t.Fatal("expected non-nil tls.Config")
|
||||||
|
}
|
||||||
|
if !cfg.InsecureSkipVerify {
|
||||||
|
t.Error("InsecureSkipVerify should be true by default when no CA is pinned")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTLSInsecureSkipVerify_FalseWhenRequireCertificateValidation(t *testing.T) {
|
||||||
|
cfg := tlsConfigForOptions(Options{
|
||||||
|
Endpoint: "localhost:5120",
|
||||||
|
RequireCertificateValidation: true,
|
||||||
|
})
|
||||||
|
if cfg == nil {
|
||||||
|
t.Fatal("expected non-nil tls.Config")
|
||||||
|
}
|
||||||
|
if cfg.InsecureSkipVerify {
|
||||||
|
t.Error("InsecureSkipVerify should be false when RequireCertificateValidation is true")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTLSInsecureSkipVerify_FalseWhenCACertFileSet(t *testing.T) {
|
||||||
|
// When a CA file is pinned, the CA-verification path is taken instead.
|
||||||
|
// tlsConfigForOptions should return nil (the CA path does not use our helper).
|
||||||
|
cfg := tlsConfigForOptions(Options{
|
||||||
|
Endpoint: "localhost:5120",
|
||||||
|
CACertFile: "/some/ca.pem",
|
||||||
|
})
|
||||||
|
if cfg != nil {
|
||||||
|
t.Error("expected nil tls.Config when CACertFile is set (CA path taken)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTLSInsecureSkipVerify_FalseWhenCustomTLSConfig(t *testing.T) {
|
||||||
|
// When TLSConfig is supplied explicitly, our default skip-verify must not overwrite it.
|
||||||
|
custom := &tls.Config{MinVersion: tls.VersionTLS13}
|
||||||
|
cfg := tlsConfigForOptions(Options{
|
||||||
|
Endpoint: "localhost:5120",
|
||||||
|
TLSConfig: custom,
|
||||||
|
})
|
||||||
|
if cfg != nil {
|
||||||
|
t.Error("expected nil tls.Config when TLSConfig is already set (custom config path taken)")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,9 @@ package mxgateway
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
pb "gitea.dohertylan.com/dohertj2/mxaccessgw/clients/go/internal/generated"
|
pb "gitea.dohertylan.com/dohertj2/mxaccessgw/clients/go/internal/generated"
|
||||||
@@ -13,6 +15,14 @@ import (
|
|||||||
"google.golang.org/protobuf/types/known/timestamppb"
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// browseChildrenPageSize is the per-request page size used by the lazy walker.
|
||||||
|
const browseChildrenPageSize = 500
|
||||||
|
|
||||||
|
// discoverHierarchyPageSize is the per-request page size used by DiscoverHierarchy.
|
||||||
|
// Mirrors the .NET client constant so large galaxies are not silently truncated
|
||||||
|
// by the server's default page cap.
|
||||||
|
const discoverHierarchyPageSize = 5000
|
||||||
|
|
||||||
// RawGalaxyRepositoryClient is the generated gRPC client interface for the
|
// RawGalaxyRepositoryClient is the generated gRPC client interface for the
|
||||||
// Galaxy Repository service exposed for callers that need direct contract
|
// Galaxy Repository service exposed for callers that need direct contract
|
||||||
// access.
|
// access.
|
||||||
@@ -40,6 +50,15 @@ type (
|
|||||||
WatchDeployEventsRequest = pb.WatchDeployEventsRequest
|
WatchDeployEventsRequest = pb.WatchDeployEventsRequest
|
||||||
// DeployEvent is one Galaxy Repository deploy event.
|
// DeployEvent is one Galaxy Repository deploy event.
|
||||||
DeployEvent = pb.DeployEvent
|
DeployEvent = pb.DeployEvent
|
||||||
|
// BrowseChildrenRequest is the request for BrowseChildren.
|
||||||
|
BrowseChildrenRequest = pb.BrowseChildrenRequest
|
||||||
|
// BrowseChildrenReply is the reply for BrowseChildren.
|
||||||
|
BrowseChildrenReply = pb.BrowseChildrenReply
|
||||||
|
// BrowseChildrenRequest_ParentGobjectId selects the parent-by-gobject-id
|
||||||
|
// variant of the BrowseChildrenRequest parent oneof. Exposed so callers
|
||||||
|
// (e.g. the mxgw-go CLI) can issue a parent-scoped single-level browse
|
||||||
|
// without reaching into the generated package.
|
||||||
|
BrowseChildrenRequest_ParentGobjectId = pb.BrowseChildrenRequest_ParentGobjectId //nolint:revive,staticcheck // mirrors generated proto oneof name
|
||||||
)
|
)
|
||||||
|
|
||||||
// RawDeployEventStream is the generated WatchDeployEvents client stream.
|
// RawDeployEventStream is the generated WatchDeployEvents client stream.
|
||||||
@@ -146,16 +165,35 @@ func (c *GalaxyClient) GetLastDeployTime(ctx context.Context) (time.Time, bool,
|
|||||||
|
|
||||||
// DiscoverHierarchy returns the deployed Galaxy object hierarchy with each
|
// DiscoverHierarchy returns the deployed Galaxy object hierarchy with each
|
||||||
// object's dynamic attributes. The objects are returned in the order supplied
|
// object's dynamic attributes. The objects are returned in the order supplied
|
||||||
// by the server.
|
// by the server. The call pages over the server's NextPageToken until the
|
||||||
|
// server signals it has no more results, matching the .NET client.
|
||||||
func (c *GalaxyClient) DiscoverHierarchy(ctx context.Context) ([]*GalaxyObject, error) {
|
func (c *GalaxyClient) DiscoverHierarchy(ctx context.Context) ([]*GalaxyObject, error) {
|
||||||
callCtx, cancel := c.callContext(ctx)
|
var objects []*GalaxyObject
|
||||||
defer cancel()
|
pageToken := ""
|
||||||
|
seen := map[string]struct{}{}
|
||||||
reply, err := c.raw.DiscoverHierarchy(callCtx, &pb.DiscoverHierarchyRequest{})
|
for {
|
||||||
if err != nil {
|
callCtx, cancel := c.callContext(ctx)
|
||||||
return nil, &GatewayError{Op: "galaxy discover hierarchy", Err: err}
|
reply, err := c.raw.DiscoverHierarchy(callCtx, &pb.DiscoverHierarchyRequest{
|
||||||
|
PageSize: discoverHierarchyPageSize,
|
||||||
|
PageToken: pageToken,
|
||||||
|
})
|
||||||
|
cancel()
|
||||||
|
if err != nil {
|
||||||
|
return nil, &GatewayError{Op: "galaxy discover hierarchy", Err: err}
|
||||||
|
}
|
||||||
|
objects = append(objects, reply.GetObjects()...)
|
||||||
|
pageToken = reply.GetNextPageToken()
|
||||||
|
if pageToken == "" {
|
||||||
|
return objects, nil
|
||||||
|
}
|
||||||
|
if _, dup := seen[pageToken]; dup {
|
||||||
|
return nil, &GatewayError{
|
||||||
|
Op: "galaxy discover hierarchy",
|
||||||
|
Err: fmt.Errorf("repeated page token %q", pageToken),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
seen[pageToken] = struct{}{}
|
||||||
}
|
}
|
||||||
return reply.GetObjects(), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WatchDeployEventsRaw starts the generated WatchDeployEvents stream for callers
|
// WatchDeployEventsRaw starts the generated WatchDeployEvents stream for callers
|
||||||
@@ -238,6 +276,206 @@ func (c *GalaxyClient) Close() error {
|
|||||||
return c.conn.Close()
|
return c.conn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LazyBrowseNode is one node in a lazy Galaxy hierarchy walk produced by
|
||||||
|
// (*GalaxyClient).Browse. Children are not fetched until Expand is called.
|
||||||
|
// The node is safe for concurrent use; concurrent Expand calls coalesce onto
|
||||||
|
// a single in-flight RPC and do not block snapshot accessors.
|
||||||
|
type LazyBrowseNode struct {
|
||||||
|
client *GalaxyClient
|
||||||
|
object *pb.GalaxyObject
|
||||||
|
hasChildrenHint bool
|
||||||
|
options BrowseChildrenOptions
|
||||||
|
|
||||||
|
// expandLock gates inspection and mutation of expand-coordination state
|
||||||
|
// (expanding, expandDone, expandErr). It is held only briefly; the BrowseChildren
|
||||||
|
// RPC itself runs outside this lock so concurrent readers and waiters are not blocked.
|
||||||
|
expandLock sync.Mutex
|
||||||
|
expanding bool
|
||||||
|
expandDone chan struct{}
|
||||||
|
expandErr error
|
||||||
|
|
||||||
|
// mu protects the children snapshot and isExpanded flag for concurrent
|
||||||
|
// Children() / IsExpanded() readers.
|
||||||
|
mu sync.RWMutex
|
||||||
|
children []*LazyBrowseNode
|
||||||
|
isExpanded bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// Object returns the underlying GalaxyObject describing this node.
|
||||||
|
func (n *LazyBrowseNode) Object() *pb.GalaxyObject { return n.object }
|
||||||
|
|
||||||
|
// HasChildrenHint reports the server-supplied hint on whether this node has
|
||||||
|
// matching descendants under the current filter set.
|
||||||
|
func (n *LazyBrowseNode) HasChildrenHint() bool { return n.hasChildrenHint }
|
||||||
|
|
||||||
|
// Children returns a snapshot copy of the currently-loaded child nodes. Returns
|
||||||
|
// an empty slice when Expand has not yet been called.
|
||||||
|
func (n *LazyBrowseNode) Children() []*LazyBrowseNode {
|
||||||
|
n.mu.RLock()
|
||||||
|
defer n.mu.RUnlock()
|
||||||
|
out := make([]*LazyBrowseNode, len(n.children))
|
||||||
|
copy(out, n.children)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsExpanded reports whether Expand has completed successfully on this node.
|
||||||
|
func (n *LazyBrowseNode) IsExpanded() bool {
|
||||||
|
n.mu.RLock()
|
||||||
|
defer n.mu.RUnlock()
|
||||||
|
return n.isExpanded
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expand fetches this node's direct children via BrowseChildren when they have
|
||||||
|
// not yet been loaded. Subsequent calls after a successful Expand are a no-op
|
||||||
|
// and do not issue another RPC.
|
||||||
|
//
|
||||||
|
// Expand is safe to call concurrently from multiple goroutines: callers that
|
||||||
|
// arrive while an expansion is in flight wait on the active RPC and share its
|
||||||
|
// result instead of issuing a second RPC. The RPC itself runs without holding
|
||||||
|
// the snapshot mutex, so concurrent Children() and IsExpanded() callers are
|
||||||
|
// not blocked for the duration of the network round trip.
|
||||||
|
//
|
||||||
|
// Failure semantics: a failed expansion surfaces the same error to every
|
||||||
|
// in-flight waiter, but the node is left in its pre-call state (isExpanded =
|
||||||
|
// false, no in-flight expansion). The next Expand call therefore retries with
|
||||||
|
// a fresh RPC; failures are not sticky.
|
||||||
|
func (n *LazyBrowseNode) Expand(ctx context.Context) error {
|
||||||
|
// Fast path: already expanded.
|
||||||
|
n.mu.RLock()
|
||||||
|
if n.isExpanded {
|
||||||
|
n.mu.RUnlock()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
n.mu.RUnlock()
|
||||||
|
|
||||||
|
// Either start a new expansion or wait on an existing one.
|
||||||
|
n.expandLock.Lock()
|
||||||
|
n.mu.RLock()
|
||||||
|
alreadyExpanded := n.isExpanded
|
||||||
|
n.mu.RUnlock()
|
||||||
|
if alreadyExpanded {
|
||||||
|
n.expandLock.Unlock()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if n.expanding {
|
||||||
|
done := n.expandDone
|
||||||
|
n.expandLock.Unlock()
|
||||||
|
select {
|
||||||
|
case <-done:
|
||||||
|
n.expandLock.Lock()
|
||||||
|
err := n.expandErr
|
||||||
|
n.expandLock.Unlock()
|
||||||
|
return err
|
||||||
|
case <-ctx.Done():
|
||||||
|
return ctx.Err()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
n.expanding = true
|
||||||
|
n.expandDone = make(chan struct{})
|
||||||
|
done := n.expandDone
|
||||||
|
n.expandLock.Unlock()
|
||||||
|
|
||||||
|
// Issue the RPC outside any lock so concurrent readers/waiters are not blocked.
|
||||||
|
parentID := n.object.GetGobjectId()
|
||||||
|
children, err := n.client.browseChildrenInner(ctx, &parentID, n.options)
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
n.mu.Lock()
|
||||||
|
n.children = children
|
||||||
|
n.isExpanded = true
|
||||||
|
n.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Publish result to waiters and clear the in-flight marker so a failed
|
||||||
|
// expansion can be retried by the next Expand call.
|
||||||
|
n.expandLock.Lock()
|
||||||
|
n.expandErr = err
|
||||||
|
n.expanding = false
|
||||||
|
close(done)
|
||||||
|
n.expandLock.Unlock()
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Browse returns the root nodes of the Galaxy hierarchy. The returned nodes
|
||||||
|
// have only their server-supplied hints populated; call Expand on each node to
|
||||||
|
// fetch its direct children. When opts is nil the server defaults apply.
|
||||||
|
func (c *GalaxyClient) Browse(ctx context.Context, opts *BrowseChildrenOptions) ([]*LazyBrowseNode, error) {
|
||||||
|
effective := BrowseChildrenOptions{}
|
||||||
|
if opts != nil {
|
||||||
|
effective = *opts
|
||||||
|
}
|
||||||
|
return c.browseChildrenInner(ctx, nil, effective)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BrowseChildrenRaw issues a single BrowseChildren RPC and returns the raw
|
||||||
|
// reply for callers that need direct page-token control. Transport-level
|
||||||
|
// failures are wrapped in *GatewayError to match the rest of the client.
|
||||||
|
func (c *GalaxyClient) BrowseChildrenRaw(ctx context.Context, req *pb.BrowseChildrenRequest) (*pb.BrowseChildrenReply, error) {
|
||||||
|
callCtx, cancel := c.callContext(ctx)
|
||||||
|
defer cancel()
|
||||||
|
reply, err := c.raw.BrowseChildren(callCtx, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, &GatewayError{Op: "galaxy browse children", Err: err}
|
||||||
|
}
|
||||||
|
return reply, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *GalaxyClient) browseChildrenInner(
|
||||||
|
ctx context.Context,
|
||||||
|
parentGobjectID *int32,
|
||||||
|
opts BrowseChildrenOptions,
|
||||||
|
) ([]*LazyBrowseNode, error) {
|
||||||
|
var nodes []*LazyBrowseNode
|
||||||
|
pageToken := ""
|
||||||
|
seen := map[string]struct{}{}
|
||||||
|
for {
|
||||||
|
req := &pb.BrowseChildrenRequest{
|
||||||
|
PageSize: browseChildrenPageSize,
|
||||||
|
PageToken: pageToken,
|
||||||
|
CategoryIds: opts.CategoryIds,
|
||||||
|
TemplateChainContains: opts.TemplateChainContains,
|
||||||
|
TagNameGlob: opts.TagNameGlob,
|
||||||
|
AlarmBearingOnly: opts.AlarmBearingOnly,
|
||||||
|
HistorizedOnly: opts.HistorizedOnly,
|
||||||
|
}
|
||||||
|
if parentGobjectID != nil {
|
||||||
|
req.Parent = &pb.BrowseChildrenRequest_ParentGobjectId{ParentGobjectId: *parentGobjectID}
|
||||||
|
}
|
||||||
|
if opts.IncludeAttributes != nil {
|
||||||
|
req.IncludeAttributes = opts.IncludeAttributes
|
||||||
|
}
|
||||||
|
|
||||||
|
reply, err := c.BrowseChildrenRaw(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, child := range reply.GetChildren() {
|
||||||
|
hasChildren := reply.GetChildHasChildren()
|
||||||
|
hint := i < len(hasChildren) && hasChildren[i]
|
||||||
|
nodes = append(nodes, &LazyBrowseNode{
|
||||||
|
client: c,
|
||||||
|
object: child,
|
||||||
|
hasChildrenHint: hint,
|
||||||
|
options: opts,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pageToken = reply.GetNextPageToken()
|
||||||
|
if pageToken == "" {
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
if _, dup := seen[pageToken]; dup {
|
||||||
|
return nil, &GatewayError{
|
||||||
|
Op: "galaxy browse children",
|
||||||
|
Err: fmt.Errorf("repeated page token %q", pageToken),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
seen[pageToken] = struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *GalaxyClient) callContext(ctx context.Context) (context.Context, context.CancelFunc) {
|
func (c *GalaxyClient) callContext(ctx context.Context) (context.Context, context.CancelFunc) {
|
||||||
timeout := c.opts.CallTimeout
|
timeout := c.opts.CallTimeout
|
||||||
if timeout == 0 {
|
if timeout == 0 {
|
||||||
|
|||||||
@@ -4,11 +4,14 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
pb "gitea.dohertylan.com/dohertj2/mxaccessgw/clients/go/internal/generated"
|
pb "gitea.dohertylan.com/dohertj2/mxaccessgw/clients/go/internal/generated"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
"google.golang.org/grpc/test/bufconn"
|
"google.golang.org/grpc/test/bufconn"
|
||||||
"google.golang.org/protobuf/types/known/timestamppb"
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
)
|
)
|
||||||
@@ -55,8 +58,8 @@ func TestGalaxyGetLastDeployTimeReturnsTimestampWhenPresent(t *testing.T) {
|
|||||||
want := time.Date(2026, 4, 28, 12, 34, 56, 0, time.UTC)
|
want := time.Date(2026, 4, 28, 12, 34, 56, 0, time.UTC)
|
||||||
fake := &fakeGalaxyServer{
|
fake := &fakeGalaxyServer{
|
||||||
deployReply: &pb.GetLastDeployTimeReply{
|
deployReply: &pb.GetLastDeployTimeReply{
|
||||||
Present: true,
|
Present: true,
|
||||||
TimeOfLastDeploy: timestamppb.New(want),
|
TimeOfLastDeploy: timestamppb.New(want),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
client, cleanup := newGalaxyBufconnClient(t, fake)
|
client, cleanup := newGalaxyBufconnClient(t, fake)
|
||||||
@@ -144,6 +147,47 @@ func TestGalaxyDiscoverHierarchyReturnsObjects(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGalaxyDiscoverHierarchyPaginatesAcrossMultiplePages(t *testing.T) {
|
||||||
|
page1 := &pb.DiscoverHierarchyReply{
|
||||||
|
Objects: []*pb.GalaxyObject{
|
||||||
|
{GobjectId: 1, TagName: "A"},
|
||||||
|
{GobjectId: 2, TagName: "B"},
|
||||||
|
},
|
||||||
|
NextPageToken: "page-2",
|
||||||
|
TotalObjectCount: 3,
|
||||||
|
}
|
||||||
|
page2 := &pb.DiscoverHierarchyReply{
|
||||||
|
Objects: []*pb.GalaxyObject{
|
||||||
|
{GobjectId: 3, TagName: "C"},
|
||||||
|
},
|
||||||
|
TotalObjectCount: 3,
|
||||||
|
}
|
||||||
|
fake := &fakeGalaxyServer{
|
||||||
|
discoverHierarchyReplies: []*pb.DiscoverHierarchyReply{page1, page2},
|
||||||
|
}
|
||||||
|
client, cleanup := newGalaxyBufconnClient(t, fake)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
objs, err := client.DiscoverHierarchy(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("DiscoverHierarchy: %v", err)
|
||||||
|
}
|
||||||
|
if got, want := len(objs), 3; got != want {
|
||||||
|
t.Fatalf("len(objs) = %d, want %d", got, want)
|
||||||
|
}
|
||||||
|
if len(fake.discoverHierarchyCalls) != 2 {
|
||||||
|
t.Fatalf("expected 2 RPC calls, got %d", len(fake.discoverHierarchyCalls))
|
||||||
|
}
|
||||||
|
if fake.discoverHierarchyCalls[0].GetPageSize() != discoverHierarchyPageSize {
|
||||||
|
t.Fatalf("first call PageSize = %d, want %d",
|
||||||
|
fake.discoverHierarchyCalls[0].GetPageSize(), discoverHierarchyPageSize)
|
||||||
|
}
|
||||||
|
if fake.discoverHierarchyCalls[1].GetPageToken() != "page-2" {
|
||||||
|
t.Fatalf("second call page token = %q, want %q",
|
||||||
|
fake.discoverHierarchyCalls[1].GetPageToken(), "page-2")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestGalaxyDialReturnsGatewayErrorOnRpcFailure(t *testing.T) {
|
func TestGalaxyDialReturnsGatewayErrorOnRpcFailure(t *testing.T) {
|
||||||
fake := &fakeGalaxyServer{failTest: true}
|
fake := &fakeGalaxyServer{failTest: true}
|
||||||
client, cleanup := newGalaxyBufconnClient(t, fake)
|
client, cleanup := newGalaxyBufconnClient(t, fake)
|
||||||
@@ -370,15 +414,20 @@ func newGalaxyBufconnClient(t *testing.T, fake *fakeGalaxyServer) (*GalaxyClient
|
|||||||
type fakeGalaxyServer struct {
|
type fakeGalaxyServer struct {
|
||||||
pb.UnimplementedGalaxyRepositoryServer
|
pb.UnimplementedGalaxyRepositoryServer
|
||||||
|
|
||||||
testReply *pb.TestConnectionReply
|
testReply *pb.TestConnectionReply
|
||||||
testAuth string
|
testAuth string
|
||||||
failTest bool
|
failTest bool
|
||||||
deployReply *pb.GetLastDeployTimeReply
|
deployReply *pb.GetLastDeployTimeReply
|
||||||
discoverReply *pb.DiscoverHierarchyReply
|
discoverReply *pb.DiscoverHierarchyReply
|
||||||
watchEvents []*pb.DeployEvent
|
discoverHierarchyCalls []*pb.DiscoverHierarchyRequest
|
||||||
watchRequest *pb.WatchDeployEventsRequest
|
discoverHierarchyReplies []*pb.DiscoverHierarchyReply
|
||||||
watchSendInterval time.Duration
|
watchEvents []*pb.DeployEvent
|
||||||
watchHoldOpen bool
|
watchRequest *pb.WatchDeployEventsRequest
|
||||||
|
watchSendInterval time.Duration
|
||||||
|
watchHoldOpen bool
|
||||||
|
browseChildrenCalls []*pb.BrowseChildrenRequest
|
||||||
|
browseChildrenReplies []*pb.BrowseChildrenReply
|
||||||
|
browseChildrenError error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *fakeGalaxyServer) TestConnection(ctx context.Context, req *pb.TestConnectionRequest) (*pb.TestConnectionReply, error) {
|
func (s *fakeGalaxyServer) TestConnection(ctx context.Context, req *pb.TestConnectionRequest) (*pb.TestConnectionReply, error) {
|
||||||
@@ -400,6 +449,12 @@ func (s *fakeGalaxyServer) GetLastDeployTime(ctx context.Context, req *pb.GetLas
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *fakeGalaxyServer) DiscoverHierarchy(ctx context.Context, req *pb.DiscoverHierarchyRequest) (*pb.DiscoverHierarchyReply, error) {
|
func (s *fakeGalaxyServer) DiscoverHierarchy(ctx context.Context, req *pb.DiscoverHierarchyRequest) (*pb.DiscoverHierarchyReply, error) {
|
||||||
|
s.discoverHierarchyCalls = append(s.discoverHierarchyCalls, req)
|
||||||
|
if len(s.discoverHierarchyReplies) > 0 {
|
||||||
|
reply := s.discoverHierarchyReplies[0]
|
||||||
|
s.discoverHierarchyReplies = s.discoverHierarchyReplies[1:]
|
||||||
|
return reply, nil
|
||||||
|
}
|
||||||
if s.discoverReply != nil {
|
if s.discoverReply != nil {
|
||||||
return s.discoverReply, nil
|
return s.discoverReply, nil
|
||||||
}
|
}
|
||||||
@@ -425,3 +480,385 @@ func (s *fakeGalaxyServer) WatchDeployEvents(req *pb.WatchDeployEventsRequest, s
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *fakeGalaxyServer) BrowseChildren(ctx context.Context, req *pb.BrowseChildrenRequest) (*pb.BrowseChildrenReply, error) {
|
||||||
|
s.browseChildrenCalls = append(s.browseChildrenCalls, req)
|
||||||
|
if s.browseChildrenError != nil {
|
||||||
|
err := s.browseChildrenError
|
||||||
|
s.browseChildrenError = nil
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(s.browseChildrenReplies) == 0 {
|
||||||
|
return &pb.BrowseChildrenReply{}, nil
|
||||||
|
}
|
||||||
|
reply := s.browseChildrenReplies[0]
|
||||||
|
s.browseChildrenReplies = s.browseChildrenReplies[1:]
|
||||||
|
return reply, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func obj(id int32, tag string, isArea bool) *pb.GalaxyObject {
|
||||||
|
return &pb.GalaxyObject{
|
||||||
|
GobjectId: id,
|
||||||
|
TagName: tag,
|
||||||
|
BrowseName: tag,
|
||||||
|
IsArea: isArea,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildBrowseReply(children []*pb.GalaxyObject, hasChildren []bool, seq uint64) *pb.BrowseChildrenReply {
|
||||||
|
return &pb.BrowseChildrenReply{
|
||||||
|
TotalChildCount: int32(len(children)),
|
||||||
|
CacheSequence: seq,
|
||||||
|
Children: children,
|
||||||
|
ChildHasChildren: hasChildren,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGalaxyBrowseNoParentReturnsRoots(t *testing.T) {
|
||||||
|
fake := &fakeGalaxyServer{
|
||||||
|
browseChildrenReplies: []*pb.BrowseChildrenReply{
|
||||||
|
buildBrowseReply(
|
||||||
|
[]*pb.GalaxyObject{obj(1, "Plant", true), obj(99, "Other", false)},
|
||||||
|
[]bool{true, false},
|
||||||
|
7,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
client, cleanup := newGalaxyBufconnClient(t, fake)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
roots, err := client.Browse(context.Background(), nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Browse: %v", err)
|
||||||
|
}
|
||||||
|
if got, want := len(roots), 2; got != want {
|
||||||
|
t.Fatalf("len(roots) = %d, want %d", got, want)
|
||||||
|
}
|
||||||
|
if roots[0].Object().GetTagName() != "Plant" {
|
||||||
|
t.Fatalf("roots[0].TagName = %q", roots[0].Object().GetTagName())
|
||||||
|
}
|
||||||
|
if !roots[0].HasChildrenHint() {
|
||||||
|
t.Fatal("roots[0].HasChildrenHint = false, want true")
|
||||||
|
}
|
||||||
|
if roots[0].IsExpanded() {
|
||||||
|
t.Fatal("roots[0].IsExpanded = true, want false")
|
||||||
|
}
|
||||||
|
if roots[1].HasChildrenHint() {
|
||||||
|
t.Fatal("roots[1].HasChildrenHint = true, want false")
|
||||||
|
}
|
||||||
|
if len(fake.browseChildrenCalls) != 1 {
|
||||||
|
t.Fatalf("BrowseChildren calls = %d, want 1", len(fake.browseChildrenCalls))
|
||||||
|
}
|
||||||
|
if fake.browseChildrenCalls[0].GetParent() != nil {
|
||||||
|
t.Fatalf("root browse should not set Parent oneof, got %T", fake.browseChildrenCalls[0].GetParent())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGalaxyBrowseExpandPopulatesChildrenAndMarksExpanded(t *testing.T) {
|
||||||
|
fake := &fakeGalaxyServer{
|
||||||
|
browseChildrenReplies: []*pb.BrowseChildrenReply{
|
||||||
|
buildBrowseReply(
|
||||||
|
[]*pb.GalaxyObject{obj(1, "Plant", true)},
|
||||||
|
[]bool{true},
|
||||||
|
1,
|
||||||
|
),
|
||||||
|
buildBrowseReply(
|
||||||
|
[]*pb.GalaxyObject{obj(10, "Area1", true), obj(11, "Tank1", false)},
|
||||||
|
[]bool{true, false},
|
||||||
|
1,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
client, cleanup := newGalaxyBufconnClient(t, fake)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
roots, err := client.Browse(context.Background(), nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Browse: %v", err)
|
||||||
|
}
|
||||||
|
if len(roots) != 1 {
|
||||||
|
t.Fatalf("len(roots) = %d, want 1", len(roots))
|
||||||
|
}
|
||||||
|
plant := roots[0]
|
||||||
|
if plant.IsExpanded() {
|
||||||
|
t.Fatal("plant.IsExpanded = true before Expand, want false")
|
||||||
|
}
|
||||||
|
if err := plant.Expand(context.Background()); err != nil {
|
||||||
|
t.Fatalf("Expand: %v", err)
|
||||||
|
}
|
||||||
|
if !plant.IsExpanded() {
|
||||||
|
t.Fatal("plant.IsExpanded = false after Expand, want true")
|
||||||
|
}
|
||||||
|
children := plant.Children()
|
||||||
|
if len(children) != 2 {
|
||||||
|
t.Fatalf("len(children) = %d, want 2", len(children))
|
||||||
|
}
|
||||||
|
if children[0].Object().GetTagName() != "Area1" {
|
||||||
|
t.Fatalf("children[0].TagName = %q, want Area1", children[0].Object().GetTagName())
|
||||||
|
}
|
||||||
|
if !children[0].HasChildrenHint() {
|
||||||
|
t.Fatal("children[0].HasChildrenHint = false, want true")
|
||||||
|
}
|
||||||
|
if children[1].HasChildrenHint() {
|
||||||
|
t.Fatal("children[1].HasChildrenHint = true, want false")
|
||||||
|
}
|
||||||
|
if len(fake.browseChildrenCalls) != 2 {
|
||||||
|
t.Fatalf("BrowseChildren calls = %d, want 2", len(fake.browseChildrenCalls))
|
||||||
|
}
|
||||||
|
parent := fake.browseChildrenCalls[1].GetParent()
|
||||||
|
parentGobj, ok := parent.(*pb.BrowseChildrenRequest_ParentGobjectId)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("Parent oneof = %T, want *BrowseChildrenRequest_ParentGobjectId", parent)
|
||||||
|
}
|
||||||
|
if parentGobj.ParentGobjectId != 1 {
|
||||||
|
t.Fatalf("ParentGobjectId = %d, want 1", parentGobj.ParentGobjectId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGalaxyBrowseExpandIdempotentNoSecondRpc(t *testing.T) {
|
||||||
|
fake := &fakeGalaxyServer{
|
||||||
|
browseChildrenReplies: []*pb.BrowseChildrenReply{
|
||||||
|
buildBrowseReply(
|
||||||
|
[]*pb.GalaxyObject{obj(1, "Plant", true)},
|
||||||
|
[]bool{true},
|
||||||
|
1,
|
||||||
|
),
|
||||||
|
buildBrowseReply(
|
||||||
|
[]*pb.GalaxyObject{obj(10, "Area1", true)},
|
||||||
|
[]bool{false},
|
||||||
|
1,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
client, cleanup := newGalaxyBufconnClient(t, fake)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
roots, err := client.Browse(context.Background(), nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Browse: %v", err)
|
||||||
|
}
|
||||||
|
plant := roots[0]
|
||||||
|
if err := plant.Expand(context.Background()); err != nil {
|
||||||
|
t.Fatalf("Expand #1: %v", err)
|
||||||
|
}
|
||||||
|
callsAfterFirst := len(fake.browseChildrenCalls)
|
||||||
|
if callsAfterFirst != 2 {
|
||||||
|
t.Fatalf("BrowseChildren calls after first Expand = %d, want 2", callsAfterFirst)
|
||||||
|
}
|
||||||
|
if err := plant.Expand(context.Background()); err != nil {
|
||||||
|
t.Fatalf("Expand #2: %v", err)
|
||||||
|
}
|
||||||
|
if got := len(fake.browseChildrenCalls); got != callsAfterFirst {
|
||||||
|
t.Fatalf("BrowseChildren calls after second Expand = %d, want %d (no extra RPC)", got, callsAfterFirst)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGalaxyBrowseExpandUnknownParentReturnsNotFoundError(t *testing.T) {
|
||||||
|
fake := &fakeGalaxyServer{
|
||||||
|
browseChildrenReplies: []*pb.BrowseChildrenReply{
|
||||||
|
buildBrowseReply(
|
||||||
|
[]*pb.GalaxyObject{obj(1, "Plant", true)},
|
||||||
|
[]bool{true},
|
||||||
|
1,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
browseChildrenError: status.Error(codes.NotFound, "parent not found"),
|
||||||
|
}
|
||||||
|
// The first Browse() consumes the first reply; the next call (Expand) will
|
||||||
|
// then hit browseChildrenError. We need the error to fire only on the second
|
||||||
|
// call, so seed the reply first and let the call sequence consume them in
|
||||||
|
// order. Because BrowseChildren in the fake consumes browseChildrenError
|
||||||
|
// before falling through to replies, swap the strategy: keep the root reply
|
||||||
|
// but have BrowseChildren return the error on the second call. We do this by
|
||||||
|
// emptying the reply list after the first Browse.
|
||||||
|
client, cleanup := newGalaxyBufconnClient(t, fake)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
// First call returns the error (because browseChildrenError takes precedence).
|
||||||
|
// To avoid that, clear it for the root call by performing a manual setup: we
|
||||||
|
// pre-stage replies first, then set the error after the first call. Easiest:
|
||||||
|
// pre-Browse() with error=nil, then set error before Expand.
|
||||||
|
fake.browseChildrenError = nil
|
||||||
|
roots, err := client.Browse(context.Background(), nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Browse: %v", err)
|
||||||
|
}
|
||||||
|
if len(roots) != 1 {
|
||||||
|
t.Fatalf("len(roots) = %d, want 1", len(roots))
|
||||||
|
}
|
||||||
|
fake.browseChildrenError = status.Error(codes.NotFound, "parent not found")
|
||||||
|
|
||||||
|
err = roots[0].Expand(context.Background())
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("Expand: error = nil, want NotFound")
|
||||||
|
}
|
||||||
|
if status.Code(err) != codes.NotFound {
|
||||||
|
t.Fatalf("status.Code = %s, want NotFound", status.Code(err))
|
||||||
|
}
|
||||||
|
if roots[0].IsExpanded() {
|
||||||
|
t.Fatal("roots[0].IsExpanded = true after failed Expand, want false")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGalaxyBrowseExpandMultiPageGathersAllPages(t *testing.T) {
|
||||||
|
firstPage := buildBrowseReply(
|
||||||
|
[]*pb.GalaxyObject{obj(1, "Plant", true)},
|
||||||
|
[]bool{true},
|
||||||
|
7,
|
||||||
|
)
|
||||||
|
|
||||||
|
pageA := buildBrowseReply(
|
||||||
|
[]*pb.GalaxyObject{obj(10, "Child1", false), obj(11, "Child2", false)},
|
||||||
|
[]bool{false, false},
|
||||||
|
7,
|
||||||
|
)
|
||||||
|
pageA.NextPageToken = "7:abc:2"
|
||||||
|
pageB := buildBrowseReply(
|
||||||
|
[]*pb.GalaxyObject{obj(12, "Child3", false)},
|
||||||
|
[]bool{false},
|
||||||
|
7,
|
||||||
|
)
|
||||||
|
|
||||||
|
fake := &fakeGalaxyServer{
|
||||||
|
browseChildrenReplies: []*pb.BrowseChildrenReply{firstPage, pageA, pageB},
|
||||||
|
}
|
||||||
|
client, cleanup := newGalaxyBufconnClient(t, fake)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
roots, err := client.Browse(context.Background(), nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Browse: %v", err)
|
||||||
|
}
|
||||||
|
if err := roots[0].Expand(context.Background()); err != nil {
|
||||||
|
t.Fatalf("Expand: %v", err)
|
||||||
|
}
|
||||||
|
children := roots[0].Children()
|
||||||
|
if len(children) != 3 {
|
||||||
|
t.Fatalf("len(children) = %d, want 3", len(children))
|
||||||
|
}
|
||||||
|
if len(fake.browseChildrenCalls) != 3 {
|
||||||
|
t.Fatalf("BrowseChildren calls = %d, want 3", len(fake.browseChildrenCalls))
|
||||||
|
}
|
||||||
|
if got := fake.browseChildrenCalls[2].GetPageToken(); got != "7:abc:2" {
|
||||||
|
t.Fatalf("third call PageToken = %q, want %q", got, "7:abc:2")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGalaxyBrowseWithFilterForwardsToRequest(t *testing.T) {
|
||||||
|
fake := &fakeGalaxyServer{
|
||||||
|
browseChildrenReplies: []*pb.BrowseChildrenReply{
|
||||||
|
buildBrowseReply(nil, nil, 1),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
client, cleanup := newGalaxyBufconnClient(t, fake)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
include := true
|
||||||
|
opts := &BrowseChildrenOptions{
|
||||||
|
CategoryIds: []int32{7, 9},
|
||||||
|
TemplateChainContains: []string{"$AppObject"},
|
||||||
|
TagNameGlob: "Tank*",
|
||||||
|
IncludeAttributes: &include,
|
||||||
|
AlarmBearingOnly: true,
|
||||||
|
HistorizedOnly: true,
|
||||||
|
}
|
||||||
|
if _, err := client.Browse(context.Background(), opts); err != nil {
|
||||||
|
t.Fatalf("Browse: %v", err)
|
||||||
|
}
|
||||||
|
if len(fake.browseChildrenCalls) != 1 {
|
||||||
|
t.Fatalf("BrowseChildren calls = %d, want 1", len(fake.browseChildrenCalls))
|
||||||
|
}
|
||||||
|
got := fake.browseChildrenCalls[0]
|
||||||
|
if want := []int32{7, 9}; len(got.GetCategoryIds()) != 2 || got.GetCategoryIds()[0] != want[0] || got.GetCategoryIds()[1] != want[1] {
|
||||||
|
t.Fatalf("CategoryIds = %v, want %v", got.GetCategoryIds(), want)
|
||||||
|
}
|
||||||
|
if want := []string{"$AppObject"}; len(got.GetTemplateChainContains()) != 1 || got.GetTemplateChainContains()[0] != want[0] {
|
||||||
|
t.Fatalf("TemplateChainContains = %v, want %v", got.GetTemplateChainContains(), want)
|
||||||
|
}
|
||||||
|
if got.GetTagNameGlob() != "Tank*" {
|
||||||
|
t.Fatalf("TagNameGlob = %q, want %q", got.GetTagNameGlob(), "Tank*")
|
||||||
|
}
|
||||||
|
if !got.GetIncludeAttributes() {
|
||||||
|
t.Fatal("IncludeAttributes = false, want true")
|
||||||
|
}
|
||||||
|
if !got.GetAlarmBearingOnly() {
|
||||||
|
t.Fatal("AlarmBearingOnly = false, want true")
|
||||||
|
}
|
||||||
|
if !got.GetHistorizedOnly() {
|
||||||
|
t.Fatal("HistorizedOnly = false, want true")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGalaxyBrowseExpandConcurrentCallersOnlyFireOneRpc(t *testing.T) {
|
||||||
|
fake := &fakeGalaxyServer{
|
||||||
|
browseChildrenReplies: []*pb.BrowseChildrenReply{
|
||||||
|
// roots
|
||||||
|
buildBrowseReply([]*pb.GalaxyObject{obj(1, "Plant", true)}, []bool{true}, 7),
|
||||||
|
// one expand: one child
|
||||||
|
buildBrowseReply([]*pb.GalaxyObject{obj(2, "Mixer", false)}, []bool{false}, 7),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
client, cleanup := newGalaxyBufconnClient(t, fake)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
roots, err := client.Browse(ctx, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Browse: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
errs := make(chan error, 10)
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
errs <- roots[0].Expand(ctx)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
close(errs)
|
||||||
|
for err := range errs {
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("concurrent Expand: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !roots[0].IsExpanded() {
|
||||||
|
t.Fatal("IsExpanded() = false after 10 concurrent expands")
|
||||||
|
}
|
||||||
|
if got, want := len(roots[0].Children()), 1; got != want {
|
||||||
|
t.Fatalf("len(children) = %d, want %d", got, want)
|
||||||
|
}
|
||||||
|
// 1 roots fetch + exactly 1 expand fetch.
|
||||||
|
if got, want := len(fake.browseChildrenCalls), 2; got != want {
|
||||||
|
t.Fatalf("RPC count = %d, want %d", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGalaxyBrowseChildrenRejectsRepeatedPageToken(t *testing.T) {
|
||||||
|
// Build a reply that carries a non-empty NextPageToken so browseChildrenInner
|
||||||
|
// will request a second page. Queue the same reply twice so the second response
|
||||||
|
// returns the same page token, triggering the duplicate-token guard.
|
||||||
|
page := buildBrowseReply(
|
||||||
|
[]*pb.GalaxyObject{obj(1, "Plant", true)},
|
||||||
|
[]bool{true},
|
||||||
|
1,
|
||||||
|
)
|
||||||
|
page.NextPageToken = "1:abc:1"
|
||||||
|
|
||||||
|
fake := &fakeGalaxyServer{
|
||||||
|
browseChildrenReplies: []*pb.BrowseChildrenReply{page, page},
|
||||||
|
}
|
||||||
|
client, cleanup := newGalaxyBufconnClient(t, fake)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
_, err := client.Browse(context.Background(), nil)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("Browse: error = nil, want repeated-page-token error")
|
||||||
|
}
|
||||||
|
var gwErr *GatewayError
|
||||||
|
if !errors.As(err, &gwErr) {
|
||||||
|
t.Fatalf("error type = %T, want *GatewayError; err = %v", err, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -34,6 +34,32 @@ type Options struct {
|
|||||||
TransportCredentials credentials.TransportCredentials
|
TransportCredentials credentials.TransportCredentials
|
||||||
// DialOptions are appended to the gRPC dial options after the defaults.
|
// DialOptions are appended to the gRPC dial options after the defaults.
|
||||||
DialOptions []grpc.DialOption
|
DialOptions []grpc.DialOption
|
||||||
|
// RequireCertificateValidation forces TLS certificate verification even when
|
||||||
|
// no CACertFile is pinned. Default false: the gateway's self-signed cert is
|
||||||
|
// accepted without verification (internal-tool posture).
|
||||||
|
RequireCertificateValidation bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// BrowseChildrenOptions configures lazy Galaxy hierarchy walks performed by
|
||||||
|
// (*GalaxyClient).Browse and (*LazyBrowseNode).Expand. All fields are optional;
|
||||||
|
// the zero value matches the dashboard default (no filters, all attributes per
|
||||||
|
// the server default).
|
||||||
|
type BrowseChildrenOptions struct {
|
||||||
|
// CategoryIds restricts results to the listed Galaxy category ids when set.
|
||||||
|
CategoryIds []int32
|
||||||
|
// TemplateChainContains restricts results to objects whose template chain
|
||||||
|
// contains any of the listed template tag names.
|
||||||
|
TemplateChainContains []string
|
||||||
|
// TagNameGlob restricts results to objects whose tag name matches the glob
|
||||||
|
// pattern when non-empty.
|
||||||
|
TagNameGlob string
|
||||||
|
// IncludeAttributes overrides the server default for attribute inclusion when
|
||||||
|
// non-nil. The pointer form mirrors the proto's optional field.
|
||||||
|
IncludeAttributes *bool
|
||||||
|
// AlarmBearingOnly limits results to alarm-bearing objects when true.
|
||||||
|
AlarmBearingOnly bool
|
||||||
|
// HistorizedOnly limits results to historized objects when true.
|
||||||
|
HistorizedOnly bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// RedactedAPIKey returns a display-safe representation of the configured API
|
// RedactedAPIKey returns a display-safe representation of the configured API
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
pb "gitea.dohertylan.com/dohertj2/mxaccessgw/clients/go/internal/generated"
|
pb "gitea.dohertylan.com/dohertj2/mxaccessgw/clients/go/internal/generated"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
@@ -387,6 +389,173 @@ func (s *Session) UnsubscribeBulk(ctx context.Context, serverHandle int32, itemH
|
|||||||
return reply.GetUnsubscribeBulk().GetResults(), nil
|
return reply.GetUnsubscribeBulk().GetResults(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WriteBulk invokes MXAccess Write sequentially for each entry inside one gateway command.
|
||||||
|
// Per-entry failures appear as BulkWriteResult entries with WasSuccessful=false; the call
|
||||||
|
// never returns an error for per-entry MXAccess failures (it returns an error only for
|
||||||
|
// protocol-level failures or transport errors).
|
||||||
|
//
|
||||||
|
// A non-nil but empty entries slice is treated as a no-op and returns an empty result
|
||||||
|
// without a wire round-trip; pass nil to surface a clear "entries are required" error.
|
||||||
|
func (s *Session) WriteBulk(ctx context.Context, serverHandle int32, entries []*WriteBulkEntry) ([]*BulkWriteResult, error) {
|
||||||
|
if entries == nil {
|
||||||
|
return nil, errors.New("mxgateway: write bulk entries are required")
|
||||||
|
}
|
||||||
|
if err := ensureBulkSize("write bulk entries", len(entries)); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(entries) == 0 {
|
||||||
|
return []*BulkWriteResult{}, nil
|
||||||
|
}
|
||||||
|
reply, err := s.invokeCommand(ctx, &pb.MxCommand{
|
||||||
|
Kind: pb.MxCommandKind_MX_COMMAND_KIND_WRITE_BULK,
|
||||||
|
Payload: &pb.MxCommand_WriteBulk{
|
||||||
|
WriteBulk: &pb.WriteBulkCommand{
|
||||||
|
ServerHandle: serverHandle,
|
||||||
|
Entries: entries,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return reply.GetWriteBulk().GetResults(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write2Bulk invokes MXAccess Write2 (timestamped) for each entry inside one gateway command.
|
||||||
|
//
|
||||||
|
// A non-nil but empty entries slice is treated as a no-op and returns an empty result
|
||||||
|
// without a wire round-trip; pass nil to surface a clear "entries are required" error.
|
||||||
|
func (s *Session) Write2Bulk(ctx context.Context, serverHandle int32, entries []*Write2BulkEntry) ([]*BulkWriteResult, error) {
|
||||||
|
if entries == nil {
|
||||||
|
return nil, errors.New("mxgateway: write2 bulk entries are required")
|
||||||
|
}
|
||||||
|
if err := ensureBulkSize("write2 bulk entries", len(entries)); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(entries) == 0 {
|
||||||
|
return []*BulkWriteResult{}, nil
|
||||||
|
}
|
||||||
|
reply, err := s.invokeCommand(ctx, &pb.MxCommand{
|
||||||
|
Kind: pb.MxCommandKind_MX_COMMAND_KIND_WRITE2_BULK,
|
||||||
|
Payload: &pb.MxCommand_Write2Bulk{
|
||||||
|
Write2Bulk: &pb.Write2BulkCommand{
|
||||||
|
ServerHandle: serverHandle,
|
||||||
|
Entries: entries,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return reply.GetWrite2Bulk().GetResults(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteSecuredBulk invokes MXAccess WriteSecured for each entry. Credential-sensitive
|
||||||
|
// values must not be logged by callers; mirrors the single-item WriteSecured contract.
|
||||||
|
//
|
||||||
|
// A non-nil but empty entries slice is treated as a no-op and returns an empty result
|
||||||
|
// without a wire round-trip; pass nil to surface a clear "entries are required" error.
|
||||||
|
func (s *Session) WriteSecuredBulk(ctx context.Context, serverHandle int32, entries []*WriteSecuredBulkEntry) ([]*BulkWriteResult, error) {
|
||||||
|
if entries == nil {
|
||||||
|
return nil, errors.New("mxgateway: write-secured bulk entries are required")
|
||||||
|
}
|
||||||
|
if err := ensureBulkSize("write-secured bulk entries", len(entries)); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(entries) == 0 {
|
||||||
|
return []*BulkWriteResult{}, nil
|
||||||
|
}
|
||||||
|
reply, err := s.invokeCommand(ctx, &pb.MxCommand{
|
||||||
|
Kind: pb.MxCommandKind_MX_COMMAND_KIND_WRITE_SECURED_BULK,
|
||||||
|
Payload: &pb.MxCommand_WriteSecuredBulk{
|
||||||
|
WriteSecuredBulk: &pb.WriteSecuredBulkCommand{
|
||||||
|
ServerHandle: serverHandle,
|
||||||
|
Entries: entries,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return reply.GetWriteSecuredBulk().GetResults(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteSecured2Bulk invokes MXAccess WriteSecured2 (timestamped) for each entry.
|
||||||
|
//
|
||||||
|
// A non-nil but empty entries slice is treated as a no-op and returns an empty result
|
||||||
|
// without a wire round-trip; pass nil to surface a clear "entries are required" error.
|
||||||
|
func (s *Session) WriteSecured2Bulk(ctx context.Context, serverHandle int32, entries []*WriteSecured2BulkEntry) ([]*BulkWriteResult, error) {
|
||||||
|
if entries == nil {
|
||||||
|
return nil, errors.New("mxgateway: write-secured2 bulk entries are required")
|
||||||
|
}
|
||||||
|
if err := ensureBulkSize("write-secured2 bulk entries", len(entries)); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(entries) == 0 {
|
||||||
|
return []*BulkWriteResult{}, nil
|
||||||
|
}
|
||||||
|
reply, err := s.invokeCommand(ctx, &pb.MxCommand{
|
||||||
|
Kind: pb.MxCommandKind_MX_COMMAND_KIND_WRITE_SECURED2_BULK,
|
||||||
|
Payload: &pb.MxCommand_WriteSecured2Bulk{
|
||||||
|
WriteSecured2Bulk: &pb.WriteSecured2BulkCommand{
|
||||||
|
ServerHandle: serverHandle,
|
||||||
|
Entries: entries,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return reply.GetWriteSecured2Bulk().GetResults(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadBulk snapshots the current value of each requested tag.
|
||||||
|
//
|
||||||
|
// MXAccess COM has no synchronous Read; the worker satisfies this by returning the
|
||||||
|
// most recent cached OnDataChange value when the tag is already advised (WasCached=true),
|
||||||
|
// or by taking a full AddItem + Advise + wait + UnAdvise + RemoveItem snapshot lifecycle
|
||||||
|
// otherwise. timeout bounds the wait per tag in the snapshot case; pass zero to use the
|
||||||
|
// worker default. Per-tag failures (timeout, invalid tag) appear as BulkReadResult entries
|
||||||
|
// with WasSuccessful=false; the call never returns an error for per-tag MXAccess failures.
|
||||||
|
//
|
||||||
|
// A non-nil but empty tagAddresses slice is treated as a no-op and returns an empty
|
||||||
|
// result without a wire round-trip; pass nil to surface a clear "tag addresses are
|
||||||
|
// required" error.
|
||||||
|
func (s *Session) ReadBulk(ctx context.Context, serverHandle int32, tagAddresses []string, timeout time.Duration) ([]*BulkReadResult, error) {
|
||||||
|
if tagAddresses == nil {
|
||||||
|
return nil, errors.New("mxgateway: tag addresses are required")
|
||||||
|
}
|
||||||
|
if err := ensureBulkSize("tag addresses", len(tagAddresses)); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(tagAddresses) == 0 {
|
||||||
|
return []*BulkReadResult{}, nil
|
||||||
|
}
|
||||||
|
var timeoutMs uint32
|
||||||
|
if timeout > 0 {
|
||||||
|
ms := timeout.Milliseconds()
|
||||||
|
if ms > int64(^uint32(0)) {
|
||||||
|
timeoutMs = ^uint32(0)
|
||||||
|
} else {
|
||||||
|
timeoutMs = uint32(ms)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reply, err := s.invokeCommand(ctx, &pb.MxCommand{
|
||||||
|
Kind: pb.MxCommandKind_MX_COMMAND_KIND_READ_BULK,
|
||||||
|
Payload: &pb.MxCommand_ReadBulk{
|
||||||
|
ReadBulk: &pb.ReadBulkCommand{
|
||||||
|
ServerHandle: serverHandle,
|
||||||
|
TagAddresses: tagAddresses,
|
||||||
|
TimeoutMs: timeoutMs,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return reply.GetReadBulk().GetResults(), nil
|
||||||
|
}
|
||||||
|
|
||||||
// Write invokes MXAccess Write.
|
// Write invokes MXAccess Write.
|
||||||
func (s *Session) Write(ctx context.Context, serverHandle, itemHandle int32, value *MxValue, userID int32) error {
|
func (s *Session) Write(ctx context.Context, serverHandle, itemHandle int32, value *MxValue, userID int32) error {
|
||||||
_, err := s.WriteRaw(ctx, serverHandle, itemHandle, value, userID)
|
_, err := s.WriteRaw(ctx, serverHandle, itemHandle, value, userID)
|
||||||
@@ -412,6 +581,97 @@ func (s *Session) WriteRaw(ctx context.Context, serverHandle, itemHandle int32,
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WriteArrayElements writes a sparse, default-filled array: only the given
|
||||||
|
// elements (index → scalar value) are set; every unmentioned index up to
|
||||||
|
// totalLength is written as the element type's default (false / 0 / "" / Unix
|
||||||
|
// epoch for time). The gateway expands the sparse representation into a full
|
||||||
|
// array write before forwarding to MXAccess — this is a RESET of unmentioned
|
||||||
|
// indices, not a preserve. Neither RESET semantics nor the original array
|
||||||
|
// content are retained.
|
||||||
|
//
|
||||||
|
// elementDataType must be a scalar MXAccess type (Boolean, Integer, Float,
|
||||||
|
// Double, String, or Time). totalLength must be at least as large as the
|
||||||
|
// highest index in elements plus one.
|
||||||
|
func (s *Session) WriteArrayElements(
|
||||||
|
ctx context.Context,
|
||||||
|
serverHandle, itemHandle int32,
|
||||||
|
elementDataType MxDataType,
|
||||||
|
totalLength uint32,
|
||||||
|
elements map[uint32]*MxValue,
|
||||||
|
userID int32,
|
||||||
|
) error {
|
||||||
|
return s.Write(ctx, serverHandle, itemHandle, buildSparseArrayValue(elementDataType, totalLength, elements), userID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// buildSparseArrayValue constructs the MxValue carrying an MxSparseArray oneof
|
||||||
|
// arm from a map of index → scalar MxValue. Keys are visited in ascending
|
||||||
|
// order so the produced slice is deterministic (important for test assertions).
|
||||||
|
func buildSparseArrayValue(elementDataType MxDataType, totalLength uint32, elements map[uint32]*MxValue) *MxValue {
|
||||||
|
indices := make([]uint32, 0, len(elements))
|
||||||
|
for idx := range elements {
|
||||||
|
indices = append(indices, idx)
|
||||||
|
}
|
||||||
|
sort.Slice(indices, func(i, j int) bool { return indices[i] < indices[j] })
|
||||||
|
|
||||||
|
sparseElements := make([]*MxSparseElement, 0, len(elements))
|
||||||
|
for _, idx := range indices {
|
||||||
|
sparseElements = append(sparseElements, &MxSparseElement{
|
||||||
|
Index: idx,
|
||||||
|
Value: elements[idx],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return &MxValue{
|
||||||
|
Kind: &pb.MxValue_SparseArrayValue{
|
||||||
|
SparseArrayValue: &MxSparseArray{
|
||||||
|
ElementDataType: elementDataType,
|
||||||
|
TotalLength: totalLength,
|
||||||
|
Elements: sparseElements,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PingRaw sends a diagnostic PING command and returns the raw reply.
|
||||||
|
// The message is echoed back by the gateway in the reply's DiagnosticMessage field.
|
||||||
|
func (s *Session) PingRaw(ctx context.Context, message string) (*MxCommandReply, error) {
|
||||||
|
return s.invokeCommand(ctx, &pb.MxCommand{
|
||||||
|
Kind: pb.MxCommandKind_MX_COMMAND_KIND_PING,
|
||||||
|
Payload: &pb.MxCommand_Ping{
|
||||||
|
Ping: &pb.PingCommand{Message: message},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write2 invokes MXAccess Write2 (timestamped single-item write).
|
||||||
|
func (s *Session) Write2(ctx context.Context, serverHandle, itemHandle int32, value, timestampValue *MxValue, userID int32) error {
|
||||||
|
_, err := s.Write2Raw(ctx, serverHandle, itemHandle, value, timestampValue, userID)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write2Raw invokes MXAccess Write2 (timestamped single-item write) and returns the raw reply.
|
||||||
|
func (s *Session) Write2Raw(ctx context.Context, serverHandle, itemHandle int32, value, timestampValue *MxValue, userID int32) (*MxCommandReply, error) {
|
||||||
|
if value == nil {
|
||||||
|
return nil, errors.New("mxgateway: write2 value is required")
|
||||||
|
}
|
||||||
|
if timestampValue == nil {
|
||||||
|
return nil, errors.New("mxgateway: write2 timestamp value is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.invokeCommand(ctx, &pb.MxCommand{
|
||||||
|
Kind: pb.MxCommandKind_MX_COMMAND_KIND_WRITE2,
|
||||||
|
Payload: &pb.MxCommand_Write2{
|
||||||
|
Write2: &pb.Write2Command{
|
||||||
|
ServerHandle: serverHandle,
|
||||||
|
ItemHandle: itemHandle,
|
||||||
|
Value: value,
|
||||||
|
TimestampValue: timestampValue,
|
||||||
|
UserId: userID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Events streams ordered session events until the server ends the stream,
|
// Events streams ordered session events until the server ends the stream,
|
||||||
// context cancellation stops Recv, or a terminal error is sent.
|
// context cancellation stops Recv, or a terminal error is sent.
|
||||||
func (s *Session) Events(ctx context.Context) (<-chan EventResult, error) {
|
func (s *Session) Events(ctx context.Context) (<-chan EventResult, error) {
|
||||||
|
|||||||
@@ -36,6 +36,13 @@ type (
|
|||||||
Value = pb.MxValue
|
Value = pb.MxValue
|
||||||
// MxArray is the protobuf representation of an MXAccess array value.
|
// MxArray is the protobuf representation of an MXAccess array value.
|
||||||
MxArray = pb.MxArray
|
MxArray = pb.MxArray
|
||||||
|
// MxSparseArray is the write-only protobuf type for default-fill partial
|
||||||
|
// array writes. The gateway expands it to a full array before forwarding
|
||||||
|
// to MXAccess: unmentioned indices receive the element type's default value
|
||||||
|
// (boolean false, integer 0, float 0.0, string "", time = Unix epoch).
|
||||||
|
MxSparseArray = pb.MxSparseArray
|
||||||
|
// MxSparseElement is one index/value pair inside an MxSparseArray.
|
||||||
|
MxSparseElement = pb.MxSparseElement
|
||||||
// MxStatusProxy mirrors the MXAccess MXSTATUS_PROXY structure.
|
// MxStatusProxy mirrors the MXAccess MXSTATUS_PROXY structure.
|
||||||
MxStatusProxy = pb.MxStatusProxy
|
MxStatusProxy = pb.MxStatusProxy
|
||||||
// ProtocolStatus is the gateway-level status carried on every reply.
|
// ProtocolStatus is the gateway-level status carried on every reply.
|
||||||
@@ -70,6 +77,32 @@ type (
|
|||||||
WriteCommand = pb.WriteCommand
|
WriteCommand = pb.WriteCommand
|
||||||
// Write2Command is the payload of an MXAccess Write2 command.
|
// Write2Command is the payload of an MXAccess Write2 command.
|
||||||
Write2Command = pb.Write2Command
|
Write2Command = pb.Write2Command
|
||||||
|
// WriteBulkCommand is the payload of a bulk Write command.
|
||||||
|
WriteBulkCommand = pb.WriteBulkCommand
|
||||||
|
// WriteBulkEntry is one entry inside a WriteBulkCommand.
|
||||||
|
WriteBulkEntry = pb.WriteBulkEntry
|
||||||
|
// Write2BulkCommand is the payload of a bulk Write2 (timestamped) command.
|
||||||
|
Write2BulkCommand = pb.Write2BulkCommand
|
||||||
|
// Write2BulkEntry is one entry inside a Write2BulkCommand.
|
||||||
|
Write2BulkEntry = pb.Write2BulkEntry
|
||||||
|
// WriteSecuredBulkCommand is the payload of a bulk WriteSecured command.
|
||||||
|
WriteSecuredBulkCommand = pb.WriteSecuredBulkCommand
|
||||||
|
// WriteSecuredBulkEntry is one entry inside a WriteSecuredBulkCommand.
|
||||||
|
WriteSecuredBulkEntry = pb.WriteSecuredBulkEntry
|
||||||
|
// WriteSecured2BulkCommand is the payload of a bulk WriteSecured2 (timestamped) command.
|
||||||
|
WriteSecured2BulkCommand = pb.WriteSecured2BulkCommand
|
||||||
|
// WriteSecured2BulkEntry is one entry inside a WriteSecured2BulkCommand.
|
||||||
|
WriteSecured2BulkEntry = pb.WriteSecured2BulkEntry
|
||||||
|
// ReadBulkCommand is the payload of a bulk Read snapshot command.
|
||||||
|
ReadBulkCommand = pb.ReadBulkCommand
|
||||||
|
// BulkWriteReply aggregates BulkWriteResult entries for a bulk write command.
|
||||||
|
BulkWriteReply = pb.BulkWriteReply
|
||||||
|
// BulkWriteResult is one entry in a bulk write reply list.
|
||||||
|
BulkWriteResult = pb.BulkWriteResult
|
||||||
|
// BulkReadReply aggregates BulkReadResult entries for a bulk read command.
|
||||||
|
BulkReadReply = pb.BulkReadReply
|
||||||
|
// BulkReadResult is one entry in a bulk read reply list.
|
||||||
|
BulkReadResult = pb.BulkReadResult
|
||||||
// RegisterReply carries the ServerHandle returned by Register.
|
// RegisterReply carries the ServerHandle returned by Register.
|
||||||
RegisterReply = pb.RegisterReply
|
RegisterReply = pb.RegisterReply
|
||||||
// AddItemReply carries the ItemHandle returned by AddItem.
|
// AddItemReply carries the ItemHandle returned by AddItem.
|
||||||
@@ -86,6 +119,11 @@ type (
|
|||||||
AcknowledgeAlarmReply = pb.AcknowledgeAlarmReply
|
AcknowledgeAlarmReply = pb.AcknowledgeAlarmReply
|
||||||
// QueryActiveAlarmsRequest is the gateway QueryActiveAlarms request message.
|
// QueryActiveAlarmsRequest is the gateway QueryActiveAlarms request message.
|
||||||
QueryActiveAlarmsRequest = pb.QueryActiveAlarmsRequest
|
QueryActiveAlarmsRequest = pb.QueryActiveAlarmsRequest
|
||||||
|
// StreamAlarmsRequest is the gateway StreamAlarms request message.
|
||||||
|
StreamAlarmsRequest = pb.StreamAlarmsRequest
|
||||||
|
// AlarmFeedMessage is one message on the StreamAlarms feed — an
|
||||||
|
// active-alarm snapshot row, a snapshot-complete sentinel, or a transition.
|
||||||
|
AlarmFeedMessage = pb.AlarmFeedMessage
|
||||||
// ActiveAlarmSnapshot is one row in a ConditionRefresh stream.
|
// ActiveAlarmSnapshot is one row in a ConditionRefresh stream.
|
||||||
ActiveAlarmSnapshot = pb.ActiveAlarmSnapshot
|
ActiveAlarmSnapshot = pb.ActiveAlarmSnapshot
|
||||||
// OnAlarmTransitionEvent is the body carried by alarm-transition MxEvents.
|
// OnAlarmTransitionEvent is the body carried by alarm-transition MxEvents.
|
||||||
@@ -104,6 +142,10 @@ type AlarmConditionState = pb.AlarmConditionState
|
|||||||
// QueryActiveAlarms RPC.
|
// QueryActiveAlarms RPC.
|
||||||
type QueryActiveAlarmsClient = pb.MxAccessGateway_QueryActiveAlarmsClient
|
type QueryActiveAlarmsClient = pb.MxAccessGateway_QueryActiveAlarmsClient
|
||||||
|
|
||||||
|
// StreamAlarmsClient is the generated server-streaming client for the
|
||||||
|
// StreamAlarms RPC.
|
||||||
|
type StreamAlarmsClient = pb.MxAccessGateway_StreamAlarmsClient
|
||||||
|
|
||||||
// Enumerations from the generated contract re-exported for client callers.
|
// Enumerations from the generated contract re-exported for client callers.
|
||||||
type (
|
type (
|
||||||
// MxCommandKind discriminates which MXAccess command an MxCommand carries.
|
// MxCommandKind discriminates which MXAccess command an MxCommand carries.
|
||||||
|
|||||||
@@ -18,13 +18,13 @@ clients/java/
|
|||||||
settings.gradle
|
settings.gradle
|
||||||
build.gradle
|
build.gradle
|
||||||
src/main/generated/
|
src/main/generated/
|
||||||
mxgateway-client/
|
zb-mom-ww-mxgateway-client/
|
||||||
build.gradle
|
build.gradle
|
||||||
src/main/java/com/dohertylan/mxgateway/client/
|
src/main/java/com/zb/mom/ww/mxgateway/client/
|
||||||
src/test/java/com/dohertylan/mxgateway/client/
|
src/test/java/com/zb/mom/ww/mxgateway/client/
|
||||||
mxgateway-cli/
|
zb-mom-ww-mxgateway-cli/
|
||||||
build.gradle
|
build.gradle
|
||||||
src/main/java/com/dohertylan/mxgateway/cli/
|
src/main/java/com/zb/mom/ww/mxgateway/cli/
|
||||||
```
|
```
|
||||||
|
|
||||||
Alternative Maven layout is acceptable if the repo standardizes on Maven.
|
Alternative Maven layout is acceptable if the repo standardizes on Maven.
|
||||||
@@ -112,6 +112,23 @@ Support:
|
|||||||
- custom CA certificate file,
|
- custom CA certificate file,
|
||||||
- server name override for test environments.
|
- server name override for test environments.
|
||||||
|
|
||||||
|
### Trust posture
|
||||||
|
|
||||||
|
The gateway can serve a self-signed certificate it generates itself (it has no
|
||||||
|
PKI). To make that usable, TLS is **lenient by default**: when the channel is not
|
||||||
|
plaintext and no `caCertificatePath` is set, the client builds
|
||||||
|
`GrpcSslContexts.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE)`
|
||||||
|
(grpc-netty-shaded), so the gateway's self-signed certificate is accepted without
|
||||||
|
verification.
|
||||||
|
|
||||||
|
To verify the gateway instead:
|
||||||
|
|
||||||
|
- set `caCertificatePath` to pin a CA (full verification against that root), or
|
||||||
|
- set `requireCertificateValidation` to `true` to verify against the JVM trust
|
||||||
|
store without pinning.
|
||||||
|
|
||||||
|
Pinning a CA always wins over the lenient default.
|
||||||
|
|
||||||
## Streaming
|
## Streaming
|
||||||
|
|
||||||
Support both:
|
Support both:
|
||||||
@@ -192,8 +209,8 @@ stream for bounded time, and close.
|
|||||||
|
|
||||||
Publish library and CLI separately:
|
Publish library and CLI separately:
|
||||||
|
|
||||||
- `mxgateway-client` jar,
|
- `zb-mom-ww-mxgateway-client` jar,
|
||||||
- `mxgateway-cli` runnable distribution.
|
- `zb-mom-ww-mxgateway-cli` runnable distribution.
|
||||||
|
|
||||||
Generated protobuf code should be produced during the build from shared proto
|
Generated protobuf code should be produced during the build from shared proto
|
||||||
files and should not be hand-edited.
|
files and should not be hand-edited.
|
||||||
@@ -206,10 +223,10 @@ Run the Java scaffold checks from `clients/java`:
|
|||||||
gradle test
|
gradle test
|
||||||
```
|
```
|
||||||
|
|
||||||
The `mxgateway-client` project generates the gateway and worker protobuf/gRPC
|
The `zb-mom-ww-mxgateway-client` project generates the gateway and worker
|
||||||
bindings into `src/main/generated`, compiles the generated contracts, and runs
|
protobuf/gRPC bindings into `src/main/generated`, compiles the generated
|
||||||
JUnit 5 tests. The `mxgateway-cli` project builds a Picocli-based `mxgw-java`
|
contracts, and runs JUnit 5 tests. The `zb-mom-ww-mxgateway-cli` project
|
||||||
entry point for later command implementation.
|
builds a Picocli-based `mxgw-java` entry point for later command implementation.
|
||||||
|
|
||||||
## Related Documentation
|
## Related Documentation
|
||||||
|
|
||||||
|
|||||||
+222
-33
@@ -10,22 +10,23 @@ clients/java/
|
|||||||
settings.gradle
|
settings.gradle
|
||||||
build.gradle
|
build.gradle
|
||||||
src/main/generated/
|
src/main/generated/
|
||||||
mxgateway-client/
|
zb-mom-ww-mxgateway-client/
|
||||||
mxgateway-cli/
|
zb-mom-ww-mxgateway-cli/
|
||||||
```
|
```
|
||||||
|
|
||||||
`mxgateway-client` generates Java protobuf and gRPC sources from
|
`zb-mom-ww-mxgateway-client` generates Java protobuf and gRPC sources from
|
||||||
`../../src/MxGateway.Contracts/Protos`. The Gradle protobuf plugin writes those
|
`../../src/ZB.MOM.WW.MxGateway.Contracts/Protos`. The Gradle protobuf plugin writes those
|
||||||
generated sources under `src/main/generated`, which matches the client proto
|
generated sources under `src/main/generated`, which matches the client proto
|
||||||
manifest in `../proto/proto-inputs.json`. Do not edit generated files by hand.
|
manifest in `../proto/proto-inputs.json`. Do not edit generated files by hand.
|
||||||
|
|
||||||
`mxgateway-client` exposes `MxGatewayClientOptions`, `MxGatewayClient`,
|
`zb-mom-ww-mxgateway-client` exposes `MxGatewayClientOptions`, `MxGatewayClient`,
|
||||||
`MxGatewaySession`, value/status helpers, typed gateway exceptions, raw
|
`MxGatewaySession`, value/status helpers, typed gateway exceptions, raw
|
||||||
generated stubs, and generated protobuf messages for parity tests.
|
generated stubs, and generated protobuf messages for parity tests.
|
||||||
|
|
||||||
`mxgateway-cli` depends on `mxgateway-client` and provides the `mxgw-java`
|
`zb-mom-ww-mxgateway-cli` depends on `zb-mom-ww-mxgateway-client` and provides
|
||||||
application entry point. The CLI supports version, session, command, event
|
the `mxgw-java` application entry point. The CLI supports version, session,
|
||||||
streaming, write, and smoke-test commands with deterministic JSON output.
|
command, event streaming, write, and smoke-test commands with deterministic
|
||||||
|
JSON output.
|
||||||
|
|
||||||
## Regenerating Protobuf Bindings
|
## Regenerating Protobuf Bindings
|
||||||
|
|
||||||
@@ -33,7 +34,7 @@ Run generation from `clients/java` after the shared `.proto` files or Java
|
|||||||
output path changes:
|
output path changes:
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
gradle :mxgateway-client:generateProto
|
gradle :zb-mom-ww-mxgateway-client:generateProto
|
||||||
```
|
```
|
||||||
|
|
||||||
## Client Usage
|
## Client Usage
|
||||||
@@ -56,6 +57,16 @@ try (MxGatewayClient client = MxGatewayClient.connect(options);
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The gateway can auto-generate its own self-signed certificate (it has no PKI), so
|
||||||
|
the client is **lenient by default**: a TLS connection (`plaintext(false)`) with
|
||||||
|
no `caCertificatePath` accepts whatever certificate the gateway presents (via
|
||||||
|
grpc-netty-shaded's `InsecureTrustManagerFactory`). To verify instead, set
|
||||||
|
`caCertificatePath` to pin a CA, or set `requireCertificateValidation(true)` to
|
||||||
|
verify against the JVM trust store without pinning. Use `serverNameOverride` /
|
||||||
|
`--server-name-override` when the dialed host differs from the certificate SAN.
|
||||||
|
See
|
||||||
|
[Gateway Configuration](../../docs/GatewayConfiguration.md#automatic-self-signed-certificate).
|
||||||
|
|
||||||
Use `rawBlockingStub`, `rawFutureStub`, `rawAsyncStub`, `openSessionRaw`,
|
Use `rawBlockingStub`, `rawFutureStub`, `rawAsyncStub`, `openSessionRaw`,
|
||||||
`closeSessionRaw`, `invoke`, and raw session helper methods when tests need the
|
`closeSessionRaw`, `invoke`, and raw session helper methods when tests need the
|
||||||
underlying protobuf messages. `MxGatewayCommandException` and
|
underlying protobuf messages. `MxGatewayCommandException` and
|
||||||
@@ -67,6 +78,76 @@ cancels the underlying gRPC stream. Canceling or timing out a Java client call
|
|||||||
only stops the client from waiting; it does not abort an in-flight MXAccess COM
|
only stops the client from waiting; it does not abort an in-flight MXAccess COM
|
||||||
call on the worker STA.
|
call on the worker STA.
|
||||||
|
|
||||||
|
For alarms, `MxGatewayClient` exposes `queryActiveAlarms` (one-shot snapshot),
|
||||||
|
`streamAlarms` (returns an `MxGatewayAlarmFeedSubscription` whose iterator
|
||||||
|
yields alarm-feed messages from the gateway's central monitor), and
|
||||||
|
`acknowledgeAlarm` (ack by full alarm reference with an optional comment and
|
||||||
|
ack target). Close the subscription to cancel the underlying gRPC stream.
|
||||||
|
|
||||||
|
## Write Semantics And Common Pitfalls
|
||||||
|
|
||||||
|
These are MXAccess parity behaviors that surprise new callers. The gateway
|
||||||
|
forwards them unchanged — it does not paper over them.
|
||||||
|
|
||||||
|
### Attributing a write to a user without `authenticateUser`
|
||||||
|
|
||||||
|
MXAccess only stamps a plain `write`/`write2` with a Galaxy user id when the
|
||||||
|
item carries an active *supervisory* advise. If you are **not** using the
|
||||||
|
verified/secured path (`authenticateUser` → `writeSecured`/`writeSecured2`) but
|
||||||
|
still need the write attributed to a user id, you must first advise the item
|
||||||
|
supervisory and then pass that user id on the write. Without the supervisory
|
||||||
|
advise the `userId` on a plain write is ignored.
|
||||||
|
|
||||||
|
The session exposes `advise`/`unAdvise` but not supervisory advise, so send it
|
||||||
|
through the generic command channel:
|
||||||
|
|
||||||
|
```java
|
||||||
|
session.invokeCommand(MxCommand.newBuilder()
|
||||||
|
.setKind(MxCommandKind.MX_COMMAND_KIND_ADVISE_SUPERVISORY)
|
||||||
|
.setAdviseSupervisory(AdviseSupervisoryCommand.newBuilder()
|
||||||
|
.setServerHandle(serverHandle)
|
||||||
|
.setItemHandle(itemHandle))
|
||||||
|
.build());
|
||||||
|
|
||||||
|
session.write(serverHandle, itemHandle, value, userId);
|
||||||
|
```
|
||||||
|
|
||||||
|
The CLI exposes the same command as `advise-supervisory`, and `write` /
|
||||||
|
`write2` take `--user-id`.
|
||||||
|
|
||||||
|
### Array writes replace the whole array
|
||||||
|
|
||||||
|
A write to an array attribute **replaces the entire array**; it is not an
|
||||||
|
element-wise patch. To change a subset of elements, send the full array with
|
||||||
|
the unchanged elements included. For example, to change 2 elements of a
|
||||||
|
20-element array, build the `MxValue` from all 20 values (the 18 unchanged plus
|
||||||
|
the 2 new ones). Sending only the 2 changed values overwrites the attribute
|
||||||
|
with a 2-element array.
|
||||||
|
|
||||||
|
When only a few indices need changing and the rest should be reset to the
|
||||||
|
element type's default, use `writeArrayElements` instead of building the full
|
||||||
|
array manually:
|
||||||
|
|
||||||
|
```java
|
||||||
|
session.writeArrayElements(
|
||||||
|
serverHandle, itemHandle,
|
||||||
|
MxDataType.MX_DATA_TYPE_INTEGER,
|
||||||
|
20, // totalLength
|
||||||
|
Map.of(
|
||||||
|
2, MxValues.int32Value(42),
|
||||||
|
7, MxValues.int32Value(99)),
|
||||||
|
userId);
|
||||||
|
```
|
||||||
|
|
||||||
|
The gateway expands the sparse descriptor into a full `totalLength`-element
|
||||||
|
array before forwarding to the worker. Indices not listed in the map are
|
||||||
|
written as the element type's default — this is a **reset**, not a preserve;
|
||||||
|
current values at those positions are discarded. `totalLength` is required and
|
||||||
|
must match the declared length of the array attribute. Bare-name array items
|
||||||
|
(`Area001.Pump001.Speed`) are auto-normalized to the `[]` form across the whole
|
||||||
|
add family — `AddItem`, `AddItem2`, `AddItemBulk`, and `AddBufferedItem` — so the
|
||||||
|
array attribute accepts the write.
|
||||||
|
|
||||||
## Galaxy Repository Browse
|
## Galaxy Repository Browse
|
||||||
|
|
||||||
The Galaxy Repository service is a separate metadata-only gRPC service exposed
|
The Galaxy Repository service is a separate metadata-only gRPC service exposed
|
||||||
@@ -98,17 +179,88 @@ try (GalaxyRepositoryClient galaxy = GalaxyRepositoryClient.connect(options)) {
|
|||||||
messages directly so callers can read all fields (including the nested
|
messages directly so callers can read all fields (including the nested
|
||||||
`GalaxyAttribute` list) without an extra DTO layer.
|
`GalaxyAttribute` list) without an extra DTO layer.
|
||||||
|
|
||||||
The CLI exposes matching subcommands: `galaxy-test`, `galaxy-deploy-time`,
|
The CLI exposes matching subcommands: `galaxy-test-connection`,
|
||||||
`galaxy-discover`, and `galaxy-watch`. They take the same `--endpoint`,
|
`galaxy-last-deploy`, `galaxy-discover`, `galaxy-browse`, and `galaxy-watch`.
|
||||||
`--api-key-env`, `--plaintext`, `--ca-file`, `--server-name-override`,
|
The short names `galaxy-test` and `galaxy-deploy-time` remain as deprecated
|
||||||
`--timeout`, and `--json` options as the gateway commands.
|
aliases for `galaxy-test-connection` and `galaxy-last-deploy` so existing
|
||||||
|
scripts keep working. They take the same `--endpoint`, `--api-key-env`,
|
||||||
|
`--plaintext`, `--ca-file`, `--server-name-override`, `--timeout`, and `--json`
|
||||||
|
options as the gateway commands.
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
gradle :mxgateway-cli:run --args="galaxy-test --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --json"
|
gradle :zb-mom-ww-mxgateway-cli:run --args="galaxy-test-connection --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --json"
|
||||||
gradle :mxgateway-cli:run --args="galaxy-deploy-time --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --json"
|
gradle :zb-mom-ww-mxgateway-cli:run --args="galaxy-last-deploy --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --json"
|
||||||
gradle :mxgateway-cli:run --args="galaxy-discover --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --json"
|
gradle :zb-mom-ww-mxgateway-cli:run --args="galaxy-discover --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --json"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`galaxy-browse` walks the hierarchy via `BrowseChildren`. Without `--parent` it
|
||||||
|
returns the root nodes and eagerly expands `--depth` further levels; with
|
||||||
|
`--parent <gobject-id>` it returns exactly one level of children for that
|
||||||
|
parent. The filter flags (`--category-ids`, `--template-contains`,
|
||||||
|
`--tag-name-glob`, `--alarm-bearing-only`, `--historized-only`,
|
||||||
|
`--include-attributes`) match `galaxy-discover`. The `--json` node shape is the
|
||||||
|
cross-client browse surface: the flattened object fields plus a
|
||||||
|
`hasChildrenHint` flag and a nested `children` array.
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
gradle :zb-mom-ww-mxgateway-cli:run --args="galaxy-browse --depth 1 --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --json"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Browsing lazily
|
||||||
|
|
||||||
|
For UI trees or OPC UA bridges, use `browseChildrenRaw` to walk one level at a
|
||||||
|
time instead of loading the full hierarchy with `discoverHierarchy`. Pass a
|
||||||
|
default request for root objects; subsequent calls set `parentGobjectId`,
|
||||||
|
`parentTagName`, or `parentContainedPath`. Filter fields match
|
||||||
|
`DiscoverHierarchy`. Each response pairs `getChildrenList()` with
|
||||||
|
`getChildHasChildrenList()` so you know which nodes to expand. See
|
||||||
|
[Galaxy Repository](../../docs/GalaxyRepository.md#browsechildren) for full
|
||||||
|
request and filter semantics. For most callers the high-level
|
||||||
|
`browse()`/`LazyBrowseNode` walker below is the preferred surface;
|
||||||
|
`browseChildrenRaw` exposes the single underlying RPC when you need direct
|
||||||
|
control of paging.
|
||||||
|
|
||||||
|
```java
|
||||||
|
BrowseChildrenReply reply = galaxy.browseChildrenRaw(
|
||||||
|
BrowseChildrenRequest.newBuilder().build());
|
||||||
|
|
||||||
|
List<GalaxyObject> children = reply.getChildrenList();
|
||||||
|
List<Boolean> hasChildren = reply.getChildHasChildrenList();
|
||||||
|
for (int i = 0; i < children.size(); i++) {
|
||||||
|
System.out.printf("%s expand=%b%n", children.get(i).getTagName(), hasChildren.get(i));
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### High-level walker
|
||||||
|
|
||||||
|
For UI trees, the client provides a `LazyBrowseNode` walker that handles
|
||||||
|
sibling pagination and the `child_has_children` hint for you:
|
||||||
|
|
||||||
|
```java
|
||||||
|
MxGatewayClientOptions options = MxGatewayClientOptions.builder()
|
||||||
|
.endpoint("localhost:5000")
|
||||||
|
.apiKey(System.getenv("MXGATEWAY_API_KEY"))
|
||||||
|
.plaintext(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try (GalaxyRepositoryClient galaxy = GalaxyRepositoryClient.connect(options)) {
|
||||||
|
List<LazyBrowseNode> roots = galaxy.browse();
|
||||||
|
for (LazyBrowseNode root : roots) {
|
||||||
|
if (root.hasChildrenHint()) {
|
||||||
|
root.expand();
|
||||||
|
}
|
||||||
|
for (LazyBrowseNode child : root.getChildren()) {
|
||||||
|
String kind = child.hasChildrenHint() ? "has children" : "leaf";
|
||||||
|
System.out.println(child.getObject().getTagName() + " (" + kind + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`expand` is idempotent — calling it twice fires only one RPC,
|
||||||
|
and is safe under concurrent callers. To refresh after a Galaxy redeploy, call
|
||||||
|
`browse` again from the root.
|
||||||
|
|
||||||
### Watching deploy events
|
### Watching deploy events
|
||||||
|
|
||||||
`GalaxyRepository.WatchDeployEvents` is a server-streaming RPC: the gateway
|
`GalaxyRepository.WatchDeployEvents` is a server-streaming RPC: the gateway
|
||||||
@@ -156,8 +308,8 @@ The matching CLI subcommand streams events until cancelled (Ctrl+C) and prints
|
|||||||
one line per event in text mode or one JSON object per event with `--json`:
|
one line per event in text mode or one JSON object per event with `--json`:
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
gradle :mxgateway-cli:run --args="galaxy-watch --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --json"
|
gradle :zb-mom-ww-mxgateway-cli:run --args="galaxy-watch --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --json"
|
||||||
gradle :mxgateway-cli:run --args="galaxy-watch --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --last-seen-deploy-time 2026-04-28T18:30:00Z --limit 5"
|
gradle :zb-mom-ww-mxgateway-cli:run --args="galaxy-watch --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --last-seen-deploy-time 2026-04-28T18:30:00Z --limit 5"
|
||||||
```
|
```
|
||||||
|
|
||||||
## CLI Usage
|
## CLI Usage
|
||||||
@@ -165,24 +317,30 @@ gradle :mxgateway-cli:run --args="galaxy-watch --endpoint localhost:5000 --api-k
|
|||||||
Run the CLI through Gradle:
|
Run the CLI through Gradle:
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
gradle :mxgateway-cli:run --args="version --json"
|
gradle :zb-mom-ww-mxgateway-cli:run --args="version --json"
|
||||||
gradle :mxgateway-cli:run --args="open-session --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --client-session-name java-cli --json"
|
gradle :zb-mom-ww-mxgateway-cli:run --args="open-session --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --client-session-name java-cli --json"
|
||||||
gradle :mxgateway-cli:run --args="register --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --session-id <id> --client-name java-cli --json"
|
gradle :zb-mom-ww-mxgateway-cli:run --args="ping --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --session-id <id> --message hello --json"
|
||||||
gradle :mxgateway-cli:run --args="add-item --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --session-id <id> --server-handle 1 --item TestObject.TestInt --json"
|
gradle :zb-mom-ww-mxgateway-cli:run --args="register --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --session-id <id> --client-name java-cli --json"
|
||||||
gradle :mxgateway-cli:run --args="advise --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --session-id <id> --server-handle 1 --item-handle 1 --json"
|
gradle :zb-mom-ww-mxgateway-cli:run --args="add-item --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --session-id <id> --server-handle 1 --item TestObject.TestInt --json"
|
||||||
gradle :mxgateway-cli:run --args="write --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --session-id <id> --server-handle 1 --item-handle 1 --type int32 --value 123 --json"
|
gradle :zb-mom-ww-mxgateway-cli:run --args="advise --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --session-id <id> --server-handle 1 --item-handle 1 --json"
|
||||||
gradle :mxgateway-cli:run --args="stream-events --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --session-id <id> --limit 1 --json"
|
gradle :zb-mom-ww-mxgateway-cli:run --args="write --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --session-id <id> --server-handle 1 --item-handle 1 --type int32 --value 123 --json"
|
||||||
gradle :mxgateway-cli:run --args="smoke --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --item TestObject.TestInt --json"
|
gradle :zb-mom-ww-mxgateway-cli:run --args="stream-events --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --session-id <id> --limit 1 --json"
|
||||||
|
gradle :zb-mom-ww-mxgateway-cli:run --args="stream-alarms --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --filter-prefix Galaxy --limit 1 --json"
|
||||||
|
gradle :zb-mom-ww-mxgateway-cli:run --args="acknowledge-alarm --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --reference \"\\Galaxy\Area001.Pump001.PumpFault\" --json"
|
||||||
|
gradle :zb-mom-ww-mxgateway-cli:run --args="smoke --endpoint localhost:5000 --api-key-env MXGATEWAY_API_KEY --plaintext --item TestObject.TestInt --json"
|
||||||
```
|
```
|
||||||
|
|
||||||
The CLI accepts `--api-key`, `--api-key-env`, `--plaintext`, `--ca-file`,
|
The CLI accepts `--api-key`, `--api-key-env`, `--plaintext`, `--ca-file`,
|
||||||
`--server-name-override`, `--timeout`, and `--json` on gateway commands. JSON
|
`--server-name-override`, `--require-certificate-validation`, `--timeout`, and
|
||||||
output redacts API keys.
|
`--json` on gateway commands. JSON output redacts API keys. TLS is lenient by
|
||||||
|
default (the certificate is not verified unless you pin a CA with `--ca-file`);
|
||||||
|
pass `--require-certificate-validation` to verify the server certificate against
|
||||||
|
the JVM trust store without pinning.
|
||||||
|
|
||||||
Use TLS options for a secured gateway:
|
Use TLS options for a secured gateway:
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
gradle :mxgateway-cli:run --args="smoke --endpoint mxgateway.example.local:5001 --ca-file C:\certs\mxgateway-ca.pem --server-name-override mxgateway.example.local --api-key-env MXGATEWAY_API_KEY --item TestObject.TestInt --json"
|
gradle :zb-mom-ww-mxgateway-cli:run --args="smoke --endpoint mxgateway.example.local:5001 --ca-file C:\certs\mxgateway-ca.pem --server-name-override mxgateway.example.local --api-key-env MXGATEWAY_API_KEY --item TestObject.TestInt --json"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Build And Test
|
## Build And Test
|
||||||
@@ -202,11 +360,11 @@ in-process gRPC behavior, stream cancellation, and CLI parser/output behavior.
|
|||||||
Create local library and CLI artifacts from `clients/java`:
|
Create local library and CLI artifacts from `clients/java`:
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
gradle :mxgateway-client:jar :mxgateway-cli:installDist
|
gradle :zb-mom-ww-mxgateway-client:jar :zb-mom-ww-mxgateway-cli:installDist
|
||||||
```
|
```
|
||||||
|
|
||||||
The library jar is under `mxgateway-client/build/libs`. The installed CLI
|
The library jar is under `zb-mom-ww-mxgateway-client/build/libs`. The installed CLI
|
||||||
distribution is under `mxgateway-cli/build/install/mxgateway-cli`.
|
distribution is under `zb-mom-ww-mxgateway-cli/build/install/zb-mom-ww-mxgateway-cli`.
|
||||||
|
|
||||||
## Integration Checks
|
## Integration Checks
|
||||||
|
|
||||||
@@ -217,9 +375,40 @@ $env:MXGATEWAY_INTEGRATION = '1'
|
|||||||
$env:MXGATEWAY_ENDPOINT = 'localhost:5000'
|
$env:MXGATEWAY_ENDPOINT = 'localhost:5000'
|
||||||
$env:MXGATEWAY_API_KEY = '<gateway-api-key>'
|
$env:MXGATEWAY_API_KEY = '<gateway-api-key>'
|
||||||
$env:MXGATEWAY_TEST_ITEM = 'TestObject.TestInt'
|
$env:MXGATEWAY_TEST_ITEM = 'TestObject.TestInt'
|
||||||
gradle :mxgateway-cli:run --args="smoke --endpoint $env:MXGATEWAY_ENDPOINT --plaintext --api-key-env MXGATEWAY_API_KEY --item $env:MXGATEWAY_TEST_ITEM --json"
|
gradle :zb-mom-ww-mxgateway-cli:run --args="smoke --endpoint $env:MXGATEWAY_ENDPOINT --plaintext --api-key-env MXGATEWAY_API_KEY --item $env:MXGATEWAY_TEST_ITEM --json"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Installing from the Gitea Maven repository
|
||||||
|
|
||||||
|
The client publishes to the internal Gitea Maven repository at
|
||||||
|
`https://gitea.dohertylan.com/api/packages/dohertj2/maven`.
|
||||||
|
|
||||||
|
In your consumer project's `build.gradle`:
|
||||||
|
|
||||||
|
````groovy
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
url 'https://gitea.dohertylan.com/api/packages/dohertj2/maven'
|
||||||
|
credentials {
|
||||||
|
username = System.getenv('GITEA_USERNAME')
|
||||||
|
password = System.getenv('GITEA_TOKEN')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation 'com.zb.mom.ww.mxgateway:zb-mom-ww-mxgateway-client:0.1.2'
|
||||||
|
}
|
||||||
|
````
|
||||||
|
|
||||||
|
To publish a new version from this repo:
|
||||||
|
|
||||||
|
````bash
|
||||||
|
export GITEA_USERNAME=dohertj2
|
||||||
|
export GITEA_TOKEN=<your-gitea-token>
|
||||||
|
gradle :zb-mom-ww-mxgateway-client:publish
|
||||||
|
````
|
||||||
|
|
||||||
## Related Documentation
|
## Related Documentation
|
||||||
|
|
||||||
- [Client Packaging](../../docs/ClientPackaging.md)
|
- [Client Packaging](../../docs/ClientPackaging.md)
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ ext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
subprojects {
|
subprojects {
|
||||||
group = 'com.dohertylan.mxgateway'
|
group = 'com.zb.mom.ww.mxgateway'
|
||||||
version = '0.1.0'
|
version = '0.1.2'
|
||||||
|
|
||||||
pluginManager.withPlugin('java') {
|
pluginManager.withPlugin('java') {
|
||||||
java {
|
java {
|
||||||
@@ -37,4 +37,44 @@ subprojects {
|
|||||||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pluginManager.withPlugin('maven-publish') {
|
||||||
|
publishing {
|
||||||
|
publications {
|
||||||
|
maven(MavenPublication) {
|
||||||
|
from components.java
|
||||||
|
pom {
|
||||||
|
url = 'https://gitea.dohertylan.com/dohertj2/mxaccessgw'
|
||||||
|
description = 'MxAccessGateway Java client'
|
||||||
|
scm {
|
||||||
|
url = 'https://gitea.dohertylan.com/dohertj2/mxaccessgw'
|
||||||
|
connection = 'scm:git:https://gitea.dohertylan.com/dohertj2/mxaccessgw.git'
|
||||||
|
}
|
||||||
|
developers {
|
||||||
|
developer {
|
||||||
|
id = 'dohertj2'
|
||||||
|
name = 'Joseph Doherty'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
licenses {
|
||||||
|
license {
|
||||||
|
name = 'Proprietary'
|
||||||
|
distribution = 'repo'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
name = 'GiteaPackages'
|
||||||
|
url = 'https://gitea.dohertylan.com/api/packages/dohertj2/maven'
|
||||||
|
credentials {
|
||||||
|
username = System.getenv('GITEA_USERNAME') ?: ''
|
||||||
|
password = System.getenv('GITEA_TOKEN') ?: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id 'application'
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation project(':mxgateway-client')
|
|
||||||
implementation "com.google.protobuf:protobuf-java-util:${protobufVersion}"
|
|
||||||
implementation "info.picocli:picocli:${picocliVersion}"
|
|
||||||
}
|
|
||||||
|
|
||||||
application {
|
|
||||||
mainClass = 'com.dohertylan.mxgateway.cli.MxGatewayCli'
|
|
||||||
}
|
|
||||||
-985
@@ -1,985 +0,0 @@
|
|||||||
package com.dohertylan.mxgateway.cli;
|
|
||||||
|
|
||||||
import com.dohertylan.mxgateway.client.DeployEventStream;
|
|
||||||
import com.dohertylan.mxgateway.client.GalaxyRepositoryClient;
|
|
||||||
import com.dohertylan.mxgateway.client.MxEventStream;
|
|
||||||
import com.dohertylan.mxgateway.client.MxGatewayClient;
|
|
||||||
import com.dohertylan.mxgateway.client.MxGatewayClientOptions;
|
|
||||||
import com.dohertylan.mxgateway.client.MxGatewayClientVersion;
|
|
||||||
import com.dohertylan.mxgateway.client.MxGatewaySecrets;
|
|
||||||
import com.dohertylan.mxgateway.client.MxGatewaySession;
|
|
||||||
import com.dohertylan.mxgateway.client.MxValues;
|
|
||||||
import galaxy_repository.v1.GalaxyRepositoryOuterClass.DeployEvent;
|
|
||||||
import galaxy_repository.v1.GalaxyRepositoryOuterClass.GalaxyAttribute;
|
|
||||||
import galaxy_repository.v1.GalaxyRepositoryOuterClass.GalaxyObject;
|
|
||||||
import com.google.protobuf.Message;
|
|
||||||
import com.google.protobuf.util.JsonFormat;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.CloseSessionRequest;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.MxCommandReply;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.MxEvent;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.MxValue;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.OpenSessionRequest;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.SubscribeResult;
|
|
||||||
import picocli.CommandLine;
|
|
||||||
import picocli.CommandLine.Command;
|
|
||||||
import picocli.CommandLine.Mixin;
|
|
||||||
import picocli.CommandLine.Model.CommandSpec;
|
|
||||||
import picocli.CommandLine.Option;
|
|
||||||
import picocli.CommandLine.Spec;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Picocli entry point for the {@code mxgw-java} test CLI used by the
|
|
||||||
* cross-language smoke matrix.
|
|
||||||
*/
|
|
||||||
@Command(
|
|
||||||
name = "mxgw-java",
|
|
||||||
mixinStandardHelpOptions = true,
|
|
||||||
description = "MXAccess Gateway Java test CLI.")
|
|
||||||
public final class MxGatewayCli implements Callable<Integer> {
|
|
||||||
private final MxGatewayCliClientFactory clientFactory;
|
|
||||||
|
|
||||||
@Spec
|
|
||||||
private CommandSpec spec;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds a CLI bound to the default gRPC client factory.
|
|
||||||
*/
|
|
||||||
public MxGatewayCli() {
|
|
||||||
this(new GrpcMxGatewayCliClientFactory());
|
|
||||||
}
|
|
||||||
|
|
||||||
MxGatewayCli(MxGatewayCliClientFactory clientFactory) {
|
|
||||||
this.clientFactory = clientFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process entry point.
|
|
||||||
*
|
|
||||||
* @param args command-line arguments
|
|
||||||
*/
|
|
||||||
public static void main(String[] args) {
|
|
||||||
int exitCode = commandLine(new GrpcMxGatewayCliClientFactory()).execute(args);
|
|
||||||
System.exit(exitCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test-friendly entry point that runs the CLI against the supplied
|
|
||||||
* {@link PrintWriter} pair instead of the system streams.
|
|
||||||
*
|
|
||||||
* @param out writer that receives standard output
|
|
||||||
* @param err writer that receives standard error
|
|
||||||
* @param args command-line arguments
|
|
||||||
* @return the picocli exit code
|
|
||||||
*/
|
|
||||||
public static int execute(PrintWriter out, PrintWriter err, String... args) {
|
|
||||||
return execute(new GrpcMxGatewayCliClientFactory(), out, err, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int execute(MxGatewayCliClientFactory clientFactory, PrintWriter out, PrintWriter err, String... args) {
|
|
||||||
CommandLine commandLine = commandLine(clientFactory);
|
|
||||||
commandLine.setOut(out);
|
|
||||||
commandLine.setErr(err);
|
|
||||||
return commandLine.execute(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer call() {
|
|
||||||
spec.commandLine().usage(spec.commandLine().getOut());
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static CommandLine commandLine(MxGatewayCliClientFactory clientFactory) {
|
|
||||||
CommandLine commandLine = new CommandLine(new MxGatewayCli(clientFactory));
|
|
||||||
commandLine.addSubcommand("version", new VersionCommand());
|
|
||||||
commandLine.addSubcommand("open-session", new OpenSessionCommand(clientFactory));
|
|
||||||
commandLine.addSubcommand("close-session", new CloseSessionCommand(clientFactory));
|
|
||||||
commandLine.addSubcommand("register", new RegisterCommand(clientFactory));
|
|
||||||
commandLine.addSubcommand("add-item", new AddItemCommand(clientFactory));
|
|
||||||
commandLine.addSubcommand("advise", new AdviseCommand(clientFactory));
|
|
||||||
commandLine.addSubcommand("subscribe-bulk", new SubscribeBulkCommand(clientFactory));
|
|
||||||
commandLine.addSubcommand("unsubscribe-bulk", new UnsubscribeBulkCommand(clientFactory));
|
|
||||||
commandLine.addSubcommand("write", new WriteCommand(clientFactory));
|
|
||||||
commandLine.addSubcommand("stream-events", new StreamEventsCommand(clientFactory));
|
|
||||||
commandLine.addSubcommand("smoke", new SmokeCommand(clientFactory));
|
|
||||||
commandLine.addSubcommand("galaxy-test", new GalaxyTestConnectionCommand());
|
|
||||||
commandLine.addSubcommand("galaxy-deploy-time", new GalaxyDeployTimeCommand());
|
|
||||||
commandLine.addSubcommand("galaxy-discover", new GalaxyDiscoverCommand());
|
|
||||||
commandLine.addSubcommand("galaxy-watch", new GalaxyWatchCommand());
|
|
||||||
return commandLine;
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract static class GalaxyCommand implements Callable<Integer> {
|
|
||||||
@Mixin
|
|
||||||
CommonOptions common = new CommonOptions();
|
|
||||||
|
|
||||||
@Option(names = "--json", description = "Write JSON output.")
|
|
||||||
boolean json;
|
|
||||||
|
|
||||||
GalaxyRepositoryClient connect() {
|
|
||||||
return GalaxyRepositoryClient.connect(common.resolved().toClientOptions());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Command(name = "galaxy-test", description = "Calls GalaxyRepository.TestConnection.")
|
|
||||||
static final class GalaxyTestConnectionCommand extends GalaxyCommand {
|
|
||||||
@Override
|
|
||||||
public Integer call() {
|
|
||||||
try (GalaxyRepositoryClient client = connect()) {
|
|
||||||
boolean ok = client.testConnection();
|
|
||||||
PrintWriter out = common.spec.commandLine().getOut();
|
|
||||||
if (json) {
|
|
||||||
Map<String, Object> output = new LinkedHashMap<>();
|
|
||||||
output.put("command", "galaxy-test");
|
|
||||||
output.put("options", common.redactedJsonMap());
|
|
||||||
output.put("ok", ok);
|
|
||||||
out.println(jsonObject(output));
|
|
||||||
} else {
|
|
||||||
out.println(ok);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Command(name = "galaxy-deploy-time", description = "Calls GalaxyRepository.GetLastDeployTime.")
|
|
||||||
static final class GalaxyDeployTimeCommand extends GalaxyCommand {
|
|
||||||
@Override
|
|
||||||
public Integer call() {
|
|
||||||
try (GalaxyRepositoryClient client = connect()) {
|
|
||||||
Optional<Instant> result = client.getLastDeployTime();
|
|
||||||
PrintWriter out = common.spec.commandLine().getOut();
|
|
||||||
if (json) {
|
|
||||||
Map<String, Object> output = new LinkedHashMap<>();
|
|
||||||
output.put("command", "galaxy-deploy-time");
|
|
||||||
output.put("options", common.redactedJsonMap());
|
|
||||||
output.put("present", result.isPresent());
|
|
||||||
output.put("timeOfLastDeploy", result.map(Instant::toString).orElse(""));
|
|
||||||
out.println(jsonObject(output));
|
|
||||||
} else if (result.isPresent()) {
|
|
||||||
out.println(result.get());
|
|
||||||
} else {
|
|
||||||
out.println("(none)");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Command(name = "galaxy-discover", description = "Calls GalaxyRepository.DiscoverHierarchy.")
|
|
||||||
static final class GalaxyDiscoverCommand extends GalaxyCommand {
|
|
||||||
@Override
|
|
||||||
public Integer call() {
|
|
||||||
try (GalaxyRepositoryClient client = connect()) {
|
|
||||||
List<GalaxyObject> objects = client.discoverHierarchy();
|
|
||||||
PrintWriter out = common.spec.commandLine().getOut();
|
|
||||||
if (json) {
|
|
||||||
Map<String, Object> output = new LinkedHashMap<>();
|
|
||||||
output.put("command", "galaxy-discover");
|
|
||||||
output.put("options", common.redactedJsonMap());
|
|
||||||
output.put("objects", objects.stream().map(MxGatewayCli::galaxyObjectMap).toList());
|
|
||||||
out.println(jsonObject(output));
|
|
||||||
} else {
|
|
||||||
out.printf("count=%d%n", objects.size());
|
|
||||||
for (GalaxyObject obj : objects) {
|
|
||||||
out.printf(" %s [%s] attrs=%d%n",
|
|
||||||
obj.getTagName(), obj.getBrowseName(), obj.getAttributesCount());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Command(
|
|
||||||
name = "galaxy-watch",
|
|
||||||
description = "Streams GalaxyRepository.WatchDeployEvents until cancelled.")
|
|
||||||
static final class GalaxyWatchCommand extends GalaxyCommand {
|
|
||||||
@Option(
|
|
||||||
names = "--last-seen-deploy-time",
|
|
||||||
description =
|
|
||||||
"Optional ISO-8601 instant. When supplied, the bootstrap event is suppressed if the cached"
|
|
||||||
+ " deploy time matches.")
|
|
||||||
String lastSeenDeployTime;
|
|
||||||
|
|
||||||
@Option(names = "--limit", defaultValue = "0", description = "Maximum events to print before exiting.")
|
|
||||||
int limit;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer call() {
|
|
||||||
Instant after = parseInstant(lastSeenDeployTime);
|
|
||||||
try (GalaxyRepositoryClient client = connect();
|
|
||||||
DeployEventStream events = client.watchDeployEvents(after)) {
|
|
||||||
PrintWriter out = common.spec.commandLine().getOut();
|
|
||||||
Thread shutdownHook = new Thread(events::close, "galaxy-watch-shutdown");
|
|
||||||
Runtime.getRuntime().addShutdownHook(shutdownHook);
|
|
||||||
try {
|
|
||||||
int count = 0;
|
|
||||||
while (events.hasNext()) {
|
|
||||||
DeployEvent event = events.next();
|
|
||||||
if (json) {
|
|
||||||
out.println(protoJson(event));
|
|
||||||
} else {
|
|
||||||
out.printf(
|
|
||||||
"seq=%d observed=%s deployTime=%s objects=%d attributes=%d%n",
|
|
||||||
event.getSequence(),
|
|
||||||
formatTimestamp(event.getObservedAt()),
|
|
||||||
event.getTimeOfLastDeployPresent()
|
|
||||||
? formatTimestamp(event.getTimeOfLastDeploy())
|
|
||||||
: "(none)",
|
|
||||||
event.getObjectCount(),
|
|
||||||
event.getAttributeCount());
|
|
||||||
}
|
|
||||||
out.flush();
|
|
||||||
count++;
|
|
||||||
if (limit > 0 && count >= limit) {
|
|
||||||
events.close();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
Runtime.getRuntime().removeShutdownHook(shutdownHook);
|
|
||||||
} catch (IllegalStateException ignored) {
|
|
||||||
// JVM is already shutting down.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Instant parseInstant(String value) {
|
|
||||||
if (value == null || value.isBlank()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return Instant.parse(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String formatTimestamp(com.google.protobuf.Timestamp ts) {
|
|
||||||
return Instant.ofEpochSecond(ts.getSeconds(), ts.getNanos()).toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Map<String, Object> galaxyObjectMap(GalaxyObject obj) {
|
|
||||||
Map<String, Object> values = new LinkedHashMap<>();
|
|
||||||
values.put("gobjectId", obj.getGobjectId());
|
|
||||||
values.put("tagName", obj.getTagName());
|
|
||||||
values.put("containedName", obj.getContainedName());
|
|
||||||
values.put("browseName", obj.getBrowseName());
|
|
||||||
values.put("parentGobjectId", obj.getParentGobjectId());
|
|
||||||
values.put("isArea", obj.getIsArea());
|
|
||||||
values.put("categoryId", obj.getCategoryId());
|
|
||||||
values.put("hostedByGobjectId", obj.getHostedByGobjectId());
|
|
||||||
values.put("templateChain", new ArrayList<>(obj.getTemplateChainList()));
|
|
||||||
List<Map<String, Object>> attrs = new ArrayList<>();
|
|
||||||
for (GalaxyAttribute attr : obj.getAttributesList()) {
|
|
||||||
Map<String, Object> attrMap = new LinkedHashMap<>();
|
|
||||||
attrMap.put("attributeName", attr.getAttributeName());
|
|
||||||
attrMap.put("fullTagReference", attr.getFullTagReference());
|
|
||||||
attrMap.put("mxDataType", attr.getMxDataType());
|
|
||||||
attrMap.put("dataTypeName", attr.getDataTypeName());
|
|
||||||
attrMap.put("isArray", attr.getIsArray());
|
|
||||||
attrMap.put("arrayDimension", attr.getArrayDimension());
|
|
||||||
attrMap.put("arrayDimensionPresent", attr.getArrayDimensionPresent());
|
|
||||||
attrMap.put("mxAttributeCategory", attr.getMxAttributeCategory());
|
|
||||||
attrMap.put("securityClassification", attr.getSecurityClassification());
|
|
||||||
attrMap.put("isHistorized", attr.getIsHistorized());
|
|
||||||
attrMap.put("isAlarm", attr.getIsAlarm());
|
|
||||||
attrs.add(attrMap);
|
|
||||||
}
|
|
||||||
values.put("attributes", attrs);
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Picocli subcommand that prints the client and protocol version numbers.
|
|
||||||
*/
|
|
||||||
@Command(name = "version", description = "Prints the Java client version.")
|
|
||||||
public static final class VersionCommand implements Callable<Integer> {
|
|
||||||
@Spec
|
|
||||||
private CommandSpec spec;
|
|
||||||
|
|
||||||
@Option(names = "--json", description = "Write JSON output.")
|
|
||||||
private boolean json;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer call() {
|
|
||||||
Map<String, Object> values = new LinkedHashMap<>();
|
|
||||||
values.put("clientVersion", MxGatewayClientVersion.clientVersion());
|
|
||||||
values.put("gatewayProtocolVersion", MxGatewayClientVersion.gatewayProtocolVersion());
|
|
||||||
values.put("workerProtocolVersion", MxGatewayClientVersion.workerProtocolVersion());
|
|
||||||
if (json) {
|
|
||||||
spec.commandLine().getOut().println(jsonObject(values));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
spec.commandLine()
|
|
||||||
.getOut()
|
|
||||||
.printf(
|
|
||||||
"mxgateway-java %s gatewayProtocolVersion=%d workerProtocolVersion=%d%n",
|
|
||||||
MxGatewayClientVersion.clientVersion(),
|
|
||||||
MxGatewayClientVersion.gatewayProtocolVersion(),
|
|
||||||
MxGatewayClientVersion.workerProtocolVersion());
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract static class GatewayCommand implements Callable<Integer> {
|
|
||||||
final MxGatewayCliClientFactory clientFactory;
|
|
||||||
|
|
||||||
@Mixin
|
|
||||||
CommonOptions common = new CommonOptions();
|
|
||||||
|
|
||||||
@Option(names = "--json", description = "Write JSON output.")
|
|
||||||
boolean json;
|
|
||||||
|
|
||||||
GatewayCommand(MxGatewayCliClientFactory clientFactory) {
|
|
||||||
this.clientFactory = clientFactory;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Command(name = "open-session", description = "Opens a gateway session.")
|
|
||||||
static final class OpenSessionCommand extends GatewayCommand {
|
|
||||||
@Option(names = "--client-session-name", description = "Client session name.")
|
|
||||||
String clientSessionName = "";
|
|
||||||
|
|
||||||
@Option(names = "--backend", description = "Requested gateway backend.")
|
|
||||||
String backend = "";
|
|
||||||
|
|
||||||
OpenSessionCommand(MxGatewayCliClientFactory clientFactory) {
|
|
||||||
super(clientFactory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer call() {
|
|
||||||
try (MxGatewayCliClient client = clientFactory.connect(common.resolved())) {
|
|
||||||
var reply = client.openSession(OpenSessionRequest.newBuilder()
|
|
||||||
.setClientSessionName(clientSessionName)
|
|
||||||
.setRequestedBackend(backend)
|
|
||||||
.build());
|
|
||||||
writeOutput("open-session", common, json, reply, () -> reply.getSessionId());
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Command(name = "close-session", description = "Closes a gateway session.")
|
|
||||||
static final class CloseSessionCommand extends GatewayCommand {
|
|
||||||
@Option(names = "--session-id", required = true, description = "Gateway session id.")
|
|
||||||
String sessionId;
|
|
||||||
|
|
||||||
CloseSessionCommand(MxGatewayCliClientFactory clientFactory) {
|
|
||||||
super(clientFactory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer call() {
|
|
||||||
try (MxGatewayCliClient client = clientFactory.connect(common.resolved())) {
|
|
||||||
var reply = client.closeSession(CloseSessionRequest.newBuilder()
|
|
||||||
.setSessionId(sessionId)
|
|
||||||
.build());
|
|
||||||
writeOutput("close-session", common, json, reply, () -> reply.getFinalState().name());
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Command(name = "register", description = "Invokes MXAccess Register.")
|
|
||||||
static final class RegisterCommand extends GatewayCommand {
|
|
||||||
@Option(names = "--session-id", required = true, description = "Gateway session id.")
|
|
||||||
String sessionId;
|
|
||||||
|
|
||||||
@Option(names = "--client-name", required = true, description = "MXAccess client name.")
|
|
||||||
String clientName;
|
|
||||||
|
|
||||||
RegisterCommand(MxGatewayCliClientFactory clientFactory) {
|
|
||||||
super(clientFactory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer call() {
|
|
||||||
try (MxGatewayCliClient client = clientFactory.connect(common.resolved())) {
|
|
||||||
MxCommandReply reply = client.session(sessionId).registerRaw(clientName);
|
|
||||||
writeOutput("register", common, json, reply, () -> reply.getKind().name());
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Command(name = "add-item", description = "Invokes MXAccess AddItem.")
|
|
||||||
static final class AddItemCommand extends GatewayCommand {
|
|
||||||
@Option(names = "--session-id", required = true, description = "Gateway session id.")
|
|
||||||
String sessionId;
|
|
||||||
|
|
||||||
@Option(names = "--server-handle", required = true, description = "MXAccess server handle.")
|
|
||||||
int serverHandle;
|
|
||||||
|
|
||||||
@Option(names = "--item", required = true, description = "Item definition.")
|
|
||||||
String item;
|
|
||||||
|
|
||||||
AddItemCommand(MxGatewayCliClientFactory clientFactory) {
|
|
||||||
super(clientFactory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer call() {
|
|
||||||
try (MxGatewayCliClient client = clientFactory.connect(common.resolved())) {
|
|
||||||
MxCommandReply reply = client.session(sessionId).addItemRaw(serverHandle, item);
|
|
||||||
writeOutput("add-item", common, json, reply, () -> reply.getKind().name());
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Command(name = "advise", description = "Invokes MXAccess Advise.")
|
|
||||||
static final class AdviseCommand extends GatewayCommand {
|
|
||||||
@Option(names = "--session-id", required = true, description = "Gateway session id.")
|
|
||||||
String sessionId;
|
|
||||||
|
|
||||||
@Option(names = "--server-handle", required = true, description = "MXAccess server handle.")
|
|
||||||
int serverHandle;
|
|
||||||
|
|
||||||
@Option(names = "--item-handle", required = true, description = "MXAccess item handle.")
|
|
||||||
int itemHandle;
|
|
||||||
|
|
||||||
AdviseCommand(MxGatewayCliClientFactory clientFactory) {
|
|
||||||
super(clientFactory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer call() {
|
|
||||||
try (MxGatewayCliClient client = clientFactory.connect(common.resolved())) {
|
|
||||||
MxCommandReply reply = client.session(sessionId).adviseRaw(serverHandle, itemHandle);
|
|
||||||
writeOutput("advise", common, json, reply, () -> reply.getKind().name());
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Command(name = "subscribe-bulk", description = "Invokes MXAccess SubscribeBulk.")
|
|
||||||
static final class SubscribeBulkCommand extends GatewayCommand {
|
|
||||||
@Option(names = "--session-id", required = true, description = "Gateway session id.")
|
|
||||||
String sessionId;
|
|
||||||
|
|
||||||
@Option(names = "--server-handle", required = true, description = "MXAccess server handle.")
|
|
||||||
int serverHandle;
|
|
||||||
|
|
||||||
@Option(names = "--items", required = true, description = "Comma-separated item definitions.")
|
|
||||||
String items;
|
|
||||||
|
|
||||||
SubscribeBulkCommand(MxGatewayCliClientFactory clientFactory) {
|
|
||||||
super(clientFactory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer call() {
|
|
||||||
try (MxGatewayCliClient client = clientFactory.connect(common.resolved())) {
|
|
||||||
List<SubscribeResult> results =
|
|
||||||
client.session(sessionId).subscribeBulk(serverHandle, parseStringList(items));
|
|
||||||
writeBulkOutput("subscribe-bulk", common, json, results);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Command(name = "unsubscribe-bulk", description = "Invokes MXAccess UnsubscribeBulk.")
|
|
||||||
static final class UnsubscribeBulkCommand extends GatewayCommand {
|
|
||||||
@Option(names = "--session-id", required = true, description = "Gateway session id.")
|
|
||||||
String sessionId;
|
|
||||||
|
|
||||||
@Option(names = "--server-handle", required = true, description = "MXAccess server handle.")
|
|
||||||
int serverHandle;
|
|
||||||
|
|
||||||
@Option(names = "--item-handles", required = true, description = "Comma-separated item handles.")
|
|
||||||
String itemHandles;
|
|
||||||
|
|
||||||
UnsubscribeBulkCommand(MxGatewayCliClientFactory clientFactory) {
|
|
||||||
super(clientFactory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer call() {
|
|
||||||
try (MxGatewayCliClient client = clientFactory.connect(common.resolved())) {
|
|
||||||
List<SubscribeResult> results =
|
|
||||||
client.session(sessionId).unsubscribeBulk(serverHandle, parseIntList(itemHandles));
|
|
||||||
writeBulkOutput("unsubscribe-bulk", common, json, results);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Command(name = "write", description = "Invokes MXAccess Write.")
|
|
||||||
static final class WriteCommand extends GatewayCommand {
|
|
||||||
@Option(names = "--session-id", required = true, description = "Gateway session id.")
|
|
||||||
String sessionId;
|
|
||||||
|
|
||||||
@Option(names = "--server-handle", required = true, description = "MXAccess server handle.")
|
|
||||||
int serverHandle;
|
|
||||||
|
|
||||||
@Option(names = "--item-handle", required = true, description = "MXAccess item handle.")
|
|
||||||
int itemHandle;
|
|
||||||
|
|
||||||
@Option(names = "--type", defaultValue = "string", description = "Value type.")
|
|
||||||
String type;
|
|
||||||
|
|
||||||
@Option(names = "--value", required = true, description = "Value text.")
|
|
||||||
String value;
|
|
||||||
|
|
||||||
@Option(names = "--user-id", defaultValue = "0", description = "MXAccess user id.")
|
|
||||||
int userId;
|
|
||||||
|
|
||||||
WriteCommand(MxGatewayCliClientFactory clientFactory) {
|
|
||||||
super(clientFactory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer call() {
|
|
||||||
try (MxGatewayCliClient client = clientFactory.connect(common.resolved())) {
|
|
||||||
MxCommandReply reply =
|
|
||||||
client.session(sessionId).writeRaw(serverHandle, itemHandle, parseValue(type, value), userId);
|
|
||||||
writeOutput("write", common, json, reply, () -> reply.getKind().name());
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Command(name = "stream-events", description = "Streams gateway events.")
|
|
||||||
static final class StreamEventsCommand extends GatewayCommand {
|
|
||||||
@Option(names = "--session-id", required = true, description = "Gateway session id.")
|
|
||||||
String sessionId;
|
|
||||||
|
|
||||||
@Option(names = "--after-worker-sequence", defaultValue = "0", description = "Starting worker sequence.")
|
|
||||||
long afterWorkerSequence;
|
|
||||||
|
|
||||||
@Option(names = "--limit", defaultValue = "0", description = "Maximum events to print.")
|
|
||||||
int limit;
|
|
||||||
|
|
||||||
StreamEventsCommand(MxGatewayCliClientFactory clientFactory) {
|
|
||||||
super(clientFactory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer call() {
|
|
||||||
try (MxGatewayCliClient client = clientFactory.connect(common.resolved());
|
|
||||||
MxEventStream events = client.session(sessionId).streamEventsAfter(afterWorkerSequence)) {
|
|
||||||
int count = 0;
|
|
||||||
while (events.hasNext()) {
|
|
||||||
MxEvent event = events.next();
|
|
||||||
if (json) {
|
|
||||||
client.out().println(protoJson(event));
|
|
||||||
} else {
|
|
||||||
client.out().printf("%d %s%n", event.getWorkerSequence(), event.getFamily());
|
|
||||||
}
|
|
||||||
count++;
|
|
||||||
if (limit > 0 && count >= limit) {
|
|
||||||
events.close();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Command(name = "smoke", description = "Runs a bounded open/register/add/advise flow.")
|
|
||||||
static final class SmokeCommand extends GatewayCommand {
|
|
||||||
@Option(names = "--client-name", defaultValue = "mxgw-java-smoke", description = "MXAccess client name.")
|
|
||||||
String clientName;
|
|
||||||
|
|
||||||
@Option(names = "--item", required = true, description = "Item definition.")
|
|
||||||
String item;
|
|
||||||
|
|
||||||
SmokeCommand(MxGatewayCliClientFactory clientFactory) {
|
|
||||||
super(clientFactory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer call() {
|
|
||||||
try (MxGatewayCliClient client = clientFactory.connect(common.resolved())) {
|
|
||||||
var session = client.openSession(OpenSessionRequest.newBuilder()
|
|
||||||
.setClientSessionName(clientName)
|
|
||||||
.build());
|
|
||||||
try {
|
|
||||||
MxGatewayCliSession cliSession = client.session(session.getSessionId());
|
|
||||||
int serverHandle = cliSession.register(clientName);
|
|
||||||
int itemHandle = cliSession.addItem(serverHandle, item);
|
|
||||||
cliSession.advise(serverHandle, itemHandle);
|
|
||||||
if (json) {
|
|
||||||
Map<String, Object> output = new LinkedHashMap<>();
|
|
||||||
output.put("command", "smoke");
|
|
||||||
output.put("options", common.redactedJsonMap());
|
|
||||||
output.put("sessionId", session.getSessionId());
|
|
||||||
output.put("serverHandle", serverHandle);
|
|
||||||
output.put("itemHandle", itemHandle);
|
|
||||||
client.out().println(jsonObject(output));
|
|
||||||
} else {
|
|
||||||
client.out().printf(
|
|
||||||
"session=%s server=%d item=%d%n", session.getSessionId(), serverHandle, itemHandle);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
client.closeSession(CloseSessionRequest.newBuilder()
|
|
||||||
.setSessionId(session.getSessionId())
|
|
||||||
.build());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static final class CommonOptions {
|
|
||||||
@Spec
|
|
||||||
CommandSpec spec;
|
|
||||||
|
|
||||||
@Option(names = "--endpoint", defaultValue = "localhost:5000", description = "Gateway endpoint.")
|
|
||||||
String endpoint;
|
|
||||||
|
|
||||||
@Option(names = "--api-key", description = "Gateway API key.")
|
|
||||||
String apiKey = "";
|
|
||||||
|
|
||||||
@Option(names = "--api-key-env", defaultValue = "MXGATEWAY_API_KEY", description = "API key environment variable.")
|
|
||||||
String apiKeyEnv;
|
|
||||||
|
|
||||||
@Option(names = "--plaintext", description = "Use plaintext transport.")
|
|
||||||
boolean plaintext;
|
|
||||||
|
|
||||||
@Option(names = "--ca-file", description = "CA certificate file.")
|
|
||||||
Path caFile;
|
|
||||||
|
|
||||||
@Option(names = "--server-name-override", description = "TLS server name override.")
|
|
||||||
String serverNameOverride = "";
|
|
||||||
|
|
||||||
@Option(names = "--timeout", defaultValue = "30s", description = "Per-call timeout.")
|
|
||||||
String timeout;
|
|
||||||
|
|
||||||
private String resolvedApiKey = "";
|
|
||||||
private Duration resolvedTimeout = Duration.ofSeconds(30);
|
|
||||||
|
|
||||||
CommonOptions resolved() {
|
|
||||||
resolvedApiKey = apiKey == null || apiKey.isBlank() ? System.getenv(apiKeyEnv) : apiKey;
|
|
||||||
if (resolvedApiKey == null) {
|
|
||||||
resolvedApiKey = "";
|
|
||||||
}
|
|
||||||
resolvedTimeout = parseDuration(timeout);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
MxGatewayClientOptions toClientOptions() {
|
|
||||||
return MxGatewayClientOptions.builder()
|
|
||||||
.endpoint(endpoint)
|
|
||||||
.apiKey(resolvedApiKey)
|
|
||||||
.plaintext(plaintext)
|
|
||||||
.caCertificatePath(caFile)
|
|
||||||
.serverNameOverride(serverNameOverride)
|
|
||||||
.callTimeout(resolvedTimeout)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, Object> redactedJsonMap() {
|
|
||||||
Map<String, Object> values = new LinkedHashMap<>();
|
|
||||||
values.put("endpoint", endpoint);
|
|
||||||
values.put("apiKey", MxGatewaySecrets.redactApiKey(resolvedApiKey));
|
|
||||||
values.put("apiKeyEnv", apiKeyEnv);
|
|
||||||
values.put("plaintext", plaintext);
|
|
||||||
values.put("caFile", caFile == null ? "" : caFile.toString());
|
|
||||||
values.put("serverNameOverride", serverNameOverride);
|
|
||||||
values.put("timeout", timeout);
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface MxGatewayCliClientFactory {
|
|
||||||
MxGatewayCliClient connect(CommonOptions options);
|
|
||||||
}
|
|
||||||
|
|
||||||
interface MxGatewayCliClient extends AutoCloseable {
|
|
||||||
PrintWriter out();
|
|
||||||
|
|
||||||
mxaccess_gateway.v1.MxaccessGateway.OpenSessionReply openSession(OpenSessionRequest request);
|
|
||||||
|
|
||||||
mxaccess_gateway.v1.MxaccessGateway.CloseSessionReply closeSession(CloseSessionRequest request);
|
|
||||||
|
|
||||||
MxGatewayCliSession session(String sessionId);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void close();
|
|
||||||
}
|
|
||||||
|
|
||||||
interface MxGatewayCliSession {
|
|
||||||
int register(String clientName);
|
|
||||||
|
|
||||||
MxCommandReply registerRaw(String clientName);
|
|
||||||
|
|
||||||
int addItem(int serverHandle, String itemDefinition);
|
|
||||||
|
|
||||||
MxCommandReply addItemRaw(int serverHandle, String itemDefinition);
|
|
||||||
|
|
||||||
void advise(int serverHandle, int itemHandle);
|
|
||||||
|
|
||||||
MxCommandReply adviseRaw(int serverHandle, int itemHandle);
|
|
||||||
|
|
||||||
MxCommandReply writeRaw(int serverHandle, int itemHandle, MxValue value, int userId);
|
|
||||||
|
|
||||||
List<SubscribeResult> subscribeBulk(int serverHandle, List<String> items);
|
|
||||||
|
|
||||||
List<SubscribeResult> unsubscribeBulk(int serverHandle, List<Integer> itemHandles);
|
|
||||||
|
|
||||||
MxEventStream streamEventsAfter(long afterWorkerSequence);
|
|
||||||
}
|
|
||||||
|
|
||||||
static final class GrpcMxGatewayCliClientFactory implements MxGatewayCliClientFactory {
|
|
||||||
@Override
|
|
||||||
public MxGatewayCliClient connect(CommonOptions options) {
|
|
||||||
return new GrpcMxGatewayCliClient(MxGatewayClient.connect(options.toClientOptions()), options.spec.commandLine().getOut());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static final class GrpcMxGatewayCliClient implements MxGatewayCliClient {
|
|
||||||
private final MxGatewayClient client;
|
|
||||||
private final PrintWriter out;
|
|
||||||
|
|
||||||
GrpcMxGatewayCliClient(MxGatewayClient client, PrintWriter out) {
|
|
||||||
this.client = client;
|
|
||||||
this.out = out;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PrintWriter out() {
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public mxaccess_gateway.v1.MxaccessGateway.OpenSessionReply openSession(OpenSessionRequest request) {
|
|
||||||
return client.openSessionRaw(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public mxaccess_gateway.v1.MxaccessGateway.CloseSessionReply closeSession(CloseSessionRequest request) {
|
|
||||||
return client.closeSessionRaw(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MxGatewayCliSession session(String sessionId) {
|
|
||||||
return new GrpcMxGatewayCliSession(MxGatewaySession.forSessionId(client, sessionId));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() {
|
|
||||||
client.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
record GrpcMxGatewayCliSession(MxGatewaySession session) implements MxGatewayCliSession {
|
|
||||||
@Override
|
|
||||||
public int register(String clientName) {
|
|
||||||
return session.register(clientName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MxCommandReply registerRaw(String clientName) {
|
|
||||||
return session.registerRaw(clientName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int addItem(int serverHandle, String itemDefinition) {
|
|
||||||
return session.addItem(serverHandle, itemDefinition);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MxCommandReply addItemRaw(int serverHandle, String itemDefinition) {
|
|
||||||
return session.addItemRaw(serverHandle, itemDefinition);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void advise(int serverHandle, int itemHandle) {
|
|
||||||
session.advise(serverHandle, itemHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MxCommandReply adviseRaw(int serverHandle, int itemHandle) {
|
|
||||||
return session.adviseRaw(serverHandle, itemHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MxCommandReply writeRaw(int serverHandle, int itemHandle, MxValue value, int userId) {
|
|
||||||
return session.writeRaw(serverHandle, itemHandle, value, userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<SubscribeResult> subscribeBulk(int serverHandle, List<String> items) {
|
|
||||||
return session.subscribeBulk(serverHandle, items);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<SubscribeResult> unsubscribeBulk(int serverHandle, List<Integer> itemHandles) {
|
|
||||||
return session.unsubscribeBulk(serverHandle, itemHandles);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MxEventStream streamEventsAfter(long afterWorkerSequence) {
|
|
||||||
return session.streamEventsAfter(afterWorkerSequence);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface TextSupplier {
|
|
||||||
String get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void writeOutput(
|
|
||||||
String command, CommonOptions common, boolean json, Message reply, TextSupplier textSupplier) {
|
|
||||||
PrintWriter out = common.spec.commandLine().getOut();
|
|
||||||
if (json) {
|
|
||||||
Map<String, Object> output = new LinkedHashMap<>();
|
|
||||||
output.put("command", command);
|
|
||||||
output.put("options", common.redactedJsonMap());
|
|
||||||
output.put("reply", new RawJson(protoJson(reply)));
|
|
||||||
out.println(jsonObject(output));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
out.println(textSupplier.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void writeBulkOutput(
|
|
||||||
String command, CommonOptions common, boolean json, List<SubscribeResult> results) {
|
|
||||||
PrintWriter out = common.spec.commandLine().getOut();
|
|
||||||
if (json) {
|
|
||||||
Map<String, Object> output = new LinkedHashMap<>();
|
|
||||||
output.put("command", command);
|
|
||||||
output.put("options", common.redactedJsonMap());
|
|
||||||
output.put("results", results.stream().map(MxGatewayCli::subscribeResultMap).toList());
|
|
||||||
out.println(jsonObject(output));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
out.println(results.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Map<String, Object> subscribeResultMap(SubscribeResult result) {
|
|
||||||
Map<String, Object> values = new LinkedHashMap<>();
|
|
||||||
values.put("serverHandle", result.getServerHandle());
|
|
||||||
values.put("tagAddress", result.getTagAddress());
|
|
||||||
values.put("itemHandle", result.getItemHandle());
|
|
||||||
values.put("wasSuccessful", result.getWasSuccessful());
|
|
||||||
values.put("errorMessage", result.getErrorMessage());
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static MxValue parseValue(String type, String text) {
|
|
||||||
return switch (type) {
|
|
||||||
case "bool" -> MxValues.boolValue(Boolean.parseBoolean(text));
|
|
||||||
case "int32" -> MxValues.int32Value(Integer.parseInt(text));
|
|
||||||
case "int64" -> MxValues.int64Value(Long.parseLong(text));
|
|
||||||
case "float" -> MxValues.floatValue(Float.parseFloat(text));
|
|
||||||
case "double" -> MxValues.doubleValue(Double.parseDouble(text));
|
|
||||||
case "string" -> MxValues.stringValue(text);
|
|
||||||
default -> throw new IllegalArgumentException("unsupported value type " + type);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<String> parseStringList(String value) {
|
|
||||||
return Arrays.stream(value.split(","))
|
|
||||||
.map(String::trim)
|
|
||||||
.filter(item -> !item.isBlank())
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<Integer> parseIntList(String value) {
|
|
||||||
return parseStringList(value).stream().map(Integer::parseInt).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Duration parseDuration(String value) {
|
|
||||||
if (value == null || value.isBlank()) {
|
|
||||||
return Duration.ofSeconds(30);
|
|
||||||
}
|
|
||||||
if (value.startsWith("P")) {
|
|
||||||
return Duration.parse(value);
|
|
||||||
}
|
|
||||||
if (value.endsWith("ms")) {
|
|
||||||
return Duration.ofMillis(Long.parseLong(value.substring(0, value.length() - 2)));
|
|
||||||
}
|
|
||||||
if (value.endsWith("s")) {
|
|
||||||
return Duration.ofSeconds(Long.parseLong(value.substring(0, value.length() - 1)));
|
|
||||||
}
|
|
||||||
if (value.endsWith("m")) {
|
|
||||||
return Duration.ofMinutes(Long.parseLong(value.substring(0, value.length() - 1)));
|
|
||||||
}
|
|
||||||
return Duration.parse(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String protoJson(Message message) {
|
|
||||||
try {
|
|
||||||
return JsonFormat.printer().omittingInsignificantWhitespace().print(message);
|
|
||||||
} catch (Exception error) {
|
|
||||||
throw new IllegalStateException("failed to write protobuf JSON", error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String jsonObject(Map<String, Object> values) {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
builder.append('{');
|
|
||||||
boolean first = true;
|
|
||||||
for (Map.Entry<String, Object> entry : values.entrySet()) {
|
|
||||||
if (!first) {
|
|
||||||
builder.append(',');
|
|
||||||
}
|
|
||||||
first = false;
|
|
||||||
builder.append(jsonString(entry.getKey())).append(':').append(jsonValue(entry.getValue()));
|
|
||||||
}
|
|
||||||
builder.append('}');
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private static String jsonValue(Object value) {
|
|
||||||
if (value == null) {
|
|
||||||
return "null";
|
|
||||||
}
|
|
||||||
if (value instanceof RawJson rawJson) {
|
|
||||||
return rawJson.value();
|
|
||||||
}
|
|
||||||
if (value instanceof String string) {
|
|
||||||
return jsonString(string);
|
|
||||||
}
|
|
||||||
if (value instanceof Number || value instanceof Boolean) {
|
|
||||||
return value.toString();
|
|
||||||
}
|
|
||||||
if (value instanceof Map<?, ?> map) {
|
|
||||||
return jsonObject((Map<String, Object>) map);
|
|
||||||
}
|
|
||||||
if (value instanceof Iterable<?> iterable) {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
builder.append('[');
|
|
||||||
boolean first = true;
|
|
||||||
for (Object item : iterable) {
|
|
||||||
if (!first) {
|
|
||||||
builder.append(',');
|
|
||||||
}
|
|
||||||
first = false;
|
|
||||||
builder.append(jsonValue(item));
|
|
||||||
}
|
|
||||||
builder.append(']');
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
return jsonString(value.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String jsonString(String value) {
|
|
||||||
return '"'
|
|
||||||
+ value.replace("\\", "\\\\")
|
|
||||||
.replace("\"", "\\\"")
|
|
||||||
.replace("\r", "\\r")
|
|
||||||
.replace("\n", "\\n")
|
|
||||||
+ '"';
|
|
||||||
}
|
|
||||||
|
|
||||||
private record RawJson(String value) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-309
@@ -1,309 +0,0 @@
|
|||||||
package com.dohertylan.mxgateway.cli;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.AddItemReply;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.CloseSessionReply;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.CloseSessionRequest;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.MxCommandKind;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.MxCommandReply;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.MxEvent;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.MxValue;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.OpenSessionReply;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.OpenSessionRequest;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.ProtocolStatus;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.ProtocolStatusCode;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.RegisterReply;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.SessionState;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.SubscribeResult;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
final class MxGatewayCliTests {
|
|
||||||
@Test
|
|
||||||
void versionCommandPrintsProtocolVersions() {
|
|
||||||
CliRun run = execute(new FakeClientFactory(), "version");
|
|
||||||
|
|
||||||
assertEquals(0, run.exitCode());
|
|
||||||
assertEquals("", run.errors());
|
|
||||||
assertTrue(run.output().contains("mxgateway-java 0.1.0"));
|
|
||||||
assertTrue(run.output().contains("gatewayProtocolVersion=3"));
|
|
||||||
assertTrue(run.output().contains("workerProtocolVersion=1"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void versionCommandPrintsJson() {
|
|
||||||
CliRun run = execute(new FakeClientFactory(), "version", "--json");
|
|
||||||
|
|
||||||
assertEquals(0, run.exitCode());
|
|
||||||
assertTrue(run.output().contains("\"clientVersion\":\"0.1.0\""));
|
|
||||||
assertTrue(run.output().contains("\"gatewayProtocolVersion\":3"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void openSessionJsonRedactsApiKey() {
|
|
||||||
CliRun run = execute(
|
|
||||||
new FakeClientFactory(),
|
|
||||||
"open-session",
|
|
||||||
"--endpoint",
|
|
||||||
"localhost:5000",
|
|
||||||
"--api-key",
|
|
||||||
"mxgw_visible_secret",
|
|
||||||
"--plaintext",
|
|
||||||
"--client-session-name",
|
|
||||||
"java-cli",
|
|
||||||
"--json");
|
|
||||||
|
|
||||||
assertEquals(0, run.exitCode());
|
|
||||||
assertTrue(run.output().contains("\"command\":\"open-session\""));
|
|
||||||
assertTrue(run.output().contains("\"sessionId\":\"session-cli\""));
|
|
||||||
assertTrue(run.output().contains("mxgw***********cret"));
|
|
||||||
assertFalse(run.output().contains("visible_secret"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void writeBuildsTypedValueFromParserOptions() {
|
|
||||||
FakeClientFactory factory = new FakeClientFactory();
|
|
||||||
CliRun run = execute(
|
|
||||||
factory,
|
|
||||||
"write",
|
|
||||||
"--session-id",
|
|
||||||
"session-cli",
|
|
||||||
"--server-handle",
|
|
||||||
"12",
|
|
||||||
"--item-handle",
|
|
||||||
"34",
|
|
||||||
"--type",
|
|
||||||
"int32",
|
|
||||||
"--value",
|
|
||||||
"123",
|
|
||||||
"--json");
|
|
||||||
|
|
||||||
assertEquals(0, run.exitCode());
|
|
||||||
assertEquals(123, factory.client.session.lastWriteValue.getInt32Value());
|
|
||||||
assertTrue(run.output().contains("\"kind\":\"MX_COMMAND_KIND_WRITE\""));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void smokeCommandRunsOpenRegisterAddAdviseAndClose() {
|
|
||||||
FakeClientFactory factory = new FakeClientFactory();
|
|
||||||
CliRun run = execute(factory, "smoke", "--item", "TestObject.TestInt", "--json");
|
|
||||||
|
|
||||||
assertEquals(0, run.exitCode());
|
|
||||||
assertTrue(factory.client.session.registerCalled);
|
|
||||||
assertTrue(factory.client.session.addItemCalled);
|
|
||||||
assertTrue(factory.client.session.adviseCalled);
|
|
||||||
assertTrue(factory.client.closeCalled);
|
|
||||||
assertTrue(run.output().contains("\"serverHandle\":42"));
|
|
||||||
assertTrue(run.output().contains("\"itemHandle\":7"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void subscribeBulkCommandPrintsResults() {
|
|
||||||
CliRun run = execute(
|
|
||||||
new FakeClientFactory(),
|
|
||||||
"subscribe-bulk",
|
|
||||||
"--session-id",
|
|
||||||
"session-cli",
|
|
||||||
"--server-handle",
|
|
||||||
"42",
|
|
||||||
"--items",
|
|
||||||
"TestMachine_001.TestChangingInt,TestMachine_002.TestChangingInt",
|
|
||||||
"--json");
|
|
||||||
|
|
||||||
assertEquals(0, run.exitCode());
|
|
||||||
assertTrue(run.output().contains("\"command\":\"subscribe-bulk\""));
|
|
||||||
assertTrue(run.output().contains("\"itemHandle\":100"));
|
|
||||||
assertTrue(run.output().contains("\"tagAddress\":\"TestMachine_002.TestChangingInt\""));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void unsubscribeBulkCommandPrintsResults() {
|
|
||||||
CliRun run = execute(
|
|
||||||
new FakeClientFactory(),
|
|
||||||
"unsubscribe-bulk",
|
|
||||||
"--session-id",
|
|
||||||
"session-cli",
|
|
||||||
"--server-handle",
|
|
||||||
"42",
|
|
||||||
"--item-handles",
|
|
||||||
"100,101",
|
|
||||||
"--json");
|
|
||||||
|
|
||||||
assertEquals(0, run.exitCode());
|
|
||||||
assertTrue(run.output().contains("\"command\":\"unsubscribe-bulk\""));
|
|
||||||
assertTrue(run.output().contains("\"itemHandle\":101"));
|
|
||||||
assertTrue(run.output().contains("\"wasSuccessful\":true"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static CliRun execute(MxGatewayCli.MxGatewayCliClientFactory factory, String... args) {
|
|
||||||
StringWriter output = new StringWriter();
|
|
||||||
StringWriter errors = new StringWriter();
|
|
||||||
int exitCode = MxGatewayCli.execute(
|
|
||||||
factory,
|
|
||||||
new PrintWriter(output, true),
|
|
||||||
new PrintWriter(errors, true),
|
|
||||||
args);
|
|
||||||
return new CliRun(exitCode, output.toString(), errors.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
private record CliRun(int exitCode, String output, String errors) {
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class FakeClientFactory implements MxGatewayCli.MxGatewayCliClientFactory {
|
|
||||||
private FakeClient client;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MxGatewayCli.MxGatewayCliClient connect(MxGatewayCli.CommonOptions options) {
|
|
||||||
client = new FakeClient(options.spec.commandLine().getOut());
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class FakeClient implements MxGatewayCli.MxGatewayCliClient {
|
|
||||||
private final PrintWriter out;
|
|
||||||
private final FakeSession session = new FakeSession();
|
|
||||||
private boolean closeCalled;
|
|
||||||
|
|
||||||
private FakeClient(PrintWriter out) {
|
|
||||||
this.out = out;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PrintWriter out() {
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OpenSessionReply openSession(OpenSessionRequest request) {
|
|
||||||
return OpenSessionReply.newBuilder()
|
|
||||||
.setSessionId("session-cli")
|
|
||||||
.setProtocolStatus(ok())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CloseSessionReply closeSession(CloseSessionRequest request) {
|
|
||||||
closeCalled = true;
|
|
||||||
return CloseSessionReply.newBuilder()
|
|
||||||
.setSessionId(request.getSessionId())
|
|
||||||
.setFinalState(SessionState.SESSION_STATE_CLOSED)
|
|
||||||
.setProtocolStatus(ok())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MxGatewayCli.MxGatewayCliSession session(String sessionId) {
|
|
||||||
return session;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class FakeSession implements MxGatewayCli.MxGatewayCliSession {
|
|
||||||
private boolean registerCalled;
|
|
||||||
private boolean addItemCalled;
|
|
||||||
private boolean adviseCalled;
|
|
||||||
private MxValue lastWriteValue;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int register(String clientName) {
|
|
||||||
registerCalled = true;
|
|
||||||
return 42;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MxCommandReply registerRaw(String clientName) {
|
|
||||||
registerCalled = true;
|
|
||||||
return MxCommandReply.newBuilder()
|
|
||||||
.setKind(MxCommandKind.MX_COMMAND_KIND_REGISTER)
|
|
||||||
.setProtocolStatus(ok())
|
|
||||||
.setRegister(RegisterReply.newBuilder().setServerHandle(42))
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int addItem(int serverHandle, String itemDefinition) {
|
|
||||||
addItemCalled = true;
|
|
||||||
return 7;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MxCommandReply addItemRaw(int serverHandle, String itemDefinition) {
|
|
||||||
addItemCalled = true;
|
|
||||||
return MxCommandReply.newBuilder()
|
|
||||||
.setKind(MxCommandKind.MX_COMMAND_KIND_ADD_ITEM)
|
|
||||||
.setProtocolStatus(ok())
|
|
||||||
.setAddItem(AddItemReply.newBuilder().setItemHandle(7))
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void advise(int serverHandle, int itemHandle) {
|
|
||||||
adviseCalled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MxCommandReply adviseRaw(int serverHandle, int itemHandle) {
|
|
||||||
adviseCalled = true;
|
|
||||||
return MxCommandReply.newBuilder()
|
|
||||||
.setKind(MxCommandKind.MX_COMMAND_KIND_ADVISE)
|
|
||||||
.setProtocolStatus(ok())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MxCommandReply writeRaw(int serverHandle, int itemHandle, MxValue value, int userId) {
|
|
||||||
lastWriteValue = value;
|
|
||||||
return MxCommandReply.newBuilder()
|
|
||||||
.setKind(MxCommandKind.MX_COMMAND_KIND_WRITE)
|
|
||||||
.setProtocolStatus(ok())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<SubscribeResult> subscribeBulk(int serverHandle, List<String> items) {
|
|
||||||
List<SubscribeResult> results = new ArrayList<>();
|
|
||||||
for (int index = 0; index < items.size(); index++) {
|
|
||||||
results.add(SubscribeResult.newBuilder()
|
|
||||||
.setServerHandle(serverHandle)
|
|
||||||
.setTagAddress(items.get(index))
|
|
||||||
.setItemHandle(100 + index)
|
|
||||||
.setWasSuccessful(true)
|
|
||||||
.build());
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<SubscribeResult> unsubscribeBulk(int serverHandle, List<Integer> itemHandles) {
|
|
||||||
List<SubscribeResult> results = new ArrayList<>();
|
|
||||||
for (Integer itemHandle : itemHandles) {
|
|
||||||
results.add(SubscribeResult.newBuilder()
|
|
||||||
.setServerHandle(serverHandle)
|
|
||||||
.setItemHandle(itemHandle)
|
|
||||||
.setWasSuccessful(true)
|
|
||||||
.build());
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public com.dohertylan.mxgateway.client.MxEventStream streamEventsAfter(long afterWorkerSequence) {
|
|
||||||
throw new UnsupportedOperationException("stream-events is covered by client tests");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ProtocolStatus ok() {
|
|
||||||
return ProtocolStatus.newBuilder()
|
|
||||||
.setCode(ProtocolStatusCode.PROTOCOL_STATUS_CODE_OK)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-65
@@ -1,65 +0,0 @@
|
|||||||
package com.dohertylan.mxgateway.client;
|
|
||||||
|
|
||||||
import galaxy_repository.v1.GalaxyRepositoryOuterClass.DeployEvent;
|
|
||||||
import galaxy_repository.v1.GalaxyRepositoryOuterClass.WatchDeployEventsRequest;
|
|
||||||
import io.grpc.stub.ClientCallStreamObserver;
|
|
||||||
import io.grpc.stub.ClientResponseObserver;
|
|
||||||
import io.grpc.stub.StreamObserver;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cancellable handle returned by the async {@code watchDeployEvents} variant.
|
|
||||||
* Mirrors {@link MxGatewayEventSubscription} but for the Galaxy Repository
|
|
||||||
* deploy-event stream.
|
|
||||||
*/
|
|
||||||
public final class DeployEventSubscription implements AutoCloseable {
|
|
||||||
private final AtomicReference<ClientCallStreamObserver<WatchDeployEventsRequest>> requestStream =
|
|
||||||
new AtomicReference<>();
|
|
||||||
private final AtomicBoolean cancelled = new AtomicBoolean();
|
|
||||||
|
|
||||||
ClientResponseObserver<WatchDeployEventsRequest, DeployEvent> wrap(StreamObserver<DeployEvent> observer) {
|
|
||||||
return new ClientResponseObserver<>() {
|
|
||||||
@Override
|
|
||||||
public void beforeStart(ClientCallStreamObserver<WatchDeployEventsRequest> stream) {
|
|
||||||
requestStream.set(stream);
|
|
||||||
if (cancelled.get()) {
|
|
||||||
stream.cancel("client cancelled deploy event stream", null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNext(DeployEvent value) {
|
|
||||||
observer.onNext(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(Throwable error) {
|
|
||||||
observer.onError(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCompleted() {
|
|
||||||
observer.onCompleted();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cancels the underlying gRPC call. Safe to invoke before the call has
|
|
||||||
* started; cancellation is recorded and applied as soon as the stream
|
|
||||||
* attaches.
|
|
||||||
*/
|
|
||||||
public void cancel() {
|
|
||||||
cancelled.set(true);
|
|
||||||
ClientCallStreamObserver<WatchDeployEventsRequest> stream = requestStream.get();
|
|
||||||
if (stream != null) {
|
|
||||||
stream.cancel("client cancelled deploy event stream", null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() {
|
|
||||||
cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-67
@@ -1,67 +0,0 @@
|
|||||||
package com.dohertylan.mxgateway.client;
|
|
||||||
|
|
||||||
import io.grpc.stub.ClientCallStreamObserver;
|
|
||||||
import io.grpc.stub.ClientResponseObserver;
|
|
||||||
import io.grpc.stub.StreamObserver;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.ActiveAlarmSnapshot;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.QueryActiveAlarmsRequest;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cancellable handle returned by {@code queryActiveAlarms}.
|
|
||||||
*
|
|
||||||
* <p>Wraps a caller-supplied {@link StreamObserver} and exposes a
|
|
||||||
* {@link #cancel()} entry point that aborts the underlying gRPC call. The
|
|
||||||
* subscription also implements {@link AutoCloseable} so it can participate in
|
|
||||||
* try-with-resources blocks.
|
|
||||||
*/
|
|
||||||
public final class MxGatewayActiveAlarmsSubscription implements AutoCloseable {
|
|
||||||
private final AtomicReference<ClientCallStreamObserver<QueryActiveAlarmsRequest>> requestStream = new AtomicReference<>();
|
|
||||||
private final AtomicBoolean cancelled = new AtomicBoolean();
|
|
||||||
|
|
||||||
ClientResponseObserver<QueryActiveAlarmsRequest, ActiveAlarmSnapshot> wrap(StreamObserver<ActiveAlarmSnapshot> observer) {
|
|
||||||
return new ClientResponseObserver<>() {
|
|
||||||
@Override
|
|
||||||
public void beforeStart(ClientCallStreamObserver<QueryActiveAlarmsRequest> stream) {
|
|
||||||
requestStream.set(stream);
|
|
||||||
if (cancelled.get()) {
|
|
||||||
stream.cancel("client cancelled active-alarms query", null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNext(ActiveAlarmSnapshot value) {
|
|
||||||
observer.onNext(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(Throwable error) {
|
|
||||||
observer.onError(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCompleted() {
|
|
||||||
observer.onCompleted();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cancels the underlying gRPC call. Safe to invoke before the call has
|
|
||||||
* started; cancellation is recorded and applied as soon as the stream
|
|
||||||
* attaches.
|
|
||||||
*/
|
|
||||||
public void cancel() {
|
|
||||||
cancelled.set(true);
|
|
||||||
ClientCallStreamObserver<QueryActiveAlarmsRequest> stream = requestStream.get();
|
|
||||||
if (stream != null) {
|
|
||||||
stream.cancel("client cancelled active-alarms query", null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() {
|
|
||||||
cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-67
@@ -1,67 +0,0 @@
|
|||||||
package com.dohertylan.mxgateway.client;
|
|
||||||
|
|
||||||
import io.grpc.stub.ClientCallStreamObserver;
|
|
||||||
import io.grpc.stub.ClientResponseObserver;
|
|
||||||
import io.grpc.stub.StreamObserver;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.MxEvent;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.StreamEventsRequest;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cancellable handle returned by the async {@code streamEvents} variant.
|
|
||||||
*
|
|
||||||
* <p>Wraps a caller-supplied {@link StreamObserver} and exposes a
|
|
||||||
* {@link #cancel()} entry point that aborts the underlying gRPC call. The
|
|
||||||
* subscription also implements {@link AutoCloseable} so it can participate in
|
|
||||||
* try-with-resources blocks.
|
|
||||||
*/
|
|
||||||
public final class MxGatewayEventSubscription implements AutoCloseable {
|
|
||||||
private final AtomicReference<ClientCallStreamObserver<StreamEventsRequest>> requestStream = new AtomicReference<>();
|
|
||||||
private final AtomicBoolean cancelled = new AtomicBoolean();
|
|
||||||
|
|
||||||
ClientResponseObserver<StreamEventsRequest, MxEvent> wrap(StreamObserver<MxEvent> observer) {
|
|
||||||
return new ClientResponseObserver<>() {
|
|
||||||
@Override
|
|
||||||
public void beforeStart(ClientCallStreamObserver<StreamEventsRequest> stream) {
|
|
||||||
requestStream.set(stream);
|
|
||||||
if (cancelled.get()) {
|
|
||||||
stream.cancel("client cancelled event stream", null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNext(MxEvent value) {
|
|
||||||
observer.onNext(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(Throwable error) {
|
|
||||||
observer.onError(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCompleted() {
|
|
||||||
observer.onCompleted();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cancels the underlying gRPC call. Safe to invoke before the call has
|
|
||||||
* started; cancellation is recorded and applied as soon as the stream
|
|
||||||
* attaches.
|
|
||||||
*/
|
|
||||||
public void cancel() {
|
|
||||||
cancelled.set(true);
|
|
||||||
ClientCallStreamObserver<StreamEventsRequest> stream = requestStream.get();
|
|
||||||
if (stream != null) {
|
|
||||||
stream.cancel("client cancelled event stream", null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() {
|
|
||||||
cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-282
@@ -1,282 +0,0 @@
|
|||||||
package com.dohertylan.mxgateway.client;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
|
|
||||||
import io.grpc.Context;
|
|
||||||
import io.grpc.ManagedChannel;
|
|
||||||
import io.grpc.Metadata;
|
|
||||||
import io.grpc.Server;
|
|
||||||
import io.grpc.ServerCall;
|
|
||||||
import io.grpc.ServerCallHandler;
|
|
||||||
import io.grpc.ServerInterceptor;
|
|
||||||
import io.grpc.inprocess.InProcessChannelBuilder;
|
|
||||||
import io.grpc.inprocess.InProcessServerBuilder;
|
|
||||||
import io.grpc.stub.ServerCallStreamObserver;
|
|
||||||
import io.grpc.stub.StreamObserver;
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
import mxaccess_gateway.v1.MxAccessGatewayGrpc;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.AddItemReply;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.BulkSubscribeReply;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.CloseSessionReply;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.CloseSessionRequest;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.MxCommandKind;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.MxCommandReply;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.MxCommandRequest;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.MxEvent;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.OpenSessionReply;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.OpenSessionRequest;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.ProtocolStatus;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.ProtocolStatusCode;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.RegisterReply;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.SessionState;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.StreamEventsRequest;
|
|
||||||
import mxaccess_gateway.v1.MxaccessGateway.SubscribeResult;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
final class MxGatewayClientSessionTests {
|
|
||||||
@Test
|
|
||||||
void unaryCallsCarryAuthMetadataAndDeadline() throws Exception {
|
|
||||||
AtomicReference<String> authorization = new AtomicReference<>();
|
|
||||||
AtomicReference<MxCommandRequest> commandRequest = new AtomicReference<>();
|
|
||||||
AtomicReference<Boolean> deadlineSeen = new AtomicReference<>(false);
|
|
||||||
|
|
||||||
TestGatewayService service = new TestGatewayService() {
|
|
||||||
@Override
|
|
||||||
public void openSession(OpenSessionRequest request, StreamObserver<OpenSessionReply> responseObserver) {
|
|
||||||
deadlineSeen.set(Context.current().getDeadline() != null);
|
|
||||||
responseObserver.onNext(OpenSessionReply.newBuilder()
|
|
||||||
.setSessionId("session-java")
|
|
||||||
.setProtocolStatus(ok())
|
|
||||||
.build());
|
|
||||||
responseObserver.onCompleted();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void invoke(MxCommandRequest request, StreamObserver<MxCommandReply> responseObserver) {
|
|
||||||
commandRequest.set(request);
|
|
||||||
responseObserver.onNext(MxCommandReply.newBuilder()
|
|
||||||
.setSessionId(request.getSessionId())
|
|
||||||
.setKind(request.getCommand().getKind())
|
|
||||||
.setProtocolStatus(ok())
|
|
||||||
.setRegister(RegisterReply.newBuilder().setServerHandle(42))
|
|
||||||
.build());
|
|
||||||
responseObserver.onCompleted();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
try (InProcessGateway gateway = InProcessGateway.start(service, authorization);
|
|
||||||
MxGatewayClient client = gateway.client("mxgw_visible_secret", Duration.ofSeconds(5))) {
|
|
||||||
MxGatewaySession session = client.openSession("junit-session");
|
|
||||||
|
|
||||||
int serverHandle = session.register("java-test-client");
|
|
||||||
|
|
||||||
assertEquals(42, serverHandle);
|
|
||||||
assertEquals("Bearer mxgw_visible_secret", authorization.get());
|
|
||||||
assertEquals("session-java", commandRequest.get().getSessionId());
|
|
||||||
assertEquals(MxCommandKind.MX_COMMAND_KIND_REGISTER, commandRequest.get().getCommand().getKind());
|
|
||||||
assertTrue(deadlineSeen.get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void methodHelpersReturnTypedHandlesAndRawReplies() throws Exception {
|
|
||||||
TestGatewayService service = new TestGatewayService() {
|
|
||||||
@Override
|
|
||||||
public void invoke(MxCommandRequest request, StreamObserver<MxCommandReply> responseObserver) {
|
|
||||||
MxCommandReply.Builder reply = MxCommandReply.newBuilder()
|
|
||||||
.setSessionId(request.getSessionId())
|
|
||||||
.setKind(request.getCommand().getKind())
|
|
||||||
.setProtocolStatus(ok());
|
|
||||||
if (request.getCommand().getKind() == MxCommandKind.MX_COMMAND_KIND_ADD_ITEM) {
|
|
||||||
reply.setAddItem(AddItemReply.newBuilder().setItemHandle(7));
|
|
||||||
}
|
|
||||||
responseObserver.onNext(reply.build());
|
|
||||||
responseObserver.onCompleted();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
try (InProcessGateway gateway = InProcessGateway.start(service, new AtomicReference<>());
|
|
||||||
MxGatewayClient client = gateway.client("", Duration.ofSeconds(5))) {
|
|
||||||
MxGatewaySession session = MxGatewaySession.forSessionId(client, "existing-session");
|
|
||||||
|
|
||||||
int itemHandle = session.addItem(12, "TestObject.TestInt");
|
|
||||||
MxCommandReply raw = session.adviseRaw(12, itemHandle);
|
|
||||||
|
|
||||||
assertEquals(7, itemHandle);
|
|
||||||
assertEquals(MxCommandKind.MX_COMMAND_KIND_ADVISE, raw.getKind());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void subscribeBulkBuildsOneBulkCommandAndReturnsResults() throws Exception {
|
|
||||||
AtomicReference<MxCommandRequest> commandRequest = new AtomicReference<>();
|
|
||||||
TestGatewayService service = new TestGatewayService() {
|
|
||||||
@Override
|
|
||||||
public void invoke(MxCommandRequest request, StreamObserver<MxCommandReply> responseObserver) {
|
|
||||||
commandRequest.set(request);
|
|
||||||
responseObserver.onNext(MxCommandReply.newBuilder()
|
|
||||||
.setSessionId(request.getSessionId())
|
|
||||||
.setKind(request.getCommand().getKind())
|
|
||||||
.setProtocolStatus(ok())
|
|
||||||
.setSubscribeBulk(BulkSubscribeReply.newBuilder()
|
|
||||||
.addResults(SubscribeResult.newBuilder()
|
|
||||||
.setServerHandle(12)
|
|
||||||
.setTagAddress("Area001.Pump001.Speed")
|
|
||||||
.setItemHandle(34)
|
|
||||||
.setWasSuccessful(true)))
|
|
||||||
.build());
|
|
||||||
responseObserver.onCompleted();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
try (InProcessGateway gateway = InProcessGateway.start(service, new AtomicReference<>());
|
|
||||||
MxGatewayClient client = gateway.client("", Duration.ofSeconds(5))) {
|
|
||||||
MxGatewaySession session = MxGatewaySession.forSessionId(client, "existing-session");
|
|
||||||
|
|
||||||
List<SubscribeResult> results = session.subscribeBulk(12, List.of("Area001.Pump001.Speed"));
|
|
||||||
|
|
||||||
assertEquals(34, results.get(0).getItemHandle());
|
|
||||||
assertEquals(MxCommandKind.MX_COMMAND_KIND_SUBSCRIBE_BULK, commandRequest.get().getCommand().getKind());
|
|
||||||
assertEquals(
|
|
||||||
List.of("Area001.Pump001.Speed"),
|
|
||||||
commandRequest.get().getCommand().getSubscribeBulk().getTagAddressesList());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void streamCancellationCancelsServerCall() throws Exception {
|
|
||||||
CountDownLatch cancelled = new CountDownLatch(1);
|
|
||||||
TestGatewayService service = new TestGatewayService() {
|
|
||||||
@Override
|
|
||||||
public void streamEvents(StreamEventsRequest request, StreamObserver<MxEvent> responseObserver) {
|
|
||||||
ServerCallStreamObserver<MxEvent> serverObserver =
|
|
||||||
(ServerCallStreamObserver<MxEvent>) responseObserver;
|
|
||||||
serverObserver.setOnCancelHandler(cancelled::countDown);
|
|
||||||
responseObserver.onNext(MxEvent.newBuilder()
|
|
||||||
.setSessionId(request.getSessionId())
|
|
||||||
.setWorkerSequence(1)
|
|
||||||
.build());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
try (InProcessGateway gateway = InProcessGateway.start(service, new AtomicReference<>());
|
|
||||||
MxGatewayClient client = gateway.client("", Duration.ofSeconds(5))) {
|
|
||||||
MxEventStream events = MxGatewaySession.forSessionId(client, "stream-session").streamEvents();
|
|
||||||
|
|
||||||
assertTrue(events.hasNext());
|
|
||||||
assertEquals(1, events.next().getWorkerSequence());
|
|
||||||
events.close();
|
|
||||||
|
|
||||||
assertTrue(cancelled.await(5, TimeUnit.SECONDS));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void commandFailureKeepsRawReply() throws Exception {
|
|
||||||
TestGatewayService service = new TestGatewayService() {
|
|
||||||
@Override
|
|
||||||
public void invoke(MxCommandRequest request, StreamObserver<MxCommandReply> responseObserver) {
|
|
||||||
responseObserver.onNext(MxCommandReply.newBuilder()
|
|
||||||
.setSessionId(request.getSessionId())
|
|
||||||
.setKind(MxCommandKind.MX_COMMAND_KIND_WRITE)
|
|
||||||
.setProtocolStatus(ProtocolStatus.newBuilder()
|
|
||||||
.setCode(ProtocolStatusCode.PROTOCOL_STATUS_CODE_MXACCESS_FAILURE)
|
|
||||||
.setMessage("MXAccess rejected the write."))
|
|
||||||
.setHresult(-2147220992)
|
|
||||||
.build());
|
|
||||||
responseObserver.onCompleted();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
try (InProcessGateway gateway = InProcessGateway.start(service, new AtomicReference<>());
|
|
||||||
MxGatewayClient client = gateway.client("", Duration.ofSeconds(5))) {
|
|
||||||
MxGatewaySession session = MxGatewaySession.forSessionId(client, "failure-session");
|
|
||||||
|
|
||||||
MxAccessException error = assertThrows(
|
|
||||||
MxAccessException.class,
|
|
||||||
() -> session.write(1, 2, MxValues.int32Value(123), 0));
|
|
||||||
|
|
||||||
assertNotNull(error.reply());
|
|
||||||
assertEquals(-2147220992, error.reply().getHresult());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ProtocolStatus ok() {
|
|
||||||
return ProtocolStatus.newBuilder()
|
|
||||||
.setCode(ProtocolStatusCode.PROTOCOL_STATUS_CODE_OK)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private abstract static class TestGatewayService extends MxAccessGatewayGrpc.MxAccessGatewayImplBase {
|
|
||||||
@Override
|
|
||||||
public void openSession(OpenSessionRequest request, StreamObserver<OpenSessionReply> responseObserver) {
|
|
||||||
responseObserver.onNext(OpenSessionReply.newBuilder()
|
|
||||||
.setSessionId("session-java")
|
|
||||||
.setProtocolStatus(ok())
|
|
||||||
.build());
|
|
||||||
responseObserver.onCompleted();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void closeSession(CloseSessionRequest request, StreamObserver<CloseSessionReply> responseObserver) {
|
|
||||||
responseObserver.onNext(CloseSessionReply.newBuilder()
|
|
||||||
.setSessionId(request.getSessionId())
|
|
||||||
.setFinalState(SessionState.SESSION_STATE_CLOSED)
|
|
||||||
.setProtocolStatus(ok())
|
|
||||||
.build());
|
|
||||||
responseObserver.onCompleted();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private record InProcessGateway(Server server, ManagedChannel channel) implements AutoCloseable {
|
|
||||||
static InProcessGateway start(
|
|
||||||
MxAccessGatewayGrpc.MxAccessGatewayImplBase service, AtomicReference<String> authorization)
|
|
||||||
throws Exception {
|
|
||||||
String serverName = "mxgw-java-" + UUID.randomUUID();
|
|
||||||
ServerInterceptor interceptor = new ServerInterceptor() {
|
|
||||||
@Override
|
|
||||||
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
|
|
||||||
ServerCall<ReqT, RespT> call,
|
|
||||||
Metadata headers,
|
|
||||||
ServerCallHandler<ReqT, RespT> next) {
|
|
||||||
authorization.set(headers.get(MxGatewayAuthInterceptor.AUTHORIZATION_HEADER));
|
|
||||||
return next.startCall(call, headers);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Server server = InProcessServerBuilder.forName(serverName)
|
|
||||||
.directExecutor()
|
|
||||||
.addService(io.grpc.ServerInterceptors.intercept(service, interceptor))
|
|
||||||
.build()
|
|
||||||
.start();
|
|
||||||
ManagedChannel channel = InProcessChannelBuilder.forName(serverName)
|
|
||||||
.directExecutor()
|
|
||||||
.build();
|
|
||||||
return new InProcessGateway(server, channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
MxGatewayClient client(String apiKey, Duration callTimeout) {
|
|
||||||
return new MxGatewayClient(
|
|
||||||
channel,
|
|
||||||
MxGatewayClientOptions.builder()
|
|
||||||
.endpoint("in-process")
|
|
||||||
.apiKey(apiKey)
|
|
||||||
.plaintext(true)
|
|
||||||
.callTimeout(callTimeout)
|
|
||||||
.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() {
|
|
||||||
channel.shutdownNow();
|
|
||||||
server.shutdownNow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,6 +9,10 @@ pluginManagement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id 'org.gradle.toolchains.foojay-resolver-convention' version '1.0.0'
|
||||||
|
}
|
||||||
|
|
||||||
dependencyResolutionManagement {
|
dependencyResolutionManagement {
|
||||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||||
repositories {
|
repositories {
|
||||||
@@ -16,7 +20,7 @@ dependencyResolutionManagement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rootProject.name = 'mxaccessgw-java'
|
rootProject.name = 'zb-mom-ww-mxaccessgw-java'
|
||||||
|
|
||||||
include 'mxgateway-client'
|
include 'zb-mom-ww-mxgateway-client'
|
||||||
include 'mxgateway-cli'
|
include 'zb-mom-ww-mxgateway-cli'
|
||||||
|
|||||||
+111
@@ -142,6 +142,37 @@ public final class GalaxyRepositoryGrpc {
|
|||||||
return getWatchDeployEventsMethod;
|
return getWatchDeployEventsMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static volatile io.grpc.MethodDescriptor<galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenRequest,
|
||||||
|
galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenReply> getBrowseChildrenMethod;
|
||||||
|
|
||||||
|
@io.grpc.stub.annotations.RpcMethod(
|
||||||
|
fullMethodName = SERVICE_NAME + '/' + "BrowseChildren",
|
||||||
|
requestType = galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenRequest.class,
|
||||||
|
responseType = galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenReply.class,
|
||||||
|
methodType = io.grpc.MethodDescriptor.MethodType.UNARY)
|
||||||
|
public static io.grpc.MethodDescriptor<galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenRequest,
|
||||||
|
galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenReply> getBrowseChildrenMethod() {
|
||||||
|
io.grpc.MethodDescriptor<galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenRequest, galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenReply> getBrowseChildrenMethod;
|
||||||
|
if ((getBrowseChildrenMethod = GalaxyRepositoryGrpc.getBrowseChildrenMethod) == null) {
|
||||||
|
synchronized (GalaxyRepositoryGrpc.class) {
|
||||||
|
if ((getBrowseChildrenMethod = GalaxyRepositoryGrpc.getBrowseChildrenMethod) == null) {
|
||||||
|
GalaxyRepositoryGrpc.getBrowseChildrenMethod = getBrowseChildrenMethod =
|
||||||
|
io.grpc.MethodDescriptor.<galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenRequest, galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenReply>newBuilder()
|
||||||
|
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
|
||||||
|
.setFullMethodName(generateFullMethodName(SERVICE_NAME, "BrowseChildren"))
|
||||||
|
.setSampledToLocalTracing(true)
|
||||||
|
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||||
|
galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenRequest.getDefaultInstance()))
|
||||||
|
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||||
|
galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenReply.getDefaultInstance()))
|
||||||
|
.setSchemaDescriptor(new GalaxyRepositoryMethodDescriptorSupplier("BrowseChildren"))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getBrowseChildrenMethod;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new async stub that supports all call types for the service
|
* Creates a new async stub that supports all call types for the service
|
||||||
*/
|
*/
|
||||||
@@ -246,6 +277,19 @@ public final class GalaxyRepositoryGrpc {
|
|||||||
io.grpc.stub.StreamObserver<galaxy_repository.v1.GalaxyRepositoryOuterClass.DeployEvent> responseObserver) {
|
io.grpc.stub.StreamObserver<galaxy_repository.v1.GalaxyRepositoryOuterClass.DeployEvent> responseObserver) {
|
||||||
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getWatchDeployEventsMethod(), responseObserver);
|
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getWatchDeployEventsMethod(), responseObserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* Returns the direct children of a parent object (or the root objects when
|
||||||
|
* `parent` is unset). Designed for OPC UA-style lazy expand: clients walk
|
||||||
|
* one level at a time instead of paging the full hierarchy. Filters mirror
|
||||||
|
* DiscoverHierarchy exactly. Backed by the same shared hierarchy cache.
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
default void browseChildren(galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenRequest request,
|
||||||
|
io.grpc.stub.StreamObserver<galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenReply> responseObserver) {
|
||||||
|
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getBrowseChildrenMethod(), responseObserver);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -326,6 +370,20 @@ public final class GalaxyRepositoryGrpc {
|
|||||||
io.grpc.stub.ClientCalls.asyncServerStreamingCall(
|
io.grpc.stub.ClientCalls.asyncServerStreamingCall(
|
||||||
getChannel().newCall(getWatchDeployEventsMethod(), getCallOptions()), request, responseObserver);
|
getChannel().newCall(getWatchDeployEventsMethod(), getCallOptions()), request, responseObserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* Returns the direct children of a parent object (or the root objects when
|
||||||
|
* `parent` is unset). Designed for OPC UA-style lazy expand: clients walk
|
||||||
|
* one level at a time instead of paging the full hierarchy. Filters mirror
|
||||||
|
* DiscoverHierarchy exactly. Backed by the same shared hierarchy cache.
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
public void browseChildren(galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenRequest request,
|
||||||
|
io.grpc.stub.StreamObserver<galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenReply> responseObserver) {
|
||||||
|
io.grpc.stub.ClientCalls.asyncUnaryCall(
|
||||||
|
getChannel().newCall(getBrowseChildrenMethod(), getCallOptions()), request, responseObserver);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -387,6 +445,19 @@ public final class GalaxyRepositoryGrpc {
|
|||||||
return io.grpc.stub.ClientCalls.blockingV2ServerStreamingCall(
|
return io.grpc.stub.ClientCalls.blockingV2ServerStreamingCall(
|
||||||
getChannel(), getWatchDeployEventsMethod(), getCallOptions(), request);
|
getChannel(), getWatchDeployEventsMethod(), getCallOptions(), request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* Returns the direct children of a parent object (or the root objects when
|
||||||
|
* `parent` is unset). Designed for OPC UA-style lazy expand: clients walk
|
||||||
|
* one level at a time instead of paging the full hierarchy. Filters mirror
|
||||||
|
* DiscoverHierarchy exactly. Backed by the same shared hierarchy cache.
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
public galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenReply browseChildren(galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenRequest request) throws io.grpc.StatusException {
|
||||||
|
return io.grpc.stub.ClientCalls.blockingV2UnaryCall(
|
||||||
|
getChannel(), getBrowseChildrenMethod(), getCallOptions(), request);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -447,6 +518,19 @@ public final class GalaxyRepositoryGrpc {
|
|||||||
return io.grpc.stub.ClientCalls.blockingServerStreamingCall(
|
return io.grpc.stub.ClientCalls.blockingServerStreamingCall(
|
||||||
getChannel(), getWatchDeployEventsMethod(), getCallOptions(), request);
|
getChannel(), getWatchDeployEventsMethod(), getCallOptions(), request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* Returns the direct children of a parent object (or the root objects when
|
||||||
|
* `parent` is unset). Designed for OPC UA-style lazy expand: clients walk
|
||||||
|
* one level at a time instead of paging the full hierarchy. Filters mirror
|
||||||
|
* DiscoverHierarchy exactly. Backed by the same shared hierarchy cache.
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
public galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenReply browseChildren(galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenRequest request) {
|
||||||
|
return io.grpc.stub.ClientCalls.blockingUnaryCall(
|
||||||
|
getChannel(), getBrowseChildrenMethod(), getCallOptions(), request);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -494,12 +578,27 @@ public final class GalaxyRepositoryGrpc {
|
|||||||
return io.grpc.stub.ClientCalls.futureUnaryCall(
|
return io.grpc.stub.ClientCalls.futureUnaryCall(
|
||||||
getChannel().newCall(getDiscoverHierarchyMethod(), getCallOptions()), request);
|
getChannel().newCall(getDiscoverHierarchyMethod(), getCallOptions()), request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* Returns the direct children of a parent object (or the root objects when
|
||||||
|
* `parent` is unset). Designed for OPC UA-style lazy expand: clients walk
|
||||||
|
* one level at a time instead of paging the full hierarchy. Filters mirror
|
||||||
|
* DiscoverHierarchy exactly. Backed by the same shared hierarchy cache.
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
public com.google.common.util.concurrent.ListenableFuture<galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenReply> browseChildren(
|
||||||
|
galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenRequest request) {
|
||||||
|
return io.grpc.stub.ClientCalls.futureUnaryCall(
|
||||||
|
getChannel().newCall(getBrowseChildrenMethod(), getCallOptions()), request);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int METHODID_TEST_CONNECTION = 0;
|
private static final int METHODID_TEST_CONNECTION = 0;
|
||||||
private static final int METHODID_GET_LAST_DEPLOY_TIME = 1;
|
private static final int METHODID_GET_LAST_DEPLOY_TIME = 1;
|
||||||
private static final int METHODID_DISCOVER_HIERARCHY = 2;
|
private static final int METHODID_DISCOVER_HIERARCHY = 2;
|
||||||
private static final int METHODID_WATCH_DEPLOY_EVENTS = 3;
|
private static final int METHODID_WATCH_DEPLOY_EVENTS = 3;
|
||||||
|
private static final int METHODID_BROWSE_CHILDREN = 4;
|
||||||
|
|
||||||
private static final class MethodHandlers<Req, Resp> implements
|
private static final class MethodHandlers<Req, Resp> implements
|
||||||
io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
|
io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
|
||||||
@@ -534,6 +633,10 @@ public final class GalaxyRepositoryGrpc {
|
|||||||
serviceImpl.watchDeployEvents((galaxy_repository.v1.GalaxyRepositoryOuterClass.WatchDeployEventsRequest) request,
|
serviceImpl.watchDeployEvents((galaxy_repository.v1.GalaxyRepositoryOuterClass.WatchDeployEventsRequest) request,
|
||||||
(io.grpc.stub.StreamObserver<galaxy_repository.v1.GalaxyRepositoryOuterClass.DeployEvent>) responseObserver);
|
(io.grpc.stub.StreamObserver<galaxy_repository.v1.GalaxyRepositoryOuterClass.DeployEvent>) responseObserver);
|
||||||
break;
|
break;
|
||||||
|
case METHODID_BROWSE_CHILDREN:
|
||||||
|
serviceImpl.browseChildren((galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenRequest) request,
|
||||||
|
(io.grpc.stub.StreamObserver<galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenReply>) responseObserver);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
@@ -580,6 +683,13 @@ public final class GalaxyRepositoryGrpc {
|
|||||||
galaxy_repository.v1.GalaxyRepositoryOuterClass.WatchDeployEventsRequest,
|
galaxy_repository.v1.GalaxyRepositoryOuterClass.WatchDeployEventsRequest,
|
||||||
galaxy_repository.v1.GalaxyRepositoryOuterClass.DeployEvent>(
|
galaxy_repository.v1.GalaxyRepositoryOuterClass.DeployEvent>(
|
||||||
service, METHODID_WATCH_DEPLOY_EVENTS)))
|
service, METHODID_WATCH_DEPLOY_EVENTS)))
|
||||||
|
.addMethod(
|
||||||
|
getBrowseChildrenMethod(),
|
||||||
|
io.grpc.stub.ServerCalls.asyncUnaryCall(
|
||||||
|
new MethodHandlers<
|
||||||
|
galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenRequest,
|
||||||
|
galaxy_repository.v1.GalaxyRepositoryOuterClass.BrowseChildrenReply>(
|
||||||
|
service, METHODID_BROWSE_CHILDREN)))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -632,6 +742,7 @@ public final class GalaxyRepositoryGrpc {
|
|||||||
.addMethod(getGetLastDeployTimeMethod())
|
.addMethod(getGetLastDeployTimeMethod())
|
||||||
.addMethod(getDiscoverHierarchyMethod())
|
.addMethod(getDiscoverHierarchyMethod())
|
||||||
.addMethod(getWatchDeployEventsMethod())
|
.addMethod(getWatchDeployEventsMethod())
|
||||||
|
.addMethod(getBrowseChildrenMethod())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+301
@@ -139,6 +139,99 @@ public final class MxAccessGatewayGrpc {
|
|||||||
return getStreamEventsMethod;
|
return getStreamEventsMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static volatile io.grpc.MethodDescriptor<mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmRequest,
|
||||||
|
mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmReply> getAcknowledgeAlarmMethod;
|
||||||
|
|
||||||
|
@io.grpc.stub.annotations.RpcMethod(
|
||||||
|
fullMethodName = SERVICE_NAME + '/' + "AcknowledgeAlarm",
|
||||||
|
requestType = mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmRequest.class,
|
||||||
|
responseType = mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmReply.class,
|
||||||
|
methodType = io.grpc.MethodDescriptor.MethodType.UNARY)
|
||||||
|
public static io.grpc.MethodDescriptor<mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmRequest,
|
||||||
|
mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmReply> getAcknowledgeAlarmMethod() {
|
||||||
|
io.grpc.MethodDescriptor<mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmRequest, mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmReply> getAcknowledgeAlarmMethod;
|
||||||
|
if ((getAcknowledgeAlarmMethod = MxAccessGatewayGrpc.getAcknowledgeAlarmMethod) == null) {
|
||||||
|
synchronized (MxAccessGatewayGrpc.class) {
|
||||||
|
if ((getAcknowledgeAlarmMethod = MxAccessGatewayGrpc.getAcknowledgeAlarmMethod) == null) {
|
||||||
|
MxAccessGatewayGrpc.getAcknowledgeAlarmMethod = getAcknowledgeAlarmMethod =
|
||||||
|
io.grpc.MethodDescriptor.<mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmRequest, mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmReply>newBuilder()
|
||||||
|
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
|
||||||
|
.setFullMethodName(generateFullMethodName(SERVICE_NAME, "AcknowledgeAlarm"))
|
||||||
|
.setSampledToLocalTracing(true)
|
||||||
|
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||||
|
mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmRequest.getDefaultInstance()))
|
||||||
|
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||||
|
mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmReply.getDefaultInstance()))
|
||||||
|
.setSchemaDescriptor(new MxAccessGatewayMethodDescriptorSupplier("AcknowledgeAlarm"))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getAcknowledgeAlarmMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static volatile io.grpc.MethodDescriptor<mxaccess_gateway.v1.MxaccessGateway.StreamAlarmsRequest,
|
||||||
|
mxaccess_gateway.v1.MxaccessGateway.AlarmFeedMessage> getStreamAlarmsMethod;
|
||||||
|
|
||||||
|
@io.grpc.stub.annotations.RpcMethod(
|
||||||
|
fullMethodName = SERVICE_NAME + '/' + "StreamAlarms",
|
||||||
|
requestType = mxaccess_gateway.v1.MxaccessGateway.StreamAlarmsRequest.class,
|
||||||
|
responseType = mxaccess_gateway.v1.MxaccessGateway.AlarmFeedMessage.class,
|
||||||
|
methodType = io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING)
|
||||||
|
public static io.grpc.MethodDescriptor<mxaccess_gateway.v1.MxaccessGateway.StreamAlarmsRequest,
|
||||||
|
mxaccess_gateway.v1.MxaccessGateway.AlarmFeedMessage> getStreamAlarmsMethod() {
|
||||||
|
io.grpc.MethodDescriptor<mxaccess_gateway.v1.MxaccessGateway.StreamAlarmsRequest, mxaccess_gateway.v1.MxaccessGateway.AlarmFeedMessage> getStreamAlarmsMethod;
|
||||||
|
if ((getStreamAlarmsMethod = MxAccessGatewayGrpc.getStreamAlarmsMethod) == null) {
|
||||||
|
synchronized (MxAccessGatewayGrpc.class) {
|
||||||
|
if ((getStreamAlarmsMethod = MxAccessGatewayGrpc.getStreamAlarmsMethod) == null) {
|
||||||
|
MxAccessGatewayGrpc.getStreamAlarmsMethod = getStreamAlarmsMethod =
|
||||||
|
io.grpc.MethodDescriptor.<mxaccess_gateway.v1.MxaccessGateway.StreamAlarmsRequest, mxaccess_gateway.v1.MxaccessGateway.AlarmFeedMessage>newBuilder()
|
||||||
|
.setType(io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING)
|
||||||
|
.setFullMethodName(generateFullMethodName(SERVICE_NAME, "StreamAlarms"))
|
||||||
|
.setSampledToLocalTracing(true)
|
||||||
|
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||||
|
mxaccess_gateway.v1.MxaccessGateway.StreamAlarmsRequest.getDefaultInstance()))
|
||||||
|
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||||
|
mxaccess_gateway.v1.MxaccessGateway.AlarmFeedMessage.getDefaultInstance()))
|
||||||
|
.setSchemaDescriptor(new MxAccessGatewayMethodDescriptorSupplier("StreamAlarms"))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getStreamAlarmsMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static volatile io.grpc.MethodDescriptor<mxaccess_gateway.v1.MxaccessGateway.QueryActiveAlarmsRequest,
|
||||||
|
mxaccess_gateway.v1.MxaccessGateway.ActiveAlarmSnapshot> getQueryActiveAlarmsMethod;
|
||||||
|
|
||||||
|
@io.grpc.stub.annotations.RpcMethod(
|
||||||
|
fullMethodName = SERVICE_NAME + '/' + "QueryActiveAlarms",
|
||||||
|
requestType = mxaccess_gateway.v1.MxaccessGateway.QueryActiveAlarmsRequest.class,
|
||||||
|
responseType = mxaccess_gateway.v1.MxaccessGateway.ActiveAlarmSnapshot.class,
|
||||||
|
methodType = io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING)
|
||||||
|
public static io.grpc.MethodDescriptor<mxaccess_gateway.v1.MxaccessGateway.QueryActiveAlarmsRequest,
|
||||||
|
mxaccess_gateway.v1.MxaccessGateway.ActiveAlarmSnapshot> getQueryActiveAlarmsMethod() {
|
||||||
|
io.grpc.MethodDescriptor<mxaccess_gateway.v1.MxaccessGateway.QueryActiveAlarmsRequest, mxaccess_gateway.v1.MxaccessGateway.ActiveAlarmSnapshot> getQueryActiveAlarmsMethod;
|
||||||
|
if ((getQueryActiveAlarmsMethod = MxAccessGatewayGrpc.getQueryActiveAlarmsMethod) == null) {
|
||||||
|
synchronized (MxAccessGatewayGrpc.class) {
|
||||||
|
if ((getQueryActiveAlarmsMethod = MxAccessGatewayGrpc.getQueryActiveAlarmsMethod) == null) {
|
||||||
|
MxAccessGatewayGrpc.getQueryActiveAlarmsMethod = getQueryActiveAlarmsMethod =
|
||||||
|
io.grpc.MethodDescriptor.<mxaccess_gateway.v1.MxaccessGateway.QueryActiveAlarmsRequest, mxaccess_gateway.v1.MxaccessGateway.ActiveAlarmSnapshot>newBuilder()
|
||||||
|
.setType(io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING)
|
||||||
|
.setFullMethodName(generateFullMethodName(SERVICE_NAME, "QueryActiveAlarms"))
|
||||||
|
.setSampledToLocalTracing(true)
|
||||||
|
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||||
|
mxaccess_gateway.v1.MxaccessGateway.QueryActiveAlarmsRequest.getDefaultInstance()))
|
||||||
|
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||||
|
mxaccess_gateway.v1.MxaccessGateway.ActiveAlarmSnapshot.getDefaultInstance()))
|
||||||
|
.setSchemaDescriptor(new MxAccessGatewayMethodDescriptorSupplier("QueryActiveAlarms"))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getQueryActiveAlarmsMethod;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new async stub that supports all call types for the service
|
* Creates a new async stub that supports all call types for the service
|
||||||
*/
|
*/
|
||||||
@@ -232,6 +325,44 @@ public final class MxAccessGatewayGrpc {
|
|||||||
io.grpc.stub.StreamObserver<mxaccess_gateway.v1.MxaccessGateway.MxEvent> responseObserver) {
|
io.grpc.stub.StreamObserver<mxaccess_gateway.v1.MxaccessGateway.MxEvent> responseObserver) {
|
||||||
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getStreamEventsMethod(), responseObserver);
|
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getStreamEventsMethod(), responseObserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
default void acknowledgeAlarm(mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmRequest request,
|
||||||
|
io.grpc.stub.StreamObserver<mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmReply> responseObserver) {
|
||||||
|
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getAcknowledgeAlarmMethod(), responseObserver);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* Session-less central alarm feed. The stream opens with the current
|
||||||
|
* active-alarm snapshot (one `active_alarm` per alarm), then a single
|
||||||
|
* `snapshot_complete`, then a `transition` for every subsequent change.
|
||||||
|
* Served by the gateway's always-on alarm monitor; any number of clients
|
||||||
|
* fan out from the single monitor without opening a worker session.
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
default void streamAlarms(mxaccess_gateway.v1.MxaccessGateway.StreamAlarmsRequest request,
|
||||||
|
io.grpc.stub.StreamObserver<mxaccess_gateway.v1.MxaccessGateway.AlarmFeedMessage> responseObserver) {
|
||||||
|
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getStreamAlarmsMethod(), responseObserver);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* Point-in-time snapshot of the currently-active alarm set served from the
|
||||||
|
* gateway's always-on alarm monitor cache (session-less). Used after a
|
||||||
|
* reconnect to seed Part 9 client state, or to reconcile alarms that may
|
||||||
|
* have been missed during a transport blip. Streamed so callers can
|
||||||
|
* begin processing without buffering the full set.
|
||||||
|
* `QueryActiveAlarmsRequest.alarm_filter_prefix` optionally narrows the
|
||||||
|
* snapshot to alarms whose `alarm_full_reference` starts with the given
|
||||||
|
* prefix; an empty prefix returns the full set.
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
default void queryActiveAlarms(mxaccess_gateway.v1.MxaccessGateway.QueryActiveAlarmsRequest request,
|
||||||
|
io.grpc.stub.StreamObserver<mxaccess_gateway.v1.MxaccessGateway.ActiveAlarmSnapshot> responseObserver) {
|
||||||
|
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getQueryActiveAlarmsMethod(), responseObserver);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -298,6 +429,47 @@ public final class MxAccessGatewayGrpc {
|
|||||||
io.grpc.stub.ClientCalls.asyncServerStreamingCall(
|
io.grpc.stub.ClientCalls.asyncServerStreamingCall(
|
||||||
getChannel().newCall(getStreamEventsMethod(), getCallOptions()), request, responseObserver);
|
getChannel().newCall(getStreamEventsMethod(), getCallOptions()), request, responseObserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public void acknowledgeAlarm(mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmRequest request,
|
||||||
|
io.grpc.stub.StreamObserver<mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmReply> responseObserver) {
|
||||||
|
io.grpc.stub.ClientCalls.asyncUnaryCall(
|
||||||
|
getChannel().newCall(getAcknowledgeAlarmMethod(), getCallOptions()), request, responseObserver);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* Session-less central alarm feed. The stream opens with the current
|
||||||
|
* active-alarm snapshot (one `active_alarm` per alarm), then a single
|
||||||
|
* `snapshot_complete`, then a `transition` for every subsequent change.
|
||||||
|
* Served by the gateway's always-on alarm monitor; any number of clients
|
||||||
|
* fan out from the single monitor without opening a worker session.
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
public void streamAlarms(mxaccess_gateway.v1.MxaccessGateway.StreamAlarmsRequest request,
|
||||||
|
io.grpc.stub.StreamObserver<mxaccess_gateway.v1.MxaccessGateway.AlarmFeedMessage> responseObserver) {
|
||||||
|
io.grpc.stub.ClientCalls.asyncServerStreamingCall(
|
||||||
|
getChannel().newCall(getStreamAlarmsMethod(), getCallOptions()), request, responseObserver);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* Point-in-time snapshot of the currently-active alarm set served from the
|
||||||
|
* gateway's always-on alarm monitor cache (session-less). Used after a
|
||||||
|
* reconnect to seed Part 9 client state, or to reconcile alarms that may
|
||||||
|
* have been missed during a transport blip. Streamed so callers can
|
||||||
|
* begin processing without buffering the full set.
|
||||||
|
* `QueryActiveAlarmsRequest.alarm_filter_prefix` optionally narrows the
|
||||||
|
* snapshot to alarms whose `alarm_full_reference` starts with the given
|
||||||
|
* prefix; an empty prefix returns the full set.
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
public void queryActiveAlarms(mxaccess_gateway.v1.MxaccessGateway.QueryActiveAlarmsRequest request,
|
||||||
|
io.grpc.stub.StreamObserver<mxaccess_gateway.v1.MxaccessGateway.ActiveAlarmSnapshot> responseObserver) {
|
||||||
|
io.grpc.stub.ClientCalls.asyncServerStreamingCall(
|
||||||
|
getChannel().newCall(getQueryActiveAlarmsMethod(), getCallOptions()), request, responseObserver);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -348,6 +520,48 @@ public final class MxAccessGatewayGrpc {
|
|||||||
return io.grpc.stub.ClientCalls.blockingV2ServerStreamingCall(
|
return io.grpc.stub.ClientCalls.blockingV2ServerStreamingCall(
|
||||||
getChannel(), getStreamEventsMethod(), getCallOptions(), request);
|
getChannel(), getStreamEventsMethod(), getCallOptions(), request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmReply acknowledgeAlarm(mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmRequest request) throws io.grpc.StatusException {
|
||||||
|
return io.grpc.stub.ClientCalls.blockingV2UnaryCall(
|
||||||
|
getChannel(), getAcknowledgeAlarmMethod(), getCallOptions(), request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* Session-less central alarm feed. The stream opens with the current
|
||||||
|
* active-alarm snapshot (one `active_alarm` per alarm), then a single
|
||||||
|
* `snapshot_complete`, then a `transition` for every subsequent change.
|
||||||
|
* Served by the gateway's always-on alarm monitor; any number of clients
|
||||||
|
* fan out from the single monitor without opening a worker session.
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/10918")
|
||||||
|
public io.grpc.stub.BlockingClientCall<?, mxaccess_gateway.v1.MxaccessGateway.AlarmFeedMessage>
|
||||||
|
streamAlarms(mxaccess_gateway.v1.MxaccessGateway.StreamAlarmsRequest request) {
|
||||||
|
return io.grpc.stub.ClientCalls.blockingV2ServerStreamingCall(
|
||||||
|
getChannel(), getStreamAlarmsMethod(), getCallOptions(), request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* Point-in-time snapshot of the currently-active alarm set served from the
|
||||||
|
* gateway's always-on alarm monitor cache (session-less). Used after a
|
||||||
|
* reconnect to seed Part 9 client state, or to reconcile alarms that may
|
||||||
|
* have been missed during a transport blip. Streamed so callers can
|
||||||
|
* begin processing without buffering the full set.
|
||||||
|
* `QueryActiveAlarmsRequest.alarm_filter_prefix` optionally narrows the
|
||||||
|
* snapshot to alarms whose `alarm_full_reference` starts with the given
|
||||||
|
* prefix; an empty prefix returns the full set.
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/10918")
|
||||||
|
public io.grpc.stub.BlockingClientCall<?, mxaccess_gateway.v1.MxaccessGateway.ActiveAlarmSnapshot>
|
||||||
|
queryActiveAlarms(mxaccess_gateway.v1.MxaccessGateway.QueryActiveAlarmsRequest request) {
|
||||||
|
return io.grpc.stub.ClientCalls.blockingV2ServerStreamingCall(
|
||||||
|
getChannel(), getQueryActiveAlarmsMethod(), getCallOptions(), request);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -397,6 +611,46 @@ public final class MxAccessGatewayGrpc {
|
|||||||
return io.grpc.stub.ClientCalls.blockingServerStreamingCall(
|
return io.grpc.stub.ClientCalls.blockingServerStreamingCall(
|
||||||
getChannel(), getStreamEventsMethod(), getCallOptions(), request);
|
getChannel(), getStreamEventsMethod(), getCallOptions(), request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmReply acknowledgeAlarm(mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmRequest request) {
|
||||||
|
return io.grpc.stub.ClientCalls.blockingUnaryCall(
|
||||||
|
getChannel(), getAcknowledgeAlarmMethod(), getCallOptions(), request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* Session-less central alarm feed. The stream opens with the current
|
||||||
|
* active-alarm snapshot (one `active_alarm` per alarm), then a single
|
||||||
|
* `snapshot_complete`, then a `transition` for every subsequent change.
|
||||||
|
* Served by the gateway's always-on alarm monitor; any number of clients
|
||||||
|
* fan out from the single monitor without opening a worker session.
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
public java.util.Iterator<mxaccess_gateway.v1.MxaccessGateway.AlarmFeedMessage> streamAlarms(
|
||||||
|
mxaccess_gateway.v1.MxaccessGateway.StreamAlarmsRequest request) {
|
||||||
|
return io.grpc.stub.ClientCalls.blockingServerStreamingCall(
|
||||||
|
getChannel(), getStreamAlarmsMethod(), getCallOptions(), request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* Point-in-time snapshot of the currently-active alarm set served from the
|
||||||
|
* gateway's always-on alarm monitor cache (session-less). Used after a
|
||||||
|
* reconnect to seed Part 9 client state, or to reconcile alarms that may
|
||||||
|
* have been missed during a transport blip. Streamed so callers can
|
||||||
|
* begin processing without buffering the full set.
|
||||||
|
* `QueryActiveAlarmsRequest.alarm_filter_prefix` optionally narrows the
|
||||||
|
* snapshot to alarms whose `alarm_full_reference` starts with the given
|
||||||
|
* prefix; an empty prefix returns the full set.
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
public java.util.Iterator<mxaccess_gateway.v1.MxaccessGateway.ActiveAlarmSnapshot> queryActiveAlarms(
|
||||||
|
mxaccess_gateway.v1.MxaccessGateway.QueryActiveAlarmsRequest request) {
|
||||||
|
return io.grpc.stub.ClientCalls.blockingServerStreamingCall(
|
||||||
|
getChannel(), getQueryActiveAlarmsMethod(), getCallOptions(), request);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -441,12 +695,23 @@ public final class MxAccessGatewayGrpc {
|
|||||||
return io.grpc.stub.ClientCalls.futureUnaryCall(
|
return io.grpc.stub.ClientCalls.futureUnaryCall(
|
||||||
getChannel().newCall(getInvokeMethod(), getCallOptions()), request);
|
getChannel().newCall(getInvokeMethod(), getCallOptions()), request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public com.google.common.util.concurrent.ListenableFuture<mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmReply> acknowledgeAlarm(
|
||||||
|
mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmRequest request) {
|
||||||
|
return io.grpc.stub.ClientCalls.futureUnaryCall(
|
||||||
|
getChannel().newCall(getAcknowledgeAlarmMethod(), getCallOptions()), request);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int METHODID_OPEN_SESSION = 0;
|
private static final int METHODID_OPEN_SESSION = 0;
|
||||||
private static final int METHODID_CLOSE_SESSION = 1;
|
private static final int METHODID_CLOSE_SESSION = 1;
|
||||||
private static final int METHODID_INVOKE = 2;
|
private static final int METHODID_INVOKE = 2;
|
||||||
private static final int METHODID_STREAM_EVENTS = 3;
|
private static final int METHODID_STREAM_EVENTS = 3;
|
||||||
|
private static final int METHODID_ACKNOWLEDGE_ALARM = 4;
|
||||||
|
private static final int METHODID_STREAM_ALARMS = 5;
|
||||||
|
private static final int METHODID_QUERY_ACTIVE_ALARMS = 6;
|
||||||
|
|
||||||
private static final class MethodHandlers<Req, Resp> implements
|
private static final class MethodHandlers<Req, Resp> implements
|
||||||
io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
|
io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
|
||||||
@@ -481,6 +746,18 @@ public final class MxAccessGatewayGrpc {
|
|||||||
serviceImpl.streamEvents((mxaccess_gateway.v1.MxaccessGateway.StreamEventsRequest) request,
|
serviceImpl.streamEvents((mxaccess_gateway.v1.MxaccessGateway.StreamEventsRequest) request,
|
||||||
(io.grpc.stub.StreamObserver<mxaccess_gateway.v1.MxaccessGateway.MxEvent>) responseObserver);
|
(io.grpc.stub.StreamObserver<mxaccess_gateway.v1.MxaccessGateway.MxEvent>) responseObserver);
|
||||||
break;
|
break;
|
||||||
|
case METHODID_ACKNOWLEDGE_ALARM:
|
||||||
|
serviceImpl.acknowledgeAlarm((mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmRequest) request,
|
||||||
|
(io.grpc.stub.StreamObserver<mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmReply>) responseObserver);
|
||||||
|
break;
|
||||||
|
case METHODID_STREAM_ALARMS:
|
||||||
|
serviceImpl.streamAlarms((mxaccess_gateway.v1.MxaccessGateway.StreamAlarmsRequest) request,
|
||||||
|
(io.grpc.stub.StreamObserver<mxaccess_gateway.v1.MxaccessGateway.AlarmFeedMessage>) responseObserver);
|
||||||
|
break;
|
||||||
|
case METHODID_QUERY_ACTIVE_ALARMS:
|
||||||
|
serviceImpl.queryActiveAlarms((mxaccess_gateway.v1.MxaccessGateway.QueryActiveAlarmsRequest) request,
|
||||||
|
(io.grpc.stub.StreamObserver<mxaccess_gateway.v1.MxaccessGateway.ActiveAlarmSnapshot>) responseObserver);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
@@ -527,6 +804,27 @@ public final class MxAccessGatewayGrpc {
|
|||||||
mxaccess_gateway.v1.MxaccessGateway.StreamEventsRequest,
|
mxaccess_gateway.v1.MxaccessGateway.StreamEventsRequest,
|
||||||
mxaccess_gateway.v1.MxaccessGateway.MxEvent>(
|
mxaccess_gateway.v1.MxaccessGateway.MxEvent>(
|
||||||
service, METHODID_STREAM_EVENTS)))
|
service, METHODID_STREAM_EVENTS)))
|
||||||
|
.addMethod(
|
||||||
|
getAcknowledgeAlarmMethod(),
|
||||||
|
io.grpc.stub.ServerCalls.asyncUnaryCall(
|
||||||
|
new MethodHandlers<
|
||||||
|
mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmRequest,
|
||||||
|
mxaccess_gateway.v1.MxaccessGateway.AcknowledgeAlarmReply>(
|
||||||
|
service, METHODID_ACKNOWLEDGE_ALARM)))
|
||||||
|
.addMethod(
|
||||||
|
getStreamAlarmsMethod(),
|
||||||
|
io.grpc.stub.ServerCalls.asyncServerStreamingCall(
|
||||||
|
new MethodHandlers<
|
||||||
|
mxaccess_gateway.v1.MxaccessGateway.StreamAlarmsRequest,
|
||||||
|
mxaccess_gateway.v1.MxaccessGateway.AlarmFeedMessage>(
|
||||||
|
service, METHODID_STREAM_ALARMS)))
|
||||||
|
.addMethod(
|
||||||
|
getQueryActiveAlarmsMethod(),
|
||||||
|
io.grpc.stub.ServerCalls.asyncServerStreamingCall(
|
||||||
|
new MethodHandlers<
|
||||||
|
mxaccess_gateway.v1.MxaccessGateway.QueryActiveAlarmsRequest,
|
||||||
|
mxaccess_gateway.v1.MxaccessGateway.ActiveAlarmSnapshot>(
|
||||||
|
service, METHODID_QUERY_ACTIVE_ALARMS)))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -579,6 +877,9 @@ public final class MxAccessGatewayGrpc {
|
|||||||
.addMethod(getCloseSessionMethod())
|
.addMethod(getCloseSessionMethod())
|
||||||
.addMethod(getInvokeMethod())
|
.addMethod(getInvokeMethod())
|
||||||
.addMethod(getStreamEventsMethod())
|
.addMethod(getStreamEventsMethod())
|
||||||
|
.addMethod(getAcknowledgeAlarmMethod())
|
||||||
|
.addMethod(getStreamAlarmsMethod())
|
||||||
|
.addMethod(getQueryActiveAlarmsMethod())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3862
-76
File diff suppressed because it is too large
Load Diff
+43171
-427
File diff suppressed because it is too large
Load Diff
@@ -12608,8 +12608,8 @@ public final class MxaccessWorker extends com.google.protobuf.GeneratedFile {
|
|||||||
"CONVERSION_FAILED\020\010\022\"\n\036WORKER_FAULT_CATE" +
|
"CONVERSION_FAILED\020\010\022\"\n\036WORKER_FAULT_CATE" +
|
||||||
"GORY_STA_HUNG\020\t\022(\n$WORKER_FAULT_CATEGORY" +
|
"GORY_STA_HUNG\020\t\022(\n$WORKER_FAULT_CATEGORY" +
|
||||||
"_QUEUE_OVERFLOW\020\n\022*\n&WORKER_FAULT_CATEGO" +
|
"_QUEUE_OVERFLOW\020\n\022*\n&WORKER_FAULT_CATEGO" +
|
||||||
"RY_SHUTDOWN_TIMEOUT\020\013B\034\252\002\031MxGateway.Cont" +
|
"RY_SHUTDOWN_TIMEOUT\020\013B&\252\002#ZB.MOM.WW.MxGa" +
|
||||||
"racts.Protob\006proto3"
|
"teway.Contracts.Protob\006proto3"
|
||||||
};
|
};
|
||||||
descriptor = com.google.protobuf.Descriptors.FileDescriptor
|
descriptor = com.google.protobuf.Descriptors.FileDescriptor
|
||||||
.internalBuildGeneratedFileFrom(descriptorData,
|
.internalBuildGeneratedFileFrom(descriptorData,
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
plugins {
|
||||||
|
id 'application'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation project(':zb-mom-ww-mxgateway-client')
|
||||||
|
implementation "com.google.protobuf:protobuf-java-util:${protobufVersion}"
|
||||||
|
implementation "info.picocli:picocli:${picocliVersion}"
|
||||||
|
|
||||||
|
testImplementation "io.grpc:grpc-inprocess:${grpcVersion}"
|
||||||
|
testImplementation "io.grpc:grpc-testing:${grpcVersion}"
|
||||||
|
}
|
||||||
|
|
||||||
|
application {
|
||||||
|
mainClass = 'com.zb.mom.ww.mxgateway.cli.MxGatewayCli'
|
||||||
|
}
|
||||||
+2298
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user