Compare commits
324
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ddcc85bbc0 | ||
|
|
1b9c4fba2f | ||
|
|
49c7683d58 | ||
|
|
a8a474dd7f | ||
|
|
19450f4029 | ||
|
|
86d54fdd68 | ||
|
|
b413f519b5 | ||
|
|
9f3e0898b9 | ||
|
|
7709f250f6 | ||
|
|
dc31b4919d | ||
|
|
0f8f7f3adc | ||
|
|
eae4f571ee | ||
|
|
e85cdcb453 | ||
|
|
2c7f47ef17 | ||
|
|
b9f7d0b1a2 | ||
|
|
7feed957a3 | ||
|
|
14031da8eb | ||
|
|
6fee0d99d9 | ||
|
|
5db7a20a41 | ||
|
|
250f7d4b6d | ||
|
|
dd02b83bc1 | ||
|
|
26c3af44e0 | ||
|
|
90a59b764e | ||
|
|
df750c4dd0 | ||
|
|
c35d7c90f6 | ||
|
|
1c2dc2c39c | ||
|
|
3faffbe22a | ||
|
|
7864c3238c | ||
|
|
cf4a8599e7 | ||
|
|
7459a4f224 | ||
|
|
f1451b102d | ||
|
|
23b2758a05 | ||
|
|
5c3a57ceb5 | ||
|
|
888a6bc536 | ||
|
|
0514d8f434 | ||
|
|
cf0adfd910 | ||
|
|
bfc87bfdf0 | ||
|
|
d9c8c61e47 | ||
|
|
3398f44b33 | ||
|
|
f4cef5aadb | ||
|
|
e12769df8e | ||
|
|
6e5ddb734f | ||
|
|
b4345cfa24 | ||
|
|
54566ade60 | ||
|
|
06a80040ff | ||
|
|
2e9b4c78f3 | ||
|
|
2b62668df8 | ||
|
|
17ca432f87 | ||
|
|
2c8833bdfe | ||
|
|
e0ab5713b6 | ||
|
|
c31b52e1df | ||
|
|
2e7478629f | ||
|
|
3afc447538 | ||
|
|
56887327e1 | ||
|
|
6c89cd6717 | ||
|
|
5243490d5f | ||
|
|
0d04eea483 | ||
|
|
3abfac1a20 | ||
|
|
574694e06e | ||
|
|
c30bba7d5c | ||
|
|
48695d3f7f | ||
|
|
3ef40387f3 | ||
|
|
776625891e | ||
|
|
fcdd869831 | ||
|
|
6a7efacac9 | ||
|
|
489b289a6d | ||
|
|
e75cc05137 | ||
|
|
f75fe665c1 | ||
|
|
58bd35be01 | ||
|
|
89143b25c7 | ||
|
|
aec005505f | ||
|
|
103725887f | ||
|
|
1ce7ddd252 | ||
|
|
3e1000e8e7 | ||
|
|
5561c54345 | ||
|
|
c7269176ca | ||
|
|
ec34e8b2f2 | ||
|
|
a54f9530b9 | ||
|
|
53850044c0 | ||
|
|
8e91091e3c | ||
|
|
92ffade5da | ||
|
|
b636cf76f2 | ||
|
|
ac001b65c6 | ||
|
|
bc3869f087 | ||
|
|
66583356ac | ||
|
|
ef11c6e418 | ||
|
|
361e4bdd48 | ||
|
|
44ad5861fc | ||
|
|
0ea6563ddb | ||
|
|
ff7f8fce49 | ||
|
|
cc28ba41d1 | ||
|
|
6fcec2c370 | ||
|
|
76393216c1 | ||
|
|
3e792a41e0 | ||
|
|
298273de91 | ||
|
|
d256ec508b | ||
|
|
8293f1764e | ||
|
|
0a119b3f03 | ||
|
|
e4940bba40 | ||
|
|
6b2a86f4f1 | ||
|
|
01b9d49df2 | ||
|
|
f3d7a9210d | ||
|
|
32e766f56c | ||
|
|
58557311d4 | ||
|
|
412a2576e0 | ||
|
|
06de560169 | ||
|
|
80b62a5a33 | ||
|
|
f05cff4ada | ||
|
|
b2d04363b6 | ||
|
|
d9d2f70917 | ||
|
|
3d07e8cf3d | ||
|
|
68f75a6f44 | ||
|
|
ad0b6968ad | ||
|
|
fdaff5dcf5 | ||
|
|
ffa92ea4ae | ||
|
|
dd305b9c3f | ||
|
|
07b581e980 | ||
|
|
79fadf3dba | ||
|
|
c05d90fd26 | ||
|
|
51f60188f5 | ||
|
|
cf93176991 | ||
|
|
6aa9307a3c | ||
|
|
3eb3cfbf9f | ||
|
|
501671c9c5 | ||
|
|
9d62fcde3d | ||
|
|
50b4c8807e | ||
|
|
c6f6dc8bf4 | ||
|
|
fb528d4683 | ||
|
|
f1b2206577 | ||
|
|
68d1865f36 | ||
|
|
3c8431837b | ||
|
|
e0d413b884 | ||
|
|
ff8ebaa326 | ||
|
|
370b84b6dd | ||
|
|
715246c9c7 | ||
|
|
a1f195721a | ||
|
|
d7de423e35 | ||
|
|
244b3de513 | ||
|
|
0683abbda6 | ||
|
|
9d2886fe67 | ||
|
|
2ac815949c | ||
|
|
046f451e76 | ||
|
|
36f191d49a | ||
|
|
f55237029f | ||
|
|
6fcf096924 | ||
|
|
547383c8d9 | ||
|
|
dc74b62304 | ||
|
|
8907681bb2 | ||
|
|
f16b921630 | ||
|
|
614e9c69e1 | ||
|
|
5a59303dd4 | ||
|
|
d427538cd9 | ||
|
|
46888af8fb | ||
|
|
efaef11e7c | ||
|
|
c095614c67 | ||
|
|
f41114ee13 | ||
|
|
39c33f082f | ||
|
|
a3c0bc977e | ||
|
|
3a39b3c516 | ||
|
|
9265746198 | ||
|
|
0236e3a47a | ||
|
|
71d52c2dc9 | ||
|
|
ce0b4872ff | ||
|
|
b686159cf3 | ||
|
|
ee7c8c393e | ||
|
|
7c4191289f | ||
|
|
f18949a1e3 | ||
|
|
f3b9cb2d62 | ||
|
|
faeb10cf9d | ||
|
|
e5f1039671 | ||
|
|
39de6bdb2d | ||
|
|
e93f970706 | ||
|
|
844677dae0 | ||
|
|
3541feef87 | ||
|
|
776a589945 | ||
|
|
396f72d7c1 | ||
|
|
62a9917a48 | ||
|
|
a3dd7c3815 | ||
|
|
e669cf6b77 | ||
|
|
c5e3c4aa18 | ||
|
|
be35ed120b | ||
|
|
9846bf3936 | ||
|
|
cb5fcee2ce | ||
|
|
08319cfd38 | ||
|
|
777c276437 | ||
|
|
5ab0e1f886 | ||
|
|
a90896f606 | ||
|
|
3f6f5ab0e0 | ||
|
|
24e5683ad2 | ||
|
|
34999d0a5a | ||
|
|
ace7ae2695 | ||
|
|
f9016907e6 | ||
|
|
0913fe28d4 | ||
|
|
400b4ff848 | ||
|
|
5a36a5f4d4 | ||
|
|
0f6539ed00 | ||
|
|
475bf1effc | ||
|
|
ec1e657687 | ||
|
|
284c84dfe6 | ||
|
|
b78c61bf44 | ||
|
|
09a41775bb | ||
|
|
b9ef3ddf91 | ||
|
|
e516496fe8 | ||
|
|
a55705db75 | ||
|
|
e39ad91e1c | ||
|
|
658472b2a8 | ||
|
|
1ad94cfe49 | ||
|
|
22a5a9a4c1 | ||
|
|
e5bbc26da5 | ||
|
|
6a628a3070 | ||
|
|
ac120658eb | ||
|
|
85a36384ce | ||
|
|
563833bc67 | ||
|
|
d77ac1600b | ||
|
|
3b41a2065a | ||
|
|
f993f01634 | ||
|
|
e7067a708b | ||
|
|
04ac2b9d3d | ||
|
|
66c6b0bf8c | ||
|
|
03dd4000fe | ||
|
|
e928295e71 | ||
|
|
b94c5823e9 | ||
|
|
467e81b543 | ||
|
|
8f7409b3e7 | ||
|
|
0d19702e12 | ||
|
|
466fa265fe | ||
|
|
ebd1852221 | ||
|
|
f1130160b1 | ||
|
|
99fba0b3ce | ||
|
|
89afbbd00a | ||
|
|
9e4af550f8 | ||
|
|
ea67280252 | ||
|
|
8c06d84a8b | ||
|
|
941186a12a | ||
|
|
0984007c6e | ||
|
|
2bb7a89777 | ||
|
|
15fc3cb785 | ||
|
|
725396589e | ||
|
|
6fc1ec4d67 | ||
|
|
0496b299dd | ||
|
|
b55c4103df | ||
|
|
6604eaaea7 | ||
|
|
29e5c72969 | ||
|
|
21e07e1b2e | ||
|
|
74afdde8de | ||
|
|
0a92ad2eb1 | ||
|
|
56d207c3f1 | ||
|
|
9172e752e3 | ||
|
|
adc9f2acfc | ||
|
|
41d17e67d2 | ||
|
|
5cacff073b | ||
|
|
c8da92c250 | ||
|
|
c4e76076e3 | ||
|
|
6a715b9a68 | ||
|
|
1f28940c95 | ||
|
|
ebff40b88f | ||
|
|
a6d14a3ac3 | ||
|
|
af96bcb9e3 | ||
|
|
619702cb04 | ||
|
|
5baec19aff | ||
|
|
39ef30c1e3 | ||
|
|
c2f2d28914 | ||
|
|
e06bc3bdf5 | ||
|
|
e19c19c013 | ||
|
|
8f324bc507 | ||
|
|
12107c42ce | ||
|
|
91c6fb4e52 | ||
|
|
7044355547 | ||
|
|
583ae65fb2 | ||
|
|
552fec0edc | ||
|
|
fcf6927fbf | ||
|
|
23f6d827d5 | ||
|
|
f083d0abab | ||
|
|
a895e36922 | ||
|
|
59d7a72288 | ||
|
|
7731f2f4d1 | ||
|
|
41ae5897c0 | ||
|
|
c7949ccfba | ||
|
|
567af79c7f | ||
|
|
6bb4a7b25c | ||
|
|
bc7cef4c34 | ||
|
|
ab9dc361d6 | ||
|
|
39da0a4dde | ||
|
|
44e864d697 | ||
|
|
0a02da3aba | ||
|
|
836771a7f0 | ||
|
|
f386badcfb | ||
|
|
1d43a484db | ||
|
|
91042cb41e | ||
|
|
10c0e4247d | ||
|
|
8e34264e6d | ||
|
|
0a840d256b | ||
|
|
8a69c51cac | ||
|
|
0262fd40bc | ||
|
|
859dfe3544 | ||
|
|
9c624a2f79 | ||
|
|
dec1061b40 | ||
|
|
be4895faa6 | ||
|
|
3c9755f0dd | ||
|
|
61ed847d7d | ||
|
|
fc9094fea8 | ||
|
|
e36c0efc4b | ||
|
|
4158a14cff | ||
|
|
201a45cba0 | ||
|
|
ab31b9b253 | ||
|
|
780ddc79a7 | ||
|
|
d5a2adaed6 | ||
|
|
008ab3f068 | ||
|
|
7d926f588d | ||
|
|
707cd07876 | ||
|
|
f7ecb9090c | ||
|
|
a19e8a7315 | ||
|
|
cf189ecf81 | ||
|
|
4405b7adcb | ||
|
|
e51ee7b7b9 | ||
|
|
dfaa74f426 | ||
|
|
1d2ce59009 | ||
|
|
3602cc05bb | ||
|
|
ac88a81ac6 | ||
|
|
01fa8e0c63 | ||
|
|
59547e0f37 | ||
|
|
3ce100a9cf | ||
|
|
6513fb0cd5 | ||
|
|
fd0fb1f760 |
No files matched your search
@@ -66,7 +66,6 @@ RUN \
|
||||
|
||||
# Dotnet
|
||||
RUN apt-get update && apt-get install -y dotnet7
|
||||
RUN apt-get update && apt-get install -y dotnet8
|
||||
|
||||
# Node
|
||||
ARG node_major=18
|
||||
@@ -88,6 +87,15 @@ RUN dpkg -i /emumba/emumba-deribit-connector-3.3.1-Linux.LICENSE_DISABLED.deb \
|
||||
# Pcap
|
||||
RUN apt-get update && apt-get install -y libpcap0.8-dev
|
||||
|
||||
# Databento (deps)
|
||||
RUN apt-get update && apt-get -y install libzstd-dev
|
||||
|
||||
# Docker in Docker
|
||||
RUN apt-get update && apt-get install -y \
|
||||
docker.io \
|
||||
docker-compose \
|
||||
docker-compose-v2
|
||||
|
||||
# Set up default executables (update-alternatives)
|
||||
RUN \
|
||||
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-$clang_major 100; \
|
||||
@@ -121,3 +129,5 @@ RUN \
|
||||
-G sudo \
|
||||
--password "$(openssl passwd -1 "$docker_pass")" \
|
||||
"$docker_user"
|
||||
|
||||
RUN usermod -aG docker "$docker_user"
|
||||
@@ -18,27 +18,12 @@
|
||||
"runArgs": [
|
||||
"--shm-size",
|
||||
"2gb",
|
||||
"-p",
|
||||
"5000:5000",
|
||||
"-p",
|
||||
"5001:5001",
|
||||
"-p",
|
||||
"5173:5173",
|
||||
"-p",
|
||||
"5174:5174",
|
||||
"-p",
|
||||
"8000:8000",
|
||||
"-p",
|
||||
"8001:8001",
|
||||
"-p",
|
||||
"8002:8002",
|
||||
"-p",
|
||||
"8003:8003",
|
||||
"-p",
|
||||
"12345:12345",
|
||||
"--network",
|
||||
"host"
|
||||
],
|
||||
"mounts": [
|
||||
"source=${localEnv:HOME}/.bts/devcontainer-mounts/${devcontainerId},target=/home/bts,type=bind"
|
||||
"source=${localEnv:HOME}/.bts/devcontainer-mounts/${devcontainerId},target=/home/bts,type=bind",
|
||||
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind"
|
||||
],
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
*.cmd text=auto eol=crlf
|
||||
*.cs text=auto eol=crlf
|
||||
*.sh text=auto eol=lf
|
||||
*.py text=auto eol=lf
|
||||
Vendored
+141
-42
@@ -6,18 +6,52 @@
|
||||
"type": "coreclr",
|
||||
"request": "attach"
|
||||
},
|
||||
{
|
||||
"name": "Api Server",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"program": "",
|
||||
"windows": {
|
||||
"preLaunchTask": "Build Api Server (Debug)",
|
||||
"program": "spark_api_server.exe",
|
||||
"args": [
|
||||
"run",
|
||||
"--sparkd",
|
||||
"http://127.0.0.1:8000/config"
|
||||
],
|
||||
"cwd": "build/Debug/bin/net7.0",
|
||||
},
|
||||
"stopAtEntry": false,
|
||||
"console": "integratedTerminal"
|
||||
},
|
||||
{
|
||||
"name": "Api Server (Skip Build)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"program": "",
|
||||
"windows": {
|
||||
"program": "spark_api_server.exe",
|
||||
"args": [
|
||||
"run",
|
||||
"--sparkd",
|
||||
"http://127.0.0.1:8000/config"
|
||||
],
|
||||
"cwd": "build/Debug/bin/net7.0",
|
||||
},
|
||||
"stopAtEntry": false,
|
||||
"console": "integratedTerminal"
|
||||
},
|
||||
{
|
||||
"name": "Bts.DataStreamWebApp.Server",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "Build DataStream WebApp (Debug)",
|
||||
"program": "${workspaceFolder}/build/Debug/bin/net8.0/Bts.DataStreamWebApp.Server.dll",
|
||||
"args": [
|
||||
"--sparkd",
|
||||
"http://localhost:8000/config",
|
||||
],
|
||||
"program": "${workspaceFolder}/build/Debug/bin/net7.0/Bts.DataStreamWebApp.Server.dll",
|
||||
"cwd": "${workspaceFolder}/build/Debug/bin/net7.0",
|
||||
"env": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||
"ASPNETCORE_HTTP_PORT": "8080",
|
||||
"ASPNETCORE_HTTPS_PORT": "8443",
|
||||
"ASPNETCORE_ENVIRONMENT": "${input:dataStreamWebAppServerEnvironment}",
|
||||
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy",
|
||||
}
|
||||
},
|
||||
@@ -25,13 +59,12 @@
|
||||
"name": "Bts.DataStreamWebApp.Server (Skip Build)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/build/Debug/bin/net8.0/Bts.DataStreamWebApp.Server.dll",
|
||||
// "args": [
|
||||
// "--config",
|
||||
// "${workspaceFolder}/src/DataStreamSuite/Bts.DataStreamWebApp.Server/Configurations/DevServer.json",
|
||||
// ],
|
||||
"program": "${workspaceFolder}/build/Debug/bin/net7.0/Bts.DataStreamWebApp.Server.dll",
|
||||
"cwd": "${workspaceFolder}/build/Debug/bin/net7.0",
|
||||
"env": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||
"ASPNETCORE_HTTP_PORT": "8080",
|
||||
"ASPNETCORE_HTTPS_PORT": "8443",
|
||||
"ASPNETCORE_ENVIRONMENT": "${input:dataStreamWebAppServerEnvironment}",
|
||||
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy",
|
||||
}
|
||||
},
|
||||
@@ -47,10 +80,9 @@
|
||||
"windows": {
|
||||
"program": "DataStreamPublisher.exe",
|
||||
},
|
||||
"args": [
|
||||
"--config",
|
||||
"${workspaceFolder}/src/DataStreamSuite/DataStreamPublisher/Configurations/${input:dataStreamPublisherConfig}.json"
|
||||
],
|
||||
"env": {
|
||||
"DOTNET_ENVIRONMENT": "${input:dataStreamPublisherEnvironment}",
|
||||
},
|
||||
"cwd": "${workspaceFolder}/build/Debug/bin/net7.0",
|
||||
"stopAtEntry": false,
|
||||
"console": "integratedTerminal"
|
||||
@@ -66,10 +98,9 @@
|
||||
"windows": {
|
||||
"program": "DataStreamPublisher.exe",
|
||||
},
|
||||
"args": [
|
||||
"--config",
|
||||
"${workspaceFolder}/src/DataStreamSuite/DataStreamPublisher/Configurations/${input:dataStreamPublisherConfig}.json"
|
||||
],
|
||||
"env": {
|
||||
"DOTNET_ENVIRONMENT": "${input:dataStreamPublisherEnvironment}",
|
||||
},
|
||||
"cwd": "${workspaceFolder}/build/Debug/bin/net7.0",
|
||||
"stopAtEntry": false,
|
||||
"console": "integratedTerminal"
|
||||
@@ -106,11 +137,10 @@
|
||||
"windows": {
|
||||
"program": "PubSubServer.exe",
|
||||
},
|
||||
"args": [
|
||||
"--config",
|
||||
"${workspaceFolder}/src/DataStreamSuite/PubSubServer/Configurations/${input:pubSubServerConfig}.json"
|
||||
],
|
||||
"cwd": "build/Debug/bin/net7.0",
|
||||
"env": {
|
||||
"DOTNET_ENVIRONMENT": "${input:pubSubServerEnvironment}",
|
||||
},
|
||||
"stopAtEntry": false,
|
||||
"console": "integratedTerminal"
|
||||
},
|
||||
@@ -125,11 +155,10 @@
|
||||
"windows": {
|
||||
"program": "PubSubServer.exe",
|
||||
},
|
||||
"args": [
|
||||
"--config",
|
||||
"${workspaceFolder}/src/DataStreamSuite/PubSubServer/Configurations/${input:pubSubServerConfig}.json"
|
||||
],
|
||||
"cwd": "build/Debug/bin/net7.0",
|
||||
"env": {
|
||||
"DOTNET_ENVIRONMENT": "${input:pubSubServerEnvironment}",
|
||||
},
|
||||
"stopAtEntry": false,
|
||||
"console": "integratedTerminal"
|
||||
},
|
||||
@@ -141,6 +170,10 @@
|
||||
"windows": {
|
||||
"preLaunchTask": "Build Spark (Debug)",
|
||||
"program": "Spark.exe",
|
||||
"args": [
|
||||
"--sparkd",
|
||||
"http://127.0.0.1:8000/config"
|
||||
],
|
||||
"cwd": "build/Debug/bin/net7.0-windows",
|
||||
},
|
||||
"stopAtEntry": false,
|
||||
@@ -165,43 +198,99 @@
|
||||
},
|
||||
{
|
||||
"name": "Sparkd",
|
||||
"type": "coreclr",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "Build Sparkd (Debug | Clang)",
|
||||
"program": "",
|
||||
"linux": {
|
||||
"program": "sparkd",
|
||||
"program": "${workspaceFolder}/build/sparkd-debug-clang/src/app_sparkd/sparkd",
|
||||
},
|
||||
"args": [
|
||||
"run"
|
||||
],
|
||||
"cwd": "build/sparkd-debug-clang/server",
|
||||
"cwd": "${workspaceFolder}/build/sparkd-debug-clang/src/app_sparkd",
|
||||
"stopAtEntry": false,
|
||||
"console": "integratedTerminal"
|
||||
}
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
},
|
||||
{
|
||||
"description": "Set Disassembly Flavor to Intel",
|
||||
"text": "-gdb-set disassembly-flavor intel",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Sparkd (Skip Build)",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "",
|
||||
"linux": {
|
||||
"program": "${workspaceFolder}/build/sparkd-debug-clang/src/app_sparkd/sparkd",
|
||||
},
|
||||
"args": [
|
||||
"test-py-md-provider"
|
||||
],
|
||||
"cwd": "${workspaceFolder}/build/sparkd-debug-clang/src/app_sparkd",
|
||||
"stopAtEntry": false,
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
},
|
||||
{
|
||||
"description": "Set Disassembly Flavor to Intel",
|
||||
"text": "-gdb-set disassembly-flavor intel",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
},
|
||||
],
|
||||
"inputs": [
|
||||
{
|
||||
"id": "dataStreamPublisherConfig",
|
||||
"id": "dataStreamPublisherEnvironment",
|
||||
"type": "pickString",
|
||||
"description": "Publisher Configuration",
|
||||
"options": [
|
||||
"MarketDataPublisher",
|
||||
"SimpleEchoClient",
|
||||
"SimpleTestDataPublisher",
|
||||
"TestDataPublisher",
|
||||
"Development",
|
||||
"MarketData",
|
||||
"Production",
|
||||
"ProductionAws",
|
||||
"Staging",
|
||||
],
|
||||
"default": "MarketDataPublisher",
|
||||
},
|
||||
{
|
||||
"id": "pubSubServerConfig",
|
||||
"id": "pubSubServerEnvironment",
|
||||
"type": "pickString",
|
||||
"description": "PubSub Configuration",
|
||||
"options": [
|
||||
"PubSubServer",
|
||||
"SimpleEchoClient",
|
||||
"Development",
|
||||
"EchoServer",
|
||||
"Production",
|
||||
"ProductionAws",
|
||||
"Staging",
|
||||
],
|
||||
"default": "PubSubServer",
|
||||
"default": "Development",
|
||||
},
|
||||
{
|
||||
"id": "dataStreamWebAppServerEnvironment",
|
||||
"type": "pickString",
|
||||
"description": "DataStream WebApp Environment",
|
||||
"options": [
|
||||
"Development",
|
||||
"Production",
|
||||
"ProductionAws",
|
||||
"Staging",
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "sparkConfigServer",
|
||||
@@ -209,5 +298,15 @@
|
||||
"description": "Config Server URL",
|
||||
"default": "http://localhost:8000/config",
|
||||
},
|
||||
{
|
||||
"id": "isSparkApiEnabled",
|
||||
"type": "pickString",
|
||||
"description": "Enable Spark Api (connect to sparkd)",
|
||||
"options": [
|
||||
"True",
|
||||
"False",
|
||||
],
|
||||
"default": "True",
|
||||
}
|
||||
]
|
||||
}
|
||||
Vendored
+103
@@ -212,6 +212,26 @@
|
||||
"color": "terminal.ansiCyan"
|
||||
},
|
||||
},
|
||||
{
|
||||
"label": "Build DataStream WebApp (Release)",
|
||||
"group": "build",
|
||||
"type": "process",
|
||||
"command": "",
|
||||
"linux": {
|
||||
"command": "tools/build_data_stream_web_app.sh",
|
||||
},
|
||||
"windows": {
|
||||
"command": "tools/build_data_stream_web_app.cmd",
|
||||
},
|
||||
"args": [
|
||||
"--configuration",
|
||||
"Release",
|
||||
],
|
||||
"icon": {
|
||||
"id": "terminal",
|
||||
"color": "terminal.ansiCyan"
|
||||
},
|
||||
},
|
||||
{
|
||||
"label": "Build Spark",
|
||||
"group": "build",
|
||||
@@ -587,6 +607,89 @@
|
||||
"color": "terminal.ansiGreen",
|
||||
},
|
||||
},
|
||||
{
|
||||
"label": "Run DataStream WebApp (Debug)",
|
||||
"dependsOn": "Build DataStream WebApp (Debug)",
|
||||
"command": "",
|
||||
"linux": {
|
||||
"command": "Bts.DataStreamWebApp.Server",
|
||||
},
|
||||
"windows": {
|
||||
"command": "Bts.DataStreamWebApp.Server.exe",
|
||||
},
|
||||
"args": [
|
||||
"--config",
|
||||
"${workspaceFolder}/src/DataStreamSuite/Bts.DataStreamWebApp.Server/Configurations/DevServer.json",
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}/build/Debug/bin/net7.0",
|
||||
"env": {
|
||||
"ASPNETCORE_HTTP_PORT": "8080",
|
||||
"ASPNETCORE_HTTPS_PORT": "8443",
|
||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy",
|
||||
}
|
||||
},
|
||||
"icon": {
|
||||
"id": "run",
|
||||
"color": "terminal.ansiGreen",
|
||||
},
|
||||
},
|
||||
{
|
||||
"label": "Run DataStream WebApp (Release)",
|
||||
"dependsOn": "Build DataStream WebApp (Release)",
|
||||
"command": "",
|
||||
"linux": {
|
||||
"command": "Bts.DataStreamWebApp.Server",
|
||||
},
|
||||
"windows": {
|
||||
"command": "Bts.DataStreamWebApp.Server.exe",
|
||||
},
|
||||
"args": [
|
||||
"--config",
|
||||
"${workspaceFolder}/src/DataStreamSuite/Bts.DataStreamWebApp.Server/Configurations/DevServer.json",
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}/build/Release/bin/net7.0",
|
||||
"env": {
|
||||
"ASPNETCORE_HTTP_PORT": "8080",
|
||||
"ASPNETCORE_HTTPS_PORT": "8443",
|
||||
"ASPNETCORE_ENVIRONMENT": "Production",
|
||||
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy",
|
||||
}
|
||||
},
|
||||
"icon": {
|
||||
"id": "run",
|
||||
"color": "terminal.ansiGreen",
|
||||
},
|
||||
},
|
||||
{
|
||||
"label": "Run DataStream WebApp (Release | Skip Build)",
|
||||
"command": "",
|
||||
"linux": {
|
||||
"command": "Bts.DataStreamWebApp.Server",
|
||||
},
|
||||
"windows": {
|
||||
"command": "Bts.DataStreamWebApp.Server.exe",
|
||||
},
|
||||
"args": [
|
||||
"--config",
|
||||
"${workspaceFolder}/src/DataStreamSuite/Bts.DataStreamWebApp.Server/Configurations/DevServer.json",
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}/build/Release/bin/net7.0",
|
||||
"env": {
|
||||
"ASPNETCORE_HTTP_PORT": "8080",
|
||||
"ASPNETCORE_HTTPS_PORT": "8443",
|
||||
"ASPNETCORE_ENVIRONMENT": "Production",
|
||||
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy",
|
||||
}
|
||||
},
|
||||
"icon": {
|
||||
"id": "run",
|
||||
"color": "terminal.ansiGreen",
|
||||
},
|
||||
},
|
||||
{
|
||||
"label": "Run PubSubServer",
|
||||
"dependsOn": "Build DataStream",
|
||||
|
||||
+15
-46
@@ -18,10 +18,10 @@ set(
|
||||
# SHARED_MEMORY_PREFIX serves as a kind of namespace so multiple applications
|
||||
# can run simultaneously without fighting over the same shm files (e.g., sparkd,
|
||||
# api server, etc.).
|
||||
set(SHARED_MEMORY_PREFIX "bts" CACHE STRING "Prefix to use when creating shared memory files")
|
||||
set(SPARK_BIN "${EXTERNALS_ROOT}/bin")
|
||||
set(SPARK_INCLUDE "${EXTERNALS_ROOT}/include")
|
||||
set(SPARK_LIB "${EXTERNALS_ROOT}/lib/$<CONFIG>")
|
||||
set(SHARED_MEMORY_PREFIX "\${BTS_SHARED_MEMORY_PREFIX}" CACHE STRING "Prefix to use when creating shared memory files")
|
||||
set(EXTERNALS_BIN "${EXTERNALS_ROOT}/bin")
|
||||
set(EXTERNALS_INCLUDE "${EXTERNALS_ROOT}/include")
|
||||
set(EXTERNALS_LIB "${EXTERNALS_ROOT}/lib/$<CONFIG>")
|
||||
set(BUILD_DOCS OFF CACHE BOOL "Build documentation")
|
||||
set(BUILD_SDK OFF CACHE BOOL "Build the sdk")
|
||||
set(EXPORT_MD_CONSUMER OFF CACHE BOOL "Export (extern) C functions for MD consumer interop")
|
||||
@@ -33,25 +33,18 @@ else()
|
||||
set(BUILD_ADMIN_WEB_APP ON CACHE BOOL "Build the Admin WebApp")
|
||||
endif()
|
||||
|
||||
include_directories(BEFORE SYSTEM ${SPARK_INCLUDE} ${EXTERNALS_ROOT}/include/zlib)
|
||||
link_directories(${SPARK_LIB})
|
||||
include_directories(BEFORE SYSTEM ${EXTERNALS_INCLUDE} ${EXTERNALS_ROOT}/include/zlib)
|
||||
link_directories(${EXTERNALS_LIB})
|
||||
|
||||
add_compile_definitions(SHARED_MEMORY_PREFIX="${SHARED_MEMORY_PREFIX}")
|
||||
add_compile_definitions(APP_DATA_DIR="${APP_DATA_DIR}")
|
||||
if(DEFINED APP_DATA_DIR_OVERRIDE)
|
||||
add_compile_definitions(APP_DATA_DIR_OVERRIDE="${APP_DATA_DIR_OVERRIDE}")
|
||||
if(DEFINED APP_DATA_DIR)
|
||||
add_compile_definitions(APP_DATA_DIR="${APP_DATA_DIR}")
|
||||
endif()
|
||||
add_compile_definitions(EXPORT_MD_CONSUMER="${EXPORT_MD_CONSUMER}")
|
||||
if(WIN32)
|
||||
# subdirs
|
||||
add_subdirectory(src/lib)
|
||||
add_subdirectory(src/lib_spark)
|
||||
else()
|
||||
# make sparkd look for libspark.so in its directory
|
||||
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
|
||||
set(CMAKE_INSTALL_RPATH ".")
|
||||
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/install")
|
||||
set(SPARK_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/$<CONFIG>")
|
||||
|
||||
if(BUILD_SPARKD)
|
||||
# Note: All macros that begin w/ 'CCAPI' are ccapi's macros (defined and/or
|
||||
# read by their code). We override some below.
|
||||
@@ -111,10 +104,14 @@ else()
|
||||
|
||||
# subdirs
|
||||
if (BUILD_SPARKD)
|
||||
add_subdirectory(src/server/sparkd)
|
||||
add_subdirectory(src/lib_system)
|
||||
add_subdirectory(src/lib_domain)
|
||||
add_subdirectory(src/lib_python_md)
|
||||
add_subdirectory(src/lib_logging)
|
||||
add_subdirectory(src/app_sparkd)
|
||||
add_subdirectory(src/data_files)
|
||||
endif()
|
||||
add_subdirectory(src/lib)
|
||||
add_subdirectory(src/lib_spark)
|
||||
if (BUILD_ADMIN_WEB_APP)
|
||||
add_subdirectory(src/Spark.Admin.WebApp)
|
||||
endif()
|
||||
@@ -124,32 +121,4 @@ else()
|
||||
if(BUILD_SDK)
|
||||
add_subdirectory(src/sdk)
|
||||
endif()
|
||||
|
||||
if(BUILD_SPARKD)
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_BINARY_DIR}/server
|
||||
COMMAND mkdir -p ${CMAKE_BINARY_DIR}/server
|
||||
COMMAND ln ARGS -sf ${CMAKE_BINARY_DIR}/src/server/sparkd/sparkd ${CMAKE_BINARY_DIR}/server
|
||||
COMMAND ln ARGS -sf ${CMAKE_BINARY_DIR}/data_files ${CMAKE_BINARY_DIR}/server
|
||||
COMMAND ln ARGS -sf ${CMAKE_BINARY_DIR}/src/lib/libspark.so ${CMAKE_BINARY_DIR}/server
|
||||
COMMAND
|
||||
ln ARGS -sf
|
||||
${EXTERNALS_ROOT}/lib/Release/libOnixS.IceImpactMulticastPriceFeedHandlerCpp.so.3.16.0.0
|
||||
${CMAKE_BINARY_DIR}/server
|
||||
COMMAND ln ARGS -sf ${EXTERNALS_ROOT}/lib/Release/libACE-5.7.5.so ${CMAKE_BINARY_DIR}/server
|
||||
COMMAND mkdir ARGS -p ${CMAKE_BINARY_DIR}/server/plugins
|
||||
COMMENT "Creating server runtime layout"
|
||||
DEPENDS sparkd data_files_dir)
|
||||
|
||||
add_custom_target(server_layout ALL DEPENDS ${CMAKE_BINARY_DIR}/server)
|
||||
|
||||
install(
|
||||
DIRECTORY "${CMAKE_BINARY_DIR}/server/plugins"
|
||||
DESTINATION "${SPARK_INSTALL_PREFIX}/bin")
|
||||
install(
|
||||
FILES
|
||||
"${SPARK_LIB}/libACE-5.7.5.so"
|
||||
"${SPARK_LIB}/libOnixS.IceImpactMulticastPriceFeedHandlerCpp.so.3.16.0.0"
|
||||
DESTINATION "${SPARK_INSTALL_PREFIX}/bin")
|
||||
endif()
|
||||
endif()
|
||||
+22
-41
@@ -20,8 +20,6 @@
|
||||
"SPARK_CMAKE_CXX_FLAGS": "/MP /WX /wd4250 /wd4251 /wd4244 /wd4267 /wd4355 /wd4275 /wd4345 /bigobj /EHsc /DCURL_STATICLIB /D_WINSOCK_DEPRECATED_NO_WARNINGS /D__TBB_NO_IMPLICIT_LINKAGE /DBOOST_ALL_NO_LIB /std:c++20 /D_SCL_SECURE_NO_WARNINGS /D_CRT_SECURE_NO_WARNINGS /D_WIN32_WINNT=0x0600"
|
||||
},
|
||||
"cacheVariables": {
|
||||
"APP_DATA_DIR": "${dollar}{APPDATA}/bts",
|
||||
"APP_DATA_DIR_OVERRIDE": "${dollar}{SPARK_DATA_DIR}",
|
||||
"CMAKE_CXX_FLAGS": "$env{SPARK_CMAKE_CXX_FLAGS}",
|
||||
"CMAKE_CXX_FLAGS_DEBUG": "$env{SPARK_CMAKE_CXX_FLAGS} /MTd",
|
||||
"CMAKE_CXX_FLAGS_RELEASE": "$env{SPARK_CMAKE_CXX_FLAGS} /MT",
|
||||
@@ -35,8 +33,7 @@
|
||||
"EXPORT_MD_CONSUMER": {
|
||||
"type": "BOOL",
|
||||
"value": "ON"
|
||||
},
|
||||
"SHARED_MEMORY_PREFIX": "spark"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -52,15 +49,9 @@
|
||||
"binaryDir": "${sourceDir}/build/${presetName}",
|
||||
"cacheVariables": {
|
||||
"platform": "",
|
||||
"APP_DATA_DIR": "${dollar}{HOME}/sparkdata",
|
||||
"APP_DATA_DIR_OVERRIDE": "${dollar}{SPARKD_DATA_DIR}",
|
||||
"CMAKE_BUILD_WITH_INSTALL_RPATH": {
|
||||
"type": "BOOL",
|
||||
"value": "ON"
|
||||
},
|
||||
"CMAKE_CXX_STANDARD": "20",
|
||||
"CMAKE_INSTALL_RPATH": ".",
|
||||
"CMAKE_INSTALL_PREFIX": "${sourceDir}/install/${presetName}/sparkd",
|
||||
"CMAKE_INSTALL_PREFIX": "${sourceDir}/install/${presetName}",
|
||||
"CMAKE_PREFIX_PATH": "${sourceDir}/cmake/;${sourceDir}/.venv/lib/python3.10/site-packages/pybind11/share/cmake/pybind11",
|
||||
"CMAKE_EXE_LINKER_FLAGS": "-Wno-undef",
|
||||
"EXTERNALS_ROOT": "${sourceDir}/externals/linux",
|
||||
"BUILD_SDK": {
|
||||
@@ -70,8 +61,7 @@
|
||||
"BUILD_ADMIN_WEB_APP": {
|
||||
"type": "BOOL",
|
||||
"value": "ON"
|
||||
},
|
||||
"SHARED_MEMORY_PREFIX": "sparkd"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -152,11 +142,7 @@
|
||||
{
|
||||
"name": "spark-api-server-windows",
|
||||
"inherits": "spark",
|
||||
"displayName": "Spark Api Server (Windows)",
|
||||
"cacheVariables": {
|
||||
"APP_DATA_DIR_OVERRIDE": "${dollar}{SPARK_API_SERVER_DATA_DIR}",
|
||||
"SHARED_MEMORY_PREFIX": "spark_api_server"
|
||||
}
|
||||
"displayName": "Spark Api Server (Windows)"
|
||||
},
|
||||
|
||||
{
|
||||
@@ -165,7 +151,6 @@
|
||||
"displayName": "Spark Api Server (Linux)",
|
||||
"generator": "Ninja Multi-Config",
|
||||
"cacheVariables": {
|
||||
"APP_DATA_DIR_OVERRIDE": "${dollar}{SPARK_API_SERVER_DATA_DIR}",
|
||||
"BUILD_ADMIN_WEB_APP": {
|
||||
"type": "BOOL",
|
||||
"value": "OFF"
|
||||
@@ -178,9 +163,12 @@
|
||||
"CMAKE_CXX_COMPILER": "clang++",
|
||||
"CMAKE_CXX_FLAGS_DEBUG": "-g -fPIC -Wall -pedantic -Wextra -Werror -Wno-missing-braces -Wno-ignored-qualifiers --std=c++20 -fdiagnostics-color -DDEBUG",
|
||||
"CMAKE_CXX_FLAGS_RELEASE": "-fPIC -Wall -pedantic -Wextra -Werror -Wno-missing-braces -Wno-ignored-qualifiers --std=c++20 -fdiagnostics-color -fno-omit-frame-pointer -DNDEBUG -O3",
|
||||
"CMAKE_INSTALL_PREFIX": "${sourceDir}/install/${presetName}",
|
||||
"CMAKE_EXPORT_COMPILE_COMMANDS": {
|
||||
"type": "BOOL",
|
||||
"value": "ON"
|
||||
},
|
||||
"CONFIG_DEFAULTS_PATH": "config/profiles/default/*.conf",
|
||||
"DOTNET_BINARY_DIR": "${sourceDir}/build/$<CONFIG>/bin/net7.0",
|
||||
"DOTNET_BINARY_DIR": "${sourceDir}/build/Spark.Api.Server/$<CONFIG>/bin/net7.0",
|
||||
"EXPORT_MD_CONSUMER": {
|
||||
"type": "BOOL",
|
||||
"value": "ON"
|
||||
@@ -218,11 +206,8 @@
|
||||
"description": "Data Stream utils ported over from Edge",
|
||||
"binaryDir": "${sourceDir}/build/${presetName}",
|
||||
"cacheVariables": {
|
||||
"APP_DATA_DIR": "${dollar}{APPDATA}/bts/DataStream",
|
||||
"APP_DATA_DIR_OVERRIDE": "${dollar}{DATA_STREAM_DATA_DIR}",
|
||||
"CONFIG_DEFAULTS_PATH": "config/profiles/default/*.conf;config/profiles/data_stream/*.conf",
|
||||
"DOTNET_BINARY_DIR": "${sourceDir}/build/$<CONFIG>/bin/net7.0;${sourceDir}/build/$<CONFIG>/bin/net7.0-windows;${sourceDir}/build/$<CONFIG>/bin/net8.0",
|
||||
"SHARED_MEMORY_PREFIX": "data_stream"
|
||||
"DOTNET_BINARY_DIR": "${sourceDir}/build/$<CONFIG>/bin/net7.0;${sourceDir}/build/$<CONFIG>/bin/net7.0-windows"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -238,8 +223,6 @@
|
||||
"inherits": "sparkd",
|
||||
"generator": "Ninja Multi-Config",
|
||||
"cacheVariables": {
|
||||
"APP_DATA_DIR": "${dollar}{HOME}/.local/share/DataStream",
|
||||
"APP_DATA_DIR_OVERRIDE": "${dollar}{DATA_STREAM_DATA_DIR}",
|
||||
"BUILD_ADMIN_WEB_APP": {
|
||||
"type": "BOOL",
|
||||
"value": "OFF"
|
||||
@@ -256,14 +239,13 @@
|
||||
"CMAKE_CXX_COMPILER": "clang++",
|
||||
"CMAKE_CXX_FLAGS_DEBUG": "-g -fPIC -Wall -pedantic -Wextra -Werror -Wno-missing-braces -Wno-ignored-qualifiers --std=c++20 -fdiagnostics-color -DDEBUG",
|
||||
"CMAKE_CXX_FLAGS_RELEASE": "-fPIC -Wall -pedantic -Wextra -Werror -Wno-missing-braces -Wno-ignored-qualifiers --std=c++20 -fdiagnostics-color -fno-omit-frame-pointer -DNDEBUG -O3",
|
||||
"CMAKE_INSTALL_PREFIX": "${sourceDir}/install/${presetName}",
|
||||
"CONFIG_DEFAULTS_PATH": "config/profiles/default/*.conf;config/profiles/data_stream/*.conf",
|
||||
"CONFIG_PROFILES": "default;data_stream",
|
||||
"DOTNET_BINARY_DIR": "${sourceDir}/build/$<CONFIG>/bin/net7.0;${sourceDir}/build/$<CONFIG>/bin/net8.0",
|
||||
"EXPORT_MD_CONSUMER": {
|
||||
"type": "BOOL",
|
||||
"value": "ON"
|
||||
},
|
||||
"SHARED_MEMORY_PREFIX": "data_stream"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
@@ -302,16 +284,7 @@
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Linux"
|
||||
},
|
||||
"hidden": true,
|
||||
"targets": [
|
||||
"data_files_dir",
|
||||
"admin_web_app_bundle",
|
||||
"install",
|
||||
"libspark",
|
||||
"rapidjson_project",
|
||||
"server_layout",
|
||||
"sparkd"
|
||||
]
|
||||
"hidden": true
|
||||
},
|
||||
|
||||
{
|
||||
@@ -321,6 +294,14 @@
|
||||
"inherits": "sparkd"
|
||||
},
|
||||
|
||||
{
|
||||
"name": "sparkd-debug-clang-j6",
|
||||
"configurePreset": "sparkd-debug-clang",
|
||||
"displayName": "Sparkd (Debug | Clang | jobs=6)",
|
||||
"inherits": "sparkd",
|
||||
"jobs": 6
|
||||
},
|
||||
|
||||
{
|
||||
"name": "sparkd-debug-gcc",
|
||||
"configurePreset": "sparkd-debug-gcc",
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
macro(export_to_parent)
|
||||
foreach(var IN ITEMS ${ARGN})
|
||||
set(${var} ${${var}} PARENT_SCOPE)
|
||||
endforeach()
|
||||
endmacro()
|
||||
@@ -0,0 +1,66 @@
|
||||
include_guard(DIRECTORY)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/ExportToParent.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/TernaryOperator.cmake)
|
||||
|
||||
function(init_library)
|
||||
set(_options SHARED STATIC)
|
||||
set(_one_value_args SOURCE_DIR)
|
||||
set(_multi_value_args)
|
||||
cmake_parse_arguments(_ARGS "${_options}" "${_one_value_args}" "${_multi_value_args}" ${ARGN})
|
||||
|
||||
if (_ARGS_SHARED AND _ARGS_STATIC)
|
||||
message(FATAL_ERROR "Invalid args passed to init_library: cannot specify STATIC and SHARED")
|
||||
endif()
|
||||
|
||||
set_ternary(_source_dir _ARGS_SOURCE_DIR _ARGS_SOURCE_DIR ${PROJECT_NAME})
|
||||
# Glob cpp sources
|
||||
file(
|
||||
GLOB_RECURSE ${PROJECT_NAME}_SOURCES
|
||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${_source_dir}/*.cpp
|
||||
)
|
||||
# Note: cpp files inside 'tests' dir(s) are considered tests.
|
||||
# Remove tests from main sources, and add them to test sources
|
||||
foreach(item ${${PROJECT_NAME}_SOURCES})
|
||||
if(${item} MATCHES "tests/*.cpp")
|
||||
list(REMOVE_ITEM ${PROJECT_NAME}_SOURCES ${item})
|
||||
list(APPEND ${PROJECT_NAME}_TEST_SOURCES ${item})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
export_to_parent(
|
||||
${PROJECT_NAME}_SOURCES
|
||||
${PROJECT_NAME}_TEST_SOURCES
|
||||
)
|
||||
|
||||
# Add main library
|
||||
if (_ARGS_STATIC)
|
||||
add_library(${PROJECT_NAME} STATIC ${${PROJECT_NAME}_SOURCES})
|
||||
elseif(_ARGS_SHARED)
|
||||
add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_SOURCES})
|
||||
else()
|
||||
add_library(${PROJECT_NAME} ${${PROJECT_NAME}_SOURCES})
|
||||
endif()
|
||||
|
||||
target_include_directories(
|
||||
${PROJECT_NAME}
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
)
|
||||
target_link_directories(
|
||||
${PROJECT_NAME}
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_LIBDIR}>
|
||||
)
|
||||
|
||||
# Add tests executable (if there are any)
|
||||
if (${PROJECT_NAME}_TEST_SOURCES)
|
||||
add_executable(${PROJECT_NAME}-tests ${${PROJECT_NAME}_TEST_SOURCES})
|
||||
target_link_libraries(${PROJECT_NAME}-tests PRIVATE ${PROJECT_NAME})
|
||||
# Catch2
|
||||
find_package(Catch2 CONFIG REQUIRED COMPONENTS Catch2WithMain)
|
||||
target_link_libraries(${PROJECT_NAME}-tests PRIVATE Catch2::Catch2WithMain)
|
||||
endif()
|
||||
endfunction()
|
||||
@@ -0,0 +1,55 @@
|
||||
function(init_shared_library)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/ExportToParent.cmake)
|
||||
set(source_dir)
|
||||
if (${ARGC} EQUAL 0)
|
||||
set(source_dir ${PROJECT_NAME})
|
||||
elseif(${ARGC} GREATER 1)
|
||||
message(FATAL_ERROR "init_shared_library received invalid arguments. Usage: init_shared_library(<OPTIONAL:source_dir>)")
|
||||
else()
|
||||
set(source_dir ${ARGV})
|
||||
endif()
|
||||
|
||||
# Glob cpp sources
|
||||
file(
|
||||
GLOB_RECURSE ${PROJECT_NAME}_SOURCES
|
||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${source_dir}/*.cpp
|
||||
)
|
||||
# Note: cpp files inside 'tests' dir(s) are considered tests.
|
||||
# Remove tests from main sources, and add them to test sources
|
||||
foreach(item ${${PROJECT_NAME}_SOURCES})
|
||||
if(${item} MATCHES "tests/*.cpp")
|
||||
list(REMOVE_ITEM ${PROJECT_NAME}_SOURCES ${item})
|
||||
list(APPEND ${PROJECT_NAME}_TEST_SOURCES ${item})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
export_to_parent(
|
||||
${PROJECT_NAME}_SOURCES
|
||||
${PROJECT_NAME}_TEST_SOURCES
|
||||
)
|
||||
|
||||
# Add main library
|
||||
add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_SOURCES})
|
||||
target_include_directories(
|
||||
${PROJECT_NAME}
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
)
|
||||
target_link_directories(
|
||||
${PROJECT_NAME}
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_LIBDIR}>
|
||||
)
|
||||
|
||||
# Add tests executable (if there are any)
|
||||
if (${PROJECT_NAME}_TEST_SOURCES)
|
||||
add_executable(${PROJECT_NAME}-tests ${${PROJECT_NAME}_TEST_SOURCES})
|
||||
target_link_libraries(${PROJECT_NAME}-tests PRIVATE ${PROJECT_NAME})
|
||||
# Catch2
|
||||
find_package(Catch2 CONFIG REQUIRED COMPONENTS Catch2WithMain)
|
||||
target_link_libraries(${PROJECT_NAME}-tests PRIVATE Catch2::Catch2WithMain)
|
||||
endif()
|
||||
endfunction(init_shared_library)
|
||||
@@ -0,0 +1,30 @@
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/PackBasic.cmake)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
function(install_basic)
|
||||
file(
|
||||
GLOB_RECURSE ${PROJECT_NAME}_HEADERS
|
||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
*.h)
|
||||
|
||||
target_sources(${PROJECT_NAME}
|
||||
PUBLIC
|
||||
FILE_SET HEADERS FILES ${${PROJECT_NAME}_HEADERS})
|
||||
|
||||
install(
|
||||
TARGETS ${PROJECT_NAME}
|
||||
EXPORT ${PROJECT_NAME}Targets
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
)
|
||||
|
||||
install(
|
||||
EXPORT ${PROJECT_NAME}Targets
|
||||
FILE ${PROJECT_NAME}Targets.cmake
|
||||
NAMESPACE ${PROJECT_NAME}::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
|
||||
|
||||
pack_basic()
|
||||
endfunction()
|
||||
@@ -0,0 +1,36 @@
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
function(pack_basic)
|
||||
find_package(Git QUIET)
|
||||
|
||||
if(GIT_FOUND)
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} describe --tags --always --dirty
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE PROJECT_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT GIT_FOUND OR PROJECT_VERSION STREQUAL "")
|
||||
set(PROJECT_VERSION "0.0.0")
|
||||
endif()
|
||||
|
||||
write_basic_package_version_file(
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY AnyNewerVersion
|
||||
)
|
||||
|
||||
configure_package_config_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
||||
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
|
||||
)
|
||||
|
||||
install(
|
||||
FILES
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
|
||||
endfunction()
|
||||
@@ -1,145 +0,0 @@
|
||||
set(Protobuf_PROTOC_EXECUTABLE "${SPARK_BIN}/protoc")
|
||||
set(PROTOBUF_INCLUDE_DIRS "${SPARK_INCLUDE}")
|
||||
set(PROTOBUF_STATIC_LIB "libprotobuf")
|
||||
|
||||
function(Protobuf_Generate_Cpp SRCS HDRS)
|
||||
set(${SRCS})
|
||||
set(${HDRS})
|
||||
|
||||
foreach(FIL ${ARGN})
|
||||
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
|
||||
get_filename_component(FIL_WE ${FIL} NAME_WE)
|
||||
get_filename_component(FIL_DIR ${FIL} DIRECTORY)
|
||||
if(FIL_DIR)
|
||||
set(FIL_WE "${FIL_DIR}/${FIL_WE}")
|
||||
endif()
|
||||
|
||||
list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc")
|
||||
list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h")
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h"
|
||||
COMMAND
|
||||
${Protobuf_PROTOC_EXECUTABLE} ARGS --cpp_out=${CMAKE_BINARY_DIR}/src -I
|
||||
${PROTOBUF_INCLUDE_DIRS} -I ${CMAKE_SOURCE_DIR}/src ${ABS_FIL}
|
||||
DEPENDS ${ABS_FIL}
|
||||
COMMENT "Running C++ protocol buffer compiler on ${FIL}"
|
||||
VERBATIM)
|
||||
endforeach()
|
||||
|
||||
set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
|
||||
|
||||
# remove some warnings from protobuf generated files
|
||||
if(WIN32)
|
||||
set_source_files_properties(${${SRCS}} PROPERTIES COMPILE_FLAGS
|
||||
"/wd4309 /wd4838")
|
||||
else()
|
||||
set_source_files_properties(
|
||||
${${SRCS}}
|
||||
PROPERTIES
|
||||
COMPILE_FLAGS
|
||||
"-Wno-unused-parameter -Wno-effc++ -Wno-pedantic -Wno-sign-compare -Wno-uninitialized"
|
||||
)
|
||||
endif()
|
||||
|
||||
set(${SRCS}
|
||||
${${SRCS}}
|
||||
PARENT_SCOPE)
|
||||
set(${HDRS}
|
||||
${${HDRS}}
|
||||
PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(Service_Compiler_Generate_Cpp SRCS HDRS)
|
||||
set(${SRCS})
|
||||
set(${HDRS})
|
||||
|
||||
foreach(FIL ${ARGN})
|
||||
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
|
||||
get_filename_component(FIL_WE ${FIL} NAME_WE)
|
||||
get_filename_component(FIL_DIR ${FIL} DIRECTORY)
|
||||
if(FIL_DIR)
|
||||
set(FIL_WE "${FIL_DIR}/${FIL_WE}")
|
||||
endif()
|
||||
|
||||
list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc")
|
||||
list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h")
|
||||
|
||||
list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.client.pb.cc")
|
||||
list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.client.pb.h")
|
||||
|
||||
list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.server.pb.cc")
|
||||
list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.server.pb.h")
|
||||
|
||||
set(TEMPLATES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/api/service_compiler/templates/cpp/client.pb.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/api/service_compiler/templates/cpp/client.pb.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/api/service_compiler/templates/cpp/server.pb.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/api/service_compiler/templates/cpp/server.pb.h
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
add_custom_command(
|
||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.client.pb.cc"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.client.pb.h"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.server.pb.cc"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.server.pb.h"
|
||||
COMMAND SET PYTHONPATH=${SPARK_PYTHON}
|
||||
COMMAND ${CMAKE_SOURCE_DIR}/.venv/Scripts/activate.bat
|
||||
COMMAND
|
||||
${Protobuf_PROTOC_EXECUTABLE} ARGS --cpp_out=${CMAKE_BINARY_DIR}/src
|
||||
--plugin=protoc-gen-service=${CMAKE_SOURCE_DIR}/src/lib/api/service_compiler/plugin.cmd
|
||||
--service_out=lang=cpp:${CMAKE_BINARY_DIR}/src -I
|
||||
${PROTOBUF_INCLUDE_DIRS} -I ${CMAKE_SOURCE_DIR}/src ${ABS_FIL}
|
||||
DEPENDS ${ABS_FIL} ${TEMPLATES}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/api/service_compiler/plugin.py
|
||||
COMMENT "Running C++ service compiler on ${FIL}"
|
||||
VERBATIM)
|
||||
else()
|
||||
add_custom_command(
|
||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.client.pb.cc"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.client.pb.h"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.server.pb.cc"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.server.pb.h"
|
||||
COMMAND ${CMAKE_SOURCE_DIR}/tools/venv_exec.sh
|
||||
ARGS
|
||||
${Protobuf_PROTOC_EXECUTABLE}
|
||||
--cpp_out=${CMAKE_BINARY_DIR}/src
|
||||
--plugin=protoc-gen-service=${CMAKE_SOURCE_DIR}/src/lib/api/service_compiler/plugin.py
|
||||
--service_out=lang=cpp,make_file_name=${ABS_FIL}:${CMAKE_BINARY_DIR}/src
|
||||
-I ${PROTOBUF_INCLUDE_DIRS} -I ${CMAKE_SOURCE_DIR}/src ${ABS_FIL}
|
||||
DEPENDS ${ABS_FIL} ${TEMPLATES}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/api/service_compiler/plugin.py
|
||||
COMMENT "Running C++ service compiler on ${FIL}"
|
||||
VERBATIM)
|
||||
endif()
|
||||
|
||||
endforeach()
|
||||
|
||||
# remove some warnings from protobuf generated files
|
||||
if(WIN32)
|
||||
set_source_files_properties(${${SRCS}} PROPERTIES COMPILE_FLAGS
|
||||
"/wd4309 /wd4838")
|
||||
else()
|
||||
set_source_files_properties(
|
||||
${${SRCS}}
|
||||
PROPERTIES
|
||||
COMPILE_FLAGS
|
||||
"-Wno-unused-parameter -Wno-effc++ -Wno-pedantic -Wno-sign-compare -Wno-uninitialized"
|
||||
)
|
||||
endif()
|
||||
|
||||
set(${SRCS}
|
||||
${${SRCS}}
|
||||
PARENT_SCOPE)
|
||||
set(${HDRS}
|
||||
${${HDRS}}
|
||||
PARENT_SCOPE)
|
||||
|
||||
endfunction()
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
include_guard(GLOBAL)
|
||||
|
||||
function(protobuf_generate_cpp)
|
||||
set(_options)
|
||||
set(_one_value_args CXX_SOURCES CXX_HEADERS CXX_OUT_DIR PROTOC)
|
||||
set(_multi_value_args PROTO_INCLUDE_DIRS PROTO_SOURCES)
|
||||
cmake_parse_arguments(_ARGS "${_options}" "${_one_value_args}" "${_multi_value_args}" ${ARGN})
|
||||
|
||||
if (NOT DEFINED _ARGS_PROTOC)
|
||||
set(_ARGS_PROTOC "${EXTERNALS_BIN}/protoc")
|
||||
endif()
|
||||
set(${_ARGS_CXX_SOURCES})
|
||||
set(${_ARGS_CXX_HEADERS})
|
||||
|
||||
set(_proto_include_cli_args)
|
||||
foreach(_dir ${_ARGS_PROTO_INCLUDE_DIRS})
|
||||
list(APPEND _proto_include_cli_args -I ${_dir})
|
||||
endforeach()
|
||||
|
||||
foreach(_fil ${_ARGS_PROTO_SOURCES})
|
||||
get_filename_component(_abs_fil ${_fil} ABSOLUTE)
|
||||
get_filename_component(_fil_we ${_fil} NAME_WE)
|
||||
get_filename_component(_fil_dir ${_fil} DIRECTORY)
|
||||
if(_fil_dir)
|
||||
set(_fil_we "${_fil_dir}/${_fil_we}")
|
||||
endif()
|
||||
list(APPEND ${_ARGS_CXX_SOURCES} "${_ARGS_CXX_OUT_DIR}/${_fil_we}.pb.cc")
|
||||
list(APPEND ${_ARGS_CXX_HEADERS} "${_ARGS_CXX_OUT_DIR}/${_fil_we}.pb.h")
|
||||
add_custom_command(
|
||||
OUTPUT
|
||||
"${_ARGS_CXX_OUT_DIR}/${_fil_we}.pb.cc"
|
||||
"${_ARGS_CXX_OUT_DIR}/${_fil_we}.pb.h"
|
||||
COMMAND
|
||||
${_ARGS_PROTOC}
|
||||
ARGS
|
||||
--cpp_out=${_ARGS_CXX_OUT_DIR} ${_proto_include_cli_args} ${_abs_fil}
|
||||
DEPENDS ${_abs_fil}
|
||||
COMMENT "Running C++ protocol buffer compiler on ${_fil}"
|
||||
VERBATIM
|
||||
)
|
||||
endforeach()
|
||||
|
||||
set_source_files_properties(
|
||||
${${_ARGS_CXX_SOURCES}}
|
||||
${${_ARGS_CXX_HEADERS}}
|
||||
PROPERTIES
|
||||
GENERATED TRUE
|
||||
)
|
||||
|
||||
# remove some warnings from protobuf generated files
|
||||
if(WIN32)
|
||||
set_source_files_properties(
|
||||
${${_ARGS_CXX_SOURCES}}
|
||||
PROPERTIES
|
||||
COMPILE_FLAGS "/wd4309 /wd4838"
|
||||
)
|
||||
else()
|
||||
set_source_files_properties(
|
||||
${${_ARGS_CXX_SOURCES}}
|
||||
PROPERTIES
|
||||
COMPILE_FLAGS "-Wno-unused-parameter -Wno-effc++ -Wno-pedantic -Wno-sign-compare -Wno-uninitialized"
|
||||
)
|
||||
endif()
|
||||
|
||||
set(${_ARGS_CXX_SOURCES} ${${_ARGS_CXX_SOURCES}} PARENT_SCOPE)
|
||||
set(${_ARGS_CXX_HEADERS} ${${_ARGS_CXX_HEADERS}} PARENT_SCOPE)
|
||||
endfunction()
|
||||
@@ -0,0 +1,49 @@
|
||||
include_guard(DIRECTORY)
|
||||
|
||||
function(protobuf_generate_fs)
|
||||
set(_options)
|
||||
set(_one_value_args TARGET_NAME OUT_DIR PROTOC)
|
||||
set(_multi_value_args PROTO_INCLUDE_DIRS PROTO_SOURCES)
|
||||
cmake_parse_arguments(_ARGS "${_options}" "${_one_value_args}" "${_multi_value_args}" ${ARGN})
|
||||
|
||||
if (NOT DEFINED _ARGS_TARGET_NAME)
|
||||
set(_ARGS_TARGET_NAME "${PROJECT_NAME}_generate_fs_protos")
|
||||
endif()
|
||||
if (NOT DEFINED _ARGS_PROTOC)
|
||||
set(_ARGS_PROTOC "${EXTERNALS_BIN}/protoc")
|
||||
endif()
|
||||
|
||||
set(_proto_include_cli_args)
|
||||
foreach(_dir ${_ARGS_PROTO_INCLUDE_DIRS})
|
||||
list(APPEND _proto_include_cli_args -I ${_dir})
|
||||
endforeach()
|
||||
|
||||
set(_outputs)
|
||||
foreach(_proto_source ${_ARGS_PROTO_SOURCES})
|
||||
# get_filename_component(_abs_proto_source ${_proto_source} ABSOLUTE)
|
||||
get_filename_component(_proto_source_we ${_proto_source} NAME_WE)
|
||||
# get_filename_component(_proto_source_dir ${_proto_source} DIRECTORY)
|
||||
list(APPEND _outputs ${_ARGS_OUT_DIR}/${_proto_source_we}.fable.fs)
|
||||
endforeach()
|
||||
|
||||
set(_venv_exec ${CMAKE_SOURCE_DIR}/tools/venv_exec.sh)
|
||||
set(_plugin_py ${CMAKE_SOURCE_DIR}/src/lib_spark/spark/api/service_compiler/plugin.py)
|
||||
set(_template_fs ${CMAKE_SOURCE_DIR}/src/lib_spark/spark/api/service_compiler/templates/fs/fable.fs)
|
||||
add_custom_command(
|
||||
OUTPUT ${_outputs}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
COMMAND ${_venv_exec}
|
||||
${_ARGS_PROTOC}
|
||||
--plugin=protoc-gen-service=${_plugin_py}
|
||||
--service_out=lang=fs,strip_out_path=1:${_ARGS_OUT_DIR}
|
||||
${_proto_include_cli_args}
|
||||
${_ARGS_PROTO_SOURCES}
|
||||
DEPENDS
|
||||
${_venv_exec}
|
||||
${_plugin_py}
|
||||
${_template_fs}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/package-lock.json
|
||||
${_ARGS_PROTO_SOURCES}
|
||||
)
|
||||
add_custom_target(${_ARGS_TARGET_NAME} ALL DEPENDS "${_outputs}")
|
||||
endfunction()
|
||||
@@ -0,0 +1,33 @@
|
||||
include_guard(DIRECTORY)
|
||||
|
||||
function(protobuf_generate_js)
|
||||
set(_options)
|
||||
set(_one_value_args TARGET_NAME OUTPUT)
|
||||
set(_multi_value_args PROTO_INCLUDE_DIRS PROTO_SOURCES)
|
||||
cmake_parse_arguments(_ARGS "${_options}" "${_one_value_args}" "${_multi_value_args}" ${ARGN})
|
||||
|
||||
if (NOT DEFINED _ARGS_TARGET_NAME)
|
||||
set(_ARGS_TARGET_NAME "${PROJECT_NAME}_generate_js_protos")
|
||||
endif()
|
||||
|
||||
set(_proto_include_cli_args)
|
||||
foreach(_dir ${_ARGS_PROTO_INCLUDE_DIRS})
|
||||
list(APPEND _proto_include_cli_args -p ${_dir})
|
||||
endforeach()
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${_ARGS_OUTPUT}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
COMMAND npx
|
||||
--no-install pbjs
|
||||
-t json-module
|
||||
-w commonjs
|
||||
-o ${_ARGS_OUTPUT}
|
||||
${_proto_include_cli_args}
|
||||
${_ARGS_PROTO_SOURCES}
|
||||
DEPENDS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/package-lock.json
|
||||
${_ARGS_PROTO_SOURCES}
|
||||
)
|
||||
add_custom_target(${_ARGS_TARGET_NAME} ALL DEPENDS ${_ARGS_OUTPUT})
|
||||
endfunction()
|
||||
@@ -0,0 +1,51 @@
|
||||
include_guard(DIRECTORY)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/TernaryOperator.cmake)
|
||||
|
||||
function(sym_link_dir)
|
||||
set(_options)
|
||||
set(_one_value_args TARGET_NAME SOURCE DEST COMMENT)
|
||||
set(_multi_value_args)
|
||||
cmake_parse_arguments(_ARGS "${_options}" "${_one_value_args}" "${_multi_value_args}" ${ARGN})
|
||||
add_custom_command(
|
||||
OUTPUT ${_ARGS_DEST}
|
||||
COMMAND ln ARGS -sf ${_ARGS_SOURCE} ${_ARGS_DEST}
|
||||
)
|
||||
set_ternary(_comment _ARGS_COMMENT "${_ARGS_COMMENT}" "linking dir ${_ARGS_SOURCE} -> ${_ARGS_DEST}")
|
||||
add_custom_target(
|
||||
${_ARGS_TARGET_NAME} ALL
|
||||
DEPENDS ${_ARGS_DEST}
|
||||
COMMENT "${_comment}"
|
||||
)
|
||||
endfunction()
|
||||
|
||||
function(sym_link_file)
|
||||
set(_options)
|
||||
set(_one_value_args TARGET_NAME SOURCE DEST INSTALL_DEST)
|
||||
set(_multi_value_args)
|
||||
cmake_parse_arguments(_ARGS "${_options}" "${_one_value_args}" "${_multi_value_args}" ${ARGN})
|
||||
add_custom_command(
|
||||
OUTPUT ${_ARGS_DEST}
|
||||
COMMAND ln ARGS -s ${_ARGS_SOURCE} ${_ARGS_DEST}
|
||||
)
|
||||
add_custom_target(
|
||||
${_ARGS_TARGET_NAME} ALL
|
||||
DEPENDS ${_ARGS_DEST}
|
||||
)
|
||||
if (DEFINED _ARGS_INSTALL_DEST)
|
||||
install(
|
||||
FILES
|
||||
${_ARGS_SOURCE}
|
||||
DESTINATION ${_ARGS_INSTALL_DEST}
|
||||
)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(sym_link_local_lib LIB_NAME)
|
||||
set(_lib_file_name "${CMAKE_SHARED_LIBRARY_PREFIX}${LIB_NAME}.so")
|
||||
file(
|
||||
CREATE_LINK
|
||||
"${CMAKE_BINARY_DIR}/src/lib_${LIB_NAME}/${_lib_file_name}"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${_lib_file_name}"
|
||||
SYMBOLIC
|
||||
)
|
||||
endfunction()
|
||||
@@ -0,0 +1,9 @@
|
||||
include_guard(GLOBAL)
|
||||
|
||||
macro(set_ternary RESULT CONDITION TRUE_VALUE FALSE_VALUE)
|
||||
if(${CONDITION})
|
||||
set(${RESULT} ${TRUE_VALUE})
|
||||
else()
|
||||
set(${RESULT} ${FALSE_VALUE})
|
||||
endif()
|
||||
endmacro()
|
||||
@@ -0,0 +1,51 @@
|
||||
services:
|
||||
sparkd:
|
||||
build:
|
||||
dockerfile: Dockerfile
|
||||
context: ./sparkd
|
||||
command: [ "./sparkd", "run" ]
|
||||
ports: [ "8000:8000", "8001:8001", "8002:8002" ]
|
||||
|
||||
pubsub:
|
||||
build:
|
||||
dockerfile: pubsub.Dockerfile
|
||||
context: ./DataStream
|
||||
command: [ "./PubSubServer" ]
|
||||
environment:
|
||||
- DOTNET_ENVIRONMENT=Production
|
||||
ports:
|
||||
- 22019:22019
|
||||
|
||||
md-publisher:
|
||||
build:
|
||||
dockerfile: md-publisher.Dockerfile
|
||||
context: ./DataStream
|
||||
depends_on:
|
||||
- pubsub
|
||||
- sparkd
|
||||
command:
|
||||
[
|
||||
"dockerize",
|
||||
"-wait",
|
||||
"tcp://pubsub:22019",
|
||||
"-wait",
|
||||
"tcp://sparkd:8000",
|
||||
"-timeout",
|
||||
"10s",
|
||||
"./DataStreamPublisher"
|
||||
]
|
||||
environment:
|
||||
- DOTNET_ENVIRONMENT=MarketData
|
||||
|
||||
webapp:
|
||||
ports:
|
||||
- 8080:8080
|
||||
- 8443:8443
|
||||
build:
|
||||
dockerfile: webapp.Dockerfile
|
||||
context: ./DataStream
|
||||
command: [ "./Bts.DataStreamWebApp.Server" ]
|
||||
environment:
|
||||
- ASPNETCORE_HTTP_PORT=8080
|
||||
- ASPNETCORE_HTTPS_PORT=8443
|
||||
- ASPNETCORE_ENVIRONMENT=Staging
|
||||
@@ -0,0 +1,72 @@
|
||||
services:
|
||||
sparkd:
|
||||
build:
|
||||
dockerfile: src/server/sparkd/Dockerfile
|
||||
command: [ "./sparkd", "run" ]
|
||||
ports: [ "8000:8000", "8001:8001", "8002:8002" ]
|
||||
|
||||
pubsub:
|
||||
environment:
|
||||
- DOTNET_ENVIRONMENT=Staging
|
||||
build:
|
||||
dockerfile: src/DataStreamSuite/PubSubServer/Dockerfile
|
||||
ports:
|
||||
- 22019:22019
|
||||
command: [ "./PubSubServer" ]
|
||||
|
||||
md-publisher:
|
||||
build:
|
||||
dockerfile: src/DataStreamSuite/DataStreamPublisher/Dockerfile
|
||||
depends_on:
|
||||
- pubsub
|
||||
- sparkd
|
||||
command:
|
||||
[
|
||||
"dockerize",
|
||||
"-wait",
|
||||
"tcp://pubsub:22019",
|
||||
"-wait",
|
||||
"tcp://sparkd:8000",
|
||||
"-timeout",
|
||||
"10s",
|
||||
"./DataStreamPublisher"
|
||||
]
|
||||
environment:
|
||||
- DOTNET_ENVIRONMENT=MarketData
|
||||
|
||||
webapp:
|
||||
ports:
|
||||
- 8080:8080
|
||||
- 8443:8443
|
||||
build:
|
||||
dockerfile: src/DataStreamSuite/Bts.DataStreamWebApp.Server/Dockerfile
|
||||
command: [ "./Bts.DataStreamWebApp.Server" ]
|
||||
environment:
|
||||
- ASPNETCORE_ENVIRONMENT=Staging
|
||||
|
||||
api-server:
|
||||
profiles:
|
||||
- api-server
|
||||
depends_on:
|
||||
- sparkd
|
||||
ports:
|
||||
- 8008:8008
|
||||
- 9443:9443
|
||||
build:
|
||||
dockerfile: src/client/spark_api_server/Dockerfile
|
||||
command: [ "./spark_api_server", "run" ]
|
||||
environment:
|
||||
- ASPNETCORE_ENVIRONMENT=Staging
|
||||
|
||||
sparkd-ping-test:
|
||||
depends_on:
|
||||
- sparkd
|
||||
profiles:
|
||||
- ping-test
|
||||
build:
|
||||
context: .
|
||||
dockerfile_inline: |
|
||||
FROM bluetradingsystems/linux_dotnet7
|
||||
USER "root"
|
||||
RUN apt-get update && apt-get -y install iputils-ping
|
||||
command: [ "ping", "sparkd" ]
|
||||
@@ -53,7 +53,7 @@ The status callback is called when the market for this security opens, closes, o
|
||||
// Subscribe to security trading status
|
||||
void IAlgoServices::subscribe_status(SecurityKey);
|
||||
// You implement
|
||||
virtual void on_status(SecurityKey, co2::TradingStatus) override;
|
||||
virtual void on_status(SecurityKey, domain::protobufs::TradingStatus) override;
|
||||
```
|
||||
|
||||
# Child Orders
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
FROM ubuntu:22.04
|
||||
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y pkg-config \
|
||||
&& apt-get install -y locales \
|
||||
&& apt-get install -y ca-certificates \
|
||||
&& apt-get install -y libssh2-1-dev \
|
||||
&& apt-get install -y software-properties-common \
|
||||
&& apt-get install -y sudo
|
||||
|
||||
# GCC
|
||||
ARG gcc_major=13
|
||||
RUN add-apt-repository ppa:ubuntu-toolchain-r/test \
|
||||
&& apt-get update \
|
||||
&& apt-get install -y g++-$gcc_major
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y dotnet7
|
||||
|
||||
RUN locale-gen en_US.UTF-8
|
||||
|
||||
ARG docker_user="bts"
|
||||
ARG docker_uid="1000"
|
||||
ARG docker_pass="bts"
|
||||
# ARG entrypoint
|
||||
|
||||
RUN \
|
||||
groupadd -g "$docker_uid" "$docker_user" \
|
||||
&& useradd \
|
||||
-m \
|
||||
-u "$docker_uid" \
|
||||
-g "$docker_uid" \
|
||||
-G sudo \
|
||||
--password "$(openssl passwd -1 "$docker_pass")" \
|
||||
"$docker_user"
|
||||
|
||||
USER bts
|
||||
WORKDIR /home/bts
|
||||
+1
-1
Submodule externals updated: cae5fd20da...ff5f02bbde.
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
using Microsoft.Win32;
|
||||
@@ -16,8 +15,11 @@ namespace BCG
|
||||
[SupportedOSPlatform("windows")]
|
||||
public static double getValue (RegistryKey rk, string name)
|
||||
{
|
||||
var str = rk.GetValue(name)?.ToString();
|
||||
return str is not null && double.TryParse(str, out var dbl) ? dbl : double.NaN;
|
||||
object v = rk.GetValue (name);
|
||||
if (v != null)
|
||||
return double.Parse (v.ToString ());
|
||||
else
|
||||
return double.NaN;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,11 @@
|
||||
namespace Bts.BooleanExpressions;
|
||||
|
||||
using bts;
|
||||
|
||||
class BooleanExpression : IBooleanExpression {
|
||||
readonly Func<IDictionary<string, object?>, bool> evaluate;
|
||||
|
||||
public BooleanExpression(Func<IDictionary<string, object?>, bool> evaluate) =>
|
||||
this.evaluate = evaluate;
|
||||
|
||||
public bool Evaluate(IDictionary<string, object?> env) {
|
||||
try {
|
||||
return evaluate(env);
|
||||
} catch (Exception ex) {
|
||||
Log.assert(false, $"BooleanExpression.Evaluate failed: {ex}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public bool Evaluate(IDictionary<string, object?> env) =>
|
||||
evaluate(env);
|
||||
}
|
||||
@@ -47,11 +47,6 @@ IsOfType '/'
|
||||
|
||||
%%
|
||||
|
||||
{StringConstant} {
|
||||
yylval.String = yytext.Substring(1, yytext.Length - 2).Replace(@"\'", "'");
|
||||
return (int)Token.STRING_CONSTANT;
|
||||
}
|
||||
|
||||
{BooleanConstant} {
|
||||
yylval.Boolean = yytext.ToLower() switch {
|
||||
"true" => true,
|
||||
@@ -62,6 +57,11 @@ IsOfType '/'
|
||||
return (int)Token.BOOLEAN_CONSTANT;
|
||||
}
|
||||
|
||||
{StringConstant} {
|
||||
yylval.String = yytext.Substring(1, yytext.Length - 2).Replace(@"\'", "'");
|
||||
return (int)Token.STRING_CONSTANT;
|
||||
}
|
||||
|
||||
{NullConstant} {
|
||||
yylval.Null = DBNull.Value;
|
||||
return (int)Token.NULL_CONSTANT;
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
VITE_DATASTREAM_WEBSOCKET_URL=wss://localhost:443
|
||||
@@ -0,0 +1 @@
|
||||
VITE_DATASTREAM_WEBSOCKET_URL=wss://localhost:443
|
||||
@@ -12,6 +12,18 @@ module.exports = {
|
||||
settings: { react: { version: '18.3.1' } },
|
||||
plugins: ['react-refresh'],
|
||||
rules: {
|
||||
"import/order": [
|
||||
"error",
|
||||
{
|
||||
"groups": [
|
||||
"builtin",
|
||||
"external",
|
||||
"internal",
|
||||
["parent", "sibling", "index"]
|
||||
],
|
||||
"newlines-between": "always"
|
||||
}
|
||||
],
|
||||
'react-refresh/only-export-components': [
|
||||
'warn',
|
||||
{ allowConstantExport: true },
|
||||
|
||||
+1277
-1
File diff suppressed because it is too large.
Load diff
@@ -19,9 +19,13 @@
|
||||
"@mui/material": "^5.15.20",
|
||||
"@mui/x-data-grid": "^7.7.1",
|
||||
"bulma": "^1.0.1",
|
||||
"classnames": "^2.5.1",
|
||||
"react": "^18.3.1",
|
||||
"react-data-grid": "^7.0.0-beta.44",
|
||||
"react-data-table-component": "^7.6.2",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-json-view-lite": "^1.4.0",
|
||||
"react-pro-sidebar": "^1.1.0",
|
||||
"react-use-websocket": "^4.8.1",
|
||||
"rpc-websockets": "^7.11.2"
|
||||
},
|
||||
@@ -30,9 +34,11 @@
|
||||
"@types/react-dom": "^18.3.0",
|
||||
"@vitejs/plugin-react": "^4.3.1",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-plugin-import": "^2.29.1",
|
||||
"eslint-plugin-react": "^7.34.2",
|
||||
"eslint-plugin-react-hooks": "^4.6.2",
|
||||
"eslint-plugin-react-refresh": "^0.4.7",
|
||||
"react-mui-sidebar": "^1.3.5",
|
||||
"vite": "^5.2.13"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { Sidebar, Menu, MenuItem, Submenu, Logo } from "react-mui-sidebar";
|
||||
import './App.css';
|
||||
|
||||
const AnimatedSideBar = () => {
|
||||
return (
|
||||
<Sidebar className={"sidebar-container"} width={"270px"}>
|
||||
<Logo img="https://adminmart.com/wp-content/uploads/2024/03/logo-admin-mart-news.png">
|
||||
AdminMart
|
||||
</Logo>
|
||||
<Menu subHeading="HOME">
|
||||
<MenuItem link="/" badge="true">
|
||||
Modern
|
||||
</MenuItem>
|
||||
<MenuItem>eCommerce</MenuItem>
|
||||
<MenuItem>Analytical</MenuItem>
|
||||
</Menu>
|
||||
<Menu subHeading="APPS">
|
||||
<MenuItem>Chat</MenuItem>
|
||||
<MenuItem>Calendar</MenuItem>
|
||||
</Menu>
|
||||
<Menu subHeading="OTHERS">
|
||||
<Submenu title="Menu Level">
|
||||
<MenuItem>Post</MenuItem>
|
||||
<MenuItem>Details</MenuItem>
|
||||
<Submenu title="Level 2">
|
||||
<MenuItem>new</MenuItem>
|
||||
<MenuItem>Hello</MenuItem>
|
||||
</Submenu>
|
||||
</Submenu>
|
||||
|
||||
<MenuItem>Chip</MenuItem>
|
||||
<MenuItem target="_blank" link="google.com">
|
||||
External Link
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
</Sidebar>
|
||||
);
|
||||
};
|
||||
|
||||
export default AnimatedSideBar;
|
||||
@@ -2,6 +2,54 @@
|
||||
@use "@material/icon-button";
|
||||
@use "@material/data-table/data-table";
|
||||
|
||||
.root-div {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.main-content-div {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.title-div {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.container {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.container-column {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.container-row {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
box.query-input-form {
|
||||
/* p: 2, display: "flex", flexFlow: "column", alignItems: "stretch" */
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
/* li.ps-menuitem-root:hover {
|
||||
background-color: #ff9922;
|
||||
} */
|
||||
|
||||
.container-row-centered {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
h1#main-header {
|
||||
padding: 4px 8px 4px 8px;
|
||||
text-align: center;
|
||||
@@ -26,3 +74,28 @@ td#cell-string {
|
||||
td#cell-date-time {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* Sidebar.css */
|
||||
/* .sidebar-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
position: relative;
|
||||
top: 0;
|
||||
left: 0;
|
||||
height: 100vh;
|
||||
background-color: #333;
|
||||
color: white;
|
||||
overflow: hidden;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.sidebar.closed {
|
||||
width: 0;
|
||||
}
|
||||
|
||||
.sidebar.open {
|
||||
width: 250px;
|
||||
} */
|
||||
@@ -1,22 +1,171 @@
|
||||
import { createTheme, ThemeProvider, CssBaseline } from '@mui/material';
|
||||
import { ThemeProvider, CssBaseline, GlobalStyles } from '@mui/material';
|
||||
import QueryStatusView from './QueryStatusView';
|
||||
import useMediaQuery from '@mui/material/useMediaQuery';
|
||||
import QueryControl from './QueryControl';
|
||||
import DataTable from './DataTable';
|
||||
import { useState, useEffect, useMemo } from 'react';
|
||||
import useWebSocket, { ReadyState } from 'react-use-websocket';
|
||||
import Sidebar from './SideBar';
|
||||
import getTheme from './Theme';
|
||||
|
||||
import '@fontsource/noto-sans';
|
||||
import './App.css';
|
||||
import './SideBar.css';
|
||||
|
||||
const webSocketUrl = import.meta.env.VITE_DATASTREAM_WEBSOCKET_URL;
|
||||
// Always use the same subscription id (1), because we only show 1 table at a time.
|
||||
// The server will automatically dispose the previous subscription and start a new one
|
||||
// if we're currently subscribed to another query.
|
||||
const subscriptionId = "1";
|
||||
|
||||
var rpcReqIdCounter = 1;
|
||||
|
||||
function subscribeReq(query) {
|
||||
return {
|
||||
jsonrpc: "2.0",
|
||||
id: rpcReqIdCounter++,
|
||||
method: "subscribe",
|
||||
params: {
|
||||
subscription_id: subscriptionId,
|
||||
query: query
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function unsubscribeReq() {
|
||||
return {
|
||||
jsonrpc: "2.0",
|
||||
id: rpcReqIdCounter++,
|
||||
method: "unsubscribe",
|
||||
params: {
|
||||
subscription_id: subscriptionId,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const App = () => {
|
||||
const prefersDarkMode = useMediaQuery('(prefers-color-scheme: dark)');
|
||||
const theme = getTheme({ mode: prefersDarkMode ? 'dark' : 'light' });
|
||||
const globalStyles = {
|
||||
':root': {
|
||||
'--primary-color': theme.palette.primary.main,
|
||||
'--primary-dark-color': theme.palette.primary.dark,
|
||||
'--secondary-color': theme.palette.secondary.main,
|
||||
'--secondary-dark-color': theme.palette.secondary.dark,
|
||||
'--background-color': theme.palette.background.default,
|
||||
},
|
||||
};
|
||||
const [blueTable, setBlueTable] = useState({ columns: null, rows: null });
|
||||
const [queryError, setQueryError] = useState(null);
|
||||
const [queryState, setQueryState] = useState("Unsubscribed");
|
||||
const queryStateDetails = useMemo(() => {
|
||||
if (queryState == "Unsubscribed") {
|
||||
return "Enter query above, then click the play button to subscribe";
|
||||
}
|
||||
if (queryState == "Subscribed") {
|
||||
return null;
|
||||
}
|
||||
}, [queryState]);
|
||||
const [sidebarIsOpen, setSidebarIsOpen] = useState(false);
|
||||
const [cannedQuery, setCannedQuery] = useState(null);
|
||||
|
||||
const onCannedQueryClicked = (cannedQuery) => {
|
||||
console.info(`Executing canned query: ${JSON.stringify(cannedQuery)}`);
|
||||
const queryText = cannedQuery.query.join("\n");
|
||||
setCannedQuery({ queryText: queryText, clickTime: Date.now() });
|
||||
subscribe(queryText);
|
||||
};
|
||||
|
||||
const { sendJsonMessage, getWebSocket, readyState } = useWebSocket(
|
||||
webSocketUrl,
|
||||
{
|
||||
onOpen: (e) => console.info(`WebSocket open. ${JSON.stringify(e)}`),
|
||||
onClose: (e) => console.info(`WebSocket closed. ${JSON.stringify(e)}`),
|
||||
onError: (e) => console.error(`WebSocket error: ${JSON.stringify(e)}`),
|
||||
shouldReconnect: () => true,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
console.info(`WebSocket readyState: ${readyState}`)
|
||||
if (readyState != ReadyState.OPEN) {
|
||||
return;
|
||||
}
|
||||
const ws = getWebSocket();
|
||||
ws.onmessage = e => {
|
||||
console.info(`Received message: ${e.data}`);
|
||||
const msg = JSON.parse(e.data);
|
||||
setQueryError(msg.error);
|
||||
if (msg.error != null) {
|
||||
setQueryState("Error");
|
||||
} else if (msg.id != null) {
|
||||
setQueryState(msg.result.status);
|
||||
} else {
|
||||
console.assert(msg.params.subscription_id == subscriptionId);
|
||||
console.info(`Received rows: ${msg.params.table.all}`);
|
||||
setBlueTable({ columns: msg.params.table.columns, rows: msg.params.table.all });
|
||||
}
|
||||
};
|
||||
}, [getWebSocket, readyState]);
|
||||
|
||||
const subscribe = (query) => {
|
||||
const req = subscribeReq(query);
|
||||
console.info(`Subscribing: ${JSON.stringify(subscribeReq(query))}`);
|
||||
sendJsonMessage(req);
|
||||
};
|
||||
|
||||
const unsubscribe = () => {
|
||||
const req = unsubscribeReq();
|
||||
console.info(`Unsubscribing: ${JSON.stringify(req)}`);
|
||||
sendJsonMessage(req);
|
||||
};
|
||||
|
||||
const onOpened = () => {
|
||||
setSidebarIsOpen(true);
|
||||
};
|
||||
|
||||
const onClosed = () => {
|
||||
setSidebarIsOpen(false);
|
||||
};
|
||||
|
||||
const sidebarWidth = sidebarIsOpen ? '250px' : '65px';
|
||||
return (
|
||||
<ThemeProvider theme={theme}>
|
||||
<CssBaseline />
|
||||
<h1 id='main-header' style={{
|
||||
color: theme.palette.text.primary,
|
||||
fontFamily: 'Noto Sans',
|
||||
}}>BTS Cloud Streams</h1>
|
||||
<QueryControl websocketUrl="ws://localhost:5000/ws" theme={theme} />
|
||||
<GlobalStyles styles={globalStyles} />
|
||||
<div className='root-div'>
|
||||
<div style={{
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
alignItems: 'flex-start',
|
||||
flexWrap: 'nowrap',
|
||||
width: sidebarWidth,
|
||||
transition: 'width 0.3s ease',
|
||||
}}>
|
||||
<Sidebar onSelection={onCannedQueryClicked} onOpened={onOpened} onClosed={onClosed} />
|
||||
</div>
|
||||
<div style={{
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
left: sidebarWidth,
|
||||
width: '100%',
|
||||
transition: 'width 0.3s ease',
|
||||
}}>
|
||||
<div style={{ width: '100%', display: 'flex', flexDirection: 'column', alignItems: 'flex-start', margin: theme.spacing(2, 0, 0, 0) }}>
|
||||
<div style={{ width: '90%', rightMargin: '100px' }}>
|
||||
<QueryControl
|
||||
queryState={queryState}
|
||||
queryText={cannedQuery?.queryText}
|
||||
queryTextResetTime={cannedQuery?.clickTime}
|
||||
subscribe={subscribe}
|
||||
unsubscribe={unsubscribe} />
|
||||
</div>
|
||||
<div style={{ width: '90%', rightMargin: '100px' }}>
|
||||
<QueryStatusView queryState={queryState} details={queryStateDetails} error={queryError} />
|
||||
<DataTable columns={blueTable?.columns ?? []} rows={blueTable?.rows ?? []} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ThemeProvider>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
@use "@material/checkbox";
|
||||
@use "@material/icon-button";
|
||||
@use "@material/data-table/data-table";
|
||||
|
||||
.data-grid-container {
|
||||
overflow: auto;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
|
||||
.data-grid {
|
||||
max-height: 1000px;
|
||||
}
|
||||
|
||||
div[role=columnheader] {
|
||||
border-top: 0px;
|
||||
border-bottom: 0px;
|
||||
background-color: var(--primary-dark-color);
|
||||
}
|
||||
|
||||
/* div[role=columnheader] {
|
||||
border-top: 0px;
|
||||
border-bottom: 0px;
|
||||
background-color: var(--primary-dark-color);
|
||||
}
|
||||
|
||||
.rdg-row {
|
||||
border: 0px;
|
||||
border-top: 0px;
|
||||
border-bottom: 0px;
|
||||
background-color: rgba(var(--primary-dark-color), 0.8);
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.rdg-row-odd {
|
||||
border: 0px;
|
||||
border-top: 0px;
|
||||
border-bottom: 0px;
|
||||
background-color: var(--primary-dark-color);
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.rdg-cell {
|
||||
border-bottom: 0px;
|
||||
}
|
||||
|
||||
.rdg-cell.even {
|
||||
border-bottom: 5px;
|
||||
}
|
||||
|
||||
.rdg-cell.odd {
|
||||
border-bottom: 5px;
|
||||
} */
|
||||
@@ -1,19 +1,40 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import { useTheme } from '@mui/material/styles';
|
||||
import { DataGrid } from '@mui/x-data-grid';
|
||||
|
||||
function getGridColDef(col) {
|
||||
return {
|
||||
field: col.name,
|
||||
headerName: col.name,
|
||||
};
|
||||
}
|
||||
import './DataGrid.css'
|
||||
import { useMemo, useState } from 'react';
|
||||
|
||||
export default function DataTable({ columns, rows }) {
|
||||
const theme = useTheme();
|
||||
const [columnWidths, setColumnWidths] = useState({});
|
||||
|
||||
const handleColumnResize = (params) => {
|
||||
const newWidth = params.width;
|
||||
setColumnWidths((prevWidths) => ({
|
||||
...prevWidths,
|
||||
[params.colDef.field]: params.width,
|
||||
}));
|
||||
};
|
||||
|
||||
const getGridColDef = useMemo(() => {
|
||||
return col => {
|
||||
return {
|
||||
field: col.name,
|
||||
headerName: col.name,
|
||||
width: columnWidths[col.name],
|
||||
};
|
||||
}
|
||||
}, [columnWidths]);
|
||||
|
||||
return (
|
||||
<DataGrid
|
||||
columns={columns.map(getGridColDef)}
|
||||
rows={rows}
|
||||
className='data-grid-container'
|
||||
autosizeOnMount={false}
|
||||
columns={columns?.map(getGridColDef) ?? []}
|
||||
onColumnResize={handleColumnResize}
|
||||
rows={rows ?? []}
|
||||
sx={{
|
||||
margin: theme.spacing(2, 0, 0, 0),
|
||||
borderColor: 'primary.main',
|
||||
backgroundColor: 'primary.dark',
|
||||
color: 'text.primary',
|
||||
@@ -49,4 +70,5 @@ DataTable.propTypes = {
|
||||
})
|
||||
).isRequired,
|
||||
rows: PropTypes.arrayOf(PropTypes.array).isRequired,
|
||||
apiRef: PropTypes.object,
|
||||
};
|
||||
@@ -1,100 +1,119 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import DataTable from './DataTable';
|
||||
import QueryInputForm from './QueryInputForm';
|
||||
import Container from '@mui/material/Container';
|
||||
import React from 'react';
|
||||
import { useRef, useState, useEffect } from 'react';
|
||||
import { useGridApiRef } from '@mui/x-data-grid';
|
||||
import Box from '@mui/material/Box';
|
||||
import Button from '@mui/material/Button';
|
||||
import Grid from '@mui/material/Grid';
|
||||
import Paper from '@mui/material/Paper';
|
||||
import PlayArrowIcon from '@mui/icons-material/PlayArrow';
|
||||
import StopIcon from '@mui/icons-material/Stop';
|
||||
import TextField from '@mui/material/TextField';
|
||||
import Tooltip from '@mui/material/Tooltip';
|
||||
|
||||
var rpcReqIdCounter = 1;
|
||||
const QueryControl = (props) => {
|
||||
const { queryState, queryText, queryTextResetTime, subscribe, unsubscribe } = props;
|
||||
// const theme = useTheme();
|
||||
let textInput = useRef();
|
||||
const [queryTextChangeTime, setQueryTextChangeTime] = useState(null);
|
||||
useEffect(() => {
|
||||
if (queryText == null || textInput.current == null) {
|
||||
return;
|
||||
}
|
||||
// Init text field (unless a non-empty string is already present, or the user has modified
|
||||
// the query - we don't want to overwrite their changes).
|
||||
if (queryTextChangeTime == null || queryTextResetTime > queryTextChangeTime) {
|
||||
console.info(`Initializing query text: ${queryText}`)
|
||||
textInput.current.value = queryText;
|
||||
}
|
||||
}, [queryText, queryTextChangeTime, queryTextResetTime]);
|
||||
const onClearClick = () => {
|
||||
textInput.current.value = '';
|
||||
};
|
||||
|
||||
function subscribeReq(query) {
|
||||
return {
|
||||
jsonrpc: "2.0",
|
||||
id: rpcReqIdCounter++,
|
||||
method: "subscribe",
|
||||
params: {
|
||||
subscription_id: "1",
|
||||
query: query
|
||||
const onRunClick = () => {
|
||||
subscribe(textInput.current.value);
|
||||
};
|
||||
|
||||
const onStopClick = () => {
|
||||
unsubscribe();
|
||||
};
|
||||
|
||||
const onKeyDown = (e) => {
|
||||
// Detect keyboard shortcuts.
|
||||
// Ctrl+Enter : Run
|
||||
if (e.ctrlKey && e.key === 'Enter') {
|
||||
onRunClick();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function unsubscribeReq() {
|
||||
return {
|
||||
jsonrpc: "2.0",
|
||||
id: rpcReqIdCounter++,
|
||||
method: "unsubscribe",
|
||||
params: {
|
||||
subscription_id: "1",
|
||||
}
|
||||
const onChange = (e) => {
|
||||
// So we know not to overwrite the changes with the canned query on re-render
|
||||
setQueryTextChangeTime(Date.now());
|
||||
};
|
||||
}
|
||||
|
||||
class QueryControl extends React.Component {
|
||||
constructor({ websocketUrl, theme }) {
|
||||
super(websocketUrl);
|
||||
console.log('Connecting to WebSocket:', websocketUrl);
|
||||
this.state = {
|
||||
rows: null,
|
||||
ws: new WebSocket(websocketUrl),
|
||||
columns: null,
|
||||
isRunning: false,
|
||||
theme: theme,
|
||||
};
|
||||
this.state.ws.onopen = () => {
|
||||
console.info('WebSocket open');
|
||||
};
|
||||
this.state.ws.onclose = () => {
|
||||
console.info('WebSocket closed');
|
||||
};
|
||||
this.state.ws.onmessage = e => {
|
||||
console.info(`Received message: ${e.data}`);
|
||||
const msg = JSON.parse(e.data);
|
||||
if (msg.id != null) {
|
||||
let newState = { ...this.state };
|
||||
newState.isRunning = msg.result.status == 'Subscribed';
|
||||
this.setState(newState);
|
||||
} else {
|
||||
let newState = { ...this.state };
|
||||
newState.rows = msg.params.all;
|
||||
console.info(`Received rows: ${newState.rows}`);
|
||||
newState.columns = msg.params.columns;
|
||||
this.setState(newState);
|
||||
}
|
||||
};
|
||||
|
||||
this.start = (query) => {
|
||||
this.state.ws.send(JSON.stringify(subscribeReq(query)));
|
||||
};
|
||||
|
||||
this.stop = () => {
|
||||
this.state.ws.send(JSON.stringify(unsubscribeReq()));
|
||||
};
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
if (this.state.ws) {
|
||||
console.warn('Closing websocket because component is unmounting');
|
||||
this.state.ws.close();
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
console.info('Rendering');
|
||||
return (
|
||||
<Container>
|
||||
<QueryInputForm isRunning={this.state.isRunning} onStart={this.start} onStop={this.stop} />
|
||||
{
|
||||
this.state.rows == null ? <p style={{ color: this.state.theme.palette.warning.main }}>No data received</p> :
|
||||
<DataTable columns={this.state.columns} rows={this.state.rows} />
|
||||
}
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
}
|
||||
return (
|
||||
<Box sx={{ display: "flex", flexFlow: "column" }}>
|
||||
<Paper elevation={3} sx={{ color: 'primary.main' }}>
|
||||
<Box sx={{ p: 2 }}>
|
||||
<TextField
|
||||
fullWidth
|
||||
multiline
|
||||
rows={10}
|
||||
variant="outlined"
|
||||
onChange={onChange}
|
||||
onKeyDown={onKeyDown}
|
||||
inputRef={textInput}
|
||||
placeholder="Enter Query..."
|
||||
/>
|
||||
</Box>
|
||||
<Box sx={{ p: 2, borderTop: 1 }}>
|
||||
<Grid container spacing={2} justifyContent="flex-start">
|
||||
<Grid item xs>
|
||||
<Tooltip title="Clear Query Text">
|
||||
<Button onClick={onClearClick} sx={{ padding: '11px', color: 'text.dark' }}>
|
||||
Clear
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</Grid>
|
||||
<Grid item>
|
||||
<Tooltip title="Run (Ctrl+Enter)">
|
||||
<Button onClick={onRunClick} sx={{
|
||||
color: `queryStartButton.${queryState}.color`,
|
||||
bgcolor: `queryStartButton.${queryState}.backgroundColor`,
|
||||
padding: '11px'
|
||||
}}>
|
||||
<PlayArrowIcon />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</Grid>
|
||||
<Grid item>
|
||||
<Tooltip title="Stop">
|
||||
<Button onClick={onStopClick} sx={{
|
||||
color: `queryStopButton.${queryState}.color`,
|
||||
bgcolor: `queryStopButton.${queryState}.backgroundColor`,
|
||||
padding: '11px'
|
||||
}}>
|
||||
<StopIcon />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Box>
|
||||
</Paper>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
QueryControl.propTypes = {
|
||||
websocketUrl: PropTypes.string.isRequired,
|
||||
theme: PropTypes.object.isRequired,
|
||||
columns: PropTypes.array,
|
||||
rows: PropTypes.array,
|
||||
isRunning: PropTypes.bool,
|
||||
queryText: PropTypes.string,
|
||||
queryTextResetTime: PropTypes.number,
|
||||
queryState: PropTypes.string,
|
||||
subscribe: PropTypes.func,
|
||||
unsubscribe: PropTypes.func,
|
||||
};
|
||||
|
||||
export default QueryControl;
|
||||
@@ -1,93 +0,0 @@
|
||||
import { useRef } from 'react';
|
||||
import Box from '@mui/material/Box';
|
||||
import Button from '@mui/material/Button';
|
||||
import Grid from '@mui/material/Grid';
|
||||
import Paper from '@mui/material/Paper';
|
||||
import PlayArrowIcon from '@mui/icons-material/PlayArrow';
|
||||
import PropTypes from 'prop-types';
|
||||
import StopIcon from '@mui/icons-material/Stop';
|
||||
import TextField from '@mui/material/TextField';
|
||||
import Tooltip from '@mui/material/Tooltip';
|
||||
|
||||
const QueryInputForm = ({ isRunning, onStart, onStop }) => {
|
||||
let textInput = useRef(null);
|
||||
|
||||
const onClearClick = () => {
|
||||
textInput.current.value = '';
|
||||
};
|
||||
|
||||
const onRunClick = () => {
|
||||
onStart(textInput.current.value);
|
||||
};
|
||||
|
||||
const onStopClick = () => {
|
||||
onStop();
|
||||
};
|
||||
|
||||
const onKeyDown = (e) => {
|
||||
// Detect keyboard shortcuts.
|
||||
// Ctrl+Enter : Run
|
||||
if (e.ctrlKey && e.key === 'Enter') {
|
||||
onRunClick();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Box sx={{ p: 2 }}>
|
||||
<Paper elevation={3} sx={{ color: 'primary.main' }}>
|
||||
<Box sx={{ p: 2 }}>
|
||||
<TextField
|
||||
fullWidth
|
||||
multiline
|
||||
rows={10}
|
||||
variant="outlined"
|
||||
onKeyDown={onKeyDown}
|
||||
inputRef={textInput}
|
||||
placeholder="Enter Query..."
|
||||
/>
|
||||
</Box>
|
||||
<Box sx={{ p: 2, borderTop: 1 }}>
|
||||
<Grid container spacing={2} justifyContent="flex-start">
|
||||
<Grid item xs>
|
||||
<Tooltip title="Clear Query Text">
|
||||
<Button onClick={onClearClick} sx={{ padding: '11px', color: 'text.dark' }}>
|
||||
Clear
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</Grid>
|
||||
<Grid item>
|
||||
<Tooltip title="Run (Ctrl+Enter)">
|
||||
<Button onClick={onRunClick} sx={{
|
||||
color: `query_start_button.${isRunning ? 'active' : 'inactive'}.color`,
|
||||
bgcolor: `query_start_button.${isRunning ? 'active' : 'inactive'}.background_color`,
|
||||
padding: '11px'
|
||||
}}>
|
||||
<PlayArrowIcon />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</Grid>
|
||||
<Grid item>
|
||||
<Tooltip title="Stop">
|
||||
<Button onClick={onStopClick} sx={{
|
||||
color: `query_stop_button.${isRunning ? 'inactive' : 'active'}.color`,
|
||||
bgcolor: `query_stop_button.${isRunning ? 'inactive' : 'active'}.background_color`,
|
||||
padding: '11px'
|
||||
}}>
|
||||
<StopIcon />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Box>
|
||||
</Paper>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
QueryInputForm.propTypes = {
|
||||
isRunning: PropTypes.bool.isRequired,
|
||||
onStart: PropTypes.func.isRequired,
|
||||
onStop: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
export default QueryInputForm;
|
||||
@@ -0,0 +1,73 @@
|
||||
import { useState } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Box, Typography, Collapse } from '@mui/material';
|
||||
import Alert from '@mui/material/Alert';
|
||||
import AlertTitle from '@mui/material/AlertTitle';
|
||||
import { useTheme } from '@mui/material/styles';
|
||||
import { alpha } from '@mui/system';
|
||||
|
||||
const QueryStatusView = ({ queryState, details, error }) => {
|
||||
const theme = useTheme();
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
let header = queryState;
|
||||
let headerContent = null;
|
||||
let detailElements = [];
|
||||
let severity = queryState == "Subscribed" ? "success" : "info";
|
||||
let cursor = details == null ? "default" : "pointer";
|
||||
if (error != null) {
|
||||
severity = "error";
|
||||
cursor = "pointer";
|
||||
header = `Error Code: ${error.code}`;
|
||||
headerContent = error.message;
|
||||
detailElements.push(<Typography variant="body1">{error.data.error_message}</Typography>);
|
||||
detailElements.push(<Typography variant="subtitle1">Stack Trace:</Typography>);
|
||||
(error.data.stack_trace ?? []).forEach(line => detailElements.push(
|
||||
<Typography variant="body2" component="pre" sx={{ whiteSpace: 'pre-wrap' }}>
|
||||
{line}
|
||||
</Typography>));
|
||||
} else if (details != null) {
|
||||
detailElements.push(<Typography variant="body1">{details}</Typography>);
|
||||
}
|
||||
return (
|
||||
<Box sx={{ margin: theme.spacing(2, 0, 0, 0) }}>
|
||||
<Alert
|
||||
severity={severity}
|
||||
onClick={() => setOpen(!open)}
|
||||
sx={{
|
||||
margin: theme.spacing(2, 0, 0, 0),
|
||||
cursor: cursor,
|
||||
}}>
|
||||
<AlertTitle>{header}</AlertTitle>
|
||||
{headerContent}
|
||||
</Alert>
|
||||
{detailElements.length == 0
|
||||
? null
|
||||
: <Collapse in={open}>
|
||||
<Box
|
||||
sx={{
|
||||
backgroundColor: alpha(theme.palette[severity].light, 0.75),
|
||||
color: theme.palette[severity].contrastText,
|
||||
padding: theme.spacing(2),
|
||||
marginTop: theme.spacing(0),
|
||||
borderRadius: theme.shape.borderRadius,
|
||||
}}
|
||||
>
|
||||
{detailElements}
|
||||
</Box>
|
||||
</Collapse>}
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
QueryStatusView.propTypes = {
|
||||
queryState: PropTypes.string,
|
||||
details: PropTypes.string,
|
||||
error: PropTypes.shape({
|
||||
code: PropTypes.number,
|
||||
message: PropTypes.string,
|
||||
data: PropTypes.object,
|
||||
})
|
||||
};
|
||||
|
||||
export default QueryStatusView;
|
||||
@@ -0,0 +1,27 @@
|
||||
import 'react-data-grid/lib/styles.css';
|
||||
import PropTypes from 'prop-types';
|
||||
import DataGrid from 'react-data-grid';
|
||||
import './DataGrid.css';
|
||||
|
||||
function getGridColDef(col) {
|
||||
return {
|
||||
key: col.name,
|
||||
name: col.name,
|
||||
};
|
||||
}
|
||||
|
||||
export default function ReactDataGrid({columns, rows}) {
|
||||
return (
|
||||
<DataGrid className={"data-grid"} rows={rows} columns={columns.map(getGridColDef)} />
|
||||
)
|
||||
}
|
||||
|
||||
ReactDataGrid.propTypes = {
|
||||
columns: PropTypes.arrayOf(
|
||||
PropTypes.shape({
|
||||
name: PropTypes.string.isRequired,
|
||||
type: PropTypes.string.isRequired,
|
||||
})
|
||||
).isRequired,
|
||||
rows: PropTypes.arrayOf(PropTypes.array).isRequired,
|
||||
};
|
||||
@@ -0,0 +1,98 @@
|
||||
/* Sidebar.css */
|
||||
.app-container {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
flex-direction: row;
|
||||
justify-content: flex-start;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: flex-start;
|
||||
align-items: flex-start;
|
||||
background-color: transparent;
|
||||
color: white;
|
||||
overflow: hidden;
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
|
||||
.sidebar.open {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.sidebar.closed {
|
||||
width: 0%;
|
||||
}
|
||||
|
||||
.sidebar-toggle-button {
|
||||
border: 0px;
|
||||
border-radius: 50%;
|
||||
box-shadow: rgba(9, 30, 66, 0.08) 0px 0px 0px 1px, rgba(9, 30, 66, 0.08) 0px 2px 4px 1px;
|
||||
color: var(--primary-color);
|
||||
cursor: pointer;
|
||||
height: 24px;
|
||||
opacity: 1;
|
||||
outline: 0px;
|
||||
padding: 0px;
|
||||
background-color: transparent;
|
||||
transition: background-color 100ms linear 0s, color 100ms linear 0s, opacity 300ms cubic-bezier(0.2, 0, 0, 1) 0s, transform 300ms cubic-bezier(0.2, 0, 0, 1) 0s;
|
||||
width: 20%;
|
||||
}
|
||||
|
||||
.sidebar-toggle-button:hover {
|
||||
transition: background-color 100ms linear 0s, color 100ms linear 0s, opacity 300ms cubic-bezier(0.2, 0, 0, 1) 0s, transform 300ms cubic-bezier(0.2, 0, 0, 1) 0s;
|
||||
}
|
||||
|
||||
.main-content.open {
|
||||
width: 165px;
|
||||
transition: width 0.3s ease;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.main-content.closed {
|
||||
width: 0%;
|
||||
/* min-width: 25px; */
|
||||
transition: width 0.3s ease;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.sidebar-menu-item {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.sidebar-menu-item.open {
|
||||
width: 100%;
|
||||
/* justify-content: flex-start; */
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
|
||||
.sidebar-menu-item.closed {
|
||||
width: 0%;
|
||||
min-width: 0px;
|
||||
/* justify-content: flex-start; */
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
|
||||
.sidebar-menu-item-content.open {
|
||||
width: 100%;
|
||||
/* justify-content: flex-start; */
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
|
||||
.sidebar-menu-item-content.closed {
|
||||
width: 0px;
|
||||
/* justify-content: flex-start; */
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
|
||||
/* Ensure span can shrink */
|
||||
.button-text {
|
||||
display: block; /* Make span a block element */
|
||||
width: 100%; /* Ensure it takes the full width of its parent */
|
||||
overflow: hidden; /* Hide any overflow content */
|
||||
white-space: nowrap; /* Prevent text wrapping */
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import Button from '@mui/material/Button';
|
||||
import { useTheme } from '@mui/material/styles';
|
||||
import PropTypes from 'prop-types';
|
||||
import Tooltip from '@mui/material/Tooltip';
|
||||
import ChevronLeftRounded from "@mui/icons-material/ChevronLeftRounded"
|
||||
import ChevronRightRounded from '@mui/icons-material/ChevronRightRounded';
|
||||
import FileCopyIcon from '@mui/icons-material/FileCopy';
|
||||
import './SideBar.css';
|
||||
|
||||
const Sidebar = ({ onSelection, onOpened, onClosed }) => {
|
||||
const theme = useTheme();
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [cannedQueries, setCannedQueries] = useState([]);
|
||||
const Icon = isOpen ? ChevronLeftRounded : ChevronRightRounded;
|
||||
|
||||
const toggleIsOpen = () => {
|
||||
if (isOpen) {
|
||||
setIsOpen(false);
|
||||
if (onClosed != null) {
|
||||
onClosed();
|
||||
}
|
||||
} else {
|
||||
setIsOpen(true);
|
||||
if (onOpened != null) {
|
||||
onOpened();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const onMenuItemClick = (event, cannedQuery) => {
|
||||
console.info(`menu item clicked: ${cannedQuery.name}`);
|
||||
onSelection(cannedQuery);
|
||||
};
|
||||
|
||||
// const onMenuItemClick = async (event, cannedQuery) => {
|
||||
// try {
|
||||
// await navigator.clipboard.writeText(cannedQuery.query.join("\n"));
|
||||
// alert(`Copied ${cannedQuery.name} to clipboard`);
|
||||
// } catch (err) {
|
||||
// console.error('Failed to copy query text: ', err);
|
||||
// }
|
||||
// };
|
||||
|
||||
useEffect(() => {
|
||||
const fetchCannedQueries = async () => {
|
||||
try {
|
||||
const response = await fetch('api/cannedqueries');
|
||||
const data = await response.json();
|
||||
setCannedQueries(data);
|
||||
} catch (error) {
|
||||
console.error('Error fetching WebSocket config:', error);
|
||||
}
|
||||
}
|
||||
fetchCannedQueries();
|
||||
}, []);
|
||||
|
||||
const mainContentClass = `main-content ${isOpen ? 'open' : 'closed'}`;
|
||||
const menuItemClass = `sidebar-menu-item ${isOpen ? 'open' : 'closed'}`;
|
||||
const menuItemContentClass = `sidebar-menu-item-content ${isOpen ? 'open' : 'closed'}`;
|
||||
const toggleButtonTitle = `${isOpen ? 'Hide' : 'Show'} Common Queries`;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={"sidebar"}
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: 'row',
|
||||
justifyContent: 'flexStart',
|
||||
alignItems: 'flexStart',
|
||||
margin: theme.spacing(2, 0, 0, 0)
|
||||
}}
|
||||
>
|
||||
<div className={mainContentClass}>
|
||||
{cannedQueries.map(cq =>
|
||||
<Button key={cq.name} className={menuItemClass} onClick={(event) => onMenuItemClick(event, cq)}>
|
||||
<div className={menuItemContentClass}>
|
||||
<span className='button-text'>{cq.name}</span>
|
||||
</div>
|
||||
</Button>)
|
||||
}
|
||||
{/* {cannedQueries.map(cq =>
|
||||
<Button
|
||||
variant="contained"
|
||||
color="primary"
|
||||
startIcon={<FileCopyIcon />}
|
||||
onClick={onMenuItemClick}
|
||||
>
|
||||
<div className={menuItemContentClass}>
|
||||
<span className='button-text'>{cq.name}</span>
|
||||
</div>
|
||||
</Button>)} */}
|
||||
</div>
|
||||
<Tooltip title={toggleButtonTitle}>
|
||||
<Button onClick={toggleIsOpen}>
|
||||
<Icon className="w-5 h-5" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Sidebar;
|
||||
|
||||
Sidebar.propTypes = {
|
||||
onSelection: PropTypes.func,
|
||||
onOpened: PropTypes.func,
|
||||
onClosed: PropTypes.func,
|
||||
};
|
||||
@@ -42,32 +42,56 @@ const getDarkPalette = () => {
|
||||
dark: '#ffffff12',
|
||||
contrastText: '#c8d4f7',
|
||||
},
|
||||
action: {
|
||||
hoverOpacity: 0.08
|
||||
},
|
||||
text: {
|
||||
primary: '#eaf8f8',
|
||||
dark: '#eaf8f8a0'
|
||||
},
|
||||
query_start_button: {
|
||||
active: {
|
||||
queryStartButton: {
|
||||
Subscribed: {
|
||||
color: '#33baf9',
|
||||
background_color: '#ffffff40',
|
||||
backgroundColor: '#ffffff40',
|
||||
},
|
||||
inactive: {
|
||||
Unsubscribed: {
|
||||
color: '#ffffff40',
|
||||
background_color: '#ffffff00',
|
||||
backgroundColor: '#ffffff00',
|
||||
}
|
||||
},
|
||||
queryStopButton: {
|
||||
Subscribed: {
|
||||
color: '#ff4444a0',
|
||||
backgroundColor: '#ffffff40',
|
||||
},
|
||||
Unsubscribed: {
|
||||
color: '#ff444450',
|
||||
backgroundColor: '#ffffff00',
|
||||
}
|
||||
},
|
||||
error: {
|
||||
light: '#e57373',
|
||||
main: '#f44336',
|
||||
dark: '#d32f2f',
|
||||
contrastText: '#fff',
|
||||
},
|
||||
warning: {
|
||||
main: '#c4823f'
|
||||
light: '#ffb74d',
|
||||
main: '#ff9800',
|
||||
dark: '#f57c00',
|
||||
contrastText: '#000',
|
||||
},
|
||||
query_stop_button: {
|
||||
active: {
|
||||
color: '#ff4444a0',
|
||||
background_color: '#ffffff40',
|
||||
},
|
||||
inactive: {
|
||||
color: '#ff444450',
|
||||
background_color: '#ffffff00',
|
||||
}
|
||||
info: {
|
||||
light: '#64b5f6',
|
||||
main: '#2196f3',
|
||||
dark: '#303030',
|
||||
contrastText: '#fff',
|
||||
},
|
||||
success: {
|
||||
light: '#81c784',
|
||||
main: '#4caf50',
|
||||
dark: '#388e3c',
|
||||
contrastText: '#000',
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
font-weight: 400;
|
||||
|
||||
color-scheme: light dark;
|
||||
color: rgba(0, 0, 0, 0.87);
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
background-color: #242424;
|
||||
|
||||
font-synthesis: none;
|
||||
|
||||
@@ -3,7 +3,5 @@ import ReactDOM from 'react-dom/client';
|
||||
import App from './App';
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
<App />
|
||||
)
|
||||
@@ -1,5 +1,5 @@
|
||||
import { fileURLToPath, URL } from 'node:url';
|
||||
import { defineConfig } from 'vite';
|
||||
import { defineConfig, loadEnv } from 'vite';
|
||||
import plugin from '@vitejs/plugin-react';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
@@ -29,13 +29,12 @@ if (!fs.existsSync(certFilePath) || !fs.existsSync(keyFilePath)) {
|
||||
}
|
||||
}
|
||||
|
||||
const target = env.ASPNETCORE_HTTPS_PORT
|
||||
? `https://localhost:${env.ASPNETCORE_HTTPS_PORT}`
|
||||
: env.ASPNETCORE_URLS
|
||||
? env.ASPNETCORE_URLS.split(';')[0]
|
||||
: 'https://localhost:5001';
|
||||
|
||||
export default defineConfig(({ $$command, mode, $$isSsrBuild, $$isPreview }) => {
|
||||
const target = env.ASPNETCORE_HTTPS_PORT
|
||||
? `https://localhost:${env.ASPNETCORE_HTTPS_PORT}`
|
||||
: env.ASPNETCORE_URLS
|
||||
? env.ASPNETCORE_URLS.split(';')[0]
|
||||
: 'https://localhost:8443';
|
||||
return {
|
||||
plugins: [plugin()],
|
||||
resolve: {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
@@ -12,8 +12,8 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommandLineParser" Version="2.9.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaProxy" Version="8.0.6" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="8.0.6" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaProxy" Version="7.0.20" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="7.0.20" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
</ItemGroup>
|
||||
@@ -27,10 +27,14 @@
|
||||
<ProjectReference Include="..\..\client\spark_api\spark_api.csproj" />
|
||||
<ProjectReference Include="..\..\client\spark_core\spark_core.csproj" />
|
||||
<ProjectReference Include="..\..\client\spark_websocket\spark_websocket.csproj" />
|
||||
<ProjectReference Include="..\Bts.Extensions.DependencyInjection\Bts.Extensions.DependencyInjection.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- <ItemGroup>
|
||||
<Content Update="wwwroot\alt-index.html" CopyToPublishDirectory="Never" />
|
||||
</ItemGroup> -->
|
||||
<ItemGroup>
|
||||
<ConfigurationProfile Include="appsettings.Development.json" />
|
||||
<ConfigurationProfile Include="appsettings.Production.json" />
|
||||
<ConfigurationProfile Include="appsettings.ProductionAws.json" />
|
||||
<ConfigurationProfile Include="appsettings.Staging.json" />
|
||||
<ConfigurationProfile Include="appsettings.json" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace Bts.DataStreamWebApp.Server;
|
||||
|
||||
public class CannedQueriesConfig {
|
||||
public List<CannedQuery>? Items { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Bts.DataStreamWebApp.Server;
|
||||
|
||||
public class CannedQuery {
|
||||
public string? Name { get; set; }
|
||||
public List<string>? Query { get; set; }
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
{
|
||||
"Spark": {
|
||||
"ConfigServer": "http://localhost:8000/config"
|
||||
},
|
||||
"SparkdCredentials": {
|
||||
"User": "bts",
|
||||
"Password": ""
|
||||
},
|
||||
"MasterWorker": {
|
||||
"Interval": "00:00:00.1"
|
||||
},
|
||||
"PubSub": {
|
||||
"Routing": {
|
||||
"PublisherRoutes": [
|
||||
{
|
||||
"Name": "default",
|
||||
"ServerAddress": "bts-cloud://127.0.0.1:12345",
|
||||
"TagRegExp": ".*"
|
||||
}
|
||||
],
|
||||
"SubscriberRoutes": [
|
||||
{
|
||||
"Name": "default",
|
||||
"ServerAddress": "bts-cloud://127.0.0.1:12345",
|
||||
"TagRegExp": ".*"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"ViewStreamDatabase": {
|
||||
"Interval": "00:00:01"
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"content_root_path": "build/Bts.DataStreamWebApp.Client/production",
|
||||
"web_root_path": "dist"
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
namespace Bts.DataStreamWebApp.Server;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class CannedQueriesController : ControllerBase {
|
||||
readonly IConfiguration config;
|
||||
|
||||
public CannedQueriesController(IConfiguration config) =>
|
||||
this.config = config;
|
||||
|
||||
[HttpGet(Name = "GetCannedQueries")]
|
||||
public IEnumerable<CannedQuery>? Get() {
|
||||
var cannedQueries = config.GetSection("CannedQueries").Get<List<CannedQuery>>()?.ToArray() ?? Array.Empty<CannedQuery>();
|
||||
return cannedQueries;
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// using Bts.DataStreamWebApp.Server;
|
||||
|
||||
// using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
// [ApiController]
|
||||
// [Route("api/[controller]")]
|
||||
// public class ConfigController : ControllerBase {
|
||||
// private readonly IConfiguration _configuration;
|
||||
|
||||
// public ConfigController(IConfiguration configuration) {
|
||||
// _configuration = configuration;
|
||||
// }
|
||||
|
||||
// [HttpGet("websocket")]
|
||||
// public ActionResult<DataStreamWebSocketConfig> GetWebSocketConfig() {
|
||||
// var endpoint = $"{_configuration["Kestrel:Endpoints:Http:Url"]}/ws";
|
||||
// var webSocketConfig = new DataStreamWebSocketConfig {
|
||||
// Endpoint = endpoint // or Https based on your setup
|
||||
// };
|
||||
// return Ok(webSocketConfig);
|
||||
// }
|
||||
// }
|
||||
+10
-16
@@ -1,36 +1,30 @@
|
||||
namespace Bts.DataStreamWebApp.Server.Controllers;
|
||||
|
||||
using BCG;
|
||||
|
||||
using bts.api.core;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
[Route("/ws")]
|
||||
public class DataStreamSubscriptionController : ControllerBase {
|
||||
readonly ILogger logger;
|
||||
readonly PrimitiveManager primitiveManager;
|
||||
readonly IServiceProvider serviceProvider;
|
||||
|
||||
public DataStreamSubscriptionController(ILogger<DataStreamSubscriptionController> logger, PrimitiveManager primitiveManager, IServiceProvider serviceProvider) {
|
||||
public DataStreamSubscriptionController(ILogger<DataStreamSubscriptionController> logger) {
|
||||
this.logger = logger;
|
||||
this.primitiveManager = primitiveManager;
|
||||
this.serviceProvider = serviceProvider;
|
||||
logger.LogInformation("Creating {ControllerType}", GetType().Name);
|
||||
}
|
||||
|
||||
[Route("/ws")]
|
||||
public async Task Get() {
|
||||
public async Task Get(CancellationToken cancellationToken) {
|
||||
if (!HttpContext.WebSockets.IsWebSocketRequest) {
|
||||
logger.LogError("Expected websocket request on path '{}'", HttpContext.Request.Path);
|
||||
return;
|
||||
}
|
||||
logger.LogInformation("Establishing websocket connection...");
|
||||
using var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync();
|
||||
logger.LogInformation("Websocket connection established.");
|
||||
var context = ServiceContext.create();
|
||||
await context.login("bts", string.Empty);
|
||||
var server = new DataStreamWebSocketServer(webSocket, logger, primitiveManager, serviceProvider);
|
||||
await server.Run();
|
||||
try {
|
||||
using var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync();
|
||||
logger.LogInformation("Websocket connection established.");
|
||||
using var server = new DataStreamWebSocketServer(webSocket, logger);
|
||||
await server.Run(cancellationToken);
|
||||
} catch (Exception ex) {
|
||||
logger.LogError("DataStreamSubscriptionController.Run threw exception: {Exception}", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,27 +7,29 @@ using bts.websocket_core.json_rpc;
|
||||
using Bts.DataStreamCore;
|
||||
using Bts.DataStreamWebApp.Server.Messages;
|
||||
|
||||
using System;
|
||||
using System.Net.WebSockets;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
class DataStreamSubscription : IDisposable {
|
||||
class DataStreamSubscription : IDisposable, IHostedService {
|
||||
public readonly ViewStream ViewStream;
|
||||
public DataPacket? LastFired;
|
||||
public readonly string Id;
|
||||
|
||||
readonly ILogger logger;
|
||||
readonly WebSocket webSocket;
|
||||
readonly DataPacketJsonSerializer dataPacketSerializer = new();
|
||||
|
||||
public DataStreamSubscription(string id, ViewStream viewStream, WebSocket webSocket, ILogger logger) {
|
||||
public DataStreamSubscription(string id, JsonRpcId requestId, ViewStream viewStream, WebSocket webSocket, ILogger logger) {
|
||||
ViewStream = viewStream;
|
||||
RequestId = requestId;
|
||||
Id = id;
|
||||
this.webSocket = webSocket;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public string Id { get; }
|
||||
public JsonRpcId RequestId { get; }
|
||||
public SubscriptionStatus Status { get; private set; }
|
||||
|
||||
public void Start() {
|
||||
@@ -40,6 +42,12 @@ class DataStreamSubscription : IDisposable {
|
||||
ViewStream.onChange += onChange;
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken) {
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
Start();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Clear() {
|
||||
if (LastFired is null) {
|
||||
return Task.CompletedTask;
|
||||
@@ -58,6 +66,12 @@ class DataStreamSubscription : IDisposable {
|
||||
ViewStream.onChange -= onChange;
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken) {
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
Stop();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public void Dispose() =>
|
||||
Stop();
|
||||
|
||||
@@ -83,7 +97,10 @@ class DataStreamSubscription : IDisposable {
|
||||
IncludeCurrent = true,
|
||||
UseObjectRows = true,
|
||||
});
|
||||
var res = JsonRpcRequest.CreateNotification(method, dp);
|
||||
var res = JsonRpcRequest.CreateNotification(method, new DataStreamSubscriptionUpdate() {
|
||||
SubscriptionId = Id,
|
||||
Table = dp
|
||||
});
|
||||
var str = serialize(res, serializerOpts);
|
||||
if (str is null) {
|
||||
logger.LogError("Unsubscribing from stream early because we failed to serialize an outgoing DataPacket");
|
||||
@@ -96,8 +113,12 @@ class DataStreamSubscription : IDisposable {
|
||||
dp.schema.columnNames.Length,
|
||||
str.Length);
|
||||
var bytes = Encoding.UTF8.GetBytes(str);
|
||||
await webSocket.SendAsync(bytes, WebSocketMessageType.Text, true, CancellationToken.None);
|
||||
LastFired = dp;
|
||||
try {
|
||||
await webSocket.SendAsync(bytes, WebSocketMessageType.Text, true, CancellationToken.None);
|
||||
LastFired = dp;
|
||||
} catch (WebSocketException ex) {
|
||||
logger.LogError($"sendDataPacket failed on webSocket.SendAsync: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
string? serialize<T>(T message, JsonSerializerOptions? opts) {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Bts.DataStreamWebApp.Server;
|
||||
|
||||
using BCG;
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
public class DataStreamSubscriptionUpdate {
|
||||
[JsonPropertyName("subscription_id")]
|
||||
public string? SubscriptionId { get; set; }
|
||||
|
||||
[JsonPropertyName("table")]
|
||||
public DataPacket? Table { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace Bts.DataStreamWebApp.Server;
|
||||
|
||||
public class DataStreamWebSocketConfig {
|
||||
public string? Endpoint { get; set; }
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
namespace Bts.DataStreamWebApp.Server.Controllers;
|
||||
|
||||
using BCG;
|
||||
|
||||
using bts.websocket_core.json_rpc;
|
||||
|
||||
using Bts.DataStreamWebApp.Server.Messages;
|
||||
@@ -11,26 +9,22 @@ using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
public class DataStreamWebSocketServer {
|
||||
public class DataStreamWebSocketServer : IDisposable, IAsyncDisposable {
|
||||
readonly ILogger logger;
|
||||
readonly WebSocket webSocket;
|
||||
readonly Dictionary<string, DataStreamSubscription> subscriptions = new();
|
||||
readonly PrimitiveManager primitiveManager;
|
||||
readonly IServiceProvider serviceProvider;
|
||||
|
||||
public DataStreamWebSocketServer(WebSocket webSocket, ILogger logger, PrimitiveManager primitiveManager, IServiceProvider serviceProvider) {
|
||||
public DataStreamWebSocketServer(WebSocket webSocket, ILogger logger) {
|
||||
this.webSocket = webSocket;
|
||||
this.logger = logger;
|
||||
this.primitiveManager = primitiveManager;
|
||||
this.serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public async Task<int> Run() {
|
||||
public async Task<int> Run(CancellationToken cancellationToken) {
|
||||
logger.LogInformation("DataStreamWebSocketServer running");
|
||||
await foreach (var req in JsonRpcRequestAsyncEnumerable.Create(webSocket, logger)) {
|
||||
await foreach (var req in JsonRpcRequestAsyncEnumerable.Create(webSocket, logger, cancellationToken)) {
|
||||
await (req.Method switch {
|
||||
"subscribe" => onSubscribe(req),
|
||||
"unsubscribe" => onUnsubscribe(req.Deserialize<UnsubscribeRequest>()),
|
||||
"subscribe" => onSubscribe(req, cancellationToken),
|
||||
"unsubscribe" => onUnsubscribe(req.Deserialize<UnsubscribeRequest>(), cancellationToken),
|
||||
_ => Task.CompletedTask,
|
||||
});
|
||||
}
|
||||
@@ -38,56 +32,117 @@ public class DataStreamWebSocketServer {
|
||||
return 0;
|
||||
}
|
||||
|
||||
async Task onSubscribe(JsonRpcRequest<JsonNode> req) {
|
||||
/// <summary>
|
||||
/// Disposes internal subscriptions. To additionally notify the client of the subscription status
|
||||
/// change(s), use <see cref="DisposeAsync"/>.
|
||||
/// </summary>
|
||||
public void Dispose() {
|
||||
GC.SuppressFinalize(this);
|
||||
disposeSubscriptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes internal subscriptions (like <see cref="Dispose"/>), then sends 'subscription status change'
|
||||
/// notifications to the client (unlike <see cref="Dispose"/>).
|
||||
/// </summary>
|
||||
public async ValueTask DisposeAsync() {
|
||||
GC.SuppressFinalize(this);
|
||||
var finalSubs = subscriptions.Values.Select(s => (s.RequestId, s.Id)).ToList();
|
||||
disposeSubscriptions();
|
||||
// Send a 'subscription status change' msg to the client for each one.
|
||||
foreach (var (requestId, id) in finalSubs) {
|
||||
await sendSubscriptionStatus(requestId, id, "unsubscribe", SubscriptionStatus.Unsubscribed, CancellationToken.None);
|
||||
}
|
||||
}
|
||||
|
||||
async Task onSubscribe(JsonRpcRequest<JsonNode> req, CancellationToken cancellationToken) {
|
||||
ArgumentNullException.ThrowIfNull(req.Id);
|
||||
ArgumentException.ThrowIfNullOrEmpty(req.Method);
|
||||
if (!SubscribeRequest.ParseQuery(req, primitiveManager, out var vs, out var subId, out var errMsg, out var errCode)) {
|
||||
logger.LogError("Invalid 'subscribe' request: {Reason}", errMsg);
|
||||
await send(new JsonRpcError<JsonNode>() {
|
||||
Code = (long)errCode,
|
||||
Message = $"{errCode}: {errMsg}",
|
||||
});
|
||||
if (!SubscribeRequest.Parse(req, out var subReq, out var parseErr, out var errCode)) {
|
||||
logger.LogError("Invalid 'subscribe' request: {Reason}", parseErr);
|
||||
var rpcError = JsonRpcResponse.CreateError<SubscriptionError>(
|
||||
req.Id, new() { Code = (long)errCode, Message = "Failed to parse subscription request", Data = parseErr });
|
||||
await send(rpcError, cancellationToken);
|
||||
return;
|
||||
}
|
||||
var subId = subReq.SubscriptionId ?? throw new InvalidOperationException("SubscriptionId is null (parse false)");
|
||||
disposeSubscription(subId);
|
||||
if (!subReq.ParseQuery(out var vs, out parseErr, out errCode)) {
|
||||
logger.LogError("Invalid 'subscribe' request: {Reason}", parseErr);
|
||||
var rpcError = JsonRpcResponse.CreateError<SubscriptionError>(
|
||||
req.Id, new() { Code = (long)errCode, Message = "Failed to parse subscription request", Data = parseErr });
|
||||
await send(rpcError, cancellationToken);
|
||||
return;
|
||||
}
|
||||
if (subscriptions.TryGetValue(subId, out var oldSub)) {
|
||||
logger.LogInformation("Disposing existing subscription with id {SubscriptionId}", subId);
|
||||
oldSub.Dispose();
|
||||
}
|
||||
vs.Reset(serviceProvider);
|
||||
var sub = new DataStreamSubscription(subId, vs, webSocket, logger);
|
||||
var sub = new DataStreamSubscription(subId, req.Id.Value, vs, webSocket, logger);
|
||||
subscriptions[subId] = sub;
|
||||
await sendSubscriptionStatus(req.Id.Value, subId, req.Method, SubscriptionStatus.Subscribed);
|
||||
sub.Start();
|
||||
await sendSubscriptionStatus(req.Id.Value, subId, req.Method, SubscriptionStatus.Subscribed, cancellationToken);
|
||||
vs.ErrorChanged += OnStreamError;
|
||||
await sub.StartAsync(cancellationToken);
|
||||
|
||||
async void OnStreamError(Exception exception) {
|
||||
logger.LogError("Error in ViewStream (disposing subscription): {Exception}", exception);
|
||||
subscriptions.Remove(sub.Id);
|
||||
sub.Dispose();
|
||||
var error = new SubscriptionError() {
|
||||
ErrorMessage = "Error in ViewStream (disposing subscription)"
|
||||
};
|
||||
if (exception is not null) {
|
||||
error.ErrorMessage += ". " + exception.Message;
|
||||
error.StackTrace = exception.StackTrace?.Split("\n")?.ToList();
|
||||
}
|
||||
var rpcError = JsonRpcResponse.CreateError<SubscriptionError>(
|
||||
req.Id, new() { Code = (long)ErrorCode.ViewStreamError, Message = "Error in ViewStream (disposing subscription)", Data = error });
|
||||
await send(rpcError, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
async Task onUnsubscribe(JsonRpcRequest<UnsubscribeRequest> req) {
|
||||
async Task onUnsubscribe(JsonRpcRequest<UnsubscribeRequest> req, CancellationToken cancellationToken) {
|
||||
ArgumentNullException.ThrowIfNull(req.Id);
|
||||
ArgumentException.ThrowIfNullOrEmpty(req.Method);
|
||||
var subId = req.Params?.SubscriptionId ?? string.Empty;
|
||||
if (!subscriptions.TryGetValue(subId, out var sub)) {
|
||||
logger.LogInformation("Ignoring '{Method}' request because no subscription was found with id {Id}.", req.Method, subId);
|
||||
return;
|
||||
if (!disposeSubscription(subId)) {
|
||||
logger.LogInformation("Unable to dispose subscription. Subscription with id {Id} not found.", subId);
|
||||
}
|
||||
logger.LogInformation("Disposing subscription");
|
||||
await sendSubscriptionStatus(req.Id.Value, subId, "unsubscribe", SubscriptionStatus.Unsubscribed, cancellationToken);
|
||||
}
|
||||
|
||||
bool disposeSubscription(string subId) {
|
||||
if (!subscriptions.TryGetValue(subId, out var sub)) {
|
||||
return false;
|
||||
}
|
||||
logger.LogInformation("Disposing subscription with id {Id}", subId);
|
||||
sub.Dispose();
|
||||
subscriptions.Remove(subId);
|
||||
await sendSubscriptionStatus(req.Id.Value, subId, req.Method, SubscriptionStatus.Unsubscribed);
|
||||
return true;
|
||||
}
|
||||
|
||||
Task sendSubscriptionStatus(JsonRpcId reqId, string subId, string method, SubscriptionStatus status) {
|
||||
Task sendSubscriptionStatus(JsonRpcId reqId, string subId, string method, SubscriptionStatus status, CancellationToken cancellationToken) {
|
||||
logger.LogInformation("Sending {Method} ack. SubscriptionId = {SubscriptionId}", method, subId);
|
||||
return send(JsonRpcResponse.Create(reqId, new SubscriptionStatusMessage() {
|
||||
var response = JsonRpcResponse.Create(reqId, new SubscriptionStatusMessage() {
|
||||
SubscriptionId = subId,
|
||||
Status = status,
|
||||
}));
|
||||
});
|
||||
return send(response, cancellationToken);
|
||||
}
|
||||
|
||||
Task send<T>(T message) {
|
||||
Task send<T>(T message, CancellationToken cancellationToken) {
|
||||
if (message is null) {
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
var str = JsonSerializer.Serialize(message);
|
||||
var bytes = Encoding.UTF8.GetBytes(str);
|
||||
logger.LogTrace("Sending data. Length = {Length}", bytes.Length);
|
||||
return webSocket.SendAsync(bytes, WebSocketMessageType.Text, true, CancellationToken.None);
|
||||
return webSocket.SendAsync(bytes, WebSocketMessageType.Text, true, cancellationToken);
|
||||
}
|
||||
|
||||
void disposeSubscriptions() {
|
||||
logger.LogInformation("Disposing DataStreamWebSocketServer subscriptions. Count: {Count}", subscriptions.Count);
|
||||
subscriptions.Values.DisposeAll();
|
||||
subscriptions.Clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
FROM bluetradingsystems/linux_dotnet7
|
||||
|
||||
RUN dotnet dev-certs https --trust
|
||||
COPY --chown=bts:bts "build/Release/bin/net7.0/linux-x64/publish" "bin"
|
||||
COPY --chown=bts:bts "build/Bts.DataStreamWebApp.Client/production/dist" "bin/wwwroot"
|
||||
COPY --chown=bts:bts "src/DataStreamSuite/Bts.DataStreamWebApp.Server/spark.conf" ".local/share/bts/Bts.DataStreamWebApp.Server/conf/spark.conf"
|
||||
WORKDIR "/home/bts/bin"
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace Bts.DataStreamWebApp.Server;
|
||||
|
||||
public class CannedQueriesResponse {
|
||||
public List<CannedQuery>? Items { get; set; }
|
||||
}
|
||||
@@ -3,4 +3,5 @@ namespace Bts.DataStreamWebApp.Server.Messages;
|
||||
enum ErrorCode {
|
||||
None = 0,
|
||||
InvalidSubscriptionRequest,
|
||||
ViewStreamError,
|
||||
}
|
||||
@@ -18,54 +18,52 @@ public class SubscribeRequest {
|
||||
[JsonPropertyName("subscription_id")]
|
||||
public string? SubscriptionId { get; set; }
|
||||
|
||||
internal static bool ParseQuery(
|
||||
JsonRpcRequest<JsonNode> req,
|
||||
PrimitiveManager primitiveManager,
|
||||
[NotNullWhen(true)] out ViewStream? stream,
|
||||
[NotNullWhen(true)] out string? subscriptionId,
|
||||
[NotNullWhen(false)] out string? errorMessage,
|
||||
out ErrorCode errorCode
|
||||
) {
|
||||
stream = null;
|
||||
subscriptionId = null;
|
||||
internal static bool Parse(JsonRpcRequest<JsonNode> req, [NotNullWhen(true)]out SubscribeRequest? subscription, [NotNullWhen(false)]out SubscriptionError? error, out ErrorCode errorCode) {
|
||||
subscription = null;
|
||||
errorCode = ErrorCode.None;
|
||||
var paramsJsonObj = req.Params?.AsObject();
|
||||
error = null;
|
||||
if (paramsJsonObj is null) {
|
||||
errorCode = ErrorCode.InvalidSubscriptionRequest;
|
||||
errorMessage = "'params' object not found";
|
||||
error = new() { ErrorMessage = "'params' object not found" };
|
||||
return false;
|
||||
}
|
||||
var subReq = paramsJsonObj.Deserialize<SubscribeRequest>();
|
||||
if (subReq is null) {
|
||||
subscription = paramsJsonObj.Deserialize<SubscribeRequest>();
|
||||
if (subscription is null) {
|
||||
errorCode = ErrorCode.InvalidSubscriptionRequest;
|
||||
errorMessage = "'params' object invalid";
|
||||
error = new() { ErrorMessage = "'params' object invalid" };
|
||||
return false;
|
||||
}
|
||||
subscriptionId = subReq.SubscriptionId ?? string.Empty;
|
||||
var query = subReq.Query;
|
||||
if (query is null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
internal bool ParseQuery([NotNullWhen(true)] out ViewStream? stream, [NotNullWhen(false)] out SubscriptionError? error, out ErrorCode errorCode) {
|
||||
stream = null;
|
||||
errorCode = ErrorCode.None;
|
||||
error = null;
|
||||
if (Query is null) {
|
||||
errorCode = ErrorCode.InvalidSubscriptionRequest;
|
||||
errorMessage = "'params.query' field not found (expected a string)";
|
||||
error = new() { ErrorMessage = "'params.query' field not found (expected a string)" };
|
||||
return false;
|
||||
}
|
||||
errorMessage = null;
|
||||
var exp = DataStreamExpressionsInterpreter.Evaluate(query);
|
||||
var exp = DataStreamExpressionsInterpreter.Evaluate(Query);
|
||||
if (exp is null) {
|
||||
errorCode = ErrorCode.InvalidSubscriptionRequest;
|
||||
errorMessage = "'params.query' expression has invalid syntax";
|
||||
error = new() { ErrorMessage = "'params.query' expression has invalid syntax" };
|
||||
return false;
|
||||
}
|
||||
string? exceptionMsg = null;
|
||||
Exception? exception = null;
|
||||
try {
|
||||
stream = exp.getView(new Dictionary<string, StatementExpression>(0), primitiveManager);
|
||||
stream = exp.getView(new Dictionary<string, StatementExpression>(0));
|
||||
} catch (Exception ex) {
|
||||
exceptionMsg = ex.ToString();
|
||||
exception = ex;
|
||||
}
|
||||
if (stream is null) {
|
||||
errorCode = ErrorCode.InvalidSubscriptionRequest;
|
||||
errorMessage = "Failed to create ViewStream from 'params.query' expression (check for typos in arguments/typenames)";
|
||||
if (exceptionMsg is not null) {
|
||||
errorMessage += ". Error" + exceptionMsg;
|
||||
error = new() { ErrorMessage = "Failed to create ViewStream from 'params.query' expression (check for typos in arguments/typenames)" };
|
||||
if (exception is not null) {
|
||||
error.ErrorMessage += ". " + exception.Message;
|
||||
error.StackTrace = exception.StackTrace?.Split("\n")?.ToList();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Bts.DataStreamWebApp.Server.Messages;
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
public class SubscriptionError {
|
||||
[JsonPropertyName("error_message")]
|
||||
public string? ErrorMessage { get; set; }
|
||||
|
||||
[JsonPropertyName("stack_trace")]
|
||||
public List<string>? StackTrace { get; set; }
|
||||
}
|
||||
@@ -1,64 +1,82 @@
|
||||
using Bts.DataStreamCore.Services;
|
||||
using Bts.DataStreamWebApp.Server.Services;
|
||||
using Bts.PubSub.Services;
|
||||
|
||||
using Spark.Api.Services;
|
||||
using Spark.Core.Services;
|
||||
|
||||
using System.Reactive.Linq;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(new WebApplicationOptions {
|
||||
Args = args,
|
||||
ApplicationName = "Bts.DataStreamWebApp.Server",
|
||||
});
|
||||
ConfigureApp(builder.Configuration);
|
||||
ConfigureServices(builder.Services, builder.Configuration);
|
||||
|
||||
var app = builder.Build();
|
||||
if (app.Environment.IsDevelopment()) {
|
||||
app.UseDirectoryBrowser();
|
||||
}
|
||||
var wsOpts = new WebSocketOptions {
|
||||
KeepAliveInterval = TimeSpan.FromMinutes(2)
|
||||
};
|
||||
app.UseWebSockets(wsOpts);
|
||||
app.UseDefaultFiles();
|
||||
app.UseStaticFiles();
|
||||
if (app.Environment.IsDevelopment()) {
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
app.UseHttpsRedirection();
|
||||
app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
try {
|
||||
Console.Write($"Starting Application");
|
||||
app.Run();
|
||||
Console.Write($"Application exited gracefully.");
|
||||
} catch (Exception ex) {
|
||||
Console.Error.Write($"Application crashed: {ex}");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
static void ConfigureApp(ConfigurationManager configBuilder) {
|
||||
configBuilder.AddCommandLine(Environment.GetCommandLineArgs());
|
||||
var cfgRoot = configBuilder.GetSection("config");
|
||||
if (cfgRoot?.Value is not null) {
|
||||
configBuilder.AddJsonFile(cfgRoot.Value);
|
||||
}
|
||||
}
|
||||
|
||||
static void ConfigureServices(IServiceCollection services, IConfiguration config) {
|
||||
services.AddDirectoryBrowser();
|
||||
services.AddControllers();
|
||||
services.AddEndpointsApiExplorer();
|
||||
services.AddSwaggerGen();
|
||||
services.AddMasterWorker(config.GetSection("MasterWorker"));
|
||||
services.AddViewStreamDatabase(config.GetSection("ViewStreamDatabase"));
|
||||
services.AddPubSubClient(config.GetSection("PubSub"));
|
||||
services.AddPrimitiveManager();
|
||||
services.AddSpark(config.GetSection("Spark"));
|
||||
services.AddSparkd(config.GetSection("SparkdCredentials"));
|
||||
services.AddHostedService<DataStreamWebAppService>();
|
||||
}
|
||||
using Bts.DataStreamCore.Services;
|
||||
using Bts.PubSub.Services;
|
||||
|
||||
using Spark.Api.Services;
|
||||
using Spark.Core.Services;
|
||||
|
||||
using System.Reactive.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(new WebApplicationOptions {
|
||||
Args = args,
|
||||
ApplicationName = "Bts.DataStreamWebApp.Server",
|
||||
});
|
||||
ConfigureApp(builder.Configuration, builder.Environment.EnvironmentName);
|
||||
ConfigureServices(builder.Services, builder.Configuration);
|
||||
|
||||
var app = builder.Build();
|
||||
var wsOpts = new WebSocketOptions {
|
||||
KeepAliveInterval = TimeSpan.FromMinutes(2)
|
||||
};
|
||||
if (app.Environment.IsDevelopment()) {
|
||||
app.UseDirectoryBrowser("/browse");
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
app.UseHttpsRedirection();
|
||||
app.UseWebSockets(wsOpts);
|
||||
app.UseDefaultFiles();
|
||||
app.UseStaticFiles();
|
||||
app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
try {
|
||||
Console.Write($"Starting Application");
|
||||
app.Run();
|
||||
Console.Write($"Application exited gracefully.");
|
||||
} catch (Exception ex) {
|
||||
Console.Error.Write($"Application crashed: {ex}");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
static void ConfigureApp(ConfigurationManager configBuilder, string environment) {
|
||||
// We prefix appsettings with the exe name because multiple exes will usually be in the build dir
|
||||
// (this way, each exe can still load its own appsettings files from the current directory).
|
||||
var exeName = Assembly.GetCallingAssembly().GetName().Name;
|
||||
AddJsonFile($"{exeName}.appsettings.json");
|
||||
AddJsonFile($"{exeName}.appsettings.{environment}.json");
|
||||
|
||||
var cfg = configBuilder.GetSection("config")?.Value;
|
||||
if (!SetBasePath(cfg)) {
|
||||
AddJsonFile(cfg);
|
||||
}
|
||||
|
||||
bool SetBasePath(string? path) {
|
||||
if (!Directory.Exists(path)) {
|
||||
return false;
|
||||
}
|
||||
configBuilder.SetBasePath(path);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AddJsonFile(string? path) {
|
||||
if (!File.Exists(path)) {
|
||||
return false;
|
||||
}
|
||||
configBuilder.AddJsonFile(path);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
static void ConfigureServices(IServiceCollection services, IConfiguration config) {
|
||||
services.AddDirectoryBrowser()
|
||||
.AddControllers().Services
|
||||
.AddEndpointsApiExplorer()
|
||||
.AddSwaggerGen();
|
||||
services.AddSpaStaticFiles();
|
||||
services.AddSpark(config.GetSection("Spark"))
|
||||
.AddSparkApi(config.GetSection("SparkApi"))
|
||||
.AddMasterWorker(config.GetSection("MasterWorker"))
|
||||
.AddViewStreamDatabase()
|
||||
.AddPubSubClient(config.GetSection("PubSub"));
|
||||
}
|
||||
@@ -6,8 +6,9 @@
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "http://localhost:5000",
|
||||
"applicationUrl": "http://localhost:8080",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_HTTP_PORT": "8080",
|
||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy",
|
||||
}
|
||||
@@ -16,8 +17,10 @@
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5000;https://localhost:5001",
|
||||
"applicationUrl": "http://localhost:8080;https://localhost:8443",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_HTTP_PORT": "8080",
|
||||
"ASPNETCORE_HTTPS_PORT": "8443",
|
||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy",
|
||||
}
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
namespace Bts.DataStreamWebApp.Server.Services;
|
||||
|
||||
using BCG;
|
||||
using BCG.Utilities.General;
|
||||
|
||||
using bts;
|
||||
using bts.api.core;
|
||||
|
||||
using Bts.DataStreamExpressions;
|
||||
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
/// <summary>
|
||||
/// An IHostedService wrapper for ViewStream publishers. It provides a way for the Application to
|
||||
/// start/stop the view publishers.
|
||||
/// </summary>
|
||||
class DataStreamWebAppService : IHostedService {
|
||||
readonly DataStreamWebAppServerConfig config;
|
||||
readonly ViewStreamDatabase vsd;
|
||||
readonly TaskCompletionSource taskCompletionSource = new();
|
||||
readonly CancellationTokenSource cancellationTokenSource = new();
|
||||
|
||||
public DataStreamWebAppService(
|
||||
ViewStreamDatabase vsd,
|
||||
IOptions<DataStreamWebAppServerConfig> config
|
||||
) {
|
||||
this.vsd = vsd;
|
||||
this.config = config.Value;
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken) {
|
||||
// Task.Factory.StartNew(Run, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default);
|
||||
return Task.CompletedTask;
|
||||
|
||||
// void Run() {
|
||||
// Log.Gen.info("DataStreamWebAppService STARTED");
|
||||
// var defaultWaitTime = TimeSpan.FromMilliseconds(100);
|
||||
// var innerCancellationToken = cancellationTokenSource.Token;
|
||||
// var psConfig = config.PubSub ?? throw new InvalidOperationException("PubSub config is null");
|
||||
// while (!innerCancellationToken.IsCancellationRequested) {
|
||||
// vsd.doWork();
|
||||
// masterWorker.doWork();
|
||||
// Thread.Sleep(defaultWaitTime);
|
||||
// }
|
||||
// Log.Gen.info("DataStreamWebAppService STOPPED");
|
||||
// taskCompletionSource.SetResult();
|
||||
// }
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken) {
|
||||
Log.Gen.info("Stopping DataStreamWebAppService");
|
||||
cancellationTokenSource.Cancel();
|
||||
return Task.CompletedTask;
|
||||
// return taskCompletionSource.Task;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
{
|
||||
"Kestrel": {
|
||||
"Endpoints": {
|
||||
"Http": {
|
||||
"Url": "http://localhost:8080"
|
||||
},
|
||||
"Https": {
|
||||
"Url": "https://localhost:8443"
|
||||
}
|
||||
}
|
||||
},
|
||||
"PubSub": {
|
||||
"Routing": {
|
||||
"PublisherRoutes": [
|
||||
{
|
||||
"Name": "default",
|
||||
"ServerAddress": "bts-cloud://localhost:22019",
|
||||
"TagRegExp": ".*"
|
||||
}
|
||||
],
|
||||
"SubscriberRoutes": [
|
||||
{
|
||||
"Name": "default",
|
||||
"ServerAddress": "bts-cloud://localhost:22019",
|
||||
"TagRegExp": ".*"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"CannedQueries": [
|
||||
{
|
||||
"Name": "BBO",
|
||||
"Query": [
|
||||
"bbo"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Name": "Trades",
|
||||
"Query": [
|
||||
"timesales"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Name": "Instruments",
|
||||
"Query": [
|
||||
"instruments"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Name": "Books",
|
||||
"Query": [
|
||||
"books"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Name": "Benzinga News",
|
||||
"Query": [
|
||||
"benzinga_news"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
{
|
||||
"WebServer": {
|
||||
"ContentRootPath": "build/Bts.DataStreamWebApp.Client/production",
|
||||
"WebRootPath": "dist"
|
||||
"Spark": {
|
||||
"ConfigServer": "http://sparkd:8000/config"
|
||||
},
|
||||
"SparkApi": {
|
||||
"IsEnabled": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
{
|
||||
"MasterWorker": {
|
||||
"Interval": "00:00:00.1"
|
||||
},
|
||||
"ViewStreamDatabase": {
|
||||
"Interval": "00:00:00.1"
|
||||
},
|
||||
"Spark": {
|
||||
"ConfigServer": "http://172.30.2.181:8000/config"
|
||||
},
|
||||
"SparkApi": {
|
||||
"Credentials": {
|
||||
"User": "bts",
|
||||
"Password": ""
|
||||
},
|
||||
"EnableAdmin": true,
|
||||
"EnableOrders": true,
|
||||
"EnablePosition": true
|
||||
},
|
||||
"PubSub": {
|
||||
"HeartbeatInterval": 15000,
|
||||
"MissingHeartbeatsBeforeGc": 50,
|
||||
"ServerPort": 22019,
|
||||
"Routing": {
|
||||
"PublisherRoutes": [
|
||||
{
|
||||
"Name": "default",
|
||||
"ServerAddress": "bts-cloud://172.30.2.181:22019",
|
||||
"TagRegExp": ".*"
|
||||
}
|
||||
],
|
||||
"SubscriberRoutes": [
|
||||
{
|
||||
"Name": "default",
|
||||
"ServerAddress": "bts-cloud://172.30.2.181:22019",
|
||||
"TagRegExp": ".*"
|
||||
}
|
||||
]
|
||||
},
|
||||
"TagTypeToAssemblyMap": {
|
||||
"Entries": [
|
||||
{
|
||||
"HandlerClass": "BCG.PubSubServerTagHandler",
|
||||
"Assembly": "DataStreamCore.dll"
|
||||
}
|
||||
]
|
||||
},
|
||||
"TagHandlerFactory": {
|
||||
"Handlers": [
|
||||
{
|
||||
"TagType": "DataStream",
|
||||
"Assembly": "DataStreamCore",
|
||||
"Class": "bts.PubsubServerStreamTagHandler"
|
||||
},
|
||||
{
|
||||
"TagType": "System_Sub",
|
||||
"Assembly": "PubSub",
|
||||
"Class": "BCG.SystemSubscriptionMapPublisher"
|
||||
},
|
||||
{
|
||||
"TagType": "System_Stats",
|
||||
"Assembly": "PubSub",
|
||||
"Class": "BCG.SystemStatsPublisher"
|
||||
},
|
||||
{
|
||||
"TagType": ".*",
|
||||
"Assembly": "DataStreamCore",
|
||||
"Class": "bts.PubsubServerGenericDataHandler"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"Kestrel": {
|
||||
"Endpoints": {
|
||||
"Http": {
|
||||
"Url": "http://172.30.2.181:8080"
|
||||
},
|
||||
"Https": {
|
||||
"Url": "https://172.30.2.181:8443"
|
||||
}
|
||||
}
|
||||
},
|
||||
"CannedQueries": [
|
||||
{
|
||||
"Name": "BBO",
|
||||
"Query": [
|
||||
"bbo"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Name": "Trades",
|
||||
"Query": [
|
||||
"timesales"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Name": "Instruments",
|
||||
"Query": [
|
||||
"instruments"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Name": "Books",
|
||||
"Query": [
|
||||
"books"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Name": "Benzinga News",
|
||||
"Query": [
|
||||
"benzinga_news"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"CannedQueries": [
|
||||
{
|
||||
"Name": "BBO",
|
||||
"Query": [
|
||||
"bbo"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Name": "Trades",
|
||||
"Query": [
|
||||
"timesales"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Name": "Instruments",
|
||||
"Query": [
|
||||
"instruments"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Name": "Books",
|
||||
"Query": [
|
||||
"books"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Name": "Benzinga News",
|
||||
"Query": [
|
||||
"benzinga_news"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -6,35 +6,80 @@
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"Spark": {
|
||||
"ConfigServer": "http://localhost:8000/config"
|
||||
},
|
||||
"SparkdCredentials": {
|
||||
"User": "bts",
|
||||
"Password": ""
|
||||
"Kestrel": {
|
||||
"Endpoints": {
|
||||
"Http": {
|
||||
"Url": "http://0.0.0.0:8080"
|
||||
},
|
||||
"Https": {
|
||||
"Url": "https://0.0.0.0:8443"
|
||||
}
|
||||
}
|
||||
},
|
||||
"MasterWorker": {
|
||||
"Interval": "00:00:00.1"
|
||||
},
|
||||
"ViewStreamDatabase": {
|
||||
"Interval": "00:00:00.1"
|
||||
},
|
||||
"SparkApi": {
|
||||
"IsEnabled": false,
|
||||
"Credentials": {
|
||||
"User": "bts",
|
||||
"Password": ""
|
||||
}
|
||||
},
|
||||
"PubSub": {
|
||||
"HeartbeatInterval": 15000,
|
||||
"MissingHeartbeatsBeforeGc": 50,
|
||||
"ServerPort": 22019,
|
||||
"Routing": {
|
||||
"PublisherRoutes": [
|
||||
{
|
||||
"Name": "default",
|
||||
"ServerAddress": "bts-cloud://127.0.0.1:12345",
|
||||
"ServerAddress": "bts-cloud://pubsub:22019",
|
||||
"TagRegExp": ".*"
|
||||
}
|
||||
],
|
||||
"SubscriberRoutes": [
|
||||
{
|
||||
"Name": "default",
|
||||
"ServerAddress": "bts-cloud://127.0.0.1:12345",
|
||||
"ServerAddress": "bts-cloud://pubsub:22019",
|
||||
"TagRegExp": ".*"
|
||||
}
|
||||
]
|
||||
},
|
||||
"TagTypeToAssemblyMap": {
|
||||
"Entries": [
|
||||
{
|
||||
"HandlerClass": "BCG.PubSubServerTagHandler",
|
||||
"Assembly": "DataStreamCore.dll"
|
||||
}
|
||||
]
|
||||
},
|
||||
"TagHandlerFactory": {
|
||||
"Handlers": [
|
||||
{
|
||||
"TagType": "DataStream",
|
||||
"Assembly": "DataStreamCore",
|
||||
"Class": "bts.PubsubServerStreamTagHandler"
|
||||
},
|
||||
{
|
||||
"TagType": "System_Sub",
|
||||
"Assembly": "PubSub",
|
||||
"Class": "BCG.SystemSubscriptionMapPublisher"
|
||||
},
|
||||
{
|
||||
"TagType": "System_Stats",
|
||||
"Assembly": "PubSub",
|
||||
"Class": "BCG.SystemStatsPublisher"
|
||||
},
|
||||
{
|
||||
"TagType": ".*",
|
||||
"Assembly": "DataStreamCore",
|
||||
"Class": "bts.PubsubServerGenericDataHandler"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"ViewStreamDatabase": {
|
||||
"Interval": "00:00:01"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
FROM bluetradingsystems/linux_dotnet7
|
||||
|
||||
RUN dotnet dev-certs https --trust
|
||||
COPY --chown=bts:bts "bin" "bin"
|
||||
COPY --chown=bts:bts "webapp.spark.conf" ".local/share/DataStream/conf/spark.conf"
|
||||
WORKDIR "/home/bts/bin"
|
||||
@@ -0,0 +1,15 @@
|
||||
Logging {
|
||||
value {
|
||||
console {
|
||||
default_level: "Info"
|
||||
}
|
||||
syslog {
|
||||
default_level: "Info"
|
||||
}
|
||||
file {
|
||||
default_level: "Info"
|
||||
}
|
||||
initial_queue_size: 120001
|
||||
max_queue_growth: 4
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
namespace Bts.Extensions.DependencyInjection;
|
||||
|
||||
/// <summary>
|
||||
/// This interface provides a way to move dependencies outside of the constructor (and accept them
|
||||
/// via <see cref="IDependOn{T}.Reset(T?)"/> instead). It was designed to resolve circular
|
||||
/// dependency issues among startup services.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of dependency</typeparam>
|
||||
public interface IDependOn<T> {
|
||||
void Reset(T? value);
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
#nullable enable
|
||||
namespace Bts.Extensions.DependencyInjection;
|
||||
|
||||
public interface IDependOnKeyed<T> : IDependOn<T> {
|
||||
string Key { get; }
|
||||
}
|
||||
-130
@@ -1,130 +0,0 @@
|
||||
namespace Bts.Extensions.DependencyInjection;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
public static class ServiceCollectionExtensions {
|
||||
/// <summary>
|
||||
/// Adds a singleton service only if a service of type <typeparamref name="T"/> hasn't been added
|
||||
/// already.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="services"></param>
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection EnsureSingleton<T>(this IServiceCollection services) where T : class =>
|
||||
services.HasService<T>()
|
||||
? services
|
||||
: services.AddSingleton<T>();
|
||||
|
||||
/// <summary>
|
||||
/// Adds a singleton service only if a service of type <typeparamref name="T"/> hasn't been added
|
||||
/// already.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="services"></param>
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection EnsureSingleton<T>(this IServiceCollection services, Func<IServiceProvider, T> implementationFactory) where T : class =>
|
||||
services.HasService<T>()
|
||||
? services
|
||||
: services.AddSingleton(implementationFactory);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a singleton service only if a service of type <typeparamref name="T"/> hasn't been added
|
||||
/// already.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the service to add.</typeparam>
|
||||
/// <typeparam name="TImplementation">The type of the implementation to use.</typeparam>
|
||||
/// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param>
|
||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
||||
public static IServiceCollection EnsureSingleton<T, TImplementation>(this IServiceCollection services) where T : class where TImplementation : class, T =>
|
||||
services.HasService<T>()
|
||||
? services
|
||||
: services.AddSingleton<T, TImplementation>();
|
||||
|
||||
/// <summary>
|
||||
/// Adds a singleton service only if a service of type <typeparamref name="T"/> hasn't been added
|
||||
/// already.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the service to add.</typeparam>
|
||||
/// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param>
|
||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
||||
public static IServiceCollection EnsureSingleton<T>(this IServiceCollection services, Func<IServiceProvider, object?, T> implementationFactory) where T : class =>
|
||||
services.HasService<T>()
|
||||
? services
|
||||
: services.AddSingleton(implementationFactory);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a singleton service only if a service of type <typeparamref name="T"/> hasn't been added
|
||||
/// already.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the service to add.</typeparam>
|
||||
/// <typeparam name="TImplementation">The type of the implementation to use.</typeparam>
|
||||
/// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param>
|
||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
||||
public static IServiceCollection EnsureSingleton<T, TImplementation>(this IServiceCollection services, Func<IServiceProvider, TImplementation> implementationFactory) where T : class where TImplementation : class, T =>
|
||||
services.HasService<T>()
|
||||
? services
|
||||
: services.AddSingleton(implementationFactory);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a singleton service only if a service of type <typeparamref name="T"/> hasn't been added
|
||||
/// already.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the service to add.</typeparam>
|
||||
/// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param>
|
||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
||||
public static IServiceCollection EnsureKeyedSingleton<T>(this IServiceCollection services, object? key) where T : class =>
|
||||
services.HasKeyedService<T>(key)
|
||||
? services
|
||||
: services.AddKeyedSingleton<T>(key);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a singleton service only if a service of type <typeparamref name="T"/> hasn't been added
|
||||
/// already.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the service to add.</typeparam>
|
||||
/// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param>
|
||||
/// <param name="implementationFactory">The factory that creates the service.</param>
|
||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
||||
public static IServiceCollection EnsureKeyedSingleton<T>(this IServiceCollection services, object? key, Func<IServiceProvider, object?, T> implementationFactory) where T : class =>
|
||||
services.HasKeyedService<T>(key)
|
||||
? services
|
||||
: services.AddKeyedSingleton(key, implementationFactory);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a singleton service only if a service of type <typeparamref name="T"/> hasn't been added
|
||||
/// already.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the service to add.</typeparam>
|
||||
/// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param>
|
||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
||||
public static IServiceCollection EnsureHostedService<T>(this IServiceCollection services) where T : class, IHostedService =>
|
||||
services.HasService<T>()
|
||||
? services
|
||||
: services.AddHostedService<T>();
|
||||
|
||||
/// <summary>
|
||||
/// Adds a singleton service only if a service of type <typeparamref name="T"/> hasn't been added
|
||||
/// already.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the service to add.</typeparam>
|
||||
/// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param>
|
||||
/// <param name="implementationFactory">The factory that creates the service.</param>
|
||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
||||
public static IServiceCollection EnsureHostedService<T>(this IServiceCollection services, Func<IServiceProvider, T> implementationFactory) where T : class, IHostedService =>
|
||||
services.HasService<T>()
|
||||
? services
|
||||
: services.AddHostedService(implementationFactory);
|
||||
|
||||
public static bool HasService<T>(this IServiceCollection services) =>
|
||||
services.Any(s => s.ServiceType.IsAssignableTo(typeof(T)));
|
||||
|
||||
public static bool HasServiceImplementation<T, TImplementation>(this IServiceCollection services) =>
|
||||
services.Any(s => s.ServiceType.IsAssignableTo(typeof(T)) && s.ImplementationType == typeof(TImplementation));
|
||||
|
||||
public static bool HasKeyedService<T>(this IServiceCollection services, object? key) =>
|
||||
services.Any(s => Equals(s.ServiceKey, key) && s.ServiceType.IsAssignableTo(typeof(T)));
|
||||
}
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
@@ -7,7 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,59 @@
|
||||
namespace Bts.Extensions.Hosting;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
using System.Diagnostics;
|
||||
|
||||
public static class HostBuilderExtensions {
|
||||
public static IHostBuilder CreateBtsBuilder(string[] args) {
|
||||
// Obtain calling assembly name here, rather than in the lambda where it is actually needed,
|
||||
// because want the name of the assembly that called this function, not the assembly that will eventually invoke
|
||||
// the lambda...that will be the Microsoft.Extensions.Hosting assembly.
|
||||
// Get the name of the assembly that called this function. That will act as the "appsettings"
|
||||
// json file prefix
|
||||
var exeName = GetCallingAssemblyName();
|
||||
return Host.CreateDefaultBuilder(args)
|
||||
.ConfigureAppConfiguration((context, configBuilder) =>
|
||||
ConfigureApp(configBuilder, context.HostingEnvironment.EnvironmentName, exeName));
|
||||
}
|
||||
|
||||
public static void ConfigureApp(IConfigurationBuilder configBuilder, string? environment = null, string? prefix = null) {
|
||||
var baseFileName = prefix is null ? "appsettings" : $"{prefix}.appsettings";
|
||||
AddJsonFile($"{baseFileName}.json");
|
||||
if (environment is not null) {
|
||||
AddJsonFile($"{baseFileName}.{environment}.json");
|
||||
}
|
||||
|
||||
var cfg = configBuilder.Build().GetSection("config")?.Value;
|
||||
if (!SetBasePath(cfg)) {
|
||||
AddJsonFile(cfg);
|
||||
}
|
||||
|
||||
bool SetBasePath(string? path) {
|
||||
if (!Directory.Exists(path)) {
|
||||
return false;
|
||||
}
|
||||
configBuilder.SetBasePath(path);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AddJsonFile(string? path) {
|
||||
if (!File.Exists(path)) {
|
||||
return false;
|
||||
}
|
||||
configBuilder.AddJsonFile(path);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetCallingAssemblyName() =>
|
||||
new StackTrace()
|
||||
.GetFrame(2)
|
||||
?.GetMethod()
|
||||
?.Module
|
||||
?.Assembly
|
||||
?.GetName()
|
||||
?.Name
|
||||
?? throw new InvalidOperationException("Failed to determine name of calling assembly (calling method is null)");
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace Bts.Net;
|
||||
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
|
||||
/// <summary>
|
||||
/// Provides facilities to compare hosts for equality.
|
||||
/// <para>
|
||||
/// This class doesn't implement IEqualityComparer because a consistent hash code cannot be
|
||||
/// guarenteed for equivalent host strings. The equals impl relies on Dns.GetHostAddresses, which
|
||||
/// is non-determinstic (implementations that depends on mutable properties face a similar problem).
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public class HostComparer {
|
||||
public static bool Equals(string? x, string? y) {
|
||||
if (x is null) {
|
||||
return y is null;
|
||||
}
|
||||
if (y is null) {
|
||||
return false;
|
||||
}
|
||||
return Dns.GetHostAddresses(x).Intersect(
|
||||
Dns.GetHostAddresses(y), IpAddressComparer.Instance).Any();
|
||||
}
|
||||
|
||||
public static bool Equals(IPHostEntry x, IPHostEntry y) =>
|
||||
x.AddressList.Intersect(y.AddressList, IpAddressComparer.Instance).Any();
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
namespace Bts.Net;
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Net;
|
||||
|
||||
/// <summary>
|
||||
/// Compares ip addresses. Unlike the default comparer, v4 and equivalent v6 addresses are
|
||||
/// considered equal.
|
||||
/// </summary>
|
||||
public class IpAddressComparer : IEqualityComparer<IPAddress> {
|
||||
public static IEqualityComparer<IPAddress> Instance { get; } = new IpAddressComparer();
|
||||
|
||||
public bool Equals(IPAddress? x, IPAddress? y) {
|
||||
if (x is null) {
|
||||
return y is null;
|
||||
}
|
||||
if (y is null) {
|
||||
return false;
|
||||
}
|
||||
return x.Equals(y) ||
|
||||
(x.IsIPv4MappedToIPv6 && x.MapToIPv4().Equals(y)) ||
|
||||
(y.IsIPv4MappedToIPv6 && y.MapToIPv4().Equals(x));
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] IPAddress address) =>
|
||||
address.IsIPv4MappedToIPv6
|
||||
// Return consistent hash code for v4 and equivalent v6
|
||||
? address.MapToIPv4().GetHashCode()
|
||||
: address.GetHashCode();
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
namespace Bts.Net;
|
||||
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
public class IpHostEntryJsonConverter : JsonConverter<IPHostEntry> {
|
||||
public override IPHostEntry? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, IPHostEntry value, JsonSerializerOptions options) {
|
||||
writer.WriteStartObject();
|
||||
// HostName
|
||||
writer.WriteString(nameof(value.HostName), value.HostName);
|
||||
// Aliases
|
||||
writer.WritePropertyName("Aliases");
|
||||
writer.WriteStartArray();
|
||||
foreach (var alias in value.Aliases) {
|
||||
writer.WriteStringValue(alias);
|
||||
}
|
||||
writer.WriteEndArray();
|
||||
// Addresses
|
||||
writer.WritePropertyName("Addresses");
|
||||
writer.WriteStartArray();
|
||||
foreach (var address in value.AddressList) {
|
||||
writer.WriteStringValue(address.ToString());
|
||||
}
|
||||
writer.WriteEndArray();
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
namespace Bts.Net;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
/// <summary>
|
||||
/// This class seriailzes IpHostEntry to json (string). A common buffer is used to reduce memory
|
||||
/// allocations on repeated calls to <see cref="Serialize"/>. For that reason, this class is NOT
|
||||
/// thread safe.
|
||||
/// </summary>
|
||||
public class IpHostEntryJsonSerializer {
|
||||
readonly MemoryStream buffer = new();
|
||||
readonly IpHostEntryJsonConverter converter;
|
||||
|
||||
public IpHostEntryJsonSerializer(IpHostEntryJsonConverter? converter = null) =>
|
||||
this.converter = converter ?? new() { };
|
||||
|
||||
public string? Serialize(IPHostEntry dp, JsonSerializerOptions? opts = null) {
|
||||
opts ??= JsonSerializerOptions.Default;
|
||||
buffer.Position = 0;
|
||||
buffer.SetLength(0);
|
||||
using (var jsonWriter = new Utf8JsonWriter(buffer)) {
|
||||
converter.Write(jsonWriter, dp, opts);
|
||||
}
|
||||
var bytes = buffer.GetBuffer();
|
||||
var span = new ArraySegment<byte>(bytes, 0, (int)buffer.Length);
|
||||
return Encoding.UTF8.GetString(span);
|
||||
}
|
||||
|
||||
public void Serialize(IPHostEntry dp, Utf8JsonWriter jsonWriter, JsonSerializerOptions? opts = null) {
|
||||
opts ??= JsonSerializerOptions.Default;
|
||||
buffer.Position = 0;
|
||||
buffer.SetLength(0);
|
||||
converter.Write(jsonWriter, dp, opts);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
namespace Bts.Net;
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
public static partial class IpUtils {
|
||||
static readonly Regex ipv4Regex = new(string.Join('.', @"(((0|1)\d)|(2\d)|\d)?\d"));
|
||||
|
||||
// public static void ParseUri(string str, out string? scheme, out string? host, out string? port, out string? path, out string? queryParams) {
|
||||
// if (Uri.TryCreate(str, UriKind.Absolute, out var uri)) {
|
||||
// }
|
||||
// }
|
||||
|
||||
// public static bool AreEndpointsEqual(Uri? x, Uri? y) {
|
||||
// if (x is null) {
|
||||
// return y is null;
|
||||
// }
|
||||
// if (y is null) {
|
||||
// return false;
|
||||
// }
|
||||
// if (x.IsAbsoluteUri != y.IsAbsoluteUri) {
|
||||
// return false;
|
||||
// }
|
||||
// if (x.IsAbsoluteUri) {
|
||||
// if (x.Scheme != y.Scheme) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// string? xHost = null;
|
||||
// }
|
||||
|
||||
// static string ResolveHostIpv4(Uri uri) {
|
||||
// // switch (uri.HostNameType) {
|
||||
// // case UriHostNameType.IPv4:
|
||||
// // return uri.Host;
|
||||
// // case UriHostNameType.Dns:
|
||||
// // break;
|
||||
// // case UriHostNameType.IPv6:
|
||||
// // var addresses = Dns.GetHostAddresses(uri.Host);
|
||||
// // foreach (var address in addresses) {
|
||||
// // if (address.IsIPv4MappedToIPv6) {
|
||||
// // return address.MapToIPv4().Address;
|
||||
// // }
|
||||
// // }
|
||||
// // break;
|
||||
// // }
|
||||
// var hostAddresses = Dns.GetHostAddresses(uri.Host);
|
||||
// foreach (IPAddress address in hostAddresses) {
|
||||
// if (address.Equals(remoteEndPoint.Address) ||
|
||||
// (address.IsIPv4MappedToIPv6 && address.MapToIPv4().Equals(remoteEndPoint.Address)) ||
|
||||
// (remoteEndPoint.Address.IsIPv4MappedToIPv6 && remoteEndPoint.Address.MapToIPv4().Equals(address))) {
|
||||
// isMatch = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// public static bool AreEndpointsEqual(string? x, string? y) {
|
||||
// if (x == y) {
|
||||
// return true;
|
||||
// }
|
||||
// if (x is null) {
|
||||
// return y is null;
|
||||
// }
|
||||
// if (y is null) {
|
||||
// return false;
|
||||
// }
|
||||
// var xUri = new Uri(x);
|
||||
// var yUri = new Uri(y);
|
||||
// // return xUri.Equals(yUri);
|
||||
// }
|
||||
|
||||
public static bool IsIpv4(string host) {
|
||||
host = removeSchemaFromUrl(host);
|
||||
host = removePortFromUrl(host);
|
||||
return ipv4Regex.IsMatch(host);
|
||||
}
|
||||
|
||||
static string removeSchemaFromUrl(string url) {
|
||||
var i = url.IndexOf("://");
|
||||
return i < 0 ? url : url.Substring(i + 3);
|
||||
}
|
||||
|
||||
static string removePortFromUrl(string url) {
|
||||
var match = MyRegex().Match(url);
|
||||
return match.Success
|
||||
? string.Concat(url.AsSpan(0, match.Index), url.AsSpan(match.Index + match.Length))
|
||||
: url;
|
||||
}
|
||||
|
||||
[GeneratedRegex(":\\d{1,4}")]
|
||||
private static partial Regex MyRegex();
|
||||
}
|
||||
@@ -7,14 +7,11 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Google.Protobuf" Version="3.24.3" />
|
||||
<PackageReference Include="YaccLexTools" Version="1.2.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DataStreamCore\DataStreamCore.csproj" />
|
||||
<ProjectReference Include="..\ExpressionCore\ExpressionCore.csproj" />
|
||||
<ProjectReference Include="..\..\client\spark_core\spark_core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Label="ColumnMapExpression">
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
<ProjectReference Include="..\DataStreamCore\DataStreamCore.csproj" />
|
||||
<ProjectReference Include="..\DataStreamExpressions\DataStreamExpressions.csproj" />
|
||||
<ProjectReference Include="..\..\client\spark_core\spark_core.csproj" />
|
||||
<ProjectReference Include="..\Bts.Extensions.DependencyInjection\Bts.Extensions.DependencyInjection.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
namespace Bts.DataStream;
|
||||
|
||||
using BCG;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class BoundImportAttribute {
|
||||
|
||||
}
|
||||
|
||||
public class DataStreamActivator {
|
||||
Dictionary<string, Type> myTypeLookupTable = new();
|
||||
|
||||
/// <summary>
|
||||
/// Constructs and returns a ViewStream of type corresponding to the friendly name
|
||||
/// </summary>
|
||||
/// <param name="friendlyName">friendly primitive name </param>
|
||||
/// <param name="args">args can be null or an empty ICollection if the paramterless constructor
|
||||
/// is the desired one</param>
|
||||
/// <returns></returns>
|
||||
public ViewStream Activate(string friendlyName, IList<object>? args) {
|
||||
object[]? constructorArgs = null;
|
||||
if (args != null && args.Count > 0) {
|
||||
constructorArgs = new object[args.Count];
|
||||
args.CopyTo(constructorArgs, 0);
|
||||
}
|
||||
if (!myTypeLookupTable.TryGetValue(friendlyName, out var type)) {
|
||||
throw new ApplicationException(friendlyName + " is not the friendly name of any of the loaded types");
|
||||
}
|
||||
return constructorArgs is null ?
|
||||
Activator.CreateInstance(myTypeLookupTable[friendlyName] as Type) as ViewStream :
|
||||
Activator.CreateInstance(myTypeLookupTable[friendlyName] as Type, constructorArgs) as ViewStream;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace Bts.DataStream;
|
||||
|
||||
using BCG;
|
||||
|
||||
public interface IViewStreamFactory {
|
||||
public ViewStream? Create();
|
||||
}
|
||||
@@ -11,8 +11,11 @@ public class PandasScriptStream : ViewStream {
|
||||
public PandasScriptStream(ViewStream vs, string file)
|
||||
: this(vs, file, null) { }
|
||||
|
||||
public PandasScriptStream(ViewStream vs, string file, string? pythonExe) {
|
||||
mySetRealSource(AttachStream<PandasStream>(new(vs, readFile(), pythonExe)));
|
||||
public PandasScriptStream(ViewStream vs, string file, string? pythonExe)
|
||||
: this(vs, file, pythonExe, ViewStreamDatabase.instance) { }
|
||||
|
||||
public PandasScriptStream(ViewStream vs, string file, string? pythonExe, ViewStreamDatabase vsd) {
|
||||
mySetRealSource(new PandasStream(vs, readFile(), pythonExe, vsd));
|
||||
|
||||
string readFile() {
|
||||
try {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
namespace Bts.DataStream;
|
||||
|
||||
using BCG;
|
||||
using BCG.Extensions;
|
||||
using BCG.Utilities.General;
|
||||
|
||||
using bts;
|
||||
@@ -22,6 +23,7 @@ public class PandasStream : ViewStream, IWorker {
|
||||
readonly string inputFile = $"PandasStream_{Guid.NewGuid()}.csv";
|
||||
readonly string outputFile = $"PandasStream_{Guid.NewGuid()}.csv";
|
||||
readonly string pythonExe;
|
||||
readonly ViewStreamDatabase vsd;
|
||||
readonly CSVSaverStream inputCsvStream;
|
||||
readonly Lazy<string> pythonCode;
|
||||
IDictionary<int, IBlueRow>? lastRowMap = null;
|
||||
@@ -32,11 +34,12 @@ public class PandasStream : ViewStream, IWorker {
|
||||
IDisposable? dispose;
|
||||
|
||||
public PandasStream(ViewStream vs, string dataFrameExpression)
|
||||
: this(vs, dataFrameExpression, null) { }
|
||||
: this(vs, dataFrameExpression, null, ViewStreamDatabase.instance) { }
|
||||
|
||||
public PandasStream(ViewStream vs, string dataFrameExpression, string? pythonExe) {
|
||||
public PandasStream(ViewStream vs, string dataFrameExpression, string? pythonExe, ViewStreamDatabase vsd) {
|
||||
pythonExe ??= Environment.GetEnvironmentVariable("PYTHON_EXE") ?? @"C:\Users\johnc\GoogleDrive\Repos\bts\spark\.venv\Scripts\python.exe";
|
||||
this.pythonExe = pythonExe;
|
||||
this.vsd = vsd;
|
||||
// This should fire an update when it writes to the output file
|
||||
inputCsvStream = new CSVSaverStream(vs, inputFile, true, int.MaxValue, true);
|
||||
pythonCode = new(getPythonCode);
|
||||
@@ -56,7 +59,7 @@ import sys
|
||||
}
|
||||
|
||||
protected override void myOnFirstSubscriber() {
|
||||
base.myOnFirstSubscriber();
|
||||
vsd.addWorker(this);
|
||||
inputCsvStream.onChange += onInputChanged;
|
||||
this.dispose = Disposable.Create(dispose);
|
||||
|
||||
@@ -65,6 +68,7 @@ import sys
|
||||
|
||||
void dispose() {
|
||||
inputCsvStream.onChange -= onInputChanged;
|
||||
vsd.removeWorker(this);
|
||||
deleteFile(inputFile);
|
||||
deleteFile(outputFile);
|
||||
}
|
||||
@@ -81,10 +85,8 @@ import sys
|
||||
}
|
||||
}
|
||||
|
||||
protected override void myOnLastSubscriber() {
|
||||
base.myOnLastSubscriber();
|
||||
protected override void myOnLastSubscriber() =>
|
||||
Disposable.dispose(ref dispose);
|
||||
}
|
||||
|
||||
static void executePythonCode(string pythonCode, string? pythonExe = null) {
|
||||
pythonExe ??= "python";
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
using BCG.Utilities.General;
|
||||
|
||||
using Bts.PubSub;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
using System;
|
||||
|
||||
namespace BCG {
|
||||
public class TCPConnectionTestStream : ViewStream, IParameterizedWorker, ITCPConnectionHandler, ITCPMessageHandler {
|
||||
public class TCPConnectionTestStream : ViewStream, IWorker, ITCPConnectionHandler, ITCPMessageHandler {
|
||||
class State {
|
||||
public int n_sends = 0;
|
||||
public int n_recvs = 0;
|
||||
public int n_sends = 0;
|
||||
public int n_recvs = 0;
|
||||
}
|
||||
private readonly string _ip;
|
||||
private readonly int _port;
|
||||
private readonly ViewStreamDatabase _vsd;
|
||||
State _state = new State();
|
||||
private readonly int _msg_size;
|
||||
|
||||
@@ -21,12 +18,14 @@ namespace BCG {
|
||||
private TimeSpan _send_period;
|
||||
private ITCPConnection _connection = null;
|
||||
private byte[] _buff;
|
||||
WorkActivator workActivator;
|
||||
|
||||
public TCPConnectionTestStream(string ip, int port, int msg_size, int send_period_seconds) {
|
||||
|
||||
public TCPConnectionTestStream(string ip, int port, int msg_size, int send_period_seconds) :
|
||||
this(ip, port, msg_size, send_period_seconds, ViewStreamDatabase.instance) { }
|
||||
public TCPConnectionTestStream(string ip, int port, int msg_size, int send_period_seconds, ViewStreamDatabase vsd) {
|
||||
_ip = ip;
|
||||
_port = port;
|
||||
_msg_size = msg_size;
|
||||
_vsd = vsd;
|
||||
_schema = BlueDataUtility.form_schema("TCPClient",
|
||||
Tuple.Create("id", TypeCode.Int32),
|
||||
Tuple.Create("n_sends", TypeCode.UInt32),
|
||||
@@ -36,21 +35,16 @@ namespace BCG {
|
||||
for (int i = 0; i < _buff.Length; i++) {
|
||||
_buff[i] = (byte)i;
|
||||
}
|
||||
workActivator = new(this);
|
||||
}
|
||||
|
||||
TimeSpan IParameterizedWorker.Interval => _send_period;
|
||||
|
||||
protected override void OnServiceProvider(IServiceProvider serviceProvider) {
|
||||
workActivator.OnWorkScheduler(serviceProvider.GetRequiredService<IWorkScheduler>());
|
||||
}
|
||||
|
||||
protected override void myOnFirstSubscriber() {
|
||||
workActivator.Start();
|
||||
MasterWorker.getInstance(false).addWorker(this, _send_period);
|
||||
var server_rci = new RemoteConnectionInfo(_ip, _port);
|
||||
bts.AsyncTCPConnector_APM.connect_to(server_rci, this);
|
||||
}
|
||||
|
||||
protected override void myOnLastSubscriber() {
|
||||
workActivator.Stop();
|
||||
MasterWorker.getInstance(false).removeWorker(this);
|
||||
}
|
||||
|
||||
public void doWork() {
|
||||
@@ -66,20 +60,20 @@ namespace BCG {
|
||||
}
|
||||
|
||||
public void onConnection(ITCPConnection connection) {
|
||||
_connection = connection;
|
||||
_connection.register(this);
|
||||
_connection = connection;
|
||||
_connection.register(this);
|
||||
}
|
||||
public bool isDisposed { get; }
|
||||
|
||||
public void onData(RemoteMessage msg) {
|
||||
bts.Log.Gen.info($"TCPConnectionTestStream received msg: {msg}");
|
||||
_state.n_recvs++;
|
||||
bts.Log.Gen.info($"TCPConnectionTestStream received msg: {msg}");
|
||||
_state.n_recvs++;
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
workActivator.Stop();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+53
-38
@@ -1,15 +1,24 @@
|
||||
using Bts.DataStream;
|
||||
using Bts.DataStreamCore;
|
||||
using Bts.DataStreamExpressions;
|
||||
using Bts.PubSub;
|
||||
|
||||
using bts;
|
||||
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Bts.DataStreamExpressions;
|
||||
using bts;
|
||||
using Bts.DataStreamCore;
|
||||
using Bts.PubSub;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BCG {
|
||||
// listens to the requests posted on "cloud_streams" request table, and
|
||||
// if unfulfilled starts a ViewPubsliher
|
||||
public class RemoteQueryManager : IParameterizedWorker {
|
||||
public class RemoteQueryManager : IHostedService {
|
||||
public class StreamPubUnit {
|
||||
public string name;
|
||||
public string stream_expression;
|
||||
@@ -25,13 +34,12 @@ namespace BCG {
|
||||
view_publisher = view_publisher_;
|
||||
}
|
||||
}
|
||||
static ViewStream? build_stream(string stream_expression, PrimitiveManager primitiveManager, IServiceProvider serviceProvider)
|
||||
static ViewStream? build_stream(string stream_expression)
|
||||
{
|
||||
try
|
||||
{
|
||||
var exp = DataStreamExpressionsInterpreter.Evaluate(stream_expression);
|
||||
var rv = exp.getView(new Dictionary<string, StatementExpression>(0), primitiveManager);
|
||||
rv?.Reset(serviceProvider);
|
||||
var rv = exp.getView(new Dictionary<string, StatementExpression>(0));
|
||||
return rv;
|
||||
|
||||
} catch (Exception ex) {
|
||||
@@ -41,31 +49,46 @@ namespace BCG {
|
||||
}
|
||||
private IDictionary<string, StreamPubUnit>
|
||||
_stream_pub_map = new Dictionary<string, StreamPubUnit>();
|
||||
private ViewStream _stream = new TableStream("cloud_streams");
|
||||
readonly IPubTableBroker _broker;
|
||||
private readonly ManagedSubscriber _sub;
|
||||
readonly PrimitiveManager primitiveManager;
|
||||
readonly IServiceProvider serviceProvider;
|
||||
readonly IManagedSubscriber _sub;
|
||||
readonly object syncRoot = new();
|
||||
IDisposable? cloudStreamsSub;
|
||||
IDisposable? remoteRequestsSub;
|
||||
bool isDisposed;
|
||||
|
||||
public RemoteQueryManager(ManagedSubscriber sub, IPubTableBroker broker, PrimitiveManager primitiveManager, IServiceProvider serviceProvider) {
|
||||
_sub = sub;
|
||||
_broker = broker;
|
||||
this.primitiveManager = primitiveManager;
|
||||
this.serviceProvider = serviceProvider;
|
||||
_stream.onChange += _on_str;
|
||||
_sub.subscribe("RemoteRequest", (string tag, byte[] data) => {
|
||||
RemoteRequest req = RemoteRequest.construct_from_bytes(data);
|
||||
_spawn_remote_stream(req.published_table_name, req.stream_expression, false);
|
||||
});
|
||||
|
||||
public RemoteQueryManager(IManagedSubscriber managedSubscriber, IPubTableBroker pubTableBroker) {
|
||||
_sub = managedSubscriber;
|
||||
_broker = pubTableBroker;
|
||||
}
|
||||
|
||||
TimeSpan IParameterizedWorker.Interval => TimeSpan.FromSeconds(1);
|
||||
|
||||
private void _on_str(object obj)
|
||||
{
|
||||
if (obj is not DataPacket dp) {
|
||||
return;
|
||||
public Task StartAsync(CancellationToken cancellationToken) {
|
||||
lock (syncRoot) {
|
||||
Log.assert(!isDisposed);
|
||||
Log.isnull(cloudStreamsSub);
|
||||
Log.isnull(remoteRequestsSub);
|
||||
cloudStreamsSub = new TableStream("cloud_streams").AsObservable().Subscribe(_on_str);
|
||||
remoteRequestsSub = _sub.Observe("RemoteRequest").Subscribe(data => {
|
||||
RemoteRequest req = RemoteRequest.construct_from_bytes(data);
|
||||
_spawn_remote_stream(req.published_table_name, req.stream_expression, false);
|
||||
});
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken) {
|
||||
lock (syncRoot) {
|
||||
if (!isDisposed) {
|
||||
isDisposed = true;
|
||||
Disposable.dispose(ref cloudStreamsSub);
|
||||
Disposable.dispose(ref remoteRequestsSub);
|
||||
}
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private void _on_str(DataPacket dp)
|
||||
{
|
||||
foreach (IBlueRow r in dp.newRows)
|
||||
{
|
||||
string name = r.get<string>("name");
|
||||
@@ -79,11 +102,7 @@ namespace BCG {
|
||||
|
||||
private void _spawn_remote_stream(string name, string stream_expression, bool persist) {
|
||||
bts.Log.Gen.info($"CloudStreamManager.assign name: {name} stream_expression: {stream_expression}");
|
||||
var stream = build_stream(stream_expression, primitiveManager, serviceProvider);
|
||||
if (stream is null) {
|
||||
Log.Gen.error($"Failed to spawn remote stream. stream_expression: {stream_expression}");
|
||||
return;
|
||||
}
|
||||
ViewStream stream = build_stream(stream_expression);
|
||||
_expose_to_ws(name, stream);
|
||||
if (persist) {
|
||||
stream = new PersistorStream(stream, name, "C:\\Temp\\", 1000000); // 10MBs
|
||||
@@ -96,9 +115,5 @@ namespace BCG {
|
||||
private void _expose_to_ws(string name, ViewStream stream) {
|
||||
// TODO: john
|
||||
}
|
||||
|
||||
public void doWork() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using bts;
|
||||
using BCG;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using bts;
|
||||
|
||||
using System;
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace BCG {
|
||||
[DataStreamUserRespresentation("remoteQuery")]
|
||||
public class RemoteQueryStream : ViewStream {
|
||||
private readonly string _name, _stream_exp;
|
||||
IPublisherCore? _publisher_core_backing;
|
||||
private PublisherCore _publisher_core = new PublisherCore();
|
||||
private ViewStream _source_str;
|
||||
|
||||
public RemoteQueryStream(params string[] lines) {
|
||||
@@ -20,14 +20,7 @@ namespace BCG {
|
||||
|
||||
}
|
||||
|
||||
IPublisherCore? _publisher_core =>
|
||||
_publisher_core_backing ??= ServiceProvider?.GetService<IPublisherCore>();
|
||||
|
||||
protected override void myOnFirstSubscriber() {
|
||||
if (_publisher_core is null) {
|
||||
throw new InvalidOperationException(
|
||||
"Unable to initialize PublisherStream because PublisherCore is null");
|
||||
}
|
||||
RemoteRequest rem_req = new RemoteRequest(_stream_exp, _name);
|
||||
byte[] rem_req_bytes = rem_req.serialize();
|
||||
_publisher_core.publish("System", "RemoteRequest", rem_req_bytes);
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace BCG {
|
||||
|
||||
public AddColumnsStream(ViewStream vs, string col_def) {
|
||||
_new_col = parse_exp(col_def);
|
||||
ViewStream rs = AttachStream(new MapStream(vs, _get_schema, _map));
|
||||
ViewStream rs = new MapStream(vs, (IBlueTableSchema s) => _get_schema(s), (IBlueRow r) => _map(r));
|
||||
mySetRealSource(rs);
|
||||
}
|
||||
|
||||
|
||||
+5
-9
@@ -91,14 +91,10 @@ namespace BCG
|
||||
}
|
||||
_increment_values = increment_values_del;
|
||||
_get_column_prefix = get_column_prefix_del;
|
||||
if(only_fire_once) {
|
||||
ViewStream vs = AttachStream(new OnlyFireOnceStream(stream));
|
||||
vs = AttachStream(new NonIncGroupByStream(vs, this));
|
||||
mySetRealSource(vs);
|
||||
} else {
|
||||
ViewStream vs = AttachStream(new NonIncGroupByStream(stream, this));
|
||||
mySetRealSource(vs);
|
||||
}
|
||||
if(only_fire_once)
|
||||
mySetRealSource(new NonIncGroupByStream(new OnlyFireOnceStream(stream), this));
|
||||
else
|
||||
mySetRealSource(new NonIncGroupByStream(stream, this));
|
||||
}
|
||||
|
||||
private void _set_schema(List<string> tc_prefixes, Pair<string, Type>[] group_by_col_info, string table_name)
|
||||
@@ -245,4 +241,4 @@ namespace BCG
|
||||
return values;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ namespace BCG
|
||||
public CaseChangeStream(ViewStream input, bool toUpper, params string[] columnsToChangeCase)
|
||||
{
|
||||
myCaseChangingColumns = columnsToChangeCase;
|
||||
mySetRealSource(AttachStream(new SuperMapStream(input, this)));
|
||||
mySetRealSource(new SuperMapStream(input, this));
|
||||
myIsUpperCase = toUpper;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -32,10 +32,10 @@ namespace BCG
|
||||
|
||||
{
|
||||
mySetRealSource (
|
||||
AttachStream(new MapStream (sourceStream,
|
||||
new MapStream (sourceStream,
|
||||
isConcatenatedDataConfined ? new ConcatenateColumnsMapperForSameDataSet (columnDefs) :
|
||||
new ConcatenateColumnsMapper (columnDefs)
|
||||
))
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace BCG
|
||||
public AverageCollectorStream(ViewStream stream, params string[] columnsToAverage)
|
||||
{
|
||||
myAveragingColumns = columnsToAverage;
|
||||
mySetRealSource(AttachStream(new CrushingCollectorStream(stream, this)));
|
||||
mySetRealSource(new CrushingCollectorStream(stream, this));
|
||||
}
|
||||
|
||||
private string[] myAveragingColumns;
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
using bts;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace BCG
|
||||
{
|
||||
namespace BCG {
|
||||
/// <summary>
|
||||
/// Provides a stream that with distinct rows with respect to the columns
|
||||
/// the user specifies in the argument
|
||||
/// </summary>
|
||||
[DataStreamUserRespresentation ("distinct")]
|
||||
public class DistinctRowStream : ViewStream
|
||||
{
|
||||
public DistinctRowStream (ViewStream stream, params string[] cols)
|
||||
{
|
||||
ArrayList groupByCols = new ArrayList ();
|
||||
foreach (string col in cols)
|
||||
foreach (string c in col.Split (' '))
|
||||
groupByCols.Add (c);
|
||||
mySetRealSource (AttachStream(new GroupByStream (stream,
|
||||
new DistinctRowEvaluator (groupByCols.ToArray (typeof(string)) as string[]), false)));
|
||||
[DataStreamUserRespresentation("distinct")]
|
||||
public class DistinctRowStream : ViewStream {
|
||||
public DistinctRowStream(ViewStream stream, params string[] cols) {
|
||||
var g_by_eval = new DistinctRowEvaluator(cols);
|
||||
ViewStream r = new GroupByStream(stream, g_by_eval);
|
||||
var proj_exp = String.Empty;
|
||||
foreach (var c in cols)
|
||||
proj_exp += $"{c} ";
|
||||
proj_exp = proj_exp.Trim();
|
||||
r = new NewProjectStream(r, proj_exp);
|
||||
mySetRealSource(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loaded 100 of 2315 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user