Skip to content

Commit

Permalink
fix: fix rollback (#627)
Browse files Browse the repository at this point in the history
* fix: fix #549

* fix: fix rollback

---------

Co-authored-by: yanpengju <[email protected]>
  • Loading branch information
codding-y and yanpengju authored Jul 31, 2023
1 parent 8bcfecf commit 5d0abc6
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ public interface IAppConfigObjectRepository : IRepository<AppConfigObject>

Task<List<(int AppId, ConfigObjectRelease Release)>> GetAppLatestReleaseConfigAsync(IEnumerable<int> appIds,
int? envClusterId = null);

Task<AppConfigObject> GetbyConfigObjectIdAsync(int configObjectId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ Task<List<BizConfigObject>> GetListByEnvClusterIdAsync(int envClusterId, int biz

Task<List<(ConfigObjectRelease Release, int ProjectId)>> GetProjectLatestReleaseConfigAsync(
List<ProjectModel> projects, int? envClusterId = null);

Task<BizConfigObject> GetByConfigObjectIdAsync(int configObjectId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@ public async Task AddConfigObjectReleaseAsync(AddConfigObjectReleaseDto dto)
else
{
//add redis cache
//TODO: encryption value
var key = $"{dto.EnvironmentName}-{dto.ClusterName}-{dto.Identity}-{configObject.Name}";
if (configObject.Encryption)
{
Expand Down Expand Up @@ -425,6 +424,38 @@ await _configObjectReleaseRepository.AddAsync(new ConfigObjectRelease(
var configObject = (await _configObjectRepository.FindAsync(config => config.Id == rollbackDto.ConfigObjectId))!;
configObject.AddContent(configObject.Content, rollbackToEntity.Content);
await _configObjectRepository.UpdateAsync(configObject);

string key = string.Empty;
var envClusters = await _pmClient.ClusterService.GetEnvironmentClustersAsync();
if (configObject.Type == ConfigObjectType.Public)
{
var publicConfigObject = await _publicConfigObjectRepository.GetByConfigObjectIdAsync(configObject.Id);
var publicConfig = await _publicConfigRepository.FindAsync(c => c.Id == publicConfigObject.PublicConfigId) ?? throw new MasaException();
var envCluster = envClusters.First(e => e.Id == publicConfigObject.EnvironmentClusterId);
key = $"{envCluster.EnvironmentName}-{envCluster.ClusterName}-{publicConfig.Identity}-{configObject.Name}";
}
else if (configObject.Type == ConfigObjectType.Biz)
{
var bizConfigObject = await _bizConfigObjectRepository.GetByConfigObjectIdAsync(configObject.Id);
var bizConfig = await _bizConfigRepository.FindAsync(c => c.Id == bizConfigObject.BizConfigId) ?? throw new MasaException();
var envCluster = envClusters.First(e => e.Id == bizConfigObject.EnvironmentClusterId);
key = $"{envCluster.EnvironmentName}-{envCluster.ClusterName}-{bizConfig.Identity}-{configObject.Name}";
}
else if (configObject.Type == ConfigObjectType.App)
{
var appConfigObject = await _appConfigObjectRepository.GetbyConfigObjectIdAsync(configObject.Id);
var app = await _pmClient.AppService.GetAsync(appConfigObject.AppId) ?? throw new MasaException(); ;
var envCluster = envClusters.First(e => e.Id == appConfigObject.EnvironmentClusterId);
key = $"{envCluster.EnvironmentName}-{envCluster.ClusterName}-{app.Identity}-{configObject.Name}";
}

var releaseContent = new PublishReleaseModel
{
Content = configObject.Encryption ? EncryptContent(rollbackToEntity.Content) : rollbackToEntity.Content,
FormatLabelCode = configObject.FormatLabelCode,
Encryption = configObject.Encryption
};
await _memoryCacheClient.SetAsync(key.ToLower(), releaseContent);
}

public async Task UpdateConfigObjectAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,14 @@ public async Task<List<AppConfigObject>> GetListByAppIdAsync(int appId)

return configData;
}


public async Task<AppConfigObject> GetbyConfigObjectIdAsync(int configObjectId)
{
var result = await Context.Set<AppConfigObject>()
.FirstOrDefaultAsync(p => p.ConfigObjectId == configObjectId);

return result ?? new(0, 0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,13 @@ from release in rNullable.DefaultIfEmpty()

return result;
}

public async Task<BizConfigObject> GetByConfigObjectIdAsync(int configObjectId)
{
var result = await Context.Set<BizConfigObject>()
.FirstOrDefaultAsync(p => p.ConfigObjectId == configObjectId);

return result ?? new(0, 0);
}
}
}

0 comments on commit 5d0abc6

Please sign in to comment.