Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/Add the get configuration api interface #634

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the Apache License. See LICENSE.txt in the project root for license information.

namespace Masa.Dcc.Service.Admin.Application.App.Queries
{
public record class ConfigObjectsByDynamicQuery(string environment, string cluster, string appId,
List<string>? configObjects) : Query<Dictionary<string, PublishReleaseModel>>
{
public override Dictionary<string, PublishReleaseModel> Result { get; set; }
}
}
6 changes: 6 additions & 0 deletions src/Services/Masa.Dcc.Service/Application/App/QueryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,5 +269,11 @@ public async Task RefreshConfigObjectToRedisAsync(RefreshConfigObjectToRedisQuer
{
query.Result = await _configObjectDomainService.RefreshConfigObjectToRedisAsync();
}

[EventHandler]
public async Task GetConfigObjectsAsync(ConfigObjectsByDynamicQuery query)
{
query.Result = await _configObjectDomainService.GetConfigObjectsAsync(query.environment, query.cluster, query.appId, query.configObjects);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the Apache License. See LICENSE.txt in the project root for license information.

using Masa.BuildingBlocks.Configuration;
using Masa.BuildingBlocks.Data;
using Masa.BuildingBlocks.StackSdks.Dcc.Contracts.Enum;
using Masa.Dcc.Service.Admin.Domain.App.Aggregates;

namespace Masa.Dcc.Service.Admin.Domain.App.Services
{
public class ConfigObjectDomainService : DomainService
Expand Down Expand Up @@ -636,5 +641,43 @@ public async Task<string> RefreshConfigObjectToRedisAsync()

return "success";
}

public async Task<Dictionary<string, PublishReleaseModel>> GetConfigObjectsAsync(string environmentName,
string clusterName, string appId, List<string>? configObjects)
{
var resultDic = new Dictionary<string, PublishReleaseModel>();

var envs = await _pmClient.EnvironmentService.GetListAsync();
var env = envs.FirstOrDefault(e => e.Name.ToLower() == environmentName.ToLower()) ?? throw new UserFriendlyException("Environment does not exist");
var clusters = await _pmClient.ClusterService.GetListByEnvIdAsync(env.Id);
var cluster = clusters.FirstOrDefault(c => c.Name.ToLower() == clusterName.ToLower()) ?? throw new UserFriendlyException("Cluster does not exist");
var apps = await _pmClient.AppService.GetListAsync();
var app = apps.FirstOrDefault(apps => apps.Identity.ToLower() == appId.ToLower()) ?? throw new UserFriendlyException("AppId does not exist");

Expression<Func<ConfigObject, bool>> configObjectFilter = configObject =>
configObject.AppConfigObject.EnvironmentClusterId == cluster.Id &&
configObject.AppConfigObject.AppId == app.Id &&
((configObjects == null || configObjects.Count == 0) || configObjects.Contains(configObject.Name));
var configObjectList = await _configObjectRepository.GetListAsync(configObjectFilter);
if (configObjects == null || configObjects.Count == 0)
{
var configObjectPublicList = await _configObjectRepository.GetListAsync(configObject => configObject.PublicConfigObject.EnvironmentClusterId == cluster.Id);
configObjectList = configObjectList.Union(configObjectPublicList);
}

foreach (var configObject in configObjectList)
{
var key = $"{configObject.Name}".ToLower();//{environmentName}-{clusterName}-{appId}-
if (resultDic.ContainsKey(key)) continue;
resultDic.Add(key, new PublishReleaseModel()
{
Encryption = configObject.Encryption,
FormatLabelCode = configObject.FormatLabelCode,
Content = configObject.Content,
});
}

return resultDic;
}
}
}
4 changes: 2 additions & 2 deletions src/Services/Masa.Dcc.Service/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"TLS_NAME": "",
"CLUSTER": "Default",
"OTLP_URL": "https://otel-collector.masastack:9013",
"REDIS": "{\"RedisHost\": \"10.130.0.235\", \"RedisPort\": 24615, \"RedisDb\": 0,\"RedisPassword\": \"Hzss@123\"}",
"CONNECTIONSTRING": "{\"Server\": \"10.130.0.235\", \"Port\": 24878,\"Database\":\"pm-dev\",\"UserId\": \"ss\",\"Password\":\"Hzss@123\"}",
"REDIS": "{\"RedisHost\": \"10.130.0.19\", \"RedisPort\": 2135, \"RedisDb\": 0,\"RedisPassword\": \"Hzss@123\"}",
"CONNECTIONSTRING": "{\"Server\": \"10.130.0.19\", \"Port\": 2415,\"Database\":\"pm-dev\",\"UserId\": \"ss\",\"Password\":\"Hzss@123\"}",
"MASA_STACK": "[{\"id\":\"pm\",\"service\":{\"id\":\"pm-service-dev\",\"domain\":\"http://pm-service-dev.masastack.com\"},\"web\":{\"id\":\"pm-web-dev\",\"domain\":\"https://pm-dev.masastack.com\"}},{\"id\":\"dcc\",\"service\":{\"id\":\"dcc-service-dev\",\"domain\":\"http://dcc-service-dev.masastack.com\"},\"web\":{\"id\":\"dcc-web-dev\",\"domain\":\"https://dcc-dev.masastack.com\"}},{\"id\":\"tsc\",\"service\":{\"id\":\"tsc-service-dev\",\"domain\":\"http://tsc-service-dev.masastack.com\"},\"web\":{\"id\":\"tsc-web-dev\",\"domain\":\"https://tsc-dev.masastack.com\"}},{\"id\":\"alert\",\"service\":{\"id\":\"alert-service-dev\",\"domain\":\"http://alert-service-dev.masastack.com\"},\"web\":{\"id\":\"alert-web-dev\",\"domain\":\"https://alert-dev.masastack.com\"}},{\"id\":\"scheduler\",\"service\":{\"id\":\"scheduler-service-dev\",\"domain\":\"http://scheduler-service-dev.masastack.com\"},\"worker\":{\"id\":\"scheduler-worker-dev\",\"domain\":\"http://scheduler-worker-dev.masastack.com\"},\"web\":{\"id\":\"scheduler-web-dev\",\"domain\":\"https://scheduler-dev.masastack.com\"}},{\"id\":\"mc\",\"service\":{\"id\":\"mc-service-dev\",\"domain\":\"http://mc-service-dev.masastack.com\"},\"web\":{\"id\":\"mc-web-dev\",\"domain\":\"https://mc-dev.masastack.com\"}},{\"id\":\"auth\",\"service\":{\"id\":\"auth-service-dev\",\"domain\":\"http://auth-service-dev.masastack.com\"},\"web\":{\"id\":\"auth-web-dev\",\"domain\":\"https://auth-dev.masastack.com\"},\"sso\":{\"id\":\"auth-sso-dev\",\"domain\":\"https://auth-sso-dev.masastack.com\"}}]",
"ELASTIC": "{\"Nodes\": [\"http://es-ydy-new.lonsid.cn:9200\"],\"Index\": \"auth_user_development\"}",
"ENVIRONMENT": "Development",
Expand Down
9 changes: 9 additions & 0 deletions src/Services/Masa.Dcc.Service/Services/OpenApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public OpenApiService()
{
App.MapPut("open-api/releasing/{environment}/{cluster}/{appId}/{configObject}", UpdateConfigObjectAsync);
App.MapPost("open-api/releasing/{environment}/{cluster}/{appId}/{isEncryption}", AddConfigObjectAsync);
App.MapPost("open-api/releasing/get/{environment}/{cluster}/{appId}", GetConfigObjectsAsync);
}

