-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Combine IFeatureActiveService & IFeatureDisableService to IFeatureMan…
…agementService
- Loading branch information
Showing
33 changed files
with
201 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...reManager.Core/FeatureManagerConstants.cs → ...gement.Core/FeatureManagementConstants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ager.Core/FeatureDisableCoreAElfModule.cs → ...t.Core/FeatureManagementCoreAElfModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/AElf.Kernel.FeatureManagement.Core/IFeatureManagementService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Volo.Abp.DependencyInjection; | ||
|
||
namespace AElf.Kernel.FeatureManagement.Core; | ||
|
||
public interface IFeatureManagementService | ||
{ | ||
Task<bool> IsFeatureActive(string featureName); | ||
Task<bool> IsFeatureDisabledAsync(params string[] featureNames); | ||
} | ||
|
||
public class DefaultFeatureManagementService : IFeatureManagementService, ITransientDependency | ||
{ | ||
public Task<bool> IsFeatureActive(string featureName) | ||
{ | ||
return Task.FromResult(false); | ||
} | ||
|
||
public Task<bool> IsFeatureDisabledAsync(params string[] featureNames) | ||
{ | ||
return Task.FromResult(false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/AElf.Kernel.FeatureManagement/FeatureManagementAElfModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using AElf.Kernel.Configuration; | ||
using AElf.Kernel.FeatureManagement.Core; | ||
using AElf.Modularity; | ||
using Volo.Abp.Modularity; | ||
|
||
namespace AElf.Kernel.FeatureManagement; | ||
|
||
[DependsOn( | ||
typeof(FeatureManagementCoreAElfModule), | ||
typeof(ConfigurationAElfModule) | ||
)] | ||
public class FeatureManagementAElfModule : AElfModule | ||
{ | ||
} |
8 changes: 8 additions & 0 deletions
8
src/AElf.Kernel.FeatureManagement/FeatureManagementOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace AElf.Kernel.FeatureManagement; | ||
|
||
public class FeatureManagementOptions | ||
{ | ||
public List<string> DisableFeatureNameList { get; set; } | ||
} |
70 changes: 70 additions & 0 deletions
70
src/AElf.Kernel.FeatureManagement/FeatureManagementService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using AElf.Kernel.Blockchain.Application; | ||
using AElf.Kernel.Configuration; | ||
using AElf.Kernel.FeatureManagement.Core; | ||
using Google.Protobuf; | ||
using Google.Protobuf.WellKnownTypes; | ||
using Volo.Abp.DependencyInjection; | ||
|
||
namespace AElf.Kernel.FeatureManagement; | ||
|
||
public class FeatureManagementService : IFeatureManagementService, ITransientDependency | ||
{ | ||
private readonly IBlockchainService _blockchainService; | ||
private readonly IConfigurationService _configurationService; | ||
private readonly IDisabledFeatureListProvider _disabledFeatureListProvider; | ||
|
||
public FeatureManagementService(IConfigurationService configurationService, IBlockchainService blockchainService, | ||
IDisabledFeatureListProvider disabledFeatureListProvider) | ||
{ | ||
_configurationService = configurationService; | ||
_blockchainService = blockchainService; | ||
_disabledFeatureListProvider = disabledFeatureListProvider; | ||
} | ||
|
||
public async Task<bool> IsFeatureActive(string featureName) | ||
{ | ||
var featureConfigurationName = GetFeatureConfigurationName(featureName); | ||
var chain = await _blockchainService.GetChainAsync(); | ||
var activeHeightByteString = await _configurationService.GetConfigurationDataAsync(featureConfigurationName, | ||
new ChainContext | ||
{ | ||
BlockHeight = chain.BestChainHeight, | ||
BlockHash = chain.BestChainHash | ||
}); | ||
var activeHeight = new Int64Value(); | ||
activeHeight.MergeFrom(activeHeightByteString); | ||
if (activeHeight.Value == 0) return false; | ||
|
||
return chain.BestChainHeight >= activeHeight.Value; | ||
} | ||
|
||
private string GetFeatureConfigurationName(string featureName) | ||
{ | ||
return $"{FeatureManagementConstants.FeatureConfigurationNamePrefix}{featureName}"; | ||
} | ||
|
||
public async Task<bool> IsFeatureDisabledAsync(params string[] featureNames) | ||
{ | ||
var chain = await _blockchainService.GetChainAsync(); | ||
if (chain == null || chain.BestChainHeight <= 1) | ||
{ | ||
// Which means chain hasn't been created yet or only genesis block exists. | ||
return false; | ||
} | ||
|
||
var nameList = await _disabledFeatureListProvider.GetDisabledFeatureListAsync(new BlockIndex | ||
{ | ||
BlockHash = chain.BestChainHash, | ||
BlockHeight = chain.BestChainHeight | ||
}); | ||
if (nameList.Length == 0) | ||
{ | ||
return false; | ||
} | ||
|
||
var isDisabled = nameList.Select(n => n.Trim()).Intersect(featureNames).Any(); | ||
return isDisabled; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
src/AElf.Kernel.FeatureManager.Core/IFeatureDisableService.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
src/AElf.Kernel.FeatureManager/FeatureManagerAElfModule.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.