From fe5ba013a0b9ba133c736ac17896253953106810 Mon Sep 17 00:00:00 2001 From: qinyouzeng Date: Thu, 24 Sep 2026 09:58:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20tsc=20=E6=B7=BB=E5=8A=A0=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E4=BE=9D=E8=B5=96=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Model/ServiceTopologiesDto.cs | 8 +++++ .../Service/ITopologyService.cs | 6 ++++ .../Service/DynamicRoleService.cs | 2 +- .../ServiceCollectionExtensions.cs | 14 ++++----- .../Service/TopologyService.cs | 16 ++++++++++ .../TscClient.cs | 5 +++- .../Service/DynamicRoleService.cs | 2 +- .../Service/TopologyService.cs | 16 ++++++++++ .../Masa.Contrib.StackSdks.Tsc/TscClient.cs | 7 +++-- .../MasaStackConfigTest.cs | 30 +++++++++---------- .../Extensions/ServiceExtensionsTests.cs | 6 ++-- 11 files changed, 81 insertions(+), 31 deletions(-) create mode 100644 src/BuildingBlocks/Tsc/Masa.BuildingBlocks.StackSdk.Tsc/Model/ServiceTopologiesDto.cs create mode 100644 src/BuildingBlocks/Tsc/Masa.BuildingBlocks.StackSdk.Tsc/Service/ITopologyService.cs create mode 100644 src/Contrib.Wasm/Masa.Contrib.StackSdks.Tsc.Wasm/Service/TopologyService.cs create mode 100644 src/Contrib/Masa.Contrib.StackSdks.Tsc/Service/TopologyService.cs diff --git a/src/BuildingBlocks/Tsc/Masa.BuildingBlocks.StackSdk.Tsc/Model/ServiceTopologiesDto.cs b/src/BuildingBlocks/Tsc/Masa.BuildingBlocks.StackSdk.Tsc/Model/ServiceTopologiesDto.cs new file mode 100644 index 0000000..a7c128d --- /dev/null +++ b/src/BuildingBlocks/Tsc/Masa.BuildingBlocks.StackSdk.Tsc/Model/ServiceTopologiesDto.cs @@ -0,0 +1,8 @@ +namespace Masa.BuildingBlocks.StackSdks.Tsc.Model; + +public class ServiceTopologiesDto +{ + public string Service { get; set; } = default!; + + public IEnumerable Servers { get; set; } = default!; +} diff --git a/src/BuildingBlocks/Tsc/Masa.BuildingBlocks.StackSdk.Tsc/Service/ITopologyService.cs b/src/BuildingBlocks/Tsc/Masa.BuildingBlocks.StackSdk.Tsc/Service/ITopologyService.cs new file mode 100644 index 0000000..06c3c5b --- /dev/null +++ b/src/BuildingBlocks/Tsc/Masa.BuildingBlocks.StackSdk.Tsc/Service/ITopologyService.cs @@ -0,0 +1,6 @@ +namespace Masa.BuildingBlocks.StackSdks.Tsc.Service; + +public interface ITopologyService +{ + public Task> GetServicesAsync(string? service = default); +} \ No newline at end of file diff --git a/src/Contrib.Wasm/Masa.Contrib.StackSdks.Auth.Wasm/Service/DynamicRoleService.cs b/src/Contrib.Wasm/Masa.Contrib.StackSdks.Auth.Wasm/Service/DynamicRoleService.cs index ea71784..87c1ac4 100644 --- a/src/Contrib.Wasm/Masa.Contrib.StackSdks.Auth.Wasm/Service/DynamicRoleService.cs +++ b/src/Contrib.Wasm/Masa.Contrib.StackSdks.Auth.Wasm/Service/DynamicRoleService.cs @@ -47,6 +47,6 @@ public async Task DeleteAsync(Guid id) public Task> HasAsync(params Guid[] roleIds) { var requestUri = $"{_party}/has"; - return _caller.PostAsync>(requestUri, new { roleIds }); + return _caller.PostAsync>(requestUri, new { roleIds })!; } } \ No newline at end of file diff --git a/src/Contrib.Wasm/Masa.Contrib.StackSdks.Config.Wasm/ServiceCollectionExtensions.cs b/src/Contrib.Wasm/Masa.Contrib.StackSdks.Config.Wasm/ServiceCollectionExtensions.cs index ac211ec..ba36430 100644 --- a/src/Contrib.Wasm/Masa.Contrib.StackSdks.Config.Wasm/ServiceCollectionExtensions.cs +++ b/src/Contrib.Wasm/Masa.Contrib.StackSdks.Config.Wasm/ServiceCollectionExtensions.cs @@ -40,14 +40,14 @@ private static Dictionary GetConfigMap(IConfiguration configurat { var configs = new Dictionary() { - { MasaStackConfigConstant.VERSION, configuration.GetValue(MasaStackConfigConstant.VERSION) }, + { MasaStackConfigConstant.VERSION, configuration.GetValue(MasaStackConfigConstant.VERSION)! }, { MasaStackConfigConstant.IS_DEMO, configuration.GetValue(MasaStackConfigConstant.IS_DEMO).ToString() }, - { MasaStackConfigConstant.DOMAIN_NAME, configuration.GetValue(MasaStackConfigConstant.DOMAIN_NAME) }, - { MasaStackConfigConstant.NAMESPACE, configuration.GetValue(MasaStackConfigConstant.NAMESPACE) }, - { MasaStackConfigConstant.CLUSTER, configuration.GetValue(MasaStackConfigConstant.CLUSTER) }, - { MasaStackConfigConstant.OTLP_URL, configuration.GetValue(MasaStackConfigConstant.OTLP_URL) }, - { MasaStackConfigConstant.MASA_STACK, configuration.GetValue(MasaStackConfigConstant.MASA_STACK) }, - { MasaStackConfigConstant.ENVIRONMENT, configuration.GetValue(MasaStackConfigConstant.ENVIRONMENT) } + { MasaStackConfigConstant.DOMAIN_NAME, configuration.GetValue(MasaStackConfigConstant.DOMAIN_NAME)! }, + { MasaStackConfigConstant.NAMESPACE, configuration.GetValue(MasaStackConfigConstant.NAMESPACE)! }, + { MasaStackConfigConstant.CLUSTER, configuration.GetValue(MasaStackConfigConstant.CLUSTER)! }, + { MasaStackConfigConstant.OTLP_URL, configuration.GetValue(MasaStackConfigConstant.OTLP_URL)! }, + { MasaStackConfigConstant.MASA_STACK, configuration.GetValue(MasaStackConfigConstant.MASA_STACK)! }, + { MasaStackConfigConstant.ENVIRONMENT, configuration.GetValue(MasaStackConfigConstant.ENVIRONMENT)! } }; return configs; } diff --git a/src/Contrib.Wasm/Masa.Contrib.StackSdks.Tsc.Wasm/Service/TopologyService.cs b/src/Contrib.Wasm/Masa.Contrib.StackSdks.Tsc.Wasm/Service/TopologyService.cs new file mode 100644 index 0000000..bccc5ce --- /dev/null +++ b/src/Contrib.Wasm/Masa.Contrib.StackSdks.Tsc.Wasm/Service/TopologyService.cs @@ -0,0 +1,16 @@ +namespace Masa.Contrib.StackSdks.Tsc.Service; + +internal class TopologyService : ITopologyService +{ + readonly ICaller _caller; + + public TopologyService(ICaller caller) + { + _caller = caller; + } + + public Task> GetServicesAsync(string? service = null) + { + return _caller.GetAsync>("api/topology/services", new { service })!; + } +} diff --git a/src/Contrib.Wasm/Masa.Contrib.StackSdks.Tsc.Wasm/TscClient.cs b/src/Contrib.Wasm/Masa.Contrib.StackSdks.Tsc.Wasm/TscClient.cs index fc9940e..15d857d 100644 --- a/src/Contrib.Wasm/Masa.Contrib.StackSdks.Tsc.Wasm/TscClient.cs +++ b/src/Contrib.Wasm/Masa.Contrib.StackSdks.Tsc.Wasm/TscClient.cs @@ -6,12 +6,13 @@ namespace Masa.Contrib.StackSdks.Tsc; internal class TscClient : ITscClient { - public TscClient(ICaller caller) + internal TscClient(ICaller caller) { LogService = new LogService(caller); MetricService = new MetricService(caller); TraceService = new TraceService(caller); ApmService = new ApmService(caller); + TopologyService = new TopologyService(caller); } public ILogService LogService { get; } @@ -21,4 +22,6 @@ public TscClient(ICaller caller) public ITraceService TraceService { get; } public IApmService ApmService { get; } + + public ITopologyService TopologyService { get; } } diff --git a/src/Contrib/Masa.Contrib.StackSdks.Auth/Service/DynamicRoleService.cs b/src/Contrib/Masa.Contrib.StackSdks.Auth/Service/DynamicRoleService.cs index e124e84..aa2e9b8 100644 --- a/src/Contrib/Masa.Contrib.StackSdks.Auth/Service/DynamicRoleService.cs +++ b/src/Contrib/Masa.Contrib.StackSdks.Auth/Service/DynamicRoleService.cs @@ -47,6 +47,6 @@ public async Task DeleteAsync(Guid id) public Task> HasAsync(params Guid[] roleIds) { var requestUri = $"{_party}/has"; - return _caller.PostAsync>(requestUri, new { roleIds }); + return _caller.PostAsync>(requestUri, new { roleIds })!; } } diff --git a/src/Contrib/Masa.Contrib.StackSdks.Tsc/Service/TopologyService.cs b/src/Contrib/Masa.Contrib.StackSdks.Tsc/Service/TopologyService.cs new file mode 100644 index 0000000..bccc5ce --- /dev/null +++ b/src/Contrib/Masa.Contrib.StackSdks.Tsc/Service/TopologyService.cs @@ -0,0 +1,16 @@ +namespace Masa.Contrib.StackSdks.Tsc.Service; + +internal class TopologyService : ITopologyService +{ + readonly ICaller _caller; + + public TopologyService(ICaller caller) + { + _caller = caller; + } + + public Task> GetServicesAsync(string? service = null) + { + return _caller.GetAsync>("api/topology/services", new { service })!; + } +} diff --git a/src/Contrib/Masa.Contrib.StackSdks.Tsc/TscClient.cs b/src/Contrib/Masa.Contrib.StackSdks.Tsc/TscClient.cs index fc9940e..431d5f0 100644 --- a/src/Contrib/Masa.Contrib.StackSdks.Tsc/TscClient.cs +++ b/src/Contrib/Masa.Contrib.StackSdks.Tsc/TscClient.cs @@ -6,12 +6,13 @@ namespace Masa.Contrib.StackSdks.Tsc; internal class TscClient : ITscClient { - public TscClient(ICaller caller) + internal TscClient(ICaller caller) { LogService = new LogService(caller); MetricService = new MetricService(caller); TraceService = new TraceService(caller); ApmService = new ApmService(caller); + TopologyService = new TopologyService(caller); } public ILogService LogService { get; } @@ -21,4 +22,6 @@ public TscClient(ICaller caller) public ITraceService TraceService { get; } public IApmService ApmService { get; } -} + + public ITopologyService TopologyService { get; } +} \ No newline at end of file diff --git a/src/Contrib/Tests/Masa.Contrib.StackSdks.Config.Tests/MasaStackConfigTest.cs b/src/Contrib/Tests/Masa.Contrib.StackSdks.Config.Tests/MasaStackConfigTest.cs index 62aa0e2..da582f5 100644 --- a/src/Contrib/Tests/Masa.Contrib.StackSdks.Config.Tests/MasaStackConfigTest.cs +++ b/src/Contrib/Tests/Masa.Contrib.StackSdks.Config.Tests/MasaStackConfigTest.cs @@ -19,21 +19,21 @@ public void Initialize() var configuration = builder.Configuration.AddJsonFile("appsettings.json", true, true).Build(); _config = new Dictionary() { - { MasaStackConfigConstant.VERSION, configuration.GetValue(MasaStackConfigConstant.VERSION) }, + { MasaStackConfigConstant.VERSION, configuration.GetValue(MasaStackConfigConstant.VERSION)! }, { MasaStackConfigConstant.IS_DEMO, configuration.GetValue(MasaStackConfigConstant.IS_DEMO).ToString() }, - { MasaStackConfigConstant.DOMAIN_NAME, configuration.GetValue(MasaStackConfigConstant.DOMAIN_NAME) }, - { MasaStackConfigConstant.NAMESPACE, configuration.GetValue(MasaStackConfigConstant.NAMESPACE) }, - { MasaStackConfigConstant.CLUSTER, configuration.GetValue(MasaStackConfigConstant.CLUSTER) }, - { MasaStackConfigConstant.OTLP_URL, configuration.GetValue(MasaStackConfigConstant.OTLP_URL) }, - { MasaStackConfigConstant.REDIS, configuration.GetValue(MasaStackConfigConstant.REDIS) }, - { MasaStackConfigConstant.CONNECTIONSTRING, configuration.GetValue(MasaStackConfigConstant.CONNECTIONSTRING) }, - { MasaStackConfigConstant.MASA_STACK, configuration.GetValue(MasaStackConfigConstant.MASA_STACK) }, - { MasaStackConfigConstant.ELASTIC, configuration.GetValue(MasaStackConfigConstant.ELASTIC) }, - { MasaStackConfigConstant.ENVIRONMENT, configuration.GetValue(MasaStackConfigConstant.ENVIRONMENT) }, - { MasaStackConfigConstant.ADMIN_PWD, configuration.GetValue(MasaStackConfigConstant.ADMIN_PWD) }, - { MasaStackConfigConstant.DCC_SECRET, configuration.GetValue(MasaStackConfigConstant.DCC_SECRET) }, - { MasaStackConfigConstant.DCC_STORE_NAME, configuration.GetValue(MasaStackConfigConstant.DCC_STORE_NAME) }, - { MasaStackConfigConstant.SUFFIX_IDENTITY, configuration.GetValue(MasaStackConfigConstant.SUFFIX_IDENTITY) } + { MasaStackConfigConstant.DOMAIN_NAME, configuration.GetValue(MasaStackConfigConstant.DOMAIN_NAME)! }, + { MasaStackConfigConstant.NAMESPACE, configuration.GetValue(MasaStackConfigConstant.NAMESPACE)! }, + { MasaStackConfigConstant.CLUSTER, configuration.GetValue(MasaStackConfigConstant.CLUSTER)! }, + { MasaStackConfigConstant.OTLP_URL, configuration.GetValue(MasaStackConfigConstant.OTLP_URL)! }, + { MasaStackConfigConstant.REDIS, configuration.GetValue(MasaStackConfigConstant.REDIS)! }, + { MasaStackConfigConstant.CONNECTIONSTRING, configuration.GetValue(MasaStackConfigConstant.CONNECTIONSTRING)! }, + { MasaStackConfigConstant.MASA_STACK, configuration.GetValue(MasaStackConfigConstant.MASA_STACK)! }, + { MasaStackConfigConstant.ELASTIC, configuration.GetValue(MasaStackConfigConstant.ELASTIC)! }, + { MasaStackConfigConstant.ENVIRONMENT, configuration.GetValue(MasaStackConfigConstant.ENVIRONMENT)! }, + { MasaStackConfigConstant.ADMIN_PWD, configuration.GetValue(MasaStackConfigConstant.ADMIN_PWD)! }, + { MasaStackConfigConstant.DCC_SECRET, configuration.GetValue(MasaStackConfigConstant.DCC_SECRET)! }, + { MasaStackConfigConstant.DCC_STORE_NAME, configuration.GetValue(MasaStackConfigConstant.DCC_STORE_NAME)! }, + { MasaStackConfigConstant.SUFFIX_IDENTITY, configuration.GetValue(MasaStackConfigConstant.SUFFIX_IDENTITY)! } }; Mock dccClient = new(); @@ -235,6 +235,6 @@ public void TestHasAlert() { var result = _stackConfig.HasAlert(); - Assert.AreEqual(true, result); + Assert.IsTrue(result); } } diff --git a/src/Contrib/Tests/Masa.Contrib.StackSdks.Tsc.OpenTelemetry.Tests/Extensions/ServiceExtensionsTests.cs b/src/Contrib/Tests/Masa.Contrib.StackSdks.Tsc.OpenTelemetry.Tests/Extensions/ServiceExtensionsTests.cs index bc28d91..95afb94 100644 --- a/src/Contrib/Tests/Masa.Contrib.StackSdks.Tsc.OpenTelemetry.Tests/Extensions/ServiceExtensionsTests.cs +++ b/src/Contrib/Tests/Masa.Contrib.StackSdks.Tsc.OpenTelemetry.Tests/Extensions/ServiceExtensionsTests.cs @@ -29,8 +29,7 @@ public void FuncTest() { ServiceName = "test-app" }, () => ObservableHelper.OTLPURL, true); - }); - Assert.IsTrue(true); + }); } [TestMethod] @@ -42,7 +41,6 @@ public void OptionsTest() { ServiceName = "test-app" }, ObservableHelper.OTLPURL, true); - }); - Assert.IsTrue(true); + }); } }