public async Task UpdateConfigObjectAsync(IEventBus eventBus, string environment, string cluster, string appId, string configObject,
Expand All @@ -25,5 +26,13 @@ public async Task AddConfigObjectAsync(IEventBus eventBus, string environment, s
await eventBus.PublishAsync(
new InitConfigObjectCommand(environment, cluster, appId, configObjects, configObjectType, isEncryption));
}

public async Task<Dictionary<string, PublishReleaseModel>> GetConfigObjectsAsync(IEventBus eventBus, string environment, string cluster, string appId,
[FromBody] List<string>? configObjects)
{
var query = new ConfigObjectsByDynamicQuery(environment, cluster, appId, configObjects);
await eventBus.PublishAsync(query);
return query.Result;
}
}
}
2 changes: 1 addition & 1 deletion src/Services/Masa.Dcc.Service/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
}
},
"ConnectionStrings": {
"DefaultConnection": "Server=10.175.171.201,32679;Database=dcc_dev;User Id=ss;Password=Hzss@123;"
"DefaultConnection": "Server=10.130.0.19:2415;Database=dcc_dev;User Id=ss;Password=Hzss@123;"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"TLS_NAME": "",
"CLUSTER": "Default",
"OTLP_URL": "https://otel-collector.masastack:9013",
"REDIS": "{\"RedisHost\": \"10.130.0.235\", \"RedisPort\": 24615, \"RedisDb\": 0,\"RedisPassword\": \"Hzss@123\"}",
"CONNECTIONSTRING": "{\"Server\": \"10.130.0.235\", \"Port\": 24878,\"Database\":\"pm-dev\",\"UserId\": \"ss\",\"Password\":\"Hzss@123\"}",
"REDIS": "{\"RedisHost\": \"10.130.0.19\", \"RedisPort\": 2135, \"RedisDb\": 0,\"RedisPassword\": \"Hzss@123\"}",
"CONNECTIONSTRING": "{\"Server\": \"10.130.0.19\", \"Port\": 2415,\"Database\":\"pm-dev\",\"UserId\": \"ss\",\"Password\":\"Hzss@123\"}",
"MASA_STACK": "[{\"id\":\"pm\",\"service\":{\"id\":\"pm-service-dev\",\"domain\":\"http://pm-service-dev.masastack.com\"},\"web\":{\"id\":\"pm-web-dev\",\"domain\":\"https://pm-dev.masastack.com\"}},{\"id\":\"dcc\",\"service\":{\"id\":\"dcc-service-dev\",\"domain\":\"http://dcc-service-dev.masastack.com\"},\"web\":{\"id\":\"dcc-web-dev\",\"domain\":\"https://dcc-dev.masastack.com\"}},{\"id\":\"tsc\",\"service\":{\"id\":\"tsc-service-dev\",\"domain\":\"http://tsc-service-dev.masastack.com\"},\"web\":{\"id\":\"tsc-web-dev\",\"domain\":\"https://tsc-dev.masastack.com\"}},{\"id\":\"alert\",\"service\":{\"id\":\"alert-service-dev\",\"domain\":\"http://alert-service-dev.masastack.com\"},\"web\":{\"id\":\"alert-web-dev\",\"domain\":\"https://alert-dev.masastack.com\"}},{\"id\":\"scheduler\",\"service\":{\"id\":\"scheduler-service-dev\",\"domain\":\"http://scheduler-service-dev.masastack.com\"},\"worker\":{\"id\":\"scheduler-worker-dev\",\"domain\":\"http://scheduler-worker-dev.masastack.com\"},\"web\":{\"id\":\"scheduler-web-dev\",\"domain\":\"https://scheduler-dev.masastack.com\"}},{\"id\":\"mc\",\"service\":{\"id\":\"mc-service-dev\",\"domain\":\"http://mc-service-dev.masastack.com\"},\"web\":{\"id\":\"mc-web-dev\",\"domain\":\"https://mc-dev.masastack.com\"}},{\"id\":\"auth\",\"service\":{\"id\":\"auth-service-dev\",\"domain\":\"http://auth-service-dev.masastack.com\"},\"web\":{\"id\":\"auth-web-dev\",\"domain\":\"https://auth-dev.masastack.com\"},\"sso\":{\"id\":\"auth-sso-dev\",\"domain\":\"https://auth-sso-dev.masastack.com\"}}]",
"ELASTIC": "{\"Nodes\": [\"http://es-ydy-new.lonsid.cn:9200\"],\"Index\": \"auth_user_development\"}",
"ENVIRONMENT": "Development",
Expand Down